Title: Software Engineering
1Software Engineering
- Refining requirements using Formal methods
2Review of discrete math
- Sets
- Finite e.g. 1,2,3
- Infinite e.g. ?
- Bags
- Sequences e.g. lt 1, 3, 3, 1gt
3Review of discrete math
- Power set of a set, ?
- What is ?1,2,3?
- What is ??
- Consider the following sets, well use in later
examples - A 1, 2, 3
- B 3, 1, 4, 7
4Review of discrete math
- Set operations
- x ? A
- x ? A
- A ? B
- A ? B
- A ? B
5Review of discrete math
- Existential and universal quantification
- ?
- ?
6Review of discrete math
- Binary Relations
- A binary relation on two sets, A and B, is a
subset of A x B - Examples lt,?
- Properties
- Reflexive
- Symmetric
- Antisymmetric
- Transitive
7Why formal methods
- Our specifications (even with the diagrams) tend
to be imprecise - Particularly inputs and outputs are often
ill-defined - Mathematics offers the promise of a precision
that doesnt exist in English
8Introducing the formal method, Z
- Definition A set of conventions for presenting
mathematical text, chosen to make it convenient
to use simple mathematics to describe computing
systems. (Jacky) - 3 parts of Z are
- Types
- Axiomatic descriptions
- Schemas
9Z types
- Definition A type is an expression of a
restricted kind (Spivey 24) - Zs only built-in types integers (?) and natural
numbers (?) - Some of the ways to declare new types
- New types
- PLANETS mercury venus earth mars
jupiter saturn uranus neptune pluto - Using other types
- SOLAR_SYSTEM PLANETS ? ASTERIOD_BELT ? SUN
10Types, continued
- What makes up a zip code?
- How can the ZIP type be created
- as a new type?
- using other types?
11Axiomatic Descriptions
- Definition An axiomatic description
introducesglobal variableswhich may or may not
specify a constraint on their values. (Spivey
48) - Two ways to declare axiomatic descriptions
- With the predicate (want to know exactly what is
in there)
lower_letters, upper_letters ? CHAR
lower_letters a, b, c, d,
e, f, g, h, i, j, k, l, m, n,
o,p,q, r, s, t, u, v, w,
x, y, z upper _letters A, B, C,
D, E, F, G, H, I, J, K, L, M,
N, O, P,Q, R, S, T, U, V,
W, X, Y, Z
12- Two ways to declare axiomatic descriptions
- Without a predicate (give the type of everything
and let the reader assume from there)
student_table ID ? NAME ? ADDRESS ? MAJOR ?
SCHEDULE
13Axiomatic descriptions
- takes a seq of any type and returns the nth
element - elementAt_ ? ? seq X ? X
- perm(A) B says that seq B is a permutation of
set A, where both A and B are of type X - perm_ ? X ? seq X
- the following allow me to find out how many xs
are in the sequence modified Spivey 124 I took
def for bags and made it for seq - __ seq X ? X ? ?
- ? s seq X ? (? n ? ? 0 ? n lt s 1 ? dom(s)
n ? elementAt(n) ran(s)) - ? s1 ? X s2 seq X ? perm(s1) s2 ? s1 s2
? - (? x X ? x ? s1 ? x ? s2 ? s1x
s2x) - literally taken from Spivey 124
- ? x X S seq X ? Sx count Sx
- // count Aa simply counts how many as are in A
14Schemas
- Definition A schema isused to describe some
part of the state or an operation on the state
(Barden) - Schemas structure
- ???????NameOfSchema?????????
- ? VariableDeclarations
- ? Predicate
. - VariableDeclarations introduce local variables
and provides the type of them - Predicate that which is true in order for this
state to occur
15Schemas adding a new student to a table
- ????????NewStudent?????????????????????????
- ?// new students info
- ? newStudentID? ID
- ? newStudentName? NAME
- ? newStudentAddress? ADDRESS
- ? newStudentMajor? MAJOR
- ?
- ? // local variables
- ? // used to go through student table
- ? temp ID ? NAME ? ADDRESS ? MAJOR ? SCHEDULE
- ? // make sure ID isnt already in the table
- ?(? temp temp ? student_table ? newStudentID? ?
dom(temp)) - ?
- ? // the ID is unique add student
- ? student_table student_table ? (newStudentID?
? newStudentName? ? - ? newStudentAddres? ? newStudentMajor)
- ??????????????????????????????????????????????????
???????
16How to get the Z font?
- Go to
- http//www.cs.kent.ac.uk/people/staff/rej/Zedfont/
latest/ - And follow the directions.