Formal Methods and Models Z Specification of the

  • Slides: 22
Download presentation
Formal Methods and Models Z Specification of the Library System Boumediene Belkhouche Fall 2012

Formal Methods and Models Z Specification of the Library System Boumediene Belkhouche Fall 2012

Library System Description � � � � � The library has many books on

Library System Description � � � � � The library has many books on different topics The library has registered readers A book may have several copies Each copy in the library has a unique ID Each reader has a unique ID At any time a certain number of copies of books are on loan to readers A reader cannot borrow more than a certain maximum Available books are kept on the library shelves A book can be borrowed or returned When a book is returned, it is put back on the shelf 2

Library System Operations � � � � Issue a copy of a book to

Library System Operations � � � � Issue a copy of a book to a reader (borrow) Return a copy of a borrowed book by the reader Add a copy of a book to the library Remove a copy of a book from the library Enquire which books are borrowed by a given reader Enquire which reader has a given book Register a new reader Remove an existing reader 3

A Z Specification Consists of 4 parts Ø Given sets, data types and constants

A Z Specification Consists of 4 parts Ø Given sets, data types and constants Ø State definition Ø Initial state Ø Operations 4

Z Specification of the Library 1. Given Sets [Book, Copy, Reader] NB. Symbols used:

Z Specification of the Library 1. Given Sets [Book, Copy, Reader] NB. Symbols used: � �↦ Ξ ∀ × → Δ ≠ ∧ ∨ ∉ ∈ ∅ ∃ ℤ ℕ ℙ ℝ ≙ �������� � 5

Z Specification of the Library 2. State definition Library stock: Copy � Book issued:

Z Specification of the Library 2. State definition Library stock: Copy � Book issued: Copy � Reader shelved: �Copy readers: �Reader shelved dom issued = dom stock shelved dom issued = ran issued readers ∀ r : readers �#(issued �{r}) �maxloans 6

Explanations �stock records copies of books in the library �issued records which copies are

Explanations �stock records copies of books in the library �issued records which copies are on loan and to whom �shelved is a subset of the copies on the shelves and available for borrowing �readers is the set of registered readers 7

Z Specification of the Library 3. Initial State Library_Init ΔLibrary shelved’ = Ø issued’

Z Specification of the Library 3. Initial State Library_Init ΔLibrary shelved’ = Ø issued’ = Ø readers’ = Ø 8

9

9

Symbols used: � � �↦ Ξ ∀ × → Δ ≠ ∧ ∨ ∉

Symbols used: � � �↦ Ξ ∀ × → Δ ≠ ∧ ∨ ∉ ∈ ∅ ∃ ℤ ℕ ℙ ℝ ≙ �: Teacher-Course {ITBP 120} tuples whose second element is “ITBP 120” are returned. � �: { bb } Teacher-Course tuples whose first element is “bb” are returned. : dir {num? } tuples whose second element is “num? ” are removed. � � : {name? } dir � tuples whose first element is “name? ” are removed. � � 10

Function override operator Function override adds pairs from f 1 to f 2 such

Function override operator Function override adds pairs from f 1 to f 2 such that it: �acts as a domain subtraction and a set union, if any element of f 2 is mapped anywhere by f 1, {Noura Œ project. A } {Noura Œ new. Proj} = ({Noura } studentproject) {Noura Œ new. Proj} 11

Z Specification of the Library 4. Operations Wcopies. OK �Library c! : �Copy r?

Z Specification of the Library 4. Operations Wcopies. OK �Library c! : �Copy r? : Reader r? ∈ readers c! = dom (issued �{r? }) �Restricts range to only those elements of the argument 12

Z Specification of the Library 4. Operations Remove. Copy. OK Library c? : Copy

Z Specification of the Library 4. Operations Remove. Copy. OK Library c? : Copy c? ∈ shelved’ = shelved {c? } stock’ = {c? } �stock �Restricts the domain to only those elements not equal to the argument 13

Z Specification of the Library 4. Operations Borrow Library c? : Copy r? :

Z Specification of the Library 4. Operations Borrow Library c? : Copy r? : Reader c? ∈ shelved r? ∈ readers # (issued �{r? }) �maxloans issued’ = issued �{c? ↦ r? } shelved’ = shelved �{c? } stock’ = stock; readers’ = readers 14

Z Specification of the Library 4. Operations Return Library c? : Copy r? :

Z Specification of the Library 4. Operations Return Library c? : Copy r? : Reader c? ∈ dom issued r? ∈ readers issued’ = issued �{c? ↦ r? } shelved’ = shelved �{c? } stock’ = stock; readers’ = readers 15

A Z Specification for the Library IS 4. Operations Who. Has. Copy Ξ Library

A Z Specification for the Library IS 4. Operations Who. Has. Copy Ξ Library c? : Copy; r! : Reader c? ∈ dom issued r! = issued (c? ) 16

Z Specification of the Library 4. Operations Register. Reader Library r? : Reader r?

Z Specification of the Library 4. Operations Register. Reader Library r? : Reader r? ∉ readers’ = reader � {r? } 17

Z Specification of the Library 4. Operations Remove. Reader Library r? : reader r?

Z Specification of the Library 4. Operations Remove. Reader Library r? : reader r? ∈ readers’ = reader � {r? } What if r? has borrowed books? 18

Z Specification of the Library 4. Operations Add. Copy. Report Ξ Library stock: Copy

Z Specification of the Library 4. Operations Add. Copy. Report Ξ Library stock: Copy � Book b? : Book rep! : Report b? ∈ ran stock �rep! = Copy. Added b? ∉ ran stock �rep! = New. Title. Added 19

Z Specification of the Library 4. Operations Enter. New. Copy Library b? : Book

Z Specification of the Library 4. Operations Enter. New. Copy Library b? : Book �c: Copy � c ∉ dom stock � stock’ = stock �{c ↦ b? } shelved’ = shelved �{c} issued’ = issued; readers’ = readers 20

Z Specification of the Library 4. Operations Add. Copy ≙ Enter. New. Copy ∧

Z Specification of the Library 4. Operations Add. Copy ≙ Enter. New. Copy ∧ Copy. Report 21

Z Specification of the Library 4. Operations Execise: do 1. 2. Which books a

Z Specification of the Library 4. Operations Execise: do 1. 2. Which books a reader has Remove a copy from the library 22