Sie sind auf Seite 1von 148

http://fskik.upsi.edu.

my

The Foundations: Logic


and Proofs

Chapter 1, Part I: Propositional Logic


http://fskik.upsi.edu.my

Chapter Summary
http://fskik.upsi.edu.my

Propositional Logic
Summary
The Language of Propositions
Connectives
Truth Values
Truth Tables
Applications
Translating English Sentences
System Specifications
Logic Puzzles
Logic Circuits
Logical Equivalences
Important Equivalences
Showing Equivalence
Satisfiability
http://fskik.upsi.edu.my

Propositional Logic

Section 1.1
http://fskik.upsi.edu.my

Section Summary
Propositions
Connectives
Negation
Conjunction
Disjunction
Implication; contrapositive, inverse,
converse
Biconditional
Truth Tables
http://fskik.upsi.edu.my

Why study logic?


To understand mathematical reasoning.

The rules of logic give precise meaning to


mathematical
statements.
distinguish between valid and invalid arguments.

Computer science:
to design computer circuits.
to construct computer programs.
to verify the correctness of programs.
http://fskik.upsi.edu.my

Logic
Logic is a study of reasoning.
Logic examines general forms which
arguments may take, which forms are
valid, and which are fallacies.
Axiomatic concepts in math:
Equals
Opposite
Truth and falsehood
Statement
Objects
Collections
http://fskik.upsi.edu.my

Logic
We intuitively know that Truth and
Falsehood are opposites. That statements
describe the world and can be true/false.
That the world is made up of objects and
that objects can be organized to form
collections.

The foundations of logic mimic our intuitions


by setting down constructs that behave
analogously.
http://fskik.upsi.edu.my

Logic True, False,


Statement
Axiom: False is the opposite to Truth.
A statement is a description of
something.
Examples of statements:
Im 31 years old.
I have 17 children.
I always tell the truth.
Im lying to you.

Qs: Which statements are True? False?


Both? Neither?
http://fskik.upsi.edu.my

Logic True, False,


Statement
Answers:

True : Im 31 years old.


False : I have 17 children.
I always tell the truth.
Both: IMPOSSIBLE, by our Axiom.
http://fskik.upsi.edu.my

Logic True, False,


Statement
Neither: Im lying to you. (If viewed on its
own)
HUH? Well suppose that
S = Im lying to you.
were true. In particular, I am actually lying,
so S is false. So its both true and false,
impossible by the Axiom.
Okay, so I guess S must be false. But then I
must not be lying to you. So the statement
is true. Again its both true and false.
In both cases we get the opposite of our
assumption, so S is neither true nor false.
http://fskik.upsi.edu.my

Propositions
To avoid painful head-aches, we ban
such silly non-sense and avoid the
most general type of statements
limiting ourselves to statements with
valid truth-values instead.

Use propositions to encounter these


problems.
http://fskik.upsi.edu.my

Propositions
Basic building blocks of logic.
Propositions a statement / declarative
sentence (sentence that declares a fact)
which is either TRUE or FALSE, but not
BOTH. It may also change according to
certain circumstances (ex: Today is Friday).
Atomic proposition a statement with
none values (statements without first
having to determine the truth or falsity of
other propositions)
http://fskik.upsi.edu.my

Propositions
Examples of propositions:
a) The Moon is made of green cheese.
b) Trenton is the capital of New Jersey.
c) Melaka is the capital of Malaysia.
d) 1+0=1
e) 0+0=2
Examples that are not propositions.
a) Sit down!
b) What time is it?
c) x+1=2
d) x+y=z
http://fskik.upsi.edu.my

Propositions
The value of a proposition is called TRUTH
VALUE (T/1, F/O).
p q p q
p p 1 1 T T
1 0 T F
1 orT or
0 F 0 1 F T
0 0 F F

Opinions, interrogative and imperative


sentences are NOT propositions.
http://fskik.upsi.edu.my

Propositions - Opinions
Opinions:

1.I think we should follow this way.


2.You should bring along your umbrella to
class.


http://fskik.upsi.edu.my

Propositions Interrogative
Statement
Interrogative statement:
- who, whom, whose, what, when, where,
why, which, how.
- Question tag: doesnt he?
1. Do you love me?
2. Who used my computer?
3. Which color that suits me best?
4. She loves chatting, doesnt she?
5. You didnt abuse drugs, did you?
http://fskik.upsi.edu.my

Propositions Imperative
Sentence
Imperative sentence:
http://fskik.upsi.edu.my

Propositions Examples
Examples:

1.2 + 3 = 5.
2.4 * 4 = 8.
3.Perak is the capital of Malaysia.
4.There are 12 months a year.
http://fskik.upsi.edu.my

Propositions Examples
Answers:

1. 2 + 3 = 5. (True)
2. 4 * 4 = 8.
(False)
3. Perak is the capital of Malaysia.
(False)
4. There are 12 months a year. (True)
http://fskik.upsi.edu.my

Propositions Exercise 1
Consider the following sentences:

1. What time is it?


2. When is the pretest?
3. How many students are in the class?
4. Do your homework.
5. Please close the door.
6. Do not spit out of the bus.
http://fskik.upsi.edu.my

Propositions Exercise 1
Consider the following sentences:

7. Java is the best programming language.


