2014-08-25 02:58:48 +00:00
|
|
|
import logic
|
2014-07-08 00:48:20 +00:00
|
|
|
|
2014-09-17 21:39:05 +00:00
|
|
|
definition Type1 := Type.{1}
|
2014-07-08 00:48:20 +00:00
|
|
|
|
2014-09-06 18:05:07 +00:00
|
|
|
context
|
2014-07-08 00:48:20 +00:00
|
|
|
parameter {A : Type}
|
|
|
|
parameter f : A → A → A
|
|
|
|
parameter one : A
|
|
|
|
parameter inv : A → A
|
|
|
|
infixl `*`:75 := f
|
|
|
|
postfix `^-1`:100 := inv
|
|
|
|
definition is_assoc := ∀ a b c, (a*b)*c = a*b*c
|
|
|
|
definition is_id := ∀ a, a*one = a
|
|
|
|
definition is_inv := ∀ a, a*a^-1 = one
|
|
|
|
end
|
|
|
|
|
|
|
|
namespace algebra
|
|
|
|
inductive mul_struct (A : Type) : Type :=
|
2014-09-04 23:36:06 +00:00
|
|
|
mk : (A → A → A) → mul_struct A
|
2014-07-08 00:48:20 +00:00
|
|
|
|
|
|
|
inductive add_struct (A : Type) : Type :=
|
2014-09-04 23:36:06 +00:00
|
|
|
mk : (A → A → A) → add_struct A
|
2014-07-08 00:48:20 +00:00
|
|
|
|
2014-09-17 21:39:05 +00:00
|
|
|
definition mul {A : Type} {s : mul_struct A} (a b : A)
|
2014-09-04 22:03:59 +00:00
|
|
|
:= mul_struct.rec (fun f, f) s a b
|
2014-07-08 00:48:20 +00:00
|
|
|
|
|
|
|
infixl `*`:75 := mul
|
|
|
|
|
2014-09-17 21:39:05 +00:00
|
|
|
definition add {A : Type} {s : add_struct A} (a b : A)
|
2014-09-04 22:03:59 +00:00
|
|
|
:= add_struct.rec (fun f, f) s a b
|
2014-07-08 00:48:20 +00:00
|
|
|
|
|
|
|
infixl `+`:65 := add
|
2014-08-07 23:59:08 +00:00
|
|
|
end algebra
|
2014-07-08 00:48:20 +00:00
|
|
|
|
|
|
|
inductive nat : Type :=
|
2014-08-22 22:46:10 +00:00
|
|
|
zero : nat,
|
|
|
|
succ : nat → nat
|
2014-07-08 00:48:20 +00:00
|
|
|
|
2014-09-04 23:36:06 +00:00
|
|
|
namespace nat
|
|
|
|
|
2014-10-02 23:20:52 +00:00
|
|
|
constant add : nat → nat → nat
|
|
|
|
constant mul : nat → nat → nat
|
2014-07-08 00:48:20 +00:00
|
|
|
|
2014-09-17 21:39:05 +00:00
|
|
|
definition is_mul_struct [instance] : algebra.mul_struct nat
|
2014-09-04 23:36:06 +00:00
|
|
|
:= algebra.mul_struct.mk mul
|
2014-07-08 00:48:20 +00:00
|
|
|
|
2014-09-17 21:39:05 +00:00
|
|
|
definition is_add_struct [instance] : algebra.add_struct nat
|
2014-09-04 23:36:06 +00:00
|
|
|
:= algebra.add_struct.mk add
|
2014-07-08 00:48:20 +00:00
|
|
|
|
|
|
|
definition to_nat (n : num) : nat
|
|
|
|
:= #algebra
|
2014-09-04 23:36:06 +00:00
|
|
|
num.rec nat.zero (λ n, pos_num.rec (succ zero) (λ n r, r + r) (λ n r, r + r + succ zero) n) n
|
2014-08-07 23:59:08 +00:00
|
|
|
end nat
|
2014-07-08 00:48:20 +00:00
|
|
|
|
|
|
|
namespace algebra
|
|
|
|
namespace semigroup
|
|
|
|
inductive semigroup_struct (A : Type) : Type :=
|
2014-09-04 23:36:06 +00:00
|
|
|
mk : Π (mul : A → A → A), is_assoc mul → semigroup_struct A
|
2014-07-08 00:48:20 +00:00
|
|
|
|
2014-09-17 21:39:05 +00:00
|
|
|
definition mul {A : Type} (s : semigroup_struct A) (a b : A)
|
2014-09-04 22:03:59 +00:00
|
|
|
:= semigroup_struct.rec (fun f h, f) s a b
|
2014-07-08 00:48:20 +00:00
|
|
|
|
2014-09-17 21:39:05 +00:00
|
|
|
definition assoc {A : Type} (s : semigroup_struct A) : is_assoc (mul s)
|
2014-09-04 22:03:59 +00:00
|
|
|
:= semigroup_struct.rec (fun f h, h) s
|
2014-07-08 00:48:20 +00:00
|
|
|
|
2014-09-17 21:39:05 +00:00
|
|
|
definition is_mul_struct [instance] (A : Type) (s : semigroup_struct A) : mul_struct A
|
2014-09-04 23:36:06 +00:00
|
|
|
:= mul_struct.mk (mul s)
|
2014-07-08 00:48:20 +00:00
|
|
|
|
|
|
|
inductive semigroup : Type :=
|
2014-09-04 23:36:06 +00:00
|
|
|
mk : Π (A : Type), semigroup_struct A → semigroup
|
2014-07-08 00:48:20 +00:00
|
|
|
|
2014-09-17 21:39:05 +00:00
|
|
|
definition carrier [coercion] (g : semigroup)
|
2014-09-04 22:03:59 +00:00
|
|
|
:= semigroup.rec (fun c s, c) g
|
2014-07-08 00:48:20 +00:00
|
|
|
|
2014-09-17 21:39:05 +00:00
|
|
|
definition is_semigroup [instance] (g : semigroup) : semigroup_struct (carrier g)
|
2014-09-04 22:03:59 +00:00
|
|
|
:= semigroup.rec (fun c s, s) g
|
2014-08-07 23:59:08 +00:00
|
|
|
end semigroup
|
2014-07-08 00:48:20 +00:00
|
|
|
|
|
|
|
namespace monoid
|
2014-07-08 01:56:51 +00:00
|
|
|
check semigroup.mul
|
|
|
|
|
2014-07-08 00:48:20 +00:00
|
|
|
inductive monoid_struct (A : Type) : Type :=
|
2014-08-22 22:46:10 +00:00
|
|
|
mk_monoid_struct : Π (mul : A → A → A) (id : A), is_assoc mul → is_id mul id → monoid_struct A
|
2014-07-08 00:48:20 +00:00
|
|
|
|
2014-09-17 21:39:05 +00:00
|
|
|
definition mul {A : Type} (s : monoid_struct A) (a b : A)
|
2014-09-04 22:03:59 +00:00
|
|
|
:= monoid_struct.rec (fun mul id a i, mul) s a b
|
2014-07-08 00:48:20 +00:00
|
|
|
|
2014-09-17 21:39:05 +00:00
|
|
|
definition assoc {A : Type} (s : monoid_struct A) : is_assoc (mul s)
|
2014-09-04 22:03:59 +00:00
|
|
|
:= monoid_struct.rec (fun mul id a i, a) s
|
2014-07-08 00:48:20 +00:00
|
|
|
|
2014-09-03 23:00:38 +00:00
|
|
|
open semigroup
|
2014-09-17 21:39:05 +00:00
|
|
|
definition is_semigroup_struct [instance] (A : Type) (s : monoid_struct A) : semigroup_struct A
|
2014-09-04 23:36:06 +00:00
|
|
|
:= semigroup_struct.mk (mul s) (assoc s)
|
2014-07-08 00:48:20 +00:00
|
|
|
|
|
|
|
inductive monoid : Type :=
|
2014-08-22 22:46:10 +00:00
|
|
|
mk_monoid : Π (A : Type), monoid_struct A → monoid
|
2014-07-08 00:48:20 +00:00
|
|
|
|
2014-09-17 21:39:05 +00:00
|
|
|
definition carrier [coercion] (m : monoid)
|
2014-09-04 22:03:59 +00:00
|
|
|
:= monoid.rec (fun c s, c) m
|
2014-07-08 00:48:20 +00:00
|
|
|
|
2014-09-17 21:39:05 +00:00
|
|
|
definition is_monoid [instance] (m : monoid) : monoid_struct (carrier m)
|
2014-09-04 22:03:59 +00:00
|
|
|
:= monoid.rec (fun c s, s) m
|
2014-08-07 23:59:08 +00:00
|
|
|
end monoid
|
|
|
|
end algebra
|
2014-07-08 00:48:20 +00:00
|
|
|
|
|
|
|
section
|
2014-09-03 23:00:38 +00:00
|
|
|
open algebra algebra.semigroup algebra.monoid
|
2014-10-02 23:20:52 +00:00
|
|
|
parameter M : monoid
|
|
|
|
parameters a b c : M
|
2014-07-08 00:48:20 +00:00
|
|
|
check a*b*c*a*b*c*a*b*a*b*c*a
|
|
|
|
check a*b
|
|
|
|
end
|