ceng.anadolu.edu.tr

Download Report

Transcript ceng.anadolu.edu.tr

DISCRETE COMPUTATIONAL
STRUCTURES
Propositional Logic
Hazırlayan
PROF. DR. YUSUF OYSAL
DISCRETE COMPUTATIONAL STRUCTURES – Propositional Logic
Logical Inference
• Why do we study propositional logic?
– We want to use them to solve problems.
– To solve a problem using the propositional logic, we often need to
start from some “premises,” and obtain a certain “conclusion” using
inferences.
• Example: Computer scientists often need to verify the
correctness of a program.
– One possible approach is to prove the program is correct.
– So one can start from the program and the semantics of the used
programming language (i.e., the premise), and use inference to
obtain a conclusion that the program does the right job.
DISCRETE COMPUTATIONAL STRUCTURES – Propositional Logic
Logical Inference
•
•
•
Deriving a logical conclusion by combining many propositions and using
formal logic: hence, determining the truth of arguments.
An argument is a sequence of statements in which the conjunction of
the initial statements (called the premises/hypotheses) is said to imply
the final statement (called the conclusion).
An argument can be presented symbolically as
(P1 Λ P2 Λ ... Λ Pn)  Q
where P1, P2, ..., Pn represent the hypotheses and Q represents the
conclusion.
DISCRETE COMPUTATIONAL STRUCTURES – Propositional Logic
Valid Argument
•
•
•
•
What is a valid argument?  When does Q logically follow from P1, P2, ..., Pn.
Informal answer: Whenever the truth of hypotheses leads to the conclusion
Note: We need to focus on the relationship of the conclusion to the hypotheses
and not just any knowledge we might have about the conclusion Q.
Example:
– P1: Neil Armstrong was the first human to step on the moon.
– P2 : Mars is a red planet
And the conclusion
– Q: No human has ever been to Mars.
– P1 Λ P2  Q is not a tautology
DISCRETE COMPUTATIONAL STRUCTURES – Propositional Logic
Valid Argument
•
An argument is valid if whenever the hypotheses are all true, the conclusion
must also be true. A valid argument is intrinsically true, i.e. (P1 Λ P2 Λ ... Λ Pn) 
Q is a tautology.
•
How to arrive at a valid argument?
– Using a proof sequence
•
It is a sequence of propositional formulas in which each formula is either a
hypothesis or the result of applying one of the formal system’s derivation rules
to earlier formulas in the sequence.
Generally speaking, 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.
•
DISCRETE COMPUTATIONAL STRUCTURES – Propositional Logic
Rules for Propositional Logic
Derivation rules for propositional logic
Equivalence Rules
Inference Rules
Allows individual formulas to be
rewritten
Allows new formulas to be
derived
Truth preserving rules
Work only in one direction
DISCRETE COMPUTATIONAL STRUCTURES – Propositional Logic
Implication Rule
•
•
•
The first, and simplest, rule is:
P
P →Q
------------Q
This rule is called Modus ponens. Intuitively, if we have the condition of an implication,
then we can obtain its consequence.
Example
If you study the BİM122 material, then you will pass
You study the BİM122 material
______________
 You will pass
DISCRETE COMPUTATIONAL STRUCTURES – Propositional Logic
Another Implication Rule
•
•
•
Recall that P →Q  P Q   Q→  P.
The implication rule just studied tells us that
Q
 Q→  P