8. x + 1 = 2.
9. x + y = z.
http://fskik.upsi.edu.my

Propositions Exercise 1
Answers:

Questions 1 3
Not propositions because it is not a declarative sentences. It is a
question.

Questions 4 6
Not propositions because it is not a declarative sentences. It is an order.

Question 7
Not propositions because it is not a declarative sentences. It is a
statement (either True, False, or Both).

Questions 8 9
Not propositions because it is neither True or False. No initial value for
x, y and z.
http://fskik.upsi.edu.my

Propositions Exercise 2
Friday is the day after Thursday.
It is raining.
The grass is green.
The sun orbits the earth.
Please close the windows.
I am happy.
10 < 15.
x + 7 = 10 where x = 3.
http://fskik.upsi.edu.my

Propositional Logic/Variables
(Statement Variables)
Variables that represent atomic
propositions such as p, q, r, s, .

The truth value of a proposition is


true, denoted by T.

The truth value of a proposition is


false, denoted by F.
http://fskik.upsi.edu.my

Propositional Logic/Variables
(Statement Variables)
Propositional logic (propositional calculas) is
a static discipline of statements which lack
semantic content.
the study of how simple propositions can
come together to make more complicated
propositions.

If the simple propositions were endowed with some


meaning and they will be very soon then the
complicated proposition would have meaning as
well, and then finding out the truth value is
actually important!
http://fskik.upsi.edu.my

Propositional Logic/Variables
(Statement Variables)
Constructing Propositions
Propositional Variables: p, q, r, s,
The proposition that is always true is denoted by T
and the proposition that is always false is denoted
by F.
Compound Propositions; constructed from logical
connectives and other propositions
Negation
Conjunction
Disjunction
Implication
Biconditional
Exclusive OR
http://fskik.upsi.edu.my

Logical
Connectives/Operators
Connectives or operators are used
to create a compound proposition from
two or more other propositions.
Negation.
Conjunction/logical conjunction/and.
Disjunction/logical disjunction/or.
Exclusive or/XOR.
Implication/imply.
Biconditional.
http://fskik.upsi.edu.my

Logical
Connectives/Operators
Operator Symbol Usage
Negation not
Conjunction and
Disjunction or
Exclusive or xor
Conditional if,then
Biconditional if
http://fskik.upsi.edu.my

Example
Example 1:

p = Tun Dr. Mahathir was the prime


minister.
q = The list of Malaysian prime ministers
includes Tun Dr. Mahathir.
r = Lions like to sleep.

All p and q are no more closely related than q and


r are, in propositional calculus. They are both
equally related as all three statements are true.
Semantically, however, p and q are the same!
http://fskik.upsi.edu.my

Compound Propositions
Compound propositions

combining one or more propositions


using logical operators/connectives
to construct mathematical statements/
propositional molecules.
http://fskik.upsi.edu.my

Compound Propositions -
Example
p = Ferry only sails on sea.
q = Ferry sails in Penang Island.
r = Penang Island is a sea.
r = Penang Island is not a sea.
p q = Ferry only sails on sea and sails
in Penang Island.
p q r = If ferry only sails on sea and
sails in Penang Island, then the Penang
Island is a sea.
http://fskik.upsi.edu.my

Compound Propositions:
Negation
A proposition can be negated.
Negation just turns a false proposition to true and
vice versa.

It is not the case that p

Example:

p = 23 = 15 +7

p happens to be false, so p is true.


http://fskik.upsi.edu.my

Compound Propositions:
Negation
The negation of a proposition p is denoted
by p and has this truth table:

p p
T F
F T

Example: If p denotes The earth is


round., then p denotes It is not
the case that the earth is round, or
more simply The earth is not round.
http://fskik.upsi.edu.my

Compound Propositions:
Negation
Negation is a unary operator (the only
non-trivial one possible).
Logical operators are defined by truth
tables.
tables which give the output of the operator
in the right-most column.
p p p p
1 0 T F
0 1
orF T
http://fskik.upsi.edu.my

Compound Propositions:
Negation
Exercise:

p = Today is Monday.

Find p.

1.Today is not Monday.


2.It is not the case that today is Monday.
http://fskik.upsi.edu.my

Compound Propositions:
Negation
Exercise:

Find the negation of the proposition.

Shahruls smartphone has at least 32GB


of memory.
http://fskik.upsi.edu.my

Compound Propositions:
Negation
Answers:

It is not the case that Shahruls


smartphone has at least 32GB of memory.

Shahruls smartphone does not have at


least 32GB of memory.

Shahruls smartphone has less than 32GB


of memory.
http://fskik.upsi.edu.my

Compound Propositions:
Negation
Find the negation of the proposition
i. Michaels PC runs Linux and
express this in simple English.

ii. Vandanas smartphone has at


least 32 GB of memory and express
this in simple English.
http://fskik.upsi.edu.my

Conjunction
Conjunction is a binary operator in that it
operates on two propositions when creating
compound proposition.

Conjunction is supposed to encapsulate what


happens when we use the word and in English.

In logic, the word but is sometimes used


instead of and.
The sun is shining, but it is raining.
The sun is shining, and it is raining
http://fskik.upsi.edu.my

Conjunction
For p and q to be true, it must be
the case that BOTH p is true, as well
as q.

