(* Peano Arithmetic using a Natural number type * Implemented by Dr. Greg Lavender * * Peano Arithmetic is based on three concepts and five axioms: * * C1: there is an object of thought (a thing) called zero * C2: there is a thing called a number * C3: there is a thing called the successor mapping * A1: 0 is a number * A2: the successor of a number is a number * A3: No two numbers have the same successor * A4: 0 is not the successor of any number * A5: any property which belongs to 0 and also * to the successor of any number belongs * to all numbers (induction hypothesis) * * Historically, Peano formulated his axiomatic view of * arithmetic using a concept of number starting with 1, not 0, * but in modern times we consider 0 as the first number * in the set of natural numbers (due to Frege). Peano * also formulated his system based on the previous * work of Richard Dedekind (1888) and Hermann Grassmann, * but we call it Peano Arithmetic not Dedekind-Grassmann * Arithmetic. *) structure Peano = struct datatype Nat = Zero | Succ of Nat val One = Succ Zero val Two = Succ One fun iszero Zero = true | iszero (Succ x) = false fun equal (Zero, Zero) = true | equal (Zero, _) = false | equal (_, Zero) = false | equal (Succ x, Succ y) = equal(x,y) fun pred Zero = raise Fail "no predecessor of Zero in Peano Arithmetic!" | pred (Succ x) = x fun plus (Zero, Zero) = Zero | plus (Succ x, Zero) = Succ x | plus (Zero, Succ x) = Succ x | plus (Succ x, Succ y) = Succ (plus (Succ x, y)) fun mult (_, Zero) = Zero | mult (Zero, _) = Zero | mult (Succ x, Succ y) = plus (Succ x, mult (Succ x, y)); fun even (n:Nat) = case n of Zero => true | Succ x => odd(x) and odd (n:Nat) = case n of Zero => false | Succ x => even(x) fun nat2int Zero = 0 | nat2int (Succ x) = 1 + nat2int(x) fun int2nat 0 = Zero | int2nat n = Succ (int2nat (n-1)) end;