Based on chapter 15 in The Way of Z.
Links to more Z lectures.
This page looks best when this
and this X are
about the same size:
X. See these viewing tips.
All properties do not have to be spelled out explicitly. From a few properties, we can infer many more by formal reasoning (applying rules).
Enables a formal model to act as a non-executable prototype.
Investigate behavior in hypothetical situations.
Validate a specification against requirements.
Check consistency and completeness.
Calculate preconditions.
Check refinement from specification to detailed design.
CALCULATION AND PROOF
An exercise in formal reasoning is a kind of calculation.
``A train moves at a constant velocity of sixty miles per hour. How far does the train travel in four hours?''
| distance, velocity, time: | ||
![]() | ||
![]() | ||
| distance = velocity * time | ||
| velocity = 60 | ||
| time = 4 | ||
To find distance, substitute equals for equals. From a=b and b=c, conclude a=c.
| distance = velocity * time | Definition |
| velocity = 60 | |
| time = 4 | |
| Arithmetic |
The proof is a predicate in vertical format.
REASONING ABOUT SETS
Calculations need not be arithmetic.
``Philip works on the adhesives team in the materials group, which is part of the research division. Is Philip in research?''
| philip: PERSON | ||
| adhesives, materials, research,manufacturing: | ||
![]() | ||
![]() | ||
| adhesives | ||
| materials | ||
| philip | ||
Show philip
research.
| philip | Definition |
| Definition | |
| Definition |
Like equality, the subset relation is transitive.
From S
T
U, infer
S
U.
REASONING WITH EQUIVALENCE AND IMPLICATION
Each step can be a predicate, connected by
the transitive logical connectives
and
.
| x: | ||
![]() | ||
![]() | ||
| 2*x + 7 = 13 | ||
Solve for x
| 2*x + 7 = 13 | Definition |
| -7, both sides | |
| Arithmetic | |
| div 2, both | |
| Algebra | |
| Arithmetic |
We have proved 2*x + 7 = 13
x = 3.
LAWS
Formal reasoning steps are justified by laws: predicates that are always true, for any values of the place holders.
Place holders can stand for expressions.
| 0 * n = 0 | Zero |
| d | Division |
| x=y | Leibniz |
Place holders can stand for predicates.
| p | Excluded middle |
| p | Contradiction |
| DeMorgan | |
| p | Distrib. |
SELECTED LAWS
About logical connectives
| p | Unit of and |
| p | Zero of and |
About sequences
| # | Size of singleton |
| ran | Range of singleton |
| # (s | # and |
| ran (s | ran and |
About the existential quantifier
| Restricted | |
| 1-pt. rule |
PRECONDITIONS BY INSPECTION
The precondition is the predicate that must be true for the operation to be defined, involving only inputs and unprimed ``before'' variables.
![]() |
Forward | ![]() | |
![]() |
|||
![]() | |||
| ch?: CHAR | |||
![]() | |||
![]() | |||
| ch? = right_arrow | |||
| right | |||
| left' = left | |||
| right' = tail(right) | |||
![]() | |||
The precondition is
| ch? = right_arrow |
PRECONDITIONS BY INSPECTION (2)
A complete case analysis reduces to p
p
![]() |
T_Forward | ![]() | |
![]() |
|||
![]() | |||
| ch?: CHAR | |||
![]() | |||
![]() | |||
| ch? = right_arrow | |||
| ((right | |||
| (right = | |||
![]() | |||
The precondition is
| ch? = right_arrow | |
| Given | |
| Excluded middle | |
| Unit of and |
PRECONDITIONS BY CALCULATION
Implicit preconditions arise when the operation definition interacts with the state invariant.
The precondition of operation Op on state S is
S'
Op,
``There exists a final state S' that satisfies the
predicate of Op.''
![]() |
Insert | ![]() | |
![]() |
|||
![]() | |||
| ch?: CHAR | |||
![]() | |||
![]() | |||
| ch? | |||
| left' = left | |||
| right' = right | |||
![]() | |||
The precondition of Insert is
| |
PRECONDITION CALCULATION
Editor'
Insert
| Expand schemas | |
| | |
| | |
| | 1-pt. rule w/ left',right' |
| | # and |
| | Size of singleton |
| | Arithmetic |
The precondition is
| ch? |
The buffer mustn't overflow!
REFINEMENT, IMPLEMENTATION
Implication can be used to check the correctness of design steps (refinement steps).
p
q means p has all the properties of q, and
possibly more besides. If you asked for q, you should be satisfied
with p.
| stronger |
| concrete |
| implementation |
| impl. |
Example
| x' > x | Specification |
| x' = x+1 | Implementation |
| x' = x+1 | Proof |
Back to Z lectures.