2014-11-14 19:22:51 +00:00
|
|
|
|
/-
|
|
|
|
|
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
|
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
Authors: Jeremy Avigad, Leonardo de Moura
|
|
|
|
|
|
|
|
|
|
Structures with multiplicative and additive components, including semirings, rings, and fields.
|
|
|
|
|
The development is modeled after Isabelle's library.
|
|
|
|
|
-/
|
|
|
|
|
|
2014-12-12 21:20:27 +00:00
|
|
|
|
import logic.eq logic.connectives data.unit data.sigma data.prod
|
2015-07-06 14:29:56 +00:00
|
|
|
|
import algebra.binary algebra.group
|
2014-11-14 19:22:51 +00:00
|
|
|
|
open eq eq.ops
|
|
|
|
|
|
|
|
|
|
namespace algebra
|
|
|
|
|
|
|
|
|
|
variable {A : Type}
|
|
|
|
|
|
|
|
|
|
/- auxiliary classes -/
|
|
|
|
|
|
|
|
|
|
structure distrib [class] (A : Type) extends has_mul A, has_add A :=
|
2014-11-30 13:31:34 +00:00
|
|
|
|
(left_distrib : ∀a b c, mul a (add b c) = add (mul a b) (mul a c))
|
|
|
|
|
(right_distrib : ∀a b c, mul (add a b) c = add (mul a c) (mul b c))
|
2014-11-14 19:22:51 +00:00
|
|
|
|
|
2014-11-30 13:31:34 +00:00
|
|
|
|
theorem left_distrib [s : distrib A] (a b c : A) : a * (b + c) = a * b + a * c :=
|
|
|
|
|
!distrib.left_distrib
|
|
|
|
|
|
|
|
|
|
theorem right_distrib [s: distrib A] (a b c : A) : (a + b) * c = a * c + b * c :=
|
|
|
|
|
!distrib.right_distrib
|
2014-11-14 19:22:51 +00:00
|
|
|
|
|
2014-12-23 22:34:16 +00:00
|
|
|
|
structure mul_zero_class [class] (A : Type) extends has_mul A, has_zero A :=
|
|
|
|
|
(zero_mul : ∀a, mul zero a = zero)
|
|
|
|
|
(mul_zero : ∀a, mul a zero = zero)
|
2014-11-14 19:22:51 +00:00
|
|
|
|
|
2014-12-23 22:34:16 +00:00
|
|
|
|
theorem zero_mul [s : mul_zero_class A] (a : A) : 0 * a = 0 := !mul_zero_class.zero_mul
|
|
|
|
|
theorem mul_zero [s : mul_zero_class A] (a : A) : a * 0 = 0 := !mul_zero_class.mul_zero
|
2014-11-14 19:22:51 +00:00
|
|
|
|
|
|
|
|
|
structure zero_ne_one_class [class] (A : Type) extends has_zero A, has_one A :=
|
|
|
|
|
(zero_ne_one : zero ≠ one)
|
|
|
|
|
|
2015-05-18 22:45:23 +00:00
|
|
|
|
theorem zero_ne_one [s: zero_ne_one_class A] : 0 ≠ (1:A) := @zero_ne_one_class.zero_ne_one A s
|
2014-11-14 19:22:51 +00:00
|
|
|
|
|
|
|
|
|
/- semiring -/
|
2014-12-12 23:22:19 +00:00
|
|
|
|
|
2014-12-23 22:34:16 +00:00
|
|
|
|
structure semiring [class] (A : Type) extends add_comm_monoid A, monoid A, distrib A,
|
2015-03-25 21:08:36 +00:00
|
|
|
|
mul_zero_class A
|
2014-11-14 19:22:51 +00:00
|
|
|
|
|
2014-12-22 19:21:22 +00:00
|
|
|
|
section semiring
|
|
|
|
|
variables [s : semiring A] (a b c : A)
|
|
|
|
|
include s
|
|
|
|
|
|
|
|
|
|
theorem ne_zero_of_mul_ne_zero_right {a b : A} (H : a * b ≠ 0) : a ≠ 0 :=
|
2015-07-21 16:10:56 +00:00
|
|
|
|
suppose a = 0,
|
|
|
|
|
have a * b = 0, from this⁻¹ ▸ zero_mul b,
|
|
|
|
|
H this
|
2014-12-22 19:21:22 +00:00
|
|
|
|
|
|
|
|
|
theorem ne_zero_of_mul_ne_zero_left {a b : A} (H : a * b ≠ 0) : b ≠ 0 :=
|
2015-07-21 16:10:56 +00:00
|
|
|
|
suppose b = 0,
|
|
|
|
|
have a * b = 0, from this⁻¹ ▸ mul_zero a,
|
|
|
|
|
H this
|
2015-06-16 06:54:23 +00:00
|
|
|
|
|
|
|
|
|
theorem distrib_three_right (a b c d : A) : (a + b + c) * d = a * d + b * d + c * d :=
|
|
|
|
|
by rewrite *right_distrib
|
2014-12-22 19:21:22 +00:00
|
|
|
|
end semiring
|
|
|
|
|
|
|
|
|
|
/- comm semiring -/
|
|
|
|
|
|
2015-05-16 12:26:59 +00:00
|
|
|
|
structure comm_semiring [class] (A : Type) extends semiring A, comm_monoid A
|
2014-12-26 21:25:05 +00:00
|
|
|
|
-- TODO: we could also define a cancelative comm_semiring, i.e. satisfying
|
|
|
|
|
-- c ≠ 0 → c * a = c * b → a = b.
|
2014-12-12 23:22:19 +00:00
|
|
|
|
|
2014-12-22 17:21:53 +00:00
|
|
|
|
section comm_semiring
|
|
|
|
|
variables [s : comm_semiring A] (a b c : A)
|
|
|
|
|
include s
|
2014-11-14 19:22:51 +00:00
|
|
|
|
|
2015-02-01 02:53:47 +00:00
|
|
|
|
definition dvd (a b : A) : Prop := ∃c, b = a * c
|
2015-07-01 00:34:35 +00:00
|
|
|
|
notation [priority algebra.prio] a ∣ b := dvd a b
|
2014-11-14 19:22:51 +00:00
|
|
|
|
|
2015-04-06 16:24:09 +00:00
|
|
|
|
theorem dvd.intro {a b c : A} (H : a * c = b) : a ∣ b :=
|
2015-02-01 02:53:47 +00:00
|
|
|
|
exists.intro _ H⁻¹
|
2014-11-14 19:22:51 +00:00
|
|
|
|
|
2015-08-10 01:23:44 +00:00
|
|
|
|
theorem dvd_of_mul_right_eq {a b c : A} (H : a * c = b) : a ∣ b := dvd.intro H
|
|
|
|
|
|
2015-04-06 16:24:09 +00:00
|
|
|
|
theorem dvd.intro_left {a b c : A} (H : c * a = b) : a ∣ b :=
|
2014-12-26 21:25:05 +00:00
|
|
|
|
dvd.intro (!mul.comm ▸ H)
|
|
|
|
|
|
2015-08-10 01:23:44 +00:00
|
|
|
|
theorem dvd_of_mul_left_eq {a b c : A} (H : c * a = b) : a ∣ b := dvd.intro_left H
|
|
|
|
|
|
2015-04-06 16:24:09 +00:00
|
|
|
|
theorem exists_eq_mul_right_of_dvd {a b : A} (H : a ∣ b) : ∃c, b = a * c := H
|
2014-11-14 19:22:51 +00:00
|
|
|
|
|
2015-04-06 16:24:09 +00:00
|
|
|
|
theorem dvd.elim {P : Prop} {a b : A} (H₁ : a ∣ b) (H₂ : ∀c, b = a * c → P) : P :=
|
2014-12-22 17:21:53 +00:00
|
|
|
|
exists.elim H₁ H₂
|
2014-11-14 19:22:51 +00:00
|
|
|
|
|
2015-04-06 16:24:09 +00:00
|
|
|
|
theorem exists_eq_mul_left_of_dvd {a b : A} (H : a ∣ b) : ∃c, b = c * a :=
|
2015-02-01 02:53:47 +00:00
|
|
|
|
dvd.elim H (take c, assume H1 : b = a * c, exists.intro c (H1 ⬝ !mul.comm))
|
|
|
|
|
|
2015-04-06 16:24:09 +00:00
|
|
|
|
theorem dvd.elim_left {P : Prop} {a b : A} (H₁ : a ∣ b) (H₂ : ∀c, b = c * a → P) : P :=
|
2015-02-01 02:53:47 +00:00
|
|
|
|
exists.elim (exists_eq_mul_left_of_dvd H₁) (take c, assume H₃ : b = c * a, H₂ c H₃)
|
|
|
|
|
|
2015-04-06 16:24:09 +00:00
|
|
|
|
theorem dvd.refl : a ∣ a := dvd.intro !mul_one
|
2014-11-14 19:22:51 +00:00
|
|
|
|
|
2015-04-06 16:24:09 +00:00
|
|
|
|
theorem dvd.trans {a b c : A} (H₁ : a ∣ b) (H₂ : b ∣ c) : a ∣ c :=
|
2014-11-30 13:31:34 +00:00
|
|
|
|
dvd.elim H₁
|
2015-02-01 02:53:47 +00:00
|
|
|
|
(take d, assume H₃ : b = a * d,
|
2014-11-30 13:31:34 +00:00
|
|
|
|
dvd.elim H₂
|
2015-02-01 02:53:47 +00:00
|
|
|
|
(take e, assume H₄ : c = b * e,
|
|
|
|
|
dvd.intro
|
2015-03-28 00:26:06 +00:00
|
|
|
|
(show a * (d * e) = c, by rewrite [-mul.assoc, -H₃, H₄])))
|
2014-11-14 19:22:51 +00:00
|
|
|
|
|
2015-04-06 16:24:09 +00:00
|
|
|
|
theorem eq_zero_of_zero_dvd {a : A} (H : 0 ∣ a) : a = 0 :=
|
2015-02-01 02:53:47 +00:00
|
|
|
|
dvd.elim H (take c, assume H' : a = 0 * c, H' ⬝ !zero_mul)
|
2014-11-14 19:22:51 +00:00
|
|
|
|
|
2015-04-06 16:24:09 +00:00
|
|
|
|
theorem dvd_zero : a ∣ 0 := dvd.intro !mul_zero
|
2014-11-14 19:22:51 +00:00
|
|
|
|
|
2015-04-06 16:24:09 +00:00
|
|
|
|
theorem one_dvd : 1 ∣ a := dvd.intro !one_mul
|
2014-11-14 19:22:51 +00:00
|
|
|
|
|
2015-04-06 16:24:09 +00:00
|
|
|
|
theorem dvd_mul_right : a ∣ a * b := dvd.intro rfl
|
2014-11-14 19:22:51 +00:00
|
|
|
|
|
2015-04-06 16:24:09 +00:00
|
|
|
|
theorem dvd_mul_left : a ∣ b * a := mul.comm a b ▸ dvd_mul_right a b
|
2014-11-14 19:22:51 +00:00
|
|
|
|
|
2015-04-06 16:24:09 +00:00
|
|
|
|
theorem dvd_mul_of_dvd_left {a b : A} (H : a ∣ b) (c : A) : a ∣ b * c :=
|
2014-11-30 13:31:34 +00:00
|
|
|
|
dvd.elim H
|
2014-11-14 19:22:51 +00:00
|
|
|
|
(take d,
|
2015-07-21 16:10:56 +00:00
|
|
|
|
suppose b = a * d,
|
2014-11-30 13:31:34 +00:00
|
|
|
|
dvd.intro
|
2015-07-21 16:10:56 +00:00
|
|
|
|
(show a * (d * c) = b * c, from by rewrite [-mul.assoc]; substvars))
|
2014-11-14 19:22:51 +00:00
|
|
|
|
|
2015-04-06 16:24:09 +00:00
|
|
|
|
theorem dvd_mul_of_dvd_right {a b : A} (H : a ∣ b) (c : A) : a ∣ c * b :=
|
2014-11-30 13:31:34 +00:00
|
|
|
|
!mul.comm ▸ (dvd_mul_of_dvd_left H _)
|
2014-11-14 19:22:51 +00:00
|
|
|
|
|
2015-05-30 12:09:34 +00:00
|
|
|
|
theorem mul_dvd_mul {a b c d : A} (dvd_ab : a ∣ b) (dvd_cd : c ∣ d) : a * c ∣ b * d :=
|
2014-11-30 13:31:34 +00:00
|
|
|
|
dvd.elim dvd_ab
|
2015-07-21 16:10:56 +00:00
|
|
|
|
(take e, suppose b = a * e,
|
2014-11-30 13:31:34 +00:00
|
|
|
|
dvd.elim dvd_cd
|
2015-07-21 16:10:56 +00:00
|
|
|
|
(take f, suppose d = c * f,
|
2014-11-30 13:31:34 +00:00
|
|
|
|
dvd.intro
|
2015-02-06 02:48:02 +00:00
|
|
|
|
(show a * c * (e * f) = b * d,
|
2015-07-21 16:10:56 +00:00
|
|
|
|
by rewrite [mul.assoc, {c*_}mul.left_comm, -mul.assoc]; substvars)))
|
2014-11-14 19:22:51 +00:00
|
|
|
|
|
2015-04-06 16:24:09 +00:00
|
|
|
|
theorem dvd_of_mul_right_dvd {a b c : A} (H : a * b ∣ c) : a ∣ c :=
|
2015-02-01 02:53:47 +00:00
|
|
|
|
dvd.elim H (take d, assume Habdc : c = a * b * d, dvd.intro (!mul.assoc⁻¹ ⬝ Habdc⁻¹))
|
2014-11-14 19:22:51 +00:00
|
|
|
|
|
2015-04-06 16:24:09 +00:00
|
|
|
|
theorem dvd_of_mul_left_dvd {a b c : A} (H : a * b ∣ c) : b ∣ c :=
|
2014-11-30 13:31:34 +00:00
|
|
|
|
dvd_of_mul_right_dvd (mul.comm a b ▸ H)
|
2014-11-14 19:22:51 +00:00
|
|
|
|
|
2015-04-06 16:24:09 +00:00
|
|
|
|
theorem dvd_add {a b c : A} (Hab : a ∣ b) (Hac : a ∣ c) : a ∣ b + c :=
|
2014-11-30 13:31:34 +00:00
|
|
|
|
dvd.elim Hab
|
2015-07-21 16:10:56 +00:00
|
|
|
|
(take d, suppose b = a * d,
|
2014-11-30 13:31:34 +00:00
|
|
|
|
dvd.elim Hac
|
2015-07-21 16:10:56 +00:00
|
|
|
|
(take e, suppose c = a * e,
|
2015-02-06 02:48:02 +00:00
|
|
|
|
dvd.intro (show a * (d + e) = b + c,
|
2015-07-21 16:10:56 +00:00
|
|
|
|
by rewrite [left_distrib]; substvars)))
|
2014-12-22 17:21:53 +00:00
|
|
|
|
end comm_semiring
|
2014-11-14 19:22:51 +00:00
|
|
|
|
|
|
|
|
|
/- ring -/
|
|
|
|
|
|
2015-03-25 21:08:36 +00:00
|
|
|
|
structure ring [class] (A : Type) extends add_comm_group A, monoid A, distrib A
|
2014-11-14 19:22:51 +00:00
|
|
|
|
|
2015-01-19 21:00:24 +00:00
|
|
|
|
theorem ring.mul_zero [s : ring A] (a : A) : a * 0 = 0 :=
|
2015-07-21 16:10:56 +00:00
|
|
|
|
have a * 0 + 0 = a * 0 + a * 0, from calc
|
2015-02-09 01:35:01 +00:00
|
|
|
|
a * 0 + 0 = a * 0 : by rewrite add_zero
|
|
|
|
|
... = a * (0 + 0) : by rewrite add_zero
|
|
|
|
|
... = a * 0 + a * 0 : by rewrite {a*_}ring.left_distrib,
|
2015-07-21 16:10:56 +00:00
|
|
|
|
show a * 0 = 0, from (add.left_cancel this)⁻¹
|
2015-01-19 21:00:24 +00:00
|
|
|
|
|
|
|
|
|
theorem ring.zero_mul [s : ring A] (a : A) : 0 * a = 0 :=
|
2015-07-21 16:10:56 +00:00
|
|
|
|
have 0 * a + 0 = 0 * a + 0 * a, from calc
|
2015-02-09 01:35:01 +00:00
|
|
|
|
0 * a + 0 = 0 * a : by rewrite add_zero
|
|
|
|
|
... = (0 + 0) * a : by rewrite add_zero
|
|
|
|
|
... = 0 * a + 0 * a : by rewrite {_*a}ring.right_distrib,
|
2015-07-21 16:10:56 +00:00
|
|
|
|
show 0 * a = 0, from (add.left_cancel this)⁻¹
|
2015-01-19 21:00:24 +00:00
|
|
|
|
|
2015-06-21 19:36:43 +00:00
|
|
|
|
definition ring.to_semiring [trans-instance] [coercion] [reducible] [s : ring A] : semiring A :=
|
2015-01-17 17:38:10 +00:00
|
|
|
|
⦃ semiring, s,
|
2015-01-19 21:00:24 +00:00
|
|
|
|
mul_zero := ring.mul_zero,
|
|
|
|
|
zero_mul := ring.zero_mul ⦄
|
2014-11-14 19:22:51 +00:00
|
|
|
|
|
|
|
|
|
section
|
2014-11-17 20:19:46 +00:00
|
|
|
|
variables [s : ring A] (a b c d e : A)
|
2014-11-14 19:22:51 +00:00
|
|
|
|
include s
|
|
|
|
|
|
2014-11-30 13:31:34 +00:00
|
|
|
|
theorem neg_mul_eq_neg_mul : -(a * b) = -a * b :=
|
|
|
|
|
neg_eq_of_add_eq_zero
|
2015-02-09 01:35:01 +00:00
|
|
|
|
begin
|
|
|
|
|
rewrite [-right_distrib, add.right_inv, zero_mul]
|
|
|
|
|
end
|
2014-11-14 19:22:51 +00:00
|
|
|
|
|
2014-11-30 13:31:34 +00:00
|
|
|
|
theorem neg_mul_eq_mul_neg : -(a * b) = a * -b :=
|
2015-01-21 20:50:42 +00:00
|
|
|
|
neg_eq_of_add_eq_zero
|
2015-02-09 01:35:01 +00:00
|
|
|
|
begin
|
|
|
|
|
rewrite [-left_distrib, add.right_inv, mul_zero]
|
|
|
|
|
end
|
2014-11-14 19:22:51 +00:00
|
|
|
|
|
2015-01-21 20:50:42 +00:00
|
|
|
|
theorem neg_mul_neg : -a * -b = a * b :=
|
2014-11-14 19:22:51 +00:00
|
|
|
|
calc
|
2015-02-09 01:35:01 +00:00
|
|
|
|
-a * -b = -(a * -b) : by rewrite -neg_mul_eq_neg_mul
|
|
|
|
|
... = - -(a * b) : by rewrite -neg_mul_eq_mul_neg
|
|
|
|
|
... = a * b : by rewrite neg_neg
|
2014-11-14 19:22:51 +00:00
|
|
|
|
|
2014-11-30 13:31:34 +00:00
|
|
|
|
theorem neg_mul_comm : -a * b = a * -b := !neg_mul_eq_neg_mul⁻¹ ⬝ !neg_mul_eq_mul_neg
|
2014-11-17 20:19:46 +00:00
|
|
|
|
|
2015-01-21 20:50:42 +00:00
|
|
|
|
theorem neg_eq_neg_one_mul : -a = -1 * a :=
|
|
|
|
|
calc
|
2015-02-09 01:35:01 +00:00
|
|
|
|
-a = -(1 * a) : by rewrite one_mul
|
|
|
|
|
... = -1 * a : by rewrite neg_mul_eq_neg_mul
|
2015-01-21 20:50:42 +00:00
|
|
|
|
|
2014-11-30 13:31:34 +00:00
|
|
|
|
theorem mul_sub_left_distrib : a * (b - c) = a * b - a * c :=
|
2014-11-17 20:19:46 +00:00
|
|
|
|
calc
|
2014-11-30 13:31:34 +00:00
|
|
|
|
a * (b - c) = a * b + a * -c : left_distrib
|
2015-02-09 01:35:01 +00:00
|
|
|
|
... = a * b + - (a * c) : by rewrite -neg_mul_eq_mul_neg
|
|
|
|
|
... = a * b - a * c : rfl
|
2014-11-17 20:19:46 +00:00
|
|
|
|
|
2014-11-30 13:31:34 +00:00
|
|
|
|
theorem mul_sub_right_distrib : (a - b) * c = a * c - b * c :=
|
2014-11-17 20:19:46 +00:00
|
|
|
|
calc
|
2014-11-30 13:31:34 +00:00
|
|
|
|
(a - b) * c = a * c + -b * c : right_distrib
|
2015-02-09 01:35:01 +00:00
|
|
|
|
... = a * c + - (b * c) : by rewrite neg_mul_eq_neg_mul
|
|
|
|
|
... = a * c - b * c : rfl
|
2014-11-17 20:19:46 +00:00
|
|
|
|
|
|
|
|
|
-- TODO: can calc mode be improved to make this easier?
|
|
|
|
|
-- TODO: there is also the other direction. It will be easier when we
|
|
|
|
|
-- have the simplifier.
|
2014-11-30 13:31:34 +00:00
|
|
|
|
|
|
|
|
|
theorem mul_add_eq_mul_add_iff_sub_mul_add_eq : a * e + c = b * e + d ↔ (a - b) * e + c = d :=
|
2014-11-17 20:19:46 +00:00
|
|
|
|
calc
|
2015-02-09 01:35:01 +00:00
|
|
|
|
a * e + c = b * e + d ↔ a * e + c = d + b * e : by rewrite {b*e+_}add.comm
|
2014-11-30 13:31:34 +00:00
|
|
|
|
... ↔ a * e + c - b * e = d : iff.symm !sub_eq_iff_eq_add
|
2015-02-09 01:35:01 +00:00
|
|
|
|
... ↔ a * e - b * e + c = d : by rewrite sub_add_eq_add_sub
|
|
|
|
|
... ↔ (a - b) * e + c = d : by rewrite mul_sub_right_distrib
|
2015-03-27 17:11:23 +00:00
|
|
|
|
|
2015-08-05 21:03:46 +00:00
|
|
|
|
theorem mul_add_eq_mul_add_of_sub_mul_add_eq : (a - b) * e + c = d → a * e + c = b * e + d :=
|
|
|
|
|
iff.mpr !mul_add_eq_mul_add_iff_sub_mul_add_eq
|
|
|
|
|
|
|
|
|
|
theorem sub_mul_add_eq_of_mul_add_eq_mul_add : a * e + c = b * e + d → (a - b) * e + c = d :=
|
|
|
|
|
iff.mp !mul_add_eq_mul_add_iff_sub_mul_add_eq
|
|
|
|
|
|
2015-03-27 17:11:23 +00:00
|
|
|
|
theorem mul_neg_one_eq_neg : a * (-1) = -a :=
|
2015-07-21 16:10:56 +00:00
|
|
|
|
have a + a * -1 = 0, from calc
|
2015-03-27 17:11:23 +00:00
|
|
|
|
a + a * -1 = a * 1 + a * -1 : mul_one
|
|
|
|
|
... = a * (1 + -1) : left_distrib
|
|
|
|
|
... = a * 0 : add.right_inv
|
|
|
|
|
... = 0 : mul_zero,
|
2015-07-21 16:10:56 +00:00
|
|
|
|
symm (neg_eq_of_add_eq_zero this)
|
2015-03-27 17:11:23 +00:00
|
|
|
|
|
2015-05-23 04:05:06 +00:00
|
|
|
|
theorem ne_zero_and_ne_zero_of_mul_ne_zero {a b : A} (H : a * b ≠ 0) : a ≠ 0 ∧ b ≠ 0 :=
|
2015-07-21 16:10:56 +00:00
|
|
|
|
have a ≠ 0, from
|
|
|
|
|
(suppose a = 0,
|
|
|
|
|
have a * b = 0, by rewrite [this, zero_mul],
|
|
|
|
|
absurd this H),
|
|
|
|
|
have b ≠ 0, from
|
|
|
|
|
(suppose b = 0,
|
|
|
|
|
have a * b = 0, by rewrite [this, mul_zero],
|
|
|
|
|
absurd this H),
|
|
|
|
|
and.intro `a ≠ 0` `b ≠ 0`
|
2014-11-14 19:22:51 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
structure comm_ring [class] (A : Type) extends ring A, comm_semigroup A
|
|
|
|
|
|
2015-06-21 19:36:43 +00:00
|
|
|
|
definition comm_ring.to_comm_semiring [trans-instance] [coercion] [reducible] [s : comm_ring A] : comm_semiring A :=
|
2015-01-17 17:38:10 +00:00
|
|
|
|
⦃ comm_semiring, s,
|
2015-01-17 01:42:30 +00:00
|
|
|
|
mul_zero := mul_zero,
|
2015-01-17 17:38:10 +00:00
|
|
|
|
zero_mul := zero_mul ⦄
|
2014-11-17 20:19:46 +00:00
|
|
|
|
|
|
|
|
|
section
|
|
|
|
|
variables [s : comm_ring A] (a b c d e : A)
|
|
|
|
|
include s
|
|
|
|
|
|
2015-03-30 18:55:16 +00:00
|
|
|
|
theorem mul_self_sub_mul_self_eq : a * a - b * b = (a + b) * (a - b) :=
|
2015-06-22 22:31:03 +00:00
|
|
|
|
begin
|
|
|
|
|
krewrite [left_distrib, *right_distrib, add.assoc],
|
|
|
|
|
rewrite [-{b*a + _}add.assoc,
|
|
|
|
|
-*neg_mul_eq_mul_neg, {a*b}mul.comm, add.right_inv, zero_add]
|
|
|
|
|
end
|
2014-11-17 20:19:46 +00:00
|
|
|
|
|
2014-11-30 13:31:34 +00:00
|
|
|
|
theorem mul_self_sub_one_eq : a * a - 1 = (a + 1) * (a - 1) :=
|
2015-06-22 22:31:03 +00:00
|
|
|
|
by rewrite [-mul_self_sub_mul_self_eq, mul_one]
|
2014-11-17 20:19:46 +00:00
|
|
|
|
|
2015-04-06 16:24:09 +00:00
|
|
|
|
theorem dvd_neg_iff_dvd : (a ∣ -b) ↔ (a ∣ b) :=
|
2014-11-17 20:19:46 +00:00
|
|
|
|
iff.intro
|
2015-07-21 16:10:56 +00:00
|
|
|
|
(suppose a ∣ -b,
|
|
|
|
|
dvd.elim this
|
|
|
|
|
(take c, suppose -b = a * c,
|
2014-11-30 13:31:34 +00:00
|
|
|
|
dvd.intro
|
2015-02-09 01:35:01 +00:00
|
|
|
|
(show a * -c = b,
|
2015-07-21 16:10:56 +00:00
|
|
|
|
by rewrite [-neg_mul_eq_mul_neg, -this, neg_neg])))
|
|
|
|
|
(suppose a ∣ b,
|
|
|
|
|
dvd.elim this
|
|
|
|
|
(take c, suppose b = a * c,
|
2014-11-30 13:31:34 +00:00
|
|
|
|
dvd.intro
|
2015-02-09 01:35:01 +00:00
|
|
|
|
(show a * -c = -b,
|
2015-07-21 16:10:56 +00:00
|
|
|
|
by rewrite [-neg_mul_eq_mul_neg, -this])))
|
2014-11-17 20:19:46 +00:00
|
|
|
|
|
2015-08-05 21:03:46 +00:00
|
|
|
|
theorem dvd_neg_of_dvd : (a ∣ b) → (a ∣ -b) :=
|
|
|
|
|
iff.mpr !dvd_neg_iff_dvd
|
|
|
|
|
|
|
|
|
|
theorem dvd_of_dvd_neg : (a ∣ -b) → (a ∣ b) :=
|
|
|
|
|
iff.mp !dvd_neg_iff_dvd
|
|
|
|
|
|
2015-04-06 16:24:09 +00:00
|
|
|
|
theorem neg_dvd_iff_dvd : (-a ∣ b) ↔ (a ∣ b) :=
|
2014-11-17 20:19:46 +00:00
|
|
|
|
iff.intro
|
2015-07-21 16:10:56 +00:00
|
|
|
|
(suppose -a ∣ b,
|
|
|
|
|
dvd.elim this
|
|
|
|
|
(take c, suppose b = -a * c,
|
2014-11-30 13:31:34 +00:00
|
|
|
|
dvd.intro
|
2015-07-21 16:10:56 +00:00
|
|
|
|
(show a * -c = b, by rewrite [-neg_mul_comm, this])))
|
|
|
|
|
(suppose a ∣ b,
|
|
|
|
|
dvd.elim this
|
|
|
|
|
(take c, suppose b = a * c,
|
2014-11-30 13:31:34 +00:00
|
|
|
|
dvd.intro
|
2015-07-21 16:10:56 +00:00
|
|
|
|
(show -a * -c = b, by rewrite [neg_mul_neg, this])))
|
2014-11-17 20:19:46 +00:00
|
|
|
|
|
2015-08-05 21:03:46 +00:00
|
|
|
|
theorem neg_dvd_of_dvd : (a ∣ b) → (-a ∣ b) :=
|
|
|
|
|
iff.mpr !neg_dvd_iff_dvd
|
|
|
|
|
|
|
|
|
|
theorem dvd_of_neg_dvd : (-a ∣ b) → (a ∣ b) :=
|
|
|
|
|
iff.mp !neg_dvd_iff_dvd
|
|
|
|
|
|
2015-04-06 16:24:09 +00:00
|
|
|
|
theorem dvd_sub (H₁ : (a ∣ b)) (H₂ : (a ∣ c)) : (a ∣ b - c) :=
|
2015-08-05 21:03:46 +00:00
|
|
|
|
dvd_add H₁ (!dvd_neg_of_dvd H₂)
|
2014-11-17 20:19:46 +00:00
|
|
|
|
end
|
|
|
|
|
|
2014-11-26 23:08:23 +00:00
|
|
|
|
/- integral domains -/
|
|
|
|
|
|
|
|
|
|
structure no_zero_divisors [class] (A : Type) extends has_mul A, has_zero A :=
|
|
|
|
|
(eq_zero_or_eq_zero_of_mul_eq_zero : ∀a b, mul a b = zero → a = zero ∨ b = zero)
|
|
|
|
|
|
2014-11-30 13:31:34 +00:00
|
|
|
|
theorem eq_zero_or_eq_zero_of_mul_eq_zero {A : Type} [s : no_zero_divisors A] {a b : A}
|
|
|
|
|
(H : a * b = 0) :
|
2014-11-26 23:08:23 +00:00
|
|
|
|
a = 0 ∨ b = 0 := !no_zero_divisors.eq_zero_or_eq_zero_of_mul_eq_zero H
|
|
|
|
|
|
2015-08-17 03:23:03 +00:00
|
|
|
|
structure integral_domain [class] (A : Type) extends comm_ring A, no_zero_divisors A,
|
|
|
|
|
zero_ne_one_class A
|
2014-11-26 23:08:23 +00:00
|
|
|
|
|
|
|
|
|
section
|
|
|
|
|
variables [s : integral_domain A] (a b c d e : A)
|
|
|
|
|
include s
|
|
|
|
|
|
2014-12-22 19:21:22 +00:00
|
|
|
|
theorem mul_ne_zero {a b : A} (H1 : a ≠ 0) (H2 : b ≠ 0) : a * b ≠ 0 :=
|
2015-07-21 16:10:56 +00:00
|
|
|
|
suppose a * b = 0,
|
|
|
|
|
or.elim (eq_zero_or_eq_zero_of_mul_eq_zero this) (assume H3, H1 H3) (assume H4, H2 H4)
|
2014-11-26 23:08:23 +00:00
|
|
|
|
|
2015-06-01 01:39:59 +00:00
|
|
|
|
theorem eq_of_mul_eq_mul_right {a b c : A} (Ha : a ≠ 0) (H : b * a = c * a) : b = c :=
|
2015-07-21 16:10:56 +00:00
|
|
|
|
have b * a - c * a = 0, from iff.mp !eq_iff_sub_eq_zero H,
|
|
|
|
|
have (b - c) * a = 0, using this, by rewrite [mul_sub_right_distrib, this],
|
|
|
|
|
have b - c = 0, from or_resolve_left (eq_zero_or_eq_zero_of_mul_eq_zero this) Ha,
|
|
|
|
|
iff.elim_right !eq_iff_sub_eq_zero this
|
2014-11-26 23:08:23 +00:00
|
|
|
|
|
2015-06-01 01:39:59 +00:00
|
|
|
|
theorem eq_of_mul_eq_mul_left {a b c : A} (Ha : a ≠ 0) (H : a * b = a * c) : b = c :=
|
2015-07-21 16:10:56 +00:00
|
|
|
|
have a * b - a * c = 0, from iff.mp !eq_iff_sub_eq_zero H,
|
|
|
|
|
have a * (b - c) = 0, using this, by rewrite [mul_sub_left_distrib, this],
|
|
|
|
|
have b - c = 0, from or_resolve_right (eq_zero_or_eq_zero_of_mul_eq_zero this) Ha,
|
|
|
|
|
iff.elim_right !eq_iff_sub_eq_zero this
|
2014-11-26 23:08:23 +00:00
|
|
|
|
|
|
|
|
|
-- TODO: do we want the iff versions?
|
|
|
|
|
|
2015-03-30 18:55:16 +00:00
|
|
|
|
theorem mul_self_eq_mul_self_iff (a b : A) : a * a = b * b ↔ a = b ∨ a = -b :=
|
|
|
|
|
iff.intro
|
2015-07-21 16:10:56 +00:00
|
|
|
|
(suppose a * a = b * b,
|
|
|
|
|
have (a - b) * (a + b) = 0,
|
|
|
|
|
by rewrite [mul.comm, -mul_self_sub_mul_self_eq, this, sub_self],
|
|
|
|
|
assert a - b = 0 ∨ a + b = 0, from !eq_zero_or_eq_zero_of_mul_eq_zero this,
|
|
|
|
|
or.elim this
|
|
|
|
|
(suppose a - b = 0, or.inl (eq_of_sub_eq_zero this))
|
|
|
|
|
(suppose a + b = 0, or.inr (eq_neg_of_add_eq_zero this)))
|
|
|
|
|
(suppose a = b ∨ a = -b, or.elim this
|
|
|
|
|
(suppose a = b, by rewrite this)
|
|
|
|
|
(suppose a = -b, by rewrite [this, neg_mul_neg]))
|
2015-03-30 18:55:16 +00:00
|
|
|
|
|
|
|
|
|
theorem mul_self_eq_one_iff (a : A) : a * a = 1 ↔ a = 1 ∨ a = -1 :=
|
2015-07-21 16:10:56 +00:00
|
|
|
|
assert a * a = 1 * 1 ↔ a = 1 ∨ a = -1, from mul_self_eq_mul_self_iff a 1,
|
|
|
|
|
by rewrite mul_one at this; exact this
|
2014-11-26 23:08:23 +00:00
|
|
|
|
|
|
|
|
|
-- TODO: c - b * c → c = 0 ∨ b = 1 and variants
|
|
|
|
|
|
2015-04-06 16:24:09 +00:00
|
|
|
|
theorem dvd_of_mul_dvd_mul_left {a b c : A} (Ha : a ≠ 0) (Hdvd : (a * b ∣ a * c)) : (b ∣ c) :=
|
2014-11-30 13:31:34 +00:00
|
|
|
|
dvd.elim Hdvd
|
2014-11-26 23:08:23 +00:00
|
|
|
|
(take d,
|
2015-07-21 16:10:56 +00:00
|
|
|
|
suppose a * c = a * b * d,
|
|
|
|
|
have b * d = c, from eq_of_mul_eq_mul_left Ha (mul.assoc a b d ▸ this⁻¹),
|
|
|
|
|
dvd.intro this)
|
2014-11-26 23:08:23 +00:00
|
|
|
|
|
2015-04-06 16:24:09 +00:00
|
|
|
|
theorem dvd_of_mul_dvd_mul_right {a b c : A} (Ha : a ≠ 0) (Hdvd : (b * a ∣ c * a)) : (b ∣ c) :=
|
2014-11-30 13:31:34 +00:00
|
|
|
|
dvd.elim Hdvd
|
2014-11-26 23:08:23 +00:00
|
|
|
|
(take d,
|
2015-07-21 16:10:56 +00:00
|
|
|
|
suppose c * a = b * a * d,
|
|
|
|
|
have b * d * a = c * a, from by rewrite [mul.right_comm, -this],
|
|
|
|
|
have b * d = c, from eq_of_mul_eq_mul_right Ha this,
|
|
|
|
|
dvd.intro this)
|
2014-11-26 23:08:23 +00:00
|
|
|
|
end
|
2014-11-17 20:19:46 +00:00
|
|
|
|
|
2014-11-14 19:22:51 +00:00
|
|
|
|
end algebra
|