Timings for Monoid.v
- /home/gitlab-runner/builds/v6HyzL39/0/coq/coq/_bench/opam.OLD/ocaml-OLD/.opam-switch/build/coq-category-theory.dev/./Structure/Monoid.v.timing
- /home/gitlab-runner/builds/v6HyzL39/0/coq/coq/_bench/opam.NEW/ocaml-NEW/.opam-switch/build/coq-category-theory.dev/./Structure/Monoid.v.timing
Require Import Category.Lib.
Require Import Category.Theory.Category.
Require Import Category.Theory.Isomorphism.
Require Import Category.Theory.Functor.
Require Import Category.Functor.Bifunctor.
Require Import Category.Structure.Terminal.
Require Import Category.Structure.Cartesian.
Require Import Category.Structure.Monoidal.
Require Import Category.Structure.Monoidal.Internal.Product.
Require Import Category.Structure.Cartesian.Closed.
Require Import Category.Instance.Sets.
Generalizable All Variables.
Context `{M : @Monoidal C}.
Class MonoidObject (mon : C) := {
mempty : I ~> mon;
mappend : mon ⨂ mon ~> mon;
(* I ⨂ mon ≈ mon, mon ⨂ I ≈ mon *)
mempty_left : mappend ∘ bimap mempty id ≈ to (@unit_left C _ mon);
mempty_right : mappend ∘ bimap id mempty ≈ to (@unit_right C _ mon);
(* (mon ⨂ mon) ⨂ mon ≈ mon ⨂ (mon ⨂ mon) *)
mappend_assoc :
mappend ∘ bimap mappend id ≈ mappend ∘ bimap id mappend ∘ to tensor_assoc
}.
Context `{@MonoidObject mon}.
Lemma mappend_assoc_sym :
mappend ∘ bimap id mappend ≈ mappend ∘ bimap mappend id ∘ (tensor_assoc ⁻¹).
Notation "mempty[ M ]" := (@mempty _ _ _ M)
(at level 9, format "mempty[ M ]") : category_scope.
Notation "mappend[ M ]" := (@mappend _ _ _ M)
(at level 9, format "mappend[ M ]") : category_scope.
(* A Monoid object in C defined in terms of the internal product is a monoid
in the usual sense (i.e., mappend reducing two objects to one).
ncatlab: "Classical monoids are of course just monoids in Set with the
cartesian product." *)
Definition Monoid := @MonoidObject C CC_Monoidal.
#[export] Program Instance Product_Monoid `(X : Monoid x) `(Y : Monoid y) :
@MonoidObject C CC_Monoidal (x × y) := {|
mempty := @mempty _ _ _ X △ @mempty _ _ _ Y;
mappend := split (@mappend _ _ _ X) (@mappend _ _ _ Y) ∘ toggle
|}.
spose (@mempty_left _ _ _ X) as HX.
spose (@mempty_left _ _ _ Y) as HY.
assert ((mempty[X] △ mempty[Y] ∘ exl) △ (id[x × y] ∘ exr)
≈ split (mempty[X] △ mempty[Y]) id[x × y])
by (unfork; cat).
rewrite exl_fork, exr_fork.
rewrite <- (id_right mempty[X]).
rewrite <- (id_left exl).
rewrite <- (id_right mempty[Y]).
rewrite <- (id_left exr).
now rewrite fork_comp; cat.
spose (@mempty_right _ _ _ X) as HX.
spose (@mempty_right _ _ _ Y) as HY.
assert ((id[x × y] ∘ exl) △ (mempty[X] △ mempty[Y] ∘ exr)
≈ split id[x × y] (mempty[X] △ mempty[Y]))
by (unfork; cat).
rewrite exl_fork, exr_fork.
rewrite <- (id_right mempty[X]).
rewrite <- (id_left exl).
rewrite <- (id_right mempty[Y]).
rewrite <- (id_left exr).
now rewrite fork_comp; cat.
spose (@mappend_assoc _ _ _ X) as HX.
spose (@mappend_assoc _ _ _ Y) as HY.
assert ((split mappend[X] mappend[Y] ∘ toggle ∘ exl) △ (id[x × y] ∘ exr)
≈ split (split mappend[X] mappend[Y] ∘ toggle) id[x × y])
by (unfork; cat).
assert ((id[x × y] ∘ exl) △ (split mappend[X] mappend[Y] ∘ toggle ∘ exr)
≈ split id[x × y] (split mappend[X] mappend[Y] ∘ toggle))
by (unfork; cat).
rewrite <- (id_left (exl (x:=x) (y:=y))) at 1.
rewrite <- (id_left (exr (x:=x) (y:=y))) at 1.
apply fork_respects; clear;
now unfold split; unfork; cat.
Definition doppel {x y z : C} : (x × y) × z ~> (x × z) × (y × z) :=
first exl △ first exr.
Lemma uncurry_exl_fork_exr {x y : C} :
uncurry exl △ uncurry exr ≈ split eval eval ∘ @doppel (y ^ x) (y ^ x) x.
#[export] Program Instance Hom_Monoid {x} `(Y : Monoid y) :
@MonoidObject C CC_Monoidal (y ^ x) := {
mempty := curry (@mempty _ _ _ Y ∘ exl);
mappend := curry (@mappend _ _ _ Y ∘ uncurry exl △ uncurry exr)
}.
spose (@mempty_left _ _ _ Y) as HY.
remember ((curry _ ∘ exl) △ (id[y ^ x] ∘ exr)) as h.
assert (h ≈ split (curry (mempty[Y] ∘ exl)) id[y ^ x])
by (rewrite Heqh; unfork; cat).
rewrite X; clear X Heqh h.
rewrite uncurry_exl_fork_exr.
rewrite <- (id_right mempty[Y]) at 1.
rewrite <- (id_left (uncurry id[y ^ x])).
now rewrite curry_uncurry.
spose (@mempty_right _ _ _ Y) as HY.
remember ((id[y ^ x] ∘ exl) △ (curry _ ∘ exr)) as h.
assert (h ≈ split id[y ^ x] (curry (mempty[Y] ∘ exl)))
by (rewrite Heqh; unfork; cat).
rewrite X; clear X Heqh h.
rewrite uncurry_exl_fork_exr.
rewrite <- (id_right mempty[Y]) at 1.
rewrite <- (id_left (uncurry id[y ^ x])).
now rewrite curry_uncurry.
spose (@mappend_assoc _ _ _ Y) as HY.
rewrite uncurry_exl_fork_exr.
remember ((curry _ ∘ exl) △ (id[y ^ x] ∘ exr)) as h.
assert (h ≈ split (curry (mappend[Y] ∘ split eval eval ∘ doppel)) id[y ^ x])
by (rewrite Heqh; unfork; cat).
rewrite X; clear X Heqh h.
remember ((id[y ^ x] ∘ exl) △ (curry _ ∘ exr)) as h.
assert (h ≈ split id[y ^ x] (curry (mappend[Y] ∘ split eval eval ∘ doppel)))
by (rewrite Heqh; unfork; cat).
rewrite X; clear X Heqh h.
rewrite <- !uncurry_comp.
rewrite <- (id_left (uncurry exr)).
now rewrite uncurry_curry.