Timings for Hartogs.v
From HoTT Require Import TruncType ExcludedMiddle Modalities.ReflectiveSubuniverse abstract_algebra HSet.
From HoTT Require Import Universes.Smallness.
From HoTT Require Import Spaces.Card.
From HoTT.Sets Require Import Ordinals Powers.
(** This file contains a construction of the Hartogs number. *)
(** We begin with some results about changing the universe of a power set using propositional resizing. *)
Definition power_inj `{PropResizing} {C : Type@{i}} (p : C -> HProp@{j})
: C -> HProp@{k}.
exact (fun a => Build_HProp (smalltype@{k j} (p a))).
Lemma injective_power_inj `{PropResizing} {ua : Univalence} (C : Type@{i})
: IsInjective (@power_inj _ C).
apply path_iff_hprop; intros Ha.
change ((fun a => Build_HProp (smalltype (p' a))) a).
change ((fun a => Build_HProp (smalltype (p a))) a).
(* TODO: Could factor this as something keeping the [HProp] universe the same, followed by [power_inj]. *)
Definition power_morph `{PropResizing} {ua : Univalence} {C B : Type@{i}} (f : C -> B)
: (C -> HProp) -> (B -> HProp).
exact (Build_HProp (smalltype (forall a, f a = b -> p a))).
Definition injective_power_morph `{PropResizing} {ua : Univalence} {C B : Type@{i}} (f : C -> B)
: IsInjective f -> IsInjective (@power_morph _ _ C B f).
apply path_iff_hprop; intros Ha.
enough (Hp : power_morph f p (f a)).
apply equiv_smalltype in Hp.
enough (Hp : power_morph f p' (f a)).
apply equiv_smalltype in Hp.
(** We'll also need this result. *)
Lemma le_Cardinal_lt_Ordinal `{PropResizing} `{Univalence} (B C : Ordinal)
: B < C -> card B β€ card C.
rewrite (bound_property B_C).
apply isinjective_simulation.
Notation "'π«'" := power_type (at level 30) : Hartogs.
Local Coercion subtype_as_type' {X} (Y : π« X) := { x : X & Y x }.
Context {univalence : Univalence}
{prop_resizing : PropResizing}
{lem: ExcludedMiddle}
(A : HSet@{A}).
(* The Hartogs number of [A] consists of all ordinals that embed into [A]. Note that this construction necessarily increases the universe level. *)
Fail Check { B : Ordinal@{A _} | card B <= card A } : Type@{A}.
Definition hartogs_number' : Ordinal.
set (carrier := {B : Ordinal@{A _} & card B <= card A}).
set (relation := fun (B C : carrier) => B.1 < C.1).
snapply (isordinal_simulation pr1).
apply isinj_embedding, (mapinO_pr1 (Tr (-1))).
(* Faster than [exact _.] *)
intros [B small_B] C C_B; cbn in *.
unshelve eexists (C; _); cbn; auto.
intros [f isinjective_f].
exists (fun '(x; x_b) => f x); cbn.
intros [x x_b] [y y_b] fx_fy.
apply path_sigma_hprop; cbn.
apply (isinjective_f x y).
Definition proper_subtype_inclusion (U V : π« A)
:= (forall a, U a -> V a) /\ merely (exists a : A, V a /\ ~(U a)).
Infix "β" := proper_subtype_inclusion (at level 50) : Hartogs.
Notation "(β)" := proper_subtype_inclusion : Hartogs.
(* The Hartogs number of [A] embeds into the threefold power set of [A]. This preliminary injection also increases the universe level though. *)
Lemma hartogs_number'_injection
: exists f : hartogs_number' -> (π« (π« (π« A))), IsInjective f.
transparent assert (Ο : (forall X : π« (π« A), Lt X)).
exact (merely (Isomorphism (X : Type; Ο X) B)).
intros [B B_A] [C C_A] H0.
apply path_sigma_hprop; cbn.
apply equiv_path_Ordinal.
assert {X : π« (π« A) & Isomorphism (X : Type; Ο X) B} as [X iso].
assert (H2 :
forall X : π« A,
IsHProp { b : B & forall a, X a <-> exists b', b' < b /\ a = f b' }).
apply hprop_allpath; intros [b1 Hb1] [b2 Hb2].
snapply path_sigma_hprop; cbn.
rapply ishprop_sigma_disjoint.
intros b1' b2' [_ ->] [_ p].
specialize (Hb1 (b'; (b'_b1, idpath))).
destruct Hb1 as (? & H2 & H3).
specialize (Hb2 (b'; (b'_b2, idpath))).
destruct Hb2 as (? & H2 & H3).
exists (fun X : π« A =>
Build_HProp { b : B & forall a, X a <-> exists b', b' < b /\ a = f b' }).
srapply equiv_adjointify.
unshelve eexists (fun a => Build_HProp (exists b', b' < b /\ a = f b')).
intros [b1 [b1_b p]] [b2 [b2_b q]].
apply path_sigma_hprop; cbn.
apply path_forall; intros a.
apply path_iff_hprop; apply Hb.
intros [X1 [b1 H'1]] [X2 [b2 H'2]].
unfold Ο, proper_subtype_inclusion.
refine (Trunc_rec _ (trichotomy_ordinal b1 b2)).
intros [a [X2a not_X1a]].
intros [a [X2a not_X1a]].
destruct X2a as [b' [b'_b2 a_fb']].
transitivity b2; assumption.
destruct X1a as [b' [b'_b1 a_fb']].
transitivity b1; assumption.
destruct X1_fb1 as [b' [b'_b1 fb1_fb']].
apply (injective f) in fb1_fb'.
apply irreflexivity in b'_b1.
assert (IsOrdinal X (Ο X)) by exact (isordinal_simulation iso.1).
refine (transitive_Isomorphism _ (X : Type; Ο X) _ _ _).
apply isomorphism_inverse.
enough (merely (Isomorphism (X : Type; Ο X) C)).
exact (ishprop_Isomorphism (Build_Ordinal X (Ο X) _) C).
(** Using hprop resizing, the threefold power set can be pushed to the same universe level as [A]. *)
Definition uni_fix (X : π« (π« (π« A))) : ((π« (π« (π« A))) : Type@{A}).
Lemma injective_uni_fix : IsInjective uni_fix.
intros H % injective_power_morph; trivial.
intros H' % injective_power_morph; trivial.
apply injective_power_inj.
(* We can therefore resize the Hartogs number of A to the same universe level as A. *)
Definition hartogs_number_carrier : Type@{A}
:= {X : π« (π« (π« A)) | smalltype (merely (exists a, uni_fix (hartogs_number'_injection.1 a) = X))}.
Lemma hartogs_equiv : hartogs_number_carrier <~> hartogs_number'.
exists (uni_fix (hartogs_number'_injection.1 a)).
apply equiv_smalltype, tr.
snapply isequiv_surj_emb.
eapply equiv_smalltype, HX.
apply isembedding_isinj_hset.
specialize (injective_uni_fix (hartogs_number'_injection.1 a) (hartogs_number'_injection.1 b)).
by apply hartogs_number'_injection.2.
Definition hartogs_number : Ordinal@{A _}
:= resize_ordinal hartogs_number' hartogs_number_carrier hartogs_equiv.
(* This final definition by satisfies the expected cardinality properties. *)
Lemma hartogs_number_injection
: exists f : hartogs_number -> π« (π« (π« A)), IsInjective f.
Lemma hartogs_number_no_injection
: ~ (exists f : hartogs_number -> A, IsInjective f).
assert (HN : card hartogs_number <= card A).
transparent assert (HNO : hartogs_number').
apply (ordinal_initial hartogs_number' HNO).
eapply (transitive_Isomorphism hartogs_number' hartogs_number).
apply isomorphism_inverse.
exact (resize_ordinal_iso hartogs_number' hartogs_number_carrier hartogs_equiv).
assert (Isomorphism hartogs_number βhartogs_number) by apply isomorphism_to_initial_segment.
eapply transitive_Isomorphism.
srapply equiv_adjointify.
intros [a Ha % equiv_smalltype].
transitivity (card hartogs_number).
napply le_Cardinal_lt_Ordinal; exact Ha.
intros [[a Ha] H % equiv_smalltype].