Download presentation
Presentation is loading. Please wait.
Published byBaldwin Todd Modified over 9 years ago
1
Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations (Part 3)
2
3-First-order Logic
3
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 B 1,1 P 1,2 is derived from meaning of B 1,1 and of P 1,2 Meaning in propositional logic is context-independent –(unlike natural language, where meaning depends on context) Fast solvers for propositional logic 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 –E.g., when we move block B, it is the same block asserted by ON_B_C. In PL atoms are strings that have no internal structure!
4
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, … –Relations: red, round, prime, brother of, bigger than, part of, comes between, … –Functions: father of, best friend, one more than, plus, …
5
Syntax of FOL: Basic elements Object Constants infinite set (convention – they start with a capital letter or numeral); Examples: Aa; 125; Q; EiffelTower Functions Constants infinite set of function constants of all arities; convention – start with lower case letter, with arity as superscript (for now…) Examples: fatherOf 1 ; times 2 ; areaOfRectangle 2 ;… Predicates (relations) infinite set of predicates or relations constants of all arities; convention – start with capital letter, with arity as superscript (for now…) Examples: Large 1 ; Parent 2 ; Clear 1 ;… Variables--- x, y, a, b,... Connectives--- , , , , Equality--- = Quantifiers --- ,
6
Syntax of FOL: Terms and WFFS Terms –An object constant is a term –A variable is a term; –A function constant of arity n, followed by n terms in parentheses and separated by commas (functional expression); – In a nutshell: Term =function (term 1,...,term n ) or constant or variable Examples: fatherOf(John); times(4. plus(3,6)); Sam;… WFFs Atoms: a predicate (or relation) constant of arity n followed by n terms in parentheses and separated by commas is an atom (or atomic formula); an atom is a wff. Note: a predicate or relation of arity 0 omits the parentheses. Examples: GreaterThan(7,2); Q; Wff: any expression formed out of predicate-calculus wffs in the same way as propositional calculus. Examples: [ GreaterThan(7,2) LessThan(15,4)] Brother(John,Sam) P
7
Syntax of FOL Sentence AtomicSentence | (Sentence Connective Sentence) | Quantifier Variable, …. Sentence | Sentence AtomicSentence Predicate(Term) | Term=Term Term Function(Term) | Constant | Variable Connective | | | Quantifiers | Constant A | X1 | John | … Variable a | x | s | … Predicte Before |HasColor | Raining |… Function Mother | LeftLeg |…
8
First-Order Logic: Semantics Sentences are true with respect to a model and an interpretation Model contains objects (domain elements) and relations among them.
9
First-Order Logic: Semantics Worlds Our language allows us to refer to objects in the world as well as to propositions. –Objects - correspond to individuals in the world (concrete or fictional, as long as we give them a name) e.g., BlockA, New-York, 7, ¼, π –Functions on individuals; –Relations or predicates over individuals. Interpretations specify referents for (these assignments are denotations) constant symbols → objects in the world predicate symbols → relations in the world function symbols →functional relations in the world Domain of interpretation – set of objects to which object constant assignments are made.
10
Truth in first-order logic Predicate Calculus World A B C F1 On Clear A B C Floor On={,, }(*) Clear = { } (*) we define the relations by the tuples of objects that participate in them On(A,B) False; Clear(B) True; On(C,F1) On(A,b) True
11
Models for FOL: Example Model with five objects: Richard the LionHeart, king of England (1189-1199); Evil King John, Richard’s brother (1199-1215); The left legs of Richard and John A crown Binary relation Unary relations (or properties) functions LeftLeg(Richard) x King(x) Greedy(x) Evil(x) King(John) Brother(Richard,John)
12
First-order logic: Models and Related Notions Satisfiability –An interpretation satisfies a wff if the wff has the value True under that interpretation. Model –An interpretation that satisfies a wff is a model of that wff. Validity –Any w wff that has the value True under all the interpretations is valid. Inconsistency –Any wff that does not have a model is inconsistent or unsatisfiable. Entailment –If a wff ω has a value True under all of those interpretations for which each of the wffs in a set Δ has the value True, then Δ logically entails ω Equivalence –Two wffs are equivalent iff their truth values are identical under all interpretations (i.e., if they logically entail one another).
13
First Order Logic: Variables and Quantification How would we say that every block in the world has a property – say “clear” We would have to say: Clear(A); Clear(B); … for all the blocks… (it may be long or worse we may have an infinite number of blocks…) What do we need: Variable symbols – convention – use lower case letters p, p1, q, … Quantifiers: Universal quantifier ( x) P(x) P(x) is true for all the values x in the universe of discourse When is it true? When is it false? Existential quantifier ( x)[P(x) there exists an element x in the universe of discourse such that P(x) is true. When is it true? When is it false?
14
Quantified formulas If ω is a wff and x is a variable symbol, then both (x) ω and (x) ω are wffs. x is the variable quantified over; ω is said to be within the scope of the quantifier if all the variables in ω are quantified over in ω, we say that we have a closed wff or closed sentence. Example: ( x) [P(x) R(x)]; ( x)[P(x) (( y) [R(x,y) S(f(x))]]
15
Quantified formulas Note 1: as we will see ( x)[( y)ω] is equivalent to ( y)[( x)ω]; We can also put all the quantified variables together, i.e., ( x,y)ω. When all the quantified variables are together, before ω, we call ω the matrix Note 2: The order of quantifiers is important! Note 3: the variables of quantifiers are “dummy” variables – we can rename them without changing the value of the wff. Note 4: quantifying over variables makes the first-order logic very powerful – why not quantify over predicate symbols or functions symbols? Not in the version of predicate calculus we are using – that is why we called it first-order logic; second- and higher-order predicate calculi allow quantification over relation and function symbols. Problem – much more complex inference mechanisms
16
Binding Variables Binding variables: When a quantifier is used on a variable x or when we assign a value to this variable, we say that this occurrence of the variable is bound. An occurrence of a variable that is not bound by a quantifier or set equal to a particular variable is free. All the variables that occur in a propositional function must be bound to turn it into a proposition (done by combination of universal and existential quantifiers and value assignments). The part of a logical expression to which a quantifier is applied is called the scope of the quantifier; A variable is free if it is outside the scope of all the quantifiers in the formula that specifies this variable.
17
Scope of All variables are bound ( x) (P(x) Q(x)) x R(x)
18
Semantics: Universal quantification x P is true in a model m iff P is true with x being each possible object in the model --- we refer to the domain of x as the universe of discourse. Everyone at Cornell is smart: x At(x,Cornell) Smart(x) Roughly speaking, equivalent to the conjunction of instantiations of P At(Mary,Cornell) Smart(Mary) At(Richard,Cornell) Smart(Richard) At(John,Cornell) Smart(John) ...
19
A common mistake to avoid Typically, is the main connective with Common mistake: using as the main connective with : x At(x,Cornell) Smart(x) means “Everyone is at Cornell and everyone is smart”
20
Existential quantification Someone at Cornell is smart: x At(x,Cornell) Smart(x) x P is true in a model m iff P is true with x being some possible object in the model Roughly speaking, equivalent to the disjunction of instantiations of P At(John,Cornell) Smart(John) At(Mary,Cornell) Smart(Mary) At(Richard,Cornell) Smart(Richard) ...
21
Another common mistake to avoid Typically, is the main connective with Common mistake: using as the main connective with : x At(x,Cornell) Smart(x) is true if there is anyone who is not at Cornell!
22
Properties of quantifiers x y is the same as y x x y is the same as y x x y is not the same as y x x y Loves(x,y) –“There is a person who loves everyone in the world” y x 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) x Likes(x,Broccoli)
23
Love Affairs Loves(x,y) x loves y Everybody loves Jerry x Loves (x, Jerry) Everybody loves somebody x y Loves (x, y) There is somebody whom somebody loves y x Loves (x, y) Nobody loves everybody x y Loves (x, y) = x y Loves (x, y) There is somebody whom Lydia doesn’t love y Loves (Lydia, y)
24
Love Affairs Loves(x,y) x loves y There is somebody whom no one loves y x Loves (x, y) There is exactly one person whom everybody loves y( x Loves(x,y) z(( w Loves (w,z) z=y)) There are exactly two people whom Lynn Loves x y ((x y) Loves(Lynn,x) Loves(Lynn,y) z( Loves (Lynn,z) (z=x z=y))) Everybody loves himself or herself x Loves(x,x) There is someone who loves no one besides herself or himself x y Loves(x,y) (x=y) (note biconditional – why?)
25
Let Q(x,y) denote “x y =0”; consider the domain of discourse the real numbers What is the truth value of a) y x Q(x,y)? b) x y Q(x,y)? False True
26
StatementWhen TrueWhen False x y P(x,y) y x P(x,y) P(x,y) is true for every pair There is a pair for which P(x.y) is false x y P(x,y) For every x there is a y for which P(x,y) is true There is an x such that P(x,y) is false for every y. x y P(x,y) There is an x such that P(x,y) is true for every y. For every x there is a y for which P(x,y) is false x y P(x,y) y x P(x,y) There is a pair x, y for which P(x,y) is true P(x,y) is flase fo every pair x,y.
27
Negation Equivalent Statement When is the negation True When is False x P(x) x P(x) For every x, P(x) is false There is an x for which P(x) is true. x P(x) x P(x) There is an x for which P(x) is false. For every x, P(x) is true.
28
There is an honest politician x H(x) Where H(x) denotes: x is honest. (universe of discourse consists of all the politicians) Negation x H(x) x H(x) (Every politician is dishonest) All Americans eat cheeseburgers x C(x) C(x) denotes: x eats cheeseburgers Negation x C(x) x C(x) (Some American does not eat cheeseburgers)
29
Equality term 1 = term 2 is true under a given interpretation if and only if term 1 and term 2 refer to the same object E.g., definition of Sibling in terms of Parent: x,y Sibling(x,y) [ (x = y) m,f (m = f) Parent(m,x) Parent(f,x) Parent(m,y) Parent(f,y)]
30
Using FOL The kinship domain: Brothers are siblings x,y Brother(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)
31
Using FOL The set domain: Only sets are empty sets or those made by adjoining something to a set s Set(s) (s = {} ) ( x,s 2 Set(s 2 ) s = {x|s 2 }) The empty set has no element adjoined to it x,s {x|s} = {} Adjoining an element already in the set has no effect x,s x s s = {x|s} Only elements have been adjoined to it x,s x s [ y,s 2 } (s = {y|s 2 } (x = y x s 2 ))] Subset s 1,s 2 s 1 s 2 ( x x s 1 x s 2 ) Equality of sets s 1,s 2 (s 1 = s 2 ) (s 1 s 2 s 2 s 1 ) Intersection x,s 1,s 2 x (s 1 s 2 ) (x s 1 x s 2 ) Uniion x,s 1,s 2 x (s 1 s 2 ) (x s 1 x s 2 )
32
Interacting with FOL KBs Substitution: Given a sentence S and a substitution σ, Sσ denotes the result of plugging σ into S; e.g., S = Smarter(x,y) σ = {x/Hillary,y/Bill} Sσ = Smarter(Hillary,Bill)
33
Knowledge engineering in FOL Identify the task Assemble the relevant knowledge Decide on a vocabulary of predicates, functions, and constants Encode general knowledge about the domain Encode a description of the specific problem instance Pose queries to the inference procedure and get answers Debug the knowledge base “The big problem of AI is what to say not how to say it but ”
34
First-Order Logic: Rules of Inference Propositional Logic rules of inference generalize to first-order logic. + Other inference rules
35
Universal instantiation (UI) Every instantiation of a universally quantified wff is entailed by it: ( x) P(x) P(c) for any variable v and ground term g E.g., ( x) (King(x) Greedy(x) Evil(x) )yields: King(John) Greedy(John) Evil(John) King(Richard) Greedy(Richard) Evil(Richard) King(Father(John)) Greedy(Father(John)) Evil(Father(John))..We conclude that P(c) is true, where c is a particular member of the universe of discourse, given the premise ( x) P(x). Example – All women are wise – Mary is wise; x can be John or Richard or Father of John
36
Universal Generalization (UG) Every instantiation of a universally quantified wff is entailed by it: P(c) for an arbitrary c ( x) P(x) E.g., King(x).. x can be John or Richard or Father of John, they are all Kings
37
Existential instantiation (EI) For any wff α, variable v, and constant symbol k that does not appear elsewhere in the knowledge base: v α Subst({v/k}, α) E.g., x Crown(x) OnHead(x,John) yields: Crown(C 1 ) OnHead(C 1,John) provided C 1 is a new constant symbol, called a Skolem constant This rule allows us to conclude that there is an element c in the universe of discourse for which P(c) is true if we know x P(x) is true; We cannot select it arbitrarily though… we may give it a name that does and continue our argument…
38
Existential instantiation (EI) (x) P(x) P(k) for some element k (we use a symbol k that does not appear elsewhere in the knowledge base) E.g., x Crown(x) OnHead(x,John) yields: Crown(C 1 ) OnHead(C 1,John) provided C 1 is a new constant symbol, called a Skolem constant This rule allows us to conclude that there is an element c in the universe of discourse for which P(c) is true if we know x P(x) is true; We cannot select it arbitrarily though… we may give it a name that does and continue our argument…
39
Existential Generalization (EG) P(c) for some element c (x) P(x) We can conclude (x) P(x), since a particular element c satisfies
40
( x) P(x) P(c) Universal Instantiation P(c) for an arbitrary c ( x) P(x) Universal Generalization (x) P(x) P(c) for some element c Existential Instantiation P(c) for some element c (x) P(x) Existential Generalization
41
Example: Let Info372(x) denote: x is taking Info 372 class Let AI(x) denote: x has taken a course in AI Consider the premises x (Info372(x) AI(x)) Info372(Ron) We can conclude AI(Ron)
42
Arguments Argument: StepReason 1 x (Info372(x) AI(x))premise 2 Info372(Ron) AI(Ron)Universal Instantiation 3 Infor372(Ron)Premise 4 AI(Ron)Modus Ponens (2 and 3)
43
Example Show that the premises: 1- A student in this class has not read the textbook; 2- Everyone in this class passed the first homework Imply Someone who has passed the first homework has not read the textbook
44
Example Solution: Let C(x) x is in this class; T(x) x has read the textbook; P(x) x passed the first homework Premises: x (Cx T(x)) x (C(x) P(x)) Conclusion: we want to show x (P(x) T(x))
45
StepReason 1 x (Cx T(x)) premise 2 C(a) T(a)Existential Instantiation from 1 3 C(a)Simplification 2 4 x (C(x) P(x)) Premise 5 C(a) P(a) Universal Instanstiation from 4 6 P(a)Modus ponens from 3 and 5 7 T(a)Simplification from 2 8 P(a) T(a) Conjunction from 6 and 7 9 x P(x) T(x) Existential generalization from 8
46
Argument: StepReason 1 x (Info372(x) AI(x))premise 2 Info372(Ron) AI(Ron)Universal Instantiation 3 Infor372(Ron)Premise 4 AI(Ron)Modus Ponens (2 and 3)
47
Reduction to propositional inference Suppose the KB contains just the following: x King(x) Greedy(x) Evil(x) King(John) Greedy(John) Brother(Richard,John) Instantiating the universal sentence in all possible ways, we have: King(John) Greedy(John) Evil(John) King(Richard) Greedy(Richard) Evil(Richard) King(John) Greedy(John) Brother(Richard,John) The new KB is propositionalized: proposition symbols are King(John), Greedy(John), Evil(John), King(Richard), etc.
48
Reduction contd. Every FOL KB can be propositionalized so as to preserve entailment (A ground sentence is entailed by new KB iff entailed by original KB) Idea: propositionalize KB and query, apply resolution, return result Problem: with function symbols, there are infinitely many ground terms, –e.g., Father(Father(Father(John)))
49
Problems with propositionalization Propositionalization seems to generate lots of irrelevant sentences. E.g., from the KB: x King(x) Greedy(x) Evil(x) King(John) y Greedy(y) Brother(Richard,John) it seems obvious that Evil(John), but propositionalization produces lots of facts such as Greedy(Richard), that are irrelevant With p k-ary predicates and n constants, there are p · n k instantiations.
50
We can get the inference immediately if we can find a substitution θ such that King(x) and Greedy(x) match King(John) and Greedy(y) θ = {x/John,y/John} works Unify(α,β) = θ if αθ = βθ
51
Inference in First-Order Logic Unification Generalized Modus Ponens Forward chaining Backward chaining Resolution More advanced… CS 472 How to perform substitution of variables, e.g., to perform resolution?
52
Summary First-order logic: –objects and relations are semantic primitives –syntax: constants, functions, predicates, equality, quantifiers Increased expressive power: sufficient to define wumpus world … but it’s much harder the Propositional Logic – in theory and in practice…
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.