440 likes | 461 Views
Chapter 7 First-order logic. Propositional logic not expressive enough needs a huge amount of rules for even for the simple 4x4 wumpus world previous examples on chapter 7 no power on handling groups of objects every object is specified indvidually First-order logic (FOL)
E N D
Chapter 7 First-order logic • Propositional logic • not expressive enough • needs a huge amount of rules • for even for the simple 4x4 wumpus world • previous examples on chapter 7 • no power on handling groups of objects • every object is specified indvidually • First-order logic (FOL) • introduces the concepts to overcome that • objects and properties
Why we need logic? • Natural language? • the expressive power – high but ambiguous • can it be used as a representation language • in AI? • serves as a medium of communication • rather than pure representation • since 1 syntax too many (hidden) semantics • For logic? • it’s like a function: one-to-one mapping.
New concepts • Relations • are the links among objects • can be functions– only one output for a given input • Examples: • Objects: people, houses, number, colors, baseball, centuries • Relations: either unary (property) or n-ary • unary: tall, large, small, red, round, prime, boring • n-ary: brother of, greater than, part of, inside, after, is • Functions: father of, best friend, one more than
Almost any fact (assertion) can be thought of a combination of • objects • and properties or relations • “One plus two equals three” • Objects: one, two, three, one plus two • Relation: equals • Function: plus A name of the object obtained by applying the function plus to the objects one and two
“Squares neighboring the wumpus are smelly.” • Objects: Squares, wumpus • Property: smelly • Relation: neighboring • FOL is important • almost any of our concept/knowledge • can be expressed as FOL Not a function because many squares may satisfy the constraints, but there is only one three
Pros & Cons of FOL • Drawback • first-order logic doesn't have the things • Categories / Classification • Time (Temporal Logic) • Events • Advantage • it can express • anything that can be programmed • Prolog
Difference of FOL and PL • PL • consider the facts: True or False • use compositionality to see • whether the sentence is true or false • FOL • consider the RELATIONS with OBJECTS: • True or False • also use compositionality
Models for FOL • What is a model? • in PL: A B => C • then how many possible combinations? • this set of truth values = a model for this world • only True or False exists • in FOL, a model contains more. • objects • domain of an FOL model • = set of objects (domain elements) it contains
There are five objects in this model • two binary relations • three unary relations • one unary function: left-leg
Formally speaking, relation is • a set of tuples of objects that are related • e.g., for relation brother, it is the set • { < Richard, King John>, <King John, Richard>} • Strictly speaking, • the functions used in FOL must be totalfunctions • i.e., a function returns a value for every input tuple • constituted by the domain elements • e.g., brother:X Y, any body must have a brother? • left_leg:X Y, anything must have a left leg? • left_leg(Leftleg1) = Leftleg2?
Terms • a logical expression of objects • Terms = • constant symbols (1, a, b, peter) • variables (X, Y, Human) • and function symbols (fatherof(peter), plus(1,2)) • Atomic sentences • the facts in Prolog • = Predicate symbol + Terms • = Relation + Objects • e.g., brother(Richard, John). • married(Father(Richard), Mother(John))
Complex sentences • multiple atomic sentences combined with logical connectives • Example: • Brother(Richard, John) Brother(John, Richard) • Older(John, 30) Younger(John, 30)
Quantifiers • Quantifiers • For expressing properties of • entire collection of objects – projection of a subset • Universal quantification () • Meaning all, • reading as “For all” • Example: “All Kings are Persons” x King(x) Person(x) If X is a King, then X is a Person • called a variable, • lowercase • if it’s a constant, • ground term
Here x King(x) Person(x) is true • if x = any domain element, • and the sentence is still true. • x Richard • x King John • x Richard’s left leg • x John’s left leg • x the crown • the above list is called the extended interpretation • By applying this list, what we have?
Are they true in the model? • Yes!!!! (but only for interpretation) • from the table of implication ( =>) • whenever the premise is false • the result is true, regardless of the conclusion • So, Universal quantifier • asserts a list of sentences (reduce our work!)
Existential quantification () • Meaning some • reading as “There exist” or “For some” • Example • x Crown(x) OnHead(x, John)
Here, we can see • => is the natural connective with • while with • if with , too strong, if => with , too weak
Nested Quantifiers • When using multiple quantifiers, e.g., • x y Brother(x, y) => Sibling (x, y) • we can write x, y instead of separate ones • x y Loves (x, y) • meaning? • Everybody x loves somebody y • then y x Loves (x, y)? • any difference?
Somebody y, whom is loved by everybody x. • Problem? • Quantifiers are not commutative • The order cannot be interchanged • Similar to a query • If we want to specify the precedence, • we should use ( ) • e.g., y ( x Loves (x, y) )
Connections between and • is a conjunction over the universe • While is a disjunction • De Morgan rules can apply to them: • x P x P • x P x P • x P x P • x P x P • So, only one of the or is necessary • we don’t need both
Equality • Equality is represented as • “=” • instead of a predicate • Example: FatherOf(John) = Henry • To ensure two objects are not the same • negation with equality is used • E.g., x,y Sister(Felix, x) Sister(Felix, y) (x = y) without that, what is the meaning?
The uniqueness quantifier ! • just specifies • One or more different objects • ! is used to specify • a unique one object • Example: “There is only one king” • !x King(x) • Or x King(x) y King(y) (x = y) • If X is a King & Y is a King then X must be Y
Using first-order logic • domain • a section of the world • about which we wish to express some knowledge • database, networking, architecture, etc. • The followings are the examples • The kinship domain • The domain of numbers, sets and lists
The kinship domain • Also called family relationships domain • The objects in the domain are people • The properties of the objects include • Gender • Age • Height, … • The relations are: • parenthood, brotherhood, marriage, …
Some Examples • m,c Mother(c)=m Female(m) Parent(m,c) • w,h Husband(h,w) Male(h) Spouse(h,w) • Disjoint categories: • x Male(x) Female(x) • Inverse relations: • p,c Parent(p,c) Child(c,p) • g,c Grandparent(g,c) p Parent(g,p) Parent(p,c) • x,y Sibling(x,y) x≠y p Parent(p,x) Parent(p,y) • we can have many more axioms like these. • this will be one of your exercises in PJ.3
Must the Male, Female, Parent be • the set of primitive predicates? • Of course, not. • We may use other predicates as the primitive set • And also, in some domains • we have no clearly identifiable basic set
The domain of numbers • Here is the theory of naturalnumbers • to check if a number is natural • NatNum • a constant symbol (basis) • 0 • a function symbol S, meaning successor NatNum(0). n NatNum(n) => NatNum(S(n)).
After that, we define constraints about the function S n 0 ≠ S(n) m, n m ≠ n => S(m) ≠ S(n) • addition of natural numbers m NatNum(m) => ( + (m, 0) = m ) m, n NatNum(m) NatNum(n) => +(S(m) , n) = S(+(m,n))
The domain of sets • We want to represent individual sets, including empty set. • What we need? • a way to building up a set • by adding an element to a set (adjoining) • take union of two sets • take intersection of two sets • Checking? • membership of an element • whether it is a set or other objects
Hence we want to define the followings • Constant symbol: • { } • Predicates: • Set, Member, Subset • Functions: • Adjoining, Union, Intersection
The domain of lists • Lists are similar to sets • difference? • Lists are ordered • An element can appear more than once • Here is the summary of their difference
The wumpus world • Recall the wumpus agent receives • a percept vector [S, B, G, BUMP, S] • As the percept is time critical, • we add an integer as the time step • percept([S, B, G, None, None], 5) • S, B, G, etc. are constant symbols • The actions in wumpus world • Turn(Right), Turn(Left), Forward, … • we want to pick up a best action for any time
To choose a best action, we may ask • a BestAction(a, 5), for example • the result may be a = Grab (a Glitter!!) • But is it some straightforward? • we have to first tell KB what happens!! • s,b,u,c,t Percept([s, Breeze, g, m, c], t) Breeze(t) • s,b,u,c,t Percept([s, b, Glitter, m, c], t) Glitter(t) • and so on. • but it’s not enough • since we need to define additional rules • t Glitter(t) => BestAction(Grab, t) • and so on.
Defining environments • Objects in the environment • squares • pits • the wumpus • For any square, • named as Square1,2 and so on. • for adjacent squares, we have to define them • pair by pair!! • hence using a rule is much better
For the pits, • we don’t need name them individually • we just need to use a unary predicate • Pit(S), to indicate a square has a pit or not • For the wumpus, • there exists only one • it lives only in exactly one square • so, we may use Home(Wumpus) to name the square • where Wumpus is a constant and Home a function
As the agent moves • it changes over time • we use At(Agent, s, t) to specify • at a time step, Agent is at s • For the properties of the environment • it is constant over time. • e.g., a square is breezy (has a breeze) s, t At(Agent, s, t) Breeze(t) => Breezy(s) The same for smelly (has a stench).
Diagnostic rules • For a given percept, what does it mean? • what results can be concluded? • e.g., if a square is breezy, then what? • implies “some adjacent square has a pit!” s Breezy(s) => r Adjacent(r, s) Pit(r) • For the reverse direction, is it true? • yes, so we have s Breezy(s) <=> r Adjacent(r, s) Pit(r)
Causal rules • For a given result, what facts can be deduced? • if r is a pit, then? • all adjacent squares of r are breezy r Pit(r) => [s Adjacent(r, s) Breezy(s)] • if all squares adjacent to a square s are not pits, then s is not breezy s [r Adjacent(r, s) => Pit(r)] => Breezy(s) • Basically, these rules are equivalent to previous bidirectional rule
Conclusion the facts or world description • Whichever kind representation • if the axioms correctly and completely • describe the way the world works • and the way the percepts are produced • then any complete logical inference procedure • will infer the strongest possible description of the world state • given the available percepts successor function