42
1 Propositional Logic From Chapter 4 Formal Specification using Z David Lightfoot

1 Propositional Logic From Chapter 4 Formal Specification using Z David Lightfoot

  • View
    218

  • Download
    0

Embed Size (px)

Citation preview

Page 1: 1 Propositional Logic From Chapter 4 Formal Specification using Z David Lightfoot

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

37

Exercise 7

• Simplify:

• s=t s EOF t EOF

Page 38: 1 Propositional Logic From Chapter 4 Formal Specification using Z David Lightfoot

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

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

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

41

Exercise 9

• Simplify:

• x=0 x 0

• x=0

Page 42: 1 Propositional Logic From Chapter 4 Formal Specification using Z David Lightfoot

42

Exercise 10

• Simplify:

• ¬(age 16 v student)

• age < 16 ¬student)