2013-12-30 19:46:03 +00:00
|
|
|
|
Import kernel.
|
2013-12-30 11:29:20 +00:00
|
|
|
|
|
|
|
|
|
Variable Nat : Type.
|
|
|
|
|
Alias ℕ : Nat.
|
|
|
|
|
|
2014-01-01 20:40:54 +00:00
|
|
|
|
Namespace Nat.
|
|
|
|
|
Builtin numeral.
|
2013-12-30 11:29:20 +00:00
|
|
|
|
|
2014-01-01 20:40:54 +00:00
|
|
|
|
Builtin add : Nat → Nat → Nat.
|
|
|
|
|
Infixl 65 + : add.
|
2013-12-30 11:29:20 +00:00
|
|
|
|
|
2014-01-01 20:40:54 +00:00
|
|
|
|
Builtin mul : Nat → Nat → Nat.
|
|
|
|
|
Infixl 70 * : mul.
|
2013-12-30 11:29:20 +00:00
|
|
|
|
|
2014-01-01 20:40:54 +00:00
|
|
|
|
Builtin le : Nat → Nat → Bool.
|
|
|
|
|
Infix 50 <= : le.
|
|
|
|
|
Infix 50 ≤ : le.
|
2013-12-30 11:29:20 +00:00
|
|
|
|
|
2014-01-01 20:40:54 +00:00
|
|
|
|
Definition ge (a b : Nat) := b ≤ a.
|
|
|
|
|
Infix 50 >= : ge.
|
|
|
|
|
Infix 50 ≥ : ge.
|
2013-12-30 11:29:20 +00:00
|
|
|
|
|
2014-01-01 20:40:54 +00:00
|
|
|
|
Definition lt (a b : Nat) := ¬ (a ≥ b).
|
|
|
|
|
Infix 50 < : lt.
|
2013-12-30 11:29:20 +00:00
|
|
|
|
|
2014-01-01 20:40:54 +00:00
|
|
|
|
Definition gt (a b : Nat) := ¬ (a ≤ b).
|
|
|
|
|
Infix 50 > : gt.
|
2013-12-30 11:29:20 +00:00
|
|
|
|
|
2014-01-01 20:40:54 +00:00
|
|
|
|
Definition id (a : Nat) := a.
|
|
|
|
|
Notation 55 | _ | : id.
|
|
|
|
|
|
2014-01-02 05:32:07 +00:00
|
|
|
|
Axiom SuccInj {a b : Nat} (H : a + 1 = b + 1) : a = b
|
2014-01-01 23:53:53 +00:00
|
|
|
|
Axiom PlusZero (a : Nat) : a + 0 = a.
|
|
|
|
|
Axiom PlusSucc (a b : Nat) : a + (b + 1) = (a + b) + 1.
|
2014-01-02 05:32:07 +00:00
|
|
|
|
Axiom MulZero (a : Nat) : a * 0 = 0.
|
|
|
|
|
Axiom MulSucc (a b : Nat) : a * (b + 1) = a * b + a.
|
2014-01-02 20:31:13 +00:00
|
|
|
|
Axiom Induction {P : Nat → Bool} (Hb : P 0) (iH : Π (n : Nat) (H : P n), P (n + 1)) (a : Nat) : P a.
|
2014-01-01 23:53:53 +00:00
|
|
|
|
|
2014-01-02 05:32:07 +00:00
|
|
|
|
Theorem ZeroNeOne : 0 ≠ 1 := Trivial.
|
|
|
|
|
|
2014-01-01 23:53:53 +00:00
|
|
|
|
Theorem ZeroPlus (a : Nat) : 0 + a = a
|
|
|
|
|
:= Induction (show 0 + 0 = 0, Trivial)
|
2014-01-02 20:31:13 +00:00
|
|
|
|
(λ (n : Nat) (iH : 0 + n = n),
|
2014-01-02 20:13:26 +00:00
|
|
|
|
calc 0 + (n + 1) = (0 + n) + 1 : PlusSucc 0 n
|
2014-01-02 20:31:13 +00:00
|
|
|
|
... = n + 1 : { iH })
|
2014-01-01 23:53:53 +00:00
|
|
|
|
a.
|
|
|
|
|
|
|
|
|
|
Theorem SuccPlus (a b : Nat) : (a + 1) + b = (a + b) + 1
|
2014-01-02 20:13:26 +00:00
|
|
|
|
:= Induction (calc (a + 1) + 0 = a + 1 : PlusZero (a + 1)
|
|
|
|
|
... = (a + 0) + 1 : { Symm (PlusZero a) })
|
2014-01-02 20:31:13 +00:00
|
|
|
|
(λ (n : Nat) (iH : (a + 1) + n = (a + n) + 1),
|
2014-01-02 20:13:26 +00:00
|
|
|
|
calc (a + 1) + (n + 1) = ((a + 1) + n) + 1 : PlusSucc (a + 1) n
|
2014-01-02 20:31:13 +00:00
|
|
|
|
... = ((a + n) + 1) + 1 : { iH }
|
2014-01-02 20:13:26 +00:00
|
|
|
|
... = (a + (n + 1)) + 1 : { show (a + n) + 1 = a + (n + 1), Symm (PlusSucc a n) })
|
2014-01-01 23:53:53 +00:00
|
|
|
|
b.
|
|
|
|
|
|
|
|
|
|
Theorem PlusComm (a b : Nat) : a + b = b + a
|
2014-01-02 20:13:26 +00:00
|
|
|
|
:= Induction (calc a + 0 = a : PlusZero a
|
|
|
|
|
... = 0 + a : Symm (ZeroPlus a))
|
2014-01-02 20:31:13 +00:00
|
|
|
|
(λ (n : Nat) (iH : a + n = n + a),
|
2014-01-02 20:13:26 +00:00
|
|
|
|
calc a + (n + 1) = (a + n) + 1 : PlusSucc a n
|
2014-01-02 20:31:13 +00:00
|
|
|
|
... = (n + a) + 1 : { iH }
|
2014-01-02 20:13:26 +00:00
|
|
|
|
... = (n + 1) + a : Symm (SuccPlus n a))
|
2014-01-01 23:53:53 +00:00
|
|
|
|
b.
|
|
|
|
|
|
2014-01-02 01:19:12 +00:00
|
|
|
|
Theorem PlusAssoc (a b c : Nat) : a + (b + c) = (a + b) + c
|
2014-01-02 20:13:26 +00:00
|
|
|
|
:= Induction (calc 0 + (b + c) = b + c : ZeroPlus (b + c)
|
|
|
|
|
... = (0 + b) + c : { Symm (ZeroPlus b) })
|
2014-01-02 20:31:13 +00:00
|
|
|
|
(λ (n : Nat) (iH : n + (b + c) = (n + b) + c),
|
2014-01-02 20:13:26 +00:00
|
|
|
|
calc (n + 1) + (b + c) = (n + (b + c)) + 1 : SuccPlus n (b + c)
|
2014-01-02 20:31:13 +00:00
|
|
|
|
... = ((n + b) + c) + 1 : { iH }
|
2014-01-02 20:13:26 +00:00
|
|
|
|
... = ((n + b) + 1) + c : Symm (SuccPlus (n + b) c)
|
|
|
|
|
... = ((n + 1) + b) + c : { show (n + b) + 1 = (n + 1) + b, Symm (SuccPlus n b) })
|
2014-01-02 01:19:12 +00:00
|
|
|
|
a.
|
|
|
|
|
|
2014-01-02 05:32:07 +00:00
|
|
|
|
Theorem ZeroMul (a : Nat) : 0 * a = 0
|
|
|
|
|
:= Induction (show 0 * 0 = 0, Trivial)
|
2014-01-02 20:31:13 +00:00
|
|
|
|
(λ (n : Nat) (iH : 0 * n = 0),
|
2014-01-02 20:13:26 +00:00
|
|
|
|
calc 0 * (n + 1) = (0 * n) + 0 : MulSucc 0 n
|
2014-01-02 20:31:13 +00:00
|
|
|
|
... = 0 + 0 : { iH }
|
2014-01-02 20:13:26 +00:00
|
|
|
|
... = 0 : Trivial)
|
2014-01-02 05:32:07 +00:00
|
|
|
|
a.
|
|
|
|
|
|
|
|
|
|
Theorem SuccMul (a b : Nat) : (a + 1) * b = a * b + b
|
2014-01-02 20:13:26 +00:00
|
|
|
|
:= Induction (calc (a + 1) * 0 = 0 : MulZero (a + 1)
|
|
|
|
|
... = a * 0 : Symm (MulZero a)
|
|
|
|
|
... = a * 0 + 0 : Symm (PlusZero (a * 0)))
|
2014-01-02 20:31:13 +00:00
|
|
|
|
(λ (n : Nat) (iH : (a + 1) * n = a * n + n),
|
2014-01-02 20:13:26 +00:00
|
|
|
|
calc (a + 1) * (n + 1) = (a + 1) * n + (a + 1) : MulSucc (a + 1) n
|
2014-01-02 20:31:13 +00:00
|
|
|
|
... = a * n + n + (a + 1) : { iH }
|
2014-01-02 20:13:26 +00:00
|
|
|
|
... = a * n + n + a + 1 : PlusAssoc (a * n + n) a 1
|
|
|
|
|
... = a * n + (n + a) + 1 : { show a * n + n + a = a * n + (n + a), Symm (PlusAssoc (a * n) n a) }
|
|
|
|
|
... = a * n + (a + n) + 1 : { PlusComm n a }
|
|
|
|
|
... = a * n + a + n + 1 : { PlusAssoc (a * n) a n }
|
|
|
|
|
... = a * (n + 1) + n + 1 : { Symm (MulSucc a n) }
|
|
|
|
|
... = a * (n + 1) + (n + 1) : Symm (PlusAssoc (a * (n + 1)) n 1))
|
2014-01-02 05:32:07 +00:00
|
|
|
|
b.
|
|
|
|
|
|
|
|
|
|
Theorem OneMul (a : Nat) : 1 * a = a
|
|
|
|
|
:= Induction (show 1 * 0 = 0, Trivial)
|
2014-01-02 20:31:13 +00:00
|
|
|
|
(λ (n : Nat) (iH : 1 * n = n),
|
2014-01-02 20:13:26 +00:00
|
|
|
|
calc 1 * (n + 1) = 1 * n + 1 : MulSucc 1 n
|
2014-01-02 20:31:13 +00:00
|
|
|
|
... = n + 1 : { iH })
|
2014-01-02 05:32:07 +00:00
|
|
|
|
a.
|
|
|
|
|
|
|
|
|
|
Theorem MulOne (a : Nat) : a * 1 = a
|
|
|
|
|
:= Induction (show 0 * 1 = 0, Trivial)
|
2014-01-02 20:31:13 +00:00
|
|
|
|
(λ (n : Nat) (iH : n * 1 = n),
|
2014-01-02 20:13:26 +00:00
|
|
|
|
calc (n + 1) * 1 = n * 1 + 1 : SuccMul n 1
|
2014-01-02 20:31:13 +00:00
|
|
|
|
... = n + 1 : { iH })
|
2014-01-02 05:32:07 +00:00
|
|
|
|
a.
|
|
|
|
|
|
|
|
|
|
Theorem MulComm (a b : Nat) : a * b = b * a
|
2014-01-02 20:13:26 +00:00
|
|
|
|
:= Induction (calc a * 0 = 0 : MulZero a
|
|
|
|
|
... = 0 * a : Symm (ZeroMul a))
|
2014-01-02 20:31:13 +00:00
|
|
|
|
(λ (n : Nat) (iH : a * n = n * a),
|
2014-01-02 20:13:26 +00:00
|
|
|
|
calc a * (n + 1) = a * n + a : MulSucc a n
|
2014-01-02 20:31:13 +00:00
|
|
|
|
... = n * a + a : { iH }
|
2014-01-02 20:13:26 +00:00
|
|
|
|
... = (n + 1) * a : Symm (SuccMul n a))
|
2014-01-02 05:32:07 +00:00
|
|
|
|
b.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Theorem Distribute (a b c : Nat) : a * (b + c) = a * b + a * c
|
2014-01-02 20:13:26 +00:00
|
|
|
|
:= Induction (calc 0 * (b + c) = 0 : ZeroMul (b + c)
|
|
|
|
|
... = 0 + 0 : Trivial
|
|
|
|
|
... = 0 * b + 0 : { Symm (ZeroMul b) }
|
|
|
|
|
... = 0 * b + 0 * c : { Symm (ZeroMul c) })
|
2014-01-02 20:31:13 +00:00
|
|
|
|
(λ (n : Nat) (iH : n * (b + c) = n * b + n * c),
|
2014-01-02 20:13:26 +00:00
|
|
|
|
calc (n + 1) * (b + c) = n * (b + c) + (b + c) : SuccMul n (b + c)
|
2014-01-02 20:31:13 +00:00
|
|
|
|
... = n * b + n * c + (b + c) : { iH }
|
2014-01-02 20:13:26 +00:00
|
|
|
|
... = n * b + n * c + b + c : PlusAssoc (n * b + n * c) b c
|
|
|
|
|
... = n * b + (n * c + b) + c : { Symm (PlusAssoc (n * b) (n * c) b) }
|
|
|
|
|
... = n * b + (b + n * c) + c : { PlusComm (n * c) b }
|
|
|
|
|
... = n * b + b + n * c + c : { PlusAssoc (n * b) b (n * c) }
|
|
|
|
|
... = (n + 1) * b + n * c + c : { Symm (SuccMul n b) }
|
|
|
|
|
... = (n + 1) * b + (n * c + c) : Symm (PlusAssoc ((n + 1) * b) (n * c) c)
|
|
|
|
|
... = (n + 1) * b + (n + 1) * c : { Symm (SuccMul n c) })
|
2014-01-02 05:32:07 +00:00
|
|
|
|
a.
|
|
|
|
|
|
|
|
|
|
Theorem Distribute2 (a b c : Nat) : (a + b) * c = a * c + b * c
|
2014-01-02 20:13:26 +00:00
|
|
|
|
:= calc (a + b) * c = c * (a + b) : MulComm (a + b) c
|
|
|
|
|
... = c * a + c * b : Distribute c a b
|
|
|
|
|
... = a * c + c * b : { MulComm c a }
|
|
|
|
|
... = a * c + b * c : { MulComm c b }.
|
2014-01-02 05:32:07 +00:00
|
|
|
|
|
|
|
|
|
Theorem MulAssoc (a b c : Nat) : a * (b * c) = a * b * c
|
2014-01-02 20:13:26 +00:00
|
|
|
|
:= Induction (calc 0 * (b * c) = 0 : ZeroMul (b * c)
|
|
|
|
|
... = 0 * c : Symm (ZeroMul c)
|
|
|
|
|
... = (0 * b) * c : { Symm (ZeroMul b) })
|
2014-01-02 20:31:13 +00:00
|
|
|
|
(λ (n : Nat) (iH : n * (b * c) = n * b * c),
|
2014-01-02 20:13:26 +00:00
|
|
|
|
calc (n + 1) * (b * c) = n * (b * c) + (b * c) : SuccMul n (b * c)
|
2014-01-02 20:31:13 +00:00
|
|
|
|
... = n * b * c + (b * c) : { iH }
|
2014-01-02 20:13:26 +00:00
|
|
|
|
... = (n * b + b) * c : Symm (Distribute2 (n * b) b c)
|
|
|
|
|
... = (n + 1) * b * c : { Symm (SuccMul n b) })
|
2014-01-02 05:32:07 +00:00
|
|
|
|
a.
|
2014-01-02 01:19:12 +00:00
|
|
|
|
|
2014-01-01 20:40:54 +00:00
|
|
|
|
SetOpaque ge true.
|
|
|
|
|
SetOpaque lt true.
|
|
|
|
|
SetOpaque gt true.
|
|
|
|
|
SetOpaque id true.
|
|
|
|
|
EndNamespace.
|