Advertisement
Guest User

Untitled

a guest
Jul 7th, 2017
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Set Implicit Arguments.
  2.  
  3. Section PublicService.
  4.  
  5.   Inductive False : Type :=.
  6.  
  7.   Definition Not (P : Type) := P -> False.
  8.  
  9.   Inductive True : Type :=
  10.   | I : True.
  11.  
  12.   Inductive Identity (T : Type) (t : T) : T -> Type :=
  13.   | identical : Identity t t.
  14.  
  15.   Inductive And (P Q : Type) : Type :=
  16.   | both : P -> Q -> And P Q.
  17.   Definition proj1 {P Q} (a : And P Q) : P :=
  18.     match a with both p q => p end.
  19.   Definition proj2 {P Q} (a : And P Q) : Q :=
  20.     match a with both p q => q end.
  21.  
  22.   Definition And_idem (P : Type) : P -> And P P.
  23.   intro p; apply (both p p).
  24.   Defined.
  25.  
  26.   Inductive Or (P Q : Type) : Type :=
  27.   | inleft : P -> Or P Q
  28.   | inright : Q -> Or P Q.
  29.  
  30.   Definition Decidable (P : Type) := Or P (Not P).
  31.  
  32.   Inductive Sigma (T : Type) (P : T -> Type) : Type :=
  33.   | witness : forall t : T, P t -> Sigma P.
  34.   Definition pi1 {T P} (s : @Sigma T P) : T :=
  35.     match s with
  36.       | witness t _ => t
  37.     end.
  38.  
  39.   Definition Relation (T : Type) := T -> T -> Type.
  40.  
  41.   Record Equivalence {T : Type} (R : Relation T)
  42.     := { equivalence_reflexivity : forall x, R x x
  43.        ; equivalence_symmetry : forall x y, R x y -> R y x
  44.        ; equivalence_transitivity : forall x y z, R x y -> R y z -> R x z
  45.        }.
  46.  
  47.   Theorem Equivalence_Identity {T : Type} : Equivalence (@Identity T).
  48.   apply Build_Equivalence.
  49.   intros x; apply identical.
  50.   intros x y; intro E; elim E; apply identical.
  51.   intros x y z; intros E F; elim F; elim E; apply identical.
  52.   Defined.
  53.  
  54.   Theorem Equivalence_Identity_Pullback {X T : Type} (f : X -> T) : Equivalence (fun x x' => @Identity T (f x) (f x')).
  55.   apply Build_Equivalence.
  56.   intros x; apply identical.
  57.   intros x y; intro E; elim E; apply identical.
  58.   intros x y z; intros E F; elim F; elim E; apply identical.
  59.   Defined.
  60.  
  61. End PublicService.
  62.  
  63. Section CategoryTheory.
  64.  
  65. Record Category
  66.   (Ob : Type)
  67.   (Hom : Ob -> Ob -> Type)
  68.   (Hom_eq : forall X Y, Relation (Hom X Y))
  69.  
  70.   := { identity : forall X, Hom X X
  71.      ; compose : forall X Y Z, Hom X Y -> Hom Y Z -> Hom X Z
  72.      ; compose_respectful_left : forall X Y Z (f f' : Hom X Y) (g : Hom Y Z),
  73.        Hom_eq _ _ f f' ->
  74.        Hom_eq _ _ (compose f g) (compose f' g)
  75.      ; compose_respectful_right : forall X Y Z (f : Hom X Y) (g g' : Hom Y Z),
  76.        Hom_eq _ _ g g' ->
  77.        Hom_eq _ _ (compose f g) (compose f g')
  78.      ; category_equivalence : forall X Y, Equivalence (Hom_eq X Y)
  79.      ; category_left_identity : forall X Y (f : Hom X Y),
  80.        Hom_eq _ _ (compose (identity _) f) f
  81.      ; category_right_identity : forall X Y (f : Hom X Y),
  82.        Hom_eq _ _ (compose f (identity _)) f
  83.      ; category_associativity : forall X Y Z W (f : Hom X Y) (g : Hom Y Z) (h : Hom Z W),
  84.        Hom_eq _ _ (compose f (compose g h))
  85.                   (compose (compose f g) h)
  86.      }.
  87.  
  88. Notation "f '[' C ']'  g" := (compose C _ _ _ f g) (at level 20).
  89. Notation "'Id[' C ']'" := (identity C _) (at level 20).
  90.  
  91. End CategoryTheory.
  92.  
  93. Section Functor.
  94.   Context {C_Ob C_Hom C_Hom_eq} (C : @Category C_Ob C_Hom C_Hom_eq).
  95.   Context {D_Ob D_Hom D_Hom_eq} (D : @Category D_Ob D_Hom D_Hom_eq).
  96.  
  97.   Record Functor
  98.     := { Map_Ob : C_Ob -> D_Ob
  99.        ; Map_Hom : forall X Y,
  100.          C_Hom X Y -> D_Hom (Map_Ob X) (Map_Ob Y)
  101.        ; functor_identity : forall X,
  102.          D_Hom_eq (Map_Hom (identity C X)) (identity D (Map_Ob X))
  103.        ; functor_compose : forall X Y Z (f : C_Hom X Y) (g : C_Hom Y Z),
  104.          D_Hom_eq (Map_Hom (compose C _ _ _ f g)) (compose D _ _ _ (Map_Hom f) (Map_Hom g))
  105.        ; Map_Hom_respectful : forall X Y (f f' : C_Hom X Y),
  106.          C_Hom_eq f f' -> D_Hom_eq (Map_Hom f) (Map_Hom f')
  107.     }.
  108.  
  109.   Notation "F '@' x" := (Map_Ob F x) (at level 20).
  110.   Notation "F '$' f" := (Map_Hom F f) (at level 20).
  111.  
  112.   (*
  113.   Theorem Functor_Map_Equation (F : Functor) {X Y} (f g : C_Hom X Y) : C_Hom_eq f g -> D_Hom_eq (Map_Hom F f) (Map_Hom F g).
  114.     intro E.
  115.     *)
  116.  
  117. End Functor.
  118.  
  119. Section SYMBOLIC.
  120.   Context {Ob Hom Hom_eq} (C : @Category Ob Hom Hom_eq).
  121.  
  122.   Inductive Syntax : Ob -> Ob -> Type :=
  123.   | idSYM : forall X : Ob, Syntax X X
  124.   | compSYM : forall X Y Z : Ob, Syntax X Y -> Syntax Y Z -> Syntax X Z
  125.   | injSYM : forall X Y, Hom X Y -> Syntax X Y.
  126.  
  127.   Inductive Semantics : Ob -> Ob -> Type :=
  128.   | nilSYM : forall X : Ob, Semantics X X
  129.   | consSYM : forall X Y Z : Ob, Hom X Y -> Semantics Y Z -> Semantics X Z.
  130.  
  131.   Fixpoint append {X Y Z : Ob} (f : Semantics X Y) : Semantics Y Z -> Semantics X Z :=
  132.   match f with
  133.     | nilSYM _ => fun g => g
  134.     | consSYM _ _ _ s f => fun g => consSYM s (append f g)
  135.   end.
  136.  
  137.   Lemma append_nil :
  138.     forall (X Y : Ob) (x : Semantics X Y),
  139.       Identity (append x (nilSYM Y)) x.
  140.     induction x; simpl.
  141.     apply identical.
  142.     elim (equivalence_symmetry Equivalence_Identity _ _ IHx).
  143.     apply identical.
  144.   Defined.
  145.    
  146.   Lemma append_associative :
  147.   forall (X Y Z W : Ob) (f : Semantics X Y) (g : Semantics Y Z) (h : Semantics Z W),
  148.     Identity (append f (append g h))
  149.              (append (append f g) h).
  150.     intros; induction f; simpl.
  151.     apply identical.
  152.     elim (IHf _).
  153.     apply identical.
  154.   Defined.
  155.  
  156.   Fixpoint evalSYN {X Y} (s : Syntax X Y) : Semantics X Y :=
  157.     match s with
  158.       | idSYM _ => nilSYM _
  159.       | compSYM _ _ _ f g => append (evalSYN f) (evalSYN g)
  160.       | injSYM _ _ f => consSYM f (nilSYM _)
  161.     end.
  162.  
  163.   Fixpoint quoteSYN {X Y} (s : Semantics X Y) : Syntax X Y :=
  164.     match s with
  165.       | nilSYM _ => idSYM _
  166.       | consSYM _ _ _ f s => compSYM (injSYM f) (quoteSYN s)
  167.     end.
  168.  
  169.   Definition Syntax_eq {X Y : Ob} (f f' : Syntax X Y) :=
  170.     Identity (evalSYN f) (evalSYN f').
  171.   Theorem Equivalence_Syntax_eq {X Y} : Equivalence (@Syntax_eq X Y).
  172.     apply (Equivalence_Identity_Pullback evalSYN).
  173.   Defined.
  174.  
  175.   Definition SYNTAX_category : Category Syntax (@Syntax_eq).
  176.   apply (Build_Category Syntax (@Syntax_eq)
  177.     idSYM
  178.     compSYM); unfold Syntax_eq; simpl.
  179.   intros X Y Z f f' g E; elim E; apply identical.
  180.   intros X Y Z f g g' E; elim E; apply identical.
  181.   intros X Y; apply Equivalence_Syntax_eq.
  182.   intros X Y f; apply identical.
  183.   intros X Y f; apply append_nil.
  184.   intros X Y Z W f g h; apply append_associative.
  185.   Defined.
  186.  
  187.   Theorem quote_eval_equal {X Y : Ob} (f : Syntax X Y) :
  188.     Syntax_eq (quoteSYN (evalSYN f)) f.
  189.     induction f; simpl in *;
  190.       try apply identical.
  191.    
  192.     Lemma quote_eval_equal_lemma {X Y Z} (e1 : Semantics X Y) (e2 : Semantics Y Z) :
  193.       Syntax_eq (quoteSYN (append e1 e2)) (compSYM (quoteSYN e1) (quoteSYN e2)).
  194.       intros; induction e1; simpl.
  195.       apply identical.
  196.       elim (IHe1 e2).
  197.       eapply (equivalence_transitivity (category_equivalence SYNTAX_category _ _)).
  198.       Focus 2.
  199.       apply (category_associativity SYNTAX_category _ _).
  200.       apply (compose_respectful_right SYNTAX_category).
  201.       apply IHe1.
  202.     Defined.
  203.    
  204.     eapply (equivalence_transitivity Equivalence_Syntax_eq).
  205.     apply quote_eval_equal_lemma.
  206.     eapply (equivalence_transitivity (category_equivalence SYNTAX_category _ _)).
  207.     apply (compose_respectful_left SYNTAX_category).
  208.     apply IHf1.
  209.     eapply (equivalence_transitivity (category_equivalence SYNTAX_category _ _)).
  210.     apply (compose_respectful_right SYNTAX_category).
  211.     apply IHf2.
  212.     apply (equivalence_reflexivity (category_equivalence SYNTAX_category _ _)).
  213.   Defined.
  214.  
  215.   Fixpoint interpret_Syntax {X Y} (f : Syntax X Y) : Hom X Y :=
  216.     match f with
  217.       | idSYM _ => identity C _
  218.       | compSYM _ _ _ f g => compose C _ _ _ (interpret_Syntax f) (interpret_Syntax g)
  219.       | injSYM _ _ f => f
  220.     end.
  221.  
  222.   Fixpoint interpret_Semantics {X Y} (f : Semantics X Y) : Hom X Y :=
  223.     match f with
  224.       | nilSYM _ => identity C _
  225.       | consSYM _ _ _ s f => compose C _ _ _ s (interpret_Semantics f)
  226.     end.
  227.  
  228.   Theorem interpretation_factors_through_evaluation {X Y} (f : Syntax X Y) :
  229.     Hom_eq (interpret_Syntax f)
  230.            (interpret_Semantics (evalSYN f)).
  231.     induction f; simpl.
  232.     apply (equivalence_reflexivity (category_equivalence C _ _)).
  233.     eapply (equivalence_transitivity (category_equivalence C _ _)).
  234.     apply compose_respectful_left.
  235.     apply IHf1.
  236.     eapply (equivalence_transitivity (category_equivalence C _ _)).
  237.     apply compose_respectful_right.
  238.     apply IHf2.
  239.     Lemma append_pushthrough_compose {X Y Z} (f : Semantics X Y) (g : Semantics Y Z) :
  240.       Hom_eq (compose C _ _ _ (interpret_Semantics f) (interpret_Semantics g))
  241.              (interpret_Semantics (append f g)).
  242.       induction f; simpl.
  243.       apply category_left_identity.
  244.       eapply (equivalence_transitivity (category_equivalence C _ _)).
  245.       apply (equivalence_symmetry (category_equivalence C _ _)).
  246.       apply (category_associativity C).
  247.       apply compose_respectful_right.
  248.       apply IHf.
  249.     Defined.
  250.     apply append_pushthrough_compose.
  251.    
  252.     apply (equivalence_symmetry (category_equivalence C _ _)).
  253.     apply category_right_identity.
  254.   Defined.
  255.  
  256.   Definition Interpret : Functor SYNTAX_category C.
  257.   Print Build_Functor.
  258.   apply (Build_Functor
  259.     SYNTAX_category C
  260.     (fun X => X)
  261.     (fun X Y f => interpret_Syntax f)
  262.   ).
  263.  
  264.   intros; apply (equivalence_reflexivity (category_equivalence C _ _)).
  265.   intros; apply (equivalence_reflexivity (category_equivalence C _ _)).
  266.  
  267.   intros X Y f f' E.
  268.   pose (quote_eval_equal f) as A.
  269.   pose (quote_eval_equal f') as B.
  270.   pose (interpretation_factors_through_evaluation f) as U.
  271.   pose (interpretation_factors_through_evaluation f') as V.
  272.   unfold Syntax_eq in *.
  273.   assert (
  274.     Hom_eq (interpret_Syntax f) (interpret_Semantics (evalSYN f'))
  275.   ) as P.
  276.   elim E.
  277.   assumption.
  278.   eapply (equivalence_transitivity (category_equivalence C _ _)).
  279.   apply P.
  280.   apply (equivalence_symmetry (category_equivalence C _ _)).
  281.   apply V.
  282.   Defined.
  283.  
  284. End SYMBOLIC.
  285.  
  286. Section IsomorphismSubcategory.
  287.   Context {Ob Hom Hom_eq} (C : @Category Ob Hom Hom_eq).
  288.  
  289.   Definition Isomorphism (X Y : Ob) :=
  290.     @Sigma (And (Hom X Y) (Hom Y X))
  291.     (fun (fg : And (Hom X Y) (Hom Y X)) =>
  292.       match fg with
  293.         | both f g =>
  294.           And (Hom_eq (compose C _ _ _ f g) (identity C _))
  295.               (Hom_eq (compose C _ _ _ g f) (identity C _))    
  296.         end).
  297.  
  298.   Definition Identity_Isomorphism (X : Ob) : Isomorphism X X.
  299.   apply (witness _ (both (identity C X) (identity C X))).
  300.   apply And_idem.
  301.   apply category_left_identity.
  302.   Defined.
  303.  
  304.   Definition Compose_Isomorphism (X Y Z : Ob)
  305.     (f : Isomorphism X Y) (g : Isomorphism Y Z) :
  306.     Isomorphism X Z.
  307.   unfold Isomorphism in *.
  308.   destruct f as [[fTo fFrom] [fPrf fPrf']].
  309.   destruct g as [[gTo gFrom] [gPrf gPrf']].
  310.   apply (witness _ (both (compose C _ _ _ fTo gTo)
  311.                          (compose C _ _ _ gFrom fFrom))).
  312.   apply both.
  313.  
  314.   pose (@SYNTAX_category Ob Hom) as SYN.
  315.   assert (
  316.     Syntax_eq
  317.      (compose SYN X Z X (compose SYN X Y Z (injSYM _ _ fTo) (injSYM _ _ gTo)) (compose SYN Z Y X (injSYM _ _ gFrom) (injSYM _ _ fFrom)))
  318.      (compose SYN _ _ _ (injSYM _ _ fTo)
  319.        (compose SYN _ _ _
  320.          (compose SYN _ _ _ (injSYM _ _ gTo) (injSYM _ _ gFrom))
  321.          (injSYM _ _ fFrom)))
  322.   ) as EQUATION by apply identical.
  323.   pose (Map_Hom_respectful (Interpret C) _ _ _ _ EQUATION) as EQUATION'; simpl in EQUATION'.
  324.  
  325.   eapply (equivalence_transitivity (category_equivalence C _ _)).
  326.   apply EQUATION'.
  327.   clear EQUATION'; clear EQUATION.
  328.  
  329.   eapply (equivalence_transitivity (category_equivalence C _ _)).
  330.   apply compose_respectful_right.
  331.   apply compose_respectful_left.
  332.   apply gPrf.
  333.  
  334.   eapply (equivalence_transitivity (category_equivalence C _ _)).
  335.   apply compose_respectful_right.
  336.   apply category_left_identity.
  337.   apply fPrf.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement