Title: Z Predicates and Schemas
1Z Predicates and Schemas
- SE 420, Formal Methods
- Mark Ardis, RIT
2Outline
- Predicate Calculus
- Logical connectives
- Quantifiers
- Schemas
- Definition
- Initialization
- Operations
- Schema calculus
3Logical Connectives
4Universal Quantifiers
- divides Z ? Z
- ? d, n Z d divides n ? n mod d 0
- 2 divides 14
- (2, 14) ? divides
Note underline syntax for infix binary operator
5Existential Quantifiers
- ? i Z i lt 10
- ? x ? y x lt y
- ? y ? x x lt y
6Cartoon of the Day (1/2)
7Cartoon of the Day (2/2)
8Editor Example
- User can type in text
- User can move cursor forward and backward through
the text - User can delete the character in front of the
cursor
9State schemas
- Editor
- left, right TEXT
- ( left ? right ) ? maxsize
left is before the cursor, right is after
closed box means that the declarations are local
10Vending Machine Example
q
d
d
n
n
n
n
n
d
d
11Exercise 1
Write a Z state schema for the vending machine
example, keeping track of the number of nickels,
dimes and quarters. Include a component of the
state that represents the monetary sum of the
coins.
12Initialization schemas
conventional name begins with Init
- InitEditor
- Editor
- left right ltgt
Editor is included
left and right come from Editor
13Exercise 2
Write the Z initialization schema for the vending
machine.
14Operation schemas
global declaration of printing characters
- printing P Char
- Insert
- ? Editor
- ch? CHAR
- ch? ? printing
- left left ? ltch?gt
- right right
? means that the state will change
? means input (! means output)
precondition
left is the value after the operation
15Exercise 3
Specify a version of the Add_Dime operation that
only works if the amount of money in the machine
is less than 20 cents.
16Implicit preconditions
- right_arrow CHAR
- right_arrow ? printing
- Forward
- ? Editor
- ch? CHAR
- ch? right_arrow
- left left ? lthead(right)gt
- right tail(right)
implicit precondition right ? ltgt
17Schema calculus
- EOF
- Editor
- right ltgt
- RightArrow
- ch? CHAR
- ch? right_arrow
- T_Forward Forward ? ( EOF ? RightArrow ? ?
Editor )
another state schema
an operation schema
? means that the state does not change
a one-line schema definition
18Exercise 4
Specify a total function T_Add_Dime in terms of
Add_Dime.