If one of these is false, than the


compound statement is false as well.
http://fskik.upsi.edu.my

Conjunction
Example:

1.Athifs cat is dead and Athifs cat is


not dead.
2.It is raining and it is warm.
3.(2 + 3 = 5) (2 < 2).
http://fskik.upsi.edu.my

Conjunction
The conjunction of propositions p and q is
denoted by p q and has this truth table:

p q pq
T T T
T F F
F T F
F F F

Example: If p denotes I am at home.


and q denotes It is raining. then p q
denotes I am at home and it is raining.
http://fskik.upsi.edu.my

Conjunction
p q pq p q pq

1 1 1 T T T

1 0 0 T F F

0 1 0 F T F

0 0 0 F F F
http://fskik.upsi.edu.my

Conjunction - Exercise
Exercise:
p = Today is Monday.
q = Tomorrow is Friday.
r = 3 + 5 = 8

Assuming p and r are true, while q false.


Out of pq, pr, qr which is true?
http://fskik.upsi.edu.my

Disjunction
Conversely, disjunction is true when
at least one of the components is
true.
The disjunction of propositions p and
q is denoted by p q.
Example: If p denotes I am at
home. and q denotes It is raining.
then p q denotes I am at home or it
is raining.
http://fskik.upsi.edu.my

Disjunction
p q pq p Q pq

1 1 1 T T T

1 0 1 T F T

0 1 1 F T T

0 0 0 F F F
http://fskik.upsi.edu.my

Disjunction - Example
Example:
Students who have taken discrete or
computer science can take this class.
- Take both (T T = T).
- Take discrete (T F = T).
- Take computer science (F T = T).
- Not taken (F F = F).
http://fskik.upsi.edu.my

Disjunction - Exercise
Find the conjunction of the
propositions p and q where p is
proposition Rebeccas PC has more
than 16 GB free hard disk space and
q is proposition The processor in
Rebeccas PC runs faster than 1
GHz.
http://fskik.upsi.edu.my

The Connective Or in English


In English or has two distinct
meanings.
Inclusive Or - In the sentence Students who have
taken MTK3013 or MTS3073 may take this class, we
assume that students need to have taken one of the
prerequisites, but may have taken both. This is the
meaning
p of disjunction.
q For p q to
p be
q true, either one
or both of p and q must be true.
T T T

T F T

F T T

F F F
http://fskik.upsi.edu.my

Disjunction : Caveat
Note: English version of disjunction
or does not always satisfy the
assumption that one of p/q being true
implies that p or q is true.

Q: Can someone come up with an


example?
http://fskik.upsi.edu.my

Disjunction : Caveat
A: The entre is served with
soup or salad.

Most restaurants definitely dont allow you


to get both soup and salad so that the
statement is false when both soup and salad
is served.

To address this situation, exclusive-or is


introduced next.
http://fskik.upsi.edu.my

Exclusive Or (XOR)
XOR of two propositions is true when exactly
one of its propositions is true and the other
one is false.
Example:

1.The circuit is either is on or of.


2.You may have cake or ice cream, but not both.
3.Let ab < 0, then either a< 0 or b < 0 but not
both.
http://fskik.upsi.edu.my

Exclusive Or (XOR)
p q P q p q P q

1 1 0 T T F

1 0 1 T F T

0 1 1 F T T

0 0 0 F F F

Note:
In this course any usage of or will connote the
logical operator as opposed to the exclusive-or.
http://fskik.upsi.edu.my

Exclusive Or (XOR) -
Example
Example:

Students who have taken discrete or computer


science, but not both, can enroll in this class.

- Take both (T T = F).


- Take discrete (T F = T).
- Take computer science (F T = T).
- Not taken (F F = F).
http://fskik.upsi.edu.my

Exclusive Or (XOR) -
Example
Rebeccas PC has more than 16 GB
free hard disk space or the
processor in Rebeccas PC runs faster
than 1 GHz
http://fskik.upsi.edu.my

Conditional (Implication)
The proposition that is false when p is
true and q is false and true otherwise.

p = hypothesis/antecedent/premise
q = conclusion/ consequence.

DEF: p q is true if q is true, or if p is


false. In the final case (p is true while q is
false) p q is false.
http://fskik.upsi.edu.my

Conditional (Implication)
This one is probably the least intuitive. Its
only partly akin to the English usage of
if,then or implies.
Semantics: p implies q is true if one can
mathematically derive q from p.
Example:
1.If it rains, the grass gets wet.
2.If the sprinklers operate, the grass gets wet.
3.If you buy your air ticket in advance, then it
is cheaper.
http://fskik.upsi.edu.my

Conditional (Implication)
In p q there does not need to be any connection between
the antecedent or the consequent. The meaning of p q
depends only on the truth values of p and q.
These implications are perfectly fine, but
would not be used in ordinary English.
If the moon is made of green cheese, then I have
more money than Bill Gates.
If the moon is made of green cheese then Im on
welfare.
If 1 + 1 = 3, then your grandma wears combat
boots.
http://fskik.upsi.edu.my

Conditional (Implication)
The implication p q can be
equivalently read as:

if p then q
p implies q
if p, q
p only if q
q if p
q when p
http://fskik.upsi.edu.my

Conditional (Implication)
The implication p q can be
equivalently read as:

