Lecture 4 PropositionalLogic 2

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 116

LOGICAL AGENTS/

Propositional Logic

Abu Saleh Musa Miah


Assist. Professor, Dept. of CSE, BAUST, Bangladesh
email: musa@baust.edu.bd, tel: +8801734264899
web: www.baust.edu.bd/cse 1
Knowledge Representation and Reasoning

 Perceiving, that is, acquiring information from environment,


 Knowledge Representation, that is, representing its
understanding of the world,
 Reasoning, is the use of symbolic representations of some
statements in order to derive new ones
 Predicate logic is the generic term for symbolic formal systems
like first-order logic, second-order logic, many-sorted logic, or
infinitary logic.

 The logical language, in turn, has two aspects,


 Syntax
 Semantics
2
Knowledge Based Agent

The central component of a knowledge-based agent is its


knowledge base, or KB. Informally, SENTENCE a knowledge base
is a set of sentences. (Here "sentence" is used as a technical term. It
is related but is not identical to the sentences of English and other
natural languages.)

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

A typical wurnpus world. The agent is in the bottom left


corner. 4
The Wumpus World
The wumpus world is a cave consisting of rooms connected by
passageways.
Looking somewhere in the cave is the wumpus, a beast that eats
anyone who enters its room.

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).

 The only mitigating feature of living in this environment is the


possibility of finding a heap of gold.

Although the wumpus world is rather tame by modern computer game


standards, it makes an excellent testbed environment for intelligent5
The Wumpus World
Performance measure: +I000 for picking up the gold, -1000 for
falling into a pit or being eaten by the wumpus, -1 for each action taken
and -10 .for using up the arrow.

Environment: A 4 x 4 grid of rooms. The agent always starts in the


square labeled [1,1], facing to the right. The locations of the gold and
the wumpus are chosen randomly, with a uniform distribution, from the
squares other than the start square. In addition, each square other than
the start can be a pit, wnth probability 0.2.

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

A typical wurnpus world. The agent is in the bottom left


corner. 8
The Wumpus World
Sensors: The agent has five sensors, each of which gives a single bit
of information:
In the square containing the wumpus and in the directly (not
diagonally) adjacent squares the agent will perceive a stench.
In the squares directly adjacent to a pit, the agent will perceive a
breeze.
In the square where the gold is, the agent will perceive a glitter.
When an agent walks into a wall, it will perceive a bump.
When the wumpus is killed, it emits a woeful scream that can be
perceived anywhere in the cave.

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

Let us watch a knowledge-based wumpus agent exploring the


environment shown in Figure 7.2.
The agent's initial knowledge base contains the rules of the environment,
as listed previously; in particular, it knows that it is in [1,1] and that [1,1]
is a safe square.
We will see how its knowledge evolves as new percepts arrive and
actions are taken.
10
The Wumpus World
The first percept is [None, None, None, None, None], from which the
agent can conclude that its neighboring squares are safe.
Figure 7.3(a) shows the agent's state of knowledge at this point.
We list (some of) the sentences in the howledge base using letters such
as B (breezy) and OK (safe, neither pit nor wumpus) marked in the
appropriate squares.
Figure 7.2, on the other hand, depicts the world itself.

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

A typical wurnpus world. The agent is in the bottom left


corner. 13
The Wumpus World
From the fact that there was no stench or breeze in [1,1], the agent can
infer that [1,2] and [2,1] are free of dangers.
They are marked with an OK to indicate this.
A cautious agent will move only into a square that it knows is OK. Let
us suppose the agent decides to move forward to [2,1], giving the scene
in Figure 7.3(b).
The agent detects a breeze in [2,1], so there must be a pit in a
neighboring square.
The pit cannot be in [I, 1], by the rules of the game,
 so there must be a pit in [2,2] or [3,1] or both.
The notation P? in Figure 7.3(b) indicates a possible pit in those
squares.
 At this point, there is only one known square that is OK and has not
