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.
|
|
|
|
|
--- Author: Floris van Doorn
|
|
|
|
|
|
2014-08-22 23:36:47 +00:00
|
|
|
|
-- data.nat.basic
|
|
|
|
|
-- ==============
|
|
|
|
|
--
|
|
|
|
|
-- Basic operations on the natural numbers.
|
|
|
|
|
|
2014-09-16 18:58:54 +00:00
|
|
|
|
import logic data.num tools.tactic algebra.binary tools.helper_tactics
|
2014-09-16 18:44:50 +00:00
|
|
|
|
import logic.core.inhabited
|
2014-08-22 23:36:47 +00:00
|
|
|
|
|
2014-09-04 23:36:06 +00:00
|
|
|
|
open tactic binary eq_ops
|
2014-09-08 07:16:20 +00:00
|
|
|
|
open decidable
|
2014-09-03 23:00:38 +00:00
|
|
|
|
open relation -- for subst_iff
|
|
|
|
|
open helper_tactics
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
|
|
|
|
-- Definition of the type
|
|
|
|
|
-- ----------------------
|
|
|
|
|
inductive nat : Type :=
|
2014-08-22 22:46:10 +00:00
|
|
|
|
zero : nat,
|
|
|
|
|
succ : nat → nat
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
2014-09-04 22:03:59 +00:00
|
|
|
|
namespace nat
|
|
|
|
|
|
2014-08-22 23:36:47 +00:00
|
|
|
|
notation `ℕ` := nat
|
2014-08-20 02:32:44 +00:00
|
|
|
|
|
2014-09-04 22:03:59 +00:00
|
|
|
|
theorem rec_zero {P : ℕ → Type} (x : P zero) (f : ∀m, P m → P (succ m)) : nat.rec x f zero = x
|
2014-08-20 02:32:44 +00:00
|
|
|
|
|
2014-09-03 23:14:29 +00:00
|
|
|
|
theorem rec_succ {P : ℕ → Type} (x : P zero) (f : ∀m, P m → P (succ m)) (n : ℕ) :
|
2014-09-04 22:03:59 +00:00
|
|
|
|
nat.rec x f (succ n) = f n (nat.rec x f n)
|
2014-08-20 02:32:44 +00:00
|
|
|
|
|
2014-09-19 22:04:52 +00:00
|
|
|
|
protected theorem induction_on {P : ℕ → Prop} (a : ℕ) (H1 : P zero) (H2 : ∀ (n : ℕ) (IH : P n), P (succ n)) :
|
2014-08-20 02:32:44 +00:00
|
|
|
|
P a :=
|
2014-09-04 22:03:59 +00:00
|
|
|
|
nat.rec H1 H2 a
|
2014-08-20 02:32:44 +00:00
|
|
|
|
|
2014-09-19 22:04:52 +00:00
|
|
|
|
protected definition rec_on {P : ℕ → Type} (n : ℕ) (H1 : P zero) (H2 : ∀m, P m → P (succ m)) : P n :=
|
2014-09-04 22:03:59 +00:00
|
|
|
|
nat.rec H1 H2 n
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
2014-09-19 22:04:52 +00:00
|
|
|
|
protected theorem is_inhabited [instance] : inhabited nat :=
|
2014-09-08 02:50:15 +00:00
|
|
|
|
inhabited.mk zero
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
|
|
|
|
-- Coercion from num
|
|
|
|
|
-- -----------------
|
|
|
|
|
|
2014-09-17 21:39:05 +00:00
|
|
|
|
definition add (x y : ℕ) : ℕ :=
|
2014-09-04 22:03:59 +00:00
|
|
|
|
nat.rec x (λ n r, succ r) y
|
2014-09-17 21:39:05 +00:00
|
|
|
|
infixl `+` := add
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
2014-09-17 21:39:05 +00:00
|
|
|
|
definition to_nat [coercion] (n : num) : ℕ :=
|
2014-09-04 23:36:06 +00:00
|
|
|
|
num.rec zero
|
2014-09-17 21:39:05 +00:00
|
|
|
|
(λ n, pos_num.rec (succ zero) (λ n r, r + r + (succ zero)) (λ n r, r + r) n) n
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
|
|
|
|
-- Successor and predecessor
|
|
|
|
|
-- -------------------------
|
|
|
|
|
|
2014-08-27 01:47:36 +00:00
|
|
|
|
theorem succ_ne_zero {n : ℕ} : succ n ≠ 0 :=
|
2014-08-02 01:40:24 +00:00
|
|
|
|
assume H : succ n = 0,
|
|
|
|
|
have H2 : true = false, from
|
2014-09-04 22:03:59 +00:00
|
|
|
|
let f := (nat.rec false (fun a b, true)) in
|
2014-08-02 01:40:24 +00:00
|
|
|
|
calc
|
2014-08-20 02:32:44 +00:00
|
|
|
|
true = f (succ n) : rfl
|
2014-08-02 01:40:24 +00:00
|
|
|
|
... = f 0 : {H}
|
2014-08-20 02:32:44 +00:00
|
|
|
|
... = false : rfl,
|
2014-08-02 01:40:24 +00:00
|
|
|
|
absurd H2 true_ne_false
|
|
|
|
|
|
|
|
|
|
-- add_rewrite succ_ne_zero
|
|
|
|
|
|
2014-09-04 22:03:59 +00:00
|
|
|
|
definition pred (n : ℕ) := nat.rec 0 (fun m x, m) n
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
|
|
|
|
theorem pred_zero : pred 0 = 0
|
|
|
|
|
|
2014-08-28 18:10:04 +00:00
|
|
|
|
theorem pred_succ {n : ℕ} : pred (succ n) = n
|
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-08-28 18:10:04 +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-09-05 04:25:21 +00:00
|
|
|
|
or.imp_or (zero_or_succ_pred n) (assume H, H)
|
2014-08-02 01:40:24 +00:00
|
|
|
|
(assume H : n = succ (pred n), exists_intro (pred n) H)
|
|
|
|
|
|
|
|
|
|
theorem case {P : ℕ → Prop} (n : ℕ) (H1: P 0) (H2 : ∀m, P (succ m)) : P n :=
|
|
|
|
|
induction_on n H1 (take m IH, H2 m)
|
|
|
|
|
|
|
|
|
|
theorem discriminate {B : Prop} {n : ℕ} (H1: n = 0 → B) (H2 : ∀m, n = succ m → B) : B :=
|
2014-09-05 04:25:21 +00:00
|
|
|
|
or.elim (zero_or_succ_pred n)
|
2014-08-02 01:40:24 +00:00
|
|
|
|
(take H3 : n = 0, H1 H3)
|
|
|
|
|
(take H3 : n = succ (pred n), H2 (pred n) H3)
|
|
|
|
|
|
|
|
|
|
theorem succ_inj {n m : ℕ} (H : succ n = succ m) : n = m :=
|
|
|
|
|
calc
|
2014-08-28 18:10:04 +00:00
|
|
|
|
n = pred (succ n) : pred_succ⁻¹
|
2014-08-02 01:40:24 +00:00
|
|
|
|
... = pred (succ m) : {H}
|
2014-08-28 18:10:04 +00:00
|
|
|
|
... = m : pred_succ
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
2014-08-27 01:47:36 +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-08-27 01:47:36 +00:00
|
|
|
|
have ne : 1 ≠ 0, from succ_ne_zero,
|
2014-08-02 01:40:24 +00:00
|
|
|
|
absurd H ne)
|
|
|
|
|
(take k IH H, IH (succ_inj H))
|
|
|
|
|
|
2014-09-19 22:04:52 +00:00
|
|
|
|
protected theorem has_decidable_eq [instance] : decidable_eq ℕ :=
|
2014-09-09 23:07:07 +00:00
|
|
|
|
take n m : ℕ,
|
2014-08-02 01:40:24 +00:00
|
|
|
|
have general : ∀n, decidable (n = m), from
|
|
|
|
|
rec_on m
|
|
|
|
|
(take n,
|
|
|
|
|
rec_on n
|
2014-09-04 23:36:06 +00:00
|
|
|
|
(inl rfl)
|
2014-08-27 01:47:36 +00:00
|
|
|
|
(λ m iH, inr succ_ne_zero))
|
2014-08-02 01:40:24 +00:00
|
|
|
|
(λ (m' : ℕ) (iH1 : ∀n, decidable (n = m')),
|
|
|
|
|
take n, rec_on n
|
2014-09-05 01:41:06 +00:00
|
|
|
|
(inr (ne.symm succ_ne_zero))
|
2014-08-22 01:24:22 +00:00
|
|
|
|
(λ (n' : ℕ) (iH2 : decidable (n' = succ m')),
|
2014-09-08 07:16:20 +00:00
|
|
|
|
decidable.by_cases
|
2014-08-22 01:24:22 +00:00
|
|
|
|
(assume Heq : n' = m', inl (congr_arg succ Heq))
|
|
|
|
|
(assume Hne : n' ≠ m',
|
|
|
|
|
have H1 : succ n' ≠ succ m', from
|
|
|
|
|
assume Heq, absurd (succ_inj Heq) Hne,
|
|
|
|
|
inr H1))),
|
2014-09-09 23:07:07 +00:00
|
|
|
|
general n
|
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-08-27 01:47:36 +00:00
|
|
|
|
theorem add_zero_right {n : ℕ} : n + 0 = n
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
2014-08-27 01:47:36 +00:00
|
|
|
|
theorem add_succ_right {n m : ℕ} : n + succ m = succ (n + m)
|
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-08-27 01:47:36 +00:00
|
|
|
|
theorem add_zero_left {n : ℕ} : 0 + n = n :=
|
2014-08-02 01:40:24 +00:00
|
|
|
|
induction_on n
|
2014-08-27 01:47:36 +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-08-27 01:47:36 +00:00
|
|
|
|
0 + succ m = succ (0 + m) : add_succ_right
|
2014-08-28 20:04:17 +00:00
|
|
|
|
... = succ m : {IH})
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
2014-08-27 01:47:36 +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-08-27 01:47:36 +00:00
|
|
|
|
(add_zero_right ▸ add_zero_right)
|
|
|
|
|
(take k IH, calc
|
|
|
|
|
succ n + succ k = succ (succ n + k) : add_succ_right
|
|
|
|
|
... = succ (succ (n + k)) : {IH}
|
|
|
|
|
... = succ (n + succ k) : {add_succ_right⁻¹})
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
2014-08-27 01:47:36 +00:00
|
|
|
|
theorem add_comm {n m : ℕ} : n + m = m + n :=
|
2014-08-02 01:40:24 +00:00
|
|
|
|
induction_on m
|
2014-08-27 01:47:36 +00:00
|
|
|
|
(add_zero_right ⬝ add_zero_left⁻¹)
|
|
|
|
|
(take k IH, calc
|
|
|
|
|
n + succ k = succ (n+k) : add_succ_right
|
|
|
|
|
... = succ (k + n) : {IH}
|
|
|
|
|
... = succ k + n : add_succ_left⁻¹)
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
2014-08-27 01:47:36 +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-08-27 01:47:36 +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-08-27 01:47:36 +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-08-27 01:47:36 +00:00
|
|
|
|
(add_zero_right ▸ add_zero_right)
|
2014-08-02 01:40:24 +00:00
|
|
|
|
(take l IH,
|
|
|
|
|
calc
|
2014-08-27 01:47:36 +00:00
|
|
|
|
(n + m) + succ l = succ ((n + m) + l) : add_succ_right
|
|
|
|
|
... = succ (n + (m + l)) : {IH}
|
|
|
|
|
... = n + succ (m + l) : add_succ_right⁻¹
|
|
|
|
|
... = n + (m + succ l) : {add_succ_right⁻¹})
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
2014-08-27 01:47:36 +00:00
|
|
|
|
theorem add_left_comm {n m k : ℕ} : n + (m + k) = m + (n + k) :=
|
|
|
|
|
left_comm @add_comm @add_assoc n m k
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
2014-08-27 01:47:36 +00:00
|
|
|
|
theorem add_right_comm {n m k : ℕ} : n + m + k = n + k + m :=
|
|
|
|
|
right_comm @add_comm @add_assoc n m k
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
|
|
|
|
-- add_rewrite add_zero_left add_zero_right
|
|
|
|
|
-- add_rewrite add_succ_left add_succ_right
|
|
|
|
|
-- add_rewrite add_comm add_assoc add_left_comm
|
|
|
|
|
|
|
|
|
|
-- ### cancelation
|
|
|
|
|
|
|
|
|
|
theorem add_cancel_left {n m k : ℕ} : n + m = n + k → m = k :=
|
|
|
|
|
induction_on n
|
|
|
|
|
(take H : 0 + m = 0 + k,
|
2014-08-27 01:47:36 +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-08-27 01:47:36 +00:00
|
|
|
|
succ (n + m) = succ n + m : add_succ_left⁻¹
|
|
|
|
|
... = succ n + k : H
|
|
|
|
|
... = succ (n + k) : add_succ_left,
|
2014-08-02 01:40:24 +00:00
|
|
|
|
have H3 : n + m = n + k, from succ_inj H2,
|
|
|
|
|
IH H3)
|
|
|
|
|
|
|
|
|
|
theorem add_cancel_right {n m k : ℕ} (H : n + m = k + m) : n = k :=
|
2014-08-27 01:47:36 +00:00
|
|
|
|
have H2 : m + n = m + k, from add_comm ⬝ H ⬝ add_comm,
|
2014-08-02 01:40:24 +00:00
|
|
|
|
add_cancel_left H2
|
|
|
|
|
|
|
|
|
|
theorem add_eq_zero_left {n m : ℕ} : n + m = 0 → n = 0 :=
|
|
|
|
|
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
|
|
|
|
|
succ (k + m) = succ k + m : add_succ_left⁻¹
|
|
|
|
|
... = 0 : H)
|
|
|
|
|
succ_ne_zero)
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
|
|
|
|
theorem add_eq_zero_right {n m : ℕ} (H : n + m = 0) : m = 0 :=
|
2014-08-27 01:47:36 +00:00
|
|
|
|
add_eq_zero_left (add_comm ⬝ H)
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
|
|
|
|
theorem add_eq_zero {n m : ℕ} (H : n + m = 0) : n = 0 ∧ m = 0 :=
|
2014-09-04 23:36:06 +00:00
|
|
|
|
and.intro (add_eq_zero_left H) (add_eq_zero_right H)
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
|
|
|
|
-- ### misc
|
|
|
|
|
|
2014-08-27 01:47:36 +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-08-27 01:47:36 +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-09-04 22:03:59 +00:00
|
|
|
|
nat.rec H1 (take n IH, add_one ▸ (H2 n IH)) a
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
|
|
|
|
-- Multiplication
|
|
|
|
|
-- --------------
|
|
|
|
|
|
2014-09-04 22:03:59 +00:00
|
|
|
|
definition mul (n m : ℕ) := nat.rec 0 (fun m x, x + n) m
|
2014-08-22 23:36:47 +00:00
|
|
|
|
infixl `*` := mul
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
2014-08-27 01:47:36 +00:00
|
|
|
|
theorem mul_zero_right {n : ℕ} : n * 0 = 0
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
2014-08-27 01:47:36 +00:00
|
|
|
|
theorem mul_succ_right {n m : ℕ} : n * succ m = n * m + n
|
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-08-27 01:47:36 +00:00
|
|
|
|
theorem mul_zero_left {n : ℕ} : 0 * n = 0 :=
|
2014-08-02 01:40:24 +00:00
|
|
|
|
induction_on n
|
2014-08-27 01:47:36 +00:00
|
|
|
|
mul_zero_right
|
|
|
|
|
(take m IH, mul_succ_right ⬝ add_zero_right ⬝ IH)
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
2014-08-27 01:47:36 +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-08-27 01:47:36 +00:00
|
|
|
|
(mul_zero_right ⬝ mul_zero_right⁻¹ ⬝ add_zero_right⁻¹)
|
|
|
|
|
(take k IH, calc
|
|
|
|
|
succ n * succ k = (succ n * k) + succ n : mul_succ_right
|
|
|
|
|
... = (n * k) + k + succ n : {IH}
|
|
|
|
|
... = (n * k) + (k + succ n) : add_assoc
|
|
|
|
|
... = (n * k) + (n + succ k) : {add_comm_succ}
|
|
|
|
|
... = (n * k) + n + succ k : add_assoc⁻¹
|
|
|
|
|
... = (n * succ k) + succ k : {mul_succ_right⁻¹})
|
|
|
|
|
|
|
|
|
|
theorem mul_comm {n m : ℕ} : n * m = m * n :=
|
2014-08-02 01:40:24 +00:00
|
|
|
|
induction_on m
|
2014-08-27 01:47:36 +00:00
|
|
|
|
(mul_zero_right ⬝ mul_zero_left⁻¹)
|
|
|
|
|
(take k IH, calc
|
|
|
|
|
n * succ k = n * k + n : mul_succ_right
|
|
|
|
|
... = k * n + n : {IH}
|
|
|
|
|
... = (succ k) * n : mul_succ_left⁻¹)
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
2014-08-27 01:47:36 +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-08-27 01:47:36 +00:00
|
|
|
|
(n + m) * 0 = 0 : mul_zero_right
|
|
|
|
|
... = 0 + 0 : add_zero_right⁻¹
|
|
|
|
|
... = 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-08-27 01:47:36 +00:00
|
|
|
|
(n + m) * succ l = (n + m) * l + (n + m) : mul_succ_right
|
|
|
|
|
... = n * l + m * l + (n + m) : {IH}
|
|
|
|
|
... = n * l + m * l + n + m : add_assoc⁻¹
|
|
|
|
|
... = n * l + n + m * l + m : {add_right_comm}
|
|
|
|
|
... = n * l + n + (m * l + m) : add_assoc
|
|
|
|
|
... = n * succ l + (m * l + m) : {mul_succ_right⁻¹}
|
|
|
|
|
... = n * succ l + m * succ l : {mul_succ_right⁻¹})
|
|
|
|
|
|
|
|
|
|
theorem mul_distr_left {n m k : ℕ} : n * (m + k) = n * m + n * k :=
|
2014-08-02 01:40:24 +00:00
|
|
|
|
calc
|
2014-08-27 01:47:36 +00:00
|
|
|
|
n * (m + k) = (m + k) * n : mul_comm
|
|
|
|
|
... = m * n + k * n : mul_distr_right
|
|
|
|
|
... = n * m + k * n : {mul_comm}
|
|
|
|
|
... = n * m + n * k : {mul_comm}
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
2014-08-27 01:47:36 +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-08-27 01:47:36 +00:00
|
|
|
|
(n * m) * 0 = 0 : mul_zero_right
|
|
|
|
|
... = n * 0 : mul_zero_right⁻¹
|
|
|
|
|
... = n * (m * 0) : {mul_zero_right⁻¹})
|
2014-08-02 01:40:24 +00:00
|
|
|
|
(take l IH,
|
|
|
|
|
calc
|
2014-08-27 01:47:36 +00:00
|
|
|
|
(n * m) * succ l = (n * m) * l + n * m : mul_succ_right
|
|
|
|
|
... = n * (m * l) + n * m : {IH}
|
|
|
|
|
... = n * (m * l + m) : mul_distr_left⁻¹
|
|
|
|
|
... = n * (m * succ l) : {mul_succ_right⁻¹})
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
2014-08-27 01:47:36 +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-08-27 01:47:36 +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-08-27 01:47:36 +00:00
|
|
|
|
theorem mul_one_right {n : ℕ} : n * 1 = n :=
|
2014-08-02 01:40:24 +00:00
|
|
|
|
calc
|
2014-08-27 01:47:36 +00:00
|
|
|
|
n * 1 = n * 0 + n : mul_succ_right
|
|
|
|
|
... = 0 + n : {mul_zero_right}
|
|
|
|
|
... = n : add_zero_left
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
2014-08-27 01:47:36 +00:00
|
|
|
|
theorem mul_one_left {n : ℕ} : 1 * n = n :=
|
2014-08-02 01:40:24 +00:00
|
|
|
|
calc
|
2014-08-27 01:47:36 +00:00
|
|
|
|
1 * n = n * 1 : mul_comm
|
|
|
|
|
... = n : mul_one_right
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
|
|
|
|
theorem mul_eq_zero {n m : ℕ} (H : n * m = 0) : n = 0 ∨ m = 0 :=
|
|
|
|
|
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-08-27 01:47:36 +00:00
|
|
|
|
n * m = n * succ l : {Hl}
|
|
|
|
|
... = succ k * succ l : {Hk}
|
|
|
|
|
... = k * succ l + succ l : mul_succ_left
|
2014-09-05 01:41:06 +00:00
|
|
|
|
... = succ (k * succ l + l) : add_succ_right)⁻¹,
|
|
|
|
|
absurd (Heq ⬝ H) succ_ne_zero))
|
2014-08-02 01:40:24 +00:00
|
|
|
|
|
|
|
|
|
---other inversion theorems appear below
|
|
|
|
|
|
|
|
|
|
-- add_rewrite mul_zero_left mul_zero_right mul_one_right mul_one_left
|
|
|
|
|
-- add_rewrite mul_succ_left mul_succ_right
|
|
|
|
|
-- add_rewrite mul_comm mul_assoc mul_left_comm
|
|
|
|
|
-- add_rewrite mul_distr_right mul_distr_left
|
2014-08-22 23:36:47 +00:00
|
|
|
|
|
2014-08-20 02:32:44 +00:00
|
|
|
|
end nat
|