First-Order Logic Topics we will cover Why FOL? Syntax and Semantics of FOL Using FOL Wumpus World in FOL Introduction Propositional Logic: Represent a knowledge base (KB) using a formal language. Has efficient linear complexity inference algorithms that allow us to reason with the knowledge in the KB, It is limited in its expressiveness. First-Order Logic: An alternative (and more expressive) language for representing KBs. Good points () and bad points () of propositional logic Propositional logic is declarative: The order of knowledge in KB not important. 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
Propositional logic has very limited expressive power,
E.g., cannot say “pits cause breezes in adjacent squares” except by writing one sentence for each square First-Order Logic (FOL) Propositional logic assumes the world contains facts, First-order logic (like natural language) assumes the world contains, Objects : represent things in the real world. E.g: people, houses, numbers, colors … Relations : represent attributes of object or relationships between objects. E.g: red, round, prime, brother of, bigger than, part of, comes between, … Functions : take object(s) and return an object result. E.g: Length(), TeammateOf(), best friend(), Sqrt() … Syntax of FOL: Basic elements Sentences in FOL represent these components of the world using the following elements: constants: represent objects E.g: Haileselassie, 2, Blue, … predicates: represent relations E.g: Brother, >, … functions: represent functions E.g: Sqrt, LeftLegOf, … variables: by convention lower case letters E.g: x, y, a, b,... connectives: the same 5 connectives as are used i.e.: , , , ,
equality: the two terms refer to the same object, i.e. =
quantifiers: existential and universal, i.e. , Atomic Sentences Atomic sentence: The simplest type of sentence in FOL. An atomic sentence consists of either: Atomic sentence = predicate (term1,...,termN) or term1 = term2 where a term is either: Term = function (term1,...,termN) or constant or variable E.g.1. TeammateOf(Kenenisa,HaileGebreselassie) The first example consists of a predicate, TeammateOf, with two constant arguments, HaileGebreselassie and Kenenisa. E.g.2 Length(LeftLegOf(Kenenisa)) = Length(RightLegOf(Kenenisa)) The second example contains two constants (both Kenenisa), combined using three functions, Length, LeftLegOf and RightLegOf. Complex Sentences Complex sentences are made from atomic sentences using connectives: We can make more complex sentences by combining atomic sentences using connectives, S, S1 S2, S1 S2, S1 S2, S1 S2, E.g. Teammate(Kenenisa,HaileGebreselassie) Teammate(HaileGebreselassie,Kenenisa) >(1,2) ≤ (1,2) >(1,2) >(1,2) Interpretations Sentences are true with respect to a model and an interpretation. Model contains objects (domain elements) and relations among them. Interpretation specifies (real-world) referents for constant symbols → objects predicate symbols → relations function symbols → functional relations
An atomic sentence predicate(term1,...,termN) is true
if the objects referred to by term1,...,termN are in the relation
referred to by predicate. First-Order Logic Quantifiers First-Order Logic Quantifiers It is FOL quantifiers that give the language its expressive power. There are two types of quantifier: universal quantifiers () existential quantifiers () Universal Quantification The symbol for universal quantification is . To interpret the universal quantification symbol in a FOL sentence we can read it as “for all …”. <variables> <sentence> E.g. x At(CS , x) Intelligent(x) Can be interpreted as stating that “for all x, At(CS, x) implies Intelligent(x)”. In other words, if everyone is at CS then they are intelligent. Definition: x P is true in a model m iff P is true with x being each possible object in the model. A common mistake to avoid Typically, is the main connective with . Common mistake: using as the main connective with : For Examples: x At(CS , x) Intelligent(x) Means “Everyone is at CS and everyone is intelligent” x At(CS , x) Intelligent(x) Means “Everyone at CS is intelligent” Existential Quantification The symbol for existential quantification is . We can read this as “there exists …”. <variables> <sentence> E.g. x At (CS , x) Intelligent(x) can be interpreted as stating that “there exists some x, such that At(CS, x) and Intelligent(x) are both true. In other words, somebody at CS is intelligent. Definition: x P is true in a model m iff P is true with x being some possible object in the model Another common mistake to avoid Typically, is the main connective with . Common mistake: using as the main connective with : For Examples: x At(CS , x) Intelligent(x) is true if there is anyone who is not at CS! x At (CS , x) Intelligent(x)
Means “Someone at CS is intelligent”
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,dorowet) x Likes(x,dorowet) x Likes(x, porridge) x Likes(x, porridge) Equality in First-Order Logic The equality symbol in FOL does not mean that same as assignment in most programming languages. A sentence involving the ‘=’ symbol in FOL is true if both of its arguments refer to the same object. term1 = term2 is true under a given interpretation if and only if term1 and term2 refer to the same object. E.g., x,y Brother(x,Abebe) Brother(y,Abebe) (x=y) x and y do not refer to the same object. In other words, Abebe has two (distinct) brothers. Without the use of the equality symbol, the above sentence would be true if x and y had the same value (i.e. Abebe has one brother). Interacting with FOL KBs Suppose a wumpus-world agent is using a FOL KB and perceives a smell and a breeze (but no glitter) at t=5: Tell(KB,Percept([Smell,Breeze,None],5)) Ask(KB,a BestAction(a,5)) Tell/Ask Operations in First-Order Logic The first operation tells the KB, the current percept at time 5. The second operation asks the KB what will be the best action to take at time 5. i.e., does the KB entail some best action at t=5? Answer: Yes, {a/Shoot} ← substitution (binding list) Given a sentence S and a substitution σ, Sσ denotes the result of plugging σ into S; e.g., S = Faster(x,y) σ = {x/Kenenisa, y/HaileGebreselassie} Sσ = Faster(Kenenisa, HaileGebreselassie) Ask(KB,S) returns some/all σ such that KB╞ Sσ Knowledge base for the wumpus world (1) Perception t,s,b Percept([s,b,Glitter],t) Glitter(t)
Reflex t Glitter(t) BestAction(Grab,t) Knowledge base for the wumpus world (2) Adjacency x,y,a,b Adjacent([x,y],[a,b]) [a,b] {[x+1,y], [x-1,y],[x,y+1],[x,y-1]}
Squares are breezy near a pit:
Diagnostic rule---infer cause from effect s Breezy(s) r Adjacent(r,s) Pit(r) Causal rule---infer effect from cause r Pit(r) [s Adjacent(r,s) Breezy(s) ] Summary First-order logic: objects and relations are semantic primitives. syntax: constants, functions, predicates, equality, quantifiers. FOL: Increased expressive power: sufficient to define wumpus world. Propositional logic lacks expressive power …