been visited yet. So the prudent agent will turn around, go back to [I, 11,
and then proceed to [1,2]. 14
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 α

Then KB ╞ α iff M(KB)  M(α)


E.g. KB = Giants won and Reds
won α = Giants won
Syntax and semantics for PL
 Valid statements in PL are determined according to the rules of
propositional syntax.
 Syntax: Consist of a single proposition symbol
 Simple Propositions:
 It is raining
 My car is painted silver
 Snow is white
Compound:
It is raining and the wind is blowing
The sum of 10 and 20 is not 50;
Stands for propositions: T and F –True and False

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

We usually denote a proposition by a letter: p, q, r, s, …

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

 Truth tables are used to show/define the relationships


between the truth values of
 the individual propositions and
 the compound propositions based on them
Propositional Semantic
• Definition: The value of a proposition is called its truth value;
denoted by p
– T or 1 if it is true or
0
– F or 0 if it is false 1

Negation: p, the negation of a proposition p, is also a proposition


Examples:
Today is not Monday
p p
It is not the case that today is Monday, etc.
0 1
1 0
Logical And, Logical Or
• The logical connective And is true only when both of the propositions are true. It is also
called a conjunction p q
• Examples pq
0 0
– It is raining and it is warm
– (2+3=5) and (1<2) 0 1
– Schroedinger’s cat is dead and Schroedinger’s is not dead.
1 0
1 1

The logical disjunction, or logical Or, is true if one or both of the propositions are
true.
Examples p q pq pq
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 pq pq pq
– 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 pq is the proposition that is
false when p is true and q is false and true otherwise

p is called the hypothesis, antecedent, premise p q pq pq pq pq


q is called the conclusion, consequence
0 0 0 0 0 True
0 1 0 1 1 True

1 0 0 1 1 False
1 1 1 1 0 True
Logical Connective: Implication
• The implication of pq 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 -1 is a positive number, then 2+2=5


True. The premise is obviously false, thus no matter what the conclusion is, the
implication holds.
• If -1 is a positive number, then 2+2=4

True. Same as above.

• If sin x = 0, then x = 0

False. x can be a multiple of . If we let x=2, then sin x=0 but x0.
The implication “if sin x = 0, then x = k, for some k” is true.
Logical Connective: Biconditional (1)
• Definition: The biconditional pq is the proposition that is true when p and q have the
same truth values. It is false otherwise.
p q pq pq pq pq p
• Note that it is equivalent to (pq)(qp)
0 0 0 0 0 1
0 1 0 1 1 1
1 0 0 1 1 0
1 1 1 1 0 1

The biconditional pq can be equivalently read as


p if and only if q
p is a necessary and sufficient condition for q
if p then q, and conversely
p iff q (Note typo in textbook, page 9, line 3)
Examples
x>0 if and only if x2 is positive
The alarm goes off iff a burglar breaks in
You may have pudding iff you eat your meat
Exercise: Which of the following biconditionals is
true?

• x2 + y2 = 0 if and only if x=0 and y=0


True. Both implications hold
• 2 + 2 = 4 if and only if 2<2

True. Both implications hold.


• x2  0 if and only if x  0

False. The implication “if x  0 then x2  0” holds.


However, the implication “if x2  0 then x  0” is false.
Consider x=-1.
The hypothesis (-1)2=1  0 but the conclusion fails.
Truth tables II
The five logical connectives:
p q pq pq pq pq pq
0 0 0 0 0 1 1
0 1 0 1 1 1 0
1 0 0 1 1 0 0
1 1 1 1 0 1 1

A complex sentence:

34
Truth Tables III
 Construct the truth table for the following compound
proposition
(( p  q ) q )
p q pq 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)  (p  q)


pq (pq) (pq) p q (p  q)
TT T F F F F
TF T F F T F
FT T F T F F
FF F T T T T
Example: Distribution

Prove that: p  (q  r)  (p  q)  (p  r)

p q r qr p(qr) pq pr (pq)(pr)


