2017-08-02 14:14:14 +02:00
|
|
|
|
Require Import HoTT HitTactics.
|
2017-09-07 15:19:48 +02:00
|
|
|
|
Require Import sub lattice_interface lattice_examples FSets.
|
2017-08-02 14:14:14 +02:00
|
|
|
|
|
|
|
|
|
Section k_finite.
|
|
|
|
|
|
2017-08-03 15:10:01 +02:00
|
|
|
|
Context (A : Type).
|
2017-08-02 14:14:14 +02:00
|
|
|
|
Context `{Univalence}.
|
|
|
|
|
|
2017-08-08 17:44:27 +02:00
|
|
|
|
Definition map (X : FSet A) : Sub A := fun a => a ∈ X.
|
2017-08-02 14:14:14 +02:00
|
|
|
|
|
2017-08-03 23:21:43 +02:00
|
|
|
|
Global Instance map_injective : IsEmbedding map.
|
2017-08-02 14:14:14 +02:00
|
|
|
|
Proof.
|
|
|
|
|
apply isembedding_isinj_hset. (* We use the fact that both [FSet A] and [Sub A] are hSets *)
|
|
|
|
|
intros X Y HXY.
|
|
|
|
|
apply fset_ext.
|
|
|
|
|
apply apD10. exact HXY.
|
|
|
|
|
Defined.
|
|
|
|
|
|
|
|
|
|
Definition Kf_sub_intern (B : Sub A) := exists (X : FSet A), B = map X.
|
|
|
|
|
|
|
|
|
|
Instance Kf_sub_hprop B : IsHProp (Kf_sub_intern B).
|
|
|
|
|
Proof.
|
|
|
|
|
apply hprop_allpath.
|
|
|
|
|
intros [X PX] [Y PY].
|
|
|
|
|
assert (X = Y) as HXY.
|
|
|
|
|
{ apply fset_ext. apply apD10.
|
|
|
|
|
transitivity B; [ symmetry | ]; assumption. }
|
|
|
|
|
apply path_sigma with HXY. simpl.
|
|
|
|
|
apply set_path2.
|
|
|
|
|
Defined.
|
|
|
|
|
|
|
|
|
|
Definition Kf_sub (B : Sub A) : hProp := BuildhProp (Kf_sub_intern B).
|
|
|
|
|
|
|
|
|
|
Definition Kf : hProp := Kf_sub (fun x => True).
|
|
|
|
|
|
2017-08-03 15:10:01 +02:00
|
|
|
|
Instance: IsHProp {X : FSet A & forall a : A, map X a}.
|
2017-08-02 14:14:14 +02:00
|
|
|
|
Proof.
|
2017-08-03 15:10:01 +02:00
|
|
|
|
apply hprop_allpath.
|
|
|
|
|
intros [X PX] [Y PY].
|
|
|
|
|
assert (X = Y) as HXY.
|
|
|
|
|
{ apply fset_ext. intros a.
|
|
|
|
|
unfold map in *.
|
|
|
|
|
apply path_hprop.
|
|
|
|
|
apply equiv_iff_hprop; intros.
|
|
|
|
|
+ apply PY.
|
|
|
|
|
+ apply PX. }
|
|
|
|
|
apply path_sigma with HXY. simpl.
|
|
|
|
|
apply path_forall. intro.
|
|
|
|
|
apply path_ishprop.
|
|
|
|
|
Defined.
|
|
|
|
|
|
|
|
|
|
Lemma Kf_unfold : Kf <~> (exists (X : FSet A), forall (a : A), map X a).
|
|
|
|
|
Proof.
|
|
|
|
|
apply equiv_equiv_iff_hprop. apply _. apply _.
|
2017-08-02 14:14:14 +02:00
|
|
|
|
split.
|
|
|
|
|
- intros [X PX]. exists X. intro a.
|
|
|
|
|
rewrite <- PX. done.
|
|
|
|
|
- intros [X PX]. exists X. apply path_forall; intro a.
|
|
|
|
|
apply path_hprop.
|
|
|
|
|
symmetry. apply if_hprop_then_equiv_Unit; [ apply _ | ].
|
|
|
|
|
apply PX.
|
|
|
|
|
Defined.
|
|
|
|
|
|
|
|
|
|
End k_finite.
|
2017-08-03 15:07:53 +02:00
|
|
|
|
|
2017-08-03 15:10:01 +02:00
|
|
|
|
Arguments map {_} {_} _.
|
|
|
|
|
|
2017-08-03 15:07:53 +02:00
|
|
|
|
Section structure_k_finite.
|
2017-08-03 15:10:01 +02:00
|
|
|
|
Context (A : Type).
|
2017-08-03 15:07:53 +02:00
|
|
|
|
Context `{Univalence}.
|
|
|
|
|
|
2017-08-08 17:44:27 +02:00
|
|
|
|
Lemma map_union : forall X Y : FSet A, map (X ∪ Y) = max_fun (map X) (map Y).
|
2017-08-03 15:07:53 +02:00
|
|
|
|
Proof.
|
|
|
|
|
intros.
|
|
|
|
|
unfold map, max_fun.
|
|
|
|
|
reflexivity.
|
|
|
|
|
Defined.
|
2017-08-03 15:10:01 +02:00
|
|
|
|
|
2017-08-08 17:44:27 +02:00
|
|
|
|
Lemma k_finite_union : closedUnion (Kf_sub A).
|
2017-08-03 15:07:53 +02:00
|
|
|
|
Proof.
|
2017-08-08 17:44:27 +02:00
|
|
|
|
unfold closedUnion, Kf_sub, Kf_sub_intern.
|
2017-08-03 15:07:53 +02:00
|
|
|
|
intros.
|
|
|
|
|
destruct X0 as [SX XP].
|
|
|
|
|
destruct X1 as [SY YP].
|
2017-08-08 17:44:27 +02:00
|
|
|
|
exists (SX ∪ SY).
|
2017-08-03 15:07:53 +02:00
|
|
|
|
rewrite map_union.
|
|
|
|
|
rewrite XP, YP.
|
|
|
|
|
reflexivity.
|
|
|
|
|
Defined.
|
|
|
|
|
|
2017-08-08 17:44:27 +02:00
|
|
|
|
Lemma k_finite_empty : closedEmpty (Kf_sub A).
|
2017-08-03 15:07:53 +02:00
|
|
|
|
Proof.
|
2017-08-08 17:44:27 +02:00
|
|
|
|
exists ∅.
|
2017-08-03 15:07:53 +02:00
|
|
|
|
reflexivity.
|
|
|
|
|
Defined.
|
|
|
|
|
|
2017-08-08 17:44:27 +02:00
|
|
|
|
Lemma k_finite_singleton : closedSingleton (Kf_sub A).
|
2017-08-03 15:07:53 +02:00
|
|
|
|
Proof.
|
|
|
|
|
intro.
|
2017-08-08 17:44:27 +02:00
|
|
|
|
exists {|a|}.
|
2017-08-03 15:07:53 +02:00
|
|
|
|
cbn.
|
|
|
|
|
apply path_forall.
|
2017-08-09 18:05:58 +02:00
|
|
|
|
intro z.
|
2017-08-03 15:07:53 +02:00
|
|
|
|
reflexivity.
|
|
|
|
|
Defined.
|
|
|
|
|
|
2017-08-03 15:10:01 +02:00
|
|
|
|
Lemma k_finite_hasDecidableEmpty : hasDecidableEmpty (Kf_sub A).
|
2017-08-03 15:07:53 +02:00
|
|
|
|
Proof.
|
2017-08-08 17:44:27 +02:00
|
|
|
|
unfold hasDecidableEmpty, closedEmpty, Kf_sub, Kf_sub_intern, map.
|
2017-08-03 15:07:53 +02:00
|
|
|
|
intros.
|
|
|
|
|
destruct X0 as [SX EX].
|
|
|
|
|
rewrite EX.
|
2017-08-14 12:43:15 +02:00
|
|
|
|
destruct (merely_choice SX) as [SXE | H1].
|
2017-08-03 15:07:53 +02:00
|
|
|
|
- rewrite SXE.
|
|
|
|
|
apply (tr (inl idpath)).
|
|
|
|
|
- apply (tr (inr H1)).
|
|
|
|
|
Defined.
|
|
|
|
|
End structure_k_finite.
|
2017-08-16 16:07:51 +02:00
|
|
|
|
|
|
|
|
|
Section k_properties.
|
|
|
|
|
Context `{Univalence}.
|
|
|
|
|
|
|
|
|
|
Lemma Kf_surjection {X Y : Type} (f : X -> Y) `{IsSurjection f} :
|
|
|
|
|
Kf X -> Kf Y.
|
|
|
|
|
Proof.
|
|
|
|
|
intros HX. apply Kf_unfold. apply Kf_unfold in HX.
|
|
|
|
|
destruct HX as [Xf HXf].
|
2017-09-07 15:19:48 +02:00
|
|
|
|
exists (fmap FSet f Xf).
|
2017-08-16 16:07:51 +02:00
|
|
|
|
intro y.
|
|
|
|
|
pose (x' := center (merely (hfiber f y))).
|
|
|
|
|
simple refine (@Trunc_rec (-1) (hfiber f y) _ _ _ x'). clear x'; intro x.
|
|
|
|
|
destruct x as [x Hfx]. rewrite <- Hfx.
|
|
|
|
|
apply fmap_isIn.
|
|
|
|
|
apply (HXf x).
|
|
|
|
|
Defined.
|
2017-08-16 17:13:08 +02:00
|
|
|
|
|
|
|
|
|
Lemma S1_Kfinite : Kf S1.
|
|
|
|
|
Proof.
|
|
|
|
|
apply Kf_unfold.
|
|
|
|
|
exists {|base|}.
|
|
|
|
|
intro a. simpl.
|
|
|
|
|
simple refine (S1_ind (fun z => Trunc (-1) (z = base)) _ _ a); simpl.
|
|
|
|
|
- apply (tr loop).
|
|
|
|
|
- apply path_ishprop.
|
|
|
|
|
Defined.
|
2017-08-17 22:43:22 +02:00
|
|
|
|
|
|
|
|
|
Lemma I_Kfinite : Kf interval.
|
|
|
|
|
Proof.
|
|
|
|
|
apply Kf_unfold.
|
|
|
|
|
exists {|Interval.one|}.
|
|
|
|
|
intro a. simpl.
|
|
|
|
|
simple refine (interval_ind (fun z => Trunc (-1) (z = Interval.one)) _ _ _ a); simpl.
|
|
|
|
|
- apply (tr seg).
|
|
|
|
|
- apply (tr idpath).
|
|
|
|
|
- apply path_ishprop.
|
|
|
|
|
Defined.
|
|
|
|
|
|
2017-08-16 16:07:51 +02:00
|
|
|
|
End k_properties.
|
2017-08-18 11:34:04 +02:00
|
|
|
|
|
|
|
|
|
Section alternative_definition.
|
|
|
|
|
Context `{Univalence} {A : Type}.
|
|
|
|
|
|
|
|
|
|
Definition kf_sub (P : A -> hProp) :=
|
|
|
|
|
BuildhProp(forall (K' : (A -> hProp) -> hProp),
|
|
|
|
|
K' ∅ -> (forall a, K' {|a|}) -> (forall U V, K' U -> K' V -> K'(U ∪ V))
|
|
|
|
|
-> K' P).
|
|
|
|
|
|
|
|
|
|
Local Ltac help_solve :=
|
|
|
|
|
repeat (let x := fresh in intro x ; destruct x) ; intros
|
|
|
|
|
; try (simple refine (path_sigma _ _ _ _ _)) ; try (apply path_ishprop) ; simpl
|
2017-09-07 15:19:48 +02:00
|
|
|
|
; unfold union, sub_union, max_fun
|
2017-08-18 11:34:04 +02:00
|
|
|
|
; apply path_forall
|
|
|
|
|
; intro z
|
|
|
|
|
; eauto with lattice_hints typeclass_instances.
|
|
|
|
|
|
|
|
|
|
Definition fset_to_k : FSet A -> {P : A -> hProp & kf_sub P}.
|
|
|
|
|
Proof.
|
|
|
|
|
hinduction.
|
|
|
|
|
- exists ∅.
|
|
|
|
|
auto.
|
|
|
|
|
- intros a.
|
|
|
|
|
exists {|a|}.
|
|
|
|
|
auto.
|
|
|
|
|
- intros [P1 HP1] [P2 HP2].
|
|
|
|
|
exists (P1 ∪ P2).
|
|
|
|
|
intros ? ? ? HP.
|
|
|
|
|
apply HP.
|
|
|
|
|
* apply HP1 ; assumption.
|
|
|
|
|
* apply HP2 ; assumption.
|
|
|
|
|
- help_solve.
|
|
|
|
|
- help_solve.
|
|
|
|
|
- help_solve.
|
|
|
|
|
- help_solve.
|
|
|
|
|
- help_solve.
|
|
|
|
|
Defined.
|
|
|
|
|
|
|
|
|
|
Definition k_to_fset : {P : A -> hProp & kf_sub P} -> FSet A.
|
|
|
|
|
Proof.
|
|
|
|
|
intros [P HP].
|
|
|
|
|
destruct (HP (Kf_sub _) (k_finite_empty _) (k_finite_singleton _) (k_finite_union _)).
|
|
|
|
|
assumption.
|
|
|
|
|
Defined.
|
|
|
|
|
|
|
|
|
|
Lemma fset_to_k_to_fset X : k_to_fset(fset_to_k X) = X.
|
|
|
|
|
Proof.
|
|
|
|
|
hinduction X ; try (intros ; apply path_ishprop) ; try (intros ; reflexivity).
|
|
|
|
|
intros X1 X2 HX1 HX2.
|
|
|
|
|
refine ((ap (fun z => _ ∪ z) HX2^)^ @ (ap (fun z => z ∪ X2) HX1^)^).
|
|
|
|
|
Defined.
|
|
|
|
|
|
|
|
|
|
Lemma k_to_fset_to_k (X : {P : A -> hProp & kf_sub P}) : fset_to_k(k_to_fset X) = X.
|
|
|
|
|
Proof.
|
|
|
|
|
simple refine (path_sigma _ _ _ _ _) ; try (apply path_ishprop).
|
|
|
|
|
apply path_forall.
|
|
|
|
|
intro z.
|
|
|
|
|
destruct X as [P HP].
|
|
|
|
|
unfold kf_sub in HP.
|
|
|
|
|
unfold k_to_fset.
|
|
|
|
|
pose (HP (Kf_sub A) (k_finite_empty A) (k_finite_singleton A) (k_finite_union A)) as t.
|
|
|
|
|
assert (HP (Kf_sub A) (k_finite_empty A) (k_finite_singleton A) (k_finite_union A) = t) as X0.
|
|
|
|
|
{ reflexivity. }
|
|
|
|
|
rewrite X0 ; clear X0.
|
|
|
|
|
destruct t as [X HX].
|
|
|
|
|
assert (P z = map X z) as X1.
|
|
|
|
|
{ rewrite HX. reflexivity. }
|
|
|
|
|
simpl.
|
|
|
|
|
rewrite X1 ; clear HX X1.
|
|
|
|
|
hinduction X ; try (intros ; apply path_ishprop).
|
|
|
|
|
- apply idpath.
|
|
|
|
|
- apply (fun a => idpath).
|
|
|
|
|
- intros X1 X2 H1 H2.
|
|
|
|
|
rewrite <- H1, <- H2.
|
|
|
|
|
reflexivity.
|
|
|
|
|
Defined.
|
|
|
|
|
|
|
|
|
|
Theorem equiv_definition : IsEquiv fset_to_k.
|
|
|
|
|
Proof.
|
|
|
|
|
apply isequiv_biinv.
|
|
|
|
|
split.
|
|
|
|
|
- exists k_to_fset.
|
|
|
|
|
intro x ; apply fset_to_k_to_fset.
|
|
|
|
|
- exists k_to_fset.
|
|
|
|
|
intro x ; apply k_to_fset_to_k.
|
|
|
|
|
Defined.
|
|
|
|
|
|
|
|
|
|
End alternative_definition.
|