First Order Logic Introduction to Artificial Intelligence CS440/ECE448 Lecture 10 SECOND HOMEWORK DUE MONDAY
Last lecture • Propositional logic • Syntax and semantics • (Sound) inference rules and procedures This Lecture • First order logic • Syntax and semantics • Fun (?) with sentences • The Wumpus world in first-order logic Reading • Chapter 8
Propositional logic: Syntax • Propositional logic is the simplest logic. • Logical constants TRUE and FALSE are sentences. • Proposition symbols P1, P2 etc. are sentences. • Symbols P1 and negated symbols P1 are called literals. • If S is a sentence, S is a sentence (NOT). • If S1 and S2 is a sentence, S1 S2 is a sentence (AND). • If S1 and S2 is a sentence, S1 S2 is a sentence (OR). • If S1 and S2 is a sentence, S1 S2 is a sentence (Implies). • If S1 and S2 is a sentence, S1 S2 is a sentence (Equivalent).
Model of P Q Propositional logic: Semantics Most sentences are sometimes true (satisfiable). P Q Some sentences are always true (valid). P P Some sentences are never true (unsatisfiable). P P
Propositional Inference: Enumeration Method • Let and KB = ( C) B C) • Is it the case that KB ? • Check all possible models -- must be true whenever KB is true
An Inference Rule: Modus Ponens • From an implication and the premise of the implication, you can infer the conclusion. Premise ___________ Conclusion • An inference rule is sound if the conclusion is true in all cases where the premises are true.
An Inference Rule: And - Elimination • From a conjunction, you can infer any of the conjuncts. 1 2 … n Premise _______________ i Conclusion • An inference rule is sound if the conclusion is true in all cases where the premises are true.
And-Introduction & Double Negation • And-Introduction 1, 2, …, n Premise _______________ 1 2 … n Conclusion • Double Negation Premise _______ Conclusion
Inference in Wumpus World Initial KB Some inferences: Apply Modus Ponens to R1 Add to KB W1,1Æ W2,1Æ W1,2 Apply to this AND-Elimination Add to KB W1,1 W2,1 W1,2 Percept Sentences S1,1 B1,1 S2,1 B2,1 S1,2 B1,2 … Environment Knowledge R1: S1,1 W1,1 W2,1 W1,2 R2: S2,1 W1,1 W2,1 W2,2 W3,1 R3: B1,1 P1,1 P2,1 P1,2 R4: B2,1 P1,1 P2,1 P2,2 P3,1 R5: B1,2 P1,1 P1,2 P2,2 P1,3 ...
First Order Logic
First Order Logic(First Order Predicate Calculus) • Propositional logic had limited ontology: • World consists of facts. • First order logic: • Objects (boxes, people, schools, …); • Relations (above, bigger than, …); • Properties (red, large, stinky, breeze, …); • Functions (father of, best friend, next class, …); • Quantification (every, there exists). • Can express the following: • Squares neighboring the Wumpus are smelly; • Squares neighboring a pit are breezy.
Syntax of FOL: Basic elements Constants Wumpus, 2, UIUC, ... Predicates Brother, >, ... Functions Sqrt, LeftLegOf, ... Connectives Variables x, y, a, b, ... Quantifiers Equality = A legitimate expression of predicate calculus is called a well-formed formula (wff) or, simply, a sentence.
Constant Symbols • A symbol, e.g. Jean, Wumpus, Arrow, GeorgeWBush, JacquesChirac. • Each constant symbol names exactly one object in a universe of discourse, but: • not all objects have symbol names; • some objects have several symbol names. • Usually denoted with upper-case first letter.
Variables • Used to represent objects or properties of objects without explicitly naming the object. • Usually lower case. • For example: • x • father • square
Relation (Predicate) Symbols • A predicate symbol is used to represent a relation in a universe of discourse. • The sentence Relation(Term1, Term2,…) is either TRUE or FALSE depending on whether Relation holds of Term1, Term2,… • To write “Voltaire wrote Candide” in a universe of discourse of names and written works: Wrote(Voltaire, Candide) This sentence is true in the intended interpretation. • Another example: Instructor (CS448, Ponce)
Function Symbols • Functions talk about the binary relation of pairs of objects. • For example, the Father relation might represent all pairs of persons in father-daughter or father-son relationships: • Father(Jane) Refers to the father of Jane • Father(Joe) Refers to Joe’s father • Father(x) Refers to the father of variable x
Atomic sentences Atomic Sentence: predicate(term1, …, termn) or term1 = term2 Term: function (term1, …, termn) or constant or variable For example: Intructor(CS448,Jean) Instructor(CS448, Son(JeanJacques)) Instructor(CS448, Son(x))
Complex sentences Complex sentences are made from atomic sentences using connectives: S S1S2 S1S2 S1 S2 S1 S2 For example: Married (Bill, Hillary) Married (Hillary, Bill) >(1,2) (1,2) >(1,2) >(1,2)
While constant symbols, variables and connectives are like propositional logic, “What are functions and predicates?” The language of logic is based on set theory: • Sets; • Relations; • Functions.
a d b c e Sets • The set of objects defines a “Universe of Discourse.” [Objects are represented by Constant Symbols.] • For example, in this blocks world, the universe of discourse is {a,b,c,d,e}. Interpretation: A a B b C c D d E e
a d b c e Relations • Def: A binary relation is a set of ordered pairs • Example: Consider set of blocks {a,b,c,d,e} • The “on” relation: • on = {<a,b>, <b,c>, <d,e>}. • The predicate On(A,B) can be interpreted as: <a,b> on. • On(A,B) is TRUE, but On(A,C) and On(C,D) are FALSE (in this interpretation).
Relations • Def: A binary relation is a set of ordered pairs. • Note: Binary relations are not necessarily finite sets. • Example: “less than” < < = {<x, y> | x, y N, z N, z 0, x+z = y }. The predicate: <(2, 3) is equivalent to: <2,3> <.
Functions • A function is a binary relation such that no two distinct members have the same first element. • In other words, if F is a function <x,y> F and <x,z> F y=z • If <x,y> F : • x is an argument of F ; • y is the value of F at x ; • y is the image of x under F. • F(x) designates the object y such that y=F(X).
a d b c e Function Example • hat = {<c,b>, <b,a>,<e,d>} • hat (c) = b • hat(b) = a • hat(d) is not defined. • Hat(E) can be interpreted as d.
a d b c e Formalizing Knowledge • The first step in formalizing knowledge is to construct a conceptualization, i.e., a representation of the objects in the world, and their relationships: • Objects – Universe of discourse; • Functions – Functional basis set; • Relations – Relational basis set. • A conceptualization is a triple < U of D, FBS, RBS >. • Blocks World: <{a,b,c,d,e}, {hat, …}, {on, …}>. • Second step is to express conceptualization using first order logic.
a d b c e Formalizing Knowledge II • Second step is to express conceptualization using first order logic. • On(A,B) • On(B,C) • On(D,E) • On(A,Hat(C))
Universal quantification • <variables> <sentence> For all (every) instances of the variables, the <sentence> is true. • Everyone at UIUC is smart: x At (x, UIUC) Smart(x) • x P is equivalent to the conjunction of instantiations of P (i.e., all x’s in universe of discourse). At (Jonathan, UIUC) Smart(Jonathan) At (MarcSnir, UIUC) Smart(MarcSnir) At (BozoTheClown, UIUC) Smart(BozoTheClown) … • Universe of discourse may be infinite, compare to propositional logic.
Universal quantification cont. Typically, is the main connective with A common mistake is to use as the main connective with What does the following mean? x At (x, UIUC) Smart(x) “Everyone is at UIUC and everyone is smart.”
x Bird (x) Fly(x) predicate predicate • The block on top of any block lies on it x On(Hat(x),x) Some more examples • “Birds Fly”
x Bird (x) Fly(x) predicate predicate Some more examples • “Birds Fly” • But what about penguins? x Bird (x)Penguin(x) Fly(x) • “Fish Swim.” x Fish (x) Swim(x)
Existential quantification • <variables> <sentence> There exist instances of the <variables> such that the <sentence> is true. • Someone at Ohio State is smart: x At (x, OhioState) Smart(x) • x P is equivalent to the disjunction of instantiations of P (i.e., all x’s in universe of discourse). At (Rodrigo, OhioState) Smart(Rodrigo) At (Nincompoop, OhioState) Smart(Nincompoop) …
Existential quantification cont. Typically, is the main connective with . A common mistake is to use as the main connective with . x At (x, UIUC) Smart(x) is true if there is anyone who is not at UIUC.