530 likes | 1.25k Views
Predicate Logic. A Logic is a formal language, with precisely defined syntax and semantics, which supports sound inference. Independent of domain of application. Different logics exist, which allow you to represent different kinds of things, and which allow more or less efficient inference.
E N D
Predicate Logic • A Logic is a formal language, with precisely defined syntax and semantics, which supports sound inference. Independent of domain of application. • Different logics exist, which allow you to represent different kinds of things, and which allow more or less efficient inference. • propositional logic, predicate logic, temporal logic, modal logic, description logic.. • But representing some things in logic may not be very natural, and inferences may not be efficient. More specialised languages may be better. Ch02 / 1
Review of Proposition Logic • We need formal notation to represent knowledge, allowing automated inference and problem solving. • One popular choice is use of logic. • In general a logic is defined by • syntax: what expressions are allowed in the language. • Semantics: what they mean, in terms of a mapping to real world • proof theory: how we can draw new conclusions from existing statements in the logic. Propositional logic is the simplest.. • Propositional logic is the simplest. • Symbols represent facts: P, Q, etc.. • These are joined by logical connectives (and, or, implication) e.g., P Q; Q R • Given some statements in the logic we can deduce new facts (e.g., from above deduce R) Ch02 / 2
Review of Proposition Logic • Propositional Logic/Calculus Sentences: • Every propositional symbol and truth symbol is a sentences. • E.g.: true, false, P, Q, and R • The negation of a sentence is a sentence. • E.g.: Q and true • The conjunction, or and, of two sentences is a sentence. • E.g.: P Q, P P • The disjunction, or or and, of two sentences is a sentence. • E.g.: P Q, P P • The implication of one sentence from another is a sentence. • E.g.: P Q • The equivalence of two sentences is a sentence. • E.g.: P Q R • An expression is a sentence, or well-formed formula (WFF), of the propositional logic if and only if it can be formed of legals symbol through some sequence of rules. E.g.: ((P Q ) R) P Q R Why? Ch02 / 3
Review of Proposition Logic: Syntax • Symbols (e.g., letters, words) are used to represent facts about the world, e.g., • “P” represents the fact “Ahmad likes chocolate” • “Q” represents the fact “Ahmad has chocolate” • Simple facts above are called atomic propositions. • Complex facts can be built by combining atomic propositions with the logical connectives: • and: , conjunction of two sentences • or: , disjunction of two sentences • if-then: (implication), P Q where P premise & Q conclusion • : equivalence • not: negation • Statements or sentences in the language are constructed from atomic propositions and logical connectives. • P Q “Ahmad likes chocolate and he doesn’t have any.” • P Q “If Ahmad likes chocolate then Ahmad has chocolate” • P Q “If Ahmad likes chocolate then Ahmad has chocolate, and vice versa” • Q “ Ahmad doesn’t have chocolate” Ch02 / 4
Review of Proposition Logic: Semantics • What does it all mean? • Sentences in propositional logic tell you about what is true or false. • P Q means that both P and Q are true. • P Q means that either P or Q is true (or both) • P Q means that false if P is true and Q is false, otherwise true. • P Q means that true if both P and Q are have the same truth value • To determine whether the sentences are truth or falsity, truth tables will be used. X Y X Y X Y X XY X Y (X Y)(XY) T T T T F T T T T F T F F F F T F T T F T T T T F F F F T T T T We now know exactly what is meant in terms of the truth of the elementary propositions when we get a sentence in the language (e.g., P Q R). Ch02 / 5
Review of Proposition Logic: Proof Theory • How do we draw new conclusions from existing supplied facts? • We can define inference rules, which are guaranteed to give true conclusions given true premises. • For propositional logic useful one is modus ponens: A, A B ————————— B • If A is true and A B is true, then conclude B is true. Ch02 / 6
Review of Proposition Logic: Proof Theory Proof Theory and Inference • So, let P mean “It is raining”, Q mean “I carry my umbrella”. • If we know that P is true, and P Q is true • We can conclude that Q is true. • Note that certain expressions are equivalent • think about P Q and P Q. • Other rules of inference can be used, e.g.,: A B, B C ——————————————— A C • This is essentially the resolution rule of inference, used in Prolog. Ch02 / 7
Review of Proposition Logic: Proof Theory • Consider: sunny raining raining umbrella • What can we conclude? • We can use the rule of inference, given the first two sentences, to conclude sunnycarryumbrella. • Proof: • Suppose we want to try and prove that a certain proposition is true, given some sentences that are true. • It turns out that the resolution rule is sufficient to do this. • We put all the sentences into a standard or “normal” form (replacing A B with A B) • There is then a standard procedure that lets you determine if the proposition in question is true. Ch02 / 8
Predicate Logic • Propositional logic isn’t powerful enough as a general knowledge representation language. • In proposition logic, each atomic symbol (P, Q, etc) denotes a proposition of some complexity. • No way to access the components of an individual assertion. • Impossible to make general statements. E.g., “It rained on Tuesday”. • Predicate logic provides this ability. How? • Instead of letting a single propositional symbol, P, denote the entire sentence “It rained on Tuesday,” we can create a predicate weather that describes a relationship between a date and the weather: weather(Tuesday,rain) • Through inference rule we can manipulate predicate logic expressions, accessing their individual components and inferring new sentences. Ch02 / 9
Predicate Logic • Advantages: • well defined formal sentences. • sound and complete inference rules. • In predicate logic the basic unit is a predicate/argument structure called an atomic sentence: Predicate(Argument1,Argument2,..,ArgumentN) - Predicate like constants and function names, begin with a lowercase letter -Predicate names a relationship between zero or more object in the world - Number of object related is the arity of the object • E.g.: • likes(Ahmad, chocolate) • tall(Abu) • Suppose Arguments can be any of: • constant symbol, such as ‘Ahmad’ • variable symbol, such as X • function expression, e.g., motherof(Abu) • So we can have: • likes(X, Abdullah) • friends(motherof(Abu), motherof(Lim)) Ch02 / 10
Predicate Logic: Syntax Syntax • Predicate logic symbols consist of • The set of letters, both upper- and lowercase • The set of digits, 0,1,…,9 • The underscore, _ • Symbols must begin with a letter and are followed by any sequence of these legal characters. • Not include special characters (#,%,@,/,&,” ”,#) • Valid symbols: George fire3 tom_and_jerry bill XXXX friends_of • Symbols include: • Truth symbols – true and false (reserved symbols) • Constant symbols – symbols expressions having the first character lowercase • Variable symbols – symbols expressions beginning with an uppercase character • Function symbols – symbols expressions having the first character lowercase. Have arity indicates the number of elements of the domain mapped onto each element of the range. Ch02 / 11
Predicate Logic: Syntax • These atomic sentences can be combined using logic connectives • likes(john, mary) tall(mary) • tall(john) nice(john) • Sentences can also be formed using quantifiers (forall) and (there exists) to indicate how to treat variables: • X lovely(X) Everything is lovely. • X lovely(X) Something is lovely. • X in(X, garden) lovely(X) Everything in the garden is lovely. • Can have several quantifiers, e.g., • X Y loves(X, Y) • Everything loves something • X handsome(X) Y loves(Y, X) • Every handsome has something that they love. Ch02 / 12
Predicate Logic:Syntax • So we can represent things like: • All men are mortal. • No one likes brussel sprouts. • Everyone taking SAK4602 will pass their exams. • Every race has a winner. • John likes everyone who is tall. • John doesn’t like anyone who likes brussel sprouts. • There is something small and slimy on the table. Term • Either constant, variable, or expression. • May used to denote objects and properties in a problem domain. • Examples: • Cat, times(2,3), X, blue, mother(jane), kate Ch02 / 13
Predicate Logic:Syntax Atomic sentences • A predicate constant of arity n followed by n terms, t1,t2,..,tn enclosed in parentheses and separated by commas. • Examples: • Truth values, true and false • likes(ahmad, aminah) • helps(bill, george) • Friends(bill, george) • friends(father_of(ahmad), father_of(abu)) • Describes a relationship between two objects in a domain discourse. • Arguments are represented as function expressions whose mappings (given that the father_of ahmad is salleh and the father_of abu is bakar) form the parameters of the predicate Ch02 / 14
Predicate Logic:Syntax Complex sentences • Combination of atomic sentences with logical connectives: , , , , , and . • , Universal quantifier – indicates that the sentence is true for all values of the domain. • , Existential quantifier – indicates that the sentence is true for at leats one value in the domain. Examples 1: • Y friends(Y, abdullah) • True if there is at least one object , indicated by Y that is a friend of abdullah. • X likes(X, ice_cream) • True for all values in the domain of the definition of X • X(likes(usman, X) eats(usman, X) • Usman eate everything that he likes. • X (bird(X) flies(X)) • There exists some bird that doesn’t fly. • X (person(X) Y loves(X, Y)) • Every person has something that they love. Ch02 / 15
Predicate Logic:Syntax Examples 2: Set of family relationship mother(rokiah, salleh) mother(rokiah, usman) father(abdullah, salleh) father(abdullah, usman) X Y (father(X,Y) mother(X,Y) parent(X, Y)) X Y Z (parent(X,Y) parent(X,Z) sibling(Y,Z)) • In this example, we use the predicates mother and father to define a set of parent-child relationships • Implications give general definitions of other relationships • parent • sibling • Implications above can be used to infer facts • sibling(usman,salleh) Ch02 / 16
Predicate Logic:Semantics Semantics • There is a precise meaning to expressions in predicate logic. • It determine their meaning in terms of objects, properties, and relationship in the world. • The truth of expressions depends on the mapping of constants, variables, predicates, and functions into objects and relationship in the domain of interest. • Like in propositional logic, it is all about determining whether something is true or false. • X P(X) means that P(X) must be true for every object X in the domain of interest. • X P(X) means that P(X) must be true for at least one object X in the domain of interest. • So if we have a domain of interest consisting of just two people, john and mary, and we know that tall(mary) and tall(john) are true, we can say that X tall(X) is true. Ch02 / 17
c b a d Predicate Logic:Semantics Examples 1: • “If it doesn’t rain tomorrow, ahmad will go fishing.” • weather(rain, tomorrow) go(ahmad, fishing). • “All basketball players are tall.” • X(basketball_players(X) tall(X) ). • “Nobody likes taxes.” • X likes(X, taxes). Examples 2: Blocks World with its predicate logic description on(c,a) on(b,d) ontable(a) ontable(d) clear(b) clear(c) hand_empty Ch02 / 18
Predicate Logic:Semantics • We need to represent knowledge based on: • Does a given block have a clear top surface? • Can we pick up block a? etc. • Assume that the computer has knowledge of the location of each block and the arm and is able to keep track of these location as the hand moves blocks about the table. • The arm can move blocks, change the state, and clear. • Example 2.1: Pick up a block and stack it on another block. • Is block a clear ? • Remove block c. • Delete the knowledge of on(c,a). • Pick up block a. • The following rule describes when a block is clear: X(Y on(Y,X) clear(X)) • For all X, X is clear if there does not exist a Y such that Y is on X. Ch02 / 19
Predicate Logic:Semantics • Example 2.2: To stack X on Y • First empty the hand, • Clear X • Clear Y • Pick up X • Put down X on Y • The following rule describes when a block is clear: X Y((hand_empty clear(X) clear(Y) pick_up(X) put_down(X,Y)) stack(X,Y)) • For all X and Y, if hand empty, and X and Y is clear, and pick up X and put X on Y such that X stack on Y. Ch02 / 20
Predicate Logic:Semantics Examples 3: Mapping of symbols into objects and relations in the domain of definition friends(ali, bakar) friends(ali, ismail) Objects and relations Asking expression : ? friends(ali, bakar) True ? friends(ali, ali) False First-Order Predicate Logic • Universally and existentially quantified variables may refer only to objects (constants) in the domain of discourse. • Predicate and function names may not be replaced by quantified variables. • Examples of valid sentences for predicate p and q and variables X and Y: • p(X) = X p(X) • X p(X) = X p(X) • X p(X) = Y p(Y) • X q(X) = Y q(Y) • X(p(X) q(X)) = Xp(X) Yq(Y) • X(p(X) q(X)) = Xp(X) Yq(Y) Ch02 / 21
Predicate Logic: Proof and Inference Proof and Inference • There again we can define inference rules allowing us to say that if certain things are true, certain other things are sure to be true, e.g. • X P(X) Q(X) P(something) ----------------- (so we can conclude)Q(something) • This involves matching P(X) against P(something) and binding the variable X to the symbol something. • What can we conclude from the following? • X tall(X) strong(X) • tall(john) • X strong(X) loves(mary, X) • Proof Procedure • A combination of an inference rule and an algorithm for applying that rule to a set of logical expressions to generate new sentences. Ch02 / 22
Predicate Logic: Proof and Inference • A predicate logic expression X logically follows from a set S of predicate logic expressions if every interpretation and variable assignment that satisfies S also satifies X. • Logically follows mean that X is true for every interpretation that satisfies S • Inference rule • Essentially a mechanical means of producing new predicate logic sentences from other sentences. • Its produce new sentences based on the syntactic form of given logical assertion. • sound • If every predicate logic expression produced by the rule from a set S of predicate logic expressions also logically follows from S. • Two examples: • Modus ponens • Resolution Ch02 / 23
Predicate Logic: Proof and Inference • Complete • If, given a set S of predicate logic expressions, the rule can infer every expression that logically follows from S. • Modus ponens. • Sound inference rule. • If the premise is true then the conclusions are guaranteed true. • If we are given an expression of the form PQ and another expression of the form P such that both are true under an interpretation I, then modus ponens allows us to infer that Q is also true for that interpretation. • Because modus ponens is sound, Q is true for all interpretations for which P and PQ are true. • Example 1: Assume the following observations P denotes “it is raining.” Q denotes “the ground is wet.” P Q denotes “if it is raining then the ground is wet.” How to proof Q is true? Now is raining (P is true) and P Q generally true, then Q is true. Ch02 / 24
Predicate Logic: Proof and Inference • Example 2: Expression containing variables “all men are mortal and Socrates is a men; therefore Socrates is mortal.” Represents the ”all men are mortal” in predicate calculus: X(man(X) mortal(X) Represents the ”Socrates is a man” in predicate calculus: man(socrates) Because the X in the implication is universally quantified, we may substitute any value in the domain for X. By subtituting socrates for X in the implication, then we can infer: man(socrates) mortal(socrates) – conclusion This is added to the set of expressions that logically follow from the original assertions. Ch02 / 25
Predicate Logic: Unification • To apply inference rule, modus ponens, an inference system must be able to determine when two expressions are the same or match. • In propositional logic, they match if and only if they are syntactically identical. • In predicate logic, the process of matching two expressions is complicated because the expression contains variables that may be replaced from the domain by any terms of arbitrary complexity. • Its require a decision process for determining the variable substitutions under which two or more expressions can be made identical. • Unification is an algorithm for determining the substitutions needed to make two predicate logic expressions match. • Unification is critically important for any AI problem solver that uses the PreC as a representation language. • Example 1: Simple substitution Substituting socrates with X to infer mortal(socrates). Ch02 / 26
Predicate Logic: Unification • Example 2: Some instances of the expression foo(X,a,goo(Y)) Generated by legal substitutions are given below: 1. foo(fred, a, goo(Z)) 2. foo(W, a, goo(jack)) 3. foo(Z, a, goo(moo(Z))) In the example above, the substitution instances or unification that would make the initial expression identical to each of the other three are written as 1. {fred/X, Z/Y} 2. {W/X, jack/Y} 3. {Z/X, moo(Z)/Y} The notation X/Y, … indicates that X is substituted for the variable Y in the original expression. Ch02 / 27
Predicate Logic: Application • Example 1: A Logic-Based Financial Advisor The function of the advisor is to help a user decide whether to invest in a savings account or the stock market. The investment that will be recommended for individual investors depends on their income and the current amount they have saved according to the following criteria: 1. Individuals with an inadequate savings account should always increasing the amount saved the priority, regardless of their income 2. Individuals with an adequate savings account and an adequate income should consider a riskier but potentially more profitable investment in the stock market. 3. Individuals with a lower income who already have an savings account may want to consider splitting their surplus income between savings and stocks, to increase the cushion in savings while attempting to increase their income through stocks. Ch02 / 28
Predicate Logic: Application • The adequacy of both is determined by the number of dependents an individual must support. Our rule: 1. At least RM5000 in the bank for each dependent. 2. An adequate income must be steady income and supply at least RM15,000 per year plus an additional RM4000 for each dependent. • To automate this advice, we translate these guidelines into sentences in the predicate logic. • Determines the major features that must be considered. Here, they are the adequacy of the savings and the income. They are represented by: savings_account(adequate). savings_account(inadequate). income(adequate). income(inadequate). 2. Conclusion are represented by the unary predicate investment, with possible values of its argument being stock, savings or combination (implying that the investment should be split) Ch02 / 29
Predicate Logic: Application • The different investment strategies are represented by implications: savings_account(inadequate) investment(savings) savings_account(inadequate) income(adequate) investment(savings) savings_account(inadequate) income(inadequate) investment(savings) 3. The advisor must determines when savings and income are adequate or inadequate: Xamount_saved(X)Y(dependents(Y) greater(X,minsavings(Y) ) ) savings_account(adequate). Xamount_saved(X)Y(dependents(Y) greater(X, minsavings(Y)))savings_account(inadequate). minsavings(Y) is a function : minsavings(Y) = 5000*Y; Ch02 / 30
Predicate Logic: Application 4. Determines when income are adequate or inadequate: Xearnings(X,steady)Y(dependents(Y) greater(X, minincome(Y)) ) income(adequate). Xearnings(X,steady)Y(dependents(Y) greater(X, minincome(Y) ) ) income(inadequate). X earnings(X,unsteady) income(inadequate). Where minincome(Y) = 15000+(4000*Y) • Inorder to perform a consultation, a description of a particular investor is added to this set of sentences using: amount_saved(22000). earnings(25000, steady). dependents(3). Ch02 / 31
Predicate Logic: Application • This yield a logical system consisting: Ch02 / 32
Predicate Logic: Application Unification Process: • Unify the conjunction of 10 and 11 with the first two components of the premise of 7 under substitution {25000/X, 3/Y} i.e., earnings(25000,steady) dependents(3) unify with earnings(X,steady) dependents(Y) under substitution {25000/X, 3/Y} yields the new implication: earnings(25000,steady) (dependents(3) greater(25000, minincome(3) ) income(inadequate). • Evaluating the function minincome yielding: earnings(25000,steady) (dependents(3) greater(25000, 27000) income(inadequate). • Since premises are true by applying modus ponen the conclusion is true. This is added as assertion 12: 12. income(inadequate). Ch02 / 33
Predicate Logic: Application • Similarly, unify sentence 9 and 10 with sentence 4, under the substitution {22000/X, 3/Y}, yielding the implication amount_saved(22000)(dependents(3) greater(22000, minsavings(3))savings_account(adequate). • Evaluating the function minsavings(3) yields the expression: amount_saved(22000)(dependents(3)greater(22000,15000) savings_account(adequate). • Again, since premises are true by applying modus ponen the conclusion is true. This is added as assertion 13: 13. Savings_account(adequate). • Finally by examining 3, 12, and 13 indicates, the premise of implication 3 is true. When we apply modus ponens a third time, the conclusion is investment(combination). • This is the suggested investment for this individual. Ch02 / 34
Logic Programming • Logic programming languages view a computer program as a set of statements in logic. • Contradict to procedural languages, we can give the system statements to try to prove. • Prolog is a logic programming language that the most widely used. • Prolog is based on predicate logic, but with slightly different notation/syntax. • Example 1: a(X) :- b(X), c(X). Equivalent to X a(X) b(X) c(X) Or equivalently X b(X) c(X) a(X) • Example 2: father(jim, fred). father(joe, jim). grandfather(X, Y) :- father(X, Z), father(Z, Y). Equivalent to XYZ ( (father(X,Z) father(Z,Y)) grandfather(X,Y)) We can ask Prolog to prove that grandfather(joe,fred) was true ?grandfather(joe,fred) yes Ch02 / 35
Logic Programming • Prolog has a built in proof/inference procedure, that lets you determine what is true given some initial set of facts. Proof method called “resolution”. Knowledge Representation using Predicate Logic • Representing Facts in Logic • We must know how to represent things in predicate logic and what expressions mean. • Outline how you get from a statement expressed in English to a statement in predicate logic: • Use the verb as predicate and the nouns as the arguments Example: “Ahmad likes ice-cream” likes(ahmad,ice_cream) “Johan loves Sarah” loves(johan,sarah) • Use logical connective to represent complex statements and its cannot be used within an argument of a predicate. Example: “Ahmad likes ice-cream likes(ahmad,ice_cream) and chocolate” likes(ahmad,chocolate) Ch02 / 36
Representing Facts in Logic “Atheer is tall and slim” tall(atheer) slim(atheer) • Statements of the form “If X then Y” can be translated into X Y Example: “Hassan is thirsty then thirsty(hassan) he drinks coffee” drinks(hassan,coffee) “Malik is thirsty then thirsty(malik) he drinks coffee or tea” drinks(malik,coffee) drinks(malik,tea) • Use to represent the facts that not true/nothing Example: “Safuan doesn’t like drinks coffee” like(safuan,coffee) • Use quantifiers (for all thing) and (there exists) Example: “All students study” Xstudent(X) study(X) • Thing is a student then that thing will study • “Someone strange likes Xstrange(X)likes(brusselsprouts) • brussel sprouts” Ch02 / 37
Representing Facts in Logic “There is some table that doesn’t have 4 legs” X(table(X) snumlegs(X,4)) “All elephants are grey” X(elephant(X) grey(X)) “All Glaswegians support either Celtic or Rangers” X(glaswegian(X) (supports(X,rangers) supports(X,celtic))) “There is something small and slimy on the table” X(small(X) slimy(X) on(X,table)) “There is no brussel sprout which is tasty” X(brusselsprout(X) tasty(X)) Ch02 / 38
The use of Logic in AI • Predicate logic provides a powerful way to represent and reason with knowledge. • Its can represent knowledge that cannot represented using frame such as negation, disjunction and quantification. • Its provide much wider range of inference because of the predicate logic have inference rules and proof procedures compare to a frame system that has the simple inheritance inference. • Predicate logic is used to: • Representing knowledge • Communicate AI theories with the community. • Logic used to describe new theory of human reasoning or language use some people • As the basis of AI programming languages • Give the meaning of natural language sentences in a natural language understanding system • Define the semantics of other simpler representation languages Ch02 / 39
The use of Logic in AI • Predicate logic hard to represent facts that involve uncertainty, defaults, beliefs, and time/change, for example: • It will probably rain tomorrow. - uncertainty • It normally rains in Glasgow. - defaults • John believes it will rain, but I don’t. - beliefs • It will get wetter and wetter as you near Glasgow. - time/change • For complex problem solving, AI programmer have to • Choose between a logic-based approach, with clear semantics and guranteed sound reference, and a more ad hoc procedural approach which might be more efficient fot the particular problem. Ch02 / 40
Logic and Frames • For a simple frame system, without defaults, one way to translate thing into logic is as follows: • For an object o with slot s and value v we get: XY (o(X) (v(Y) s(X,Y) ) ) Example: “Elephant has_part head” XY (elephant(X) (head(Y) haspart(X,Y))) • For one object o is an instance of class c we get: c(o) Example: “Nellie’s an elephant” elephant(nellie) • If one class c1 is subclass of another class c2 we get: X (c1(X) c2(X) ). Example: “All elephants are mammal” Xelephant(X) mammal(X) Ch02 / 41
Logic and Frames • Inheritance still works in the logic-based version by applying the inference rule modus ponens: Example: “Elephant has_part head” XY (elephant(X) (head(Y) haspart(X,Y))) and “Nellie’s an elephant” elephant(nellie) to conclude that “Nellie has a head” Y head(Y) haspart(nellie,Y) Ch02 / 42
Summary • Intelligent systems require that we have • Knowledge formally represented • New inferences/conclusions possible. • Formal languages have been developed to support knowledge representation. • One important one is the use of logic - very general purpose way to formally represent truths about the world, and draw sound conclusions from these. • Predicate logic provides well defined language for knowledge rep supporting inference. • But representing some things in logic may not be very natural, and inferences may not be efficient. More specialised languages may be better. • Frames/Networks/Objects more natural, but only explicitly support inheritance, and may not have well defined semantics. • Current trend is either to just use OO, or to use logic, but specialises non-logic-based languages still exist. Ch02 / 43