520 likes | 634 Views
Explorations in Artificial Intelligence. Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations (Part 3). 3-First-order Logic. Pros and cons of propositional logic. Propositional logic is declarative
E N D
Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations (Part 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 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) • 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!
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, …
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: fatherOf1; times2; areaOfRectangle2;… • Predicates (relations) • infinite set of predicates or relations constants of all arities; • convention – start with capital letter, with arity as superscript (for now…) • Examples: Large1; Parent2; Clear1;… • Variables --- x, y, a, b,... • Connectives --- , , , , • Equality --- = • Quantifiers --- ,
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 (term1,...,termn) 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
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 |…
First-Order Logic:Semantics Sentences are true with respect to a model and an interpretation Model contains objects (domain elements) and relations among them.
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) constantsymbols→objects in the world predicatesymbols→relations in the world functionsymbols→ functional relations in the world • Domain of interpretation – set of objects to which object constant assignments are made.
Truth in first-order logic On(A,B) False; Clear(B) True; On(C,F1) On(A,b) True (*) we define the relations by the tuples of objects that participate in them
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)
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).
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?
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))]]
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
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.
All variables are bound (x) (P(x) Q(x)) x R(x) Scope of
Semantics:Universal quantification • <variables> <sentence> • 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) ...
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”
Existential quantification • <variables> <sentence> • Someone at Cornell is smart: • x At(x,Cornell) Smart(x) • xP 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) ...
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!
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)
Love Affairs Loves(x,y) x loves y • Everybody loves Jerry • x Loves (x, Jerry) • Everybody loves somebody • x yLoves (x, y) • There is somebody whom somebody loves • yxLoves (x, y) • Nobody loves everybody • x yLoves (x, y) = xyLoves (x, y) • There is somebody whom Lydia doesn’t love • yLoves (Lydia, y)
Love AffairsLoves(x,y) x loves y • There is somebody whom no one loves • y xLoves (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 ((xy) 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?)
Let Q(x,y) denote “xy =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
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)
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,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)
Using FOL • The set domain: • Only sets are empty sets or those made by adjoining something to a set • s Set(s) (s = {} ) (x,s2 Set(s2) s = {x|s2}) • 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,s2} (s = {y|s2} (x = y x s2))] • Subset • s1,s2 s1 s2 (x x s1 x s2) • Equality of sets • s1,s2 (s1 = s2) (s1 s2 s2 s1) • Intersection • x,s1,s2 x (s1 s2) (x s1 x s2) • Uniion • x,s1,s2 x (s1 s2) (x s1 x s2)
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)
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 ”
First-Order Logic:Rules of Inference • Propositional Logic rules of inference generalize to first-order logic. • + • Other inference rules
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
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
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., xCrown(x) OnHead(x,John) yields: • Crown(C1) OnHead(C1,John) • provided C1 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…
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., xCrown(x) OnHead(x,John) yields: • Crown(C1) OnHead(C1,John) • provided C1 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…
Existential Generalization (EG) • P(c) for some element c • (x) P(x) We can conclude (x) P(x), since a particular element c satisfies
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)
Arguments • Argument: • Step Reason • 1x (Info372(x) AI(x)) premise • 2 Info372(Ron) AI(Ron) Universal Instantiation • 3 Infor372(Ron) Premise • 4 AI(Ron) Modus Ponens (2 and 3)
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
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))
Step Reason • 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
Argument: • Step Reason • 1x (Info372(x) AI(x)) premise • 2 Info372(Ron) AI(Ron) Universal Instantiation • 3 Infor372(Ron) Premise • 4 AI(Ron) Modus Ponens (2 and 3)
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.
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)))
Problems withpropositionalization • 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·nk instantiations.
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 αθ = βθ