You are on page 1of 43

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

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. what they mean, in terms of a Semantics: mapping to real world we can draw new proof theory: how conclusions from existing statements in the logic. Propositional the is the simplest.. Propositional logic is logicsimplest. 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

Review of Proposition Logic Propositional Logic/Calculus Sentences: Every propositional symbol and truth symbol is a sentences. E.g.: true, false,sentence is a sentence. The negation of a P, Q, and R E.g.: Q and true The conjunction, or and, of two sentences is a sentence. E.g.: P Q, P or and, of two sentences is The disjunction, or P a sentence. E.g.: P Q, P one sentence from another The implication of P is a sentence. E.g.: P Q The equivalence of two sentences is a sentence. An E.g.: P Qis aR expression 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? 3 Ch02

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. can be built by combining atomic Complex facts 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 doesnt have any. P Q If Ahmad likes chocolate then Ahmad has chocolate likes chocolate then Ahmad P Q If Ahmad has chocolate, and vice versa Q Ahmad doesnt have chocolate
4

Ch02

Review of Proposition Logic: Semantics What does it all mean? Sentences in propositional logic tell you about what is true or that both P and Q are true. P Q means false. P Q means that either P or Q is true (or both) means that false if P is true and Q is P Q false, otherwise true. if both P and Q are P Q means that true have the same truth value To determine whether the sentences are truth or falsity, truth tables will be used. XY TT TF FT FF X Y X Y X XY T T F T F F T F T F F T X Y (X Y)(XY) T T T F F T T T 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). 5 Ch02

Review of Proposition Logic: Proof Theory How do we draw new conclusions from existing supplied facts?inference rules, which are We can define 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

Review of Proposition Logic: Proof Theory Proof Theory and Inference So, let P mean It is raining, Q mean I carry my umbrella. P is true, and P Q is true If we know that 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

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 sunny carryumbrella. 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 We put allto do this. sufficient 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 isnt 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: Through inference rule we can manipulate weather(Tuesday,rain) predicate logic expressions, accessing their individual components and inferring new sentences.

Ch02

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 E.g.: - Predicate names a relationship between zero or more object in likes(Ahmad, chocolate) the world - Number of tall(Abu) object related is the arity of the object

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)) 10 Ch02 /

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: Symbols include: George fire3 tom_and_jerry bill XXXX Truth symbols true and false (reserved friends_of 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 11 Ch02 / domain mapped onto each element of the

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. Everything in X in(X, garden) lovely(X) e.g., Can have several quantifiers, the garden is lovely. 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 doesnt like anyone who likes brussel sprouts. Term There is something small and slimy on the Either constant, variable, or expression. table. 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 doesnt fly. X (person(X) Y loves(X, Y)) Every person has something that they love. 15 Ch02 /

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 relationshipsgive general definitions of other Implications 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 propositional logic, Like indomain of interest. 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

Predicate Logic:Semantics Examples 1: If it doesnt 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 2: Blocks World Exampleslikes(X, taxes). with its predicate logic description on(c,a) c b on(b,d) a ontable(a d ) ontable(d ) clear(b) clear(c) hand_em pty 18 Ch02 /

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 a block and stack it on Example 2.1: Pick up blocks, change the state, and clear. 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: Y((hand_empty clear(X) clear(Y) X 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, Objects and bakar) relations friends(ali, Asking ismail) : expression ? friends(ali, bakar) Tru e ? friends(ali, Fals ali) e 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 X q(X) = Y q(Y) p(X) X(p(X) q(X)) = Xp(X) X p(X) = X Yq(Y) p(X) X(p(X) q(X)) = Xp(X) X p(X) = Y Yq(Y) 21 p(Y) Ch02 /

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 Inference rule every interpretation that satisfies S 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

Complete If, given a set S of predicate logic expressions, the rule can infer every Modus expression that logically follows from S. ponens. Sound inference rule. If the premise is true then the conclusions are guaranteed true. expression of the form PQ If we are given an 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 raining (P true? proof Q is is true) and P Q generally Now is true, then Q is true. 24 Ch02 /

Predicate Logic: Proof and Inference

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 man(socrates) subtituting socrates for X in the mortal(socrates) implication, then we can infer: 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 sameif and only if In propositional logic, they match or match. 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 decision process for determining Its require a the domain by any terms of arbitrary complexity. 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. important for any AI Unification is critically 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 savings 1. Individuals with an inadequate to the following criteria: account should always increasing the amount saved the priority, regardless of 2.their income with an adequate savings Individuals account and an adequate income should consider a riskier but potentially more 3.profitable investment inlower income who Individuals with a the stock market. 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 2.dependent. An adequate income must be steady income and supply at least RM15,000 per year plus an additional RM4000 for each Todependent. this advice, we translate these automate guidelines into sentences in the predicate logic. 1.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 29 Ch02 / should be split)

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) 3. The advisor must determines when savings income(inadequate) and income are adequate or inadequate: investment(savings) 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(inadequat e). 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). amount_saved(22000). earnings(25000, steady). dependents(3).

