-- Lecture 3 -- page 33 mod! BASIC-NAT{ [Zero NzNat < Nat] op 0 : -> Zero op s_ : Nat -> NzNat } mod! NAT+ { pr(BASIC-NAT) op _+_ : Nat Nat -> Nat vars M N : Nat eq N + 0 = N . eq M + s N = s(M + N) . } mod! NAT+AC { pr(NAT+) op _+_ : Nat Nat -> Nat {assoc comm} } select NAT+AC set trace on -- You do not need bracket for associative operators -- like 0 + N + s 0 instead of (0 + N) + s 0 or 0 + (N + s 0) -- You can see in the trace of the following reduction -- that N + 0 = N can be applied to 0 + (N + s 0) since + is commutative red 0 + N:Nat + s 0 . set trace off -- page 34, 35 mod! BAG{ [Elt < Bag] ops a b c : -> Elt op _ _ : Bag Bag -> Bag { assoc comm } op _in_ : Elt Bag -> Bool var E : Elt var B : Bag eq E in (E B) = true . } select BAG red c in a b c . -- page 36 mod! BAG2{ [Elt < Bag] ops 0 1 : -> Elt op _ _ : Bag Bag -> Bag { assoc comm } var E : Elt eq (E E) = 0 1 . } select BAG2 -- red 0 0 1 . start 0 0 1 . apply 1 at term . apply 1 at term . apply 1 at term . -- page 37 mod! BAG3{ [Elt < Bag] ops 0 1 : -> Elt op begin-with-0 : Bag -> Bool op _ _ : Bag Bag -> Bag { assoc comm } var B : Bag eq begin-with-0(0 B) = true . eq begin-with-0(1 B) = false . } select BAG3 start begin-with-0 (0 1) . apply 1 at term . start begin-with-0 (0 1) . apply 2 at term .