T T T T T T T T
T T F F T T T T
T F T F T T T T
T F F F T T T T
F T T T T T T T
F T F F F T F F
F F T F F F T F
F F F F F F F F
Compound Proposition

 It is raining and wind is blowing


 The moon I made of green cheese or it is
not
 If you study hard (then) you will be
rewarded
 The sum of 10 and 20 is not 50

– T and F are special symbols having the values true and false.
Propositional logic: Syntax
• Propositional logic is the simplest logic – illustrates basic ideas

• The proposition symbols P1, P2 etc are sentences

If S is a sentence, S is a sentence (negation)



– If S1 and S2 are sentences, S1  S2 is a sentence (conjunction)

– If S1 and S2 are sentences, S1  S2 is a sentence (disjunction)

– If S1 and S2 are sentences, S1  S2 is a sentence (implication)

– If S1 and S2 are sentences, S1  S2 is a sentence (biconditional)
Propositional logic: Semantics
Each model specifies true/false for each proposition symbol

E.g. P1,2 P2,2 P3,1


false truefalse

(With these symbols, 8 possible models, can be enumerated automatically)

Rules for evaluating truth with respect to a model m:

S is true iff S is false


S1  S2 is true iff S1 is true and S2 is true
S1  S2 is true iff S1is true or S2 is true
S1  S2 is true iff S1 is false or S2 is true
i.e., is false iff S1 is true and S2 is false
S1  S2 is true iff S1S2 is true and S2S1 is true

Simple recursive process evaluates an arbitrary sentence, e.g.,

P1,2  (P2,2  P3,1) = true  (true  false) = true  true = true


Predicate Calculus

1. Suppose “x<2” ,P(x) become a proposition and have truth value

Example: What is the truth value of P(1) and P(2)?

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

a. P(3) P(-1)=? b. P(3)P(-1)=? c.

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

• If it is raining, then it is not sunny


RAININGSUNNY
Translating between English and Logic
convert facts and rules about the real world into logical expressions using the logical operators.
First, we will consider the simple operators, ∧, ∨, and ¬

“It is raining and it is Tuesday.”


might be expressed as: R ∧T
Where R means “it is raining” and T means “it is Tuesday.”
it is raining in New York” as: N(R)
We might equally well choose to write it as: R(N)

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

• P means “It is hot.”


• Q means “It is humid.”
• R means “It is raining.”
• (P  Q)  R
“If it is hot and humid, then it is raining”
• QP
“If it is humid, then it is hot”
• A better way:
Hot = “It is hot”
Humid = “It is humid”
Raining = “It is raining”

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)

 “if it is raining then I will get wet.”


 This sentence might be translated into logic as R→W(I)
This is read “R implies W(I)” or “IF R THEN W(I)”.
 “raining implies I’ll get wet” or “IF it’s raining THEN I’ll get wet.”
 Implication can be used to express much more complex concepts than this.

For example, “Whenever he eats sandwiches that have pickles in them, he ends up
either asleep at his desk or singing loud songs”
S(y) means that y is a
S(y) ∧E(x, y) ∧P(y)→A(x) ∨(S(x, z) ∧L(z)) sandwich.
E(x
y)
means that x (the man) eats y (the sandwich).
P(y) means that y (the sandwich) has pickles in it.
A(x) means that x ends up asleep at his desk.
S(x, z) means that x (the man) sings z (songs).
L(z) means that z (the songs) are loud.
Translating between English and Logic
 Fish (x) ∧living (x) →has_scales (x)
 single letters to represent logical variables acceptable to use
longer variable names,
QUICK TASK
 truth table can be used to display the possible values for A ∧(B ∨C)

 Using truth table prove that are equivalent


P  Q and ( P  Q ) & (Q  P )
Limitation of PPL
• Socrates is a man: SOCRATESMAN
• Plato is a man: PLATOMAN
• Which would be a totally separate assertion,
-not be able to draw any conclusions about the similarities between
Socrates & Plato
• Much better
MAN(SOCRATES)
MAN(PLATO) Structure of the representation
reflects the structure of the
knowledge itself
Limitation of PPL
• to use predicates applied to arguments.
• More difficult:
All men are mortal: MORTALMAN
-fails to capture the relationship between any individual being a
man & that individual being a mortal
-need variables & quantification unless we are willing to write
separate statements about the morality of every known man
Predicate logic (First order predicate logic-FOPL) is needed to
represent fact
Semantics