q whenever p
p is a sufficient condition for q
q is a necessary condition for p
q follows from p
http://fskik.upsi.edu.my

Diferent Ways of Expressing p


q
if p, then q p implies q
if p, q p only if q
q unless p q when p
q if p q when p
q whenever p p is sufficient for q
q follows from p q is necessary for p

a necessary condition for p is q


a sufficient condition for q is p
http://fskik.upsi.edu.my

Conditional (Implication)
Some of the ways reverse the order of p
and q but have the same connotation:

q if p. q whenever p. q is necessary for p.

To aid in remembering these, I suggest


inserting is true after every variable:

Example: p is true only if q is true.


http://fskik.upsi.edu.my

Conditional (Implication)
p q P q p q P q

T T T
1 1 1

1 0 0 T F F

0 1 1 F T T

0 0 1 F F T
http://fskik.upsi.edu.my

Conditional (Implication)
Example 1:

If I am elected, then I will lower taxes.

- Elected, lower taxes (T T = T)


- Elected, not lower taxes (T F = F)
- Not elected, lower taxes (F T = T)
- Not elected, not lower taxes (F F = T)
http://fskik.upsi.edu.my

Conditional (Implication)
Example 2:

If you get 100% on the final, then you will get an


A.

- Get 100%, get A (T T


= T)
- Not get 100%, may or may not receive an A
depending on other factors.
- Not get 100%, not get A, cheated (F F
= T)
http://fskik.upsi.edu.my

Conditional (Implication)
One way to view the logical conditional is to
think of an obligation or contract.
If I am elected, then I will lower taxes.
If you get 100% on the final, then you will
get an A.

If the politician is elected and does not lower


taxes, then the voters can say that he or she
has broken the campaign pledge. Something
similar holds for the professor. This corresponds
to the case where p is true and q is false.
http://fskik.upsi.edu.my

Conditional (Implication)
Exercise:

Which of the following implications is true?

1. If -1 is a positive number, then 2 + 2 = 5.

2. If -1 is a positive number, then 2 + 2 = 4.

3. If sin x = 0, then x = 0.
http://fskik.upsi.edu.my

Conditional (Implication)
Answers:

Question 1 2:

True: The hypothesis is obviously false, thus no


matter what the conclusion, the implication
holds.
http://fskik.upsi.edu.my

Conditional (Implication)
Answers:

Question 3:

False: x can be any multiple of , for example if


we let x = 2 then clearly sin x = 0, but x 0.

The implication if sin x = 0 then x = k for some


integer k is True.
http://fskik.upsi.edu.my

Why F F is True?
Remember, all of these are mathematical
constructs, not attempts to mimic English.
Mathematically, p should imply q
whenever it is possible to derive q by from
p by using valid arguments.
For example consider the mathematical
analog of no. 4:
If 0 = 1 then 3 = 9.
Q: Is this true mathematically?
http://fskik.upsi.edu.my

Why F F is True?
A: YES mathematically and YES by the
truth table.

Heres a mathematical proof:


1. 0 = 1 (assumption)
http://fskik.upsi.edu.my

Why F F is True?
A: YES mathematically and YES by the
truth table.

Heres a mathematical proof:


1. 0 = 1 (assumption)
2. 1 = 2 (added 1 to both sides)
3. 3 = 6 (multiplied both sides by 3)
4. 0 = 3 (multiplied no. 1 by 3)
5. 3 = 9 (added no. 3 and no. 4) QED
http://fskik.upsi.edu.my

Why F F is True?
As we want the conditional to make
sense in the semantic context of
mathematics, we better define it as
we have!

Other questionable rows of the truth


table can also be justified in a similar
manner.
http://fskik.upsi.edu.my

Converse, Contrapositive, and


Inverse
From p q we can form new conditional
statements .
q p is the converse of p q
q p is the contrapositive of p q
pq is the inverse of p q
Example: Find the converse, inverse, and
contrapositive of It raining is a sufficient
condition for my not going to town.
Solution:
converse: If I do not go to town, then it is raining.
inverse: If it is not raining, then I will go to town.
contrapositive: If I go to town, then it is not raining.
http://fskik.upsi.edu.my

Biconditional
If p and q are propositions, then we can form the
biconditional proposition p q , read as p if and only if
q . The biconditional p q denotes the proposition with
this truth table:
p q p q
T T T
T F F
F T F
F F T

If p denotes I am at home. and q denotes It is


raining. then p q denotes I am at home if and
only if it is raining.
http://fskik.upsi.edu.my

Biconditional
For p q to be true, p and q must have
the same truth value.
Else, p q is false:
p q P q p q P q

1 1 1 T T T

1 0 0 T F F

0 1 0 F T F

0 0 1 F F T
http://fskik.upsi.edu.my

p q pq q p P q

1 1 1 1 1

1 0 0 1 0

0 1 1 0 0

0 0 1 1 1
http://fskik.upsi.edu.my

Biconditional
Some common or alternative ways p if
and only if q is expressed in English:

p if and only if q
p is necessary and sufficient for q
if p then q, and conversely
p iff q
http://fskik.upsi.edu.my

Biconditional
Example:

You can take the flight if and only if you


buy a ticket.
http://fskik.upsi.edu.my

