3: logicgraham/cs1021/slides/logic.pdf · 2003-10-31 · cs1021 why logic? (continued) ’ & $...
TRANSCRIPT
'
&
$
%
3: Logic
CS1021'
&
$
%
Why logic?
Logic about inference or argument
Start from assumptions or axioms
Make deductions according to rules of reasoning
Logic 3-1
CS1021 Why logic? (continued)'
&
$
%
• If I don’t buy a lottery ticket on Saturday I won’t win the jackpot.
• If I win the lottery jackpot on Saturday then I must have bought a ticket.
• If I don’t buy a lottery ticket on Saturday I won’t win the jackpot. So, if I
buy a ticket I will win the jackpot.
• If it is raining then there are clouds in the sky. Today is cloudy, so it must
be raining.
• If I don’t work on this course I won’t pass the exams. I’m not doing a
thing, I wonder what will happen?
Logic 3-2
CS1021 Why logic? (continued)'
&
$
%
• If I don’t buy a lottery ticket on Saturday I won’t win the jackpot.
• If I win the lottery jackpot on Saturday then I must have bought a ticket.
• If I don’t buy a lottery ticket on Saturday I won’t win the jackpot. So, if I
buy a ticket I will win the jackpot.
• If it is raining then there are clouds in the sky. Today is cloudy, so it must
be raining.
• If I don’t work on this course I won’t pass the exams. I’m not doing a
thing, I wonder what will happen?
Logic 3-2
CS1021 Why logic? (continued)'
&
$
%
• If I don’t buy a lottery ticket on Saturday I won’t win the jackpot.
• If I win the lottery jackpot on Saturday then I must have bought a ticket.
• If I don’t buy a lottery ticket on Saturday I won’t win the jackpot. So, if I
buy a ticket I will win the jackpot.
• If it is raining then there are clouds in the sky. Today is cloudy, so it must
be raining.
• If I don’t work on this course I won’t pass the exams. I’m not doing a
thing, I wonder what will happen?
Logic 3-2
CS1021 Why logic? (continued)'
&
$
%
• If I don’t buy a lottery ticket on Saturday I won’t win the jackpot.
• If I win the lottery jackpot on Saturday then I must have bought a ticket.
• If I don’t buy a lottery ticket on Saturday I won’t win the jackpot. So, if I
buy a ticket I will win the jackpot.
• If it is raining then there are clouds in the sky. Today is cloudy, so it must
be raining.
• If I don’t work on this course I won’t pass the exams. I’m not doing a
thing, I wonder what will happen?
Logic 3-2
CS1021 Why logic? (continued)'
&
$
%
• If I don’t buy a lottery ticket on Saturday I won’t win the jackpot.
• If I win the lottery jackpot on Saturday then I must have bought a ticket.
• If I don’t buy a lottery ticket on Saturday I won’t win the jackpot. So, if I
buy a ticket I will win the jackpot.
• If it is raining then there are clouds in the sky. Today is cloudy, so it must
be raining.
• If I don’t work on this course I won’t pass the exams. I’m not doing a
thing, I wonder what will happen?
Logic 3-2
CS1021 Why logic? (continued)'
&
$
%
• If I don’t buy a lottery ticket on Saturday I won’t win the jackpot.
• If I win the lottery jackpot on Saturday then I must have bought a ticket.
• If I don’t buy a lottery ticket on Saturday I won’t win the jackpot. So, if I
buy a ticket I will win the jackpot.
• If it is raining then there are clouds in the sky. Today is cloudy, so it must
be raining.
• If I don’t work on this course I won’t pass the exams. I’m not doing a
thing, I wonder what will happen?
Logic 3-2
CS1021 Why logic? (continued)'
&
$
%
Can formalize the rules of reasoning used – symbolic logic
Helps to clarify the process of reasoning
Gives possibility of mechanizing reasoning process
Logic 3-3
CS1021'
&
$
%
Applications of Logic in Computer Science
• Programming – statements like if...then ...else use Boolean
expressions
• Computer Design – Logic gates used as basis of all hardware design
• Program Specification – piece of mathematics that describes precisely
the desired behaviour of a piece of software
• Program Verification – proving that a program satisfies its specification
• Automated theorem proving – proving that a mathematical theorem is
the consequence of a number of assumptions
Logic 3-4
CS1021'
&
$
%
Applications of Logic in Computer Science
• Programming – statements like if...then ...else use Boolean
expressions
• Computer Design – Logic gates used as basis of all hardware design
• Program Specification – piece of mathematics that describes precisely
the desired behaviour of a piece of software
• Program Verification – proving that a program satisfies its specification
• Automated theorem proving – proving that a mathematical theorem is
the consequence of a number of assumptions
Logic 3-4
CS1021'
&
$
%
Applications of Logic in Computer Science
• Programming – statements like if...then ...else use Boolean
expressions
• Computer Design – Logic gates used as basis of all hardware design
• Program Specification – piece of mathematics that describes precisely
the desired behaviour of a piece of software
• Program Verification – proving that a program satisfies its specification
• Automated theorem proving – proving that a mathematical theorem is
the consequence of a number of assumptions
Logic 3-4
CS1021'
&
$
%
Applications of Logic in Computer Science
• Programming – statements like if...then ...else use Boolean
expressions
• Computer Design – Logic gates used as basis of all hardware design
• Program Specification – piece of mathematics that describes precisely
the desired behaviour of a piece of software
• Program Verification – proving that a program satisfies its specification
• Automated theorem proving – proving that a mathematical theorem is
the consequence of a number of assumptions
Logic 3-4
CS1021'
&
$
%
Applications of Logic in Computer Science
• Programming – statements like if...then ...else use Boolean
expressions
• Computer Design – Logic gates used as basis of all hardware design
• Program Specification – piece of mathematics that describes precisely
the desired behaviour of a piece of software
• Program Verification – proving that a program satisfies its specification
• Automated theorem proving – proving that a mathematical theorem is
the consequence of a number of assumptions
Logic 3-4
CS1021'
&
$
%
Applications of Logic in Computer Science
• Data Bases – need to be able to structure and efficiently execute
queries
• Knowledge bases – need to be able to make deductions from existing
body of facts
• Semantic Web searches – need to be able to search for web content by
knowing something about the meaning of the content, rather than just
the syntax.
• Logic programming – can use particular forms of logic as programming
languages in their own right
Logic 3-5
CS1021'
&
$
%
Applications of Logic in Computer Science
• Data Bases – need to be able to structure and efficiently execute
queries
• Knowledge bases – need to be able to make deductions from existing
body of facts
• Semantic Web searches – need to be able to search for web content by
knowing something about the meaning of the content, rather than just
the syntax.
• Logic programming – can use particular forms of logic as programming
languages in their own right
Logic 3-5
CS1021'
&
$
%
Applications of Logic in Computer Science
• Data Bases – need to be able to structure and efficiently execute
queries
• Knowledge bases – need to be able to make deductions from existing
body of facts
• Semantic Web searches – need to be able to search for web content by
knowing something about the meaning of the content, rather than just
the syntax.
• Logic programming – can use particular forms of logic as programming
languages in their own right
Logic 3-5
CS1021'
&
$
%
Applications of Logic in Computer Science
• Data Bases – need to be able to structure and efficiently execute
queries
• Knowledge bases – need to be able to make deductions from existing
body of facts
• Semantic Web searches – need to be able to search for web content by
knowing something about the meaning of the content, rather than just
the syntax.
• Logic programming – can use particular forms of logic as programming
languages in their own right
Logic 3-5
CS1021'
&
$
%
Symbolic logic
Simplest form is concerned with propositions
Statements that can take value true or false
• Blue is a colour
• 1 + 1 = 2
• 2 + 2 = 22
• All computer scientists have beards
Logic 3-6
CS1021'
&
$
%
Symbolic logic
Simplest form is concerned with propositions
Statements that can take value true or false
• Blue is a colour
• 1 + 1 = 2
• 2 + 2 = 22
• All computer scientists have beards
Logic 3-6
CS1021'
&
$
%
Symbolic logic
Simplest form is concerned with propositions
Statements that can take value true or false
• Blue is a colour
• 1 + 1 = 2
• 2 + 2 = 22
• All computer scientists have beards
Logic 3-6
CS1021'
&
$
%
Symbolic logic
Simplest form is concerned with propositions
Statements that can take value true or false
• Blue is a colour
• 1 + 1 = 2
• 2 + 2 = 22
• All computer scientists have beards
Logic 3-6
CS1021 Symbolic logic (continued)'
&
$
%
The following are not propositions
• 42
• Is it raining?
• Manchester United
Logic 3-7
CS1021 Symbolic logic (continued)'
&
$
%
The following are not propositions
• 42
• Is it raining?
• Manchester United
Logic 3-7
CS1021 Symbolic logic (continued)'
&
$
%
The following are not propositions
• 42
• Is it raining?
• Manchester United
Logic 3-7
CS1021 Symbolic logic (continued)'
&
$
%
Can form compound propositions using logical connectives (or operators)
• Today is Wednesday and it’s raining
• Either this is Manchester or I’m a Dutchman
• If it’s Wednesday at 11 this must be CS1021
Logic 3-8
CS1021 Symbolic logic (continued)'
&
$
%
Can form compound propositions using logical connectives (or operators)
• Today is Wednesday and it’s raining
• Either this is Manchester or I’m a Dutchman
• If it’s Wednesday at 11 this must be CS1021
Logic 3-8
CS1021 Symbolic logic (continued)'
&
$
%
Can form compound propositions using logical connectives (or operators)
• Today is Wednesday and it’s raining
• Either this is Manchester or I’m a Dutchman
• If it’s Wednesday at 11 this must be CS1021
Logic 3-8
CS1021 Symbolic logic (continued)'
&
$
%
Can form compound propositions using logical connectives (or operators)
• Today is Wednesday and it’s raining
• Either this is Manchester or I’m a Dutchman
• If it’s Wednesday at 11 this must be CS1021
Will introduce the full range of logical connectives and study their properties.
Logic 3-9
CS1021'
&
$
%
The Logical Connectives
name symbol translation
negation ¬ not
conjunction ∧ and
disjunction ∨ or
implication ⇒ implies
bi-implication ⇔ iff
→ and↔ are often used instead of⇒ and⇔.
• ¬ - unary - prefix ¬p,¬q
• others - binary - infix (p∧q)
Logic 3-10
CS1021 The Logical Connectives (continued)'
&
$
%
• ∧ - ‘and’, ‘but’
• ∨ - inclusive or
• ⇒ some English translations of A⇒ B.
A implies B
If A then B
A only if B
B if A
A is a sufficient case for B
B is necessary for A
• ⇔ - ‘if and only if’, abbreviated to ‘iff’.
Logic 3-11
CS1021 The Logical Connectives (continued)'
&
$
%
• ∧ - ‘and’, ‘but’
• ∨ - inclusive or
• ⇒ some English translations of A⇒ B.
A implies B
If A then B
A only if B
B if A
A is a sufficient case for B
B is necessary for A
• ⇔ - ‘if and only if’, abbreviated to ‘iff’.
Logic 3-11
CS1021 The Logical Connectives (continued)'
&
$
%
• ∧ - ‘and’, ‘but’
• ∨ - inclusive or
• ⇒ some English translations of A⇒ B.
A implies B
If A then B
A only if B
B if A
A is a sufficient case for B
B is necessary for A
• ⇔ - ‘if and only if’, abbreviated to ‘iff’.
Logic 3-11
CS1021 The Logical Connectives (continued)'
&
$
%
• ∧ - ‘and’, ‘but’
• ∨ - inclusive or
• ⇒ some English translations of A⇒ B.
A implies B
If A then B
A only if B
B if A
A is a sufficient case for B
B is necessary for A
• ⇔ - ‘if and only if’, abbreviated to ‘iff’.
Logic 3-11
CS1021 The Logical Connectives (continued)'
&
$
%
• ∧ - ‘and’, ‘but’
• ∨ - inclusive or
• ⇒ some English translations of A⇒ B.
A implies B
If A then B
A only if B
B if A
A is a sufficient case for B
B is necessary for A
• ⇔ - ‘if and only if’, abbreviated to ‘iff’.
Logic 3-11
CS1021'
&
$
%
Truth Tables
Negation
p ¬p
T F
F T
Logic 3-12
CS1021 Truth Tables (continued)'
&
$
%
p1 p2 p1∧ p2 p1∨ p2 p1⇒ p2 p1⇔ p2
T T T T T T
T F F T F F
F T F T T F
F F F F T T
Logic 3-13
CS1021'
&
$
%
Why the table for⇒?
x> 3 implies x> 1
where x is an integer variable. Surely this sentence is universally true; i.e. it
is true whatever integer value x may have. Now let us give x the values
4,2,0 in turn
x x> 3 x> 1 x > 3⇒ x> 1
4 T T T
2 F T T
0 F F T
Logic 3-14
CS1021'
&
$
%
Some properties
p1 p2 p1∧ p2 p1∨ p2 p2∧ p1 p2∨ p1
T T T T T T
T F F T F T
F T F T F T
F F F F F F
Both ∧ and ∨ are commutative
They are also associative
(p1∧ p2)∧ p3 = p1∧ (p2∧ p3)
Logic 3-15
CS1021'
&
$
%
Formulae
Propositions denoted by names such as p,q, p3,r7
1. Every proposition is a formula (in fact an atomic formula).
2. If A is a formula then so is ¬A.
3. If A,B are formulae then so are
(A∧B),(A∨B),(A⇒ B) and (A⇔ B).
Another formal language. Language PL of Propositional Logic
Logic 3-16
CS1021 Formulae (continued)'
&
$
%
¬((p1∨ p2)⇒ (¬p3∧ p4))
has parse tree
p1 p2(∨)
(p1∨ p2)
p3(¬)
¬p3 p4(∧)
(¬p3∧ p4)(⇒)
((p1∨ p2)⇒ (¬p3∧ p4))(¬)
¬((p1∨ p2)⇒ (¬p3∧ p4))
Logic 3-17
CS1021 Formulae (continued)'
&
$
%
or
p1 p2(∨)
.
p3(¬)
. p4(∧)
.(⇒)
.(¬)
.
Logic 3-18
CS1021'
&
$
%
Some syntactic conventions
1. When using formulae it is standard practice to leave off the outermost
parentheses.
2. Leave out internal parentheses from repeated use of ∧ and repeated
use of ∨.
e.g.
• p∧¬q abbreviates (p∧¬q)
• (p∨¬q∨ (q⇒ r))⇒ p abbreviates
(((p∨¬q)∨ (q⇒ r))⇒ p).
Logic 3-19
CS1021'
&
$
%
Truth Valuations
Let p1, . . . , pn be a list of n distinct atomic formulae.
A truth valuation for the list is an allocation
(p1 = x1, . . . , pn = xn)
of a truth value xi to each pi in the list.
e.g. (p = T,q = F,r = F) is a truth valuation for p,q,r.
Logic 3-20
CS1021 Truth Valuations (continued)'
&
$
%
Can also think of a truth valuation as a function
{p1, p2, . . . pn} −→ {T,F}
If all the atomic formulae occurring in a formula A are in the list p1, . . . pn.
Then given a truth valuation for the list, A can be evaluated.
Logic 3-21
CS1021 Truth Valuations (continued)'
&
$
%
This truth value is determined following the way the formula has been built
up, using the truth tables for the connectives that are involved.
If the formula is atomic then the truth valuation itself determines its truth
value.
For a compound (i.e. non-atomic) formula the truth value can be found using
the truth tables for the connectives.
Logic 3-22
CS1021 Truth Valuations (continued)'
&
$
%
e.g. at the valuation
(p = T,q = F,r = F)
• p∧q is F ,
• (p∧q)⇒ r is T ,
• ¬((p∧q)⇒ r) is F .
Logic 3-23
CS1021 Truth Valuations (continued)'
&
$
%
Instead of the truth tables truth schemes can be used.
In each scheme the compound formula gets the truth value false if it is not
true.
Truth scheme just a description of the corresponding truth table.
Logic 3-24
CS1021'
&
$
%
The Truth Schemes
Negation ¬A is true iff A is false.
Conjunction A1∧A2 is true iff both A1,A2 are true.
Disjunction A1∨A2 is true iff at least one of A1,A2 are true.
Implication A1⇒ A2 is true iff either A1 is false or A2 is true (or both).
Bi-implication A1⇔ A2 is true iff A1,A2 have the same truth value.
Logic 3-25
CS1021'
&
$
%
Tautologies and Contradictions
Let A be a formula and let p1, . . . , pn be a list of atomic formulae that include
all those occurring in A. Then
• A is a tautology if it evaluates to T in every truth valuation for the list.
• A is contradictory if it is always false;
i.e. it gets the truth value F at every truth valuation for the list p1, . . . , pn.
Logic 3-26
CS1021'
&
$
%
Tautologies and Contradictions
Let A be a formula and let p1, . . . , pn be a list of atomic formulae that include
all those occurring in A. Then
• A is a tautology if it evaluates to T in every truth valuation for the list.
• A is contradictory if it is always false;
i.e. it gets the truth value F at every truth valuation for the list p1, . . . , pn.
Logic 3-26
CS1021 Tautologies and Contradictions (continued)'
&
$
%
e.g. let p be an atomic formula. Then
• p∨¬p is a tautology.
• p∧¬p is contradictory.
p ¬p p∧¬p p∨¬p
T F F T
F T F T
Logic 3-27
CS1021 Tautologies and Contradictions (continued)'
&
$
%
If a formula is not contradictory then that means that it must be true at some
truth valuations.
We then sometimes write that the formula is satisfiable.
For example
p∨¬q
is satisfiable
Logic 3-28
CS1021'
&
$
%
Truth Tables
p1 p2 p3 ¬p1 p2∧ p3 ¬p1∨ (p2∧ p3)
T T T F T T
T T F F F F
T F T F F F
T F F F F F
F T T T T T
F T F T F T
F F T T F T
F F F T F T
¬p1∨ (p2∧ p3) is not a tautology. It is satisfiable.
Logic 3-29
CS1021'
&
$
%
Logical Equivalence
Two formulae, A,B, are logically equivalent if they have the same truth value
at every truth valuation for any list of atomic formulae that includes those
occurring in either A or B;
i.e. A,B have the same truth tables.
Logic 3-30
CS1021 Logical Equivalence (continued)'
&
$
%
For example:
p1 p2 ¬p1 ¬p1∨ p2 p1⇒ p2
T T F T T
T F F F F
F T T T T
F F T T T
So ¬p1∨ p2 is logically equivalent to p1⇒ p2.
Logic 3-31
CS1021'
&
$
%
Notation:
• Write |= A for ‘A is a tautology’.
– A is contradictory iff |= ¬A.
– A is satisfiable iff 6|= ¬A.
• Write A |==| B for ‘A is logically equivalent to B’.
A |==| B iff |= A⇔ B.
Logic 3-32
CS1021'
&
$
%
Logical Equivalence LawsCommutativity
A1∧A2 |==| A2∧A1
A1∨A2 |==| A2∨A1
Associativity
A1∧ (A2∧A3) |==| (A1∧A2)∧A3
A1∨ (A2∨A3) |==| (A1∨A2)∨A3
Distributivity
A∧ (B1∨B2) |==| (A∧B1)∨ (A∧B2)
A∨ (B1∧B2) |==| (A∨B1)∧ (A∨B2)
(B1∨B2)∧A |==| (B1∧A)∨ (B2∧A)
Logic 3-33
CS1021'
&
$
%
(B1∧B2)∨A |==| (B1∨A)∧ (B2∨A)
Idempotency
A∧A |==| A
A∨A |==| AAbsorbtion
A∧ (A∨B) |==| A
A∨ (A∧B) |==| ADouble Negation (Involution)
¬¬A |==| A
Logic 3-34
CS1021'
&
$
%
De Morgan
¬(A1∧A2) |==| ¬A1∨¬A2
¬(A1∨A2) |==| ¬A1∧¬A2
A1∧A2 |==| ¬(¬A1∨¬A2)
A1∨A2 |==| ¬(¬A1∧¬A2)
Redundancy If |= B and |= ¬C then
A∧B |==| A
A∨C |==| A
Logic 3-35
CS1021'
&
$
%
Implication
A⇒ B |==| ¬A∨B
¬(A⇒ B) |==| A∧¬B
A⇒ B |==| ¬B⇒¬A
A⇒¬B |==| B⇒¬A
Logic 3-36
CS1021'
&
$
%
Bi-implication
A⇔ B |==| (A⇒ B)∧ (B⇒ A)
A⇔ B |==| (¬A∨B)∧ (¬B∨A)
A⇔ B |==| (A∧B)∨ (¬A∧¬B)
¬(A⇔ B) |==| (A∧¬B)∨ (B∧¬A)
¬(A⇔ B) |==| ¬(A∧B)∧ (A∨B)
Logic 3-37
CS1021 Logical Equivalence Laws (continued)'
&
$
%
Any of the above can be checked using truth tables.
For example
A∧ (B1∨B2) |==| (A∧B1)∨ (A∧B2)
A B1 B2 B1∨B2 A∧ (B1∨B2) A∧B1 A∧B2 (A∧B1)∨ (A∧B2)
T T T
T T F
T F T
T F F
F T T
F T F
F F T
F F F
Logic 3-38
CS1021'
&
$
%
Implication
A⇒ B |==| ¬B⇒¬A
This equivalence is one we use often in everyday reasoning
If we know that a implies b, and we also know that b is false, then
we can deduce the fact that a must be false as well
¬B⇒¬A is called the contrapositive of A⇒ B
Logic 3-39
CS1021'
&
$
%
Normal Forms
Can simplify a formula to produce an equivalent formula in some standard
(or normal form)
There are three useful kinds of normal form for propositional logic, NNF ,
CNF and DNF .
We will describe algorithms which, for any formula A, find a formula A′, in the
normal form, such that A |==| A′.
Logic 3-40
CS1021'
&
$
%
Negation Normal Form (NNF)
A formula that is either atomic or is the negation of an atomic formula is
called a literal;
e.g. if p is an atomic formula (proposition) then both p and ¬p are literals.
A formula is in Negation Normal Form, abbreviated NNF , if it is built up from
literals using only conjunction and disjunction.
So
((¬p1∧ p2)∨ p3)∧¬p2 is in NNF ,
¬(p1∧ p2)∨ p3 is NOT in NNF
Logic 3-41
CS1021 Negation Normal Form (NNF) (continued)'
&
$
%
Every formula of PL is logically equivalent to a formula in NNF .
To produce the NNF formula carry out the following procedures:-
1. Eliminate connectives⇒,⇔ from the formula, using the two laws
A⇒ B |==| ¬A∨B,
A⇔ B |==| (¬A∨B)∧ (¬B∨A).
Logic 3-42
CS1021 Negation Normal Form (NNF) (continued)'
&
$
%
2. The resulting formula will be built up using only ¬,∧,∨.
May still not be in NNF because negation may be applied to a
non-literal; i.e. there may be occurrences of formulae having one of the
forms
¬¬A,¬(A1∧A2),¬(A1∨A2).
In the first case the double negation can be eliminated using the double
negation law
¬¬A |==| A
In other two cases the negation can be driven inside the binary
connective using the two De Morgan Laws
¬(A1∧A2) |==| ¬A1∨¬A2,
¬(A1∨A2) |==| ¬A1∧¬A2.
Repeat these steps until we have a formula in NNF .
Logic 3-43
CS1021'
&
$
%
Examples1.
¬((p1∧ p2)⇒ p3︸ ︷︷ ︸)
|==|¬(¬(p1∧ p2)∨ p3)
|==|¬¬(p1∧ p2)︸ ︷︷ ︸∧¬p3
|==|(p1∧ p2)∧¬p3
Logic 3-44
CS1021'
&
$
%
2.
¬((p2⇒ p1)︸ ︷︷ ︸∧¬p3)
|==|¬((¬p2∨ p1)∧¬p3)
|==|¬(¬p2∨ p1)︸ ︷︷ ︸∨¬¬p3︸ ︷︷ ︸
|==|(¬¬p2︸ ︷︷ ︸∧¬p1)∨ p3
|==|(p2∧¬p1)∨ p3
Logic 3-45
CS1021'
&
$
%
Conjunctive Normal Form (CNF)
A (disjunctive) clause is a disjunction of one or more literals.
For example
p
p∨q
p∨¬q
p1∨¬p2∨ p3∨ p4
A formula is in Conjunctive Normal Form, abbreviated CNF , if it is a
conjunction of clauses;
Logic 3-46
CS1021'
&
$
%
Examples
1. ¬p1∨ p2
2. (p2∨ p3)∧ (¬p1∨ p3)
3. (p1∨¬p2∨¬p1)∧ (p2∨¬p3∨ p1)
4. p1∧¬p2∧ p3
Logic 3-47
CS1021 Examples (continued)'
&
$
%
Every formula of PL is logically equivalent to a formula in CNF .
First put the formula in NNF .
If the resulting formula is not in CNF then repeatedly use the following
procedures until a formula in CNF is eventually obtained:-
1. Get rid of inner parentheses from repeated conjunctions and
disjunctions, using the laws
(A1∧·· ·∧An)∧A |==| A1∧·· ·∧An∧A,
A∧ (A1∧·· ·∧An) |==| A∧A1∧·· ·∧An,
(A1∨·· ·∨An)∨A |==| A1∨·· ·∨An∨A,
A∨ (A1∨·· ·∨An) |==| A∨A1∨·· ·∨An,
Logic 3-48
CS1021 Examples (continued)'
&
$
%
2. Bring disjunctions inside conjunctions using the distributivity laws
(A1∧·· ·∧An)∨A |==| (A1∨A)∧·· ·∧ (An∨A),
A∨ (A1∧·· ·∧An) |==| (A∨A1)∧·· ·∧ (A∨An),
where n≥ 2.
Logic 3-49
CS1021'
&
$
%
Example
Put ¬((p2⇒ p1)¬p3) in CNF.
¬((p2⇒ p1)︸ ︷︷ ︸∧¬p3)
|==| (by example 2 of 3.1)
(p2∧¬p1)∨ p3
|==| (by distributivity)
(p2∨ p3)∧ (¬p1∨ p3)
Logic 3-50
CS1021'
&
$
%
CNF test for tautologies
The only way that a clause can be a tautology is if one of the literals in the
clause is the negation of another literal in the clause.
So, for example, ¬p1∨ p2∨ p1∨ p3 is a clause that is a tautology, but
¬p1∨ p2∨ p3 is not a tautology because it is false at the valuation
(p1 = T, p2 = F, p3 = F).
Also, a conjunction is a tautology exactly when all the conjuncts are
tautologies.
Logic 3-51
CS1021 CNF test for tautologies (continued)'
&
$
%
For example
(p1∨ p3∨ p4∨¬p3)∧ (¬p4∨ p3∨ p1)∧ (p2∨ p1∨¬p2∨ p1)
is not a tautology because the second clause ¬p4∨ p3∨ p1 does not have a
literal and its negation.
Logic 3-52
CS1021'
&
$
%
Disjunctive Normal Form (DNF)
Disjunctive Normal Form (DNF) is defined just like CNF except that the roles
of conjunction and disjunction are interchanged.
A formula is a conjunctive clause if it is a conjunction of one or more literals
A formula is in disjunctive normal form (DNF) if it is a disjunction of one or
more conjunctive clauses.
The method we have described for putting a formula in CNF also applies for
putting a formula in DNF, provided that we interchange the roles of ∨ and ∧.
Logic 3-53
CS1021 Disjunctive Normal Form (DNF) (continued)'
&
$
%
Corresponding to the CNF test for tautologies we get the following DNF test
for contradictions:-
To test a formula in DNF for being contradictory check that for each
conjunctive clause in the formula there is an occurrence of a literal and its
negation. For example the DNF formula
(p3∧ p4∧¬p3)∨ (p1∧¬p1)
is easily seen to be contradictory.
Logic 3-54
CS1021'
&
$
%
Functional Completeness
In this section we discuss the possibility of other connectives than the
particular connectives we have been considering.
Perhaps there are missing connectives that could be added to Propositional
Logic to get a more expressive Logic. (What does expressive mean?)
We will show that in a precise sense that is not the case - Propositional
Logic is Functionally Complete.
Logic 3-55
CS1021 Functional Completeness (continued)'
&
$
%
A connective can be specified by giving a truth table that spells out how the
truth value of a formula built with the connective depends on the truth values
of its components.
For example consider a new binary connective # . We specify the
connective using a truth table. For example:-
p1 p2 p1 # p2
T T F
T F T
F T T
F F F
So we have the truth scheme:-
• A1 # A2 is true iff exactly one of A1,A2 is true and the other is false.
Logic 3-56
CS1021 Functional Completeness (continued)'
&
$
%
You may already have noticed that the formula ¬(p1⇔ p2) has the same
truth table as the above table for p1 # p2;
So the two formulae are logically equivalent
This means that # is redundant - the occurrences of # in a formula can be
systematically eliminated using the logical equivalence.
Logic 3-57
CS1021 Functional Completeness (continued)'
&
$
%
There is a systematic way to find, given any truth table, a formula in DNF
having that truth table.
Suppose the truth table involves the atomic formulae p1, . . . , pn
We may associate a conjunctive clause l1∧·· ·∧ ln with any row of the truth
table, where
li is pi if pi is T in that row and ¬pi if pi is F in that row.
Now let A be the disjunction of those conjunctive clauses corresponding to
the rows where the truth table gives the value T in the right hand column.
It should be obvious that the truth table of A is exactly the truth table we
started with.
In the case of the truth table for # we would get the DNF formula
(p1∧¬p2)∨ (¬p1∧ p2).
Logic 3-58
CS1021'
&
$
%
Example
Find a formula A in DNF whose truth table is:-
p1 p2 p3 A
T T T F
T T F T
T F T T
T F F F
F T T F
F T F F
F F T F
F F F T
Logic 3-59
CS1021'
&
$
%
Example
Find a formula A in DNF whose truth table is:-
p1 p2 p3 A
T T T F
T T F T p1∧ p2∧¬p3
T F T T
T F F F
F T T F
F T F F
F F T F
F F F T
Logic 3-59
CS1021'
&
$
%
Example
Find a formula A in DNF whose truth table is:-
p1 p2 p3 A
T T T F
T T F T p1∧ p2∧¬p3
T F T T p1∧¬p2∧ p3
T F F F
F T T F
F T F F
F F T F
F F F T
Logic 3-59
CS1021'
&
$
%
Example
Find a formula A in DNF whose truth table is:-
p1 p2 p3 A
T T T F
T T F T p1∧ p2∧¬p3
T F T T p1∧¬p2∧ p3
T F F F
F T T F
F T F F
F F T F
F F F T ¬p1∧¬p2∧¬p3
Logic 3-59
CS1021 Example (continued)'
&
$
%
There are three rows of this table which have T under A and these determine
the conjunctive clauses
p1∧ p2∧¬p3,
p1∧¬p2∧ p3 and
¬p1∧¬p2∧¬p3.
The formula A that we want is their disjunction:-
(p1∧ p2∧¬p3)∨ (p1∧¬p2∧ p3)∨ (¬p1∧¬p2∧¬p3).
Logic 3-60
CS1021 Example (continued)'
&
$
%
So, for every possible truth table there is a formula having that truth table.
Moreover that formula can be in DNF
So it only involves the connectives ¬,∧,∨.
We say that {¬,∧,∨} is a functionally complete set of connectives.
There is no truth table which can not be expressed as a formula involving
only these connectives.
Logic 3-61
CS1021 Example (continued)'
&
$
%
In fact there is still some redundancy because only one of ∧,∨ is needed
together with ¬.
This is because the De Morgan Laws allow one of them to be defined in
terms of the other.
For example, because of the law
A∧B |==| ¬(¬A∨¬B),
all the occurrences of ∧ in a formula in DNF can be systematically
eliminated so as to get a logically equivalent formula involving only the
connectives ¬,∨.
Logic 3-62
CS1021 Example (continued)'
&
$
%
For example we have:-
(p1∧¬p2)︸ ︷︷ ︸∨(¬p1∧ p2)︸ ︷︷ ︸|==|
¬(¬p1∨ p2)∨¬(p1∨¬p2)
Logic 3-63
CS1021'
&
$
%
Predicates and Quantifiers
One of the limitations of propositional calculus is that it has no way of
handling arguments such as the following
All computer science students are witty and intelligent.
Eve is a computer science student.
Therefore Eve is witty and intelligent.
Logic 3-64
CS1021 Predicates and Quantifiers (continued)'
&
$
%
We can identify the three propositions here
p All computer science students are witty and intelligent
q Eve is a computer science student
r Eve is witty and intelligent.
We want to argue that p∧q⇒ r, but have no way of formalising the fact that
q and r are both statements about the same individual.
Logic 3-65
CS1021 Predicates and Quantifiers (continued)'
&
$
%
To do this we need to introduce the notion of a predicate.
A predicate is just a boolean valued function.
In the above example we have two such predicates
CS(x) x is a computer science student
W (x) x is witty and intelligent
The above argument can then be recast as
For all x CS(x)⇒W (x)
CS(Eve)
Therefore W (Eve)
Logic 3-66
CS1021'
&
$
%
Quantifiers
Given a predicate P, there are two ways of obtaining a truth value,
Can apply predicate to a a particular individual (for example CS(Eve) above)
Can also quantify it.
Logic 3-67
CS1021 Quantifiers (continued)'
&
$
%
Given a predicate P, we can assert that P(x) is true whatever the value of x.
“For all x, I(x)”.
This statement has one of the values true or false, and does not depend on
a particular value of x.
The predicate has been universally quantified, by the use of the word “For
all”.
Logic 3-68
CS1021 Quantifiers (continued)'
&
$
%
The universal quantifier is denoted symbolically by the symbol ∀,Write things like ∀x,P(x).
The argument regarding CS students becomes
∀x,CS(x)⇒W (x)
CS(Eve)
Therefore W (Eve)
Logic 3-69
CS1021 Quantifiers (continued)'
&
$
%
Can also use existential quantification
In English usually done using phrases such as “there exists” or “for some”.
Write this symbolically as ∃,∃x,P(x), read as “there exists a value for x such that P(x) is true”.
Logic 3-70
CS1021 Quantifiers (continued)'
&
$
%
If CS and W are the predicates as above, note the difference between the
following statements.
∀x CS(x)⇒W (x)
∀x CS(x)∧W (x)
∃x CS(x)∧W (x)
∀x W (x)⇒CS(x)
Logic 3-71
CS1021 Quantifiers (continued)'
&
$
%
Predicates can involve more than one variable, and statements can be built
using more than one quantifier, for example
Every dog has its day
can be written
∀x Dog(x)⇒∃d HasDay(x,d)
Logic 3-72
CS1021 Quantifiers (continued)'
&
$
%
and
There is someone in this room who is at least as tall as anyone
else in the room
∃x InRoom(x)∧ (∀y InRoom(y)⇒ AsTallAs(x,y))
Logic 3-73
CS1021 Quantifiers (continued)'
&
$
%
What about the following?
∀x InRoom(x)⇒ (∃y InRoom(y)∧AsTallAs(x,y))
Logic 3-74
CS1021 Quantifiers (continued)'
&
$
%
The predicates F and O are defined by
F(x) iff x is a Unix file
O(x,y) iff x is the owner of y
Explain in English the meaning of the following statements
i) ∀x (F(x)⇒∃y O(y,x))
ii) ∃x (∀y (F(y)⇒ O(x,y)))
iii) ∀x (F(x)⇒ (∀y∀z (O(y,x)∧O(z,x)⇒ y = z)))
Which, if any, of these statements do you think are true? Give reasons
Logic 3-75
CS1021 Quantifiers (continued)'
&
$
%
In the design specification for a library system, B(p,b) denotes the
predicate ‘person p has borrowed book b’ and O(b) denotes ‘the book b is
overdue’. Write the following sentences in symbolic form:-
• Person p1 has borrowed at least one book.
Logic 3-76
CS1021 Quantifiers (continued)'
&
$
%
In the design specification for a library system, B(p,b) denotes the
predicate ‘person p has borrowed book b’ and O(b) denotes ‘the book b is
overdue’. Write the following sentences in symbolic form:-
• Person p1 has borrowed at least one book.
∃b B(p1,b)
Logic 3-76
CS1021 Quantifiers (continued)'
&
$
%
In the design specification for a library system, B(p,b) denotes the
predicate ‘person p has borrowed book b’ and O(b) denotes ‘the book b is
overdue’. Write the following sentences in symbolic form:-
• Person p1 has borrowed at least one book.
∃b B(p1,b)
• Book b1 has been borrowed.
Logic 3-76
CS1021 Quantifiers (continued)'
&
$
%
In the design specification for a library system, B(p,b) denotes the
predicate ‘person p has borrowed book b’ and O(b) denotes ‘the book b is
overdue’. Write the following sentences in symbolic form:-
• Person p1 has borrowed at least one book.
∃b B(p1,b)
• Book b1 has been borrowed.
∃p B(p,b1)
Logic 3-76
CS1021 Quantifiers (continued)'
&
$
%
In the design specification for a library system, B(p,b) denotes the
predicate ‘person p has borrowed book b’ and O(b) denotes ‘the book b is
overdue’. Write the following sentences in symbolic form:-
• Person p1 has borrowed at least one book.
∃b B(p1,b)
• Book b1 has been borrowed.
∃p B(p,b1)
• Person p2 has borrowed at least two books.
Logic 3-76
CS1021 Quantifiers (continued)'
&
$
%
In the design specification for a library system, B(p,b) denotes the
predicate ‘person p has borrowed book b’ and O(b) denotes ‘the book b is
overdue’. Write the following sentences in symbolic form:-
• Person p1 has borrowed at least one book.
∃b B(p1,b)
• Book b1 has been borrowed.
∃p B(p,b1)
• Person p2 has borrowed at least two books.
∃b1,b2 (B(p2,b1)∧B(p2,b2)∧b1 6= b2)
Logic 3-76
CS1021 Quantifiers (continued)'
&
$
%
In the design specification for a library system, B(p,b) denotes the
predicate ‘person p has borrowed book b’ and O(b) denotes ‘the book b is
overdue’. Write the following sentences in symbolic form:-
• Person p1 has borrowed at least one book.
∃b B(p1,b)
• Book b1 has been borrowed.
∃p B(p,b1)
• Person p2 has borrowed at least two books.
∃b1,b2 (B(p2,b1)∧B(p2,b2)∧b1 6= b2)
• No book has been borrowed by more than one person.
Logic 3-76
CS1021 Quantifiers (continued)'
&
$
%
In the design specification for a library system, B(p,b) denotes the
predicate ‘person p has borrowed book b’ and O(b) denotes ‘the book b is
overdue’. Write the following sentences in symbolic form:-
• Person p1 has borrowed at least one book.
∃b B(p1,b)
• Book b1 has been borrowed.
∃p B(p,b1)
• Person p2 has borrowed at least two books.
∃b1,b2 (B(p2,b1)∧B(p2,b2)∧b1 6= b2)
• No book has been borrowed by more than one person.
¬∃b ∃p1, p2(B(p1,b)∧B(p2,b)∧ p1 6= p2)
Logic 3-76
CS1021 Quantifiers (continued)'
&
$
%
In the design specification for a library system, B(p,b) denotes the
predicate ‘person p has borrowed book b’ and O(b) denotes ‘the book b is
overdue’. Write the following sentences in symbolic form:-
• Person p1 has borrowed at least one book.
∃b B(p1,b)
• Book b1 has been borrowed.
∃p B(p,b1)
• Person p2 has borrowed at least two books.
∃b1,b2 (B(p2,b1)∧B(p2,b2)∧b1 6= b2)
• No book has been borrowed by more than one person.
¬∃b ∃p1, p2(B(p1,b)∧B(p2,b)∧ p1 6= p2)
• If a book is overdue, then it must have been borrowed.
Logic 3-76
CS1021 Quantifiers (continued)'
&
$
%
In the design specification for a library system, B(p,b) denotes the
predicate ‘person p has borrowed book b’ and O(b) denotes ‘the book b is
overdue’. Write the following sentences in symbolic form:-
• Person p1 has borrowed at least one book.
∃b B(p1,b)
• Book b1 has been borrowed.
∃p B(p,b1)
• Person p2 has borrowed at least two books.
∃b1,b2 (B(p2,b1)∧B(p2,b2)∧b1 6= b2)
• No book has been borrowed by more than one person.
¬∃b ∃p1, p2(B(p1,b)∧B(p2,b)∧ p1 6= p2)
• If a book is overdue, then it must have been borrowed.
∀b O(b)⇒ (∃p B(p,b))
Logic 3-76
CS1021'
&
$
%
Negation of quantified statements
If P is some predicate, then the expression ¬∀x P(x), says that “it is not the
case that all x have the property described by P”.
This means that there must be at least one individual a, say, for which it is
the case that ¬P(a), is true.
In other words ∃x ¬P(x).
So negation turns the universal quantifier into the existential, and we have
(¬∀x P(x)) |==| (∃x ¬P(x))
Logic 3-77
CS1021 Negation of quantified statements (continued)'
&
$
%
Similarly we have
(¬∃x P(x)) |==| (∀x ¬P(x))
If there is no x for which P(x) is true, it must be the case that, for all x, ¬P(x)
is true.
Logic 3-78
CS1021 Negation of quantified statements (continued)'
&
$
%
These rules of negation are an extension of the de Morgan Laws of
propositional logic. How?
Logic 3-79
CS1021 Negation of quantified statements (continued)'
&
$
%
If X is a finite set {x1,x2, . . .xn} the statement
∀x ∈ X p(x)
can be rewritten as
p(x1)∧ p(x2)∧ . . .∧ p(xn)
and
∃x ∈ X p(x)
can be rewritten as
p(x1)∨ p(x2)∨ . . .∨ p(xn)
Logic 3-80
CS1021'
&
$
%
Some examples
If CS and W are the predicates as above,
∀x CS(x)⇒W (x) All CS students are witty and intelligent
∃x CS(x)∧W (x) There is a witty and intelligent CS student
∀x W (x)⇒CS(x) All witty and intelligent people are CS students
We will construct the negations of these
Logic 3-81
CS1021 Some examples (continued)'
&
$
%
¬∀x CS(x)⇒W (x)
= ∃x ¬(CS(x)⇒W (x))
= ∃x CS(x)∧¬W (x))
Logic 3-82
CS1021 Some examples (continued)'
&
$
%
¬∀x CS(x)⇒W (x)
= ∃x ¬(CS(x)⇒W (x))
= ∃x CS(x)∧¬W (x))
There is a CS student who is not witty and intlligent
Logic 3-83
CS1021 Some examples (continued)'
&
$
%
¬∃x CS(x)∧W (x)
= ∀x ¬(CS(x)∧W (x))
= ∀x ¬CS(x)∨¬W (x)
= ∀x ¬CS(x)∨¬W (x)
= ∀x CS(x)⇒¬W (x)
Logic 3-84
CS1021 Some examples (continued)'
&
$
%
¬∃x CS(x)∧W (x)
= ∀x ¬(CS(x)∧W (x))
= ∀x ¬CS(x)∨¬W (x)
= ∀x ¬CS(x)∨¬W (x)
= ∀x CS(x)⇒¬W (x)
All CS students are not witty and intelligent
Logic 3-85
CS1021 Some examples (continued)'
&
$
%
¬∀x W (x)⇒CS(x)
= ∃x ¬(W (x)⇒CS(x))
= ∃x (W (x)∧¬CS(x))
Logic 3-86
CS1021 Some examples (continued)'
&
$
%
¬∀x W (x)⇒CS(x)
= ∃x ¬(W (x)⇒CS(x))
= ∃x (W (x)∧¬CS(x))
There is someone who is not a CS student who is witty and intelligent
Logic 3-87
CS1021 Some examples (continued)'
&
$
%
The statement
No book has been borrowed by more than one person
¬∃b ∃p1, p2(B(p1,b)∧B(p2,b)∧ p1 6= p2)
can be rewritten as
∀b ¬ ∃p1, p2(B(p1,b)∧B(p2,b)∧ p1 6= p2)
= ∀b ∀p1, p2 ¬ (B(p1,b)∧B(p2,b)∧ p1 6= p2)
= ∀b ∀p1, p2(¬B(p1,b)∨¬B(p2,b)∨ p1 = p2)
= ∀b ∀p1, p2((B(p1,b)∧B(p2,b))⇒ p1 = p2)
Logic 3-88
CS1021 Some examples (continued)'
&
$
%
The statement
No book has been borrowed by more than one person
¬∃b ∃p1, p2(B(p1,b)∧B(p2,b)∧ p1 6= p2)
can be rewritten as
∀b ¬ ∃p1, p2(B(p1,b)∧B(p2,b)∧ p1 6= p2)
= ∀b ∀p1, p2 ¬ (B(p1,b)∧B(p2,b)∧ p1 6= p2)
= ∀b ∀p1, p2(¬B(p1,b)∨¬B(p2,b)∨ p1 = p2)
= ∀b ∀p1, p2((B(p1,b)∧B(p2,b))⇒ p1 = p2)
If two people have borrowed the same book, then they must have been the
same person
Logic 3-89
CS1021 Some examples (continued)'
&
$
%
There is someone in this room who is at least as tall as anyone
else in the room
if we negate this statement, we get
There is not someone in this room who is at least as tall as
anyone else in the room
Symbolically this becomes
¬(∃x InRoom(x)∧ (∀y InRoom(y)⇒ AsTallAs(x,y)))
which can be rewritten as
Logic 3-90
CS1021 Some examples (continued)'
&
$
%
∀x¬(InRoom(x)∧ (∀y InRoom(y)⇒ AsTallAs(x,y)))
= ∀x¬(InRoom(x)∧ (∀y InRoom(y)⇒ AsTallAs(x,y)))
= ∀x(¬InRoom(x)∨¬(∀y InRoom(y)⇒ AsTallAs(x,y)))
= ∀x(¬InRoom(x)∨ (∃y ¬(InRoom(y)⇒ AsTallAs(x,y))))
= ∀x(¬InRoom(x)∨ (∃y InRoom(y)∧¬AsTallAs(x,y)))
= ∀x(InRoom(x)⇒ (∃y InRoom(y)∧¬AsTallAs(x,y)))
which in English is
For everyone in the room there is someone in the room who they
are not as tall as.
Logic 3-91