duminda wijesekeraswe 623: fall 20021 schemas in z chapter 6 in potter sinclair and till

28
Duminda Wijeseke ra SWE 623: Fall 2002 1 Schemas in Z Chapter 6 in Potter Sinclair and Till

Upload: annabel-karen-griffith

Post on 04-Jan-2016

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Duminda WijesekeraSWE 623: Fall 20021 Schemas in Z Chapter 6 in Potter Sinclair and Till

Duminda Wijesekera SWE 623: Fall 2002 1

Schemas in Z

Chapter 6 in Potter Sinclair and Till

Page 2: Duminda WijesekeraSWE 623: Fall 20021 Schemas in Z Chapter 6 in Potter Sinclair and Till

Duminda Wijesekera SWE 623: Fall 2002 2

Schemas

• Z’s main representational mechanism of structure and functions.

• Example:

initialStock: Stock

# initialStock < maxlines

i :ITEM; n : N | (i,n)initalStock /\ n<100

stockItem : P ITEM

stockItems = dom initialStock

Page 3: Duminda WijesekeraSWE 623: Fall 20021 Schemas in Z Chapter 6 in Potter Sinclair and Till

Duminda Wijesekera SWE 623: Fall 2002 3

Schemas Describing Abstract States

Account Opened

AccountOverdrawn

AuthorizedWithdrawal

Account closed

Account in Good Standing

Overdraft Paid Off

Regular Withdrawal

Deposit

Page 4: Duminda WijesekeraSWE 623: Fall 20021 Schemas in Z Chapter 6 in Potter Sinclair and Till

Duminda Wijesekera SWE 623: Fall 2002 4

Schemas Describing Abstract StatesExample 1:

BankAccount 1total, minBalance: R

` total > minBalanceExample 2:

BankAccount 2total, minBalance: R

` inGoodStanding: BOOLEANinGoodStanding (total > minBalance)

Page 5: Duminda WijesekeraSWE 623: Fall 20021 Schemas in Z Chapter 6 in Potter Sinclair and Till

Duminda Wijesekera SWE 623: Fall 2002 5

Schemas Describing OperationsBankAccount with Operations

total, minBalance: R

withdraw : R BOOL

overDraft: R x BOOL R

total > minBalance

x?:R;out!:Bool. [total – x? < minBalance => out! = withdraw(x?)/\out! = TRUE /\ total’ = total-x]

\/[total – x? > minBalance => out! =FALSE /\

out! = withdraw(x?)/\ total’ = total ]

Page 6: Duminda WijesekeraSWE 623: Fall 20021 Schemas in Z Chapter 6 in Potter Sinclair and Till

Duminda Wijesekera SWE 623: Fall 2002 6

Schema Calculus: Operations on Schemas

• Schemas can be built from other schemas.• Schema calculus has some operations on schemas to

build new schemas from the old.• Operations:

– Inclusion– Decoration– Disjunction– Conjunction– Negation– composition

Page 7: Duminda WijesekeraSWE 623: Fall 20021 Schemas in Z Chapter 6 in Potter Sinclair and Till

Duminda Wijesekera SWE 623: Fall 2002 7

Inclusion - 1BankAccount with Operations

Bank Account 1

Bank Overdraft

Where Bank Overdraft can be defined separately

Page 8: Duminda WijesekeraSWE 623: Fall 20021 Schemas in Z Chapter 6 in Potter Sinclair and Till

Duminda Wijesekera SWE 623: Fall 2002 8

Inclusion - 2Bank Regular Withdrawtotal, minBalance: Rwithdraw : R BOOLoverDraft: R x BOOL Rtotal > minBalancex?:R;out!:Bool. [total – x? < minBalance => out! = withdraw(x)/\out! = TRUE /\

minBalance’ = minBalance-x?] \/[total – x? > minBalance => out! =FALSE /\

out! = withdraw(x?)/\ total’ = total ]

Page 9: Duminda WijesekeraSWE 623: Fall 20021 Schemas in Z Chapter 6 in Potter Sinclair and Till

Duminda Wijesekera SWE 623: Fall 2002 9

Decoration• Adding ?, ! And ‘ to variables is referred to

as decoration.

• Can use ‘ for schemas themselves.

• Example:Double Min Balance

Bank Account, Bank Account’

doubleMinBalance: R R

monBalance’ = 2*minBalance