Biconditional
Examples:

1.x > 0 if and only if x is positive.

2. The alarm goes of if a burglar breaks


in.

3. You may have pudding if and only if


you
eat your meat.
http://fskik.upsi.edu.my

Biconditional
Exercises:

1.x + y = 0 if and only if x = 0 and y =


0.

2. 2 + 2 = 4 if and only if 2 < 2.

3. x 0 if and only if x 0.
http://fskik.upsi.edu.my

Biconditional
Answers:

Questions 1 -2
True: Both implications hold.

Question 3
False: The converse holds. That is if x 0
then x 0. However the implication is
false; consider x = -1. Then the hypothesis
is true, 1 0 but the conclusion fails.
http://fskik.upsi.edu.my

Biconditional
Q : Which operator is the opposite of?
A : has exactly the opposite truth table as .

Q: Could we define all other logical operations


using only negation and exclusive or?
A: No. Notice that and each maintain parity
between truth and false; no matter what combination
of these symbols, impossible to get a truth table with
four output rows consisting of 3 Ts and 1 F (such as
implication and disjunction).
http://fskik.upsi.edu.my

Truth Tables For Compound


Propositions
Construction of a truth table:
Rows
Need a row for every possible combination of
values for the atomic propositions.
Columns
Need a column for the compound proposition
(usually at far right)
Need a column for the truth value of each
expression that occurs in the compound
proposition as it is built up.
This includes the atomic propositions
http://fskik.upsi.edu.my

Example Truth Table


Construct a truth table for

p q r r pq pq
r
T T T F T F
T T F T T T
T F T F T F
T F F T T T
F T T F T F
F T F T T T
F F T F F T
F F F T F T
http://fskik.upsi.edu.my

Example Truth Table


Construct the truth table for the
following compound proposition:

((p q) q)

1.Count the atomic propositions/variables.


2.Use the formula 2.
3.Draw the rows and columns.
4.Input the truth value.
http://fskik.upsi.edu.my

Example Truth Table


p q p q q ((p q) q)

0
http://fskik.upsi.edu.my

Example Truth Table


p q p q q ((p q) q)

1 1

1 0

0 1

0 0
http://fskik.upsi.edu.my

Example Truth Table


p q p q q ((p q) q)

1 1 1

1 0 0

0 1 0

0 0 0
http://fskik.upsi.edu.my

Example Truth Table


p q p q q ((p q) q)

1 1 1 0

1 0 0 1

0 1 0 0

0 0 0 1
http://fskik.upsi.edu.my

Example Truth Table


p q p q q ((p q) q)

1 1 1 0 1

1 0 0 1 1

0 1 0 0 0

0 0 0 1 1
http://fskik.upsi.edu.my

Equivalent Propositions
Two propositions are equivalent if they
always have the same truth value.
Example: Show using a truth table
that the biconditional is equivalent to
the contrapositive.
p q p q p q q
Solution: p
T T F F T T
T F F T F F
F T T F T T
F F T T T T
http://fskik.upsi.edu.my

Using a Truth Table to Show


Non-Equivalence
Example: Show using truth tables
that neither the converse nor
inverse of an implication are not
equivalent to the implication.
p
Solution:
q p q p q p q p
q
T T F F T T T
T F F T F T T
F T T F T F F
F F T T F T T
http://fskik.upsi.edu.my

Problem
How many rows are there in a truth table
with n propositional variables?

Solution: 2n We will see how to do this


in Chapter 6.

Note that this means that with n


propositional variables, we can construct 2n
distinct (i.e., not equivalent) propositions.
http://fskik.upsi.edu.my

Precedence of Logical
Operators
Operator Precedence
1
2
3
4
5

p q r is equivalent to (p q)
r
If the intended meaning is p (q r )
then parentheses must be used.
http://fskik.upsi.edu.my

Applications of
Propositional Logic

Section 1.2
http://fskik.upsi.edu.my

Applications of Propositional
Logic: Summary
Translating English to Propositional
Logic
System Specifications
Boolean Searching
Logic Puzzles
Logic Circuits
AI Diagnosis Method (Optional)
http://fskik.upsi.edu.my

Translating English
Sentences
Steps to convert an English sentence to
a statement in propositional logic
Identify atomic propositions and represent
using propositional variables.
Determine appropriate logical connectives
If I go to Harrys or to the country, I will
not go shopping.
p: I go to Harrys
If p or q then not r.
q: I go to the country.
r: I will go shopping.
http://fskik.upsi.edu.my

Example
Problem: Translate the following sentence
into propositional logic:
You can access the Internet from campus
only if you are a computer science major or
you are not a freshman.
One Solution: Let a, c, and f represent
respectively You can access the internet
from campus, You are a computer science
major, and You are a freshman.
a (c f )
http://fskik.upsi.edu.my

System Specifications
System and Software engineers take
requirements in English and express them in a
precise specification language based on logic.
Example: Express in propositional logic:
The automated reply cannot be sent when the
file system is full
Solution: One possible solution: Let p denote
The automated reply can be sent and q
denote The file system is full.
q p
http://fskik.upsi.edu.my

