Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Computational M-types #1233

Merged
merged 61 commits into from Jun 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
106800e
Start of Inductives.
LuisScoccola Dec 12, 2017
5c000de
Modified travis and Makefile.
LuisScoccola Dec 12, 2017
918e13c
Merged travis.
LuisScoccola Dec 12, 2017
205f3c2
Added a bit on coalgebras, added polynomial functors.
LuisScoccola Dec 12, 2017
77661cb
Trying to prove Lemma 5.1.8 in Felix's thesis.
LuisScoccola Dec 13, 2017
f6ebfab
Finished the proof of 5.1.8
LuisScoccola Dec 13, 2017
73a69c2
Closer to proving that WHom'(W, C) is contractible for every C.
LuisScoccola Dec 14, 2017
8d3d189
Proved that WHom'(W,C) is contractible for every C
LuisScoccola Dec 14, 2017
c4486e9
Proving WHom' is equivalent to WHom.
LuisScoccola Dec 14, 2017
6f69d5b
Finished proof that W is an initial algebra.
LuisScoccola Dec 16, 2017
7ca97ed
Fixed some typos.
LuisScoccola Dec 17, 2017
7e46c64
Cleaning algebras.v a bit
LuisScoccola Dec 24, 2017
5d51473
Cleaning addresses.v a bit
LuisScoccola Dec 24, 2017
116c4d7
Construct M-types from nat
s9ferech Jan 21, 2018
eaeaa40
Make M-types indexed
s9ferech Feb 8, 2018
2af232b
Extend M-types for judgmental computation rule
s9ferech Mar 7, 2018
54b9d06
the base file with the project context
rmatthes Apr 1, 2019
5182d39
WIP: Make W-types indexed
s9ferech Apr 1, 2019
4353399
WIP: Define mu- and nu-containers
s9ferech Apr 1, 2019
3f48ece
resolved conflicts
Apr 1, 2019
7dad77c
Merge branch 'LuisScoccola-master' into restorescoccolarech
Apr 1, 2019
ef9c646
most recent version of felix
Apr 1, 2019
d232b69
compiling version
Apr 1, 2019
39d8c34
epsilon
Apr 1, 2019
62c9fc3
my slides at the EUTYPES workshop in Nijmegen 2018 with comments on R…
rmatthes Apr 1, 2019
a68437a
Merge pull request #2 from unimath2019-ri/restorescoccolarech
dominik-kirst Apr 1, 2019
91d228c
Merge branch 'dev' of https://github.com/unimath2019-ri/UniMath into dev
rmatthes Apr 1, 2019
cea58a0
Merge branch 'master' into dev
rmatthes Apr 1, 2019
2417afc
independence of propositional resizing rule mentioned
rmatthes Apr 1, 2019
80f406d
forgotten commenting of non-compiling code
rmatthes Apr 1, 2019
26de029
Merge pull request #3 from unimath2019-ri/commentnoncompilingpart
rmatthes Apr 1, 2019
8ce0ddf
Added missing statements from Felix without proof.
Apr 2, 2019
409da2c
Merge branch 'dev' of https://github.com/unimath2019-ri/UniMath into dev
Apr 2, 2019
c101d8d
Proof of Lemma 11 from Non-wellfounded trees.
Apr 2, 2019
2fd92b7
starting on ComputationalM.v
Apr 2, 2019
d0a9431
Merge branch 'dev' of https://github.com/unimath2019-ri/UniMath into dev
Apr 2, 2019
48f9819
minor improvements
rmatthes Apr 2, 2019
3b9fbe2
Merge pull request #4 from unimath2019-ri/minorimprovementsoninductives
rmatthes Apr 2, 2019
e693b75
corecursive equation
dominik-kirst Apr 2, 2019
27cf1ce
morphism equation and refactoring
dominik-kirst Apr 3, 2019
f46e0cf
carriers are equal
dominik-kirst Apr 4, 2019
331188f
still working on equations
dominik-kirst Apr 4, 2019
54c3deb
proved finality plus cleanup
dominik-kirst Apr 5, 2019
00aa48b
inform makefile about ComputationalM.v, replace reflexivity by apply …
rmatthes Apr 6, 2019
5f49e04
replaces some projections by accessors (very shallow contribution)
rmatthes May 16, 2019
e48805d
Merge branch 'master' into computationalM
rmatthes May 16, 2019
3882ba9
shallow changes to reestablish compilation
rmatthes May 16, 2019
78858b7
wip on establishing isprop for the crucial property P
rmatthes May 16, 2019
242397f
fills the gaps in the development: P proven a proposition, fine-tunin…
rmatthes May 16, 2019
94893bd
epsilon
dominik-kirst Jun 3, 2019
e771582
delta
dominik-kirst Jun 3, 2019
ade382c
Merge branch 'master' into computationalM
rmatthes Jun 4, 2019
b55caed
corrects a left-over from the merge process
rmatthes Jun 4, 2019
5912b8a
some cleanup
rmatthes Jun 4, 2019
af3c4cd
erased remaining two upstream lemmas
dominik-kirst Jun 5, 2019
8a00fc4
modifies list of authors after email exchange with Dominik
rmatthes Jun 5, 2019
2473613
leaves out material on which project work at UniMathSchool 2019 was b…
rmatthes Jun 5, 2019
6e37919
tiny changes to minimize number of modified files in PR
rmatthes Jun 5, 2019
5d19115
description of PR integrated into introductory comments
rmatthes Jun 6, 2019
f6af06a
Defined replaces Qed everywhere, except for the lemma proved by idpath
rmatthes Jun 6, 2019
efb26ef
last Qed turned into Defined
rmatthes Jun 6, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions UniMath/CONTENTS.md
Expand Up @@ -448,4 +448,5 @@ The packages and files are listed here in logical order: each file depends only
- [W/Naturals.v](Induction/W/Naturals.v)
- [W/Uniqueness.v](Induction/W/Uniqueness.v)
- [M/Chains.v](Induction/M/Chains.v)
- [M/ComputationalM.v](Induction/M/ComputationalM.v)
- [All.v](Induction/All.v)
1 change: 1 addition & 0 deletions UniMath/Induction/.package/files
Expand Up @@ -7,3 +7,4 @@ W/Fibered.v
W/Naturals.v
W/Uniqueness.v
M/Chains.v
M/ComputationalM.v
308 changes: 308 additions & 0 deletions UniMath/Induction/M/ComputationalM.v
@@ -0,0 +1,308 @@
(** ** Refinement of M-types

M-types can be refined to satisfy the right definitional equalities.
This idea is from Felix Rech's Bachelor's thesis, and Felix
Rech also developed together with Luis Scoccola a first formalization
in UniMath as project work of the UniMath 2017 school. The present
formalization was obtained as project work of the UniMath 2019 school
and is heavily inspired by that former formalization.

Author: Dominik Kirst (@dominik-kirst) and Ralph Matthes (@rmatthes)

*)

