Professional Documents
Culture Documents
Formal Methods Coursework
Formal Methods Coursework
Question 1.
Temperature for each region has got variations from other regions mak-
ing it unique.
Types required:
[REGION , TEMPERATURE ]
WeatherMap
location : P REGION
weather : REGION → 7 TEMPERATURE
dom weather = location
i
(b) A schema that updates the WeatherMap database by adding tem-
perature of a particular region.
This schema changes the temperature of a region that is existing in the
database
Update
∆WeatherMap
reg? : REGION
temp? : TEMPERATURE
reg? ∈ location
weather 0 = weather ⊕ {reg? 7→ temp?}
LookUp
ΞWeatherMap
reg? : REGION
temp! : TEMPERATURE
reg? ∈ location
temp! = weather (reg?)
(d) A schema that shows the initial state of the WeatherMap database.
This schema shows the state of the WeatherMap Database before putting
any weather information in it.
InitialMap
∆WeatherMap
weather 0 = {}
ii
Question 2.
A good can be bought if sufficient coins have been entered, the good
is available and the exact change can be given.
Below are the basic types required for the vending machine
[GOOD, COIN , REPORT ]
N=={n : Z | n≥ 0}
REPORT ::= some goods are not priced | Item already priced | Item not
in stock | More money is required | You have some balance | Operation is
unsuccessful | Item out of stock
iii
The constant for the maximum number of goods that can be in the vending
machine is
maxGoods : GOOD → 7 N
VENDING MACHINE
VendingMachine
stock : bag GOOD
cost : GOOD → 7 N
float : bag COIN
dom stock v dom cost
dom cost ≤ dom maxGoods
InitVendingMachine
∆VendingMachine
stock 0 = [[]]
cost 0 = {}
float 0 = [[]]
GivePrice
∆VendingMachine
good ? : GOOD
price? : N
good ? 7→ price? ∈/ cost
cost 0 = cost ∪ {good ? 7→ price?}
stock 0 = stock
float 0 = float
iv
A schema that can be used to reprice an item that already has price
associated with it.
Reprice
∆VendingMachine
good ? : GOOD
price? : N
good ? 7→ price? ∈ cost
cost 0 = cost ⊕ {good ? 7→ price?}
stock 0 = stock
float 0 = float
(v) Schema specifying what happens when some one buys an item from
the machine.
This schema allows a person to remove a good from the vending machine
by putting an acceptable coin (in ?). When the coin is in excess of a given
price of the good, then the machine gives the coin(out ?).
Buy
∆VendingMachine
in?, out! : bagCOIN
item? : GOOD
item? in stock
sum(in?) ≥ cost(item?)
out! v float
sum(in?) = sum(out!) + cost(item?)
stock 0 ] {item? 7→ 1} = stock
float 0 ] out? = float ] in?
cost 0 = cost
v
(vi) The Schema specifying what happens when the Item someone wants
to buy is not in the machine.
This schema returns an item not in stock if the item you are looking for is
not in the system.
itemNotInSystem
ΞVendingMachine
item? : GOOD
rep! : REPORT
¬(dom stock 0 v dom cost 0 )
rep! = ”Item is not in stock”
(vii)The schema to report Success. This schema returns true if the op-
eration is successful.
Success
report! : REPORT
report! = ”Ok”
(viii) Other schemas defining the different what-ifs in the Vending Ma-
chine Operations.
These schemas show other operations that can occur in the vending machine.
Not in stock
NoStock
ΞVendingMachine
item? : GOOD
rep! : REPORT
¬(item? in stock)
rep! = “Item out of stock”
vi
Less money
LessMoney
ΞVendingMachine
In? : bag COIN
item? : GOOD
rep! : REPORT
sum(in?) < cost(item?)
rep! = “More Money Required”
Already priced
AlreadyPriced
ΞVendingMachine
item? : GOOD
price? : N
rep! : REPORT
item? 7→ price? ∈ cost
rep! = ”Item already priced”
Restock
∆VendingMachine
new ? : bag GOOD
stock 0 = stock ] new ?
cost 0 = cost
float 0 = float
vii
GoodNotPriced
ΞVendingMachine
new ? : bag GOOD
rep! : REPORT
¬(dom new ? v dom cost)
rep! = “Some Goods Not Priced”
viii
Give Change
Change
∆VendingMachine
item? : GOOD
rep! : REPORT
in?, out 0 : bag COIN
item?instock
sum(in?) ≥ cost(item?)
¬(out! v float)
sum(in?) = sum(out!) + cost(item?)
stock 0 ] item? 7→ 1 = stock
float 0 ] out? = float ] in?
cost 0 = cost
rep! = ”You have some balance”
ix