Consistent System
Specifications
Definition: A list of propositions is consistent
if it is possible to assign truth values to the
proposition variables so that each proposition
is true.
Exercise: Are these specifications
consistent?
The diagnostic message is stored in the bufer or it is retransmitted.
The diagnostic message is not stored in the bufer.
If the diagnostic message is stored in the bufer, then it is retransmitted.
Solution: Let p denote The diagnostic message is not stored in the
bufer. Let q denote The diagnostic message is retransmitted The
specification can be written as: p q, p q, p. When p is false and q
is true all three statements are true. So the specification is consistent.
What if The diagnostic message is not retransmitted is added.
Solution: Now we are adding q and there is no satisfying assignment. So
the specification is not consistent.
http://fskik.upsi.edu.my

Logic Puzzles
An island has two kinds of inhabitants, knights, who always
tell the truth, and knaves, who always lie.
You go to the island and meet A and B. Raymond
Smullyan
A says B is a knight.
(Born
B says The two of us are of opposite types. 1919)
Example: What are the types of A and B?
Solution: Let p and q be the statements that A is a knight
and B is a knight, respectively. So, then p represents the
proposition that A is a knave and q that B is a knave.
If A is a knight, then p is true. Since knights tell the truth, q
must also be true. Then (p q) ( p q) would have to be
true, but it is not. So, A is not a knight and therefore p must be
true.
If A is a knave, then B must not be a knight since knaves always
lie. So, then both p and q hold since both are knaves.
Logic Circuits
http://fskik.upsi.edu.my

(Studied in depth in Chapter


12)
Electronic circuits; each input/output signal can be viewed as a 0 or 1.
0 represents False
1 represents True
Complicated circuits are constructed from three basic circuits called gates.

The inverter (NOT gate)takes an input bit and produces the negation of that bit.
The OR gate takes two input bits and produces the value equivalent to the
disjunction of the two bits.
The AND gate takes two input bits and produces the value equivalent to the
conjunction of the two bits.
More complicated digital circuits can be constructed by combining these
basic circuits to produce the desired output given the input signals by
building a circuit for each piece of the output expression and then
combining them. For example:
http://fskik.upsi.edu.my

Diagnosis of Faults in an
Electrical System (Optional)
AI Example (from Artificial Intelligence:
Foundations of Computational Agents by
David Poole and Alan Mackworth, 2010)
Need to represent in propositional logic the
features of a piece of machinery or circuitry
that are required for the operation to
produce observable features. This is called
the Knowledge Base (KB).
We also have observations representing
the features that the system is exhibiting
now.
http://fskik.upsi.edu.my

Electrical System Diagram


(optional)Outside Power
s1 cb1

Have lights (l1, l2),


w1 wires (w0, w1, w2, w3,
w3 w4), switches (s1, s2,
w2 s3), and circuit
breakers (cb1)
s2 s3
The next page gives the
w0 w4 knowledge base
describing the circuit and
the current observations.
l1

l2
http://fskik.upsi.edu.my

Representing the Electrical


System in Propositional Logic
We need to represent our common-sense
understanding of how the electrical system works in
propositional logic.
For example: If l1 is a light and if l1 is receiving
current, then l1 is lit.
lit_l1 light_l1 live_l1 ok_l1
Also: If w1 has current, and switch s2 is in the up
position, and s2 is not broken, then w0 has current.
live_w0 live_w1 up_s2 ok_s2
This task of representing a piece of our common-
sense world in logic is a common one in logic-based
AI.
http://fskik.upsi.edu.my

Knowledge Base (opt)


We have outside power.
live_outside
light_l1 Both l1 and l2 are lights.
light_l2
live_l1 live_w0
live_w0 live_w1 up_s2 ok_s2 If s2 is ok and s2 is in a
live_w0 live_w2 down_s2 ok_s2 down position and w2 has
current, then w0 has
live_w1 live_w3 up_s1 ok_s1 current.
live_w2 live_w3 down_s1 ok_s1
live_l2 live_w4
live_w4 live_w3 up_s3 ok_s3
live_w3 live_outside ok_cb1
lit_l1 light_l1 live_l1 ok_l1
lit_l2 light_l2 live_l2 ok_l2
http://fskik.upsi.edu.my

Observations (opt)
Observations need to be added to
the KB
Both Switches up
up_s1
up_s2
Both lights are dark
lit_l1
lit_l2
http://fskik.upsi.edu.my

Diagnosis (opt)
We assume that the components are working ok, unless
we are forced to assume otherwise. These atoms are
called assumables.
The assumables (ok_cb1, ok_s1, ok_s2, ok_s3, ok_l1,
ok_l2) represent the assumption that we assume that the
switches, lights, and circuit breakers are ok.
If the system is working correctly (all assumables are
true), the observations and the knowledge base are
consistent (i.e., satisfiable).
The augmented knowledge base is clearly not consistent
if the assumables are all true. The switches are both up,
but the lights are not lit. Some of the assumables must
then be false. This is the basis for the method to
diagnose possible faults in the system.
A diagnosis is a minimal set of assumables which must
be false to explain the observations of the system.
http://fskik.upsi.edu.my

Diagnostic Results (opt)