Require Import UniMath.Foundations.All.
Require Import UniMath.MoreFoundations.All.

Require Import UniMath.CategoryTheory.Core.Categories.
Require Import UniMath.CategoryTheory.Core.Functors.
Require Import UniMath.CategoryTheory.FunctorCoalgebras.
Require Import UniMath.CategoryTheory.categories.Type.Core.

Require Import UniMath.Induction.PolynomialFunctors.
Require Import UniMath.Induction.M.Core.
Require Import UniMath.Induction.M.Uniqueness.

(**
The construction is called a refinement: as input we take any final coalgebra
for the respective polynomial functor describing an M-type (hence, with the
provable coiteration rule), the output is the refined final coalgebra with the
equational rule of coiteration holding definitionally: Lemma [corec_computation]
is proved merely by [idpath]. Of course, both coalgebras are equal - provably
(Lemma [coalgebras_eq]).
*)
Section Refinement.

Context (A : UU).
Context (B : A → UU).
Local Notation F := (polynomial_functor A B).

Variable M0 : coalgebra F.
Local Notation carrierM0 := (coalgebra_ob _ M0).
Local Notation destrM0 := (coalgebra_mor _ M0).

Variable finalM0 : is_final M0.
Local Notation corecM0 C := (pr11 (finalM0 C)).

Local Open Scope cat.
Local Open Scope functions.

(* Refinement of the final coalgebra to computable elements *)

Definition carrierM := ∑ m0 : carrierM0, ∃ C c, corecM0 C c = m0.

(* Definition of the corecursor *)

Definition corecM (C : coalgebra F) (c : coalgebra_ob _ C) : carrierM.
Proof.
exists (corecM0 C c). apply hinhpr. exists C, c. apply idpath.
Defined.

(* Definition of a proposition we factor the computation through *)

Local Definition P (m0 : carrierM0) :=
∑ af : F carrierM, destrM0 m0 = # F pr1 af.

