Title: Clase 13 - 11-07-00 Cap
1Clase 13 - 11-07-00Capítulo 7Lógica de Primer
Orden
Diapositivas crudasobtenidas de la Web, sin
elaborar ni traducir (temas ya conocidos de
otros cursos)
2Clase 13 --04-07-00
- PARTE III - Conocimiento y RazonamientoCapítulo
6. AGENTES QUE RAZONAN CON LÓGICA
PROPOSITIVA-Capítulo 7. LÓGICA DE PRIMER ORDEN
lt-Capítulo 8 . CONFORMACIÓN DE UNA BASE DE
CONOCIMIENTOS-Capítulo 9 LA INFERENCIA EN LA
LÓGICA DE PRIMER ORDEN-Capïtulo 10 SISTEMAS DE
RAZONAMIENTO LÓGICO
3Lógica de Primer Orden
- Constantes
- representan objectos del mundo real
- juan, 0, 1, libro, etc. (notación a, b, c, )
- Funciones
- los nombres para objetos no representan
relaciones en el mundo real (notación P, Q, R,
) - se_gustan(juan,maría), x gt y, valioso(oro)
- predicado especial para la igualdad ()
- Variables
- testaferros o guardasitios de objetos (notación
x, y, z, ) - Conectivos o conectores y Cuantificadores
- ?,?, ?,?,?,?
- () se puede considerar que la igualdad es un
signo de predicado con un significado previamente
definido
4Lógica de Primer Orden
- Oraciones Atómicas (fórmulas atómicas)
- predicados (término1, término2, , términok)
- donde
- término funcción(término1, término2, ,
términok) o constante, o variable - Fórmulas Compuestas
57.1
- 7.1 Syntax and Semantics
- - constants
- - predicates
- - functions (not evaluated)
- - terms refer to objects (constants or
functions) - - atomic sentences
- - complex sentences atomics plus connectives
- - quantifiers
- - universal
- - existential
- - equality
67.2
- 7.2 Extensions and Notational Variations
- - higher-order logic
- - lambda operator
- - uniqueness quantifier
- - uniqueness operator
- - notational variations
77.3
- 7.3 Using First-Order Logic
- - kinship domain
- - axioms, definitions and theorems
- - set domain
- - special notation for sets, lists and arithmetic
- - asking questions and getting answers (Prolog)
87.4
- 7.4 Logical Agents for the Wumpus World Fig7.2
Fig6.1 - - Percept (PerceptList,TimeStep)
- - Action Turn(Right), Turn(Left), Forward,
Shoot, Grab, Release, Climb - - Turn is a function, Release is new
- - reflex, model-based, goal-based
97.5
- 7.5 A Simple Reflex Agent
- - percept(S,B,glitter,U,C,T) gt action(grab,T)
- - OR percept(S,B,glitter,U,C,T) gt atgold(T)
- atgold(T) gt action(grab,T)
- - no memory, does the same thing in the same
situations - - randomness may help (e.g., orientation)
107.6-Representing Change
- The traditional ontology for reasoning about
action is called the situation calculus. It
involves three basic categories - a "state" is a snapshot of the world,
- a "fluent" is a changing relationship between
objects, and - an "action" is an event that changes one state
into another. - States, fluents, and actions can be represented
as logical terms - let a and b be constants naming two blocks,
- stack(a,b) can name the action of placing a on b,
- do(s0, stack(a,b)) can name the state resulting
from doing this action in the initial state s0. - Axiomatic description of how the world changes
- Effect axioms describe the properties of
situations resulting from actions - e.g., "x"y"s Øblocked(x,s) Ù Øblocked(y,s) Þ
above(x, y, do(s, stack(x,y))) - Frame axioms represent how the world stays the
same - e.g., "x"y"z"s above(x,y,s) Ù a ¹ stack(x,z) Þ
above(x, y, do(s,a)) - In general there will be too many frame axioms
that can be stated
117.6.1
- 7.6.1 Representing Change in the World
- - retract(agent_location(X,Y)),
assert(agent_location(X1,Y1)) - - but no recollection of route (okay for
simulator, but not for agent) - - situation calculus
- - at(agent,1,1,s0)
- - result(Action,Situation1) Situation2
- - frame axiom
- - (holding(X,S) and (A ! release)) gt
holding(X,result(A,S)) - -
127.6.2
- 7.6.2- successor-state axiom
- - holding(X,result(A,S)) ltgt (A grab) and
present(X,S) and portable(X)) - V (holding(X,S)
and (A ! release)) - - keeping track of location
- - at(Agent,Location,Situation)
- - orientation(Agent,Situation)
- - locationToward(Location,Orientation)
NewLocation - - locationAhead(Agent,Situation)
AheadLocation - -
137.6.3
- 7.6.3 adjacent(Location1,Location2)
- - wall(Location)
- - agent location changes upon moving forward
into a non-wall - - agent orientation changes upon turning left
or right - - agent no longer has arrow after shoot
- - hasarrow(Agent,result(Action,Situation))
ltgt hasarrow(Agent,Situation) -
Action ! shoot - - gold location, wumpus location and health
-
147.6.4
- 7.6.4- wumpus dead if agent has arrow and shoots
in direction of wumpus - - dead(wumpus,result(Action,S)) ltgt Action
shoot hasarrow(agent,S) -
at(agent,X,Y,S) -
orientation(agent,S) 0 -
at(wumpus,X1,Y1,S) Y Y1 X lt X1 - - three other disjuncts for other
orientations - - why would agent shoot?
- - need a goal
- -
-
157.7
- 7.7 Deducing Hidden Properties of the World
- - causal rules (model-based)
- - at(wumpus,L1,S) adjacent(L1,L2) gt
smelly(L2) - - at(pit,L1,S) adjacent(L1,L2) gt breezy(L2)
- - at(wumpus,L,S) at(pit,L,S) ltgt ok(L)
- - diagnostic rules
- - at(agent,L,S) stench(S) gt smelly(L)
- - at(agent,L,S) breeze(S) gt breezy(L)
- - percept(none,none,G,U,C,T) at(agent,L1,S)
adjacent(L1,L2) gt ok(L2) - - compare to above causal rule
- - causal rules infer strongest conclusions
167.8
- 7.8 Preferences Among Actions
- - action-value system
- - great, good, medium and risky actions
- - great(A,S) gt action(A,S)
- - good(A,S) E(A2) great(A2,S) gt
action(A,S) - - great(A,S) ltgt (A grab atgold(S)) V
- (A climb at(agent,1,1,S)
holding(gold,S))
177.9
- 7.9 Toward a Goal-Based Agent
- - above preferences will get the gold safely (if
possible), but then what - - holding(gold,S) gt goalLocation(1,1,S)
- - kill the wumpus
- - achieve via
- - inference (inefficient for long paths)
- - search
- - planning
- Logic and Knowledge Representation
- Semantics of First-Order Predicate Logic
- Proof Theory and the Notion of Derivation
- Resolution Mechanism
- Forward and Backward Chaining
18Transformation to FOPC3
- Mary got good grades in courses CS101 and passed
CS102 - John passed CS102
- Student who gets good grades in a course passes
that course - Students who pass a course are happy
- A student who is not happy hasnt passed all
his/her courses - Only one student failed all the courses
19Transformation to FOPC4
- Usar habitualmente ? con ?
- e.g.,
- says, all humans are mortal
- but,
- say, everything is human and mortal
- Usually use Ù with
- e.g.,
- says, there is a bird that does not fly
- but,
- is also true for anything that is not a bird
- "xy is not the same as y"x
- e.g.,
- says, there is someone who loves everyone
- but,
- says, everyone is loved by at least one person
20Cuantificadores
- " se reinterpreta como conjunción para todos
los objetos del dominio - p.ej.,
- se interpreta como
- cse reinterpreta como disyunction para todos
los objetos del dominio - p.ej.
- Se reinterpreta como
- Dualidad de los cuantificadores
- cada uno de ellos se puede expresar usando el
otro - lo cual es una aplicación de las leyes de
deMorgan - ejemplos
21Interpretations Models in FOPC6
- Definition An interpretation is a mapping which
assigns - objects in domain to constants in the language
- functional relationships in domain to function
symbols - relations to predicate symbols
- usual logical relationships to connectives and
quantifiers Ø, Ù, Ú, Þ, Û, ", - Definition Models
- An interpretation M is a model for a set of
sentences S, if every sentence in S is true with
respect to M (if S is a singleton s, then we
say that M is a model for s). - Notation S
- If there is a model M for S, then S is
satisfiable - If S is true in every interpretation M (every
interpretation is a model for S), then S is valid
M
22Interpretations Models in FOPC7
- Example
-
- where N, L are predicate symbols, and f a
function symbol - interpretation 1
- domain positive integers
- N(x) x is a natural number
- L(x,y) x is less than y
- f(x) predecessor of x (i.e., x-1)
- then s says predecessor of any natural number
is a natural number (of course this is false, so
this interpretation is not a model for s) - interpretation 2
- domain all people
- N(x) x is a person
- L(x,y) x likes y
- f(x) mother of x
- then s says everyone likes his/her mother
23Models as Sets of Atomic Formulas8
- If we assume the language has no quantifiers and
variables, then models can be represented as sets
of atomic formulas - note that we can eliminate quantifiers and
variables by completely expanding conjunctions of
ground formulas (formulas without variables) - let A be the set of all ground atomic formulas in
the language, then a model M can be expressed as
a subset of A (M Í A) - for an atomic formula s, s Î M, means M is a
model of s, otherwise s is false in M - Example Consider KB consisting of
- if we assume that the named constants are the
only objects in the domain, then A bird(sam),
bird(tweety), flies(sam), flies(tweety) - then, M bird(tweety), bird(sam), flies(sam)
is a model for flies(sam), "x(bird(x)),
x(bird(x) Ù flies(x)), but M is not a model for
flies(tweety), "x(flies(x)), or x(Ø bird(x)) - Note that if there is a function symbol in the
language, then A is infinite
24Semantics of FOPC Operators9
- Let F and G be FOPC Formulas, and M be any
interpretation - F Ù G is true in M iff both F and G are true in
M - F Ú G is true in M iff at least one of F or G
is true in M - ØF is true in M iff both F is false in M
- F Þ G is true in M iff either F is false in M
or G is true in M - F Û G is true in M iff both F and G are true in
M or both are false in M - So far this is the same as propositional how
about quantifiers - "x F is true in M iff for any object d in the
domain, Fd is true in M, where Fd is the
result of replacing every free occurrence of x in
F with d - x F is true in M iff for some object d in the
domain, Fd is true in M, where Fd is the
result of replacing every free occurrence of x in
F with d - Example Again consider KB
- x(bird(x) Ù flies(x)) is entailed by KB, since
bird(tweety) Ù flies(tweety), is true in every
model of KB (taking d tweety)
25Proof Theory of FOPC10
- The rules of inference for propositional logic
still apply in the context of FOPC - And-Introduction (AI)
- And-Elimination (AE)
- Or-Introduction (OI)
- Negation-Elimination(NE)
- Modes Ponens (MP)
- In addition we have inference rules
- for quantifiers
- Universal Instantiation (UI)
- where, t is a term replacing free occurrences
- of x in F (x must not occur in t)
- Existential Instantiation (EI)
- where, f is a new function symbol, and y
- is a free variable (not quantified in F)
The formula F is derivable (provable) from KB,
if 1. F is already in KB (a fact or axiom) 2. F
is the result of applying a rule of inference
to sentences derivable from KB
26Universal / Existential Instantiation11
- Universal Instantiation (UI)
- where, t is a term replacing free occurrences
- of x in F (x must not occur in t)
- Example
- From "y(likes(jean,y)) we can infer
likes(jean,joe), likes(joe, mother_of(joe)), etc
27Universal / Existential Instantiation11
- Existential Instantiation (EI)
- where, f is a new function symbol, and y
- is a free variable (not quantified in F)
- Example Consider y(likes(x,y)) we can infer
likes(x,f(x)), where f is a new function symbol
representing an object that satisfies
y(likes(x,y)) (f is called a Skolem function) - Note If there are no free variables in F, then
we can use a new constant symbol (a function with
no arguments) - Consider y"x(likes(x,y)) we can infer
"x(likes(x,a), where a is a new constant symbol
(a is called a Skolem constant)
28Example of Derivation12
- Let KB parent(john,mary), parent(john,joe),
-
- This derivation shows that KB
29Soundness and Completeness of FOPC13
- Soundness of FOPC
- given a set of sentences KB and a sentence s,
then - KB s implies KB s
- note that if s is derived from KB, but KB does
not entail s, then at least one of the inference
rules used to derive s must have been unsound - Completeness of FOPC
- given a set of sentences KB and a sentence s,
then - KB s implies KB s
- note that if s is entailed by KB, but we cannot
derive s from KB, then out inference system (set
of inference rules) must be incomplete - However, note that entailment for FOPC is
semi-decidable
30Forward and Backward Chaining
- Inference rules (e.g., resolution, generalized
Modes Ponens) can be used in forward or backward
chaining systems - Forward Chaining
- Start with KB, infer new consequences using
inference rule(s), add new consequences to KB,
continue this process (possibly until a goal is
reached) - In a knowledge-based agent this amounts to
repeated application of the TELL operation - May generate many irrelevant conclusions, so not
usually suitable for solving for a specific goal - Useful for building a knowledge base
incrementally as new facts come in - Backward Chaining
- Start with goal to be proved, apply inference
rules in a backward manner to obtain premises,
then try to solve for premises until known facts
(already in KB) are reached - This is useful for solving for a particular goal
- In a knowledge-based agent this amounts to
applications of the ASK operation - The proofs can be viewed as a tree
- root is the goal to be proved
- for each node, its children are the conjuncts
that make up the premises for a clause - see example in next slide
31Proof Trees for Backward Chaining
KB
z john
z z2
z z1
x x1
x x2
fail
x1 bob
x2 sue
z1 john
32Logical Reasoning Agents
- Recall the general template for a knowledge-based
agent
- Water-Jug Problem
- percepts may be in the form
- Precept(x, y, t), where x, y represent
- contents of 4 and 3 gallon jugs and t
- represents the current time instance
- actions may be of the form
- fill(4-gal), fill(3-gal), empty(4-gal),
- empty(3-gal), dump(4-gal, 3-gal), etc.
- e.g., agent tries to determine what is the best
action at time 7, by ASKing if - x Action(x,7), which might give an answer such
as x fill(3-gal).
loop forever Input percepts time 0 KB
tell(KB, make-sentence(percept)) action
ask(KB, action-query) Output action KB
tell(KB, make-sentence(action)) time time
1 end
33Logical Reasoning Agents
- In the simple reflex agent, the KB might include
rules that directly (or indirectly) connect
percepts with actions - e.g., Percept(x,y, t) Ù (xy ³ 4) Ù (y gt 0) Þ
Action(dump(3-gal, 4-gal), t) - However, for the agent to be able to reason about
the results of its actions in a reasonable
manner, it must be able to specify a model of the
world and how it changes
34FINAL DE CLASE