The semantics or meaning of a sentence is just


the value true or false: that is, it is as
assignment of a truth value to the sentences.

Having specified the syntax of propositional


logic, we now specify its semantics

An interpretation for a sentence or group of


sentences in an assignment of the truth value to
each propositional symbol. 53
Semantic Rules for statements
Consider t and f' denotes true statements, f and t' denotes false statements, and
a is any statement.

T & ~F

 𝑓 ∨ 𝑡 ′

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

• 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.

57
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.

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

Consider the proposition p  q


–Its converse is the proposition q  p
–Its inverse is the proposition p  q
–Its contrapositive is the proposition q  p
Properties of Statement
Satisfiable: Some interpretation which is true
Equivalence: Two sentences are equivalent if they have the
same truth value under every interpretations.
Tautology : A compound proposition that is always true, no
matter what the truth values of the propositions that occur in it is
called a tautology
P V ~P
Contradiction: A compound proposition that is always false is
called a contradiction
P & ~P

Contingency: A proposition that is neither a tautology nor a


contradiction is a contingency
Logical Consequences: A sentence is a logical consequence of
another if it is satisfied by all interpretations which satisfy the
first
Example: On The above definitions:
.P V ~P is toghtology since every interpretation results in a value
of true for (P V ~P ).
P & ~P is a contradiction since every interpretation results in a
value of false for (P & ~P).
P and ~(~P) are equivalent since each has the same truth values
under every interpretation.
P is a logical consequence of (P & Q) since any interpretation for
which (P & Q) is true, P is also true.

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

Validity is connected to inference via the Deduction Theorem:


KB ╞ α if and only if (KB  α) is valid

A sentence is satisfiable if it is true in some model


e.g., A B, C

A sentence is unsatisfiable if it is true in no models


e.g., AA

Satisfiability is connected to inference via the following:


KB ╞ α if and only if (KB α) is unsatisfiable
Logical Equivalences: Example 1
Show that (Exercise 25 from Rosen)
(p  r)  (q  r)  (p  q)  r
p q r p r q r (p r)  (q  r) pq (p  q)  r
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
Table 4.2 lists some of the important laws
of PL (Some Equivalence Laws)

66
Using Logical Equivalences: Example 1

• Logical equivalences can be used to construct additional logical


equivalences
• Example: Show that (p  q) q is a tautology

• Example (Exercise 17)*: Show that (p  q)  (p  q)


Using Logical Equivalences: Example 1

• Logical equivalences can be used to construct additional logical


equivalences
• Example: Show that (p  q) q is a tautology
0. (p  q) q
1.  (p  q)  q Implication Law on 0
2.  (p  q)  q De Morgan’s Law (1st) on 1
3.  p  (q  q) Associative Law on 2
4.  p  1 Negation Law on 3
5.  1 Domination Law on 4
Using Logical Equivalences: Example 2
• Example (Exercise 17)*: Show that (p  q)  (p  q)
• Sometimes it helps to start with the second proposition (p  q)
0. (p  q)
1.  (p  q)  (q  p) Equivalence Law on 0
2.  (p  q)  (q  p) Implication Law on 1
3.  (((p  q)  (q  p))) Double negation on 2
4.  ((p  q)  (q  p)) De Morgan’s Law…
5.  ((p  q)  (q  p)) De Morgan’s Law
6.  ((p  q)  (p  p)  (q  q)  (q  p)) Distribution Law
7.  ((p  q)  (q  p)) Identity Law
8.  ((q  p )  (p  q)) Implication Law
9.  (p  q) Equivalence Law
*See Table 8 (p 25) but you are not allowed to use the table for the proof
Using Logical Equivalences: Example 3

• Show that (q  p)  (p  q)  q


