(*| 整列順序 ======== |*) Require Import function. Require Import power. Require Import relation. From Stdlib Require Import Logic.Description. From Stdlib Require Import Logic.FunctionalExtensionality. Set Implicit Arguments. (*| HoTT Bookの10章に従う。 |*) Section WellOrder. Variable X : Type. Variable R : bin_rel X. Inductive accessible (a : X) : Prop := | acc : (forall b, R b a -> accessible b) -> accessible a. Check accessible_ind. Check accessible_rect. Definition well_founded : Prop := forall a, accessible a. Definition extensional : Prop := forall a b, (forall c, R c a <-> R c b) -> a = b. Definition transitive : Prop := forall a b c, R a b -> R b c -> R a c. Definition is_well_order : Prop := well_founded /\ extensional /\ transitive. End WellOrder. Record well_order (X : Type) : Type := make_well_order { R :> bin_rel X; R_is_well_order :> is_well_order R; }. Definition well_ordered_type : Type := { X : Type & well_order X }. Definition proj_well_ordered_type (X : well_ordered_type) : Type := projT1 X. Coercion proj_well_ordered_type : well_ordered_type >-> Sortclass. Definition initial_segment (X : Type) (R : well_order X) (x : X) : power X := fun y => R y x. Section Simulation. Variables (X : Type) (Y : Type). Definition is_simulation (P : well_order X) (Q : well_order Y) (f : X -> Y) : Prop := forall x : X, image f (initial_segment P x) = initial_segment Q (f x). Definition monotone (P : bin_rel X) (Q : bin_rel Y) (f : X -> Y) : Prop := forall x x' : X, P x x' -> Q (f x) (f x'). Lemma simulation_is_monotone (P : well_order X) (Q : well_order Y) (f : X -> Y) : is_simulation P Q f -> monotone P Q f. Proof. unfold monotone. intros. specialize (H x'). apply (f_equal (fun g => g (f x))) in H. unfold initial_segment, image, mem in H. rewrite<- H. exists x. split; [exact H0 | reflexivity]. Qed. Lemma simulation_characterization (P : well_order X) (Q : well_order Y) (f : X -> Y) : is_simulation P Q f <-> ( monotone P Q f /\ forall x, forall y, Q y (f x) -> exists x', P x' x /\ f x' = y ). Proof. split; intro. - (* .unfold *) split. + (* .unfold *) apply simulation_is_monotone. assumption. + (* .unfold *) intros. specialize (H x). unfold initial_segment in H. apply (f_equal (fun f => f y)) in H. rewrite<- H in H0. unfold image, mem in H0. assumption. - (* .unfold *) destruct H. unfold is_simulation. intro. apply inclusion_antisymmetric. + intros y H1. unfold initial_segment, mem. unfold image, initial_segment, mem in H1. destruct H1 as [x0 [H1 H2]]. subst y. apply H. assumption. + intros y H1. unfold image, initial_segment, mem. unfold initial_segment, mem in H1. specialize (H0 x y H1). assumption. Qed. (*| Simulationは単射である。 |*) Lemma simulation_is_injective (P : well_order X) (Q : well_order Y) (f : X -> Y) : is_simulation P Q f -> injective f. Proof. intros H x. destruct P as [P [H1 [H2 H3]]]. induction (H1 x). intros x' H5. apply H2. intro. apply simulation_characterization in H. simpl in H. destruct H as [H H6]. split; intro. - specialize (H c a H7). rewrite H5 in H. specialize (H6 _ _ H). destruct H6 as [x [H6 H8]]. rewrite<- H8 in H. symmetry in H8. specialize (H4 _ H7 _ H8). subst x. exact H6. - specialize (H _ _ H7). rewrite<- H5 in H. specialize (H6 _ _ H). destruct H6 as [x [H8 H10]]. rewrite<- H10 in H. specialize (H4 _ H8 _ H10). subst x. exact H8. Qed. Lemma simulation_helper_unique (P : well_order X) (Q : well_order Y) (f : X -> Y) : is_simulation P Q f -> forall x, forall y, Q y (f x) -> exists! x', P x' x /\ f x' = y. Proof. intros. apply simulation_characterization in H as H'. destruct H' as [_ H']. specialize (H' x y H0). destruct H'. exists x0. unfold unique. split. - assumption. - intros. destruct H1, H2. subst y. symmetry. apply (simulation_is_injective H). assumption. Qed. Definition simulation_helper_data (P : well_order X) (Q : well_order Y) (f : X -> Y) : is_simulation P Q f -> forall x, forall y, Q y (f x) -> X. Proof. intros. pose proof ( constructive_definite_description _ (simulation_helper_unique H x y H0) ) as H1. exact (proj1_sig H1). Defined. Definition simulation_helper_prop (P : well_order X) (Q : well_order Y) (f : X -> Y) (H : is_simulation P Q f) : forall x, forall y (H0 : Q y (f x)), P (simulation_helper_data H x y H0) x /\ f (simulation_helper_data H x y H0) = y. Proof. intros. pose ( constructive_definite_description _ (simulation_helper_unique H x y H0) ) as H1. exact (proj2_sig H1). Qed. Lemma simulation_unique (P : well_order X) (Q : well_order Y) (f g : X -> Y) (H0 : is_simulation P Q f) (H1 : is_simulation P Q g) : f = g. Proof. extensionality x. apply simulation_characterization in H0, H1. destruct H0, H1. destruct P as [P [H3 [H4 H5]]]. destruct Q as [Q [H6 [H7 H8]]]. simpl in H, H0, H1, H2. induction (H3 x). apply (H7 (f a) (g a)). intro. split; intro. - specialize (H0 _ _ H11). destruct H0 as [x [Pxa e]]. subst c. specialize (H10 _ Pxa). rewrite H10. apply H1. assumption. - specialize (H2 _ _ H11). destruct H2 as [x [Pxa e]]. subst c. specialize (H10 _ Pxa). rewrite<- H10. apply H. assumption. Qed. End Simulation. Definition simulation (X Y : well_ordered_type) : Type := {f : X -> Y & is_simulation (projT2 X) (projT2 Y) f}. Definition hartogs_type (X : Type) : Type := {S : power X & well_order (sig S)}. Definition hartogs_helper (X : Type) : hartogs_type X -> well_ordered_type := fun S => existT _ (sig (projT1 S)) (projT2 S). Definition hartogs_order (X : Type) : bin_rel (hartogs_type X) := fun S T => inhabited (simulation (hartogs_helper S) (hartogs_helper T)).