![Page 1: 1 Propositional Logic From Chapter 4 Formal Specification using Z David Lightfoot](https://reader035.vdocuments.us/reader035/viewer/2022062516/56649d555503460f94a32a48/html5/thumbnails/1.jpg)
1
Propositional Logic
From Chapter 4
Formal Specification using Z
David Lightfoot
![Page 2: 1 Propositional Logic From Chapter 4 Formal Specification using Z David Lightfoot](https://reader035.vdocuments.us/reader035/viewer/2022062516/56649d555503460f94a32a48/html5/thumbnails/2.jpg)
2
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 . In Z negation is written as ¬ (pronounced not)
p ¬p
false true
true false
)(b
![Page 3: 1 Propositional Logic From Chapter 4 Formal Specification using Z David Lightfoot](https://reader035.vdocuments.us/reader035/viewer/2022062516/56649d555503460f94a32a48/html5/thumbnails/3.jpg)
3
Propositional calculus
• Conjunction is pronounced ‘ and’ and is written as .
p q p q
false false false
false true false
true false false
true true true
![Page 4: 1 Propositional Logic From Chapter 4 Formal Specification using Z David Lightfoot](https://reader035.vdocuments.us/reader035/viewer/2022062516/56649d555503460f94a32a48/html5/thumbnails/4.jpg)
4
Propositional calculus
• Disjunction is pronounced ‘ or’ and is written as .
p q p q
false false false
false true true
true false true
true true true
![Page 5: 1 Propositional Logic From Chapter 4 Formal Specification using Z David Lightfoot](https://reader035.vdocuments.us/reader035/viewer/2022062516/56649d555503460f94a32a48/html5/thumbnails/5.jpg)
5
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
• The proposition p is called the hypothesis (or antecedent )
• and the proposition q is called the conclusion (or consequence). Can also be written as:
qp
p q
![Page 6: 1 Propositional Logic From Chapter 4 Formal Specification using Z David Lightfoot](https://reader035.vdocuments.us/reader035/viewer/2022062516/56649d555503460f94a32a48/html5/thumbnails/6.jpg)
6
Truth Table For Implication (Conditional Proposition)
p q qp
t r u e t r u e t r u e
t r u e f a l s e f a l s e
f a l s e t r u e t r u e
f a l s e f a l s e t r u e
p q
![Page 7: 1 Propositional Logic From Chapter 4 Formal Specification using Z David Lightfoot](https://reader035.vdocuments.us/reader035/viewer/2022062516/56649d555503460f94a32a48/html5/thumbnails/7.jpg)
7
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
raining raincoat (true)
raining ¬raincoat (false)
¬raining raincoat (true)
¬raining ¬raincoat (true)
To get truth value for last two
cases apply (¬P Q)
(¬P Q)
P Q P Q
F F T
F T T
T F F
T T T
![Page 8: 1 Propositional Logic From Chapter 4 Formal Specification using Z David Lightfoot](https://reader035.vdocuments.us/reader035/viewer/2022062516/56649d555503460f94a32a48/html5/thumbnails/8.jpg)
8
Implication
P Q
is a predicate that is true if (¬P Q)
Example:
(11 < 3) (2+2=5) is true
(11<3) (2+2=4) is true
(11 > 3) (2+2=5) is false
(11>3) (2+2=4) is true
P Q P Q
F F T
F T T
T F F
T T T
![Page 9: 1 Propositional Logic From Chapter 4 Formal Specification using Z David Lightfoot](https://reader035.vdocuments.us/reader035/viewer/2022062516/56649d555503460f94a32a48/html5/thumbnails/9.jpg)
9
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:
qp
![Page 10: 1 Propositional Logic From Chapter 4 Formal Specification using Z David Lightfoot](https://reader035.vdocuments.us/reader035/viewer/2022062516/56649d555503460f94a32a48/html5/thumbnails/10.jpg)
10
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
![Page 11: 1 Propositional Logic From Chapter 4 Formal Specification using Z David Lightfoot](https://reader035.vdocuments.us/reader035/viewer/2022062516/56649d555503460f94a32a48/html5/thumbnails/11.jpg)
11
Truth Table For Equivalence
p q qp
t r u e t r u e t r u e
t r u e f a l s e f a l s e
f a l s e t r u e f a l s e
f a l s e f a l s e t r u e
![Page 12: 1 Propositional Logic From Chapter 4 Formal Specification using Z David Lightfoot](https://reader035.vdocuments.us/reader035/viewer/2022062516/56649d555503460f94a32a48/html5/thumbnails/12.jpg)
12
Equivalence
(P Q) (¬P Q)
((P Q) (Q P)) (P Q)
![Page 13: 1 Propositional Logic From Chapter 4 Formal Specification using Z David Lightfoot](https://reader035.vdocuments.us/reader035/viewer/2022062516/56649d555503460f94a32a48/html5/thumbnails/13.jpg)
13
DeMorgan’s Laws
¬(P Q) ¬P ¬Q
¬(P Q) ¬Q ¬P
![Page 14: 1 Propositional Logic From Chapter 4 Formal Specification using Z David Lightfoot](https://reader035.vdocuments.us/reader035/viewer/2022062516/56649d555503460f94a32a48/html5/thumbnails/14.jpg)
14
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 Q) ¬P ¬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.
![Page 15: 1 Propositional Logic From Chapter 4 Formal Specification using Z David Lightfoot](https://reader035.vdocuments.us/reader035/viewer/2022062516/56649d555503460f94a32a48/html5/thumbnails/15.jpg)
15
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.
![Page 16: 1 Propositional Logic From Chapter 4 Formal Specification using Z David Lightfoot](https://reader035.vdocuments.us/reader035/viewer/2022062516/56649d555503460f94a32a48/html5/thumbnails/16.jpg)
16
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.
![Page 17: 1 Propositional Logic From Chapter 4 Formal Specification using Z David Lightfoot](https://reader035.vdocuments.us/reader035/viewer/2022062516/56649d555503460f94a32a48/html5/thumbnails/17.jpg)
17
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 ¬B ) (Shakespear).
• A contradiction is always false e.g.:
• (B ¬B )
![Page 18: 1 Propositional Logic From Chapter 4 Formal Specification using Z David Lightfoot](https://reader035.vdocuments.us/reader035/viewer/2022062516/56649d555503460f94a32a48/html5/thumbnails/18.jpg)
18
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.
![Page 19: 1 Propositional Logic From Chapter 4 Formal Specification using Z David Lightfoot](https://reader035.vdocuments.us/reader035/viewer/2022062516/56649d555503460f94a32a48/html5/thumbnails/19.jpg)
19
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 .
![Page 20: 1 Propositional Logic From Chapter 4 Formal Specification using Z David Lightfoot](https://reader035.vdocuments.us/reader035/viewer/2022062516/56649d555503460f94a32a48/html5/thumbnails/20.jpg)
20
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:
•
• given any truth values of p1……pn, either P and Q are both true or both false.
QP
![Page 21: 1 Propositional Logic From Chapter 4 Formal Specification using Z David Lightfoot](https://reader035.vdocuments.us/reader035/viewer/2022062516/56649d555503460f94a32a48/html5/thumbnails/21.jpg)
21
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:
P Q• Contratrast this definition with implies, which
can be defined in terms of a truth table. Difffers form Stimulus/Response and Condition/Response.
licationLogicalImp
![Page 22: 1 Propositional Logic From Chapter 4 Formal Specification using Z David Lightfoot](https://reader035.vdocuments.us/reader035/viewer/2022062516/56649d555503460f94a32a48/html5/thumbnails/22.jpg)
22
Value Variable Value: a constant,no location in time or space
Variable: holder for value, has location in time space
![Page 23: 1 Propositional Logic From Chapter 4 Formal Specification using Z David Lightfoot](https://reader035.vdocuments.us/reader035/viewer/2022062516/56649d555503460f94a32a48/html5/thumbnails/23.jpg)
23
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.
![Page 24: 1 Propositional Logic From Chapter 4 Formal Specification using Z David Lightfoot](https://reader035.vdocuments.us/reader035/viewer/2022062516/56649d555503460f94a32a48/html5/thumbnails/24.jpg)
24
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
![Page 25: 1 Propositional Logic From Chapter 4 Formal Specification using Z David Lightfoot](https://reader035.vdocuments.us/reader035/viewer/2022062516/56649d555503460f94a32a48/html5/thumbnails/25.jpg)
25
Exercise 0
• Draw the truth table for:
• p XOR q
• Show that the following two definitions are equivalent.
• p XOR q (p q) ¬(p q)
• p XOR q (p ¬q) (¬p q)
![Page 26: 1 Propositional Logic From Chapter 4 Formal Specification using Z David Lightfoot](https://reader035.vdocuments.us/reader035/viewer/2022062516/56649d555503460f94a32a48/html5/thumbnails/26.jpg)
26
Exercise 1
• Show by truth table that:
(P Q) (¬P Q)
![Page 27: 1 Propositional Logic From Chapter 4 Formal Specification using Z David Lightfoot](https://reader035.vdocuments.us/reader035/viewer/2022062516/56649d555503460f94a32a48/html5/thumbnails/27.jpg)
27
Exercise 2
• Show by truth table that:
(P Q) (Q P) (P Q)
![Page 28: 1 Propositional Logic From Chapter 4 Formal Specification using Z David Lightfoot](https://reader035.vdocuments.us/reader035/viewer/2022062516/56649d555503460f94a32a48/html5/thumbnails/28.jpg)
28
Exercise 3
• By using the laws from chapter 4 simplify:
¬(p onboard onboard < capacity
![Page 29: 1 Propositional Logic From Chapter 4 Formal Specification using Z David Lightfoot](https://reader035.vdocuments.us/reader035/viewer/2022062516/56649d555503460f94a32a48/html5/thumbnails/29.jpg)
29
Exercise 3: Answer
• By using the laws from chapter 4 simplify:
¬(p onboard onboard < capacity
¬(p onboard) ¬onboard < capacity
p onboard onboard capacity
![Page 30: 1 Propositional Logic From Chapter 4 Formal Specification using Z David Lightfoot](https://reader035.vdocuments.us/reader035/viewer/2022062516/56649d555503460f94a32a48/html5/thumbnails/30.jpg)
30
Exercise 4
• By using the laws from chapter 4 simplify:
(a b) (a c) (a ¬c)
![Page 31: 1 Propositional Logic From Chapter 4 Formal Specification using Z David Lightfoot](https://reader035.vdocuments.us/reader035/viewer/2022062516/56649d555503460f94a32a48/html5/thumbnails/31.jpg)
31
Exercise 4: Answer
• By using the laws from chapter 4 simplify:
(a b) (a c) (a ¬c)
a (b c ¬c)
a (b true) a true a
![Page 32: 1 Propositional Logic From Chapter 4 Formal Specification using Z David Lightfoot](https://reader035.vdocuments.us/reader035/viewer/2022062516/56649d555503460f94a32a48/html5/thumbnails/32.jpg)
32
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.
![Page 33: 1 Propositional Logic From Chapter 4 Formal Specification using Z David Lightfoot](https://reader035.vdocuments.us/reader035/viewer/2022062516/56649d555503460f94a32a48/html5/thumbnails/33.jpg)
33
Exercise 5
• Given • p loggedIn p user
Check that
p loggedIn p user
can be simplified to:
p loggedIn
user truth table
![Page 34: 1 Propositional Logic From Chapter 4 Formal Specification using Z David Lightfoot](https://reader035.vdocuments.us/reader035/viewer/2022062516/56649d555503460f94a32a48/html5/thumbnails/34.jpg)
34
Exercise 5 Answer
• Given • p loggedIn p user
----
p loggedIn 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
![Page 35: 1 Propositional Logic From Chapter 4 Formal Specification using Z David Lightfoot](https://reader035.vdocuments.us/reader035/viewer/2022062516/56649d555503460f94a32a48/html5/thumbnails/35.jpg)
35
Exercise 6
• Use DeMorgan’s Laws to simplify •
62 xx
![Page 36: 1 Propositional Logic From Chapter 4 Formal Specification using Z David Lightfoot](https://reader035.vdocuments.us/reader035/viewer/2022062516/56649d555503460f94a32a48/html5/thumbnails/36.jpg)
36
Exercise 6:Answer
• Use DeMorgan’s Laws to simplify
• ¬(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
62 xx
![Page 37: 1 Propositional Logic From Chapter 4 Formal Specification using Z David Lightfoot](https://reader035.vdocuments.us/reader035/viewer/2022062516/56649d555503460f94a32a48/html5/thumbnails/37.jpg)
37
Exercise 7
• Simplify:
• s=t s EOF t EOF
![Page 38: 1 Propositional Logic From Chapter 4 Formal Specification using Z David Lightfoot](https://reader035.vdocuments.us/reader035/viewer/2022062516/56649d555503460f94a32a48/html5/thumbnails/38.jpg)
38
Exercise 7 Solution
• Simplify:
• s=t s EOF t EOF
• s=t s EOF
![Page 39: 1 Propositional Logic From Chapter 4 Formal Specification using Z David Lightfoot](https://reader035.vdocuments.us/reader035/viewer/2022062516/56649d555503460f94a32a48/html5/thumbnails/39.jpg)
39
Exercise 8
• Simplify:• x=x (x y v x=y)
![Page 40: 1 Propositional Logic From Chapter 4 Formal Specification using Z David Lightfoot](https://reader035.vdocuments.us/reader035/viewer/2022062516/56649d555503460f94a32a48/html5/thumbnails/40.jpg)
40
Exercise 8 Solution
• Simplify:• x=x (x y v x=y)
• x y
![Page 41: 1 Propositional Logic From Chapter 4 Formal Specification using Z David Lightfoot](https://reader035.vdocuments.us/reader035/viewer/2022062516/56649d555503460f94a32a48/html5/thumbnails/41.jpg)
41
Exercise 9
• Simplify:
• x=0 x 0
• x=0
![Page 42: 1 Propositional Logic From Chapter 4 Formal Specification using Z David Lightfoot](https://reader035.vdocuments.us/reader035/viewer/2022062516/56649d555503460f94a32a48/html5/thumbnails/42.jpg)
42
Exercise 10
• Simplify:
• ¬(age 16 v student)
• age < 16 ¬student)