450 likes | 552 Views
Lecture 10 Z MDA for Graphical User Interface. Review Lecture 9 Proposition, First Order Logic. Roadmap for Today Z background Z language constructs and syntax Z schema. Z Background. History Invented at 70s, program research group @ oxford, J. R . Abrial ,
E N D
Review Lecture 9 Proposition, First Order Logic Roadmap for Today • Z background • Z language constructs and syntax • Z schema
Z Background • History • Invented at 70s, program research group @ oxford, J. R. Abrial, • 2002, standardized by ISO • Why Z • Easy to find faults • High school math • Precise • A list of related tools: Type Checker, Z deduction system • Community Z Tools (CZT) project • Tools for developing and checking Z specifications in Microsoft word • Latex style tools
Basic Vocabulary of Z • Z: typed first-order predicate logic • Three basic elements • Sets, Set Operations, Logic • Sets may be enumerated: { red, yellow, green }
Z Types and Sets • Every Zexpression (arithmetic, set) has a type that can be determined • A type is either • a given set, or • a compound type built up from simpler types using a type constructor A set is not necessarily a type, but a type is a set • There are a few predefined sets: Z , N , N1 • All sets must contain elements of the same type • The only predefined type is Z • N is a set, but all of its elements are members of Z
Predicates, Equations • There is no Boolean type in Z: • Predicates are not expressions, they are assertions about values. • Equations are not expressions, they are predicates that equate to values.
Possible Set Definitions Note All types are disjoint (not for sets that are used as types) All terms have a unique type
Defining types and abbreviations [CHAR] introduce a basic data type by enclosing its name in square brackets COLOR ::= red | green | blue introduce a free type by enumerating its elements TEXT == seq CHAR introduce an abbreviation by using “==“ Convention: upcase
Normalization • Normalization: stating the types (not just the sets) of each variable SMALL = { 1, 2, 3 } BIG = { 100, 200, 300} s, b: Z s: SMALL; b: BIG s SMALL b BIG un-normalized (declaration with sets) normalized
Expressions • Sets • union: { 1, 2, 3} {3, 4} = { 1, 2, 3, 4} • difference: {1, 2, 3, 4} \ { 2, 3} = { 1, 4} • intersection: {1, 2, 3, 4} {2, 3} = { 2, 3} • cardinality: # { red, white, blue} = 3 • Arithmetic • mathematical tool-kit contains standard operators: +, -, * • Integer division only 13 div 5 = 2 13 mod 5 = 3
Declarations and Variables • Variables are declared as being of a type or set: i: Z color: { red, yellow, green } • Variables may be constrained when defined: size: N size > 640
Axiomatic definitions Declarations above the line iroot: N → N • a: N• iroot(a)*iroot(a) a < (iroot(a)+1) * (iroot(a)+1) Z paragraph Predicates below the line
Tuples and Records • Cartesian product types (or cross product types) can be used to describe tuples: DAY == 1..31; MONTH == 1..12; YEAR == Z DATE == DAY × MONTH × YEAR landing, birth: DATE landing = (20, 7, 1969) birth = (7, 4, 1949)
Relations • A set of tuples defines a relation [NAME] ID == N DEPT ::= admin | man | rsrch EMPLOYEE == ID × NAME × DEPT Employee: P EMPLOYEE Employee = { ( 111, Larry, admin ) ( 222, Curly, man ) ( 333, Mo, rsrch ) }
Binary Relations • A set of 2-tuples (pairs) defines a binary relation [NAME] PHONE == 0..9999 phone: NAME PHONE phone = { groucho | 1234, harpo | 2345, chico | 3456 }
Domain and Range • Recall this binary relation: phone = { groucho | 1234, harpo | 2345, chico | 3456 } domphone = { groucho, harpo, chico } ran phone = { 1234, 2345, 3456 }
Operators for Relations • Restriction { groucho, harpo } <| phone = { groucho | 1234, harpo | 2345 } phone |> (3000..3999) = { chico | 3456 } • Overriding phone + { groucho | 5555 } = { groucho | 5555, harpo | 2345, chico | 3456 } • Inverse phone ~ = { 5555 |groucho, 2345 |harpo, 3456 | chico }
Sequences • sequences are functions, which are relations, which are sets week day == {1 |Monday, 2 | Tuesday, 3 |Wednesday, 4 | Thursday, 5 |Friday} weekday == <Monday, Tuesday, Wednesday, Thursday, Friday>
Sequence operations head: head (<Good, Fair, Poor>) = Good last: last (<Good, Fair, Poor>) = Poor tail: tail (<Good, Fair, Poor>) = <Fair,Poor> front: front (<Good, Fair, Poor>) = <Good, Fair> Concatenation: week == <Sunday> weekday <Saturday>
Lambda Expression Function isqr isqr == {i: Z• i i*i} (def using set) isqr == ( i: Z • i*i ) (lambda expression) isqr: Z → N i: Z •isqr i = i*i
Z Schema • The Z schema is a 2-dimensional graphical notation for describing: – state spaces – operations • Definition: A vertical-form schema is either of the form
Z Schema Or • In the latter case, the predicate part is assumed to be ‘true’.
Z Schema • The declarations part of the schema will contain: – a list of variable declarations; and – references to other schemas (this is called schema inclusion) • Variable declarations have the usual form: x1; x2; : : : ; xn : T; • The predicate part of a schema contains a list of predicates, separated either by semi-colons or new lines.
State and Operation Schema States A state is a variable assignment A schema describes a set of states Operations To describe an operation, a schema must describe pairs of states (pre/post) Variables are decorated with ‘ to refer to their value in the post state
State Schema • The value of tel will be a partial function from NAME to PHONE, i.e., it will associate names with phone numbers
Operation Schemas • In specifying a system operation, we must consider: • the objects that are known to remain unchanged by the operation • the objects that may be altered by the operation • pre-conditions • post-conditions
Example: Phonebook Lookup Analyze the problem: • Accesses the PhoneBookschema • It does not change it • Takes a single ‘input’ —a name • Produces a single output —a phone number • Pre-condition: the name is known to the database.
To Do • Proposal (due 10/10 4:00pm) • Reading assignment - Wed 10/12 in class • Alloy?
Wild & Crazy Ideas Career Paths of Software Engineers? Where will we be in the future? Can I code at 60?