From Chapter 4 Formal Specification using Z David Lightfoot
Published byModified over 4 years ago
Presentation on theme: "From Chapter 4 Formal Specification using Z David Lightfoot"— Presentation transcript:
1 From Chapter 4 Formal Specification using Z David Lightfoot Propositional LogicFrom Chapter 4Formal Specification using ZDavid 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 ¬pfalse truetrue false
3 Propositional calculus Conjunction is pronounced ‘ and’ and is written as L.p q p L qfalse false falsefalse true falsetrue false falsetrue true true
4 Propositional calculus Disjunction is pronounced ‘ or’ and is written as v.p q p v qfalse false falsefalse true truetrue false truetrue true true
5 Implication Definition If p and q are propositions, the compound propositionif p then qis called a conditional proposition (‘implies’) and is denoted asThe proposition p is called the hypothesis (or antecedent )and the proposition q is called the conclusion (or consequence). Can also be written as:
6 Truth Table For Implication (Conditional Proposition)
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 rainingraining raincoat (true)raining ¬raincoat (false)¬raining raincoat (true)¬raining ¬raincoat (true)To get truth value for last twocases apply (¬P v Q)(¬P v Q)P Q P QF F TF T TT F FT T T
8 Implication P Q is a predicate that is true if (¬P v Q) Example: (11 > 3) (2+2=5) is false(11>3) (2+2=4) is trueP Q P QF F TF T TT F FT T T
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:
10 EquivalenceAn alternative ways to state the equivalence (or a bi-conditional proposition) are:p is equivalent to qp is a necessary and sufficient condition for qp if and only if q
13 DeMorgan’s Laws¬(P L Q) ¬P v ¬Q¬(P v Q) ¬Q L ¬P
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 L Q) ¬P v ¬QWe complete the truth table, building towards the expressions to be compared.Write the truth table for DeMorgan’s laws in Word, using Z fonts.
15 Using Laws of LogicLaws 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.
16 Order of evaluation 1. Logical connectives within brackets. 2. Negation3.45Where you have a choice use brackets.Associativity is left except for the conditional which is right.
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 v ¬B ) (Shakespear).A contradiction is always false e.g.:(B L¬B )
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.
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 .
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.
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 QContratrast this definition with implies, which can be defined in terms of a truth table. Difffers form Stimulus/Response and Condition/Response.
22 Value Variable Value: a constant,no location in time or space Variable: holder for value, has location in time space
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 onesUndefined 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.
24 Logical Argument A logical argument is a sequence of propositions: p1 Punch is a catp2 All cats are cleverpnq Punch is clever
25 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)
26 Exercise 1Show by truth table that:(P Q) (¬P v Q)
27 Exercise 2Show by truth table that:(P Q) L (Q P) (P Q)
28 Exercise 3 By using the laws from chapter 4 simplify: ¬(p onboard L #onboard < capacity )
29 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 )
30 Exercise 4 By using the laws from chapter 4 simplify: (a L b) v (a L c) v(a L ¬c)
31 Exercise 4: Answer By using the laws from chapter 4 simplify: (a L b) v (a L c) v(a L ¬c)a L (b v c v ¬c)a L (b v true) a L true a
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.
33 Exercise 5 Given p loggedIn p user Check that p loggedIn L p user can be simplified to:p loggedInuser truth table
34 Exercise 5 Answer Given p loggedIn p user ---- p loggedIn L p user Can only be true is if both sub-expressions are trueBecause of the given implication ifp loggedInthen so isp user