See Artificial Intelligence: Foundations of Computational Agents
(by David Poole and Alan Mackworth, 2010) for details on this
problem and how the method of consistency based diagnosis
can determine possible diagnoses for the electrical system.
The approach yields 7 possible faults in the system. At least
one of these must hold:
Circuit Breaker 1 is not ok.
Both Switch 1 and Switch 2 are not ok.
Both Switch 1 and Light 2 are not ok.
Both Switch 2 and Switch 3 are not ok.
Both Switch 2 and Light 2 are not ok.
Both Light 1 and Switch 3 are not ok.
Both Light 1 and Light 2 are not ok.
http://fskik.upsi.edu.my

Propositional Equivalences

Section 1.3
http://fskik.upsi.edu.my

Section Summary
Tautologies, Contradictions, and
Contingencies.
Logical Equivalence
Important Logical Equivalences
Showing Logical Equivalence
Normal Forms (optional, covered in
exercises in text)
Disjunctive Normal Form
Conjunctive Normal Form
Propositional Satisfiability
Sudoku Example
http://fskik.upsi.edu.my

Tautologies, Contradictions,
and Contingencies

P p p p p p
T F T F
F T T F
http://fskik.upsi.edu.my

Logically Equivalent

p q p p q p q
T T F T T
T F F F F
F T T T T
F F T T T
http://fskik.upsi.edu.my

Logically Equivalent
Exercises:
Are (p r) v (q r ) and (p q) r logically equivalent? Prove it using
truth table.

p q r pr q (p r) v (q pq (p q)
r r) r

1
1
1
1
0
0
0
0
http://fskik.upsi.edu.my

p q r pr q r (p r) v (q pq (p q)
r) r

1 1

1 1

1 0

1 0

0 1

0 1

0 0

0 0
http://fskik.upsi.edu.my

p q r pr q r (p r) v (q pq (p q)
r) r

1 1 1 1

1 1 0 0

1 0 1 1

1 0 0 0

0 1 1 1

0 1 0 1

0 0 1 1

0 0 0 1
http://fskik.upsi.edu.my

p q r pr q r (p r) v (q pq (p q)
r) r

1 1 1 1 1

1 1 0 0 0

1 0 1 1 1

1 0 0 0 1

0 1 1 1 1

0 1 0 1 0

0 0 1 1 1

0 0 0 1 1
http://fskik.upsi.edu.my

p q r pr q r (p r) v (q pq (p q)
r) r

1 1 1 1 1 1

1 1 0 0 0 0

1 0 1 1 1 1

1 0 0 0 1 1

0 1 1 1 1 1

0 1 0 1 1 1

0 0 1 1 1 1

0 0 0 1 1 1
http://fskik.upsi.edu.my

p q r pr q r (p r) v (q pq (p q)
r) r

1 1 1 1 1 1 1

1 1 0 0 0 0 1

1 0 1 1 1 1 0

1 0 0 0 1 1 0

0 1 1 1 1 1 0

0 1 0 1 1 1 0

0 0 1 1 1 1 0

0 0 0 1 1 1 0
http://fskik.upsi.edu.my

p q r pr q r (p r) v (q pq (p q)
r) r

1 1 1 1 1 1 1 1

1 1 0 0 0 0 1 0

1 0 1 1 1 1 0 1

1 0 0 0 1 1 0 1

0 1 1 1 1 1 0 1

0 1 0 1 1 1 0 1

0 0 1 1 1 1 0 1

0 0 0 1 1 1 0 1
http://fskik.upsi.edu.my

Logically Equivalent
Exercises:
Show that (p q) q is a tautology? Prove it using truth table.

p q pq (p q) q

1 1 1 1

1 0 0 1

0 1 0 1

0 0 0 1
http://fskik.upsi.edu.my

De Morgans Laws

Augustus De Morgan

1806-1871

This truth table shows that De Morgans Second Law holds.


p q p q (pq) (pq) pq
T T F F T F F
T F F T T F F
F T T F T F F
F F T T F T T
http://fskik.upsi.edu.my

Key Logical Equivalences


Identity Laws: ,

Domination Laws: ,

Idempotent laws: ,

Double Negation Law:

Negation Laws: ,
http://fskik.upsi.edu.my

Key Logical Equivalences


(cont)
http://fskik.upsi.edu.my

More Logical Equivalences


http://fskik.upsi.edu.my

Constructing New Logical


Equivalences
We can show that two expressions are logically
equivalent by developing a series of logically
equivalent statements.
To prove that we produce a series of
equivalences beginning with A and ending with B.

Keep in mind that whenever a proposition


(represented by a propositional variable) occurs in
the equivalences listed earlier, it may be replaced
by an arbitrarily complex compound proposition.
http://fskik.upsi.edu.my

Equivalence Proofs
Example: Show that

is logically equivalent to
Solution:
http://fskik.upsi.edu.my

Equivalence Proofs
Example: Show that

is a tautology.
Solution:
http://fskik.upsi.edu.my

Equivalence Proofs

Show that
( p q ) p and
q

are logically equivalence

( p ( p q ))
Show that p and
q
are logically equivalence.
http://fskik.upsi.edu.my

Disjunctive Normal Form


(optional)
A propositional formula is in disjunctive normal
form if it consists of a disjunction of (1, ,n)
disjuncts where each disjunct consists of a
conjunction of (1, , m) atomic formulas or the
negation of an atomic formula.
Yes

No
Disjunctive Normal Form is important for the
circuit design methods discussed in Chapter
12.
http://fskik.upsi.edu.my