Using Logical Equivalences: Example 3

• Show that (q  p)  (p  q)  q


0. (q  p)  (p  q)
1.  (q  p)  (p  q) Implication Law
2.  (q  p)  (p  q) De Morgan’s
& Double negation
3.  (q  p)  (q  p) Commutative Law
4.  q  (p  p) Distributive Law
5.  q  1 Identity Law
q Identity Law
Inference Rules
• The inference rules of PL provide the means to perform
logical proofs or deductions.

• Few Such Rules are as follows:


Modus ponens
Chain Rule

72
Rules of Inference

73
Inference rules. Modus Ponens:
From P and P → Q infer Q. This sometimes written as

P
P →Q
Q

The form P → Q and P are given then the sentence Q can be


inferred.
if ( WumpusAhead A WumpusAlive) →Shoot and ( WumpusAhead A
WumpusAlive) are given, then Shoot can be inferred. 74
Inference rules. Modus Ponens:
From P and P → Q infer Q. This sometimes written as

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:

Given: (Joe is a father) And: (Joe is a


father) → ( Joe has a child)
Conclude: (Joe has a child)

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.

All Student in CS must take Pascal John is a CS major


It is not possible in PL to conclude that john must take Pascal
Syntax Of FOPL
•is  read as “For all x, P(x) ” or “For every x, P(x) ” An element for which P(x) is false is
called a counterexample of

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.

We can see that it is important that the domain always be specified.


Existential Quantifier
Truth Values of Quantifiers
Syntax of FOPL Quantifiers
• Universal quantification
– (x)P(x) means that P holds for all values of x in the domain associated with that
variable
– E.g., (x) dolphin(x)  mammal(x)

• 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

The two quantifier symbols are  ( existential quantification) and  (universal


quantification).
Where (x) means for some x or there is an x . and (x) means for all x.
When more than one variable is being quantified by the same quantifier, such as, (x)
(y) (z), we abbreviate with a single quantifier and drop the parentheses to get xyz.
91
Quantifiers
• Universal quantifiers are often used with “implies” to form “rules”:
(x) student(x)  smart(x) means “All students are smart”

• Universal quantification is rarely used to make blanket statements


about every individual in the world:
• (x)student(x)smart(x) means “Everyone in the world is a student
and is smart”
• Existential quantifiers are usually used with “and” to specify a list
of properties about an individual:
(x) student(x)  smart(x) means “There is a student who is smart”

• A common mistake is to represent this English sentence as the FOL


sentence:
(x) student(x)  smart(x)
– But what happens when there is a person who is not a student?
92
Quantifier Scope
• Switching the order of universal quantifiers does not change the
meaning:
– (x)(y)P(x,y) ↔ (y)(x) P(x,y)

• Similarly, you can switch the order of existential quantifiers:


– (x)(y)P(x,y) ↔ (y)(x) P(x,y)

• Switching the order of universals and existentials does change


meaning:
– Everyone likes someone: (x)(y) likes(x,y)
– Someone is liked by everyone: (y)(x) likes(x,y)

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: All employees earning $1400 or more per


year pay taxes.

• E2: Some employees are sick today

• E3: No employee earns more than the


precedent
FOPL

 E(x) => x is an employee


 P(x) => x is president
 i(x) => income of x
 GE(u,v) => u is grater than v
 S(x) => x is sick today
 T(x) => x pays tax
FOPL
• E1: All employees earning $1400 or more per year pay taxes.

 E(x) => x is an employee


 P(x) => x is president
 i(x) => income of x
 GE(u,v) => u is grater than v
 S(x) => x is sick today
 T(x) => x pays tax

• E1’:
x(( E ( x) & GE (i ( x),1400))  T ( x))
FOPL

• E2: Some employees are sick today

• E2’: y ( E ( y )  S ( y ))

 E(x) => x is an employee


 P(x) => x is president
 i(x) => income of x
 GE(u,v) => u is grater than v
 S(x) => x is sick today
 T(x) => x pays tax
