2014-08-02 01:40:24 +00:00
|
|
|
|
--- Copyright (c) 2014 Floris van Doorn. All rights reserved.
|
|
|
|
|
--- Released under Apache 2.0 license as described in the file LICENSE.
|
2014-11-22 08:15:51 +00:00
|
|
|
|
--- Author: Floris van Doorn, Leonardo de Moura
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
2014-08-22 23:36:47 +00:00
|
|
|
|
-- Basic operations on the natural numbers.
|
|
|
|
|
|
2014-12-12 21:20:27 +00:00
|
|
|
|
import logic.connectives data.num algebra.binary
|
2014-08-22 23:36:47 +00:00
|
|
|
|
|
2014-11-22 08:15:51 +00:00
|
|
|
|
open eq.ops binary
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
2014-09-04 22:03:59 +00:00
|
|
|
|
namespace nat
|
|
|
|
|
|
2014-11-18 05:58:42 +00:00
|
|
|
|
definition addl (x y : ℕ) : ℕ :=
|
|
|
|
|
nat.rec y (λ n r, succ r) x
|
|
|
|
|
infix `⊕`:65 := addl
|
|
|
|
|
|
|
|
|
|
theorem addl.succ_right (n m : ℕ) : n ⊕ succ m = succ (n ⊕ m) :=
|
|
|
|
|
nat.induction_on n
|
|
|
|
|
rfl
|
|
|
|
|
(λ n₁ ih, calc
|
|
|
|
|
succ n₁ ⊕ succ m = succ (n₁ ⊕ succ m) : rfl
|
|
|
|
|
... = succ (succ (n₁ ⊕ m)) : ih
|
|
|
|
|
... = succ (succ n₁ ⊕ m) : rfl)
|
|
|
|
|
|
|
|
|
|
theorem add_eq_addl (x : ℕ) : ∀y, x + y = x ⊕ y :=
|
|
|
|
|
nat.induction_on x
|
|
|
|
|
(λ y, nat.induction_on y
|
|
|
|
|
rfl
|
|
|
|
|
(λ y₁ ih, calc
|
|
|
|
|
zero + succ y₁ = succ (zero + y₁) : rfl
|
|
|
|
|
... = succ (zero ⊕ y₁) : {ih}
|
|
|
|
|
... = zero ⊕ (succ y₁) : rfl))
|
|
|
|
|
(λ x₁ ih₁ y, nat.induction_on y
|
|
|
|
|
(calc
|
|
|
|
|
succ x₁ + zero = succ (x₁ + zero) : rfl
|
|
|
|
|
... = succ (x₁ ⊕ zero) : {ih₁ zero}
|
|
|
|
|
... = succ x₁ ⊕ zero : rfl)
|
|
|
|
|
(λ y₁ ih₂, calc
|
|
|
|
|
succ x₁ + succ y₁ = succ (succ x₁ + y₁) : rfl
|
|
|
|
|
... = succ (succ x₁ ⊕ y₁) : {ih₂}
|
|
|
|
|
... = succ x₁ ⊕ succ y₁ : addl.succ_right))
|
|
|
|
|
|
2014-08-02 01:40:24 +00:00
|
|
|
|
-- Successor and predecessor
|
|
|
|
|
-- -------------------------
|
|
|
|
|
|
2014-10-02 01:50:17 +00:00
|
|
|
|
theorem succ_ne_zero (n : ℕ) : succ n ≠ 0 :=
|
2014-11-09 03:00:40 +00:00
|
|
|
|
assume H, no_confusion H
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
|
|
|
|
-- add_rewrite succ_ne_zero
|
|
|
|
|
|
2014-11-22 08:15:51 +00:00
|
|
|
|
theorem pred.zero : pred 0 = 0 :=
|
|
|
|
|
rfl
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
2014-11-22 08:15:51 +00:00
|
|
|
|
theorem pred.succ (n : ℕ) : pred (succ n) = n :=
|
|
|
|
|
rfl
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
2014-09-19 22:40:39 +00:00
|
|
|
|
irreducible pred
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
|
|
|
|
theorem zero_or_succ_pred (n : ℕ) : n = 0 ∨ n = succ (pred n) :=
|
|
|
|
|
induction_on n
|
2014-09-05 04:25:21 +00:00
|
|
|
|
(or.inl rfl)
|
|
|
|
|
(take m IH, or.inr
|
2014-10-02 01:39:47 +00:00
|
|
|
|
(show succ m = succ (pred (succ m)), from congr_arg succ !pred.succ⁻¹))
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
|
|
|
|
theorem zero_or_exists_succ (n : ℕ) : n = 0 ∨ ∃k, n = succ k :=
|
2014-12-15 20:05:44 +00:00
|
|
|
|
or_of_or_of_imp_of_imp (zero_or_succ_pred n) (assume H, H)
|
2014-12-16 03:05:03 +00:00
|
|
|
|
(assume H : n = succ (pred n), exists.intro (pred n) H)
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
|
|
|
|
theorem case {P : ℕ → Prop} (n : ℕ) (H1: P 0) (H2 : ∀m, P (succ m)) : P n :=
|
|
|
|
|
induction_on n H1 (take m IH, H2 m)
|
|
|
|
|
|
2014-10-02 01:39:47 +00:00
|
|
|
|
theorem succ.inj {n m : ℕ} (H : succ n = succ m) : n = m :=
|
2014-11-09 03:00:40 +00:00
|
|
|
|
no_confusion H (λe, e)
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
2014-10-02 01:39:47 +00:00
|
|
|
|
theorem succ.ne_self {n : ℕ} : succ n ≠ n :=
|
2014-08-02 01:40:24 +00:00
|
|
|
|
induction_on n
|
|
|
|
|
(take H : 1 = 0,
|
2014-10-02 01:50:17 +00:00
|
|
|
|
have ne : 1 ≠ 0, from !succ_ne_zero,
|
2014-08-02 01:40:24 +00:00
|
|
|
|
absurd H ne)
|
2014-10-02 01:39:47 +00:00
|
|
|
|
(take k IH H, IH (succ.inj H))
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
2014-11-22 08:15:51 +00:00
|
|
|
|
|
|
|
|
|
theorem discriminate {B : Prop} {n : ℕ} (H1: n = 0 → B) (H2 : ∀m, n = succ m → B) : B :=
|
|
|
|
|
or.elim (zero_or_succ_pred n)
|
|
|
|
|
(take H3 : n = 0, H1 H3)
|
|
|
|
|
(take H3 : n = succ (pred n), H2 (pred n) H3)
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
|
|
|
|
theorem two_step_induction_on {P : ℕ → Prop} (a : ℕ) (H1 : P 0) (H2 : P 1)
|
|
|
|
|
(H3 : ∀ (n : ℕ) (IH1 : P n) (IH2 : P (succ n)), P (succ (succ n))) : P a :=
|
|
|
|
|
have stronger : P a ∧ P (succ a), from
|
|
|
|
|
induction_on a
|
2014-09-04 23:36:06 +00:00
|
|
|
|
(and.intro H1 H2)
|
2014-08-02 01:40:24 +00:00
|
|
|
|
(take k IH,
|
2014-09-05 00:44:53 +00:00
|
|
|
|
have IH1 : P k, from and.elim_left IH,
|
|
|
|
|
have IH2 : P (succ k), from and.elim_right IH,
|
2014-09-04 23:36:06 +00:00
|
|
|
|
and.intro IH2 (H3 k IH1 IH2)),
|
2014-09-05 00:44:53 +00:00
|
|
|
|
and.elim_left stronger
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
|
|
|
|
theorem sub_induction {P : ℕ → ℕ → Prop} (n m : ℕ) (H1 : ∀m, P 0 m)
|
|
|
|
|
(H2 : ∀n, P (succ n) 0) (H3 : ∀n m, P n m → P (succ n) (succ m)) : P n m :=
|
|
|
|
|
have general : ∀m, P n m, from induction_on n
|
|
|
|
|
(take m : ℕ, H1 m)
|
|
|
|
|
(take k : ℕ,
|
|
|
|
|
assume IH : ∀m, P k m,
|
|
|
|
|
take m : ℕ,
|
|
|
|
|
discriminate
|
2014-08-27 01:47:36 +00:00
|
|
|
|
(assume Hm : m = 0, Hm⁻¹ ▸ (H2 k))
|
|
|
|
|
(take l : ℕ, assume Hm : m = succ l, Hm⁻¹ ▸ (H3 k l (IH l)))),
|
2014-08-02 01:40:24 +00:00
|
|
|
|
general m
|
|
|
|
|
|
|
|
|
|
-- Addition
|
|
|
|
|
-- --------
|
2014-11-22 08:15:51 +00:00
|
|
|
|
theorem add.zero_right (n : ℕ) : n + 0 = n :=
|
|
|
|
|
rfl
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
2014-11-22 08:15:51 +00:00
|
|
|
|
theorem add.succ_right (n m : ℕ) : n + succ m = succ (n + m) :=
|
|
|
|
|
rfl
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
2014-09-19 22:40:39 +00:00
|
|
|
|
irreducible add
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
2014-10-02 01:39:47 +00:00
|
|
|
|
theorem add.zero_left (n : ℕ) : 0 + n = n :=
|
2014-08-02 01:40:24 +00:00
|
|
|
|
induction_on n
|
2014-10-02 01:39:47 +00:00
|
|
|
|
!add.zero_right
|
2014-08-02 01:40:24 +00:00
|
|
|
|
(take m IH, show 0 + succ m = succ m, from
|
|
|
|
|
calc
|
2014-10-31 06:28:35 +00:00
|
|
|
|
0 + succ m = succ (0 + m) : add.succ_right
|
2014-10-31 15:29:46 +00:00
|
|
|
|
... = succ m : IH)
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
2014-10-02 01:39:47 +00:00
|
|
|
|
theorem add.succ_left (n m : ℕ) : (succ n) + m = succ (n + m) :=
|
2014-08-02 01:40:24 +00:00
|
|
|
|
induction_on m
|
2014-10-02 01:39:47 +00:00
|
|
|
|
(!add.zero_right ▸ !add.zero_right)
|
2014-08-27 01:47:36 +00:00
|
|
|
|
(take k IH, calc
|
2014-10-31 06:28:35 +00:00
|
|
|
|
succ n + succ k = succ (succ n + k) : add.succ_right
|
2014-10-31 15:29:46 +00:00
|
|
|
|
... = succ (succ (n + k)) : IH
|
2014-10-31 08:02:49 +00:00
|
|
|
|
... = succ (n + succ k) : add.succ_right)
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
2014-10-02 01:39:47 +00:00
|
|
|
|
theorem add.comm (n m : ℕ) : n + m = m + n :=
|
2014-08-02 01:40:24 +00:00
|
|
|
|
induction_on m
|
2014-10-02 01:39:47 +00:00
|
|
|
|
(!add.zero_right ⬝ !add.zero_left⁻¹)
|
2014-08-27 01:47:36 +00:00
|
|
|
|
(take k IH, calc
|
2014-10-31 06:28:35 +00:00
|
|
|
|
n + succ k = succ (n+k) : add.succ_right
|
2014-10-31 15:29:46 +00:00
|
|
|
|
... = succ (k + n) : IH
|
2014-10-31 06:28:35 +00:00
|
|
|
|
... = succ k + n : add.succ_left)
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
2014-10-02 01:39:47 +00:00
|
|
|
|
theorem add.move_succ (n m : ℕ) : succ n + m = n + succ m :=
|
|
|
|
|
!add.succ_left ⬝ !add.succ_right⁻¹
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
2014-10-02 01:39:47 +00:00
|
|
|
|
theorem add.comm_succ (n m : ℕ) : n + succ m = m + succ n :=
|
|
|
|
|
!add.move_succ⁻¹ ⬝ !add.comm
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
2014-10-02 01:39:47 +00:00
|
|
|
|
theorem add.assoc (n m k : ℕ) : (n + m) + k = n + (m + k) :=
|
2014-08-02 01:40:24 +00:00
|
|
|
|
induction_on k
|
2014-10-02 01:39:47 +00:00
|
|
|
|
(!add.zero_right ▸ !add.zero_right)
|
2014-08-02 01:40:24 +00:00
|
|
|
|
(take l IH,
|
|
|
|
|
calc
|
2014-10-31 06:28:35 +00:00
|
|
|
|
(n + m) + succ l = succ ((n + m) + l) : add.succ_right
|
2014-10-31 15:29:46 +00:00
|
|
|
|
... = succ (n + (m + l)) : IH
|
2014-10-31 06:28:35 +00:00
|
|
|
|
... = n + succ (m + l) : add.succ_right
|
2014-10-31 08:02:49 +00:00
|
|
|
|
... = n + (m + succ l) : add.succ_right)
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
2014-10-02 01:39:47 +00:00
|
|
|
|
theorem add.left_comm (n m k : ℕ) : n + (m + k) = m + (n + k) :=
|
2014-10-31 15:29:46 +00:00
|
|
|
|
left_comm add.comm add.assoc n m k
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
2014-10-02 01:39:47 +00:00
|
|
|
|
theorem add.right_comm (n m k : ℕ) : n + m + k = n + k + m :=
|
2014-10-31 15:29:46 +00:00
|
|
|
|
right_comm add.comm add.assoc n m k
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
|
|
|
|
-- ### cancelation
|
|
|
|
|
|
2014-10-02 01:39:47 +00:00
|
|
|
|
theorem add.cancel_left {n m k : ℕ} : n + m = n + k → m = k :=
|
2014-08-02 01:40:24 +00:00
|
|
|
|
induction_on n
|
|
|
|
|
(take H : 0 + m = 0 + k,
|
2014-10-02 01:39:47 +00:00
|
|
|
|
!add.zero_left⁻¹ ⬝ H ⬝ !add.zero_left)
|
2014-08-02 01:40:24 +00:00
|
|
|
|
(take (n : ℕ) (IH : n + m = n + k → m = k) (H : succ n + m = succ n + k),
|
|
|
|
|
have H2 : succ (n + m) = succ (n + k),
|
|
|
|
|
from calc
|
2014-10-31 06:28:35 +00:00
|
|
|
|
succ (n + m) = succ n + m : add.succ_left
|
2014-08-27 01:47:36 +00:00
|
|
|
|
... = succ n + k : H
|
2014-10-31 06:28:35 +00:00
|
|
|
|
... = succ (n + k) : add.succ_left,
|
2014-10-02 01:39:47 +00:00
|
|
|
|
have H3 : n + m = n + k, from succ.inj H2,
|
2014-08-02 01:40:24 +00:00
|
|
|
|
IH H3)
|
|
|
|
|
|
2014-10-02 01:39:47 +00:00
|
|
|
|
theorem add.cancel_right {n m k : ℕ} (H : n + m = k + m) : n = k :=
|
|
|
|
|
have H2 : m + n = m + k, from !add.comm ⬝ H ⬝ !add.comm,
|
|
|
|
|
add.cancel_left H2
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
2014-10-02 01:39:47 +00:00
|
|
|
|
theorem add.eq_zero_left {n m : ℕ} : n + m = 0 → n = 0 :=
|
2014-08-02 01:40:24 +00:00
|
|
|
|
induction_on n
|
2014-09-04 23:36:06 +00:00
|
|
|
|
(take (H : 0 + m = 0), rfl)
|
2014-08-02 01:40:24 +00:00
|
|
|
|
(take k IH,
|
2014-08-27 01:47:36 +00:00
|
|
|
|
assume H : succ k + m = 0,
|
2014-08-28 01:34:09 +00:00
|
|
|
|
absurd
|
2014-08-27 01:47:36 +00:00
|
|
|
|
(show succ (k + m) = 0, from calc
|
2014-10-31 06:28:35 +00:00
|
|
|
|
succ (k + m) = succ k + m : add.succ_left
|
2014-08-27 01:47:36 +00:00
|
|
|
|
... = 0 : H)
|
2014-10-02 01:50:17 +00:00
|
|
|
|
!succ_ne_zero)
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
2014-10-02 01:39:47 +00:00
|
|
|
|
theorem add.eq_zero_right {n m : ℕ} (H : n + m = 0) : m = 0 :=
|
|
|
|
|
add.eq_zero_left (!add.comm ⬝ H)
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
2014-10-02 01:39:47 +00:00
|
|
|
|
theorem add.eq_zero {n m : ℕ} (H : n + m = 0) : n = 0 ∧ m = 0 :=
|
|
|
|
|
and.intro (add.eq_zero_left H) (add.eq_zero_right H)
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
|
|
|
|
-- ### misc
|
|
|
|
|
|
2014-10-02 01:39:47 +00:00
|
|
|
|
theorem add.one (n : ℕ) : n + 1 = succ n :=
|
|
|
|
|
!add.zero_right ▸ !add.succ_right
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
2014-10-02 01:39:47 +00:00
|
|
|
|
theorem add.one_left (n : ℕ) : 1 + n = succ n :=
|
|
|
|
|
!add.zero_left ▸ !add.succ_left
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
|
|
|
|
-- TODO: rename? remove?
|
|
|
|
|
theorem induction_plus_one {P : nat → Prop} (a : ℕ) (H1 : P 0)
|
|
|
|
|
(H2 : ∀ (n : ℕ) (IH : P n), P (n + 1)) : P a :=
|
2014-10-02 01:39:47 +00:00
|
|
|
|
nat.rec H1 (take n IH, !add.one ▸ (H2 n IH)) a
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
|
|
|
|
-- Multiplication
|
|
|
|
|
-- --------------
|
|
|
|
|
|
2014-11-22 08:15:51 +00:00
|
|
|
|
theorem mul.zero_right (n : ℕ) : n * 0 = 0 :=
|
|
|
|
|
rfl
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
2014-11-22 08:15:51 +00:00
|
|
|
|
theorem mul.succ_right (n m : ℕ) : n * succ m = n * m + n :=
|
|
|
|
|
rfl
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
2014-09-19 22:40:39 +00:00
|
|
|
|
irreducible mul
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
|
|
|
|
-- ### commutativity, distributivity, associativity, identity
|
|
|
|
|
|
2014-10-02 01:39:47 +00:00
|
|
|
|
theorem mul.zero_left (n : ℕ) : 0 * n = 0 :=
|
2014-08-02 01:40:24 +00:00
|
|
|
|
induction_on n
|
2014-10-02 01:39:47 +00:00
|
|
|
|
!mul.zero_right
|
|
|
|
|
(take m IH, !mul.succ_right ⬝ !add.zero_right ⬝ IH)
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
2014-10-02 01:39:47 +00:00
|
|
|
|
theorem mul.succ_left (n m : ℕ) : (succ n) * m = (n * m) + m :=
|
2014-08-02 01:40:24 +00:00
|
|
|
|
induction_on m
|
2014-10-02 01:39:47 +00:00
|
|
|
|
(!mul.zero_right ⬝ !mul.zero_right⁻¹ ⬝ !add.zero_right⁻¹)
|
2014-08-27 01:47:36 +00:00
|
|
|
|
(take k IH, calc
|
2014-10-31 06:28:35 +00:00
|
|
|
|
succ n * succ k = (succ n * k) + succ n : mul.succ_right
|
2014-10-31 15:29:46 +00:00
|
|
|
|
... = (n * k) + k + succ n : IH
|
2014-10-31 06:28:35 +00:00
|
|
|
|
... = (n * k) + (k + succ n) : add.assoc
|
2014-10-31 08:02:49 +00:00
|
|
|
|
... = (n * k) + (n + succ k) : add.comm_succ
|
2014-10-31 06:28:35 +00:00
|
|
|
|
... = (n * k) + n + succ k : add.assoc
|
2014-10-31 08:02:49 +00:00
|
|
|
|
... = (n * succ k) + succ k : mul.succ_right)
|
2014-08-27 01:47:36 +00:00
|
|
|
|
|
2014-10-02 01:39:47 +00:00
|
|
|
|
theorem mul.comm (n m : ℕ) : n * m = m * n :=
|
2014-08-02 01:40:24 +00:00
|
|
|
|
induction_on m
|
2014-10-02 01:39:47 +00:00
|
|
|
|
(!mul.zero_right ⬝ !mul.zero_left⁻¹)
|
2014-08-27 01:47:36 +00:00
|
|
|
|
(take k IH, calc
|
2014-10-31 06:28:35 +00:00
|
|
|
|
n * succ k = n * k + n : mul.succ_right
|
2014-10-31 15:29:46 +00:00
|
|
|
|
... = k * n + n : IH
|
2014-10-31 06:28:35 +00:00
|
|
|
|
... = (succ k) * n : mul.succ_left)
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
2014-10-02 01:39:47 +00:00
|
|
|
|
theorem mul.distr_right (n m k : ℕ) : (n + m) * k = n * k + m * k :=
|
2014-08-02 01:40:24 +00:00
|
|
|
|
induction_on k
|
|
|
|
|
(calc
|
2014-10-31 06:28:35 +00:00
|
|
|
|
(n + m) * 0 = 0 : mul.zero_right
|
|
|
|
|
... = 0 + 0 : add.zero_right
|
2014-10-31 08:02:49 +00:00
|
|
|
|
... = n * 0 + 0 : mul.zero_right
|
|
|
|
|
... = n * 0 + m * 0 : mul.zero_right)
|
2014-08-02 01:40:24 +00:00
|
|
|
|
(take l IH, calc
|
2014-10-31 06:28:35 +00:00
|
|
|
|
(n + m) * succ l = (n + m) * l + (n + m) : mul.succ_right
|
2014-10-31 15:29:46 +00:00
|
|
|
|
... = n * l + m * l + (n + m) : IH
|
2014-10-31 06:28:35 +00:00
|
|
|
|
... = n * l + m * l + n + m : add.assoc
|
2014-10-31 08:02:49 +00:00
|
|
|
|
... = n * l + n + m * l + m : add.right_comm
|
2014-10-31 06:28:35 +00:00
|
|
|
|
... = n * l + n + (m * l + m) : add.assoc
|
2014-10-31 08:02:49 +00:00
|
|
|
|
... = n * succ l + (m * l + m) : mul.succ_right
|
|
|
|
|
... = n * succ l + m * succ l : mul.succ_right)
|
2014-08-27 01:47:36 +00:00
|
|
|
|
|
2014-10-02 01:39:47 +00:00
|
|
|
|
theorem mul.distr_left (n m k : ℕ) : n * (m + k) = n * m + n * k :=
|
2014-08-02 01:40:24 +00:00
|
|
|
|
calc
|
2014-10-31 06:28:35 +00:00
|
|
|
|
n * (m + k) = (m + k) * n : mul.comm
|
|
|
|
|
... = m * n + k * n : mul.distr_right
|
2014-10-31 08:02:49 +00:00
|
|
|
|
... = n * m + k * n : mul.comm
|
|
|
|
|
... = n * m + n * k : mul.comm
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
2014-10-02 01:39:47 +00:00
|
|
|
|
theorem mul.assoc (n m k : ℕ) : (n * m) * k = n * (m * k) :=
|
2014-08-02 01:40:24 +00:00
|
|
|
|
induction_on k
|
|
|
|
|
(calc
|
2014-10-31 06:28:35 +00:00
|
|
|
|
(n * m) * 0 = 0 : mul.zero_right
|
|
|
|
|
... = n * 0 : mul.zero_right
|
2014-10-31 08:02:49 +00:00
|
|
|
|
... = n * (m * 0) : mul.zero_right)
|
2014-08-02 01:40:24 +00:00
|
|
|
|
(take l IH,
|
|
|
|
|
calc
|
2014-10-31 06:28:35 +00:00
|
|
|
|
(n * m) * succ l = (n * m) * l + n * m : mul.succ_right
|
2014-10-31 15:29:46 +00:00
|
|
|
|
... = n * (m * l) + n * m : IH
|
2014-10-31 06:28:35 +00:00
|
|
|
|
... = n * (m * l + m) : mul.distr_left
|
2014-10-31 08:02:49 +00:00
|
|
|
|
... = n * (m * succ l) : mul.succ_right)
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
2014-10-02 01:39:47 +00:00
|
|
|
|
theorem mul.left_comm (n m k : ℕ) : n * (m * k) = m * (n * k) :=
|
|
|
|
|
left_comm mul.comm mul.assoc n m k
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
2014-10-02 01:39:47 +00:00
|
|
|
|
theorem mul.right_comm (n m k : ℕ) : n * m * k = n * k * m :=
|
|
|
|
|
right_comm mul.comm mul.assoc n m k
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
2014-10-02 01:39:47 +00:00
|
|
|
|
theorem mul.one_right (n : ℕ) : n * 1 = n :=
|
2014-08-02 01:40:24 +00:00
|
|
|
|
calc
|
2014-10-31 06:28:35 +00:00
|
|
|
|
n * 1 = n * 0 + n : mul.succ_right
|
2014-10-31 08:02:49 +00:00
|
|
|
|
... = 0 + n : mul.zero_right
|
2014-10-31 06:28:35 +00:00
|
|
|
|
... = n : add.zero_left
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
2014-10-02 01:39:47 +00:00
|
|
|
|
theorem mul.one_left (n : ℕ) : 1 * n = n :=
|
2014-08-02 01:40:24 +00:00
|
|
|
|
calc
|
2014-10-31 06:28:35 +00:00
|
|
|
|
1 * n = n * 1 : mul.comm
|
|
|
|
|
... = n : mul.one_right
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
2014-10-02 01:39:47 +00:00
|
|
|
|
theorem mul.eq_zero {n m : ℕ} (H : n * m = 0) : n = 0 ∨ m = 0 :=
|
2014-08-02 01:40:24 +00:00
|
|
|
|
discriminate
|
2014-09-05 04:25:21 +00:00
|
|
|
|
(take Hn : n = 0, or.inl Hn)
|
2014-08-02 01:40:24 +00:00
|
|
|
|
(take (k : ℕ),
|
|
|
|
|
assume (Hk : n = succ k),
|
|
|
|
|
discriminate
|
2014-09-05 04:25:21 +00:00
|
|
|
|
(take (Hm : m = 0), or.inr Hm)
|
2014-08-02 01:40:24 +00:00
|
|
|
|
(take (l : ℕ),
|
2014-08-22 01:24:22 +00:00
|
|
|
|
assume (Hl : m = succ l),
|
|
|
|
|
have Heq : succ (k * succ l + l) = n * m, from
|
2014-09-05 01:41:06 +00:00
|
|
|
|
(calc
|
2014-10-31 15:29:46 +00:00
|
|
|
|
n * m = n * succ l : Hl
|
|
|
|
|
... = succ k * succ l : Hk
|
2014-10-31 06:28:35 +00:00
|
|
|
|
... = k * succ l + succ l : mul.succ_left
|
|
|
|
|
... = succ (k * succ l + l) : add.succ_right)⁻¹,
|
2014-10-02 01:50:17 +00:00
|
|
|
|
absurd (Heq ⬝ H) !succ_ne_zero))
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
2014-08-20 02:32:44 +00:00
|
|
|
|
end nat
|