------------ P
If we replace  Q→  P in the above with P →Q, then we get another implication rule
(Modus tonens):
Q
P →Q
------------ P
DISCRETE COMPUTATIONAL STRUCTURES – Propositional Logic
Yet Another Implication Rule
•
•
•
•
We have:
P →Q
Q →R
--------- P →R
Intuitively, if P implies Q and Q implies R, then we can get that P implies R.
This rule is called Hypothetical syllogism.
Example: P →Q means “if there is a storm, then the office is closed.” Q →R means “if
the office is closed, then I don’t go to work.” P →R means “if there is a storm, then I
don’t go to work.”
DISCRETE COMPUTATIONAL STRUCTURES – Propositional Logic
Conjunction and Simplification Rules
•
•
•
•
Rules are not restricted to implications. For example, we have a conjunction rule:
P
Q
---PQ
Intuitively, this means when you have P and Q both being true, then P  Q is also true.
A closely related rule (simplification):
PQ
-----P
Intuitively, this means when you have P  Q being true, clearly P is also true.
DISCRETE COMPUTATIONAL STRUCTURES – Propositional Logic
Disjunction Rules
•
•
One is (Disjunctive syllogism):
PQ
P
-------Q
Another is (Addition rule):
P
--------PQ
DISCRETE COMPUTATIONAL STRUCTURES – Propositional Logic
Resolution Rule
•
•
•
Third disjunction rule (Resolution rule):
PQ
P  R
------------ Q R
It plays an important role in AI systems.
Intuitively, it means: if P implies R and P implies Q (why? Where do we get these
implications?) , then we must have either Q or R. Clearly, this is true since one of P
and P must be true.
DISCRETE COMPUTATIONAL STRUCTURES – Propositional Logic
Other Rules
•
•
We can have more rules like:
PQ
P →R
Q →S
------------ R S
Intuitively it means we can do inference in each of two cases (P or Q) independently.
DISCRETE COMPUTATIONAL STRUCTURES – Propositional Logic
Rules of Inference or Method of Proof
Rule of Inference
Tautology (Deduction Theorem)
Name
P
PQ
P  (P  Q)
Addition
PQ
P
(P  Q)  P
Simplification
P
Q
PQ
[(P)  (Q)]  (P  Q)
Conjunction
P
PQ
Q
[(P)  (P Q)]  P
Modus Ponens
Q
PQ
 P
[(Q)  (P Q)]  P
Modus Tollens
PQ
QR
 P R