Inorder to perform a consultation, a description of a particular investor is added Whereset of sentences using: minincome(Y) = 15000+(4000*Y) to this

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, dependents(3) earnings(25000,steady) 3/Y} i.e., 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) ) Evaluating the function minincome yielding: income(inadequate). earnings(25000,steady) (dependents(3) greater(25000, 27000) income(inadequate).are true by applying modus Since premises 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) Again, since premises are true by applying savings_account(adequate). 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 conclusiontheinvestment(combination).for this This is is suggested investment 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. predicate logic, but with Prolog is based on 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:

grandfather(joe,fred) was true ?grandfather(joe,fred) yes Ch02 /

father(jim, fred). father(joe, jim). grandfather(X, Y) :- father(X, Z), father(Z, Y). Equivalent to XYZ ( (father(X,Z) father(Z,Y)) We can ask to prove that grandfather(X,Y)) Prolog
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: as predicate and the nouns as Use the verb the arguments Example:
Ahmad likes ice-cream likes(ahmad,ice_cream) Johan loves Sarah loves(johan,sarah) Use logical connective to represent complex Ahmad likes ice-cream likes(ahmad,ice_cream) and chocolate 36 likes(ahmad,chocolate)

statements and its cannot be used within an argument of a predicate. Example:

Ch02 /

Representing Facts in Logic


Atheer is tall and slim tall(atheer) slim(atheer) Statements of the form If X then Y can be Hassan is thirsty then thirsty(hassan) he drinks coffee drinks(hassan,coffee) Malik is thirsty then thirsty(malik) tea Use he drinks coffee or facts that not to represent the drinks(malik,coffee) true/nothing Example: drinks(malik,tea) Safuan doesnt like drinks coffee like(safuan,coffee) Use quantifiers (for all thing) and (there

translated into Example: X Y

exists) Example:

All students study Xstudent(X) study(X) - Thing is a student then that thing will study Someone strange likes likes(brusselsprouts)
37

Ch02 /

Xstrange(X)

Representing Facts in Logic


There is some table that doesnt have 4 legs X(table(X) grey All elephants are snumlegs(X,4)) 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) which is tasty There is no brussel sprout on(X,table)) 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 is used the simple inheritance Predicate logic has to: inference. 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 system understandingsemantics of other simpler Define the 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. uncertaintyrains in Glasgow. It normally - defaults John believes it will rain, but I dont. - beliefs It will get wetter and wetter as you near Glasgow. For complex- time/change 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: object o with slot s and value v we get: For an 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:

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)

Nellies an elephant elephant(nellie)

Ch02 /

41

Logic and Frames Inheritance still works in the logic-based version by applying the inference rule modus ponens: Example: and
Elephant has_part head XY (elephant(X) (head(Y) haspart(X,Y))) Nellies an elephant elephant(nellie) Nellie has a head Y head(Y) haspart(nellie,Y)

to conclude that

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. well defined language Predicate logic provides 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. to just use OO, or to use Current trend is either logic, but specialises non-logic-based languages still exist. Ch02 /
43

You might also like