240 likes | 444 Views
First Order Logic (FOL). Slides from Srini Narayanan, Sebastian Thrun, Peter Norvig, and etc. Jianlin Feng School of Software SUN YAT-SEN UNIVERSITY. First Order Logic (FOL). Why FOL? Syntax and semantics of FOL Using FOL Wumpus world in FOL Knowledge engineering in FOL.
E N D
First Order Logic (FOL) Slides from Srini Narayanan, Sebastian Thrun, Peter Norvig, and etc. Jianlin Feng School of Software SUN YAT-SEN UNIVERSITY
First Order Logic (FOL) • Why FOL? • Syntax and semantics of FOL • Using FOL • Wumpus world in FOL • Knowledge engineering in FOL
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) 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
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, …
Models for FOL: Example • A model containing: • 5 objects: R, J, 2 legs, crown. • 2 binary relations, “brother” and “on head” • 3 unary relations, “person”, “king” and “crown” • 1 unary function, left-leg.
Models for FOL • Models for propositional logic • sets of truth values for the proposition symbols. • Models for FOL • The domain of a model is the set of objects it contains. • A relation is just the set of tuples of objects that are related. • A tuple is a collection of objects arranged in a fixed order. • E.g., {<Richard the Lionheart, King John>, < King John, Richard the Lionheart >}, {<the crown, King John>}. • Unary relations are called “properties”. • Functions are special kinds of relations • in that a given object must be related to exactly one object in this way.
Syntax of FOL: Basic elements • Constants: stand for objects. • KingJohn, 2, UCB,... • Predicates : stand for relations • Brother, >,... • Functions : stand for functions • Sqrt, LeftLegOf,... • Variables x, y, a, b,... • Connectives , , , , • Equality = • Quantifiers ,
Symbols and Interpretations • As in propositional logic, every model must provide the information required to determine if any given sentence is true or false. • A model in FOL consists of a set of objects and an interpretation that maps • constant symbols to objects, • predicate symbols to relations on those objects, • and function symbols to functions on those objects.
Atomic sentences that state facts Atomic sentence = predicate (term1,...,termn) or term1 = term2 • A term is a logical expression that refers to an object. Term = function (term1,...,termn) or constant or variable • Variable • A variable is a term • A term with no variables is called a ground term • E.g., Brother(KingJohn, RichardTheLionheart) • > (Length(LeftLegOf(Richard)), Length(LeftLegOf(KingJohn)))
Complex sentences • Complex sentences are made from atomic sentences using connectives S, S1 S2, S1 S2, S1 S2, S1S2, E.g. Sibling(KingJohn,Richard) Sibling(Richard,KingJohn) >(1,2) ≤ (1,2) >(1,2) >(1,2)
Truth in first-order logic • Sentences are true with respect to a model and an interpretation • Model contains objects (domain elements) and relations among them • Interpretation specifies referents for constantsymbols→objects predicatesymbols→relations functionsymbols→ functional relations • An atomic sentence predicate(term1,...,termn) is true iff the objects referred to by term1,...,termn are in the relation referred to by predicate • The truth of a complex sentence is derived from its constituent logical connectives and the truths of its constituent atomic sentences.
Universal quantification • <variables> <sentence> Everyone at UCB is smart: x At(x,UCB) Smart(x) • x P is true in a model m iff P is true with x being each possible object in the model • is really a conjunction over the universe of objects. At(KingJohn,UCB) Smart(KingJohn) At(Richard,UCB) Smart(Richard) At(UCB,UCB) Smart(UCB) ...
A common mistake to avoid • Typically, is the main connective with • Common mistake: using as the main connective with : x At(x,UCB) Smart(x) means “Everyone is at UCB and everyone is smart”
Existential quantification • <variables> <sentence> • Someone at UCB is smart: • x At(x,UCB) Smart(x) • xP is true in a model m iff P is true with x being some possible object in the model • is really a disjunction over the universe of objects. At(KingJohn,UCB) Smart(KingJohn) At(Richard,UCB) Smart(Richard) At(UCB,UCB) Smart(UCB) ...
Another common mistake to avoid • Typically, is the main connective with • Common mistake: using as the main connective with : x At(x,UCB) Smart(x) is true if there is anyone who is not at UCB!
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” • Better to use parentheses, x (y Loves(x,y)) • yx Loves(x,y) • “Everyone in the world is loved by at least one person” • y (x Loves(x,y)) • Quantifier duality: each can be expressed using the other • x Likes(x,IceCream) x Likes(x,IceCream) • x Likes(x,Broccoli) xLikes(x,Broccoli)
Equality • term1 = term2is true under a given interpretation if and only if term1and term2refer to the same object • We can use the equality symbol to state facts about a given function. • E.g., Father(John) = Henry, • says that the object referred to by Father(John) and the object referred to by Henry are the same.
Equality (2) • term1 = term2is true under a given interpretation if and only if term1and term2refer to the same object • We can also use the equality symbol with negation to insist that two terms are not the same object. • E.g., x, y Brother(x, Richard) Brother(y, Richard) (x=y). • says that Richard has at least two brothers.
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)
Interacting with FOL KBs • Suppose a wumpus-world agent is using an 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)) • 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 = Smarter(x,y) σ = {x/Hillary,y/Bill} Sσ = Smarter(Hillary,Bill) • Ask(KB,S) returns some/all σ such that KB╞σ
KB for the wumpus world • Perception • t,s,b Percept([s,b,Glitter],t) Glitter(t) • Reflex • t Glitter(t) BestAction(Grab,t)
Deducing hidden properties • x,y,a,b Adjacent([x,y],[a,b]) [a,b] {[x+1,y], [x-1,y],[x,y+1],[x,y-1]} Properties of squares: • s,t At(Agent,s,t) Breeze(t) Breezy(s) 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) ]
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
Summary • First-order logic: • objects and relations are semantic primitives • syntax: constants, functions, predicates, equality, quantifiers • Increased expressive power: sufficient to express real-world problems