From dcf87145a1059659099bbecde55973de0d36d43f Mon Sep 17 00:00:00 2001 From: Josh Chen Date: Tue, 18 Sep 2018 03:04:37 +0200 Subject: Theories fully reorganized. Well-formedness rules removed. New methods etc. --- Equal.thy | 10 +- EqualProps.thy | 398 ++++++++++++------------------------------------------- HoTT_Base.thy | 4 +- HoTT_Methods.thy | 18 +-- Prod.thy | 5 +- Univalence.thy | 194 ++++++++------------------- 6 files changed, 158 insertions(+), 471 deletions(-) diff --git a/Equal.thy b/Equal.thy index f9bc223..7a31e37 100644 --- a/Equal.thy +++ b/Equal.thy @@ -7,7 +7,7 @@ Equality type *) theory Equal -imports HoTT_Base HoTT_Methods +imports HoTT_Base begin @@ -36,13 +36,13 @@ axiomatization where p: x =\<^sub>A y; x: A; y: A; - \x y. \x: A; y: A\ \ C x y: x =\<^sub>A y \ U i; - \x. x: A \ f x: C x x (refl x) \ \ ind\<^sub>= (\x. f x) p : C x y p" and + \x. x: A \ f x: C x x (refl x); + \x y. \x: A; y: A\ \ C x y: x =\<^sub>A y \ U i \ \ ind\<^sub>= (\x. f x) p : C x y p" and Equal_comp: "\ a: A; - \x y. \x: A; y: A\ \ C x y: x =\<^sub>A y \ U i; - \x. x: A \ f x: C x x (refl x) \ \ ind\<^sub>= (\x. f x) (refl a) \ f a" + \x. x: A \ f x: C x x (refl x); + \x y. \x: A; y: A\ \ C x y: x =\<^sub>A y \ U i \ \ ind\<^sub>= (\x. f x) (refl a) \ f a" lemmas Equal_routine [intro] = Equal_form Equal_intro Equal_elim lemmas Equal_comp [comp] diff --git a/EqualProps.thy b/EqualProps.thy index 19c788c..abb2623 100644 --- a/EqualProps.thy +++ b/EqualProps.thy @@ -1,361 +1,137 @@ -(* Title: HoTT/EqualProps.thy - Author: Josh Chen +(* +Title: EqualProps.thy +Author: Joshua Chen +Date: 2018 Properties of equality *) theory EqualProps - imports - HoTT_Methods - Equal - Prod +imports HoTT_Methods Equal Prod + begin -section \Symmetry / Path inverse\ - -definition inv :: "t \ t" ("_\" [1000] 1000) where "p\ \ ind\<^sub>= (\x. (refl x)) p" - -text " - In the proof below we begin by using path induction on \p\ with the application of \rule Equal_elim\, telling Isabelle the specific substitutions to use. - The proof is finished with a standard application of the relevant type rules. -" - -lemma inv_type: - assumes "A : U i" and "x : A" and "y : A" and "p: x =\<^sub>A y" shows "p\: y =\<^sub>A x" -unfolding inv_def -by (rule Equal_elim[where ?x=x and ?y=y]) (routine lems: assms) - \ \The type doesn't depend on \p\ so we don't need to specify \?p\ in the \where\ clause above.\ - -text " - The next proof requires explicitly telling Isabelle what to substitute on the RHS of the typing judgment after the initial application of the type rules. - (If viewing this inside Isabelle, place the cursor after the \proof\ statement and observe the second subgoal.) -" - -lemma inv_comp: - assumes "A : U i " and "a : A" shows "(refl a)\ \ refl a" -unfolding inv_def -proof compute - show "\x. x: A \ refl x: x =\<^sub>A x" .. -qed (routine lems: assms) - - -section \Transitivity / Path composition\ - -text " - Raw composition function, of type \\x:A. \y:A. x =\<^sub>A y \ (\z:A. y =\<^sub>A z \ x =\<^sub>A z)\ polymorphic over the type \A\. -" - -definition rpathcomp :: t where "rpathcomp \ \<^bold>\_ _ p. ind\<^sub>= (\_. \<^bold>\_ q. ind\<^sub>= (\x. (refl x)) q) p" - -text " - More complicated proofs---the nested path inductions require more explicit step-by-step rule applications: -" - -lemma rpathcomp_type: - assumes "A: U i" - shows "rpathcomp: \x:A. \y:A. x =\<^sub>A y \ (\z:A. y =\<^sub>A z \ x =\<^sub>A z)" -unfolding rpathcomp_def -proof - fix x assume 1: "x: A" - show "\<^bold>\y p. ind\<^sub>= (\_. \<^bold>\z q. ind\<^sub>= refl q) p: \y:A. x =\<^sub>A y \ (\z:A. y =\<^sub>A z \ x =\<^sub>A z)" - proof - fix y assume 2: "y: A" - show "\<^bold>\p. ind\<^sub>= (\_. \<^bold>\z q. ind\<^sub>= refl q) p: x =\<^sub>A y \ (\z:A. y =\<^sub>A z \ x =\<^sub>A z)" - proof - fix p assume 3: "p: x =\<^sub>A y" - show "ind\<^sub>= (\_. \<^bold>\z q. ind\<^sub>= refl q) p: \z:A. y =\<^sub>A z \ x =\<^sub>A z" - proof (rule Equal_elim[where ?x=x and ?y=y]) - show "\u. u: A \ \<^bold>\z q. ind\<^sub>= refl q: \z:A. u =\<^sub>A z \ u =\<^sub>A z" - proof - show "\u z. \u: A; z: A\ \ \<^bold>\q. ind\<^sub>= refl q: u =\<^sub>A z \ u =\<^sub>A z" - proof - fix u z q assume asm: "u: A" "z: A" "q: u =\<^sub>A z" - show "ind\<^sub>= refl q: u =\<^sub>A z" - by (rule Equal_elim[where ?x=u and ?y=z]) (routine lems: assms asm) - qed (routine lems: assms) - qed (rule assms) - qed (routine lems: assms 1 2 3) - qed (routine lems: assms 1 2) - qed (rule assms) -qed fact - -corollary - assumes "A: U i" "x: A" "y: A" "z: A" "p: x =\<^sub>A y" "q: y =\<^sub>A z" - shows "rpathcomp`x`y`p`z`q: x =\<^sub>A z" - by (routine lems: assms rpathcomp_type) - -text " - The following proof is very long, chiefly because for every application of \`\ we have to show the wellformedness of the type family appearing in the equality computation rule. -" - -lemma rpathcomp_comp: - assumes "A: U i" and "a: A" - shows "rpathcomp`a`a`(refl a)`a`(refl a) \ refl a" -unfolding rpathcomp_def -proof compute - fix x assume 1: "x: A" - show "\<^bold>\y p. ind\<^sub>= (\_. \<^bold>\z q. ind\<^sub>= refl q) p: \y:A. x =\<^sub>A y \ (\z:A. y =\<^sub>A z \ x =\<^sub>A z)" - proof - fix y assume 2: "y: A" - show "\<^bold>\p. ind\<^sub>= (\_. \<^bold>\z q. ind\<^sub>= refl q) p: x =\<^sub>A y \ (\z:A. y =\<^sub>A z \ x =\<^sub>A z)" - proof - fix p assume 3: "p: x =\<^sub>A y" - show "ind\<^sub>= (\_. \<^bold>\z q. ind\<^sub>= refl q) p: \z:A. y =\<^sub>A z \ x =\<^sub>A z" - proof (rule Equal_elim[where ?x=x and ?y=y]) - show "\u. u: A \ \<^bold>\z q. ind\<^sub>= refl q: \z:A. u =\<^sub>A z \ u =\<^sub>A z" - proof - show "\u z. \u: A; z: A\ \ \<^bold>\q. ind\<^sub>= refl q: u =\<^sub>A z \ u =\<^sub>A z" - proof - fix u z assume asm: "u: A" "z: A" - show "\q. q: u =\<^sub>A z \ ind\<^sub>= refl q: u =\<^sub>A z" - by (rule Equal_elim[where ?x=u and ?y=z]) (routine lems: assms asm) - qed (routine lems: assms) - qed (rule assms) - qed (routine lems: assms 1 2 3) - qed (routine lems: assms 1 2) - qed (rule assms) - - next show "(\<^bold>\y p. ind\<^sub>= (\_. \<^bold>\z q. ind\<^sub>= refl q) p)`a`(refl a)`a`(refl a) \ refl a" - proof compute - fix y assume 1: "y: A" - show "\<^bold>\p. ind\<^sub>= (\_. \<^bold>\z q. ind\<^sub>= refl q) p: a =\<^sub>A y \ (\z:A. y =\<^sub>A z \ a =\<^sub>A z)" - proof - fix p assume 2: "p: a =\<^sub>A y" - show "ind\<^sub>= (\_. \<^bold>\z q. ind\<^sub>= refl q) p: \z:A. y =\<^sub>A z \ a =\<^sub>A z" - proof (rule Equal_elim[where ?x=a and ?y=y]) - fix u assume 3: "u: A" - show "\<^bold>\z q. ind\<^sub>= refl q: \z:A. u =\<^sub>A z \ u =\<^sub>A z" - proof - fix z assume 4: "z: A" - show "\<^bold>\q. ind\<^sub>= refl q: u =\<^sub>A z \ u =\<^sub>A z" - proof - show "\q. q: u =\<^sub>A z \ ind\<^sub>= refl q: u =\<^sub>A z" - by (rule Equal_elim[where ?x=u and ?y=z]) (routine lems: assms 3 4) - qed (routine lems: assms 3 4) - qed fact - qed (routine lems: assms 1 2) - qed (routine lems: assms 1) - - next show "(\<^bold>\p. ind\<^sub>= (\_. \<^bold>\z. \<^bold>\q. ind\<^sub>= refl q) p)`(refl a)`a`(refl a) \ refl a" - proof compute - fix p assume 1: "p: a =\<^sub>A a" - show "ind\<^sub>= (\_. \<^bold>\z q. ind\<^sub>= refl q) p: \z:A. a =\<^sub>A z \ a =\<^sub>A z" - proof (rule Equal_elim[where ?x=a and ?y=a]) - fix u assume 2: "u: A" - show "\<^bold>\z q. ind\<^sub>= refl q: \z:A. u =\<^sub>A z \ u =\<^sub>A z" - proof - fix z assume 3: "z: A" - show "\<^bold>\q. ind\<^sub>= refl q: u =\<^sub>A z \ u =\<^sub>A z" - proof - show "\q. q: u =\<^sub>A z \ ind\<^sub>= refl q: u =\<^sub>A z" - by (rule Equal_elim[where ?x=u and ?y=z]) (routine lems: assms 2 3) - qed (routine lems: assms 2 3) - qed fact - qed (routine lems: assms 1) - - next show "(ind\<^sub>=(\_. \<^bold>\z q. ind\<^sub>= refl q)(refl a))`a`(refl a) \ refl a" - proof compute - fix u assume 1: "u: A" - show "\<^bold>\z q. ind\<^sub>= refl q: \z:A. u =\<^sub>A z \ u =\<^sub>A z" - proof - fix z assume 2: "z: A" - show "\<^bold>\q. ind\<^sub>= refl q: u =\<^sub>A z \ u =\<^sub>A z" - proof - show "\q. q: u =\<^sub>A z \ ind\<^sub>= refl q: u =\<^sub>A z" - by (rule Equal_elim[where ?x=u and ?y=z]) (routine lems: assms 1 2) - qed (routine lems: assms 1 2) - qed fact - - next show "(\<^bold>\z q. ind\<^sub>= refl q)`a`(refl a) \ refl a" - proof compute - fix a assume 1: "a: A" - show "\<^bold>\q. ind\<^sub>= refl q: a =\<^sub>A a \ a =\<^sub>A a" - proof - show "\q. q: a =\<^sub>A a \ ind\<^sub>= refl q: a =\<^sub>A a" - by (rule Equal_elim[where ?x=a and ?y=a]) (routine lems: assms 1) - qed (routine lems: assms 1) - - next show "(\<^bold>\q. ind\<^sub>= refl q)`(refl a) \ refl a" - proof compute - show "\p. p: a =\<^sub>A a \ ind\<^sub>= refl p: a =\<^sub>A a" - by (rule Equal_elim[where ?x=a and ?y=a]) (routine lems: assms) - show "ind\<^sub>= refl (refl a) \ refl a" - proof compute - show "\x. x: A \ refl(x): x =\<^sub>A x" .. - qed (routine lems: assms) - qed (routine lems: assms) - qed fact - qed (routine lems: assms) - qed (routine lems: assms) - qed fact -qed fact - - -text "The raw object lambda term is cumbersome to use, so we define a simpler constant instead." - -axiomatization pathcomp :: "[t, t] \ t" (infixl "\" 120) where - pathcomp_def: "\ - A: U i; - x: A; y: A; z: A; - p: x =\<^sub>A y; q: y =\<^sub>A z - \ \ p \ q \ rpathcomp`x`y`p`z`q" +section \Symmetry of equality/Path inverse\ +definition inv :: "t \ t" ("_\" [1000] 1000) where "p\ \ ind\<^sub>= (\x. refl x) p" -lemma pathcomp_type: - assumes "A: U i" "x: A" "y: A" "z: A" "p: x =\<^sub>A y" "q: y =\<^sub>A z" - shows "p \ q: x =\<^sub>A z" +lemma inv_type: "\A: U i; x: A; y: A; p: x =\<^sub>A y\ \ p\: y =\<^sub>A x" +unfolding inv_def by (elim Equal_elim) routine -proof (subst pathcomp_def) - show "A: U i" "x: A" "y: A" "z: A" "p: x =\<^sub>A y" "q: y =\<^sub>A z" by fact+ -qed (routine lems: assms rpathcomp_type) +lemma inv_comp: "\A: U i; a: A\ \ (refl a)\ \ refl a" +unfolding inv_def by compute routine -lemma pathcomp_comp: - assumes "A : U i" and "a : A" shows "(refl a) \ (refl a) \ refl a" -by (subst pathcomp_def) (routine lems: assms rpathcomp_comp) +section \Transitivity of equality/Path composition\ +text \ +Composition function, of type @{term "x =\<^sub>A y \ (y =\<^sub>A z) \ (x =\<^sub>A z)"} polymorphic over @{term A}, @{term x}, @{term y}, and @{term z}. +\ -lemmas inv_type [intro] -lemmas pathcomp_type [intro] +definition pathcomp :: t where "pathcomp \ \<^bold>\p. ind\<^sub>= (\_. \<^bold>\q. ind\<^sub>= (\x. (refl x)) q) p" -lemmas inv_comp [comp] -lemmas pathcomp_comp [comp] +syntax "_pathcomp" :: "[t, t] \ t" (infixl "\" 120) +translations "p \ q" \ "CONST pathcomp`p`q" +lemma pathcomp_type: + assumes "A: U i" and "x: A" "y: A" "z: A" + shows "pathcomp: x =\<^sub>A y \ (y =\<^sub>A z) \ (x =\<^sub>A z)" +unfolding pathcomp_def by rule (elim Equal_elim, routine add: assms) -section \Weak higher groupoid structure of types\ +corollary pathcomp_trans: + assumes "A: U i" and "x: A" "y: A" "z: A" and "p: x =\<^sub>A y" "q: y =\<^sub>A z" + shows "p \ q: x =\<^sub>A z" +by (routine add: assms pathcomp_type) -schematic_goal whg1a: +lemma pathcomp_comp: + assumes "A: U i" and "a: A" + shows "(refl a) \ (refl a) \ refl a" +unfolding pathcomp_def proof compute + show "(ind\<^sub>= (\_. \<^bold>\q. ind\<^sub>= (\x. refl x) q) (refl a))`(refl a) \ refl a" + proof compute + show "\<^bold>\q. (ind\<^sub>= (\x. refl x) q): a =\<^sub>A a \ a =\<^sub>A a" + by (routine add: assms) + + show "(\<^bold>\q. (ind\<^sub>= (\x. refl x) q))`(refl a) \ refl a" + proof compute + show "\q. q: a =\<^sub>A a \ ind\<^sub>= (\x. refl x) q: a =\<^sub>A a" by (routine add: assms) + qed (derive lems: assms) + qed (routine add: assms) + + show "\p. p: a =\<^sub>A a \ ind\<^sub>= (\_. \<^bold>\q. ind\<^sub>= (\x. refl x) q) p: a =\<^sub>A a \ a =\<^sub>A a" + by (routine add: assms) +qed (routine add: assms) + + +section \Higher groupoid structure of types\ + +schematic_goal pathcomp_right_id: assumes "A: U(i)" "x: A" "y: A" "p: x =\<^sub>A y" - shows "?a: p =[x =\<^sub>A y] (p \ (refl(y)))" -proof (rule Equal_elim[where ?x=x and ?y=y and ?p=p]) - show "\x. x: A \ refl(refl(x)): refl(x) =[x =\<^sub>A x] (refl(x) \ refl(x))" - by compute (routine lems: assms) -qed (routine lems: assms) + shows "?a: p \ (refl y) =[x =\<^sub>A y] p" +proof (rule Equal_elim[where ?x=x and ?y=y and ?p=p]) \ \@{method elim} does not seem to work with schematic goals.\ + show "\x. x: A \ refl(refl x): (refl x) \ (refl x) =[x =\<^sub>A x] (refl x)" + by (derive lems: assms pathcomp_comp) +qed (routine add: assms pathcomp_type) -schematic_goal whg1b: +schematic_goal pathcomp_left_id: assumes "A: U(i)" "x: A" "y: A" "p: x =\<^sub>A y" - shows "?a: p =[x =\<^sub>A y] (refl(x) \ p)" + shows "?a: (refl x) \ p =[x =\<^sub>A y] p" proof (rule Equal_elim[where ?x=x and ?y=y and ?p=p]) - show "\x. x: A \ refl(refl(x)): refl(x) =[x =\<^sub>A x] (refl(x) \ refl(x))" - by compute (routine lems: assms) -qed (routine lems: assms) + show "\x. x: A \ refl(refl x): (refl x) \ (refl x) =[x =\<^sub>A x] (refl x)" + by (derive lems: assms pathcomp_comp) +qed (routine add: assms pathcomp_type) -schematic_goal whg2a: +schematic_goal pathcomp_left_inv: assumes "A: U(i)" "x: A" "y: A" "p: x =\<^sub>A y" shows "?a: (p\ \ p) =[y =\<^sub>A y] refl(y)" proof (rule Equal_elim[where ?x=x and ?y=y and ?p=p]) - show "\x. x: A \ refl(refl(x)): ((refl(x))\ \ refl(x)) =[x =\<^sub>A x] refl(x)" - by (compute | routine lems: assms)+ -qed (routine lems: assms)+ + show "\x. x: A \ refl(refl x): (refl x)\ \ (refl x) =[x =\<^sub>A x] (refl x)" + by (derive lems: assms inv_comp pathcomp_comp) +qed (routine add: assms inv_type pathcomp_type) -schematic_goal whg2b: +schematic_goal pathcomp_right_inv: assumes "A: U(i)" "x: A" "y: A" "p: x =\<^sub>A y" shows "?a: (p \ p\) =[x =\<^sub>A x] refl(x)" proof (rule Equal_elim[where ?x=x and ?y=y and ?p=p]) - show "\x. x: A \ refl(refl(x)): (refl(x) \ (refl(x))\) =[x =\<^sub>A x] refl(x)" - by (compute | routine lems: assms)+ -qed (routine lems: assms)+ + show "\x. x: A \ refl(refl x): (refl x) \ (refl x)\ =[x =\<^sub>A x] (refl x)" + by (derive lems: assms inv_comp pathcomp_comp) +qed (routine add: assms inv_type pathcomp_type) -schematic_goal whg3: +schematic_goal inv_involutive: assumes "A: U(i)" "x: A" "y: A" "p: x =\<^sub>A y" shows "?a: p\\ =[x =\<^sub>A y] p" proof (rule Equal_elim[where ?x=x and ?y=y and ?p=p]) - show "\x. x: A \ refl(refl(x)): (refl(x))\\ =[x =\<^sub>A x] refl(x)" - by (compute | routine lems: assms)+ -qed (routine lems: assms) - - -lemma assumes "A: U(i)" shows "\x. x: A \ refl(x): x =\<^sub>A x" -by (rule Prod_atomize[where ?A=A and ?B="\x. x =\<^sub>A x"]) (routine lems: assms) - + show "\x. x: A \ refl(refl x): (refl x)\\ =[x =\<^sub>A x] (refl x)" + by (derive lems: assms inv_comp) +qed (routine add: assms inv_type) -schematic_goal +schematic_goal pathcomp_assoc: assumes - "A: U(i)" and - "x: A" "y: A" "z: A" "w: A" and + "A: U(i)" + "x: A" "y: A" "z: A" "w: A" "p: x =\<^sub>A y" "q: y =\<^sub>A z" "r: z =\<^sub>A w" shows "?a: p \ (q \ r) =[x =\<^sub>A w] (p \ q) \ r" proof (rule Equal_elim[where ?x=x and ?y=y and ?p=p]) - fix y assume "y: A" - show "refl(q \ r): refl(y) \ (q \ r) =[y =\<^sub>A w] (refl(y) \ q) \ r" - proof (compute lems: whg1b) - - -section \Higher groupoid structure of types\ - -lemma - assumes "A: U i" "x: A" "y: A" "p: x =\<^sub>A y" - shows - "ind\<^sub>= (\u. refl (refl u)) p: p =[x =\<^sub>A y] p \ (refl y)" and - "ind\<^sub>= (\u. refl (refl u)) p: p =[x =\<^sub>A y] (refl x) \ p" - -proof - - show "ind\<^sub>= (\u. refl (refl u)) p: p =[x =[A] y] p \ (refl y)" - by (rule Equal_elim[where ?p=p and ?x=x and ?y=y]) (derive lems: assms)+ - - show "ind\<^sub>= (\u. refl (refl u)) p: p =[x =[A] y] (refl x) \ p" - by (rule Equal_elim[where ?p=p and ?x=x and ?y=y]) (derive lems: assms)+ -qed - - -lemma - assumes "A: U i" "x: A" "y: A" "p: x =\<^sub>A y" - shows - "ind\<^sub>= (\u. refl (refl u)) p: p\ \ p =[y =\<^sub>A y] (refl y)" and - "ind\<^sub>= (\u. refl (refl u)) p: p \ p\ =[x =\<^sub>A x] (refl x)" - -proof - - show "ind\<^sub>= (\u. refl (refl u)) p: p\ \ p =[y =\<^sub>A y] (refl y)" - by (rule Equal_elim[where ?p=p and ?x=x and ?y=y]) (derive lems: assms)+ - - show "ind\<^sub>= (\u. refl (refl u)) p: p \ p\ =[x =\<^sub>A x] (refl x)" - by (rule Equal_elim[where ?p=p and ?x=x and ?y=y]) (derive lems: assms)+ -qed - - -lemma - assumes "A: U i" "x: A" "y: A" "p: x =\<^sub>A y" - shows "ind\<^sub>= (\u. refl (refl u)) p: p\\ =[x =\<^sub>A y] p" -by (rule Equal_elim[where ?p=p and ?x=x and ?y=y]) (derive lems: assms) - -text "Next we construct a proof term of associativity of path composition." - -schematic_goal - assumes - "A: U i" - "x: A" "y: A" "z: A" "w: A" - "p: x =\<^sub>A y" "q: y =\<^sub>A z" "r: z =\<^sub>A w" - shows - "?a: p \ (q \ r) =[x =\<^sub>A z] (p \ q) \ r" - -apply (rule Equal_elim[where ?p=p and ?x=x and ?y=y]) -apply (rule assms)+ -\ \Continue by substituting \refl x \ q = q\ etc.\ -sorry + fix x assume "x: A" + show "refl (q \ r): (refl x) \ (q \ r) =[x =\<^sub>A w] ((refl x) \ q) \ r" + \ \This requires substitution of *propositional* equality. \ + sorry + oops section \Transport\ -definition transport :: "t \ t" where - "transport p \ ind\<^sub>= (\x. (\<^bold>\x. x)) p" +definition transport :: "t \ t" where "transport p \ ind\<^sub>= (\_. (\<^bold>\x. x)) p" -text "Note that \transport\ is a polymorphic function in our formulation." +text \Note that @{term transport} is a polymorphic function in our formulation.\ -lemma transport_type: - assumes - "A: U i" "P: A \ U i" - "x: A" "y: A" - "p: x =\<^sub>A y" - shows "transport p: P x \ P y" -unfolding transport_def -by (rule Equal_elim[where ?p=p and ?x=x and ?y=y]) (routine lems: assms) - -lemma transport_comp: - assumes "A: U i" and "x: A" - shows "transport (refl x) \ id" -unfolding transport_def by (derive lems: assms) +lemma transport_type: "\p: x =\<^sub>A y; x: A; y: A; A: U i; P: A \ U i\ \ transport p: P x \ P y" +unfolding transport_def by (elim Equal_elim) routine + +lemma transport_comp: "\A: U i; x: A\ \ transport (refl x) \ id" +unfolding transport_def by derive end diff --git a/HoTT_Base.thy b/HoTT_Base.thy index 17e3142..7453883 100644 --- a/HoTT_Base.thy +++ b/HoTT_Base.thy @@ -7,9 +7,7 @@ Basic setup of a homotopy type theory object logic with a cumulative Russell-sty *) theory HoTT_Base -imports - Pure - "HOL-Eisbach.Eisbach" +imports Pure "HOL-Eisbach.Eisbach" begin diff --git a/HoTT_Methods.thy b/HoTT_Methods.thy index 411176e..8929f69 100644 --- a/HoTT_Methods.thy +++ b/HoTT_Methods.thy @@ -3,14 +3,11 @@ Title: HoTT_Methods.thy Author: Joshua Chen Date: 2018 -Method setup for the HoTT logic. Relies heavily on Eisbach. +Method setup for the HoTT logic. *) theory HoTT_Methods -imports - "HOL-Eisbach.Eisbach" - "HOL-Eisbach.Eisbach_Tools" - HoTT_Base +imports HoTT_Base "HOL-Eisbach.Eisbach" "HOL-Eisbach.Eisbach_Tools" begin @@ -43,16 +40,19 @@ Premises of the rule(s) applied are added as new subgoals. section \Derivation search\ -text \Combine @{method routine} and @{method compute} to search for derivations of judgments.\ +text \ +Combine @{method routine} and @{method compute} to search for derivations of judgments. +Also handle universes using methods @{method hierarchy} and @{method cumulativity} defined in @{file HoTT_Base.thy}. +\ -method derive uses lems = (routine add: lems | compute comp: lems)+ +method derive uses lems = (routine add: lems | compute comp: lems | cumulativity | hierarchy)+ section \Induction\ text \ - Placeholder section for the automation of induction, i.e. using the elimination rules. - At the moment one must directly apply them with \rule X_elim\. +Placeholder section for the automation of induction, i.e. using the elimination rules. +At the moment one must directly apply them with \rule X_elim\. \ diff --git a/Prod.thy b/Prod.thy index db18454..4aa7119 100644 --- a/Prod.thy +++ b/Prod.thy @@ -17,7 +17,7 @@ section \Basic definitions\ axiomatization Prod :: "[t, tf] \ t" and lambda :: "(t \ t) \ t" (binder "\<^bold>\" 30) and - appl :: "[t, t] \ t" ("(1_`/_)" [60, 61] 60) \ \Application binds tighter than abstraction.\ + appl :: "[t, t] \ t" ("(1_`/_)" [105, 106] 105) \ \Application binds tighter than abstraction.\ syntax "_prod" :: "[idt, t, t] \ t" ("(3\_:_./ _)" 30) @@ -43,7 +43,7 @@ axiomatization where Prod_elim: "\f: \x:A. B x; a: A\ \ f`a: B a" and - Prod_comp: "\\x. x: A \ b x: B x; a: A\ \ (\<^bold>\x. b x)`a \ b a" and + Prod_comp: "\a: A; \x. x: A \ b x: B x\ \ (\<^bold>\x. b x)`a \ b a" and Prod_uniq: "f: \x:A. B x \ \<^bold>\x. f`x \ f" and @@ -68,6 +68,7 @@ lemmas Prod_comps [comp] = Prod_comp Prod_uniq section \Additional definitions\ definition compose :: "[t, t] \ t" (infixr "o" 110) where "g o f \ \<^bold>\x. g`(f`x)" + syntax "_compose" :: "[t, t] \ t" (infixr "\" 110) translations "g \ f" \ "g o f" diff --git a/Univalence.thy b/Univalence.thy index 001ee33..3c9b520 100644 --- a/Univalence.thy +++ b/Univalence.thy @@ -1,176 +1,88 @@ -(* Title: HoTT/Univalence.thy - Author: Joshua Chen +(* +Title: Univalence.thy +Author: Joshua Chen +Date: 2018 Definitions of homotopy, equivalence and the univalence axiom. *) theory Univalence -imports - HoTT_Methods - EqualProps - ProdProps - Sum +imports HoTT_Methods EqualProps Prod Sum begin section \Homotopy and equivalence\ -axiomatization homotopic :: "[t, t] \ t" (infix "~" 100) where - homotopic_def: "\ - f: \x:A. B x; - g: \x:A. B x - \ \ f ~ g \ \x:A. (f`x) =[B x] (g`x)" +definition homotopic :: "[t, tf, t, t] \ t" where "homotopic A B f g \ \x:A. (f`x) =[B x] (g`x)" -axiomatization isequiv :: "t \ t" where - isequiv_def: "f: A \ B \ isequiv f \ (\g: B \ A. g \ f ~ id) \ (\g: B \ A. f \ g ~ id)" +syntax "_homotopic" :: "[t, idt, t, t, t] \ t" ("(1_ ~[_:_. _]/ _)" [101, 0, 0, 0, 101] 100) +translations "f ~[x:A. B] g" \ "CONST homotopic A (\x. B) f g" -definition equivalence :: "[t, t] \ t" (infix "\" 100) - where "A \ B \ \f: A \ B. isequiv f" - - -text "The identity function is an equivalence:" - -lemma isequiv_id: - assumes "A: U i" and "id: A \ A" - shows "<\x. refl x>, \x. refl x>>: isequiv id" -proof (derive lems: assms isequiv_def homotopic_def) - fix g assume asm: "g: A \ A" - show "id \ g: A \ A" - unfolding compose_def by (routine lems: asm assms) - - show "\x:A. ((id \ g)`x) =\<^sub>A (id`x): U i" - unfolding compose_def by (routine lems: asm assms) - next - - show "<\<^bold>\x. x, \<^bold>\x. refl x>: \g:A \ A. (g \ id) ~ id" - unfolding compose_def by (derive lems: assms homotopic_def) - - show "<\<^bold>\x. x, lambda refl>: \g:A \ A. (id \ g) ~ id" - unfolding compose_def by (derive lems: assms homotopic_def) -qed (rule assms) +declare homotopic_def [comp] +definition isequiv :: "[t, t, t] \ t" ("(3isequiv[_, _]/ _)") where + "isequiv[A, B] f \ (\g: B \ A. g \ f ~[x:A. A] id) \ (\g: B \ A. f \ g ~[x:B. B] id)" -text "We use the following lemma in a few proofs:" +text \ +The meanings of the syntax defined above are: +\<^item> @{term "f ~[x:A. B x] g"} expresses that @{term f} and @{term g} are homotopic functions of type @{term "\x:A. B x"}. +\<^item> @{term "isequiv[A, B] f"} expresses that the non-dependent function @{term f} of type @{term "A \ B"} is an equivalence. +\ -lemma isequiv_type: - assumes "A: U i" and "B: U i" and "f: A \ B" - shows "isequiv f: U i" - by (derive lems: assms isequiv_def homotopic_def compose_def) - - -text "The equivalence relation \\\ is symmetric:" +definition equivalence :: "[t, t] \ t" (infix "\" 100) + where "A \ B \ \f: A \ B. isequiv[A, B] f" + +lemma id_isequiv: + assumes "A: U i" "id: A \ A" + shows "<\x. refl x>, \x. refl x>>: isequiv[A, A] id" +unfolding isequiv_def proof (routine add: assms) + show "\g. g: A \ A \ id \ g ~[x:A. A] id: U i" by (derive lems: assms) + show "\x. refl x>: \g:A \ A. (g \ id) ~[x:A. A] id" by (derive lems: assms) + show "\x. refl x>: \g:A \ A. (id \ g) ~[x:A. A] id" by (derive lems: assms) +qed -lemma equiv_sym: +lemma equivalence_symm: assumes "A: U i" and "id: A \ A" shows "\x. refl x>, \x. refl x>>>: A \ A" unfolding equivalence_def proof - show "<\x. refl x>, \x. refl x>>: isequiv id" using assms by (rule isequiv_id) - - fix f assume "f: A \ A" - with assms(1) assms(1) show "isequiv f: U i" by (rule isequiv_type) -qed (rule assms) + show "\f. f: A \ A \ isequiv[A, A] f: U i" by (derive lems: assms isequiv_def) + show "<\x. refl x>, \x. refl x>>: isequiv[A, A] id" using assms by (rule id_isequiv) +qed fact -section \idtoeqv and the univalence axiom\ +section \idtoeqv\ -definition idtoeqv :: t - where "idtoeqv \ \<^bold>\p. = (\A. <\x. refl x>, \x. refl x>>) p>" +definition idtoeqv :: t where "idtoeqv \ \<^bold>\p. = (\_. <\x. refl x>, \x. refl x>>) p>" - -text "We prove that equal types are equivalent. The proof is long and uses universes." +text \We prove that equal types are equivalent. The proof involves universe types.\ theorem assumes "A: U i" and "B: U i" shows "idtoeqv: (A =[U i] B) \ A \ B" -unfolding idtoeqv_def equivalence_def -proof - fix p assume "p: A =[U i] B" - show "= (\A. <\x. refl x>, \x. refl x>>) p>: \f: A \ B. isequiv f" - proof - { fix f assume "f: A \ B" - with assms show "isequiv f: U i" by (rule isequiv_type) - } - - show "transport p: A \ B" - proof (rule transport_type[where ?P="\x. x" and ?A="U i" and ?i="Suc i"]) - show "\x. x: U i \ x: U (Suc i)" by cumulativity - show "U i: U (Suc i)" by hierarchy - qed fact+ +unfolding idtoeqv_def equivalence_def proof (routine add: assms) + show *: "\f. f: A \ B \ isequiv[A, B] f: U i" + unfolding isequiv_def by (derive lems: assms) + + show "\p. p: A =[U i] B \ transport p: A \ B" + by (derive lems: assms transport_type[where ?i="Suc i"]) + \ \Instantiate @{thm transport_type} with a suitable universe level here...\ + + show "\p. p: A =[U i] B \ ind\<^sub>= (\_. <\x. refl x>, \x. refl x>>) p: isequiv[A, B] (transport p)" + proof (elim Equal_elim) + show "\T. T: U i \ <\x. refl x>, \x. refl x>>: isequiv[T, T] (transport (refl T))" + by (derive lems: transport_comp[where ?i="Suc i" and ?A="U i"] id_isequiv) + \ \...and also here.\ - show "ind\<^sub>= (\A. <\x. refl x>, \x. refl x>>) p: isequiv (transport p)" - proof (rule Equal_elim[where ?C="\_ _ p. isequiv (transport p)"]) - fix A assume asm: "A: U i" - show "<\x. refl x>, \x. refl x>>: isequiv (transport (refl A))" - proof (derive lems: isequiv_def) - show "transport (refl A): A \ A" - unfolding transport_def - by (compute lems: Equal_comp[where ?A="U i" and ?C="\_ _ _. A \ A"]) (derive lems: asm) - - show "<\x. refl x>, \x. refl x>>: - (\g:A \ A. g \ (transport (refl A)) ~ id) \ - (\g:A \ A. (transport (refl A)) \ g ~ id)" - proof (subst (1 2) transport_comp) - show "U i: U (Suc i)" by (rule U_hierarchy) rule - show "U i: U (Suc i)" by (rule U_hierarchy) rule - - show "<\x. refl x>, \x. refl x>>: - (\g:A \ A. g \ id ~ id) \ (\g:A \ A. id \ g ~ id)" - proof - show "\g:A \ A. id \ g ~ id: U i" - proof (derive lems: asm homotopic_def) - fix g assume asm': "g: A \ A" - show *: "id \ g: A \ A" by (derive lems: asm asm' compose_def) - show "\x:A. ((id \ g)`x) =\<^sub>A (id`x): U i" by (derive lems: asm *) - qed (routine lems: asm) - - show "\x. refl x>: \g:A \ A. id \ g ~ id" - proof - fix g assume asm': "g: A \ A" - show "id \ g ~ id: U i" - proof (derive lems: homotopic_def) - show *: "id \ g: A \ A" by (derive lems: asm asm' compose_def) - show "\x:A. ((id \ g)`x) =\<^sub>A (id`x): U i" by (derive lems: asm *) - qed (routine lems: asm) - next - show "\<^bold>\x. refl x: id \ id ~ id" - proof compute - show "\<^bold>\x. refl x: id ~ id" by (subst homotopic_def) (derive lems: asm) - qed (rule asm) - qed (routine lems: asm) - - show "\x. refl x>: \g:A \ A. g \ id ~ id" - proof - fix g assume asm': "g: A \ A" - show "g \ id ~ id: U i" by (derive lems: asm asm' homotopic_def compose_def) - next - show "\<^bold>\x. refl x: id \ id ~ id" - proof compute - show "\<^bold>\x. refl x: id ~ id" by (subst homotopic_def) (derive lems: asm) - qed (rule asm) - qed (routine lems: asm) - qed - qed fact+ - qed - next - - fix A' B' p' assume asm: "A': U i" "B': U i" "p': A' =[U i] B'" - show "isequiv (transport p'): U i" - proof (rule isequiv_type) - show "transport p': A' \ B'" by (derive lems: asm transport_def) - qed fact+ - qed fact+ - qed - next - - show "A =[U i] B: U (Suc i)" proof (derive lems: assms, (rule U_hierarchy, rule lt_Suc)?)+ -qed + show "\A B p. \A: U i; B: U i; p: A =[U i] B\ \ isequiv[A, B] (transport p): U i" + unfolding isequiv_def by (derive lems: assms transport_type) + qed fact+ +qed (derive lems: assms) -text "The univalence axiom." +section \The univalence axiom\ -axiomatization univalence :: t where - UA: "univalence: isequiv idtoeqv" +axiomatization univalence :: "[t, t] \ t" where UA: "univalence A B: isequiv[A, B] idtoeqv" end -- cgit v1.2.3