(* Title: HoTT/EqualProps.thy Author: Josh Chen Date: Jun 2018 Properties of equality. *) theory EqualProps imports HoTT_Methods Equal Prod begin section \Symmetry / Path inverse\ definition inv :: "[Term, Term, Term] \ Term" ("(1inv[_,/ _,/ _])") where "inv[A,x,y] \ \<^bold>\p:x =\<^sub>A y. indEqual[A] (\x y _. y =\<^sub>A x) (\x. refl(x)) x y p" lemma inv_type: assumes "p : x =\<^sub>A y" shows "inv[A,x,y]`p : y =\<^sub>A x" proof show "inv[A,x,y] : (x =\<^sub>A y) \ (y =\<^sub>A x)" proof (unfold inv_def, standard) fix p assume asm: "p : x =\<^sub>A y" show "indEqual[A] (\x y _. y =[A] x) refl x y p : y =\<^sub>A x" proof standard+ show "x : A" by (wellformed jdgmt: asm) show "y : A" by (wellformed jdgmt: asm) qed (assumption | rule | rule asm)+ qed (wellformed jdgmt: assms) qed (rule assms) lemma inv_comp: assumes "a : A" shows "inv[A,a,a]`refl(a) \ refl(a)" proof - have "inv[A,a,a]`refl(a) \ indEqual[A] (\x y _. y =\<^sub>A x) (\x. refl(x)) a a refl(a)" proof (unfold inv_def, standard) show "refl(a) : a =\<^sub>A a" using assms .. fix p assume asm: "p : a =\<^sub>A a" show "indEqual[A] (\x y _. y =\<^sub>A x) refl a a p : a =\<^sub>A a" proof standard+ show "a : A" by (wellformed jdgmt: asm) then show "a : A" . \ \The elimination rule requires that both arguments to \indEqual\ be shown to have the correct type.\ qed (assumption | rule | rule asm)+ qed also have "indEqual[A] (\x y _. y =\<^sub>A x) (\x. refl(x)) a a refl(a) \ refl(a)" by (standard | assumption | rule assms)+ finally show "inv[A,a,a]`refl(a) \ refl(a)" . qed section \Transitivity / Path composition\ text "``Raw'' composition function, of type \\x,y:A. x =\<^sub>A y \ (\z:A. y =\<^sub>A z \ x =\<^sub>A z)\." definition rcompose :: "Term \ Term" ("(1rcompose[_])") where "rcompose[A] \ \<^bold>\x:A. \<^bold>\y:A. \<^bold>\p:x =\<^sub>A y. indEqual[A] (\x y _. \z:A. y =\<^sub>A z \ x =\<^sub>A z) (\x. \<^bold>\z:A. \<^bold>\p:x =\<^sub>A z. indEqual[A](\x z _. x =\<^sub>A z) (\x. refl(x)) x z p) x y p" text "``Natural'' composition function abbreviation, effectively equivalent to a function of type \\x,y,z:A. x =\<^sub>A y \ y =\<^sub>A z \ x =\<^sub>A z\." abbreviation compose :: "[Term, Term, Term, Term] \ Term" ("(1compose[_,/ _,/ _,/ _])") where "compose[A,x,y,z] \ \<^bold>\p:x =\<^sub>A y. \<^bold>\q:y =\<^sub>A z. rcompose[A]`x`y`p`z`q" lemma compose_comp: assumes "a : A" shows "compose[A,a,a,a]`refl(a)`refl(a) \ refl(a)" proof (unfold rcompose_def) have "compose[A,a,a,a]`refl(a) \ \<^bold>\q:a =\<^sub>A a. rcompose[A]`a`a`refl(a)`a`q" proof standard+ (*TODO: Set up the Simplifier to handle this proof at some point.*) fix p q assume "p : a =\<^sub>A a" and "q : a =\<^sub>A a" then show "rcompose[A]`a`a`p`a`q : a =\<^sub>A a" proof (unfold rcompose_def) have "(\<^bold>\x:A. \<^bold>\y:A. \<^bold>\p:x =\<^sub>A y. (indEqual[A] (\x y _. \z:A. y =[A] z \ x =[A] z) (\x. \<^bold>\z:A. \<^bold>\q:x =\<^sub>A z. (indEqual[A] (\x z _. x =\<^sub>A z) refl x z q)) x y p))`a`a`p`a`q \ ..." (*Okay really need to set up the Simplifier...*) oops text "The above proof is a good candidate for proof automation; in particular we would like the system to be able to automatically find the conditions of the \using\ clause in the proof. This would likely involve something like: 1. Recognizing that there is a function application that can be simplified. 2. Noting that the obstruction to applying \Prod_comp\ is the requirement that \refl(a) : a =\<^sub>A a\. 3. Obtaining such a condition, using the known fact \a : A\ and the introduction rule \Equal_intro\." lemmas Equal_simps [simp] = inv_comp compose_comp section \Pretty printing\ abbreviation inv_pretty :: "[Term, Term, Term, Term] \ Term" ("(1_\<^sup>-\<^sup>1[_, _, _])" 500) where "p\<^sup>-\<^sup>1[A,x,y] \ inv[A,x,y]`p" abbreviation compose_pretty :: "[Term, Term, Term, Term, Term, Term] \ Term" ("(1_ \[_, _, _, _]/ _)") where "p \[A,x,y,z] q \ compose[A,x,y,z]`p`q"