2014-11-07 02:30:46 +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
|
|
|
|
|
2014-11-13 00:46:41 +00:00
|
|
|
Various multiplicative and additive structures. Partially modeled on Isabelle's library.
|
2014-11-07 02:30:46 +00:00
|
|
|
-/
|
|
|
|
|
2014-12-01 04:34:12 +00:00
|
|
|
import logic.eq data.unit data.sigma data.prod
|
2015-07-01 00:34:35 +00:00
|
|
|
import algebra.function algebra.binary algebra.priority
|
2014-11-07 02:30:46 +00:00
|
|
|
|
2014-11-13 00:46:41 +00:00
|
|
|
open eq eq.ops -- note: ⁻¹ will be overloaded
|
2014-11-30 13:31:34 +00:00
|
|
|
open binary
|
2014-11-07 02:30:46 +00:00
|
|
|
|
|
|
|
namespace algebra
|
|
|
|
|
2014-11-13 00:46:41 +00:00
|
|
|
variable {A : Type}
|
2014-11-07 02:30:46 +00:00
|
|
|
|
|
|
|
/- overloaded symbols -/
|
|
|
|
|
|
|
|
structure has_mul [class] (A : Type) :=
|
|
|
|
(mul : A → A → A)
|
|
|
|
|
|
|
|
structure has_add [class] (A : Type) :=
|
|
|
|
(add : A → A → A)
|
|
|
|
|
|
|
|
structure has_one [class] (A : Type) :=
|
|
|
|
(one : A)
|
|
|
|
|
|
|
|
structure has_zero [class] (A : Type) :=
|
|
|
|
(zero : A)
|
|
|
|
|
|
|
|
structure has_inv [class] (A : Type) :=
|
|
|
|
(inv : A → A)
|
|
|
|
|
|
|
|
structure has_neg [class] (A : Type) :=
|
|
|
|
(neg : A → A)
|
|
|
|
|
2015-07-01 00:34:35 +00:00
|
|
|
infixl [priority algebra.prio] `*` := has_mul.mul
|
|
|
|
infixl [priority algebra.prio] `+` := has_add.add
|
|
|
|
postfix [priority algebra.prio] `⁻¹` := has_inv.inv
|
|
|
|
prefix [priority algebra.prio] `-` := has_neg.neg
|
|
|
|
notation 1 := !has_one.one
|
|
|
|
notation 0 := !has_zero.zero
|
2014-11-07 02:30:46 +00:00
|
|
|
|
|
|
|
/- semigroup -/
|
|
|
|
|
|
|
|
structure semigroup [class] (A : Type) extends has_mul A :=
|
|
|
|
(mul_assoc : ∀a b c, mul (mul a b) c = mul a (mul b c))
|
|
|
|
|
2014-11-30 13:31:34 +00:00
|
|
|
theorem mul.assoc [s : semigroup A] (a b c : A) : a * b * c = a * (b * c) :=
|
2014-11-07 02:30:46 +00:00
|
|
|
!semigroup.mul_assoc
|
|
|
|
|
|
|
|
structure comm_semigroup [class] (A : Type) extends semigroup A :=
|
|
|
|
(mul_comm : ∀a b, mul a b = mul b a)
|
|
|
|
|
2014-11-30 13:31:34 +00:00
|
|
|
theorem mul.comm [s : comm_semigroup A] (a b : A) : a * b = b * a :=
|
2014-11-07 02:30:46 +00:00
|
|
|
!comm_semigroup.mul_comm
|
|
|
|
|
2014-11-30 13:31:34 +00:00
|
|
|
theorem mul.left_comm [s : comm_semigroup A] (a b c : A) : a * (b * c) = b * (a * c) :=
|
|
|
|
binary.left_comm (@mul.comm A s) (@mul.assoc A s) a b c
|
2014-11-07 02:30:46 +00:00
|
|
|
|
2014-11-30 13:31:34 +00:00
|
|
|
theorem mul.right_comm [s : comm_semigroup A] (a b c : A) : (a * b) * c = (a * c) * b :=
|
|
|
|
binary.right_comm (@mul.comm A s) (@mul.assoc A s) a b c
|
2014-11-07 02:30:46 +00:00
|
|
|
|
|
|
|
structure left_cancel_semigroup [class] (A : Type) extends semigroup A :=
|
|
|
|
(mul_left_cancel : ∀a b c, mul a b = mul a c → b = c)
|
|
|
|
|
2014-11-30 13:31:34 +00:00
|
|
|
theorem mul.left_cancel [s : left_cancel_semigroup A] {a b c : A} :
|
2014-11-07 02:30:46 +00:00
|
|
|
a * b = a * c → b = c :=
|
|
|
|
!left_cancel_semigroup.mul_left_cancel
|
|
|
|
|
2015-06-15 11:16:30 +00:00
|
|
|
abbreviation eq_of_mul_eq_mul_left' := @mul.left_cancel
|
|
|
|
|
2014-11-07 02:30:46 +00:00
|
|
|
structure right_cancel_semigroup [class] (A : Type) extends semigroup A :=
|
|
|
|
(mul_right_cancel : ∀a b c, mul a b = mul c b → a = c)
|
|
|
|
|
2014-11-30 13:31:34 +00:00
|
|
|
theorem mul.right_cancel [s : right_cancel_semigroup A] {a b c : A} :
|
2014-11-07 02:30:46 +00:00
|
|
|
a * b = c * b → a = c :=
|
|
|
|
!right_cancel_semigroup.mul_right_cancel
|
|
|
|
|
2015-06-15 11:16:30 +00:00
|
|
|
abbreviation eq_of_mul_eq_mul_right' := @mul.right_cancel
|
|
|
|
|
2014-11-07 02:30:46 +00:00
|
|
|
/- additive semigroup -/
|
|
|
|
|
|
|
|
structure add_semigroup [class] (A : Type) extends has_add A :=
|
|
|
|
(add_assoc : ∀a b c, add (add a b) c = add a (add b c))
|
|
|
|
|
2014-11-30 13:31:34 +00:00
|
|
|
theorem add.assoc [s : add_semigroup A] (a b c : A) : a + b + c = a + (b + c) :=
|
2014-11-07 02:30:46 +00:00
|
|
|
!add_semigroup.add_assoc
|
|
|
|
|
|
|
|
structure add_comm_semigroup [class] (A : Type) extends add_semigroup A :=
|
2014-11-14 19:22:51 +00:00
|
|
|
(add_comm : ∀a b, add a b = add b a)
|
2014-11-07 02:30:46 +00:00
|
|
|
|
2014-11-30 13:31:34 +00:00
|
|
|
theorem add.comm [s : add_comm_semigroup A] (a b : A) : a + b = b + a :=
|
2014-11-14 19:22:51 +00:00
|
|
|
!add_comm_semigroup.add_comm
|
2014-11-07 02:30:46 +00:00
|
|
|
|
2014-11-30 13:31:34 +00:00
|
|
|
theorem add.left_comm [s : add_comm_semigroup A] (a b c : A) :
|
2014-11-07 02:30:46 +00:00
|
|
|
a + (b + c) = b + (a + c) :=
|
2014-11-30 13:31:34 +00:00
|
|
|
binary.left_comm (@add.comm A s) (@add.assoc A s) a b c
|
2014-11-07 02:30:46 +00:00
|
|
|
|
2014-11-30 13:31:34 +00:00
|
|
|
theorem add.right_comm [s : add_comm_semigroup A] (a b c : A) : (a + b) + c = (a + c) + b :=
|
|
|
|
binary.right_comm (@add.comm A s) (@add.assoc A s) a b c
|
2014-11-07 02:30:46 +00:00
|
|
|
|
|
|
|
structure add_left_cancel_semigroup [class] (A : Type) extends add_semigroup A :=
|
|
|
|
(add_left_cancel : ∀a b c, add a b = add a c → b = c)
|
|
|
|
|
2014-11-30 13:31:34 +00:00
|
|
|
theorem add.left_cancel [s : add_left_cancel_semigroup A] {a b c : A} :
|
2014-11-07 02:30:46 +00:00
|
|
|
a + b = a + c → b = c :=
|
|
|
|
!add_left_cancel_semigroup.add_left_cancel
|
|
|
|
|
2015-06-15 11:16:30 +00:00
|
|
|
abbreviation eq_of_add_eq_add_left := @add.left_cancel
|
|
|
|
|
2014-11-07 02:30:46 +00:00
|
|
|
structure add_right_cancel_semigroup [class] (A : Type) extends add_semigroup A :=
|
|
|
|
(add_right_cancel : ∀a b c, add a b = add c b → a = c)
|
|
|
|
|
2014-11-30 13:31:34 +00:00
|
|
|
theorem add.right_cancel [s : add_right_cancel_semigroup A] {a b c : A} :
|
2014-11-07 02:30:46 +00:00
|
|
|
a + b = c + b → a = c :=
|
|
|
|
!add_right_cancel_semigroup.add_right_cancel
|
|
|
|
|
2015-06-15 11:16:30 +00:00
|
|
|
abbreviation eq_of_add_eq_add_right := @add.right_cancel
|
|
|
|
|
2014-11-07 02:30:46 +00:00
|
|
|
/- monoid -/
|
|
|
|
|
|
|
|
structure monoid [class] (A : Type) extends semigroup A, has_one A :=
|
2014-12-24 02:14:19 +00:00
|
|
|
(one_mul : ∀a, mul one a = a) (mul_one : ∀a, mul a one = a)
|
2014-11-07 02:30:46 +00:00
|
|
|
|
2014-12-24 02:14:19 +00:00
|
|
|
theorem one_mul [s : monoid A] (a : A) : 1 * a = a := !monoid.one_mul
|
2014-11-07 02:30:46 +00:00
|
|
|
|
2014-12-24 02:14:19 +00:00
|
|
|
theorem mul_one [s : monoid A] (a : A) : a * 1 = a := !monoid.mul_one
|
2014-11-13 00:46:41 +00:00
|
|
|
|
2014-11-07 02:30:46 +00:00
|
|
|
structure comm_monoid [class] (A : Type) extends monoid A, comm_semigroup A
|
|
|
|
|
|
|
|
/- additive monoid -/
|
|
|
|
|
|
|
|
structure add_monoid [class] (A : Type) extends add_semigroup A, has_zero A :=
|
2014-12-24 02:14:19 +00:00
|
|
|
(zero_add : ∀a, add zero a = a) (add_zero : ∀a, add a zero = a)
|
2014-11-07 02:30:46 +00:00
|
|
|
|
2014-12-24 02:14:19 +00:00
|
|
|
theorem zero_add [s : add_monoid A] (a : A) : 0 + a = a := !add_monoid.zero_add
|
2014-11-07 02:30:46 +00:00
|
|
|
|
2014-12-24 02:14:19 +00:00
|
|
|
theorem add_zero [s : add_monoid A] (a : A) : a + 0 = a := !add_monoid.add_zero
|
2014-11-13 00:46:41 +00:00
|
|
|
|
2014-11-07 02:30:46 +00:00
|
|
|
structure add_comm_monoid [class] (A : Type) extends add_monoid A, add_comm_semigroup A
|
|
|
|
|
2015-05-16 08:27:49 +00:00
|
|
|
definition add_monoid.to_monoid {A : Type} [s : add_monoid A] : monoid A :=
|
|
|
|
⦃ monoid,
|
|
|
|
mul := add_monoid.add,
|
|
|
|
mul_assoc := add_monoid.add_assoc,
|
|
|
|
one := add_monoid.zero A,
|
|
|
|
mul_one := add_monoid.add_zero,
|
|
|
|
one_mul := add_monoid.zero_add
|
|
|
|
⦄
|
|
|
|
|
|
|
|
definition add_comm_monoid.to_comm_monoid {A : Type} [s : add_comm_monoid A] : comm_monoid A :=
|
|
|
|
⦃ comm_monoid,
|
|
|
|
add_monoid.to_monoid,
|
|
|
|
mul_comm := add_comm_monoid.add_comm
|
|
|
|
⦄
|
|
|
|
|
2015-06-09 06:14:21 +00:00
|
|
|
section add_comm_monoid
|
|
|
|
|
|
|
|
theorem add_comm_three {A : Type} [s : add_comm_monoid A] (a b c : A) : a + b + c = c + b + a :=
|
|
|
|
by rewrite [{a + _}add.comm, {_ + c}add.comm, -*add.assoc]
|
|
|
|
|
|
|
|
end add_comm_monoid
|
|
|
|
|
2014-11-07 02:30:46 +00:00
|
|
|
/- group -/
|
|
|
|
|
|
|
|
structure group [class] (A : Type) extends monoid A, has_inv A :=
|
2014-11-13 00:46:41 +00:00
|
|
|
(mul_left_inv : ∀a, mul (inv a) a = one)
|
2014-11-07 02:30:46 +00:00
|
|
|
|
2014-12-24 02:14:19 +00:00
|
|
|
-- Note: with more work, we could derive the axiom one_mul
|
2014-11-07 02:30:46 +00:00
|
|
|
|
2014-11-13 00:46:41 +00:00
|
|
|
section group
|
2014-11-07 02:30:46 +00:00
|
|
|
|
2014-11-13 00:46:41 +00:00
|
|
|
variable [s : group A]
|
|
|
|
include s
|
|
|
|
|
2014-11-30 13:31:34 +00:00
|
|
|
theorem mul.left_inv (a : A) : a⁻¹ * a = 1 := !group.mul_left_inv
|
2014-11-13 00:46:41 +00:00
|
|
|
|
|
|
|
theorem inv_mul_cancel_left (a b : A) : a⁻¹ * (a * b) = b :=
|
2015-03-28 00:26:06 +00:00
|
|
|
by rewrite [-mul.assoc, mul.left_inv, one_mul]
|
2014-11-07 02:30:46 +00:00
|
|
|
|
2014-11-13 00:46:41 +00:00
|
|
|
theorem inv_mul_cancel_right (a b : A) : a * b⁻¹ * b = a :=
|
2015-03-28 00:26:06 +00:00
|
|
|
by rewrite [mul.assoc, mul.left_inv, mul_one]
|
2014-11-07 02:30:46 +00:00
|
|
|
|
2014-11-30 13:31:34 +00:00
|
|
|
theorem inv_eq_of_mul_eq_one {a b : A} (H : a * b = 1) : a⁻¹ = b :=
|
2015-03-28 00:26:06 +00:00
|
|
|
by rewrite [-mul_one a⁻¹, -H, inv_mul_cancel_left]
|
2014-11-13 00:46:41 +00:00
|
|
|
|
2015-05-23 04:05:06 +00:00
|
|
|
theorem one_inv : 1⁻¹ = (1 : A) := inv_eq_of_mul_eq_one (one_mul 1)
|
2014-11-13 00:46:41 +00:00
|
|
|
|
2014-12-17 18:32:38 +00:00
|
|
|
theorem inv_inv (a : A) : (a⁻¹)⁻¹ = a := inv_eq_of_mul_eq_one (mul.left_inv a)
|
2014-11-13 00:46:41 +00:00
|
|
|
|
2014-12-17 18:32:38 +00:00
|
|
|
theorem inv.inj {a b : A} (H : a⁻¹ = b⁻¹) : a = b :=
|
2015-03-28 00:26:06 +00:00
|
|
|
by rewrite [-inv_inv, H, inv_inv]
|
2014-11-13 00:46:41 +00:00
|
|
|
|
|
|
|
theorem inv_eq_inv_iff_eq (a b : A) : a⁻¹ = b⁻¹ ↔ a = b :=
|
2014-12-17 18:32:38 +00:00
|
|
|
iff.intro (assume H, inv.inj H) (assume H, congr_arg _ H)
|
2014-11-13 00:46:41 +00:00
|
|
|
|
|
|
|
theorem inv_eq_one_iff_eq_one (a b : A) : a⁻¹ = 1 ↔ a = 1 :=
|
2015-05-23 04:05:06 +00:00
|
|
|
one_inv ▸ inv_eq_inv_iff_eq a 1
|
2014-11-13 00:46:41 +00:00
|
|
|
|
2014-11-30 13:31:34 +00:00
|
|
|
theorem eq_inv_of_eq_inv {a b : A} (H : a = b⁻¹) : b = a⁻¹ :=
|
2015-03-06 02:46:07 +00:00
|
|
|
by rewrite [H, inv_inv]
|
2014-11-13 00:46:41 +00:00
|
|
|
|
|
|
|
theorem eq_inv_iff_eq_inv (a b : A) : a = b⁻¹ ↔ b = a⁻¹ :=
|
2014-11-30 13:31:34 +00:00
|
|
|
iff.intro !eq_inv_of_eq_inv !eq_inv_of_eq_inv
|
2014-11-13 00:46:41 +00:00
|
|
|
|
2014-11-30 13:31:34 +00:00
|
|
|
theorem mul.right_inv (a : A) : a * a⁻¹ = 1 :=
|
2014-11-13 00:46:41 +00:00
|
|
|
calc
|
2014-12-17 18:32:38 +00:00
|
|
|
a * a⁻¹ = (a⁻¹)⁻¹ * a⁻¹ : inv_inv
|
2015-03-06 02:46:07 +00:00
|
|
|
... = 1 : mul.left_inv
|
2014-11-13 00:46:41 +00:00
|
|
|
|
|
|
|
theorem mul_inv_cancel_left (a b : A) : a * (a⁻¹ * b) = b :=
|
|
|
|
calc
|
2015-03-06 02:46:07 +00:00
|
|
|
a * (a⁻¹ * b) = a * a⁻¹ * b : by rewrite mul.assoc
|
|
|
|
... = 1 * b : mul.right_inv
|
|
|
|
... = b : one_mul
|
2014-11-13 00:46:41 +00:00
|
|
|
|
|
|
|
theorem mul_inv_cancel_right (a b : A) : a * b * b⁻¹ = a :=
|
|
|
|
calc
|
2014-11-30 13:31:34 +00:00
|
|
|
a * b * b⁻¹ = a * (b * b⁻¹) : mul.assoc
|
|
|
|
... = a * 1 : mul.right_inv
|
2014-12-24 02:14:19 +00:00
|
|
|
... = a : mul_one
|
2014-11-13 00:46:41 +00:00
|
|
|
|
2015-05-23 04:05:06 +00:00
|
|
|
theorem mul_inv (a b : A) : (a * b)⁻¹ = b⁻¹ * a⁻¹ :=
|
2014-11-30 13:31:34 +00:00
|
|
|
inv_eq_of_mul_eq_one
|
2014-11-13 00:46:41 +00:00
|
|
|
(calc
|
2014-11-30 13:31:34 +00:00
|
|
|
a * b * (b⁻¹ * a⁻¹) = a * (b * (b⁻¹ * a⁻¹)) : mul.assoc
|
2015-03-06 02:46:07 +00:00
|
|
|
... = a * a⁻¹ : mul_inv_cancel_left
|
|
|
|
... = 1 : mul.right_inv)
|
2014-11-13 00:46:41 +00:00
|
|
|
|
2014-11-30 13:31:34 +00:00
|
|
|
theorem eq_of_mul_inv_eq_one {a b : A} (H : a * b⁻¹ = 1) : a = b :=
|
2014-11-13 00:46:41 +00:00
|
|
|
calc
|
2015-03-06 02:46:07 +00:00
|
|
|
a = a * b⁻¹ * b : by rewrite inv_mul_cancel_right
|
|
|
|
... = 1 * b : H
|
|
|
|
... = b : one_mul
|
2014-11-13 00:46:41 +00:00
|
|
|
|
2015-02-25 18:32:19 +00:00
|
|
|
theorem eq_mul_inv_of_mul_eq {a b c : A} (H : a * c = b) : a = b * c⁻¹ :=
|
2015-03-06 02:46:07 +00:00
|
|
|
by rewrite [-H, mul_inv_cancel_right]
|
2014-11-13 00:46:41 +00:00
|
|
|
|
2015-02-25 18:32:19 +00:00
|
|
|
theorem eq_inv_mul_of_mul_eq {a b c : A} (H : b * a = c) : a = b⁻¹ * c :=
|
2015-03-06 02:46:07 +00:00
|
|
|
by rewrite [-H, inv_mul_cancel_left]
|
2014-11-13 00:46:41 +00:00
|
|
|
|
2015-02-25 18:32:19 +00:00
|
|
|
theorem inv_mul_eq_of_eq_mul {a b c : A} (H : b = a * c) : a⁻¹ * b = c :=
|
2015-03-06 02:46:07 +00:00
|
|
|
by rewrite [H, inv_mul_cancel_left]
|
2014-11-13 00:46:41 +00:00
|
|
|
|
2015-02-25 18:32:19 +00:00
|
|
|
theorem mul_inv_eq_of_eq_mul {a b c : A} (H : a = c * b) : a * b⁻¹ = c :=
|
2015-03-06 02:46:07 +00:00
|
|
|
by rewrite [H, mul_inv_cancel_right]
|
2014-11-13 00:46:41 +00:00
|
|
|
|
2015-02-25 18:32:19 +00:00
|
|
|
theorem eq_mul_of_mul_inv_eq {a b c : A} (H : a * c⁻¹ = b) : a = b * c :=
|
2014-12-17 18:32:38 +00:00
|
|
|
!inv_inv ▸ (eq_mul_inv_of_mul_eq H)
|
2014-11-13 00:46:41 +00:00
|
|
|
|
2015-02-25 18:32:19 +00:00
|
|
|
theorem eq_mul_of_inv_mul_eq {a b c : A} (H : b⁻¹ * a = c) : a = b * c :=
|
2014-12-17 18:32:38 +00:00
|
|
|
!inv_inv ▸ (eq_inv_mul_of_mul_eq H)
|
2014-11-13 00:46:41 +00:00
|
|
|
|
2015-02-25 18:32:19 +00:00
|
|
|
theorem mul_eq_of_eq_inv_mul {a b c : A} (H : b = a⁻¹ * c) : a * b = c :=
|
2014-12-17 18:32:38 +00:00
|
|
|
!inv_inv ▸ (inv_mul_eq_of_eq_mul H)
|
2014-11-13 00:46:41 +00:00
|
|
|
|
2015-02-25 18:32:19 +00:00
|
|
|
theorem mul_eq_of_eq_mul_inv {a b c : A} (H : a = c * b⁻¹) : a * b = c :=
|
2014-12-17 18:32:38 +00:00
|
|
|
!inv_inv ▸ (mul_inv_eq_of_eq_mul H)
|
2014-11-13 00:46:41 +00:00
|
|
|
|
2014-11-26 23:08:23 +00:00
|
|
|
theorem mul_eq_iff_eq_inv_mul (a b c : A) : a * b = c ↔ b = a⁻¹ * c :=
|
2014-11-30 13:31:34 +00:00
|
|
|
iff.intro eq_inv_mul_of_mul_eq mul_eq_of_eq_inv_mul
|
2014-11-26 23:08:23 +00:00
|
|
|
|
|
|
|
theorem mul_eq_iff_eq_mul_inv (a b c : A) : a * b = c ↔ a = c * b⁻¹ :=
|
2014-11-30 13:31:34 +00:00
|
|
|
iff.intro eq_mul_inv_of_mul_eq mul_eq_of_eq_mul_inv
|
2014-11-26 23:08:23 +00:00
|
|
|
|
2015-01-19 21:00:24 +00:00
|
|
|
theorem mul_left_cancel {a b c : A} (H : a * b = a * c) : b = c :=
|
2015-03-28 00:26:06 +00:00
|
|
|
by rewrite [-inv_mul_cancel_left a b, H, inv_mul_cancel_left]
|
2015-01-19 21:00:24 +00:00
|
|
|
|
|
|
|
theorem mul_right_cancel {a b c : A} (H : a * b = c * b) : a = c :=
|
2015-03-28 00:26:06 +00:00
|
|
|
by rewrite [-mul_inv_cancel_right a b, H, mul_inv_cancel_right]
|
2015-01-19 21:00:24 +00:00
|
|
|
|
2015-06-04 08:51:34 +00:00
|
|
|
theorem mul_eq_one_of_mul_eq_one {a b : A} (H : b * a = 1) : a * b = 1 :=
|
|
|
|
by rewrite [-inv_eq_of_mul_eq_one H, mul.left_inv]
|
|
|
|
|
|
|
|
theorem mul_eq_one_iff_mul_eq_one (a b : A) : a * b = 1 ↔ b * a = 1 :=
|
|
|
|
iff.intro !mul_eq_one_of_mul_eq_one !mul_eq_one_of_mul_eq_one
|
|
|
|
|
2015-06-21 19:36:43 +00:00
|
|
|
definition group.to_left_cancel_semigroup [trans-instance] [coercion] [reducible] :
|
2015-06-04 08:51:34 +00:00
|
|
|
left_cancel_semigroup A :=
|
2015-01-17 17:38:10 +00:00
|
|
|
⦃ left_cancel_semigroup, s,
|
2015-01-19 21:00:24 +00:00
|
|
|
mul_left_cancel := @mul_left_cancel A s ⦄
|
2014-11-13 00:46:41 +00:00
|
|
|
|
2015-06-21 19:36:43 +00:00
|
|
|
definition group.to_right_cancel_semigroup [trans-instance] [coercion] [reducible] :
|
2015-06-04 08:51:34 +00:00
|
|
|
right_cancel_semigroup A :=
|
2015-01-17 17:38:10 +00:00
|
|
|
⦃ right_cancel_semigroup, s,
|
2015-01-19 21:00:24 +00:00
|
|
|
mul_right_cancel := @mul_right_cancel A s ⦄
|
2014-11-13 00:46:41 +00:00
|
|
|
|
|
|
|
end group
|
2014-11-07 02:30:46 +00:00
|
|
|
|
|
|
|
structure comm_group [class] (A : Type) extends group A, comm_monoid A
|
|
|
|
|
|
|
|
/- additive group -/
|
|
|
|
|
|
|
|
structure add_group [class] (A : Type) extends add_monoid A, has_neg A :=
|
2014-11-13 00:46:41 +00:00
|
|
|
(add_left_inv : ∀a, add (neg a) a = zero)
|
|
|
|
|
|
|
|
section add_group
|
|
|
|
|
|
|
|
variables [s : add_group A]
|
|
|
|
include s
|
|
|
|
|
2014-11-30 13:31:34 +00:00
|
|
|
theorem add.left_inv (a : A) : -a + a = 0 := !add_group.add_left_inv
|
2014-11-13 00:46:41 +00:00
|
|
|
|
|
|
|
theorem neg_add_cancel_left (a b : A) : -a + (a + b) = b :=
|
2015-03-28 00:26:06 +00:00
|
|
|
by rewrite [-add.assoc, add.left_inv, zero_add]
|
2014-11-13 00:46:41 +00:00
|
|
|
|
|
|
|
theorem neg_add_cancel_right (a b : A) : a + -b + b = a :=
|
2015-03-28 00:26:06 +00:00
|
|
|
by rewrite [add.assoc, add.left_inv, add_zero]
|
2014-11-13 00:46:41 +00:00
|
|
|
|
2014-11-30 13:31:34 +00:00
|
|
|
theorem neg_eq_of_add_eq_zero {a b : A} (H : a + b = 0) : -a = b :=
|
2015-03-28 00:26:06 +00:00
|
|
|
by rewrite [-add_zero, -H, neg_add_cancel_left]
|
2014-11-13 00:46:41 +00:00
|
|
|
|
2015-05-18 22:45:23 +00:00
|
|
|
theorem neg_zero : -0 = (0 : A) := neg_eq_of_add_eq_zero (zero_add 0)
|
2014-11-13 00:46:41 +00:00
|
|
|
|
2014-12-17 18:32:38 +00:00
|
|
|
theorem neg_neg (a : A) : -(-a) = a := neg_eq_of_add_eq_zero (add.left_inv a)
|
2014-11-13 00:46:41 +00:00
|
|
|
|
2015-03-30 18:55:16 +00:00
|
|
|
theorem eq_neg_of_add_eq_zero {a b : A} (H : a + b = 0) : a = -b :=
|
|
|
|
by rewrite [-neg_eq_of_add_eq_zero H, neg_neg]
|
|
|
|
|
2014-12-17 18:32:38 +00:00
|
|
|
theorem neg.inj {a b : A} (H : -a = -b) : a = b :=
|
2014-11-13 00:46:41 +00:00
|
|
|
calc
|
2014-12-17 18:32:38 +00:00
|
|
|
a = -(-a) : neg_neg
|
2014-11-30 13:31:34 +00:00
|
|
|
... = b : neg_eq_of_add_eq_zero (H⁻¹ ▸ (add.left_inv _))
|
2014-11-13 00:46:41 +00:00
|
|
|
|
|
|
|
theorem neg_eq_neg_iff_eq (a b : A) : -a = -b ↔ a = b :=
|
2014-12-17 18:32:38 +00:00
|
|
|
iff.intro (assume H, neg.inj H) (assume H, congr_arg _ H)
|
2014-11-13 00:46:41 +00:00
|
|
|
|
2014-12-17 18:32:38 +00:00
|
|
|
theorem neg_eq_zero_iff_eq_zero (a : A) : -a = 0 ↔ a = 0 :=
|
|
|
|
neg_zero ▸ !neg_eq_neg_iff_eq
|
2014-11-13 00:46:41 +00:00
|
|
|
|
2014-11-30 13:31:34 +00:00
|
|
|
theorem eq_neg_of_eq_neg {a b : A} (H : a = -b) : b = -a :=
|
2014-12-17 18:32:38 +00:00
|
|
|
H⁻¹ ▸ (neg_neg b)⁻¹
|
2014-11-13 00:46:41 +00:00
|
|
|
|
|
|
|
theorem eq_neg_iff_eq_neg (a b : A) : a = -b ↔ b = -a :=
|
2014-11-30 13:31:34 +00:00
|
|
|
iff.intro !eq_neg_of_eq_neg !eq_neg_of_eq_neg
|
2014-11-13 00:46:41 +00:00
|
|
|
|
2014-11-30 13:31:34 +00:00
|
|
|
theorem add.right_inv (a : A) : a + -a = 0 :=
|
2014-11-13 00:46:41 +00:00
|
|
|
calc
|
2014-12-17 18:32:38 +00:00
|
|
|
a + -a = -(-a) + -a : neg_neg
|
2014-11-30 13:31:34 +00:00
|
|
|
... = 0 : add.left_inv
|
2014-11-13 00:46:41 +00:00
|
|
|
|
|
|
|
theorem add_neg_cancel_left (a b : A) : a + (-a + b) = b :=
|
2015-03-28 00:26:06 +00:00
|
|
|
by rewrite [-add.assoc, add.right_inv, zero_add]
|
2014-11-13 00:46:41 +00:00
|
|
|
|
|
|
|
theorem add_neg_cancel_right (a b : A) : a + b + -b = a :=
|
2015-03-28 00:26:06 +00:00
|
|
|
by rewrite [add.assoc, add.right_inv, add_zero]
|
2014-11-13 00:46:41 +00:00
|
|
|
|
2015-01-26 16:42:13 +00:00
|
|
|
theorem neg_add_rev (a b : A) : -(a + b) = -b + -a :=
|
2014-11-30 13:31:34 +00:00
|
|
|
neg_eq_of_add_eq_zero
|
2015-02-06 02:03:02 +00:00
|
|
|
begin
|
2015-03-28 00:26:06 +00:00
|
|
|
rewrite [add.assoc, add_neg_cancel_left, add.right_inv]
|
2015-02-06 02:03:02 +00:00
|
|
|
end
|
2014-11-13 00:46:41 +00:00
|
|
|
|
2015-02-25 18:32:19 +00:00
|
|
|
-- TODO: delete these in favor of sub rules?
|
|
|
|
theorem eq_add_neg_of_add_eq {a b c : A} (H : a + c = b) : a = b + -c :=
|
2014-11-13 00:46:41 +00:00
|
|
|
H ▸ !add_neg_cancel_right⁻¹
|
|
|
|
|
2015-02-25 18:32:19 +00:00
|
|
|
theorem eq_neg_add_of_add_eq {a b c : A} (H : b + a = c) : a = -b + c :=
|
2014-11-13 00:46:41 +00:00
|
|
|
H ▸ !neg_add_cancel_left⁻¹
|
|
|
|
|
2015-02-25 18:32:19 +00:00
|
|
|
theorem neg_add_eq_of_eq_add {a b c : A} (H : b = a + c) : -a + b = c :=
|
2014-11-13 00:46:41 +00:00
|
|
|
H⁻¹ ▸ !neg_add_cancel_left
|
|
|
|
|
2015-02-25 18:32:19 +00:00
|
|
|
theorem add_neg_eq_of_eq_add {a b c : A} (H : a = c + b) : a + -b = c :=
|
2014-11-13 00:46:41 +00:00
|
|
|
H⁻¹ ▸ !add_neg_cancel_right
|
|
|
|
|
2015-02-25 18:32:19 +00:00
|
|
|
theorem eq_add_of_add_neg_eq {a b c : A} (H : a + -c = b) : a = b + c :=
|
2014-12-17 18:32:38 +00:00
|
|
|
!neg_neg ▸ (eq_add_neg_of_add_eq H)
|
2014-11-13 00:46:41 +00:00
|
|
|
|
2015-02-25 18:32:19 +00:00
|
|
|
theorem eq_add_of_neg_add_eq {a b c : A} (H : -b + a = c) : a = b + c :=
|
2014-12-17 18:32:38 +00:00
|
|
|
!neg_neg ▸ (eq_neg_add_of_add_eq H)
|
2014-11-13 00:46:41 +00:00
|
|
|
|
2015-02-25 18:32:19 +00:00
|
|
|
theorem add_eq_of_eq_neg_add {a b c : A} (H : b = -a + c) : a + b = c :=
|
2014-12-17 18:32:38 +00:00
|
|
|
!neg_neg ▸ (neg_add_eq_of_eq_add H)
|
2014-11-13 00:46:41 +00:00
|
|
|
|
2015-02-25 18:32:19 +00:00
|
|
|
theorem add_eq_of_eq_add_neg {a b c : A} (H : a = c + -b) : a + b = c :=
|
2014-12-17 18:32:38 +00:00
|
|
|
!neg_neg ▸ (add_neg_eq_of_eq_add H)
|
2014-11-13 00:46:41 +00:00
|
|
|
|
2014-11-26 23:08:23 +00:00
|
|
|
theorem add_eq_iff_eq_neg_add (a b c : A) : a + b = c ↔ b = -a + c :=
|
2014-11-30 13:31:34 +00:00
|
|
|
iff.intro eq_neg_add_of_add_eq add_eq_of_eq_neg_add
|
2014-11-26 23:08:23 +00:00
|
|
|
|
|
|
|
theorem add_eq_iff_eq_add_neg (a b c : A) : a + b = c ↔ a = c + -b :=
|
2014-11-30 13:31:34 +00:00
|
|
|
iff.intro eq_add_neg_of_add_eq add_eq_of_eq_add_neg
|
2014-11-26 23:08:23 +00:00
|
|
|
|
2015-01-19 21:00:24 +00:00
|
|
|
theorem add_left_cancel {a b c : A} (H : a + b = a + c) : b = c :=
|
|
|
|
calc b = -a + (a + b) : !neg_add_cancel_left⁻¹
|
|
|
|
... = -a + (a + c) : H
|
|
|
|
... = c : neg_add_cancel_left
|
|
|
|
|
|
|
|
theorem add_right_cancel {a b c : A} (H : a + b = c + b) : a = c :=
|
|
|
|
calc a = (a + b) + -b : !add_neg_cancel_right⁻¹
|
|
|
|
... = (c + b) + -b : H
|
|
|
|
... = c : add_neg_cancel_right
|
|
|
|
|
2015-06-21 19:36:43 +00:00
|
|
|
definition add_group.to_left_cancel_semigroup [trans-instance] [coercion] [reducible] :
|
2014-11-13 00:46:41 +00:00
|
|
|
add_left_cancel_semigroup A :=
|
2015-01-17 17:38:10 +00:00
|
|
|
⦃ add_left_cancel_semigroup, s,
|
2015-01-19 21:00:24 +00:00
|
|
|
add_left_cancel := @add_left_cancel A s ⦄
|
2014-11-13 00:46:41 +00:00
|
|
|
|
2015-06-21 19:36:43 +00:00
|
|
|
definition add_group.to_add_right_cancel_semigroup [trans-instance] [coercion] [reducible] :
|
2014-11-13 00:46:41 +00:00
|
|
|
add_right_cancel_semigroup A :=
|
2015-01-17 17:38:10 +00:00
|
|
|
⦃ add_right_cancel_semigroup, s,
|
2015-01-19 21:00:24 +00:00
|
|
|
add_right_cancel := @add_right_cancel A s ⦄
|
2014-11-13 00:46:41 +00:00
|
|
|
|
2014-11-30 13:31:34 +00:00
|
|
|
/- sub -/
|
2014-11-13 00:46:41 +00:00
|
|
|
|
|
|
|
-- TODO: derive corresponding facts for div in a field
|
2014-11-30 13:31:34 +00:00
|
|
|
definition sub [reducible] (a b : A) : A := a + -b
|
2014-11-13 00:46:41 +00:00
|
|
|
|
2015-07-01 00:34:35 +00:00
|
|
|
infix [priority algebra.prio] `-` := sub
|
2014-11-13 00:46:41 +00:00
|
|
|
|
2015-02-25 19:14:57 +00:00
|
|
|
theorem sub_eq_add_neg (a b : A) : a - b = a + -b := rfl
|
|
|
|
|
2014-11-30 13:31:34 +00:00
|
|
|
theorem sub_self (a : A) : a - a = 0 := !add.right_inv
|
2014-11-13 00:46:41 +00:00
|
|
|
|
2014-11-30 13:31:34 +00:00
|
|
|
theorem sub_add_cancel (a b : A) : a - b + b = a := !neg_add_cancel_right
|
2014-11-13 00:46:41 +00:00
|
|
|
|
2014-11-30 13:31:34 +00:00
|
|
|
theorem add_sub_cancel (a b : A) : a + b - b = a := !add_neg_cancel_right
|
2014-11-13 00:46:41 +00:00
|
|
|
|
2014-11-30 13:31:34 +00:00
|
|
|
theorem eq_of_sub_eq_zero {a b : A} (H : a - b = 0) : a = b :=
|
2014-11-13 00:46:41 +00:00
|
|
|
calc
|
2014-11-30 13:31:34 +00:00
|
|
|
a = (a - b) + b : !sub_add_cancel⁻¹
|
2014-11-13 00:46:41 +00:00
|
|
|
... = 0 + b : H
|
2014-12-24 02:14:19 +00:00
|
|
|
... = b : zero_add
|
2014-11-13 00:46:41 +00:00
|
|
|
|
2014-11-30 13:31:34 +00:00
|
|
|
theorem eq_iff_sub_eq_zero (a b : A) : a = b ↔ a - b = 0 :=
|
|
|
|
iff.intro (assume H, H ▸ !sub_self) (assume H, eq_of_sub_eq_zero H)
|
2014-11-13 00:46:41 +00:00
|
|
|
|
2015-01-07 01:44:04 +00:00
|
|
|
theorem zero_sub (a : A) : 0 - a = -a := !zero_add
|
2014-11-13 00:46:41 +00:00
|
|
|
|
2015-01-07 01:44:04 +00:00
|
|
|
theorem sub_zero (a : A) : a - 0 = a := subst (eq.symm neg_zero) !add_zero
|
2014-11-13 00:46:41 +00:00
|
|
|
|
2015-06-22 19:22:11 +00:00
|
|
|
theorem sub_neg_eq_add (a b : A) : a - (-b) = a + b :=
|
|
|
|
by change a + -(-b) = a + b; rewrite neg_neg
|
2014-11-13 00:46:41 +00:00
|
|
|
|
2015-01-07 01:44:04 +00:00
|
|
|
theorem neg_sub (a b : A) : -(a - b) = b - a :=
|
2014-11-30 13:31:34 +00:00
|
|
|
neg_eq_of_add_eq_zero
|
2014-11-13 00:46:41 +00:00
|
|
|
(calc
|
2015-06-22 22:11:14 +00:00
|
|
|
a - b + (b - a) = a - b + b - a : by krewrite -add.assoc
|
2015-03-06 02:46:07 +00:00
|
|
|
... = a - a : sub_add_cancel
|
|
|
|
... = 0 : sub_self)
|
2014-11-13 00:46:41 +00:00
|
|
|
|
2015-01-07 01:44:04 +00:00
|
|
|
theorem add_sub (a b c : A) : a + (b - c) = a + b - c := !add.assoc⁻¹
|
2014-11-13 00:46:41 +00:00
|
|
|
|
2014-11-30 13:31:34 +00:00
|
|
|
theorem sub_add_eq_sub_sub_swap (a b c : A) : a - (b + c) = a - c - b :=
|
2014-11-13 00:46:41 +00:00
|
|
|
calc
|
2015-01-26 16:42:13 +00:00
|
|
|
a - (b + c) = a + (-c - b) : neg_add_rev
|
2015-06-22 22:11:14 +00:00
|
|
|
... = a - c - b : by krewrite -add.assoc
|
2014-11-13 00:46:41 +00:00
|
|
|
|
2014-11-30 13:31:34 +00:00
|
|
|
theorem sub_eq_iff_eq_add (a b c : A) : a - b = c ↔ a = c + b :=
|
|
|
|
iff.intro (assume H, eq_add_of_add_neg_eq H) (assume H, add_neg_eq_of_eq_add H)
|
2014-11-13 00:46:41 +00:00
|
|
|
|
2014-11-30 13:31:34 +00:00
|
|
|
theorem eq_sub_iff_add_eq (a b c : A) : a = b - c ↔ a + c = b :=
|
|
|
|
iff.intro (assume H, add_eq_of_eq_add_neg H) (assume H, eq_add_neg_of_add_eq H)
|
2014-11-13 00:46:41 +00:00
|
|
|
|
2014-11-30 13:31:34 +00:00
|
|
|
theorem eq_iff_eq_of_sub_eq_sub {a b c d : A} (H : a - b = c - d) : a = b ↔ c = d :=
|
2014-11-13 00:46:41 +00:00
|
|
|
calc
|
2015-03-06 02:46:07 +00:00
|
|
|
a = b ↔ a - b = 0 : eq_iff_sub_eq_zero
|
|
|
|
... = (c - d = 0) : H
|
|
|
|
... ↔ c = d : iff.symm (eq_iff_sub_eq_zero c d)
|
2014-11-13 00:46:41 +00:00
|
|
|
|
2015-02-25 18:32:19 +00:00
|
|
|
theorem eq_sub_of_add_eq {a b c : A} (H : a + c = b) : a = b - c :=
|
|
|
|
!eq_add_neg_of_add_eq H
|
|
|
|
|
|
|
|
theorem sub_eq_of_eq_add {a b c : A} (H : a = c + b) : a - b = c :=
|
|
|
|
!add_neg_eq_of_eq_add H
|
|
|
|
|
|
|
|
theorem eq_add_of_sub_eq {a b c : A} (H : a - c = b) : a = b + c :=
|
|
|
|
eq_add_of_add_neg_eq H
|
|
|
|
|
|
|
|
theorem add_eq_of_eq_sub {a b c : A} (H : a = c - b) : a + b = c :=
|
|
|
|
add_eq_of_eq_add_neg H
|
2014-11-13 00:46:41 +00:00
|
|
|
end add_group
|
2014-11-07 02:30:46 +00:00
|
|
|
|
|
|
|
structure add_comm_group [class] (A : Type) extends add_group A, add_comm_monoid A
|
|
|
|
|
2014-11-13 00:46:41 +00:00
|
|
|
section add_comm_group
|
2015-02-25 18:32:19 +00:00
|
|
|
variable [s : add_comm_group A]
|
|
|
|
include s
|
2014-11-13 00:46:41 +00:00
|
|
|
|
2014-11-30 13:31:34 +00:00
|
|
|
theorem sub_add_eq_sub_sub (a b c : A) : a - (b + c) = a - b - c :=
|
|
|
|
!add.comm ▸ !sub_add_eq_sub_sub_swap
|
2014-11-13 00:46:41 +00:00
|
|
|
|
2014-11-30 13:31:34 +00:00
|
|
|
theorem neg_add_eq_sub (a b : A) : -a + b = b - a := !add.comm
|
2014-11-13 00:46:41 +00:00
|
|
|
|
2015-01-26 16:42:13 +00:00
|
|
|
theorem neg_add (a b : A) : -(a + b) = -a + -b := add.comm (-b) (-a) ▸ neg_add_rev a b
|
2014-11-13 00:46:41 +00:00
|
|
|
|
2014-11-30 13:31:34 +00:00
|
|
|
theorem sub_add_eq_add_sub (a b c : A) : a - b + c = a + c - b := !add.right_comm
|
2014-11-13 00:46:41 +00:00
|
|
|
|
2015-01-07 01:44:04 +00:00
|
|
|
theorem sub_sub (a b c : A) : a - b - c = a - (b + c) :=
|
2015-02-06 02:03:02 +00:00
|
|
|
by rewrite [▸ a + -b + -c = _, add.assoc, -neg_add]
|
2014-11-13 00:46:41 +00:00
|
|
|
|
2014-11-30 13:31:34 +00:00
|
|
|
theorem add_sub_add_left_eq_sub (a b c : A) : (c + a) - (c + b) = a - b :=
|
2015-03-28 00:26:06 +00:00
|
|
|
by rewrite [sub_add_eq_sub_sub, (add.comm c a), add_sub_cancel]
|
2014-11-13 00:46:41 +00:00
|
|
|
|
2015-02-25 18:32:19 +00:00
|
|
|
theorem eq_sub_of_add_eq' {a b c : A} (H : c + a = b) : a = b - c :=
|
|
|
|
!eq_sub_of_add_eq (!add.comm ▸ H)
|
|
|
|
|
|
|
|
theorem sub_eq_of_eq_add' {a b c : A} (H : a = b + c) : a - b = c :=
|
|
|
|
!sub_eq_of_eq_add (!add.comm ▸ H)
|
|
|
|
|
|
|
|
theorem eq_add_of_sub_eq' {a b c : A} (H : a - b = c) : a = b + c :=
|
|
|
|
!add.comm ▸ eq_add_of_sub_eq H
|
|
|
|
|
|
|
|
theorem add_eq_of_eq_sub' {a b c : A} (H : b = c - a) : a + b = c :=
|
|
|
|
!add.comm ▸ add_eq_of_eq_sub H
|
2014-11-13 00:46:41 +00:00
|
|
|
end add_comm_group
|
|
|
|
|
2015-05-14 02:01:48 +00:00
|
|
|
definition group_of_add_group (A : Type) [G : add_group A] : group A :=
|
|
|
|
⦃group,
|
|
|
|
mul := has_add.add,
|
|
|
|
mul_assoc := add.assoc,
|
|
|
|
one := !has_zero.zero,
|
|
|
|
one_mul := zero_add,
|
|
|
|
mul_one := add_zero,
|
|
|
|
inv := has_neg.neg,
|
|
|
|
mul_left_inv := add.left_inv⦄
|
|
|
|
|
2014-11-07 02:30:46 +00:00
|
|
|
end algebra
|