Transcript true
Propositional Logic
From Chapter 4
Formal Specification using Z
David Lightfoot
1
Propositional calculus
• Propositional calculus is also known as
Boolean algebra. Propositions in Z are either
true or false. Negation can be written using
bar notation (b ) . In Z negation is written as
¬ (pronounced not)
p
¬p
false
true
true
false
2
Propositional calculus
• Conjunction is pronounced ‘ and’ and is
written as L.
p
q
pL q
false
false
false
false
true
false
true
false
false
true
true
true
3
Propositional calculus
• Disjunction is pronounced ‘ or’ and is
written as v.
p
q
pv q
false
false
false
false
true
true
true
false
true
true
true
true
4
Implication Definition
• If p and q are propositions, the compound proposition
– if p then q
• is called a conditional proposition (‘implies’) and is
denoted as
pq
• The proposition p is called the hypothesis (or antecedent )
• and the proposition q is called the conclusion (or
consequence). Can also be written as:
pq
5
Truth Table For Implication
(Conditional Proposition)
pq
p
q
true
true
true
true
false
false
false
true
true
false
false
true
pq
6
Implication P Q
“If it is raining I will wear a raincoat.”
Statement does not say what I will do if it is not
raining. Rule only covers first two cases, must apply
logic of first two cases to second two cases, i.e.
when its not raining
(¬P v Q)
raining raincoat (true)
P Q
P Q
raining ¬raincoat (false)
F F
T
¬raining raincoat (true)
F T
T
¬raining ¬raincoat (true)
T F
F
To get truth value for last two
T T
T
cases apply (¬P v Q)
7
Implication
P Q
is a predicate that is true if (¬P v Q)
Example:
P Q
P Q
(11 < 3) (2+2=5) is true
F F
T
(11<3) (2+2=4) is true
F T
T
(11 > 3) (2+2=5) is false
T F
F
(11>3) (2+2=4) is true
T T
T
8
Equivalence
• If p and q are propositions, the compound
proposition:
• p if and only if q
• (sometimes written “p iff q”)
• it is also is called a bi-conditional proposition
and is denoted by:
pq
9
Equivalence
• An alternative ways to state the equivalence (or a
bi-conditional proposition) are:
• p is equivalent to q
• p is a necessary and sufficient condition for q
• p if and only if q
10
Truth Table For Equivalence
p
q
true
true
true
true
false
false
false
true
false
false
false
true
pq
11
Equivalence
(P
Q) (¬P v Q)
((P
Q) L (QP)) (P Q)
12
DeMorgan’s Laws
¬(P L Q) ¬P v ¬Q
¬(P v Q) ¬Q L ¬P
13
Demonstrating Laws of Logic
• A law is a relationship which holds good
irrespective of the propositions involved.
The truth tables can be used to demonstrate
the validity of a law. For example, to show
the validity of the first of DeMorgan’s laws:
¬(P L Q) ¬P v ¬Q
We complete the truth table, building towards
the expressions to be compared.
Write the truth table for DeMorgan’s laws in
Word, using Z fonts.
14
Using Laws of Logic
• Laws are used to prove that two statements
in the propositional calculus, that may not
necessarily be identical, are equivalent. In
formal specifications laws that are used in
chains of transformations are called proofs
which can verify that a specification is
consistent and makes deductions about
behaviour of a system from its specification.
15
Order of evaluation
•
•
•
•
•
•
•
1. Logical connectives within brackets.
2. Negation
3.
4
5
Where you have a choice use brackets.
Associativity is left except for the conditional
which is right.
16
Logic Terminology
• ‘and’ is often called a Conjunction
• ‘or’ is often called a Disjunction.
• A tautology is a proposition that is always
true e.g.:
(B v ¬B ) (Shakespear).
• A contradiction is always false e.g.:
• (B L¬B )
17
Logic Terminology(Not Core)
• A Well Formed Formula (WFF).
• Let p,q,r.., be propositions. If we have
some compound proposition (or formula)
called W involving p,q,r.., whenever these
variables are replace by their truth values
and W becomes a proposition. Then W is a
well formed formula.
18
Logic Terminology(Not Core)
• In some cases, two different propositions
may have the same truth values no matter
what truth values their constituent
propositions have. Such propositions are
said to be logically equivalent .
19
Logic Terminology(Not Core)
• Suppose that the compound proposition P
and Q are made up of the propositions
p1……pn. We say the P and Q are logically
equivalent and write:
• P Q
• given any truth values of p1……pn, either P
and Q are both true or both false.
20
Logic Terminology(Not Core)
If P and Q are wffs, we say that P logically
implies Q if any assignment of truth values
to the propositions which make P true also
make Q true. We write:
LogicalImplication
P
Q
• Contratrast this definition with implies,
which can be defined in terms of a truth
table. Difffers form Stimulus/Response and
Condition/Response.
21
Value Variable
Value: a constant,no location in time or space
Variable: holder for value, has location in time
space
22
Mathematical proof
• A mathematical system consists of:
• Axioms which are assumed true.
• Definitions which are used to create new concepts in terms
of existing ones
• Undefined terms are not explicitly defined but are
implicitly defined by axioms.
• A theorem is a proposition that has been proved to be true.
• An argument that establishes the truth of a theorem is
called a proof.
• Logic it the tool for the analysis of proof.
23
Logical Argument
• A logical argument is a sequence of propositions:
p1
Punch is a cat
p2
All cats are clever
pn
-----------q
Punch is clever
24
Exercise 0
• Draw the truth table for:
• p XOR q
• Show that the following two definitions are
equivalent.
• p XOR q (p v q) L ¬(p L q)
• p XOR q (p L ¬q) v (¬p L q)
25
Exercise 1
• Show by truth table that:
(PQ) (¬P v Q)
26
Exercise 2
• Show by truth table that:
(P Q) L (Q P) (P Q)
27
Exercise 3
• By using the laws from chapter 4 simplify:
¬(p onboard L
#onboard < capacity )
28
Exercise 3: Answer
• By using the laws from chapter 4 simplify:
¬(p onboard L
#onboard < capacity )
¬(p onboard) v
¬(#onboard < capacity )
p onboard v
#onboard
capacity )
29
Exercise 4
• By using the laws from chapter 4 simplify:
(a L b) v (a L
c) v(a L ¬c)
30
Exercise 4: Answer
• By using the laws from chapter 4 simplify:
(a L b) v (a L
c) v(a L ¬c)
aL
aL
(b v
cv
¬c)
(b v
true)
aL
true
a
31
Exercise 5
• Recall from chapter 2
• 1. Certain people are registered as users of a
computer system. At any given time, some
of these users are logged in to the computer.
There is a limit (unspecified) to the number
of users logged in at any one time. All users
are either staff users or customers.
32
Exercise 5
• Given
• p loggedIn p user
Check that
p loggedIn L p user
can be simplified to:
p loggedIn
user truth table
33
Exercise 5 Answer
• Given
• p loggedIn p user
---p loggedIn L p user
Can only be true is if both sub-expressions are true
Because of the given implication if
p loggedIn
then so is
p user
34
Exercise 6
• Use DeMorgan’s Laws to simplify
•
x 2 x 6
35
Exercise 6:Answer
• Use DeMorgan’s Laws to simplify
x 2 x 6
•
•
•
•
•
¬(x=2 and x=6)
Tricky
¬(x=2) V ¬(x=6)
any number is either different from 2 or different from 6
Moving towards variables
36
Exercise 7
• Simplify:
• s=t L s EOF L t EOF
37
Exercise 7 Solution
• Simplify:
• s=t L s EOF L t EOF
• s=t L s EOF
38
Exercise 8
• Simplify:
• x=x L (x y v x=y)
39
Exercise 8 Solution
•
•
•
Simplify:
x=x L (x y v x=y)
xy
40
Exercise 9
• Simplify:
• x=0 L x 0
• x=0
41
Exercise 10
• Simplify:
• ¬(age 16 v student)
• age < 16 L ¬student)
42