Presentation is loading. Please wait.

Presentation is loading. Please wait.

Formal Specification and Z CS3300 Fall 2015. Formal Specification Produces a mathematical model Typically associated with analysis Differs from design.

Similar presentations


Presentation on theme: "Formal Specification and Z CS3300 Fall 2015. Formal Specification Produces a mathematical model Typically associated with analysis Differs from design."— Presentation transcript:

1 Formal Specification and Z CS3300 Fall 2015

2 Formal Specification Produces a mathematical model Typically associated with analysis Differs from design diagrams because they have formal semantics Currently used in some safety critical applications, but not in general development Issues with scaling and translation to code

3 Formal Specification Languages VDM Larch Alloy Z (zed) OCL And a host of others

4 Z Model-based notation Collection of state variables Operations that change state This is a notation, not a methodology

5 Specify a Text Editor First we define some primitive types. These are in square brackets: [CHAR] And then some composite types: TEXT == seq CHAR These definitions are considered global. Say we have a constraint, for this we use an axiomatic constraint

6 maxsize :  maxsize <=65535 Then we can define a Schema – combines data and invariants Editor left, right : TEXT # (left ^ right) <= maxsize

7 Now we specify what happens on initialization, Zed provides a special schema Init Init Editor left = right = Now we need to introduce some operations, but first we need another axiomatic definition printing : Ƥ CHAR

8 And now we can define our actual operation schema Insert  Editor ch? : CHAR ch? ∈ printing left' = left ^ right' = right

9 What about moving right with the arrow key? We have to recognize the difference with Insert right_arrow : CHAR right_arrow ∉ printing Forward Δ Editor ch? : CHAR ch ? = right_arrow left' = left ^ right' = tail(right)

10 Forward Δ Editor ch? : CHAR ch ? = right_arrow right != left' = left ^ right' = tail(right) Completing the preconditions But what should we do if the right is empty?

11 T_Forward ≙ Forward ⋁ (EOF ⋀ RightArrow ⋀ Ξ Editor) EOF Editor right =

12 Let'sTry some on our own Delete Backward (moves cursor back one) T_Backward

13 How about a Birthday Book Keep track of names and dates We define our basic types: [NAME, DATE]

14 Basic Schema BirthdayBook known : ℙ NAME birthday : NAME ↦ DATE known = dom birthday

15 Initialization Init BirthdayBook known = ∅

16 How about adding a birthday? AddBirthday ∆ BirthdayBook name? : NAME date? : DATE birthday' = birthday ∪ {name? ↦ date?} name? ∉ known

17 How about looking up a birthday? FindBirthday Ξ BirthdayBook name? : NAME date! : DATE name? ∊ known date! = birthday(name?)

18 How about find everyone whose birthday is today? Remind Ξ BirthdayBook today? : DATE cards! : ℙ NAME cards! = { n : known | birthday(n) = today? }

19 How about errors? REPORT ::= ok | already_known | not_known Success result! : REPORT result! = ok

20 What about adding an already known name? AlreadyKnown Ξ BirthdayBook name? : NAME result! : REPORT name? ∊ known result! = already_known T_AddBirthday = AlreadyKnown ∨ (AddBirthday ∧ Success)


Download ppt "Formal Specification and Z CS3300 Fall 2015. Formal Specification Produces a mathematical model Typically associated with analysis Differs from design."

Similar presentations


Ads by Google