470 likes | 729 Views
First Order Logic. CS 171/271 (Chapters 8 and 9) Some text and images in these slides were drawn from Russel & Norvig’s published material. Propositional Logic Limitations. Stating similar facts is cumbersome Can’t make generalizations
E N D
First Order Logic CS 171/271 (Chapters 8 and 9) Some text and images in these slides were drawn fromRussel & Norvig’s published material
Propositional Logic Limitations • Stating similar facts is cumbersome • Can’t make generalizations • The world (in propositional logic) contains facts, not objects • Natural language deals with objects (nouns) and relations (verbs), hence is more expressive • Ontological commitment of PL is limited
First Order Logic • World consists of • Objects • Relations • Functions • Sentences are made up of • Symbols: for constant objects, predicates, and functions • Connectives: as in PL • Quantifiers and variables: x, y
FOL Syntax • Sentence • Atomic Sentence • ( Sentence Connective Sentence ) • Sentence • Quantifier Variable Sentence • Atomic Sentence • Predicate-Symbol( Term, … ) • Term = Term
FOL Syntax • Term (refers to an object) • Function-Symbol( Term, … ) • Constant-Symbol • Variable • Connective: , , , , • Quantifier: , • Variable: x, y, z, …
Symbols • Constants: John, Richard, C, L1, L2 • Predicates: • Person={John, Richard} • King={Richard} • Crown={C} • Brother={(John,Richard),(Richard,John)} • OnHead={(C,Richard)} • Functions: • LeftLeg={(Richard->L1),(John->L2)}(strictly speaking, the function should be total)
Models and Interpretations • A model in FOL consists of the objects (domain elements) and relations (including functions) • See example diagram • “conceptual” view of world • An interpretation associates the symbols to the objects, relations, and functions in the model • Number of interpretations for a given set of symbols is combinatorially explosive
Semantics • Truth of a sentence in FOL: • Determined with respect to a model and an interpretation • Analogous notions for entailment, validity, and satisfiability • Model enumeration is impractical in FOL
Sample Sentences • Person(John) Person(Richard) • OnHead(C, John) • LeftLeg(John) = L1 LeftLeg(Richard) = L1 • Richard, and LeftLeg(John) are examples of terms(a term is an expression that refers to an object) • Atomic Sentences: constructed by equating terms (=) or by a predicate (with terms as arguments) • Complex Sentences: sentences with connectives
Quantifiers • Universal Quantification • x P is true in a model m iff P is true with x being each possible object in the model • A conjunction of instantiations • Existential Quantification • x P is true in a model m iff P is true with x being some object in the model • A disjunction of instantiations
Sample SentencesUsing Quantifiers • x King(x) Person(x) • x Crown(x) OnHead(x,John) • “John has a crown on his head” • xy Brother(x,y) Brother(y,x) • xy Brother(x,Richard) Brother(y,Richard) (x=y) • “Richard has at least 2 brothers”
Properties of Quantifiers • Nested Quantifiers • x y P equivalent to y x P • y x P equivalent to y x P • Does not apply if quantifiers are different • De Morgan’s law for quantifiers • x P x P • x P x P • x P x P • x P x P
More About Quantifiers • Be careful when: • Using quantifiers (, ) in combination with , • The domain consists of multiple kinds of objects • In the quantified sentence(such as x P or x P), P would typically contain terms that are variables • Not just ground terms (terms that have no variables) • x P as a query: binding list more important than truth of the sentence
Axioms and Theorems • Axioms are sentences that represent first principles • Plain facts • Definitions • Theorems are sentences entailed by axioms
Some Useful Domains • Natural Numbers • Built from 0, successor function S, and Peano axioms • Sets • , , , , and element insertion • Lists • Nil, Cons, Append, First, Rest, Find, …
FOL and the Wumpus World • We can represent the Wumpus World in a more compact fashion • Less sentences needed to represent rules • We can include time and percept objects in the world • A percept is represented as a list of constant symbols • Predicates with time arguments capture the dynamic nature of the agent moving in this world
Knowledge Engineering • Identify the task • Assemble the relevant knowledge • Decide on a vocabulary • Encode general knowledge of the domain • Encode the specific problem instance • Pose queries to the inference procedure • Debug the knowledge base
Inference Algorithms in FOL • Reduction to Propositional Inference(Propositionalization) • Lifting and Unification • Resolution
Propositionalization • Strategy: convert KB to propositional logic and then use PL inference • Ground atomic sentences become propositional symbols • What about the quantifiers?
Example • KB in FOL: • x King(x) Greedy(x) Evil(x) • King(John) • Greedy(John) • Brother(Richard,John) • The last 3 sentences can be symbols in PL • Apply Universal Instantiation to the first sentence
Universal Instantiation • UI says that from a universally quantified sentence, we can infer any sentence obtained by substituting a ground term for the variable • Back to Example • From: x King(x) Greedy(x) Evil(x) • To: • King(John) Greedy(John) Evil(John) • King(Richard) Greedy(Richard) Evil(Richard) • …
Issue with UI • Ground terms: all symbols that refer to objects as well as function applications (recall that function applications return objects) • For example, suppose Father is a function: • Father(John) and Father(Richard) are also objects/ground terms • But so are Father(Father(John)) and Father(Father(Father(John))) • Infinitely many ground terms/instantiations
Existential Instantiation • Whenever there is a sentence, x P, introduce a new object symbol called the skolem constant and then add the unquantified sentence P, substituting the variable with that constant • Example: • From: x Crown(x) OnHead(x, John) • To: Crown(Cnew) OnHead(Cnew, John)
Substitution • UI and EI apply substitutions • A substitution is represented by a variable v and a ground term g; {v/g} • Can have sets of these pairs if there are more variables involved • Let be a sentence (possibly containing v) • SUBST( {v/g}, ) stands for the sentence that applies the substitution to
UI and EI Defined • UI:vα ___for any ground term gSUBST({v/g}, α) • EI:vα ___for some constant symbol k notSUBST({v/k}, α) yet in the knowledge base
Back to Propositionalization • Given a KB in FOL, convert KB to PL by • applying UI and EI to quantified sentences • converting atomic sentences to symbols • If there are no functions (Datalog KB), UI application does not result in infinitely many sentences • Regular PL Inference can now be carried out without problems • What if there are functions?
Dealing with Infinitely Many Ground Terms • Can set a depth-limit for ground terms • Depth specifies levels of function nesting allowed • Carry out reduction and inference process for depth 1, then 2, then 3, … • Stop when entailment can be concluded • This works if there is such a proof, but goes into an endless loop if there is not • The strategy is complete • The entailment problem in this sense is semidecidable
Inefficiencies in Propositionalization • An inordinate number of irrelevant sentences may be generated, resulting from UI • This motivates generating only those sentences that are important in entailment
Example • Suppose KB contains: • x King(x) Greedy(x) Evil(x) • y Greedy(y) • King(John) • Suppose we want to conclude Evil(John) • Because of the existence of objects other than John (such as Richard) and the existence of functions, UI will generate many sentences
Example, continued • It is sufficient to generate: • King(John) Greedy(John) Evil(John) • Greedy(John) • Which is just: • SUBST( {x/John}, King(x) Greedy(x) Evil(x) ) • SUBST( {y/John}, Greedy(y) ) • Applying the substitution matches the • Premises: King(x) Greedy(x) • With other sentences in the KB:Greedy(y), King(John)
Lifted Modus Ponens • Lifting: Raising propositional inference rules to first order logic • Example: Generalized Modus Ponens If there is a substitution θ, such thatSUBST(θ, pi) = SUBST(θ, pi’) for all i, then p1', p2', … , pn’, ( p1 p2 … pn q) _______________________________________________________________________________ SUBST(θ,q) • In our example, = {x/John, y/John}
Unification • Process that makes logical expressions identical • Goal: match the premises of implications so that conclusions can be derived • UNIFY algorithm takes two sentences and returns a unifier (substitution) if it exists
About UNIFY • UNIFY returns a Most General Unifier (MGU) • There are efficiency issues withOCCUR-CHECK function • May need to standardize apart: rename variables to avoid name clashes • Unification is a key component of all first-order algorithms
Algorithms that use unification • Forward and backward chaining algorithms • Will not be discussed • Resolution-based theorem proving systems
PL Resolution Revisited • Recall PL Resolution algorithm: • Convert (KB ) to CNF • Repeatedly get pairs of clauses and eliminate complementary literals • If an empty clause results, KB╞ • Resolution applies to FOL, but we need to refine definitions of: • CNF (for quantified sentences) • Resolution inference rule / complimentary literals
CNF Conversion in FOL • Eliminate biconditionals and implications • Move inwards (De Morgan’s) • For quantifiers: x P x P, x P x P • Standardize variables • Eliminate possible name clashes • Skolemize (Apply EI to existential sentences) • Introduce Skolem constants or functions • Drop universal quantifiers • Distribute over
Example Everyone who loves all animals is loved by someone: x [y Animal(y) Loves(x,y)] [y Loves(y,x)] • Eliminate biconditionals and implications • x [y Animal(y) Loves(x,y)] [yLoves(y,x)] • Move inwards: • x [y (Animal(y) Loves(x,y))] [y Loves(y,x)] • x [y Animal(y) Loves(x,y)] [y Loves(y,x)] • x [y Animal(y) Loves(x,y)] [y Loves(y,x)] • Standardize variables: each quantifier should use a different one • x [y Animal(y) Loves(x,y)] [z Loves(z,x)]
Example, continued • Skolemize: a more general form of existential instantiation. • Each existential variable is replaced by a Skolem function of the enclosing universally quantified variables: • x [Animal(F(x)) Loves(x,F(x))] Loves(G(x),x) • Drop universal quantifiers: • [Animal(F(x)) Loves(x,F(x))] Loves(G(x),x) • Distribute over : • [Animal(F(x)) Loves(G(x),x)] [Loves(x,F(x)) Loves(G(x),x)]
Resolution • Lifted version of resolution inference rule: l1··· lk, m1··· mn (l1··· li-1 li+1 ··· lk m1··· mj-1 mj+1··· mn)θ where Unify(li, mj) = θ. • The two clauses are assumed to be standardized apart so that they share no variables • For example, Rich(x) Unhappy(x) , Rich(Ken) Unhappy(Ken) with θ = {x/Ken}
Making ResolutionMore Efficient • Can favor particular clauses in the KB • Unit preference (unit clauses) • Sets of support • Input resolution (e.g. “single spine”) • Subsumption • Reduces size of KB by eliminating redundant sentences