FOPL
• E3: No employee earns more than the precedent
• E3’: ~
xy (( E ( x ) & P ( y ))  GE ( i ( x ), i ( y )))

 E(x) => x is an employee


 P(x) => x is president
 i(x) => income of x
 GE(u,v) => u is grater than v
 S(x) => x is sick today
 T(x) => x pays tax
Conversion Of FOPL sentence to Clausal Form
• Step 1: Eliminate all implication () and
equivalency () connectives
(P  Q  ~P  Q, P  Q  (~P  Q) & (~Q 
P)

• Step 2: Move all negations (~) so that they


immediately precedes an atom
(use P in place of ~(~P) and x ~P(x) in place of
~x P(x)
Conversion Of FOPL sentence to Clausal Form
Step 3: Rename variables, if necessary, so that all
quantifiers have different variable assignments
x ( P(x)  x Q(x) ) should be renamed as x
( P(x)  y Q(y) )
Step 4: Move all universal quantifiers to the left of
the expression and put the expression into CNF
form
Step 5: Skolemize all existential quantifiers
Conversion Of FOPL sentence to Clausal
Form
Step 6: Eliminate all Universal quantifier and
conjunctions since they are retained implicitly. ( as x
P(x)  P(x) ).

 Step 7: Convert the formula into a conjunction of


disjuncts
8. Create a separate clause corresponding to each conjunct.
9. Standardize apart the variables in the set of obtained
clauses.
Conversion to Clause Form
1. Eliminate .
P  Q  P  Q
2. Reduce the scope of each  to a single term.
(P  Q)  P  Q
(P  Q)  P  Q
x: P  x: P
x: p  x: P
 P  P
3. Standardize variables so that each quantifier binds a unique variable.
(x P(x))  (x Q(x))  (x P(x))  (y Q(y))

112
Conversion to Clause Form
4. Move all quantifiers to the left without changing their relative order.
(xP(x))  (y Q(y))  xy(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))

• x y( ~ z P(f(x), y, z)  (u Q( x, u) & v R( y, v)))

• y( z~ P(f(c), y, z)  (u Q( x, u) & v R( y, v)))

• y( ~ P(f(c), y, g(y))  ( Q( c, h(y)) & R( y, i(y))))


A  B & C
• (~ P(f(c), y, g(y))  ( Q( c, h(y)) )& ( ~ P(f(c), y, g(y))  R( y,
i(y) )
(A  B) & ( A  C )
Example
• ∀(X)(q(X)→(∃(Y)(¬(p(X,Y)∨r(X,Y))→h(X,Y))∧f(X)))
• First, eliminate the implications: ∀(X)(q(X)→(∃(Y)
((p(X,Y)∨r(X,Y))∨h(X,Y))∧f(X)))∀(X)(¬q(X)∨(∃(Y)
((p(X,Y)∨r(X,Y))∨h(X,Y))∧f(X)))
• Move the quantifiers out front: ∀(X)∃(Y)
(¬q(X)∨((p(X,Y)∨r(X,Y)∨h(X,Y))∧f(X)))
• Skolemize existential quantifiers with g(X)/Y: ∀(X)
(¬q(X)∨((p(X,g(X))∨r(X,g(X))∨h(X,g(X)))∧f(X)))
• Remove universal quantifiers:
¬q(X)∨((p(X,g(X))∨r(X,g(X))∨h(X,g(X)))∧f(X))
Example
• To write ¬q(X)∨((p(X,g(X))∨r(X,g(X))∨h(X,g(X)))∧f(X)) in
clausal form, you first need to put it in conjunctive normal
form. To do so, you can distribute the first disjunction over
the paranthesis to yield:
(¬q(X)∨f(X))∧(¬q(X)∨p(X,g(X))∨r(X,g(X))∨h(X,g(X)))
• Each part of the conjunction corresponds to a clause, which
is a finite disjunction of atomics. Thus, the clausal form of
your original wff is: {{¬q(X),f(X)},
{¬q(X),p(X,g(X)),r(X,g(X)),h(X,g(X))}}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy