Lecture 4 PropositionalLogic 2
Lecture 4 PropositionalLogic 2
Lecture 4 PropositionalLogic 2
Propositional Logic
The standard names for these tasks are TELL and ASK,
respectively. Both INFERENCE tasks may involve inference-that is,
deriving new sentences from old
3
The Wumpus World
The wumpus can be shot by an agent, but the agent has only one
arrow.
Some rooms contain bottomless pits that will trap anyone who
wanders into these rooms (except for the wumpus, which is too big to
fall in).
Actuators: The agent can move forward, turn left by 90°, or turn
right by 90". The agent dies a miserable death if it enters a square
containing a pit or a live wumpus. (It is safe, albeit smelly, to enter a
square with a dead wunlpus.) Moving forward has no
6
The Wumpus World
Actuators: The agent can move forward, turn left by 90°, or turn
right by 90".
The agent dies a miserable death if it enters a square containing a pit
or a live wumpus. (It is safe, albeit smelly, to enter a square with a dead
wumpus.) Moving forward has no effect if there is a wall in front of the
agent.
The action Grab can be used to pick up an object that is in the same
square as the agent.
The action Shoot can be used to fire an arrow in a straight line in the
direction the agent is facing. The arrow continues until it either hits (and
hence kills) the wumpus or hits a wall. The agent only has one arrow, so
only the first Shoot action has any effect
7
The Wumpus World
9
The Wumpus World
In most instances of the wumpus world, it is possible for the agent to
retrieve the gold safely.
Occasionally, the agent must choose between going home empty-
handed and risking death to find the gold.
About 21% of the environments are utterly unfair, because the gold is
in a pit or surrounded by pits
11
The Wumpus World
Figure 7.3 The first step taken by the agent in the wumpus world. (a) The initial situation, after
percept [None, None, None, None, None]. (b) After one move, with percept [None, Breeze,
None, None, None].
12
The Wumpus World
Figure 7.3 The first step taken by the agent in the wumpus world. (a) The initial situation, after
percept [None, None, None, None, None]. (b) After one move, with percept [None, Breeze,
None, None, None].
15
The Wumpus World
The new percept in [1,2] is [Stench, None, None, None, None], resulting
in the state of knowledge shown in Figure 7.4(a). The stench in [1,2]
means that there must be a wumpus nearby.
But the wumpus cannot be in [1,1], by the rules of the game, and it
cannot be in [2,2] (or the agent would have detected a stench when it was
in [2,1]).
Therefore, the agent can infer that the wumpus is in [1,3].
The notation W! indicates this.
Moreover, the lack of a Breeze in [1,2] implies that there is no pit in
[2,2]. Yet we already inferred that there must be a pit in either [2,2] or
[3,1], so this means it must be in [3,1].
This is a fairly difficult inference, because it combines knowledge gained
at different times in different places and relies on the lack of a percept to
make one crucial step. The inference is beyond the abilities of most
animals, but it is typical of the kind of reasoning that a logical agent
does. 16
The Wumpus World
Figure 7.4 Two later stages in the progress of the agent. (a) After the third move,
with percept [Stench, None, None, None, None]. (b) After the fifth move, with percept
[Stench, Breeze, Glitter, None, None].
17
The Wumpus World
Figure 7.5 Possible models for the presence of pits in squares [1,2], [2,2], and
[3,1], given observations of nothing in [1,1] and a breeze in [2,1]. (a) Models of
the knowledge base and a1 (no pit in [1,2]). (b) Models of the knowledge base
and a2 (no pit in [2,2]). 18
The Wumpus World
The inference is beyond the abilities of most animals, but it is typical
of the kind of reasonin g that a logical agent does.
The agent has now proved to itself that there is neither a pit nor a
wumpus in [2,2], so it is OK to move there.
will not show the agent's state of knowledge at [2,2]; we just assume
that the agent turns and moves to [2,3], giving us Figure 7.4(b). In [2,3],
the agent detects a glitter, so it should grab the gold and thereby end the
game.
In each case where the agent draws a conclusion from the available
information, that conclusion is guaranteed to be correct if the available
information is correct. This is a fundamental property of logical
reasoning.
19
Introduction
• Representing Facts-the language of logic
• Logical formalism is appealing because it immediately suggests a
powerful way of deriving new knowledge from old
-mathematical deduction
a new statement is true by proving that it follows from the statements
that are already known.
Deductions as a way of deriving answers to questions & solutions to
problems
(and)
Logic symbols: (for all)
(material implication) ` : ( there exist)
(not)
(or)
Logic in general
• 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;
i.e., define truth of a sentence in a world
E.g., the language of arithmetic
x + 2 y is a sentence; x2 + y > is not a sentence
x + 2 y is true in the number x + 2 is no less than the number y
x + 2 y is true in a world where x=7; y =1
x + 2 y is false in a world where x=0; y =6
Models
• Logicians typically think in terms of models, which are formally structured
worlds with respect to which truth can be evaluated
We say m is a model of a
sentence α if α is true in m
M(α) is the set of all models of α
23
Propositional Logic syntax is a combination of
Propositions and
Logical connectives
Propositional
A proposition – a sentence that can be either true or false but not
both
.
• Propositions:
x is greater than y
Noam wrote this letter
It is raining
My car is painted silver
John and Sue have five children
Snow is white
People live on the moon
25
Logical connectives and their symbols
Logical connectives Symbol
Not or Negation ~
And or Conjunction &
Or or Disjunction
If… Then or Implication
If and only If or Double Implication
Biconditional
The logical disjunction, or logical Or, is true if one or both of the propositions are
true.
Examples p q pq pq
It is raining or it is the second lecture 0 0 0
(2+2=5) (1<2)
You may have cake or ice cream 0 1 0
1 0 0
1 1 1
Exclusive Or, Implication
• The exclusive Or, or XOR, of two propositions is true when exactly one of the
propositions is true and the other one is false
• Example p q pq pq pq
– The circuit is either ON or OFF but not both 0 0 0 0
– Let ab<0, then either a<0 or b<0 but not both
0 1 0 1
– You may have cake or ice cream, but not both
• Truth table 1 0 0 1
1 1 1 1
Definition: Let p and q be two propositions. The implication pq is the proposition that is
false when p is true and q is false and true otherwise
1 0 0 1 1 False
1 1 1 1 0 True
Logical Connective: Implication
• The implication of pq can be also read as
– If p then q
– p implies q
– If p, q
– p only if q
– q if p
– q when p
– q whenever p
– q follows from p
– p is a sufficient condition for q (p is sufficient for q)
– q is a necessary condition for p (q is necessary for p)
Examples
If you buy you air ticket in advance, it is cheaper.
If x is an integer, then x2 0.
If it rains, the grass gets wet.
If 2+2=5, then all unicorns are pink.
Exercise: Which of the following implications is true?
• If sin x = 0, then x = 0
False. x can be a multiple of . If we let x=2, then sin x=0 but x0.
The implication “if sin x = 0, then x = k, for some k” is true.
Logical Connective: Biconditional (1)
• Definition: The biconditional pq is the proposition that is true when p and q have the
same truth values. It is false otherwise.
p q pq pq pq pq p
• Note that it is equivalent to (pq)(qp)
0 0 0 0 0 1
0 1 0 1 1 1
1 0 0 1 1 0
1 1 1 1 0 1
A complex sentence:
34
Truth Tables III
Construct the truth table for the following compound
proposition
(( p q ) q )
p q pq q (( p q ) q )
0 0 0 1 1
0 1 0 0 0
1 0 0 1 1
1 1 1 0 1
Example: DeMorgans
Prove that: p (q r) (p q) (p r)
– T and F are special symbols having the values true and false.
Propositional logic: Syntax
• Propositional logic is the simplest logic – illustrates basic ideas
2. p(x) denote “x>0” and the domain be the integer then P(-3)=? P(0)=? P(3)=?
3. Let “x+y=z” be dentoed by R(x,y,z) and U is integer find these truth value
R(2,-1,5)=? R(3,4,7)=?
4. Let “x-y=z” be denoted by Q(x,y,z), R(x,3,z)=? with U as the integers. Find the truth values
Q(x,3,z)=? Q(2,-1,3)=? Q(3,4,7)=?
Predicate Calculus
• Predicate calculus allows us to reason about properties of objects
and relationships between objects.
“I like cheese” A. ¬ A “I do not like cheese,”
predicate calculus, we use predicates to express properties of
objects.
L(me, cheese)
where L is a predicate that represents the idea of “liking.”
expresses a relationship between me and cheese.
This can be useful, as we will see, in describing environments for
robots and other agents
Block A is on top of Block B. T(A,B)
For example, to express the idea that everyone likes cheese, we
might say (x)(P(x)→L(x, C))
Compound Proposition
• Connectives from propositional logic carry over to predicate logic,
If P(x) denote “x>0” find these truth values
d. e. P(3) P(y)=? f.
Representing Simple Facts in Logic
• Propositional Logic (PPL): a way of
representing real world knowledge
• Appealing because it is simple to deal with & a
decision procedure for it exists
• Real world facts can be represented easily
using prepositions logic
• Written as well-formed formulas (wff’s)
An Example
• It is raining: RAINING
• It is sunny: SUNNY
• It is windy: WINDY
N(R), we are saying that a property of the rain is that it is in New York, whereas with R(N) we are
saying that a property of New York
is that it is raining.
“it is raining in New York, and I’m either getting sick or just very tired” can be expressed as
follows: R(N) ∧(S(I) ∨T(I))
Translating between English and Logic
47
Translating between English and Logic
¬ operator is applied exactly as you would expect—to express negation.
For example, It is not raining in New York, expressed as ¬ R(N)
“I’m either not well or just very tired” would be translated as ¬ W(I) ∨T(I)
T & ~F
𝑓 ∨ 𝑡 ′
t
54
Example
• Let assign true to P , false to Q and false to R in statement
((P & -Q) →R)VQ.
• What is the meaning of the statement?
Answer:
• Rule 2 gives - Q as true.
• Rule 3 gives (P & -Q) as true.
• Rule 6 gives (P & -Q) →R as false.
• Rule 5 gives the statement ((P & -Q) →R)VQ value as false.
55
Assignment
• Find the meaning of the statement
(-PVQ)&R→SV(-R&Q)
for each of the interpretations given below.
• (a). I1 : P is true, Q is true, R is false, S is true.
• (b). I2 : P is true, Q is false, R is true, S is true.
56
Example
57
Example
58
Example
• Find the meaning of the following statement:
• ~(P V ~Q) & (R → S) for the interpretation given bellow:
• I: P is true, Q is false, R is true and S is false.
Answer:
• Rule 2 gives -Q as true.
• Rule 4 gives (P V -Q) as true.
• Rule 4 gives ~(P V -Q) as false.
• Rule 6 gives (R → S) as false.
• Rule 3 gives the statement ~(P V ~Q) & (R → S) value as false.
59
Different cases of implication
62
Logical equivalence
• Two sentences are logically equivalent iff true
in same models: α ≡ ß iff α╞ β and β╞ α
Validity and satisfiability
A sentence is valid if it is true in all models,
e.g., True, A A, A A, (A (A B)) B
66
Using Logical Equivalences: Example 1
72
Rules of Inference
73
Inference rules. Modus Ponens:
From P and P → Q infer Q. This sometimes written as
P
P →Q
Q
P→Q
P
• Another useful inference rule is And-Eliminatio Which, says
that, from a conjunction, any of the conjuncts can be inferred:
For example, from ( WumpusAhead A WumpusAlive), WumpusAlive
can be inferred.
75
Example For Modus Ponens:
76
77
Chain Rule hypothetical Syllogism
• Form P → Q and Q→ R, infer P→R.
Or
P→Q
Q→R
P→R
78
Logical equivalence vs. inference
By using inference rules, we can “prove” the conclusion follows
from the premises. In inference, we can always replace a logic
formula with another one that is logically equivalent, just as we have
seen for the implication rule.
79
80
3rd Disjunction rule
81
82
83
84
85
86
First Order Periodic Logic
• We
need quantifiers to express the meaning of English words
including all and some.
• “All men are mortal”
• “Some cats do not have fur”
• The two most important quantifiers are:
• Universal quantifier,, “For all”, symbol:
• Existential Quantifier, “there exists,”:
• The semantics of FOPL are determined by interpretations assigned to predicates, rather than
propositions.
Examples:
1. If P(x) denotes “x>=0” and U is the integers, then is false, We can use P(-2) as a
counterexample.
2. If P(x) denotes “x>=0” and U is the positive integers, then is true.
3. If P(x) denotes “x is even” and U is the integers, then is false. We can use P(3) as a
counterexample.
• Existential quantification
– ( x)P(x) means that P holds for some value of x in the domain associated with that
variable
– E.g., ( x) mammal(x) lays-eggs(x)
– Permits one to make a statement about some object without naming it
93
Connections between All and Exists
We can relate sentences involving and using De
Morgan’s laws:
(x) P(x) ↔ (x) P(x)
(x) P ↔ (x) P(x)
(x) P(x) ↔ (x) P(x)
(x) P(x) ↔ (x) P(x)
94
Syntax of FOPL
• Functions:
• which are a subset of relations where there is only one “value”
for any given “input”
• Function symbols denote relations defined on a domain D. They
map n elements (n≥0) to a single element of the domain.
• Symbols f , g, & h, and words such as father-of , or age-of,
represent functions.
• An n place (n-ary) function is written as f(t1, t2, t3, .. .. .. tn) where
the ti are terms (constants, variables, or functions) defined over
some domain. A 0-ary function is a constant.
• Brother-of, bigger-than, outside, part-of, has-color, occurs-after,
owns, visits, precedes, ..
95
Syntax of FOPL
• An atomic formula is a wffs (well-formed formulas) .
• If P and Q are wffs, then ~P, P & Q, P V Q, P
P↔Q, x P(x), and x P(x) are wffs.
• Wffs are formed only by applying the above rules a finite
number of times.
• The above rules state that all wffs are formed from
atomic formulas and the proper application of
quantifiers and logical connections.
96
Syntax of FOPL
• Some examples of valid wffs are
• MAN(john)
• PILOT(father-of(bill))
• xyz((FATHER(x,y)&FATHER(y,z))
→GRANDFATHER(x,z))
• x NUMBER(x) →(y GREATER-THAN(y,x))
97
Quantified inference rules
Rules of inference start to be more useful when applied to quantified
statements.
Rules for quantified statements:
• Universal instantiation
– x P(x) P(C)
• Universal generalization
– P(C) P(B) … x P(x)
• Existential instantiation
– x P(x) P(C) skolem constant F
• Existential generalization
– P(C) x P(x)
98
Quantified inference rules
Prove things that are maybe less obvious. e.g.
“Students who pass the course either do the homework or attend lecture
“Bob did not attend every lecture;” “Bob passed the course.”
99
Quantified inference rules
Prove things that are maybe less obvious. e.g.
“Students who pass the course either do the homework or attend lecture
“Bob did not attend every lecture;” “Bob passed the course.”
100
Quantified inference rules
e.g.S1= “Bob failed the course, but attended every lecture;”
S2=“everyone who did the homework every week passed the course;”
s3=“if a student passed the course, then they did some of the
homework.”
B =bob W=week H=homework
P=pass
We want to conclude that not every student submitted every
homework assignment.
Translate into logic as (domain for s being students in the course and
w being weeks of the semester):
101
Quantified inference rules
102
Translating English to FOL
Every gardener likes the sun.
x gardener(x) likes(x,Sun)
You can fool some of the people all of the time.
x t person(x) time(t) can-fool(x,t)
You can fool all of the people some of the time.
x t (person(x) time(t) can-fool(x,t))
All purple mushrooms are poisonous. Equivalent
x (mushroom(x) purple(x)) poisonous(x)
No purple mushroom is poisonous.
x (mushroom(x) purple(x)) poisonous(x)
Clinton is not tall.
tall(Clinton)
103
Translating between English and Logic Notation
• E1’:
x(( E ( x) & GE (i ( x),1400)) T ( x))
FOPL
• E2’: y ( E ( y ) S ( y ))
112
Conversion to Clause Form
4. Move all quantifiers to the left without changing their relative order.
(xP(x)) (y Q(y)) xy(P(x) (Q(y))
5. Eliminate (Skolemization).
x P(x) P(c) Skolem constant
x:y P(x, y) xP(x, f(x)) Skolem function
6. Drop .
xP(x) P(x)
7. Convert the formula into a conjunction of disjuncts.
(P Q) R (P R) (Q R)
8. Create a separate clause corresponding to each conjunct.
9. Standardize apart the variables in the set of obtained clauses.
113
Example
• x y z P(f(x), y, z) (u Q( x, u) & v R( y, v))