Mod 4 Highlighted
Mod 4 Highlighted
Logical Agents – Knowledge based agents, Logic, Propositional Logic, Propositional Theorem proving,
Agents based on Propositional Logic. First Order Predicate Logic – Syntax and Semantics of First Order
Logic, Using First Order Logic, Knowledge representation in First Order Logic. Inference in First Order
Logic – Propositional Vs First Order inference, Unification and Lifting, Forward chaining, Backward
chaining, Resolution.
Logical Agents
The idea is that an agent can represent knowledge of its world, its goals and the current situation by
sentences in logic and decide what to do by inferring that a certain action or course of action is
appropriate to achieve its goals.
Knowledge-Based Agents
Central component of a Knowledge-Based Agent is a Knowledge-Base
It is a set of sentences in a formal language
Sentences are expressed using a knowledge representation language
Two generic functions:
– TELL - add new sentences (facts) to the KB • “Tell it what it needs
to know”
– ASK - query what is known from the KB • “Ask what to do next”
1
Performance Measure: Performance measure is the unit to define the success of an agent.
Performance varies with agents based on their different precepts.
Environment: Environment is the surrounding of an agent at every instant. It keeps changing
with time if the agent is set in motion.
Actuator: An actuator is a part of the agent that delivers the output of action to the environment.
Sensor: Sensors are the receptive parts of an agent that takes in the input for the agent.
A simple knowledge-based agent
Logic
Logics are formal languages for representing information such that conclusions can be drawn
Syntax defines the sentences in the language
Semantics define the "meaning" of sentences; define truth of each sentence with respect to each possible
world
E.g., the language of arithmetic
x+2 ≥ y is a sentence
x2+y > {} is not a sentence
x+2 ≥ y is true iff the number x+2 is no less than the number y
x+2 ≥ y is true in a world where x = 7, y = 1
2
Model- “possible world, mathematical abstractions, each of which simply fixes the truth or falsehood
of every relevant sentence
Possible worlds- real environments that the agent might or might not be in
If a sentence α is true in model m, we say that m satisfies α or sometimes m is a model of α.
We use the notation M(α) to mean the set of all models of α
Entailment
Entailment means a sentence follows logically from another : to mean that the sentence α entails the
sentence β
α |= β if and only if, in every model in which α is true, β is also true
α |= β if and only if M(α) ⊆ M(β) .
Knowledge base KB entails sentence α if and only if α is true in all worlds where KB is true
Eg. the KB containing “the Phillies won” and “the Reds won” entails “Either the Phillies won or the
Reds won”
Eg. x+y = 4 entails 4 = x+y
Entailment is a relationship between sentences (i. e. , syntax) that is based on semantics
Inference and Entailment
Inference is a procedure that allows new sentences to be derived from a knowledge base. Understanding
inference and entailment: think of Set of all consequences of a KB as a haystack, α as the needle,
Entailment is like the needle being in the haystack and Inference is like finding it.
if an inference algorithm i can derive α from KB, we write
3
Sound and Truth Preserving Inference
An inference algorithm that derives only entailed sentences is called sound or truth preserving.
Soundness is a highly desirable property. An unsound inference procedure essentially makes things up
as it goes along—it announces the discovery of nonexistent needles. It is easy to see that model
checking, when it is applicable is a sound procedure. The property of completeness is also desirable: an
inference algorithm is complete if it can derive any sentence that is entailed
A reasoning process whose conclusions are guaranteed to be true in any world in which the premises
are true; in particular, if KB is true in the real world, then any sentence α derived from KB by a sound
inference procedure is also true in the real world
4
◦ A literal is either an atomic proposition or its negation. E.g., W1,3 is a positive literal,
and ¬W1,3 is a negative literal.
◦ Conjunction p1 ∧ p2. E.g., W1,3 ∧ P3,1
◦ Disjunction p1 ∨ p2 E.g., W1,3 ∨ P3,1
Truth Table
The semantics define the rules to determine the truth of a sentence.
5
Precedence of operators
1. Expressions in parentheses are processed (inside to outside)
2. Negation
3. AND
4. OR
5. Implication
6. Biconditional
7. Left to right
Use parentheses whenever you have any doubt!
Logical Equivalence
Two propositions p and q are logically equivalent if and only if the columns in the truth table giving
their truth values agree. We write this as p ⇔ q or p ≡ q.
pq is equivalent to ¬pvq
Properties
Commutativity:
p∧q=q∧p
p∨q=q∨p
Associativity:
p ∧ q) ∧ r = p ∧ (q ∧ r)
(p ∨ q) ∨ r = p ∨ (q ∨ r)
Identity element:
p ∧ T rue = p
p ∨ T rue = T rue
¬(¬p) = p
p∧p=pp∨p=p
Distributivity:
p ∧ (q ∨ r) = (p ∧ q) ∨ (p ∧ r)
6
p ∨ (q ∧ r) = (p ∨ q) ∧ (p ∨ r)
p ∧ (¬p) = False and p ∨ (¬p) = T rue
DeMorgan’s laws:
¬(p ∧ q) = (¬p) ∨ (¬q)
¬(p ∨ q) = (¬p) ∧ (¬q)
Converse statement would be: “If the grass is wet, then it is raining.”
Inverse statement would be: “If it is NOT raining, then the grass is NOT wet.”
Contrapositive statement would be: “If the grass is NOT wet, then it is NOT raining.”
Inference (Modus Ponens)
7
For example, if (WumpusAhead ∧WumpusAlive) ⇒ Shoot and (WumpusAhead ∧ WumpusAlive) are
given, then Shoot can be inferred
Modus Tollens
From a conjunction, any of the conjuncts can be inferred. For example, from (WumpusAhead ∧
WumpusAlive), WumpusAlive can be inferred.
8
DNF and CNF
DNF: Disjunctive Normal Form, OR of ANDs (terms)
e.g. (p∧¬q) ∨ (¬p∧¬r)
CNF: Conjunctive Normal Form
“Every sentence of propositional logic is logically equivalent to a conjunction of clauses”. AND of ORs
(clauses)
e.g. (p∨¬q) ∧ (¬p∨¬r)
Definite clauses
9
Horn Clause
10
AGENTS BASED ON PROPOSITIONAL LOGIC: Wumpus world – Knowledge Base
Atomic propositions
14
Room[1,1], room does not have wumpus(¬ W11), no stench (¬S11), no Pit(¬P11), no breeze(¬B11),
no gold (¬G11), visited (V11), and the room is Safe(OK11).
Inference
Prove that Wumpus is in the room (1, 3) using propositional rules which have been derived for the
Wumpus world and using inference rule.
¬ W31
15
Apply Modus Ponens to S12 and R4 which is S12 → W13 ∨. W12 ∨. W22 ∨.W11, we will get the output
as W13∨ W12 ∨ W22 ∨.W11.
16
First-Order Logic (FOL)
It is an extension to propositional logic. FOL is sufficiently expressive to represent the natural language
statements in a concise way. First-order logic is also known as Predicate logic or First-order predicate
logic.
First-order logic (FOL) models the world in terms of
Objects, which are things with individual identities
Properties of objects that distinguish them from other objects
Relations that hold among sets of objects
Functions, which are a subset of relations where there is only one “value” for any given “input”
Examples:
Objects: Students, lectures…
Relations: Brother-of, bigger-than, outside..
Properties: blue, oval, even, large, ...
Functions: father-of, best-friend, second-half, one-more-than ...
FOL is also called as Predicate Logic. It is a generalization of Propositional Logic that allows us to
express and infer arguments in infinite models, Eg,
Some birds can fly
All men are mortal
At least one student has course registered
Terms
A term is a logical expression that refers to an object. Constant symbols are therefore terms, but it is
not always convenient to have a distinct symbol to name every object. For example, in English we might
17
use the expression “King John’s left leg” rather than giving a name to his leg. This is what function
symbols are for: instead of using a constant symbol, we use LeftLeg(John).
Consider a term f(t1,...,tn). The function symbol f refers to some function in the model (call it F); the
argument terms refer to objects in the domain (call them d1,...,dn); and the term as a whole refers to the
object that is the value of the function F applied to d1,...,dn.
universal and
existential.
18
∀ is usually pronounced “For all ...”.
The symbol x is called a variable. A variable is a term all by itself, and as such can also serve as the
argument of a function—for example, LeftLeg(x). A term with no variables is called a ground term.
∀ x, y Sibling(x, y) ⇔ Sibling(y, x) .
In other cases we will have mixtures. “Everybody loves somebody” means that for every person, there
is someone that person loves:
∀ x ∃ y Loves(x, y) .
On the other hand, to say “There is someone who is loved by everyone,” we write
∃ y ∀ x Loves(x, y) .
says that everyone has a particular property, namely, the property that they love someone. On the other
hand, ∃ y (∀ x Loves(x, y)) says that someone in the world has a particular property, namely the property
of being loved by everybody
19
Asserting that everyone dislikes parsnips is the same as asserting there does not exist someone who
likes them, and vice versa:
∀ x ¬Likes(x,Parsnips ) is equivalent to ¬∃ x Likes(x,Parsnips) .
“Everyone likes ice cream” means that there is no one who does not like ice cream:
Equality
We can use the equality symbol to signify that two terms refer to the same object.
For example, Father (John) = Henry
says that the object referred to by Father (John) and the object referred to by Henry are the same.
Because an interpretation fixes the referent of any term, determining the truth of an equality sentence is
simply a matter of seeing that the referents of the two terms are the same object.
To say that Richard has at least two brothers, we would write
20
21
Free and Bound Variable
There are two types of variables in First-order logic which are given below:
Free Variable: A variable is said to be a free variable in a formula if it occurs outside the scope of the
quantifier.
Predicate symbol must be same, atoms or expression with different predicate symbol can never
be unified.
Number of Arguments in both expressions must be identical.
Unification will fail if there are two similar variables present in the same expression.
The Unification Algorithm
26
Inference engine
The inference engine is the component of the intelligent system in artificial intelligence, which applies
logical rules to the knowledge base to infer new information from known facts. Inference engine
commonly proceeds in two modes, which are:
Forward chaining
Backward chaining
Forward Chaining
Forward chaining is a form of reasoning which start with atomic sentences in the knowledge base and
applies inference rules (Modus Ponens) in the forward direction to extract more data until a goal is
reached. The Forward-chaining algorithm starts from known facts, triggers all rules whose premises are
satisfied, and add their conclusion to the known facts. This process repeats until the problem is solved.
Given a new fact, generate all consequences
Assumes all rules are of the form C1 and C2 and C3 and…. --> Result. Each rule & binding generates
a new fact This new fact will “trigger” other rules. Keep going until the desired fact is generated. (Semi-
decidable as is FOL in general)
FC: Example Knowledge Base
The law says that it is a crime for an American to sell weapons to hostile nations. The country Nono,
an enemy America, has some missiles, and all of its missiles were sold to it by Col. West, who is an
American.
Prove that Col. West is a criminal.
38
Backward Chaining
Back Chaining considers the item to be proven a goal. Find a rule whose head is the goal (and bindings).
Apply bindings to the body, and prove these (subgoals) in turn. If you prove all the subgoals, increasing
the binding set as you go, you will prove the item.
39
40
41