Page 10: Duminda WijesekeraSWE 623: Fall 20021 Schemas in Z Chapter 6 in Potter Sinclair and Till

Duminda Wijesekera SWE 623: Fall 2002 10

Full Expansion of a Decorated Schema

• Replace primed entities by their definitions Double Min Balance

total, total’, minBalance, minBalance’ :R

doubleMinBalance : R R

total > minBalance /\ total’ > minBalance’

Page 11: Duminda WijesekeraSWE 623: Fall 20021 Schemas in Z Chapter 6 in Potter Sinclair and Till

Duminda Wijesekera SWE 623: Fall 2002 11

Schema Disjunction

• Want to specify define two cases separately and state that they are two cases of the same “thing”.

• Example:– Bank WithdrawCash = Bank

RegularWithdraw \/ Bank Overdraft– Bank Regular Withdraw defined earlier

Page 12: Duminda WijesekeraSWE 623: Fall 20021 Schemas in Z Chapter 6 in Potter Sinclair and Till

Duminda Wijesekera SWE 623: Fall 2002 12

Schema Disjunction - 2

Bank Overdraft

Bank Account 1, Bank Account 1’

overdraft : R x BOOL BOOL

x?: R, approve?: BOOL

x?:R;out!:Bool. [approve? => (out! /\ total’=total-x?)

total’ = total-x?]

\/[not approve? => (not out! /\ total’=total)]

Page 13: Duminda WijesekeraSWE 623: Fall 20021 Schemas in Z Chapter 6 in Potter Sinclair and Till

Duminda Wijesekera SWE 623: Fall 2002 13

Schema Conjunction

• When one schema can be written specified as “two specifications”

• Results in taking the conjunction of both constraints

• Example:Bank Overdraft = sendMessage/\adjustBalance

Page 14: Duminda WijesekeraSWE 623: Fall 20021 Schemas in Z Chapter 6 in Potter Sinclair and Till

Duminda Wijesekera SWE 623: Fall 2002 14

Schema Conjunction - 2

send MessageBank Account 1, Bank Account 1’overdraft : R x BOOL BOOLx?: R, approve?: BOOLx?:R;out!:Bool. [approve? => out! /\total’=total-x?)]

\/[ approve? => ( out! /\ total’=total)]

Page 15: Duminda WijesekeraSWE 623: Fall 20021 Schemas in Z Chapter 6 in Potter Sinclair and Till

Duminda Wijesekera SWE 623: Fall 2002 15

Schema Conjunction - 3

Adjust Total

Bank Account 1, Bank Account 1’

overdraft : R x BOOL BOOL

x?: R, approve?: BOOL

x?:R;out!:Bool. [approve? => out! /\ total’ t=total-x?]

\/[ approve? => ( out! /\ total’=total)]

Page 16: Duminda WijesekeraSWE 623: Fall 20021 Schemas in Z Chapter 6 in Potter Sinclair and Till

Duminda Wijesekera SWE 623: Fall 2002 16

Schema NegationExample 1:

BankAccount 1total, minBalance: R

