--> **************************************************************** --> proof scores for associativity and commutativity of --> _+_ and _*_ over Nat.PNAT --> **************************************************************** --> ---------------------------------------------------------------- --> PNAT: Peano NATural numbers --> ---------------------------------------------------------------- mod! PNAT { [Nat] op 0 : -> Nat {constr} . op s_ : Nat -> Nat {constr} . } --> ---------------------------------------------------------------- --> PNAT with addition _+_ --> ---------------------------------------------------------------- mod! PNAT+ { pr(PNAT) op _+_ : Nat Nat -> Nat . eq 0 + Y:Nat = Y . eq s X:Nat + Y:Nat = s(X + Y) . } --> **************************************************************** -- set trace whole on --> set trace whole on --> ---------------------------------------------------------------- --> ================================================================ --> proof score for proving right 0 of _+_: --> eq X:Nat + 0 = X . --> with the induction on X:Nat --> ---------------------------------------------------------------- --> induction base select PNAT+ . red 0 + 0 = 0 . -- induction step open PNAT+ . --> induction hypothesis op n : -> Nat . eq n + 0 = n . -- check the step red s n + 0 = s n . close --> QED --> ================================================================ #| --> induction base -- reduce in PNAT+ : ((0 + 0) = 0):Bool ---> (0 = 0):Bool ---> (true):Bool --> induction hypothesis_ -- reduce in %PNAT+ : (((s n) + 0) = (s n)):Bool ---> ((s (n + 0)) = (s n)):Bool ---> ((s n) = (s n)):Bool ---> (true):Bool |# --> ================================================================ --> proof score for proving right s_ of _+_: --> eq X:Nat + s Y:Nat = s (X + Y) . --> with the induction on X:Nat --> ---------------------------------------------------------------- --> induction base open PNAT+ . op y : -> Nat . red 0 + s y = s (0 + y) . close --> induction step open PNAT+ . -- induction hypothesis op n : -> Nat . eq n + s Y:Nat = s (n + Y) . -- check the step op y : -> Nat . red s n + s y = s (s n + y) . close --> QED --> ================================================================ #| --> induction base -- reduce in %PNAT+ : ((0 + (s y)) = (s (0 + y))):Bool ---> ((s y) = (s (0 + y))):Bool ---> ((s y) = (s y)):Bool ---> (true):Bool --> induction step -- reduce in %PNAT+ : (((s n) + (s y)) = (s ((s n) + y))):Bool ---> ((s (n + (s y))) = (s ((s n) + y))):Bool ---> ((s (s (n + y))) = (s ((s n) + y))):Bool ---> ((s (s (n + y))) = (s (s (n + y)))):Bool ---> (true):Bool |# --> **************************************************************** -- set trace on --> set trace on --> ---------------------------------------------------------------- --> ================================================================ --> proof score for proving commutativity of _+_: --> eq (X:Nat + Y:Nat) = (Y + X) . --> with the induction on X:Nat --> ---------------------------------------------------------------- --> induction base open PNAT+ . -- already proved property eq X:Nat + 0 = X . -- check the base op y : -> Nat . red 0 + y = y + 0 . close --> induction step open PNAT+ . -- induction hypothesis op n : -> Nat . eq n + Y:Nat = Y + n . -- already proved property eq X:Nat + s Y:Nat = s (X + Y) . -- check the step op y : -> Nat . red s n + y = y + s n . close --> QED --> ================================================================ #| --> induction base -- reduce in %PNAT+ : ((0 + y) = (y + 0)):Bool 1>[1] rule: eq (0 + Y:Nat) = Y { Y:Nat |-> y } 1<[1] (0 + y):Nat --> (y):Nat ---> (y = (y + 0)):Bool 1>[2] rule: eq (X:Nat + 0) = X { X:Nat |-> y } 1<[2] (y + 0):Nat --> (y):Nat ---> (y = y):Bool 1>[3] rule: eq (CUX = CUX) = true { CUX |-> y } 1<[3] (y = y):Bool --> (true):Bool ---> (true):Bool --> induction step -- reduce in %PNAT+ : (((s n) + y) = (y + (s n))):Bool 1>[1] rule: eq ((s X:Nat) + Y:Nat) = (s (X + Y)) { X:Nat |-> n, Y:Nat |-> y } 1<[1] ((s n) + y):Nat --> (s (n + y)):Nat ---> ((s (n + y)) = (y + (s n))):Bool 1>[2] rule: eq (n + Y:Nat) = (Y + n) { Y:Nat |-> y } 1<[2] (n + y):Nat --> (y + n):Nat ---> ((s (y + n)) = (y + (s n))):Bool 1>[3] rule: eq (X:Nat + (s Y:Nat)) = (s (X + Y)) { X:Nat |-> y, Y:Nat |-> n } 1<[3] (y + (s n)):Nat --> (s (y + n)):Nat ---> ((s (y + n)) = (s (y + n))):Bool 1>[4] rule: eq (CUX = CUX) = true { CUX |-> (s (y + n)) } 1<[4] ((s (y + n)) = (s (y + n))):Bool --> (true):Bool ---> (true):Bool |# --> ---------------------------------------------------------------- -- set trace off --> set trace off --> **************************************************************** --> ================================================================ --> proof score for proving associativity of _+_: --> eq (X:Nat + Y:Nat) + Z:Nat = X + (Y + Z) . --> with the induction on X:Nat --> ---------------------------------------------------------------- --> induction base open PNAT+ . -- check the base ops y z : -> Nat . red (0 + y) + z = 0 + (y + z) . close --> induction step open PNAT+ . -- induction hypothesis op n : -> Nat . eq (n + Y:Nat) + Z:Nat = n + (Y + Z) . -- check the step ops y z : -> Nat . red (s n + y) + z = s n + (y + z) . close --> QED --> ================================================================ #| --> induction base -- reduce in %PNAT+ : (((0 + y) + z) = (0 + (y + z))):Bool ---> ((y + z) = (0 + (y + z))):Bool ---> ((y + z) = (y + z)):Bool ---> (true):Bool --> induction step -- reduce in %PNAT+ : ((((s n) + y) + z) = ((s n) + (y + z))):Bool ---> (((s (n + y)) + z) = ((s n) + (y + z))):Bool ---> ((s ((n + y) + z)) = ((s n) + (y + z))):Bool ---> ((s (n + (y + z))) = ((s n) + (y + z))):Bool ---> ((s (n + (y + z))) = (s (n + (y + z)))):Bool ---> (true):Bool |# --> ---------------------------------------------------------------- --> PNAT with associative and commutative addition _+_ --> ---------------------------------------------------------------- mod! PNAT+ac { pr(PNAT) -- assoc and comm have been proved to hold op _+_ : Nat Nat -> Nat {assoc comm} -- definition of _+_ eq 0 + Y:Nat = Y . eq (s X:Nat) + Y:Nat = s(X + Y) . } select PNAT+ac . show op _+_ . --> ---------------------------------------------------------------- --> PNAT with multiplication _*_ --> ---------------------------------------------------------------- mod! PNAT* { pr(PNAT+ac) op _*_ : Nat Nat -> Nat {prec: 40} eq 0 * Y:Nat = 0 . eq s X:Nat * Y:Nat = Y + X * Y . } --> ================================================================ --> proof score for proving right 0 of _*_: --> eq X:Nat * 0 = X . --> with the induction on X:Nat --> ---------------------------------------------------------------- --> induction base select PNAT* . red 0 * 0 = 0 . --> induction step open PNAT* . -- induction hypothesis op n : -> Nat . eq n * 0 = 0 . -- check the step red s n * 0 = 0 . close --> QED --> ================================================================ #| --> induction base -- reduce in PNAT* : ((0 * 0) = 0):Bool ---> (0 = 0):Bool ---> (true):Bool --> induction step -- reduce in %PNAT* : (((s n) * 0) = 0):Bool ---> ((0 + (n * 0)) = 0):Bool ---> ((0 + 0) = 0):Bool ---> (0 = 0):Bool ---> (true):Bool |# --> ================================================================ --> proof score for proving right s_ of _*_: --> eq X:Nat * s Y:Nat = X + X * Y . --> with the induction on X:Nat --> ----------------------------------------------------------------- --> induction base open PNAT* . op y : -> Nat . red 0 * s y = 0 + 0 * y . close --> induction step open PNAT* . -- induction hypothesis op n : -> Nat . eq n * s Y:Nat = n + n * Y . -- check the step op y : -> Nat . red s n * s y = s n + s n * y . close --> QED --> ================================================================ #| --> induction base -- reduce in %PNAT* : ((0 * (s y)) = (0 + (0 * y))):Bool ---> (0 = (0 + (0 * y))):Bool ---> (0 = (0 + 0)):Bool ---> (0 = 0):Bool ---> (true):Bool --> induction step -- reduce in %PNAT* : (((s n) * (s y)) = ((s n) + ((s n) * y))):Bool ---> (((s y) + (n * (s y))) = ((s n) + ((s n) * y))):Bool ---> (((s y) + (n + (n * y))) = ((s n) + ((s n) * y))):Bool ---> ((s (y + ((n * y) + n))) = ((s n) + ((s n) * y))):Bool ---> ((s ((n * y) + (n + y))) = ((s n) + (y + (n * y)))):Bool ---> ((s ((n * y) + (n + y))) = (s (n + ((n * y) + y)))):Bool ---> (true):Bool |# --> **************************************************************** -- set trace on --> set trace on --> ---------------------------------------------------------------- --> ================================================================ --> proof score for proving commutativity of _*_: --> eq (X:Nat * Y:Nat) = (Y * X) . --> with the induction on X:Nat --> ----------------------------------------------------------------- --> induction base open PNAT* . -- already proved property eq X:Nat * 0 = 0 . -- check the base op y : -> Nat . red 0 * y = y * 0 . close --> induction step open PNAT* . -- induction hypothesis op n : -> Nat . eq n * Y:Nat = Y * n . -- already proved property eq X:Nat * (s Y:Nat) = X + X * Y . -- check the step op y : -> Nat . red s n * y = y * s n . close --> QED --> ================================================================ #| --> induction base -- reduce in %PNAT* : ((0 * y) = (y * 0)):Bool 1>[1] rule: eq (0 * Y:Nat) = 0 { Y:Nat |-> y } 1<[1] (0 * y):Nat --> (0):Nat ---> (0 = (y * 0)):Bool 1>[2] rule: eq (X:Nat * 0) = 0 { X:Nat |-> y } 1<[2] (y * 0):Nat --> (0):Nat ---> (0 = 0):Bool 1>[3] rule: eq (CUX = CUX) = true { CUX |-> 0 } 1<[3] (0 = 0):Bool --> (true):Bool ---> (true):Bool --> induction step -- reduce in %PNAT* : (((s n) * y) = (y * (s n))):Bool 1>[1] rule: eq ((s X:Nat) * Y:Nat) = (Y + (X * Y)) { X:Nat |-> n, Y:Nat |-> y } 1<[1] ((s n) * y):Nat --> (y + (n * y)):Nat ---> ((y + (n * y)) = (y * (s n))):Bool 1>[2] rule: eq (n * Y:Nat) = (Y * n) { Y:Nat |-> y } 1<[2] (n * y):Nat --> (y * n):Nat ---> ((y + (y * n)) = (y * (s n))):Bool 1>[3] rule: eq (X:Nat * (s Y:Nat)) = (X + (X * Y)) { X:Nat |-> y, Y:Nat |-> n } 1<[3] (y * (s n)):Nat --> (y + (y * n)):Nat ---> (((y * n) + y) = (y + (y * n))):Bool 1>[4] rule: eq (CUX = CUX) = true { CUX |-> ((y * n) + y) } 1<[4] (((y * n) + y) = ((y * n) + y)):Bool --> (true):Bool ---> (true):Bool |# --> ---------------------------------------------------------------- -- set trace off --> set trace off --> **************************************************************** --> ================================================================ --> proof score for proving distributivity of _*_ over _+_ --> from right: --> eq (X:Nat + Y:Nat) * Z:Nat = X * Z + Y * Z . --> with the induction on X:Nat --> ---------------------------------------------------------------- --> induction base open PNAT* . ops y z : -> Nat . red (0 + y) * z = 0 * z + y * z . close --> induction step open PNAT* . -- induction hypothesis op n : -> Nat . eq (n + Y:Nat) * Z:Nat = n * Z + Y * Z . -- check the step ops y z : -> Nat . red (s n + y) * z = s n * z + y * z . close --> QED --> ================================================================ #| --> induction base -- reduce in %PNAT* : (((0 + y) * z) = ((0 * z) + (y * z))):Bool ---> ((y * z) = ((0 * z) + (y * z))):Bool ---> ((y * z) = (0 + (y * z))):Bool ---> ((y * z) = (y * z)):Bool ---> (true):Bool --> induction step -- reduce in %PNAT* : ((((s n) + y) * z) = (((s n) * z) + (y * z))):Bool ---> (((s (n + y)) * z) = (((s n) * z) + (y * z))):Bool ---> ((z + ((y + n) * z)) = (((s n) * z) + (y * z))):Bool ---> ((z + ((n * z) + (y * z))) = (((s n) * z) + (y * z))):Bool ---> (((n * z) + ((y * z) + z)) = ((z + (n * z)) + (y * z))):Bool ---> (true):Bool |# --> ================================================================ --> proof score for proving associativity of _*_: --> eq (X:Nat * Y:Nat) * Z:Nat = X * (Y * Z) . --> with the induction on X:Nat --> ---------------------------------------------------------------- --> induction base open PNAT* . ops y z : -> Nat . red (0 * y) * z = 0 * (y * z) . close --> induction step open PNAT* . -- induction hypothesis op n : -> Nat . eq (n * Y:Nat) * Z:Nat = n * (Y * Z) . -- already proved property eq (X:Nat + Y:Nat) * Z:Nat = X * Z + Y * Z . -- check the step ops y z : -> Nat . red (s n * y) * z = s n * (y * z) . close --> QED --> ================================================================ #| --> induction base -- reduce in %PNAT* : (((0 * y) * z) = (0 * (y * z))):Bool ---> ((0 * z) = (0 * (y * z))):Bool ---> (0 = (0 * (y * z))):Bool ---> (0 = 0):Bool ---> (true):Bool --> induction step -- reduce in %PNAT* : ((((s n) * y) * z) = ((s n) * (y * z))):Bool ---> (((y + (n * y)) * z) = ((s n) * (y * z))):Bool ---> ((((n * y) * z) + (y * z)) = ((s n) * (y * z))):Bool ---> (((n * (y * z)) + (y * z)) = ((s n) * (y * z))):Bool ---> (((y * z) + (n * (y * z))) = ((y * z) + (n * (y * z)))):Bool ---> (true):Bool |# --> ---------------------------------------------------------------- --> Peano style natural numbers with assoc+comm _+_, _*_ --> which satisfy distributive law --> ---------------------------------------------------------------- mod! PNAT*ac { pr(PNAT+ac) op _*_ : Nat Nat -> Nat {assoc comm prec: 40} eq 0 * Y:Nat = 0 . eq s X:Nat * Y:Nat = Y + X * Y . -- distributive law eq X:Nat * (Y:Nat + Z:Nat) = X * Y + X * Z . } --> ---------------------------------------------------------------- --> factorial functions on Nat.PNAT*ac --> ---------------------------------------------------------------- mod! FACT { pr(PNAT*ac) -- one argument factorial function op fact1 : Nat -> Nat . eq fact1(0) = s 0 . eq fact1(s N:Nat) = s N * fact1(N) . -- two arguments factorial function op fact2 : Nat Nat -> Nat . eq fact2(0,N2:Nat) = N2 . eq fact2(s N1:Nat,N2:Nat) = fact2(N1,s N1 * N2) . } --> ================================================================ --> proof score for the property: --> eq fact2(N1:Nat,N2:Nat) = fact1(N1) * N2 . --> with the induction on N1:Nat --> ---------------------------------------------------------------- --> induction base open FACT . op n2 : -> Nat . red fact2(0,n2) = fact1(0) * n2 . close --> induction step open FACT . -- induction hypothesis op n1 : -> Nat . eq fact2(n1,N2:Nat) = fact1(n1) * N2 . -- check the step op n2 : -> Nat . red fact2(s n1,n2) = fact1(s n1) * n2 . close --> QED --> ================================================================ #| --> induction base -- reduce in %FACT : (fact2(0,n2) = (fact1(0) * n2)):Bool ---> (n2 = (fact1(0) * n2)):Bool ---> (n2 = ((s 0) * n2)):Bool ---> (n2 = (n2 + (0 * n2))):Bool ---> (n2 = (n2 + 0)):Bool ---> (n2 = n2):Bool ---> (true):Bool --> induction step -- reduce in %FACT : (fact2((s n1),n2) = (fact1((s n1)) * n2)):Bool ---> (fact2(n1,((s n1) * n2)) = (fact1((s n1)) * n2)):Bool ---> ((fact1(n1) * ((s n1) * n2)) = (fact1((s n1)) * n2)):Bool ---> ((fact1(n1) * (n2 + (n1 * n2))) = (fact1((s n1)) * n2)):Bool ---> (((fact1(n1) * (n2 * n1)) + (fact1(n1) * n2)) = (fact1((s n1)) * n2)):Bool ---> (((n2 * fact1(n1)) + (n2 * (n1 * fact1(n1)))) = (((s n1) * fact1(n1)) * n2)):Bool ---> (((n2 * fact1(n1)) + (n2 * (n1 * fact1(n1)))) = ((fact1(n1) + (n1 * fact1(n1))) * n2)):Bool ---> (((n2 * fact1(n1)) + (n2 * (n1 * fact1(n1)))) = ((n2 * fact1(n1)) + (n2 * (fact1(n1) * n1)))):Bool ---> (true):Bool |# --> ---------------------------------------------------------------- -- set trace whole off --> set trace whole off --> **************************************************************** --> **************************************************************** --> end of file eof --> ****************************************************************