adt bool is functions true : bool false : bool and, or : bool * bool -> bool not : bool -> bool axioms [B1] and(true,x) = x [B2] and(false,x) = false [B3] not(true) = false [B4] not(false) = true [B5] or(x,y) = not(and(not(x),not(y))) end
functions 0 : Nat S : Nat -> Nat mul : Nat * Nat -> Nat plus : Nat * Nat -> Nat axioms [1] plus(x,0) = x [2] plus(x,Sy) = S(plus(x,y)) [3] mul(x,0) = 0 [4] mul(x,Sy) = plus(mul(x,y),x) end
mul(plus(S 0,S 0),S 0) -[2]-> mul(S(plus(S 0,0)), S 0) -[1]-> mul(SS 0,S 0) -[4]-> plus(mul(SS0,0),SS0) -[3]-> plus(0,SS0) -[2*]-> SS0
functions new : stack; push : element * stack -> stack; empty : stack -> boolean; pop : stack -> stack; top : stack -> element; axioms empty( new ) = true empty( push(x,s) ) = false top( push(x,s) ) = x pop( push(x,s) ) = s preconditions pre: pop( s : stack ) = not empty(s) pre: top( s : stack ) = not empty(s) end
object account is functions bal : account -> money methods credit : account * money -> account debit : account * money -> account error overdraw : money -> money axioms bal(new(A)) = 0 bal(credit(A,M)) = bal(A) + M bal(debit(A,M)) = bal(A) - M if bal(A) >= M error-axioms bal(debit(A,M)) = overdraw(M) if bal(A) < M end
object ctr isfunction n : ctr -> nat method incr : ctr -> ctr axioms n(new(C)) = 0 n(incr(C)) = n(C) + 1 end
ctr
<n(incr(incr(new(C)))),{ C }> -[new]-> <n(incr(incr(C))),{ C[n:=0] }> -[incr]-> <n(incr(C)),{ C[n:=1] }> -[incr]-> <n(C), { C[n:=2] }> -[n]-> <2, { C[n:=2] }>