` total > minBalanceBad bank Account = = Bank Account 1

Bad BankAccounttotal, minBalance: R (total > minBalance)

Page 17: Duminda WijesekeraSWE 623: Fall 20021 Schemas in Z Chapter 6 in Potter Sinclair and Till

Duminda Wijesekera SWE 623: Fall 2002 17

Schema Hiding Operations

• Used to hide some variables and declarations of already known schemas.

• Use to hide variables.

• Format– [Decs | Pred] \ Hidden variables– [Reduced Decs | Hidden Decs . Predicate]

Page 18: Duminda WijesekeraSWE 623: Fall 20021 Schemas in Z Chapter 6 in Potter Sinclair and Till

Duminda Wijesekera SWE 623: Fall 2002 18

Schemas Hiding Example -1BankAccount with Operationstotal, minBalance: Rwithdraw : R BOOLoverDraft: R x BOOL Rtotal > minBalancex?:R; app?out!:Bool. [total – x? < minBalance=>out! = overDraft x?, app? /\out! /\

total’ = total-x] \/[total – x? < minBalance => out! =FALSE /\ out! = overDraft(x?,app?)/\ total’=total]

Page 19: Duminda WijesekeraSWE 623: Fall 20021 Schemas in Z Chapter 6 in Potter Sinclair and Till

Duminda Wijesekera SWE 623: Fall 2002 19

Schemas Hiding Example -2BankAccount with Operationstotal, minBalance: Rwithdraw : R BOOLoverDraft: R x BOOL Rtotal > minBalancex?:R; app?out!:Bool. [total – x? < minBalance=>out! = overDraft x?, app? /\out! /\

total’ = total-x] \/[total – x? < minBalance => out! =FALSE /\ out! = overDraft(x?,app?)/\ total’=total]

Page 20: Duminda WijesekeraSWE 623: Fall 20021 Schemas in Z Chapter 6 in Potter Sinclair and Till

Duminda Wijesekera SWE 623: Fall 2002 20

Schema Composition• Recall that function composition:

– If f : S1 -> S2 and g: S2 -> S3 then – fog : S1 -> S3

• Schema Composition imports this idea to schemas.

• Example: Consider overdrawn bank account– To close account:

• Must pay up to minimum balance• Then close account from account in good standing

Page 21: Duminda WijesekeraSWE 623: Fall 20021 Schemas in Z Chapter 6 in Potter Sinclair and Till

Duminda Wijesekera SWE 623: Fall 2002 21

Schema Composition Method

1. Replace primed variables (‘)in first schema with double primed variables (“)

S[“/’]

2. Replace un-primed variables in second schema with double primed variables (“)

T[‘/]

3. Existentially quantify variables in double primed state (“)

State” . S[“/’]/\T[“/]

Page 22: Duminda WijesekeraSWE 623: Fall 20021 Schemas in Z Chapter 6 in Potter Sinclair and Till

Duminda Wijesekera SWE 623: Fall 2002 22

Schema Composition Example -1

toGoodStanding

Bank Account 1

toGoodStanding: R -> NULL

total < minBalance

x?:R ( x+total > minBalance) =>

total’ = total + x?

Page 23: Duminda WijesekeraSWE 623: Fall 20021 Schemas in Z Chapter 6 in Potter Sinclair and Till

Duminda Wijesekera SWE 623: Fall 2002 23

Schema Composition Example -2closeInGoodStanding Bank Account 1close: BOOL -> Rtotal > minBalance x?:BOOL, return!:R ( total>minBalance)

=> return!=total /\ total’=0

closeFromDefault = toGoodStanding ocloseFromGoodStanding

Page 24: Duminda WijesekeraSWE 623: Fall 20021 Schemas in Z Chapter 6 in Potter Sinclair and Till

Duminda Wijesekera SWE 623: Fall 2002 24

Schema Composition Example -3closeFromDefault

Bank Account 1

close: BOOL -> R

Bank Account”

x?: R toGoodStanding x /\ close true return’

Page 25: Duminda WijesekeraSWE 623: Fall 20021 Schemas in Z Chapter 6 in Potter Sinclair and Till

Duminda Wijesekera SWE 623: Fall 2002 25

Schema Preconditions

• Applicable only to schemas representing operations

• Pre Op = = State’; Out! . Op

• Means that the schema should be applied to those state that result in the given predicate satisfies in the post state.

• Here: Op is the operation

Page 26: Duminda WijesekeraSWE 623: Fall 20021 Schemas in Z Chapter 6 in Potter Sinclair and Till

Duminda Wijesekera SWE 623: Fall 2002 26

Schema Precondition ExampleSimple

x,y: N

x < y

NonEndPoint

Simple; Z!:N

x < x’ < z! < y’ < y

Page 27: Duminda WijesekeraSWE 623: Fall 20021 Schemas in Z Chapter 6 in Potter Sinclair and Till

Duminda Wijesekera SWE 623: Fall 2002 27

Constructing pre NonEndPoint

preNonEndPoint

Simple

x’,y’,z!: N x < x’ < z < y’ < y

Can simplify the statement

x’,y’,z!: N x < x’ < z < y’ < y to

x+3 < y

Page 28: Duminda WijesekeraSWE 623: Fall 20021 Schemas in Z Chapter 6 in Potter Sinclair and Till

Duminda Wijesekera SWE 623: Fall 2002 28

Schema Types

• A way to record data types by specifying filed and their types of a structure.

• ExampleBook

title, author, isbn, publisher : String

Pubdate, pages: Z

slength title < 80, slength author < 80,

(checksum isbn) mode 11 = 0

O < pages /\ 1800 < pubdate < 2050