propositional and predicate logic - itu.dk · propositional and predicate logic formal concepts in...
TRANSCRIPT
Propositional and Predicate LogicFormal Concepts in Computer Science
Marco Carbone
IT University of Copenhagen
ITU, January, 2009
Why “Formal Concepts inComputer Science”?An (incomplete) list of arguments:
• Concrete knowledge
- Common knowledge for computer scientists,- Common frame of reference, and- Prerequisite/advantage in future courses and projects.
• Meta-level knowledge, aid in providing
- Abstract thinking,- Cogent reasoning,- Precise argumentation, and- Precise descriptions.
Marco Carbone 2 ITU, January, 2009
Overview (this part of the course)
“Formal Concepts in Computer Science”
• Models for reasoning: Propositional and Predicate Logic
• Models for data: Set theory (sets, relations, and functions)
• Models for computation: Automata (finite automata, Turingmachines)
• Models for languages: Grammars (regular grammars, context freegrammars)
• Tool: UPPAAL
Marco Carbone 3 ITU, January, 2009
Introduction (I)• Logic is a branch of mathematics used for precise reasoning, e.g.
helpful in doing proofs and also used in programming languages:
while ( x < 5 && (y != 8 || x <= 8) )
if ( x + y > 13 && x > 2 && !(y < 10) ) ...
else ...
• Propositional logic is a simple logic:
P, Q ::= p | P | P ∧ Q | P ∨ Q | P ∨ Q | P → Q | P ↔ Q
where p is a basic (atomic) proposition e.g. the rose is red
• its extension with variables and quantifiers
P, Q ::= . . . | x | (∀x)P | (∃x)P
is called predicate logic.
Marco Carbone 4 ITU, January, 2009
Introduction (II)Logic is used to establish the truth value, false (F ) or true (T ), ofstatements. Some propositions are always true or false
• A triangle has three sides • London is in Denmark
but the value of others may depend on the context
• It’s raining • The sun is shining • I’m getting wet
Not all propositions are basic, they may also be compound by logicalconnectives
• If it’s raining then I’m getting wet
• If the sun is shining then it’s not raining
Marco Carbone 5 ITU, January, 2009
Introduction (III)Propositional Logic can be considered as a mathematical model toinvestigate certain arguments i.e. find a proof.
Given the propositions
• If it’s not raining then I’m not getting wet
• If the sun is shining then it’s not raining
• The sun is shining
we can then conclude
• I’m not getting wet
Later we shall see how to prove formally this kind of things
Marco Carbone 6 ITU, January, 2009
Overview (Logic)• Propositional Logic
Logical Connectives
Tautologies
Logical Equivalence and Logical Implication
Arguments and Inference Rules
• Predicate Logic
Universal and Existential Quantification
Arguments and Inference Rules
Two-place/n-ary Predicates
Negation of Quantified Predicates
Marco Carbone 7 ITU, January, 2009
Compound Proposition: Negation
• Denoted by: p (sometimes also by ¬p, p̃, neg(p))
• Meaning: p is false whenever p is true, and vice versa
• Example:p = It’s rainingp = it’s not raining
• We can formally define it using a truth table:p pT FF T
Marco Carbone 8 ITU, January, 2009
Compound Proposition: Conjunction
• Denoted by: p ∧ q (it is also called and, binary operator)
• Meaning:p ∧ q is true whenever both p and q aretrue, otherwise it’s false
• Example: It’s raining and I’m getting wet.
• Truth table:
p q p ∧ qT T TT F FF T FF F F
Marco Carbone 9 ITU, January, 2009
Compound Proposition: Disjunction
• Denoted by: p ∨ q (it is also called or, binary operator)
• Meaning:p ∨ q is true whenever either p or q istrue (or both), otherwise it’s false
• Example: It’s raining or I’m getting wet.
• Truth table:
p q p ∨ qT T TT F TF T TF F F
Marco Carbone 10 ITU, January, 2009
What if two propositions, say it’s raining and the sun is shining,should not be true simultaneously?
Inclusive disjunction is not appropriate.
Marco Carbone 11 ITU, January, 2009
Compound Proposition: Exclusive Disjunction
• Denoted by: p∨q (also by ⊕, called xor, binary operator)
• Meaning:p∨q is true whenever either p or q istrue (exclusively), otherwise it’s false
• Example: It’s raining xor the sun is shining
• Truth table:
p q p ∨ qT T FT F TF T TF F F
Marco Carbone 12 ITU, January, 2009
Compound Proposition: Conditional
• Denoted by: p→ q (also by⇒, ⊃, aka logical implication)
• Meaning:if p holds then also q must be true, however if pis false no requirement on q is posed
• Example: If it’s raining then I’m getting wet
• Truth table:
p q p → qT T TT F FF T TF F T
Marco Carbone 13 ITU, January, 2009
Compound Proposition: Bidirectional
• Denoted by: p↔ q (also by iff,⇔, aka logical equivalence)
• Meaning: p and q have the same value
• Example: it’s raining if and only if I’m getting wet
• Truth table:
p q p ↔ qT T TT F FF T FF F T
Marco Carbone 14 ITU, January, 2009
Example (I)
Let’s construct the truth table for the compound proposition
(p ∨ q)↔ (p→ q)
p q p p ∨ q p → q (p ∨ q)↔ (p→ q)T TT FF TF F
Marco Carbone 15 ITU, January, 2009
Example (II)
Let’s construct the truth table for the compound proposition
(p ∨ q)↔ (p→ q)
p q p p ∨ q p → q (p ∨ q)↔ (p→ q)T T FT F FF T TF F T
Marco Carbone 16 ITU, January, 2009
Example (III)
Let’s construct the truth table for the following compound proposition
(p ∨ q)↔ (p→ q)
p q p p ∨ q p → q (p ∨ q)↔ (p→ q)T T F TT F F FF T T TF F T T
Marco Carbone 17 ITU, January, 2009
Example (IV)
Let’s construct the truth table for the following compound proposition
(p ∨ q)↔ (p→ q)
p q p p ∨ q p → q (p ∨ q)↔ (p→ q)T T F T TT F F F FF T T T TF F T T T
Marco Carbone 18 ITU, January, 2009
Example (V)
Let’s construct the truth table for the following compound proposition
(p ∨ q)↔ (p→ q)
p q p p ∨ q p → q (p ∨ q)↔ (p→ q)T T F T T TT F F F F TF T T T T TF F T T T T
Marco Carbone 19 ITU, January, 2009
Tautologies
. . . some compound propositions are always true!
• A tautology is a proposition which is true no matter what the truthvalues of its simple components are.
• For example: p ∨ p and (p ∨ q)↔ (p→ q)
p p p ∨ pT F TT F TF T TF T T
p q p p ∨ q p→ q (p ∨ q)↔ (p→ q)T T F T T TT F F F F TF T T T T TF F T T T T
Marco Carbone 20 ITU, January, 2009
Tautologies: Exercises
• Exercise: Show p↔ p , p ∧ p↔ p , p ∨ p↔ p , p ∧ T ↔ p
and p ∨ F ↔ p are tautologies.
• Exercise: Show p ∧ q ↔ p ∨ q and p ∨ q ↔ p ∧ q aretautologies (De Morgan’s Laws).
• Exercise: Show (p→ [q → r])↔ ([p ∧ q]→ r) is a tautology.
• Exercise: Show (p→ q)↔ (q → p) is a tautology.
Marco Carbone 21 ITU, January, 2009
Logical Equivalence
Two propositions P and Q are logically equivalentif P ↔ Q is a tautology
• If P and Q are logically equivalent we write P ≡ Q.
• Example: (p ∨ q) ≡ (p→ q) as (p ∨ q)↔ (p→ q) is atautology
• Example: (p→ q) ≡ (q → p) as (p→ q)↔ (q → p) is atautology
Logically equivalent propositions can be interchanged ina compound proposition without altering its truth value.
• Example: p ∧ (p ∨ q) ≡ p ∧ (p→ q) as (p ∨ q) ≡ (p→ q)
Marco Carbone 22 ITU, January, 2009
Logical Implication
A proposition P logically implies proposition Qif P → Q is a tautology.
• If P logically implies Q we write P ` Q.
Example p∧ (p→ q) ` q because [p∧ (p→ q)]→ q is a tautology.
Example (p→ q) ` (q → p) because (p→ q)→ (q → p) is atautology.
Marco Carbone 23 ITU, January, 2009
Arguments (1)
An argument consists of premises (propositions P1, . . . , Pn) and aconclusion (a proposition Q) supposed to follow logically from thepremises.
The argument with premises P1, . . . , Pn and conclusion Q is valid if
P1 ∧ . . . ∧ Pn ` Q
i.e. if the premises logically implies the conclusion.
Marco Carbone 24 ITU, January, 2009
Arguments (2)
Examples.
it’s raining ∧ (It’s raining→ I’m getting wet) ` I’m getting wet
and
(I’m getting wet→ it’s raining)∧(the sun is shining→ it’s NOT raining) ∧ the sun is shining`
I’m NOT getting wet
We may show an argument to be correct using truthtables, or we can reason at a higher level using generallyvalid rules (inference rules)
Marco Carbone 25 ITU, January, 2009
Inference Rules (I)
To help showing that a conclusion follows logically from a set ofpremises we may apply inference rules on the form:
p1...pn
∴ q
The validity of the rule is ensured if (p1∧ . . .∧ pn)→ q is a tautology.
Marco Carbone 26 ITU, January, 2009
Inference Rules (II)
(Modus Ponens)p
p→ q∴ q
(based on [p ∧ (p→ q)] → q)
(Addition)p
∴ p ∨ q(Simplification)
p ∧ q∴ p
(Conjuntion)pq
∴ p ∧ q
(Modus Tollens)q
p→ q∴ p
(based on [q ∧ (p→ q)]→ p)
Marco Carbone 27 ITU, January, 2009
Example
Example Let p be it’s raining, let q be I’m getting wet, and let r be thesun is shining. Let’s argue that (q → p) ∧ (r → p) ∧ r ` q.
Given premises q → p, r → p, and r the following steps show theconclusion q follows logically from the premises:1 r (premise)2 r → p (premise)3 p (from 1 and 2 using Modus Ponens)4 q → p (premise)5 q (from 3 and 4 using Modus Tollens)
Notice the importance of the order of the steps.
Exercise Let p, q, and r be as above. What about the correctness ofthe argument (p→ q) ∧ (r → p) ∧ r ` q ?
Marco Carbone 28 ITU, January, 2009
Predicate Logic (I)
In propositional logic we may state
Peter is a human being and Ann is a human being.
However, we have no means to express that the two propositions areabout the same general property: is a human being.
A predicate P (x) describes a property, say
x is a human being.
where x is a free variable that may be substituted by values in theuniverse of discourse (UoD) of the predicate.
We can write the two propositions above as P (Peter) and P (Ann).
Marco Carbone 29 ITU, January, 2009
Predicate Logic (II)Predicate Logic can be considered a model to investigate certainarguments, arguments that can’t be expressed in propositional logic.
Given the following propositions as premises
All human beings are mammals
Peter is a human being
We should be able to conclude that
Peter is a mammal.
This immediate raises the two questions:
• How to express propositions like the first premise?
• How to provide rules to help judge the validity of the argument?
Marco Carbone 30 ITU, January, 2009
Universal QuantificationThe proposition
All human beings are intelligent.
can be expressed in predicate logic using universal quantification.
If I(x) describes
x is intelligent
and H(x) describes
x is a human being.
then the proposition above can be defined by (∀x)[H(x)→ I(x)]
If it’s understood that the UoD is human beings, we may write (∀x)I(x) instead.
Marco Carbone 31 ITU, January, 2009
Existential QuantificationIf M(x) describes
x is a mammal.
Then the proposition
Not all mammals are human beings.
can be expressed by (¬ is negation) ¬(∀x)[M(x)→ H(x)]
Alternatively, using existential quantification we may write
(∃x)[M(x) ∧ ¬H(x)]
or alternatively, if the UoD is mammals, (∃x)[¬H(x)] saying that (at least) one
mammal is not a human being.
Marco Carbone 32 ITU, January, 2009
Arguments in Predicate Logic
• What about the argument on slide 30, is it sound?
• We can represent the premises by
(∀x)[H(x)→M(x)] and H(Peter)
• But how to conclude M(Peter) ?
• to formally do so we need inference rules about how to interpretquantifications.
Marco Carbone 33 ITU, January, 2009
Inference Rules for UniversalQuantification
Universal Specification
If (∀x)P (x) is true then P (a) is true for every element a in UoD.
(∀x)P (x)∴ P (a) if a in UoD
Universal Generalization
If P (a) is true for every element a in UoD then (∀x)P (x) is true.
P (a) for any a in UoD∴ (∀x)P (x)
Marco Carbone 34 ITU, January, 2009
Inference Rules for Quantification
Existential Specification
If (∃x)P (x) is true then P (a) is true for (at least) one element a inUoD.
(∃x)P (x)∴ P (a) for some a in UoD
Existential Generalization
If P (a) is true for some element a in UoD then (∃x)P (x) is true.
P (a) for some a in UoD∴ (∃x)P (x)
Marco Carbone 35 ITU, January, 2009
Example
Given the premises
(∀x)[H(x)→M(x)]
andH(a)
the following steps show that the the conclusion M(a) followslogically from the premises:
1 (∀x)[H(x)→M(x)] (premise)2 H(a)→M(a) (from 1 using Universal Specification)3 H(a) (premise)4 M(a) (from 3 and 2 using Modus Ponens)
Marco Carbone 36 ITU, January, 2009
ExercisesExercise Translate the following into symbolic form:
i) Everybody likes him.ii) Somebody cried out for help and called the police.iii) Nobody can ignore her.
Define your predicates, and consider the UoD.
Exercise Find an UoD and two unary predicates P (x) and Q(x)such that (∀x)[P (x)→ Q(x)] is true.
Exercise Find an UoD and two unary predicates P (x) and Q(x)such that (∃x)[P (x) ∧Q(x)] is false but (∃x)P (x) ∧ (∃x)Q(x) istrue.
Exercise Show that (∀x)P (x) ` (∃x)P (x).
Exercise Given the premises (∃x)P (x) and (∀x)[P (x)→ Q(x)]give a series of steps concluding that (∃x)Q(x).
Marco Carbone 37 ITU, January, 2009
Two-place Predicates (I)Consider properties like
is larger than and lives in the same city as
We need two variables in order to define predicates describing suchproperties
Let L(x, y) be the predicate
x lives in the same city as y
A single quantification, e.g. (∀x)L(x, y) leaves one variable free (anddefines a predicate), so we must quantify over both x and y to makea proposition:
(∀x)(∀y)L(x, y), (∀x)(∃y)L(x, y), (∃x)(∀y)L(x, y), (∃x)(∃y)L(x, y)
(∀y)(∀x)L(x, y), (∀y)(∃x)L(x, y), (∃y)(∀x)L(x, y), (∃y)(∃x)L(x, y)
Marco Carbone 38 ITU, January, 2009
Two-place Predicates (II)The order of the quantifications may be important, for instance lettingUoD be Danish citizens then
(∃y)(∀x)L(x, y)
means that (at least) one Danish citizen lives in the same city as allother Danish citizens which is (hard to believe and) not the same as
(∀x)(∃y)L(x, y)
On the other hand
(∀x)(∀y)L(x, y) ≡ (∀y)(∀x)L(x, y)
and(∃x)(∃y)L(x, y) ≡ (∃y)(∃x)L(x, y)
Exercise Give an intuitive argument for the validity of the logicalequivalences above.
Marco Carbone 39 ITU, January, 2009
Negation of Quantified Predicates
The proposition¬(∀x)P (x)
states that it’s not the case that all a (in the UoD) satisfies P (x), thisis that same as
(∃x)[¬P (x)]
so¬(∀x)P (x) ≡ (∃x)[¬P (x)]
likewise¬(∃x)P (x) ≡ (∀x)[¬P (x)]
Exercise (Difficult) Show ¬(∀x)(∃y)P (x, y) ` (∃x)(∀y)[¬P (x, y)].Hint: (∃y)P (x, y) is a predicate over x.
Marco Carbone 40 ITU, January, 2009
Exercises
1) Solve the exercises on the previous slides.
2) If time permits I suggest you solve some of the following exercisestaken from Garnier and Taylor, “Discrete Mathematics for NewTechnology” (see the compendium “Formal Concepts in ComputerScience”):
Exercise 1.1.8 page 13Exercise 1.2 page 15 (you don’t need to consider contradictions)Exercise 1.3 page 19Exercise 1.4.3 page 27Exercise 1.5.4 page 36
Marco Carbone 41 ITU, January, 2009