2014-11-04 03:18:10 +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
|
|
|
|
|
|
|
|
-- algebra.group
|
|
|
|
-- =============
|
|
|
|
|
|
|
|
-- Various structures with 1, *, inv, including groups.
|
|
|
|
|
2014-12-01 05:16:01 +00:00
|
|
|
import logic.eq
|
2014-11-04 03:18:10 +00:00
|
|
|
import data.unit data.sigma data.prod
|
2015-07-06 22:05:01 +00:00
|
|
|
import algebra.binary
|
2014-11-04 03:18:10 +00:00
|
|
|
|
|
|
|
open eq
|
|
|
|
|
|
|
|
namespace algebra
|
|
|
|
|
|
|
|
structure has_mul [class] (A : Type) :=
|
|
|
|
mk :: (mul : A → A → A)
|
|
|
|
|
|
|
|
structure has_one [class] (A : Type) :=
|
|
|
|
mk :: (one : A)
|
|
|
|
|
|
|
|
structure has_inv [class] (A : Type) :=
|
|
|
|
mk :: (inv : A → A)
|
|
|
|
|
|
|
|
infixl `*` := has_mul.mul
|
|
|
|
postfix `⁻¹` := has_inv.inv
|
2014-11-26 02:04:06 +00:00
|
|
|
notation 1 := !has_one.one
|
2014-11-04 03:18:10 +00:00
|
|
|
|
|
|
|
structure semigroup [class] (A : Type) extends has_mul A :=
|
|
|
|
mk :: (assoc : ∀ a b c, mul (mul a b) c = mul a (mul b c))
|
|
|
|
|
|
|
|
set_option pp.notation false
|
|
|
|
-- set_option pp.implicit true
|
|
|
|
-- set_option pp.coercions true
|
|
|
|
print instances has_mul
|
|
|
|
|
|
|
|
section
|
|
|
|
variables {A : Type} [s : semigroup A]
|
|
|
|
include s
|
|
|
|
variables a b : A
|
|
|
|
|
|
|
|
example : a * b = semigroup.mul a b :=
|
|
|
|
rfl
|
|
|
|
|
|
|
|
theorem mul_assoc (a b c : A) : a * b * c = a * (b * c) :=
|
|
|
|
semigroup.assoc a b c
|
|
|
|
end
|
|
|
|
|
|
|
|
structure comm_semigroup [class] (A : Type) extends semigroup A :=
|
|
|
|
mk :: (comm : ∀a b, mul a b = mul b a)
|
|
|
|
|
|
|
|
namespace comm_semigroup
|
|
|
|
variables {A : Type} [s : comm_semigroup A]
|
|
|
|
include s
|
|
|
|
variables a b c : A
|
|
|
|
theorem mul_comm : a * b = b * a := !comm_semigroup.comm
|
|
|
|
|
|
|
|
theorem mul_left_comm : a * (b * c) = b * (a * c) :=
|
|
|
|
binary.left_comm mul_comm mul_assoc a b c
|
|
|
|
end comm_semigroup
|
|
|
|
|
2014-11-04 06:17:43 +00:00
|
|
|
structure monoid [class] (A : Type) extends semigroup A, has_one A :=
|
2014-11-04 03:18:10 +00:00
|
|
|
mk :: (right_id : ∀a, mul a one = a) (left_id : ∀a, mul one a = a)
|
|
|
|
|
|
|
|
section
|
|
|
|
variables {A : Type} [s : monoid A]
|
|
|
|
variable a : A
|
|
|
|
include s
|
|
|
|
|
|
|
|
theorem mul_right_id : a * 1 = a := !monoid.right_id
|
|
|
|
theorem mul_left_id : 1 * a = a := !monoid.left_id
|
|
|
|
end
|
|
|
|
|
2014-11-04 06:17:43 +00:00
|
|
|
structure comm_monoid [class] (A : Type) extends monoid A, comm_semigroup A
|
2014-11-04 03:18:10 +00:00
|
|
|
|
2014-11-04 16:40:32 +00:00
|
|
|
print prefix algebra.comm_monoid
|
|
|
|
|
2014-11-04 06:17:43 +00:00
|
|
|
structure Semigroup :=
|
|
|
|
mk :: (carrier : Type) (struct : semigroup carrier)
|
2014-11-04 03:18:10 +00:00
|
|
|
|
2015-01-26 19:31:12 +00:00
|
|
|
attribute Semigroup.carrier [coercion]
|
|
|
|
attribute Semigroup.struct [instance]
|
2014-11-04 03:18:10 +00:00
|
|
|
|
2014-11-04 06:17:43 +00:00
|
|
|
structure CommSemigroup :=
|
|
|
|
mk :: (carrier : Type) (struct : comm_semigroup carrier)
|
2014-11-04 03:18:10 +00:00
|
|
|
|
2015-01-26 19:31:12 +00:00
|
|
|
attribute CommSemigroup.carrier [coercion]
|
|
|
|
attribute CommSemigroup.struct [instance]
|
2014-11-04 03:18:10 +00:00
|
|
|
|
2014-11-04 06:17:43 +00:00
|
|
|
structure Monoid :=
|
|
|
|
mk :: (carrier : Type) (struct : monoid carrier)
|
2014-11-04 03:18:10 +00:00
|
|
|
|
2015-01-26 19:31:12 +00:00
|
|
|
attribute Monoid.carrier [coercion]
|
|
|
|
attribute Monoid.struct [instance]
|
2014-11-04 03:18:10 +00:00
|
|
|
|
2014-11-04 06:17:43 +00:00
|
|
|
structure CommMonoid :=
|
|
|
|
mk :: (carrier : Type) (struct : comm_monoid carrier)
|
|
|
|
|
2015-01-26 19:31:12 +00:00
|
|
|
attribute CommMonoid.carrier [coercion]
|
|
|
|
attribute CommMonoid.struct [instance]
|
2014-11-04 03:18:10 +00:00
|
|
|
|
|
|
|
end algebra
|
|
|
|
|
|
|
|
open algebra
|
|
|
|
|
|
|
|
section examples
|
|
|
|
|
|
|
|
theorem test1 {S : Semigroup} (a b c d : S) : a * (b * c) * d = a * b * (c * d) :=
|
|
|
|
calc
|
2014-11-04 16:40:32 +00:00
|
|
|
a * (b * c) * d = a * b * c * d : mul_assoc
|
|
|
|
... = a * b * (c * d) : mul_assoc
|
2014-11-04 03:18:10 +00:00
|
|
|
|
|
|
|
theorem test2 {M : CommSemigroup} (a b : M) : a * b = a * b := rfl
|
|
|
|
|
|
|
|
theorem test3 {M : Monoid} (a b c d : M) : a * (b * c) * d = a * b * (c * d) :=
|
|
|
|
calc
|
2014-11-04 16:40:32 +00:00
|
|
|
a * (b * c) * d = a * b * c * d : mul_assoc
|
|
|
|
... = a * b * (c * d) : mul_assoc
|
2014-11-04 03:18:10 +00:00
|
|
|
|
|
|
|
-- for test4b to work, we need instances at the level of the bundled structures as well
|
2015-02-24 22:09:20 +00:00
|
|
|
definition Monoid_Semigroup [coercion] [reducible] (M : Monoid) : Semigroup :=
|
2014-11-04 03:18:10 +00:00
|
|
|
Semigroup.mk (Monoid.carrier M) _
|
|
|
|
|
|
|
|
theorem test4 {M : Monoid} (a b c d : M) : a * (b * c) * d = a * b * (c * d) :=
|
|
|
|
test1 a b c d
|
|
|
|
|
|
|
|
theorem test5 {M : Monoid} (a b c : M) : a * 1 * b * c = a * (b * c) :=
|
|
|
|
calc
|
2015-01-20 02:00:14 +00:00
|
|
|
a * 1 * b * c = a * b * c : {!mul_right_id}
|
2014-11-04 16:40:32 +00:00
|
|
|
... = a * (b * c) : mul_assoc
|
2014-11-04 03:18:10 +00:00
|
|
|
|
|
|
|
theorem test5a {M : Monoid} (a b c : M) : a * 1 * b * c = a * (b * c) :=
|
|
|
|
calc
|
2015-01-20 02:00:14 +00:00
|
|
|
a * 1 * b * c = a * b * c : {!mul_right_id}
|
2014-11-04 16:40:32 +00:00
|
|
|
... = a * (b * c) : mul_assoc
|
2014-11-04 03:18:10 +00:00
|
|
|
|
|
|
|
theorem test5b {A : Type} {M : monoid A} (a b c : A) : a * 1 * b * c = a * (b * c) :=
|
|
|
|
calc
|
2014-11-04 16:40:32 +00:00
|
|
|
a * 1 * b * c = a * b * c : mul_right_id
|
|
|
|
... = a * (b * c) : mul_assoc
|
2014-11-04 03:18:10 +00:00
|
|
|
|
|
|
|
theorem test6 {M : CommMonoid} (a b c : M) : a * 1 * b * c = a * (b * c) :=
|
|
|
|
calc
|
2014-11-04 16:40:32 +00:00
|
|
|
a * 1 * b * c = a * b * c : mul_right_id
|
|
|
|
... = a * (b * c) : mul_assoc
|
2014-11-04 03:18:10 +00:00
|
|
|
end examples
|