[(PQ)  (Q  R)]  (PR)
Hypothetical Syllogism
(“chaining”)
PQ
P
Q
[(P  Q)  (P)]  Q
Disjunctive syllogism
PQ
P  R
QR
[(P  Q)  (P  R)]  (Q  R)
Resolution
DISCRETE COMPUTATIONAL STRUCTURES – Propositional Logic
Inference Example
•
Prove P Λ P  Q
1.
P
2.
P
3.
PVQ
4.
QVP
5.
(Q) V P
6.
Q  P
7.
(Q)
8.
Q
(called Inconsistency)
premise 1
premise 2
1, addition
3, commutativity
4, double negation
5, implication
2, 6, Modus Tollens
7, double negation
DISCRETE COMPUTATIONAL STRUCTURES – Propositional Logic
Inference Example
Suppose:
(1) If it is Saturday today, then we play football or
basketball.
(2) If the football field is occupied, we don’t play
football.
(3) It is Saturday today, and the football field is
occupied.
Prove that we play basketball or volleyball.
First we formalize the problem:
P: It is Saturday today.
Q: We play football.
R: We play basketball.
S: The football field is occupied.
T: We play volleyball.
Our premise:P(QR), SQ, P, S
Need to prove:RT
(1) P  (QR)
(2) P
(3) QR
(4) S  Q
(5) S
(6) Q
(7) R
(8) RT
Premise 1
Premise 2
1, 2, Implication
Premise 3
Premise 4
3, 4, Implication
3, 6, Disjunction
7, Addition
DISCRETE COMPUTATIONAL STRUCTURES – Propositional Logic
Predicates
Propositional logic cannot adequately express the meaning of all statements in
mathematics and in natural language. For example, suppose that we know that
• “Every computer connected to the university network is functioning properly.”
No rules of propositional logic allow us to conclude the truth of the statement
• “Computer3 is functioning properly,”
where Computer3 is one of the computers connected to the university network.
Likewise, we cannot use the rules of propositional logic to conclude from the
statement
• “CS2 is under attack by an intruder,”
where CS2 is a computer on the university network, to conclude the truth of
• “There is a computer on the university network that is under attack by an
intruder.”
DISCRETE COMPUTATIONAL STRUCTURES – Propositional Logic
Predicates
Statements involving variables, such as
• “x > 3,” “x = y + 3,” “x + y = z,”
• “computer x is under attack by an intruder,”
• “computer x is functioning properly,”
are often found in mathematical assertions, in computer programs, and in system
specifications. These statements are neither true nor false when the values of the
variables are not specified.
The statement “x is greater than 3” has two parts. The first part, the variable x, is the
subject of the statement. The second part—the predicate, “is greater than 3”—refers
to a property that the subject of the statement can have:
•
P(x): “x is greater than 3”
where P denotes the predicate “is greater than 3” and x is the variable. Once a value
has been assigned to the variable x, the statement P(x) becomes a proposition and has
a truth value.
DISCRETE COMPUTATIONAL STRUCTURES – Propositional Logic
Predicates
Example:
Let P(x) denote the statement “x > 3.” What are the truth values of P(4) and P(2)?
Solution: We obtain the statement P(4) by setting x = 4 in the statement “x > 3.” Hence, P(4),
which is the statement “4 > 3,” is true. However, P(2), which is the statement “2 > 3,” is false.
Example:
Let A(x) denote the statement “Computer x is under attack by an intruder.” Suppose that of the
computers on campus, only CS2 and MATH1 are currently under attack by intruders. What are
truth values of A(CS1), A(CS2), and A(MATH1)?
Solution: We obtain the statement A(CS1) by setting x = CS1 in the statement “Computer x is
under attack by an intruder.” Because CS1 is not on the list of computers currently under attack,
we conclude that A(CS1) is false. Similarly, because CS2 and MATH1 are on the list of computers
under attack, we know that A(CS2) and A(MATH1) are true.
DISCRETE COMPUTATIONAL STRUCTURES – Propositional Logic
Predicates
A predicate is a property or description of subjects in the universe of discourse. The
following predicates are all italicized :
• Ahmet is tall.
• The bridge is structurally sound.
• 17 is a prime number.
By taking a variable subject denoted by symbols such as x, y, z, and applying a
predicate one obtains a propositional function (or formula). When an object from
the universe is plugged in for x, y, etc. a truth value results:
• x is tall. …e.g. plug in x = Ahmet
• y is structurally sound. …e.g. plug in y = FSM
• n is a prime number. …e.g. plug in n = 111
DISCRETE COMPUTATIONAL STRUCTURES – Propositional Logic
Multivariable Predicates
Multivariable predicates generalize predicates to allow descriptions of relationships
between subjects. These subjects may or may not even be in the same universe of
discourse. For example:
– Ahmet is taller than Burak.
– 17 is greater than one of 12, 45.
– Ahmet is at least 5 centimeters taller than Burak.
Q: What universes of discourse are involved?
The multivariable predicates, together with their variables create multivariable
propositional functions. In the above examples, we have the following
generalizations:
– x is taller than y
– a is greater than one of b, c
– x is at least n inches taller than y
DISCRETE COMPUTATIONAL STRUCTURES – Propositional Logic
Quantifiers
•
•
•
•
•
•
Existential Quantifier
“” reads “there exists”
Universal Quantifier
“” reads “for all”
“x P (x)” is true when an instance can be found which when plugged in for x makes
P (x) true
Like disjunctioning over entire universe
x P (x )  P (x1) P (x2) P (x3)  …
“x P (x)” true when every instance of x makes P (x) true when plugged in
Like conjunctioning over entire universe
x P (x )  P (x1) P (x2)  P (x3)  …
DISCRETE COMPUTATIONAL STRUCTURES – Propositional Logic
Predicates and Quantifiers
Example:
Let P(x) be the statement “x + 1 > x.” What is the truth value of the quantification
∀xP(x), where the domain consists of all real numbers?
Solution: Because P(x) is true for all real numbers x, the quantification ∀xP(x) is true.
Example:
Let Q(x) be the statement “x < 2.” What is the truth value of the quantification
∀xQ(x), where the domain consists of all real numbers?
Solution: Q(x) is not true for every real number x, because, for instance, Q(3) is false.
That is, x = 3 is a counterexample for the statement ∀xQ(x). Thus ∀xQ(x) is false.
DISCRETE COMPUTATIONAL STRUCTURES – Propositional Logic
Predicates and Quantifiers
Example:
Let P(x) denote the statement “x > 3.” What is the truth value of the quantification ∃xP(x),
where the domain consists of all real numbers?
Solution: Because “x > 3” is sometimes true, for instance, when x = 4, the existential
quantification of P(x), which is ∃xP(x), is true.
Example:
Let Q(x) denote the statement “x = x + 1.”What is the truth value of the quantification
∃xQ(x),
where the domain consists of all real numbers?
Solution: Because Q(x) is false for every real number x, the existential quantification of
Q(x), which is ∃xQ(x), is false.
DISCRETE COMPUTATIONAL STRUCTURES – Propositional Logic
Multivariate Quantification
•
Quantification involving only one variable is fairly straightforward. Just a bunch
of OR’s or a bunch of AND’s. When two or more variables are involved each of
which is bound by a quantifier, the order of the binding is important and the
meaning often requires some thought.
•
When evaluating an expression such as x y z P (x,y,z ) translate the
proposition in the same order to English: There is an x such that for all y there is
a z such that P (x,y,z) holds: P (x,y,z ) = “y - x ≥ z ”
1. There is an x such that for all y there is a z such that y - x ≥ z.
2. There is some number x which when subtracted from any number y results in
a number bigger than some number z.
Q:
If the universe of discourse for x, y, and z
is the natural numbers
{0,1,2,3,4,5,6,7,…} what’s the truth value of xy z P (x,y,z )?
DISCRETE COMPUTATIONAL STRUCTURES – Propositional Logic
Multivariate Quantification
Set the universe of discourse to be all natural numbers {0, 1, 2, 3, … }. Let R (x,y ) = “x <
y”.
Q1: What does x y R (x,y ) mean?
Q2: What does y x R (x,y ) mean?
A1: x y R (x,y ):
“All numbers x admit a bigger number y ”
A2: y x R (x,y ):
“Some number y is bigger than all x”
Q: What’s the true value of each expression?
A: 1 is true and 2 is false.
x y R (x,y ): “All numbers x admit a bigger number y ” just set y = x + 1
y x R (x,y ): “Some number y is bigger than all numbers x” y is never bigger than
itself, so setting x = y is a counterexample
So the order is important!
DISCRETE COMPUTATIONAL STRUCTURES – Propositional Logic
Logical Equivalence with Formulas
27
Two logical expressions possibly involving propositional formulas and quantifiers are said
to be logically equivalent if no matter what universe and what particular propositional
formulas are plugged in, the expressions always have the same truth value.
– x y Q (x,y ) and y x Q (y,x ) are equivalent: names of variables don’t
matter.
– x y Q (x,y ) and y x Q (x,y ) are not!
Recall DeMorgan’s identities:
• Conjunctional negation:
•
Disjunctional negation:
(p1p2…pn)  (p1p2…pn)
(p1p2…pn)  (p1p2…pn)
DISCRETE COMPUTATIONAL STRUCTURES – Propositional Logic
Logical Equivalence with Formulas
28
Since the quantifiers are the same as taking a bunch of AND’s () or OR’s () we have:
• Universal negation:
 x P(x )  x P(x )
• Existential negation:
 x P(x )  x P(x )
Compute:  x y x2  y
In English, we are trying to find the opposite of “every x admits a y greater or
equal to x’s square”. The opposite is that “some x does not admit a y greater or
equal to x’s square”
Algebraically, one just flips all quantifiers from  to  and vice versa, and negates
the interior propositional function. In our case we get: x y ( x 2  y )  x
y x 2 > y