Disjunctive Normal Form


(optional)
Example: Show that every compound proposition
can be put in disjunctive normal form.
Solution: Construct the truth table for the
proposition. Then an equivalent proposition is the
disjunction with n disjuncts (where n is the number
of rows for which the formula evaluates to T). Each
disjunct has m conjuncts where m is the number of
distinct propositional variables. Each conjunct
includes the positive form of the propositional
variable if the variable is assigned T in that row and
the negated form if the variable is assigned F in that
row. This proposition is in disjunctive normal from.
http://fskik.upsi.edu.my

Disjunctive Normal Form


(optional)
Example: Find the Disjunctive
Normal Form (DNF) of
(pq)r

Solution: This proposition is true


when r is false or when both p and q
are false.
( p q) r
http://fskik.upsi.edu.my

Conjunctive Normal Form

(optional)
A compound proposition is in Conjunctive Normal
Form (CNF) if it is a conjunction of disjunctions.
Every proposition can be put in an equivalent CNF.
Conjunctive Normal Form (CNF) can be obtained by
eliminating implications, moving negation inwards
and using the distributive and associative laws.
Important in resolution theorem proving used in
artificial Intelligence (AI).
A compound proposition can be put in conjunctive
normal form through repeated application of the
logical equivalences covered earlier.
http://fskik.upsi.edu.my

Conjunctive Normal Form


(optional)
Example: Put the following into CNF:

Solution:
1. Eliminate implication signs:

2. Move negation inwards; eliminate double


negation:

3. Convert to CNF using associative/distributive


laws
http://fskik.upsi.edu.my

Propositional Satisfiability
A compound proposition is satisfiable
if there is an assignment of truth
values to its variables that make it
true. When no such assignments
exist, the compound proposition is
unsatisfiable.
A compound proposition is
unsatisfiable if and only if its negation
is a tautology.
http://fskik.upsi.edu.my

Questions on Propositional
Satisfiability
Example: Determine the satisfiability of the
following compound propositions:

Solution: Satisfiable. Assign T to p, q, and r.

Solution: Satisfiable. Assign T to p and F to q.

Solution: Not satisfiable. Check each possible


assignment of truth values to the propositional
variables and none will make the proposition true.
http://fskik.upsi.edu.my

Notation

Needed for the next example.


http://fskik.upsi.edu.my

Sudoku
A Sudoku puzzle is represented by a 99
grid made up of nine 33 subgrids, known
as blocks. Some of the 81 cells of the
puzzle are assigned one of the numbers
1,2, , 9.
The puzzle is solved by assigning numbers
to each blank cell so that every row,
column and block contains each of the
nine possible numbers.
Example
http://fskik.upsi.edu.my

Encoding as a Satisfiability
Problem
Let p(i,j,n) denote the proposition
that is true when the number n is in
the cell in the ith row and the jth
column.
There are 99 9 = 729 such
propositions.
In the sample puzzle p(5,1,6) is true,
but p(5,j,6) is false for j = 2,3,9
http://fskik.upsi.edu.my

Encoding (cont)
For each cell with a given value, assert
p(d,j,n), when the cell in row i and column
j has the given value.
Assert that every row contains every
number.

Assert that every column contains every


number.
http://fskik.upsi.edu.my

Encoding (cont)
Assert that each of the 3 x 3 blocks
contain every number.

(this is tricky - ideas from chapter 4 help)


Assert that no cell contains more than one
number. Take the conjunction over all
values of n, n, i, and j, where each
variable ranges from 1 to 9 and ,
of
http://fskik.upsi.edu.my

Solving Satisfiability
Problems
To solve a Sudoku puzzle, we need to find an
assignment of truth values to the 729 variables
of the form p(i,j,n) that makes the conjunction
of the assertions true. Those variables that are
assigned T yield a solution to the puzzle.
A truth table can always be used to determine
the satisfiability of a compound proposition. But
this is too complex even for modern computers
for large problems.
There has been much work on developing
efficient methods for solving satisfiability
problems as many practical problems can be
translated into satisfiability problems.
http://fskik.upsi.edu.my

Bit Strings
Electronic computers achieve their
calculations inside semiconducting
materials.

For reliability, only two stable


voltage states are used and so the
most fundamental operations are
carried out by switching voltages
between these two stable states.
http://fskik.upsi.edu.my

Bit Strings
In logic, only two truth values are
allowed. Thus propositional logic is
ideal for modeling computers.

High voltage values are modeled by


True, which for brevity we call the
number 1, while low voltage values are
modeled by False or 0.
http://fskik.upsi.edu.my

Bit Strings
Thus voltage memory stored in a
computer can be represented by a
sequence of 0s and 1s such as:
01 1011 0010 1001
Another portion of the memory might
look like as follows:
10 0010 1111 1001
Each of the number in the sequence is
called a bit, and the whole sequence of
bits is called a bit string.
http://fskik.upsi.edu.my

Bit Strings
It turns out that the analogs of the logical
operations can be carried out quite easily
inside the computer, one bit at a time.
This can then be transferred to whole bit
strings.
Example, the exclusive-or of the previous bit
strings is:

01 1011 0010 1001


10 0010 1111 1001
11 1001 1101 0000

Das könnte Ihnen auch gefallen