830 likes | 846 Views
This chapter provides an introduction to First Order Logic (FOL), also known as predicate calculus, focusing on its syntax, semantics, and use in knowledge engineering. It discusses the pros and cons of FOL compared to propositional logic and provides examples of FOL models and syntax elements.
E N D
Introduction to Artificial Intelligence Chapter 08 First Order Logic (FOL) aka. predicate calculus
Outline • Why FOL? • Syntax and semantics of FOL • Using FOL • Wumpus world in FOL • Knowledge engineering in FOL
Pros and Cons of Propositional Logic Propositional logic is declarative Propositional logic allows partial/disjunctive/negated information • (unlike most data structures and databases) • Propositional logic is compositional: • meaning of B1,1 P1,2 is derived from meaning of B1,1 and of P1,2 Meaning in propositional logic is context-independent • (unlike natural language, where meaning depends on context) Propositional logic has very limited expressive power • (unlike natural language) • e.g., cannot say "pits cause breezes in adjacent squares " except by writing one sentence for each square
First-order logic • Whereas propositional logic assumes the world contains facts, first-order logic (like natural language) assumes the world contains • Objects: people, houses, numbers, colors, baseball games, wars, … squares, pits, wumpuses • Relations among objects : red, round, prime, brother of, bigger than, part of, comes between, is breezy, is adjacent to, shoots (it can be unary relations or properties, or n-ary relations) … • Functions: father of, best friend, one more than, plus, (relations in which there is only one “value” for a given “input”) …
Any assertion can be thought of as referring to objects and properties or relations. • For example: • “One plus two equals three.” • Objects: one, two, three, one plus two. • Relation: equals; • Functions: plus. • (“one plus two” is a name for the object that is obtained by applying the function “plus” to the objects “one” and “two”. “Three” is another name for this object.) • “Squares neighboring the Wumpus are smelly.” • Objects: Wumpus, squares; • Properties: smelly; is breezy, • Relation: neighboring.
Any assertion can be thought of as referring to objects and properties or relations. • For example: • “Evil King John ruled England in 1200.” • Objects: John, England. • Relation: ruled; • Properties: evil, king.
Figure 8.1 Formal languages and their ontological and epistemological commitments.
What is the models of a logical language: The models of a logical language are the formal structures that constitute the possible worlds under consideration. Each model links the vocabulary of the logical sentences to elements of the possible world, so that the truth of any sentence can be determined.
Models for first-order logic: • The domain of a model is the set of objects (or domain elements) it contains. • The relations are the sets of tuples of objects that are related. • (A tuple is a collection of objects arranged in a fixed order and is written with angle brackets surrounding the objects.) • For example, in this model, the brotherhood relation in this has the set • {<Richard the Lionheart, King John>, <King John, Richard the Lionheart>}. • “on head” relation contains <the crown, King John> • The property of “person” is true of both <Richard> and <John>. i.e., person(Richard the Lionheart), person(John). • The property of “king” is true only of John. i.e., King(John) • The property of “crown” is true only of the crown. • The unary “left-leg” function which has two mappings: • < Richard the Lionheart> Richard’s left leg • <King John> John’s left leg
Models for FOL: Example Figure 8.2: A model containing five objects, two binary relations, three unary relations(indicated by labels on the objects), and one unary function, left-leg.
Syntax of FOL: Basic elements • Constants Richard, John, 1, 2, 3, squares, pits, wumpuses, ... • Predicates Brother, OnHead, Person, King, Crown, neighboring, smelly, isBreezy, greater, equal, less than, >,... • Functions Sqrt, LeftLegOf,... • Variables x, y, a, b,... • Connectives ∧, ∨, ⇒, , , • Equality = • Quantifiers ,
Models for first-order logic: • The domain of a model is the set of objects (or domain elements) it contains. • The relations are the sets of tuples of objects that are related. • The unary “left-leg” function which has two mappings: • < Richard the Lionheart> Richard’s left leg • <King John> John’s left leg • An interpretation that specifies exactly which objects, relations and function are referred to by the constant, predicate, and function symbols. • Possible interpretation for our example: • Maps Richard to Richard the Lionheart and John to the evil King John. • Brother refers to the brotherhood relation. • OnHead refers to the “on head” relation that holds between he crown and King John. • Person, King and Crown refers to the set of objects that are persons, kings and crowns.
In Figure 8.2, there are five objects in the model, two binary relations, three unary relations(indicated by labels on the objects), and one unary function, left-leg. There are five objects in the model, namely, Brother, OnHead, Person, King and Crown, which are predicate symbols. So there are 25 possible interpretations, just for the constant symbols, Richard and John. (52 )
Summary • The basic syntactic elements of FOL are the symbols that stand for objects, relations, and functions. • Constant symbols stand for objects, e.g., Richard, John • Predicate symbols stand for relations, • e.g., Brother, OnHead, Person, King, and Crown • Function symbols stand for functions, e.g., LeftLeg • A model includes objects, symbols, and an interpretation which objects, relations, and functions are referred to by the constant, predicate and function symbols. • The intended interpretation is as follows: • Richard refers to Richard the Lionheart and John refers to the evil King John. • Brother refers to the brotherhood relation, • {<Richard the Lionheart, King John>, <King John, Richard the Lionheart>}. • OnHeadrefers to the “on head” relation that holds between he crown and King John; • Person, King, and Crown refer to the sets of objects that are persons, kings, and crowns. • LeftLeg refers to the “left leg” function, that is the mapping • <Richard the Lionheart> Richard’s left leg and <King John> John’s left leg.
First-Order Logic (FOL) Syntax • User defines these primitives: • Constant symbols (i.e., the "individuals" in the world) • e.g., Richard, John, Mary, 3 • Function symbols (mapping individuals to individuals) • e.g., left_leg(John) = John’s left leg, father-of(Mary) = John, • color-of(Sky) = Blue • Predicate symbols (mapping from individuals to truth values) • e.g., brother(Richard, John), onHead(the crown, King John), • person(John), king(John), crown(the crown), greater(5,3), • green(Grass), color(Grass, Green) …
∧, ∨, ⇒, , , , First-Order Logic (FOL) Syntax (specified in Backus-Naur form) • The syntax of the FOL with equality, • Connectives: not (), equal (=), and (∧), or (∨), implies (⇒), if and only if () • Variable | x | y | … • Constant John | crown | A | 3 | … • Predicate true | false | after | raining | loves | … • Function Mother | FatherOf | Leftleg | … • Quantifiers Universal () | Existential () Operator precedences are specified, from highest to lowest. The precedence of quantifiers is such that a quantifier holds over everything to the right of it.
∧, ∨, ⇒, , , , First-Order Logic (FOL) Syntax (specified in Backus-Naur form) • The syntax of the FOL with equality, • Term Function(Term, …) | Constant | Variable • AtomicSentence Predicate | Predicate(Term, …) | Term = Term • Sentence AtomicSentence | ComplexSentence • ComplexSentence ( Sentence ) | [ Sentence ] | Sentence | Sentence ∧ Sentence | Sentence ∨ Sentence | Sentence ⇒ Sentence | Sentence Sentence | Quantifier Variable, … Sentence
∧, ∨, ⇒, , , , First-Order Logic (FOL) Syntax (specified in Backus-Naur form) • The syntax of the FOL with equality, • Term Function(Term, …) | Constant | Variable • Function(Term) is a Term. • LeftLeg(John) for the expression of an object “King John’s left leg”. This does not a “subroutine call” that “returns a value.” • The formal semantics of terms is: • The terms refers to objects in the domain of Termi‘s each of which is di. The function symbol Function refers to some function in the model which takes the argument terms. The value of the function Function refers to the term as a whole.
First-Order Logic (FOL) Syntax (specified in Backus-Naur form) ∧, ∨, ⇒, , , , • AtomicSentence Predicate | Predicate(Term, …) | Term = Term • Predicate symbols refers to relations. AtomicSentence states the facts • Brother(Richard, John) states under the intended interpretation that Richard the Lionheart is the brother of King John. • Pit(AtLocation(i, j)) • Atomic sentence can have complex terms as arguments, such as, • Married(Father(Richard), Mother(John)) • isBreezy(agent (AtLocation(i, j)), pit(AtLocation(i, j+1)) • An atomic sentence is true in a given model if the realtion referred to by the predicate symbol holds among the objects referred to by the arguments.
Complex sentences • Complex sentences are made from atomic sentences using connectives S, S1 S2, S1 S2, S1 S2, S1S2, E.g. Sibling(King John, Richard) Sibling(Richard, King John) Brother(LeftLeg(Richard), John) Brother(Richard, John) Brother(John, Richard) King(Richard) King(John) King(Richard) King(John) These sentences are true in the model under our intended interpretation.
∧, ∨, ⇒, , , , Translating English to FOL • Every gardener likes the sun. (x) gardener(x) ⇒ likes(x, Sun) • You can fool some of the people all of the time. (x)(t) (person(x) ∧ time(t)) ⇒ can-fool(x, t) • You can fool all of the people some of the time. (x)(t) (person(x) ∧ time(t)) ⇒ can-fool(x, t) • All purple mushrooms are poisonous. (x) (mushroom(x) ∧ purple(x)) ⇒ poisonous(x)
∧, ∨, ⇒, , , , Translating English to FOL • No purple mushroom is poisonous. (x) purple(x) ∧ mushroom(x) ∧ poisonous(x) or, equivalently, (x) (mushroom(x) ∧ purple(x)) ⇒ poisonous(x) • There are exactly two purple mushrooms. (x)(y) mushroom(x) ∧ purple(x) ∧ mushroom(y) ∧ purple(y) ∧ (x=y) ∧ (z) (mushroom(z) ∧ purple(z)) ⇒ ((x=z) ∨ (y=z)) • Deb is not tall. tall(Deb) • X is above Y if X is directly on top of Y or else there is a pile of one or more other objects directly on top of one another starting with X and ending with Y. (x)(y) above(x, y) (on(x, y) ∨ (z) (on(x, z) ∧ above(z, y)))
∧, ∨, ⇒, , , , The universally quantified sentence x King(x) ⇒ Person(x) is true in the original model if the sentence King(x) ⇒ Person(x) is true under each of the five extended interpretations: x Richard the Lionheart, x King John, x Richard’s left leg x John’s left leg x the crown That is, the universally quantified sentence is equivalent to asserting the following sentences: Richard the Lionheart is a king ⇒ Richard the Lionheart is a person King John is a king ⇒ King John is a person Richard’s left leg is a king ⇒ Richard’s left leg is a person John’s left leg is a king ⇒ John’s left leg is a person The crown is a king ⇒ the crown is a person
Truth in first-order logic • Sentences are true with respect to a model and an interpretation • Model contains objects (domain elements of a model) and relations among them • Interpretation specifies referents for constant symbols → objects John → King John predicate symbols → relationsMary, John →Spouse function symbols → functional relationsJohn, Left-leg →Left_leg • An atomic sentence predicate(term1, ..., termn) is true iff the objectsreferred to by term1, ..., termn are in the relation referred to by predicate
Quantifiers • Universal quantification corresponds to conjunction ("and" (∧)) in that (x)P(x) means that P holds for all values of x in the domain associated with that variable. • e.g., (x) dolphin(x) ⇒ mammal(x) • Existential quantification corresponds to disjunction ("or“(∨)) in that (x)P(x) means that P holds for some value of x in the domain associated with that variable. • e.g., (x) mammal(x) ∧ lays-eggs(x) • Universal quantifiers are usually used with "implies“(⇒) to form "if-then rules." • e.g., (x) cs380-student(x) ⇒ smart(x) means "All cs380 students are smart." • You rarely use universal quantification to make blanket statements about every individual in the world: (x)cs380-student(x) ∧ smart(x) meaning that everyone in the world is a cs380 student and is smart. (A common mistake!)
Universal quantification • <variables> <sentence> Everyone at Google is smart: x At(x, Google) Smart(x) • x P is true in a model miffP is true with x being each possible object in the model • Roughly speaking, equivalent to the conjunction of instantiations of P At(KingJohn, England) Smart(KingJohn) At(Richard, England) Smart(Richard) At(England, England) Smart(England) ...
A common mistake to avoid Typically, is the main connective with • Common mistake: using as the main connective with : x At(x, Google) Smart(x) means “Everyone is at Google and everyone is smart” • A good sentence: x At(x, Google) ⇒Smart(x) means all person in Google are smart.
∧, ∨, ⇒, , , , Quantifiers • Existential quantifiers are usually used with "and" to specify a list of properties or facts about an individual. • e.g., (x) cs380-student(x) ∧ smart(x) means "there is a cs380 student who is smart." • A common mistake is to represent this English sentence as the FOL sentence: • (x) cs380-student(x) ⇒ smart(x) • Switching the order of universal quantifiers does not change the meaning: (x)(y)P(x, y) is logically equivalent to (y)(x)P(x, y). Similarly, you can switch the order of existential quantifiers. • Switching the order of universals and existential does change meaning: • Everyone likes someone: (x)(y)likes(x, y) • Someone is liked by everyone: (y)(x)likes(x, y)
Another common mistake to avoid • Typically, is the main connective with • Common mistake: using as the main connective with : x At(x, Google) Smart(x) is true if there is anyone who is not at Google!
Properties of quantifiers • x y is the same as yx • x y is the same as yx • x y is not the same as yx • x y Loves(x, y) • “There is a person who loves everyone in the world” • yx Loves(x,y) • “Everyone in the world is loved by at least one person” • Quantifier duality: each can be expressed using the other • x Likes(x, IceCream) x Likes(x, IceCream) • x Likes(x, Broccoli) xLikes(x, Broccoli)
∧, ∨, ⇒, , , , Because is a conjunction over the universe of objects and is a disjunction, They obey De Moran’s rules: x P x P x P x P (P ∨ Q) P ∧ Q (P ∧ Q) P ∨ Q (P ∧ Q) ) (P ∨ Q))
Equality Use the equality symbol to signify that two terms refer to the same object. Father(John) = Henry It says that the object referred to by Father(John) and the object referred to by Henry ae the same. Use the equality symbol to state facts. Use with negation to insist that two terms are not the sameobjects. x, y Brother(x, Richard) ∧ Brother(y, Richard)) ∧ (x = y) which state that Richard has at least two brothers. The following sentence does not have he intended meaning. x, y Brother(x, Richard) ∧ Brother(y, Richard))
∧, ∨, ⇒, , , , First-Order Logic (FOL) Syntax… • Sentences are built up of terms and atoms: • A term (denoting a real-world object) is a constant symbol, a variable symbol, or a function e.g. left-leg-of ( ). For example, x and f(x1, ..., xn) are terms, where each xi is a term. • An atom (which has value true or false) is either an n-place predicate of n terms, or, if P and Q are atoms, then ~P, P V Q, P ∧ Q, P ⇒ Q, P Q are atoms • A sentence is an atom, or, if P is a sentence and x is a variable, then (x)P and (x)P are sentences • A well-formed formula (wff) is a sentence containing no "free“ variables. i.e., all variables are "bound" by universal or existential quantifiers. • e.g., (x)P(x, y) has x bound as a universally quantified variable, but y is free.
Equality • term1 = term2is true under a given interpretation if and only if term1and term2refer to the same object • e.g., definition of Sibling in terms of Parent: x,ySibling(x, y) [(x = y) m, f (m = f) Parent(m, x) Parent(f, x) Parent(m,y) Parent(f,y)]
Using FOL The kinship domain: • Brothers are siblings x,yBrother(x, y) Sibling(x, y) • One's mother is one's female parent m, c Mother(c) = m (Female(m) Parent(m,c)) • “Sibling” is symmetric x, y Sibling(x, y) Sibling(y, x)
Using FOL The set domain: • s Set(s) (s = {} ) (x, s2 Set(s2) s = {x | s2}) • x, s {x|s} = {} • x, s x s s = {x | s} • x, s x s [ y, s2(s = {y | s2} (x = y x s2))] • s1, s2 s1 s2 (x x s1 x s2) • s1, s2 (s1 = s2) (s1 s2 s2 s1) • x, s1, s2 x (s1 s2) (x s1 x s2) • x, s1,s 2 x (s1 s2) (x s1 x s2)
Automated inference for FOL • Automated inference using FOL is harder than PL • Variables can potentially take on an infinite number of possible values from their domains • Hence there are potentially an infinite number of ways to apply the Universal Elimination rule of inference • Godel's Completeness Theorem says that FOL entailment is only semidecidable • If a sentence is true given a set of axioms, there is a procedure that will determine this • If the sentence is false, then there is no guarantee that a procedure will ever determine this —i.e., it may never halt
∧, ∨, ⇒, , , , , ⊢I Generalized Modus Ponens • Modus Ponens • P, P ⇒ Q ⊨ Q • Generalized Modus Ponens (GMP) extends this to rules in FOL • Combines And-Introduction, Universal-Elimination, and Modus Ponens, e.g., • from P(c) and Q(c) and x P(x) ∧ Q(x) ⇒ R(x) derive R(c) • Need to deal with • more than one condition on left side of rule • variables
∧, ∨, ⇒, , , , , ⊢I Generalized Modus Ponens • General case: Given • atomic sentences P1, P2, ..., PN • implication sentence (Q1∧ Q2∧ ... ∧ QN) ⇒ R • Q1, ..., QN and R are atomic sentences • substitution subst(θ, Pi) = subst(θ, Qi) for i=1,...,N • Derive new sentence: subst(θ, R) • Substitutions • subst(θ, α) denotes the result of applying a set of substitutions defined by θ to the sentence α • A substitution list θ = {v1/t1, v2/t2, ..., vn/tn} means to replace all occurrences of variable symbol vi by term ti • Substitutions made in left-to-right order in the list • subst({x/Cheese, y/Mickey}, eats(y, x)) = eats(Mickey, Cheese)
Unification • Unification is a "pattern matching" procedure that takes two atomic sentences, called literals, as input, and returns "failure" if they do not match and a substitution list, Theta, if they do match. • i.e., unify(p, q) = Theta means subst(Theta, p) = subst(Theta, q) for two atomic sentences p and q. • Theta is called the most general unifier (mgu) • All variables in the given two literals are implicitly universally quantified • To make literals match, replace (universally quantified) variables by terms
Unification algorithm procedure unify(p, q, θ) Scan p and q left-to-right and find the first corresponding terms where p and q “disagree” (i.e., p and q not equal) If there is no disagreement, return θ (success!) Let r and s be the terms in p and q, respectively, where disagreement first occurs If variable(r) then { Let θ = union(θ, {r/s}) Return unify(subst(θ, p), subst(θ, q), θ) } else if variable(s) then { Let θ = union(θ, {s/r}) Return unify(subst(θ, p), subst(θ, q), θ) } else return “Failure” end
Unification • Examples
Unification • Unify is a linear time algorithm that returns the most general unifier (mgu), i.e., a shortest length substitution list that makes the two literals match. • (In general, there is not a unique minimum length substitution list, but unify returns one of them.) • A variable can never be replaced by a term containing that variable. For example, x/f(x) is illegal. • This "occurs check" should be done in the above pseudocode before making the recursive calls.
More Unification Examples • Make sentences look alike. • Unify p(a, X) and p(a, b) • Unify p(a, X) and p(Y, b) • Unify p(a, X) and p(Y, f(Y)) • Unify p(a, X) and p(X, b) • Unify p(a, X) and p(Y, b) • Unify p(a, b) and p(X, X)
More Unification Examples • Unify p(a, X) and p(a, b) • answer: X/b p(a, b) • Unify p(a, X) and p(Y, b) • answer: Y/a, X/b p(a,b) • Unify p(a, X) and p(Y, f(Y)) • answer: Y/a, X/f(a) p(a, f(a))
More Unification Examples • Unify p(a, X) and p(X, b) • failure. θ is undefined for X/a and Y/b are not well defined. • Unify p(a, X) and p(Y, b) • answer: Y/a, X/b p(a, b) • Unify p(a, b) and p(X, X) • Failure. θ is undefined for a variable X cannot replace by a and b., i.e., X/a and X/b • Unify p(X, f(Y), b) and P(X, f(b), b) • answer: Y/b this is an mgu • X/b, Y/b this in not an mgu • X can be referred to different mgu.
Most General Unifier (mgu) • If s is any unifier of expressions E and g is the most general unifier of E, then for s applied to E there exists another unifier s’ such that subst(s, E) = subst(s’, subs(g, E)). • Basic idea: Commit a variable to an expression only if you have to; keep it as general as possible.
A statement is in conjunctive normal form if it is a conjunction (sequence of ANDs) consisting of one or more conjuncts, each of which is a disjunction (OR) of one or more literals (i.e., statement letters and negations of statement letters. Examples of conjunctive normal forms (CNF) include A • (A ˅ B) ˄ (A ˅ C) • A ˅ B • A ˄ (B ˅ C)