Professional Documents
Culture Documents
Foundations of Computing - Tom Arthey, 6100146, Ta00057
Foundations of Computing - Tom Arthey, 6100146, Ta00057
1.(a)
i. dom(drives)
{anna, bob, christie, dave}
ii. ran(drives)
{audi, BMW, fiat, skoda}
vi. drives-1
{(audi, anna), (fiat, bob), (BMW, anna), (fiat, christie),
(skoda, christie), (audi, dave), (BMW, dave), (skoda, anna)}
Not a function.
Not a function.
2. Part one.
(a) The languages that Albert speaks
speaks ⩥ {Albert} ⩥
(h) The languages spoken by the people who do not speak English
ran((speaks-1 ⩥ {English} ⩥ ) ⩥ speaks)
(i) The other languages spoken by the people who speak Japanese
ran((speaks-1 ⩥ {Japanese} ⩥ ) ◁ speaks) ∖ {Japanese}
Part two.
(a) Anyone who speaks Swedish also speaks English
speaks-1 ⩥ {Swedish} ⩥ ⊆ speaks-1 ⩥ {English} ⩥
(d) Anyone who speaks Dutch and Flemish also speaks English
(speaks-1 ⩥ {Dutch} ⩥ ∩ speaks-1 ⩥ {Flemish} ⩥) ⊆ speaks-1
⩥ {English} ⩥
InitTrolley
′Trolley
′trolley = ∅
Minus
item? ∈ dom(trolley)
ΔTrolley
( trolley(item?) = 1 ⇒
trolley′ = {item?} ⩥ trolley)
( trolley(item?) ≠ 1 ⇒
trolley′ = ({item?} ⩥ trolley) ∪ ({item ↦ trolley(item?) −1}) )
PresentQuery
ΞTrolley
item? : GOODS
present! : BOOL
DiscountRunningTotal
ΞTrolley
total! : ℕ
NumberOfItemsQuery
ΞTrolley
number! : ℕ
number! = Σ g∈ ran(trolley) g
MealDeal
mealDeal : ℙ GOODS
priceMealDeal : ℕ
# (mealDeal) ≥ 2
priceMealDeal > 0
priceMealDeal < Σ g∈ mealDeal price(g)
8. Schema for NumberOfItemsQuery
lowest : ℙ1ℕ ↠ ℕ
∀x:G ⩥ lowest(G) ≤ x
∃x:G ⩥ lowest(G) = x
discount : MealDeal → ℕ
NewRunningTotal
ΞTrolley
ΞMealDeal
total! : ℕ
( ¬( mealDeal ⊆ dom(trolley) ) ⇒
total! = Σ g∈ dom(trolley) price(g) * trolley(g) )
( mealDeal ⊆ dom(trolley) ⇒
total! =
( Σ g∈ dom(trolley) price(g) * trolley(g) )
− ( lowest( trolley ⩥ mealDeal ⩥ ) * discount(MealDeal) ) )