(** in order to show [P] to be a proposition, a not obviously equivalent
formulation is given for which it is easy to show [isaprop] *)
Local Definition P' (m0 : carrierM0) :=
∑ ap : ∑ a : A, pr1 (destrM0 m0) = a,
∏ (b : B (pr1 ap)),
∑ mp : ∑ m0' : carrierM0,
transportf (λ a, B a -> carrierM0)
(pr2 ap)
(pr2 (destrM0 m0)) b =
m0',
∃ C c, corecM0 C c = pr1 mp.

(** the easy auxiliary lemma *)
Local Lemma P'_isaprop m0 :
isaprop (P' m0).
Proof.
apply isofhleveltotal2.
- apply isofhlevelcontr.
apply iscontrcoconusfromt.
- intro ap; induction ap as [a p].
apply impred; intros b.
apply isofhleveltotal2.
+ apply isofhlevelcontr.
apply iscontrcoconusfromt.
+ intro mp; induction mp as [m0' q].
apply isapropishinh.
Defined.

(** the crucial lemma *)
Local Lemma P_isaprop (m0 : carrierM0) :
isaprop (P m0).
Proof.
use (@isofhlevelweqb _ _ (P' m0) _ (P'_isaprop m0)).
simple refine (weqcomp (weqtotal2asstor _ _) _).
simple refine (weqcomp _ (invweq (weqtotal2asstor _ _))).
apply weqfibtototal; intro a.
intermediate_weq (
∑ f : B a → carrierM,
∑ p : pr1 (destrM0 m0) = a,
transportf
(λ a, B a -> carrierM0)
p
(pr2 (destrM0 m0)) =
pr1 ∘ f).
{
apply weqfibtototal; intro f.
apply total2_paths_equiv.
}
intermediate_weq (∑ p : pr1 (destrM0 m0) = a,
∑ f : B a → carrierM,
transportf
(λ a, B a → carrierM0)
p
(pr2 (destrM0 m0)) =
pr1 ∘ f).
{ apply weqtotal2comm. }
apply weqfibtototal; intro p.
intermediate_weq (∑ fg : ∑ f : B a -> carrierM0,
∏ b, ∃ C c, corecM0 C c = f b,
transportf
(λ a, B a -> carrierM0)
p
(pr2 (destrM0 m0)) =
pr1 fg).
{ use weqbandf.
- apply weqfuntototaltototal.
- cbn.
intro f.
apply idweq.
}
intermediate_weq (∑ f : B a → carrierM0,
∑ _ : ∏ b, ∃ C c, corecM0 C c = f b,
transportf
(λ a, B a → carrierM0)
p
(pr2 (destrM0 m0)) =
f).
{ apply weqtotal2asstor. }
intermediate_weq (∑ f : B a → carrierM0,
∑ _ : ∏ b, ∃ C c, corecM0 C c = f b,
∏ b, transportf
(λ a, B a → carrierM0)
p
(pr2 (destrM0 m0)) b =
f b).
{ apply weqfibtototal; intro f.
apply weqfibtototal; intros _.
apply weqtoforallpaths.
}
intermediate_weq (∑ f : B a → carrierM0,
∏ b, ∑ _ : ∃ C c, corecM0 C c = f b,
transportf
(λ a, B a → carrierM0)
p
(pr2 (destrM0 m0)) b =
f b).
{ apply weqfibtototal; intro f.
apply invweq.
apply weqforalltototal.
}
intermediate_weq (∏ b, ∑ m0' : carrierM0,
∑ _ : ∃ C c, corecM0 C c = m0',
transportf
(λ a, B a -> carrierM0)
p
(pr2 (destrM0 m0)) b =
m0').
{ apply invweq.
apply weqforalltototal.
}
apply weqonsecfibers; intro b.
intermediate_weq (∑ m0' : carrierM0,
∑ _ : transportf
(λ a, B a -> carrierM0)
p
(pr2 (destrM0 m0)) b =
m0',
∃ C c, corecM0 C c = m0').
{
apply weqfibtototal; intro m0'.
apply weqdirprodcomm.
}
intermediate_weq (∑ mp : ∑ m0', transportf (λ a, B a → carrierM0) p
(pr2 (destrM0 m0)) b = m0',
∃ C c, corecM0 C c = pr1 mp).
{
apply invweq.
apply weqtotal2asstor.
}
use weqbandf.
- apply weqfibtototal; intro m0'.
apply idweq.
- cbn. intro mp.
apply idweq.
Defined.

(* Now the destructor of M can be defined *)

Local Definition destrM' (m : carrierM) : P (pr1 m).
Proof.
induction m as [m0 H]. apply (squash_to_prop H); try apply P_isaprop.
intros [C [c H1]].
refine ((# F (corecM C) ∘ (pr2 C)) c,, _). cbn [pr1]. clear H.
assert (H : is_coalgebra_homo F (corecM0 C)).
{ destruct finalM0 as [[G H] H']. apply H. }
apply toforallpaths in H.
apply pathsinv0.
intermediate_path (destrM0 (corecM0 C c)).
- apply H.
- apply maponpaths. assumption.
Defined.

Definition destrM (m : carrierM) : F carrierM :=
pr1 (destrM' m).

Definition M : coalgebra F :=
(carrierM,, destrM).

(* The destructor satisfies the corecursion equation definitionally *)

Lemma corec_computation C c :
destrM (corecM C c) = # F (corecM C) (pr2 C c).
Proof.
apply idpath.
Defined.

(* The two carriers are equal *)

Lemma eq_corecM0 m0 :
corecM0 M0 m0 = m0.
Proof.
induction finalM0 as [[G H1] H2]. cbn.
specialize (H2 (coalgebra_homo_id F M0)).
change (pr1 (G,, H1) m0 = pr1 (coalgebra_homo_id F M0) m0).
apply (maponpaths (fun X => pr1 X m0)).
apply pathsinv0.
assumption.
Defined.

Definition injectM0 m0 :
∃ C c, corecM0 C c = m0.
Proof.
apply hinhpr. exists M0, m0. apply eq_corecM0.
Defined.

Lemma carriers_weq :
carrierM ≃ carrierM0.
Proof.
apply (weq_iso pr1 (λ m0, m0,, injectM0 m0)).
- intros [m H]. cbn. apply maponpaths, ishinh_irrel.
- intros x. cbn. apply idpath.
Defined.

Lemma carriers_eq :
carrierM = carrierM0.
Proof.
apply weqtopaths, carriers_weq.
Defined. (** needs to be transparent *)

(* The two coalgebras are equal *)

Local Lemma eq1 (m0 : carrierM0) :
transportf (λ X, X → F X) carriers_eq destrM m0
= transportf (λ X, F X) carriers_eq (destrM (transportf (λ X, X) (!carriers_eq) m0)).
Proof.
destruct carriers_eq. apply idpath.
Defined.

Local Lemma eq2 (m0 : carrierM0) :
transportf (λ X, X) (!carriers_eq) m0 = m0,, injectM0 m0.
Proof.
apply (transportf_pathsinv0' (idfun UU) carriers_eq).
unfold carriers_eq. rewrite weqpath_transport. apply idpath.
Defined.

Local Lemma eq3 m0 :
destrM (m0,, injectM0 m0) = pr1 (destrM0 m0),, corecM M0 ∘ pr2 (destrM0 m0).
Proof.
apply idpath.
Defined.

Lemma coalgebras_eq :
M = M0.
Proof.
use total2_paths_f; try apply carriers_eq.
apply funextfun. intro m0.
rewrite eq1. rewrite eq2. rewrite eq3.
cbn. unfold polynomial_functor_obj.
rewrite transportf_total2_const.
use total2_paths_f; try apply idpath.
cbn. apply funextsec. intros b. rewrite <- helper_A.
unfold carriers_eq. rewrite weqpath_transport.
cbn. rewrite eq_corecM0. apply idpath.
Defined.

(* Thus M is final *)

Lemma finalM : is_final M.
Proof.
rewrite coalgebras_eq. apply finalM0.
Defined.

End Refinement.
10 changes: 10 additions & 0 deletions UniMath/MoreFoundations/PartA.v
Expand Up @@ -578,6 +578,16 @@ Proof.
intros. induction p. reflexivity.
Defined.


Lemma transportf_total2_const (A B : UU) (P : B -> A -> UU) (b : B) (a1 a2 : A) (e : a1 = a2) (p : P b a1) :
transportf (λ x, ∑ y, P y x) e (b,, p) = b,, transportf (P b) e p.
Proof.
induction e.
apply idpath.
Defined.



(** ** h-levels and paths *)

Lemma isaprop_wma_inhab X : (X -> isaprop X) -> isaprop X.
Expand Down