From 746fab6476dc622a982d5ebaeb30a2e1426c3316 Mon Sep 17 00:00:00 2001 From: Josh Chen Date: Sun, 19 Aug 2018 17:28:48 +0200 Subject: Higher groupoid structure of types --- EqualProps.thy | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 67 insertions(+), 4 deletions(-) diff --git a/EqualProps.thy b/EqualProps.thy index a1d4c45..be8e53e 100644 --- a/EqualProps.thy +++ b/EqualProps.thy @@ -33,7 +33,7 @@ text " " lemma inv_comp: - assumes "A : U(i)" and "a : A" shows "(refl a)\ \ refl(a)" + 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" .. @@ -194,7 +194,7 @@ qed fact text "The raw object lambda term is cumbersome to use, so we define a simpler constant instead." -axiomatization pathcomp :: "[Term, Term] \ Term" (infixl "\" 60) where +axiomatization pathcomp :: "[Term, Term] \ Term" (infixl "\" 120) where pathcomp_def: "\ A: U(i); x: A; y: A; z: A; @@ -214,8 +214,71 @@ lemma pathcomp_comp: by (subst pathcomp_def) (routine lems: assms rpathcomp_comp) -lemmas EqualProps_type [intro] = inv_type pathcomp_type -lemmas EqualProps_comp [comp] = inv_comp pathcomp_comp +lemmas inv_type [intro] +lemmas pathcomp_type [intro] +lemmas inv_comp [comp] +lemmas pathcomp_comp [comp] + + +section \Weak higher groupoid structure of types\ + +schematic_goal whg1a: + 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) + +schematic_goal whg1b: + assumes "A: U(i)" "x: A" "y: A" "p: x =\<^sub>A y" + shows "?a: p =[x =\<^sub>A y] (refl(x) \ 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) + +schematic_goal whg2a: + 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)+ + +schematic_goal whg2b: + 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)+ + +schematic_goal whg3: + 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) + + +schematic_goal + assumes + "A: U(i)" and + "x: A" "y: A" "z: A" "w: A" and + "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) + end -- cgit v1.2.3 From ae909b21905be847a2ce01388e34708c9d0246c0 Mon Sep 17 00:00:00 2001 From: Josh Chen Date: Sun, 19 Aug 2018 17:29:25 +0200 Subject: Trying to atomize universal quantification --- Prod.thy | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Prod.thy b/Prod.thy index b0408b9..3b74531 100644 --- a/Prod.thy +++ b/Prod.thy @@ -81,4 +81,13 @@ syntax "_COMPOSE" :: "[Term, Term] \ Term" (infixr "\" 70) translations "g \ f" \ "g o f" +section \Atomization\ + +text " + Universal statements can be internalized within the theory; the following rule is admissible. +" (* PROOF NEEDED *) + +axiomatization where Prod_atomize: "(\<^bold>\x. b(x): \x:A. B(x)) \ (\x. x: A \ b(x): B(x))" + + end -- cgit v1.2.3 From 515872533295e8464799467303fff923b52a2c01 Mon Sep 17 00:00:00 2001 From: Josh Chen Date: Sat, 15 Sep 2018 20:51:39 +0200 Subject: begin reorganizing --- HoTT_Base.thy | 19 ++++++++++--------- tests/Test.thy | 2 +- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/HoTT_Base.thy b/HoTT_Base.thy index 1110e14..8ea767f 100644 --- a/HoTT_Base.thy +++ b/HoTT_Base.thy @@ -1,11 +1,12 @@ (* Title: HoTT/HoTT_Base.thy - Author: Josh Chen + Author: Joshua Chen Basic setup and definitions of a homotopy type theory object logic with a cumulative universe hierarchy à la Russell. *) theory HoTT_Base - imports Pure +imports Pure + begin @@ -13,7 +14,7 @@ section \Foundational definitions\ text "Meta syntactic type for object-logic types and terms." -typedecl Term +typedecl t section \Judgments\ @@ -23,19 +24,19 @@ text " For judgmental/definitional equality we use the existing Pure equality \\\ and hence do not need to define a separate judgment for it. " -judgment has_type :: "[Term, Term] \ prop" ("(3_:/ _)" [0, 0] 1000) +judgment hastype :: "[t, t] \ prop" ("(3_:/ _)") section \Universe hierarchy\ -text "Finite meta-ordinals to index the universes." +text "Meta-numerals to index the universes." -typedecl Ord +typedecl ord axiomatization - O :: Ord and - S :: "Ord \ Ord" ("S_" [0] 1000) and - lt :: "[Ord, Ord] \ prop" (infix "<-" 999) + O :: ord and + S :: "ord \ ord" ("S_") and + lt :: "[ord, ord] \ prop" (infix "<-" 999) where Ord_min: "\n. O <- S(n)" and diff --git a/tests/Test.thy b/tests/Test.thy index b0eb87a..de65dbd 100644 --- a/tests/Test.thy +++ b/tests/Test.thy @@ -23,7 +23,7 @@ declare[[unify_trace_simp, unify_trace_types, simp_trace, simp_trace_depth_limit \ \Turn on trace for unification and the simplifier, for debugging.\ -section \\-type\ +section \\-type\ subsection \Typing functions\ -- cgit v1.2.3 From ea0c0c5427888982adce10ab25cebe445997f08b Mon Sep 17 00:00:00 2001 From: Josh Chen Date: Mon, 17 Sep 2018 13:13:08 +0200 Subject: Moved function composition lemmas into Prod.thy --- Prod.thy | 102 +++++++++++++++++++++++++++++----------------------------- ProdProps.thy | 57 -------------------------------- 2 files changed, 51 insertions(+), 108 deletions(-) delete mode 100644 ProdProps.thy diff --git a/Prod.thy b/Prod.thy index a3cc347..db18454 100644 --- a/Prod.thy +++ b/Prod.thy @@ -1,89 +1,89 @@ -(* Title: HoTT/Prod.thy - Author: Josh Chen +(* +Title: Prod.thy +Author: Joshua Chen +Date: 2018 -Dependent product (function) type +Dependent product type *) theory Prod - imports HoTT_Base +imports HoTT_Base HoTT_Methods + begin -section \Constants and syntax\ +section \Basic definitions\ axiomatization - Prod :: "[t, tf] \ t" and + Prod :: "[t, tf] \ t" and lambda :: "(t \ t) \ t" (binder "\<^bold>\" 30) and - appl :: "[t, t] \ t" (infixl "`" 60) - \ \Application binds tighter than abstraction.\ + appl :: "[t, t] \ t" ("(1_`/_)" [60, 61] 60) \ \Application binds tighter than abstraction.\ syntax - "_PROD" :: "[idt, t, t] \ t" ("(3\_:_./ _)" 30) - "_PROD_ASCII" :: "[idt, t, t] \ t" ("(3PROD _:_./ _)" 30) + "_prod" :: "[idt, t, t] \ t" ("(3\_:_./ _)" 30) + "_prod_ascii" :: "[idt, t, t] \ t" ("(3II _:_./ _)" 30) -text "The translations below bind the variable \x\ in the expressions \B\ and \b\." +text \The translations below bind the variable @{term x} in the expressions @{term B} and @{term b}.\ translations "\x:A. B" \ "CONST Prod A (\x. B)" - "PROD x:A. B" \ "CONST Prod A (\x. B)" + "II x:A. B" \ "CONST Prod A (\x. B)" -text "Nondependent functions are a special case." +text \Non-dependent functions are a special case.\ -abbreviation Function :: "[t, t] \ t" (infixr "\" 40) +abbreviation Fun :: "[t, t] \ t" (infixr "\" 40) where "A \ B \ \_: A. B" +axiomatization where +\ \Type rules\ -section \Type rules\ + Prod_form: "\A: U i; B: A \ U i\ \ \x:A. B x: U i" and -axiomatization where - Prod_form: "\A: U i; B: A \ U i\ \ \x:A. B x: U i" -and - Prod_intro: "\\x. x: A \ b x: B x; A: U i\ \ \<^bold>\x. b x: \x:A. B x" -and - Prod_elim: "\f: \x:A. B x; a: A\ \ f`a: B a" -and - Prod_appl: "\\x. x: A \ b x: B x; a: A\ \ (\<^bold>\x. b x)`a \ b a" -and - Prod_uniq: "f : \x:A. B x \ \<^bold>\x. (f`x) \ f" -and - Prod_eq: "\\x. x: A \ b x \ c x; A: U i\ \ \<^bold>\x. b x \ \<^bold>\x. c x" - -text " - The Pure rules for \\\ only let us judge strict syntactic equality of object lambda expressions; Prod_eq is the actual definitional equality rule. - - Note that the syntax \\<^bold>\\ (bold lambda) used for dependent functions clashes with the proof term syntax (cf. \
2.5.2 of the Isabelle/Isar Implementation). -" - -text " - In addition to the usual type rules, it is a meta-theorem that whenever \\x:A. B x: U i\ is derivable from some set of premises \, then so are \A: U i\ and \B: A \ U i\. - - That is to say, the following inference rules are admissible, and it simplifies proofs greatly to axiomatize them directly. -" + Prod_intro: "\\x. x: A \ b x: B x; A: U i\ \ \<^bold>\x. b x: \x:A. B x" and -axiomatization where - Prod_wellform1: "(\x:A. B x: U i) \ A: U i" -and - Prod_wellform2: "(\x:A. B x: U i) \ B: A \ U i" + 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_uniq: "f: \x:A. B x \ \<^bold>\x. f`x \ f" and +\ \Congruence rules\ -text "Rule attribute declarations---set up various methods to use the type rules." + Prod_form_eq: "\A: U i; B: A \ U i; C: A \ U i; \x. x: A \ B x \ C x\ \ \x:A. B x \ \x:A. C x" and + + Prod_intro_eq: "\\x. x: A \ b x \ c x; A: U i\ \ \<^bold>\x. b x \ \<^bold>\x. c x" + +text \ +The Pure rules for \\\ only let us judge strict syntactic equality of object lambda expressions. +The actual definitional equality rule is @{thm Prod_intro_eq}. +Note that this is a separate rule from function extensionality. + +Note that the bold lambda symbol \\<^bold>\\ used for dependent functions clashes with the proof term syntax (cf. \
2.5.2 of the Isabelle/Isar Implementation). +\ -lemmas Prod_comp [comp] = Prod_appl Prod_uniq -lemmas Prod_wellform [wellform] = Prod_wellform1 Prod_wellform2 lemmas Prod_routine [intro] = Prod_form Prod_intro Prod_elim +lemmas Prod_comps [comp] = Prod_comp Prod_uniq -section \Function composition\ +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) +syntax "_compose" :: "[t, t] \ t" (infixr "\" 110) translations "g \ f" \ "g o f" +declare compose_def [comp] + +lemma compose_assoc: + assumes "A: U i" and "f: A \ B" "g: B \ C" "h: \x:C. D x" + shows "(h \ g) \ f \ h \ (g \ f)" +by (derive lems: assms Prod_intro_eq) -section \Polymorphic identity function\ +lemma compose_comp: + assumes "A: U i" and "\x. x: A \ b x: B" and "\x. x: B \ c x: C x" + shows "(\<^bold>\x. c x) \ (\<^bold>\x. b x) \ \<^bold>\x. c (b x)" +by (derive lems: assms Prod_intro_eq) -abbreviation id :: t where "id \ \<^bold>\x. x" +abbreviation id :: t where "id \ \<^bold>\x. x" \ \Polymorphic identity function\ end diff --git a/ProdProps.thy b/ProdProps.thy deleted file mode 100644 index a68f79b..0000000 --- a/ProdProps.thy +++ /dev/null @@ -1,57 +0,0 @@ -(* Title: HoTT/ProdProps.thy - Author: Josh Chen - -Properties of the dependent product -*) - -theory ProdProps - imports - HoTT_Methods - Prod -begin - - -section \Composition\ - -text " - The proof of associativity needs some guidance; it involves telling Isabelle to use the correct rule for \-type definitional equality, and the correct substitutions in the subgoals thereafter. -" - -lemma compose_assoc: - assumes "A: U i" and "f: A \ B" "g: B \ C" "h: \x:C. D x" - shows "(h \ g) \ f \ h \ (g \ f)" -proof (subst (0 1 2 3) compose_def) - show "\<^bold>\x. (\<^bold>\y. h`(g`y))`(f`x) \ \<^bold>\x. h`((\<^bold>\y. g`(f`y))`x)" - proof (subst Prod_eq) - \ \Todo: set the Simplifier (or other simplification methods) up to use \Prod_eq\!\ - - show "\x. x: A \ (\<^bold>\y. h`(g`y))`(f`x) \ h`((\<^bold>\y. g`(f`y))`x)" - proof compute - show "\x. x: A \ h`(g`(f`x)) \ h`((\<^bold>\y. g`(f`y))`x)" - proof compute - show "\x. x: A \ g`(f`x): C" by (routine lems: assms) - qed - show "\x. x: B \ h`(g`x): D (g`x)" by (routine lems: assms) - qed (routine lems: assms) - qed fact -qed - - -lemma compose_comp: - assumes "A: U i" and "\x. x: A \ b x: B" and "\x. x: B \ c x: C x" - shows "(\<^bold>\x. c x) \ (\<^bold>\x. b x) \ \<^bold>\x. c (b x)" -proof (subst compose_def, subst Prod_eq) - show "\a. a: A \ (\<^bold>\x. c x)`((\<^bold>\x. b x)`a) \ (\<^bold>\x. c (b x))`a" - proof compute - show "\a. a: A \ c ((\<^bold>\x. b x)`a) \ (\<^bold>\x. c (b x))`a" - by (derive lems: assms) - qed (routine lems: assms) -qed (derive lems: assms) - - -text "Set up the \compute\ method to automatically simplify function compositions." - -lemmas compose_comp [comp] - - -end -- cgit v1.2.3 From 76ac8ed82317f3f62f26ecc88f412c61004bcffa Mon Sep 17 00:00:00 2001 From: Josh Chen Date: Mon, 17 Sep 2018 13:13:55 +0200 Subject: Reorganizing theories --- Coprod.thy | 64 +++++++++++++++++++++----------------------------------- Empty.thy | 22 ++++++++----------- HoTT.thy | 2 +- HoTT_Base.thy | 25 ++++++++++++---------- HoTT_Methods.thy | 56 +++++++++++++++++++------------------------------ Nat.thy | 60 ++++++++++++++++++++++++---------------------------- Proj.thy | 56 ++++++++++++++++++------------------------------- Sum.thy | 57 ++++++++++++++++++++----------------------------- Unit.thy | 32 +++++++++++++--------------- 9 files changed, 155 insertions(+), 219 deletions(-) diff --git a/Coprod.thy b/Coprod.thy index 97e0566..d97228e 100644 --- a/Coprod.thy +++ b/Coprod.thy @@ -1,65 +1,49 @@ -(* Title: HoTT/Coprod.thy - Author: Josh Chen +(* +Title: Coprod.thy +Author: Joshua Chen +Date: 2018 Coproduct type *) theory Coprod - imports HoTT_Base -begin +imports HoTT_Base +begin -section \Constants and type rules\ axiomatization - Coprod :: "[t, t] \ t" (infixr "+" 50) and - inl :: "t \ t" and - inr :: "t \ t" and + Coprod :: "[t, t] \ t" (infixr "+" 50) and + inl :: "t \ t" and + inr :: "t \ t" and indCoprod :: "[t \ t, t \ t, t] \ t" ("(1ind\<^sub>+)") where - Coprod_form: "\A: U i; B: U i\ \ A + B: U i" -and - Coprod_intro_inl: "\a: A; B: U i\ \ inl a: A + B" -and - Coprod_intro_inr: "\b: B; A: U i\ \ inr b: A + B" -and + Coprod_form: "\A: U i; B: U i\ \ A + B: U i" and + + Coprod_intro_inl: "\a: A; B: U i\ \ inl a: A + B" and + + Coprod_intro_inr: "\b: B; A: U i\ \ inr b: A + B" and + Coprod_elim: "\ + u: A + B; C: A + B \ U i; \x. x: A \ c x: C (inl x); - \y. y: B \ d y: C (inr y); - u: A + B - \ \ ind\<^sub>+ c d u: C u" -and + \y. y: B \ d y: C (inr y) \ \ ind\<^sub>+ (\ x. c x) (\y. d y) u: C u" and + Coprod_comp_inl: "\ + a: A; C: A + B \ U i; \x. x: A \ c x: C (inl x); - \y. y: B \ d y: C (inr y); - a: A - \ \ ind\<^sub>+ c d (inl a) \ c a" -and + \y. y: B \ d y: C (inr y) \ \ ind\<^sub>+ (\x. c x) (\y. d y) (inl a) \ c a" and + Coprod_comp_inr: "\ + b: B; C: A + B \ U i; \x. x: A \ c x: C (inl x); - \y. y: B \ d y: C (inr y); - b: B - \ \ ind\<^sub>+ c d (inr b) \ d b" - - -text "Admissible formation inference rules:" - -axiomatization where - Coprod_wellform1: "A + B: U i \ A: U i" -and - Coprod_wellform2: "A + B: U i \ B: U i" - - -text "Rule attribute declarations:" - -lemmas Coprod_intro = Coprod_intro_inl Coprod_intro_inr + \y. y: B \ d y: C (inr y) \ \ ind\<^sub>+ (\x. c x) (\y. d y) (inr b) \ d b" +lemmas Coprod_routine [intro] = Coprod_form Coprod_intro_inl Coprod_intro_inr Coprod_elim lemmas Coprod_comp [comp] = Coprod_comp_inl Coprod_comp_inr -lemmas Coprod_wellform [wellform] = Coprod_wellform1 Coprod_wellform2 -lemmas Coprod_routine [intro] = Coprod_form Coprod_intro Coprod_elim end diff --git a/Empty.thy b/Empty.thy index 107f2d7..3060867 100644 --- a/Empty.thy +++ b/Empty.thy @@ -1,28 +1,24 @@ -(* Title: HoTT/Empty.thy - Author: Josh Chen +(* +Title: Empty.thy +Author: Joshua Chen +Date: 2018 Empty type *) theory Empty - imports HoTT_Base -begin - +imports HoTT_Base -section \Constants and type rules\ +begin -section \Empty type\ axiomatization - Empty :: t ("\") and + Empty :: t ("\") and indEmpty :: "t \ t" ("(1ind\<^sub>\)") where - Empty_form: "\: U O" -and - Empty_elim: "\C: \ \ U i; z: \\ \ ind\<^sub>\ z: C z" - + Empty_form: "\: U O" and -text "Rule attribute declarations:" + Empty_elim: "\a: \; C: \ \ U i\ \ ind\<^sub>\ a: C a" lemmas Empty_routine [intro] = Empty_form Empty_elim diff --git a/HoTT.thy b/HoTT.thy index abb1085..3f2d475 100644 --- a/HoTT.thy +++ b/HoTT.thy @@ -30,7 +30,7 @@ begin lemmas forms = Nat_form Prod_form Sum_form Coprod_form Equal_form Unit_form Empty_form lemmas intros = - Nat_intro Prod_intro Sum_intro Equal_intro Coprod_intro Unit_intro + Nat_intro_0 Nat_intro_succ Prod_intro Sum_intro Equal_intro Coprod_intro_inl Coprod_intro_inr Unit_intro lemmas elims = Nat_elim Prod_elim Sum_elim Equal_elim Coprod_elim Unit_elim Empty_elim lemmas routines = diff --git a/HoTT_Base.thy b/HoTT_Base.thy index 07fbfc4..efc6182 100644 --- a/HoTT_Base.thy +++ b/HoTT_Base.thy @@ -1,7 +1,9 @@ -(* Title: HoTT/HoTT_Base.thy - Author: Joshua Chen +(* +Title: HoTT_Base.thy +Author: Joshua Chen +Date: 2018 -Basic setup of a homotopy type theory object logic with a Russell-style cumulative universe hierarchy. +Basic setup of a homotopy type theory object logic with a cumulative Russell-style universe hierarchy. *) theory HoTT_Base @@ -49,8 +51,8 @@ Using method @{method rule} with @{thm U_cumulative} is unsafe, if applied blind One should instead use @{method elim}, or instantiate @{thm U_cumulative} suitably. \ -method cumulativity = (elim U_cumulative, proveSuc) \ \Proves \A: U i \ A: U (Suc (... (Suc i) ...))\.\ -method hierarchy = (rule U_hierarchy, proveSuc) \ \Proves \U i: U (Suc (... (Suc i) ...)).\\ +method cumulativity = (elim U_cumulative, proveSuc) \ \Proves \A: U i \ A: U (Suc (... (Suc i) ...))\\ +method hierarchy = (rule U_hierarchy, proveSuc) \ \Proves \U i: U (Suc (... (Suc i) ...))\\ section \Type families\ @@ -59,22 +61,23 @@ abbreviation (input) constrained :: "[t \ t, t, t] \ pro where "f: A \ B \ (\x. x : A \ f x: B)" text \ -The abbreviation @{abbrev constrained} is used to define type families, which are constrained expressions @{term "P: A \ B"} where @{term "A::t"} and @{term "B::t"} are small types. +The abbreviation @{abbrev constrained} is used to define type families, which are constrained expressions @{term "P: A \ B"}, where @{term "A::t"} and @{term "B::t"} are small types. \ -type_synonym tf = "t \ t" \ \Type of type families.\ +type_synonym tf = "t \ t" \ \Type of type families\ section \Named theorems\ +named_theorems comp + text \ Declare named theorems to be used by proof methods defined in @{file HoTT_Methods.thy}. -\wellform\ declares necessary well-formedness conditions for type and inhabitation judgments. -\comp\ declares computation rules, which are usually passed to invocations of the method \subst\ to perform equational rewriting. +@{attribute comp} declares computation rules. +These are used by the \compute\ method, and may also be passed to invocations of the method \subst\ to perform equational rewriting. \ -named_theorems wellform -named_theorems comp +(* Todo: Set up the simplifier! *) end diff --git a/HoTT_Methods.thy b/HoTT_Methods.thy index abb6dda..9849195 100644 --- a/HoTT_Methods.thy +++ b/HoTT_Methods.thy @@ -1,63 +1,51 @@ -(* Title: HoTT/HoTT_Methods.thy - Author: Josh Chen +(* +Title: HoTT_Methods.thy +Author: Joshua Chen +Date: 2018 -Method setup for the HoTT library. Relies heavily on Eisbach. +Method setup for the HoTT logic. Relies heavily on Eisbach. *) theory HoTT_Methods - imports - "HOL-Eisbach.Eisbach" - "HOL-Eisbach.Eisbach_Tools" - HoTT_Base +imports + "HOL-Eisbach.Eisbach" + "HOL-Eisbach.Eisbach_Tools" + HoTT_Base + begin section \Deriving typing judgments\ -method routine uses lems = (assumption | rule lems | standard)+ - -text " - @{method routine} proves routine type judgments \a : A\ using the rules declared [intro] in the respective theory files, as well as additional provided lemmas. -" - -text " - \wellformed'\ finds a proof of any valid typing judgment derivable from the judgment passed as \jdmt\. - If no judgment is passed, it will try to resolve with the theorems declared \wellform\. - \wellform\ is like \wellformed'\ but takes multiple judgments. - - The named theorem \wellform\ is declared in HoTT_Base.thy. -" +method routine uses add = (assumption | rule add | rule)+ -method wellformed' uses jdmt declares wellform = - match wellform in rl: "PROP ?P" \ \( - catch \rule rl[OF jdmt]\ \fail\ | - catch \wellformed' jdmt: rl[OF jdmt]\ \fail\ - )\ - -method wellformed uses lems = - match lems in lem: "?X : ?Y" \ \wellformed' jdmt: lem\ +text \ +The method @{method routine} proves type judgments @{prop "a : A"} using the rules declared @{attribute intro} in the respective theory files, as well as additional provided lemmas passed using the modifier \add\. +\ section \Substitution and simplification\ -text "Import the \subst\ method, used for substituting definitional equalities." - ML_file "~~/src/Tools/misc_legacy.ML" ML_file "~~/src/Tools/IsaPlanner/isand.ML" ML_file "~~/src/Tools/IsaPlanner/rw_inst.ML" ML_file "~~/src/Tools/IsaPlanner/zipper.ML" ML_file "~~/src/Tools/eqsubst.ML" -text "Perform basic single-step computations:" +\ \Import the @{method subst} method, used for substituting definitional equalities.\ -method compute uses lems = (subst lems comp | rule lems comp) +method compute declares comp = (subst comp) +text \ +Method @{method compute} performs single-step simplifications, using any rules declared @{attribute comp} in the context. +Premises of the rule(s) applied are added as new subgoals. +\ section \Derivation search\ -text " Combine \routine\, \wellformed\, and \compute\ to search for derivations of judgments." +text \Combine @{method routine} and @{method compute} to search for derivations of judgments.\ -method derive uses lems = (routine lems: lems | compute lems: lems | wellformed lems: lems)+ +method derive uses lems = (routine add: lems | compute comp: lems)+ section \Induction\ diff --git a/Nat.thy b/Nat.thy index a82e7cb..46b1af5 100644 --- a/Nat.thy +++ b/Nat.thy @@ -1,54 +1,48 @@ -(* Title: HoTT/Nat.thy - Author: Josh Chen +(* +Title: Nat.thy +Author: Joshua Chen +Date: 2018 Natural numbers *) theory Nat - imports HoTT_Base -begin +imports HoTT_Base +begin -section \Constants and type rules\ axiomatization - Nat :: t ("\") and - zero :: t ("0") and - succ :: "t \ t" and + Nat :: t ("\") and + zero :: t ("0") and + succ :: "t \ t" and indNat :: "[[t, t] \ t, t, t] \ t" ("(1ind\<^sub>\)") where - Nat_form: "\: U O" -and - Nat_intro_0: "0: \" -and - Nat_intro_succ: "n: \ \ succ n: \" -and + Nat_form: "\: U O" and + + Nat_intro_0: "0: \" and + + Nat_intro_succ: "n: \ \ succ n: \" and + Nat_elim: "\ - C: \ \ U i; - \n c. \n: \; c: C n\ \ f n c: C (succ n); a: C 0; - n: \ - \ \ ind\<^sub>\ f a n: C n" -and + n: \; + C: \ \ U i; + \n c. \n: \; c: C n\ \ f n c: C (succ n) \ \ ind\<^sub>\ (\n c. f n c) a n: C n" and + Nat_comp_0: "\ + a: C 0; C: \ \ U i; - \n c. \n: \; c: C(n)\ \ f n c: C (succ n); - a: C 0 - \ \ ind\<^sub>\ f a 0 \ a" -and + \n c. \n: \; c: C(n)\ \ f n c: C (succ n) \ \ ind\<^sub>\ (\n c. f n c) a 0 \ a" and + Nat_comp_succ: "\ - C: \ \ U i; - \n c. \n: \; c: C n\ \ f n c: C (succ n); a: C 0; - n: \ - \ \ ind\<^sub>\ f a (succ n) \ f n (ind\<^sub>\ f a n)" - - -text "Rule attribute declarations:" + n: \; + C: \ \ U i; + \n c. \n: \; c: C n\ \ f n c: C (succ n) \ \ ind\<^sub>\ (\n c. f n c) a (succ n) \ f n (ind\<^sub>\ f a n)" -lemmas Nat_intro = Nat_intro_0 Nat_intro_succ -lemmas Nat_comp [comp] = Nat_comp_0 Nat_comp_succ -lemmas Nat_routine [intro] = Nat_form Nat_intro Nat_elim +lemmas Nat_routine [intro] = Nat_form Nat_intro_0 Nat_intro_succ Nat_elim +lemmas Nat_comps [comp] = Nat_comp_0 Nat_comp_succ end diff --git a/Proj.thy b/Proj.thy index 74c561c..f272224 100644 --- a/Proj.thy +++ b/Proj.thy @@ -1,62 +1,46 @@ -(* Title: HoTT/Proj.thy - Author: Josh Chen +(* +Title: Proj.thy +Author: Joshua Chen +Date: 2018 Projection functions \fst\ and \snd\ for the dependent sum type. *) theory Proj - imports - HoTT_Methods - Prod - Sum -begin +imports + HoTT_Methods + Prod + Sum +begin -definition fst :: "Term \ Term" where "fst p \ ind\<^sub>\ (\x y. x) p" -definition snd :: "Term \ Term" where "snd p \ ind\<^sub>\ (\x y. y) p" -text "Typing judgments and computation rules for the dependent and non-dependent projection functions." +definition fst :: "t \ t" where "fst p \ ind\<^sub>\ (\x y. x) p" +definition snd :: "t \ t" where "snd p \ ind\<^sub>\ (\x y. y) p" lemma fst_type: - assumes "\x:A. B x: U i" and "p: \x:A. B x" shows "fst p: A" + assumes "A: U i" and "B: A \ U i" and "p: \x:A. B x" shows "fst p: A" unfolding fst_def by (derive lems: assms) lemma fst_comp: assumes "A: U i" and "B: A \ U i" and "a: A" and "b: B a" shows "fst \ a" -unfolding fst_def -proof compute - show "a: A" and "b: B a" by fact+ -qed (routine lems: assms)+ +unfolding fst_def by compute (derive lems: assms) lemma snd_type: - assumes "\x:A. B x: U i" and "p: \x:A. B x" shows "snd p: B (fst p)" -unfolding snd_def -proof + assumes "A: U i" and "B: A \ U i" and "p: \x:A. B x" shows "snd p: B (fst p)" +unfolding snd_def proof show "\p. p: \x:A. B x \ B (fst p): U i" by (derive lems: assms fst_type) - fix x y - assume asm: "x: A" "y: B x" - show "y: B (fst )" - proof (subst fst_comp) - show "A: U i" by (wellformed lems: assms(1)) - show "\x. x: A \ B x: U i" by (wellformed lems: assms(1)) - qed fact+ + fix x y assume asm: "x: A" "y: B x" + show "y: B (fst )" by (derive lems: asm assms fst_comp) qed fact lemma snd_comp: assumes "A: U i" and "B: A \ U i" and "a: A" and "b: B a" shows "snd \ b" -unfolding snd_def -proof compute - show "\x y. y: B x \ y: B x" . - show "a: A" by fact - show "b: B a" by fact -qed (routine lems: assms) - - -text "Rule attribute declarations:" +unfolding snd_def by (derive lems: assms) -lemmas Proj_type [intro] = fst_type snd_type -lemmas Proj_comp [comp] = fst_comp snd_comp +lemmas Proj_types [intro] = fst_type snd_type +lemmas Proj_comps [comp] = fst_comp snd_comp end diff --git a/Sum.thy b/Sum.thy index 92375b9..422e01b 100644 --- a/Sum.thy +++ b/Sum.thy @@ -1,69 +1,58 @@ -(* Title: HoTT/Sum.thy - Author: Josh Chen +(* +Title: Sum.thy +Author: Joshua Chen +Date: 2018 Dependent sum type *) theory Sum - imports HoTT_Base -begin +imports HoTT_Base +begin -section \Constants and syntax\ axiomatization - Sum :: "[t, Typefam] \ t" and - pair :: "[t, t] \ t" ("(1<_,/ _>)") and + Sum :: "[t, tf] \ t" and + pair :: "[t, t] \ t" ("(1<_,/ _>)") and indSum :: "[[t, t] \ t, t] \ t" ("(1ind\<^sub>\)") syntax - "_SUM" :: "[idt, t, t] \ t" ("(3\_:_./ _)" 20) - "_SUM_ASCII" :: "[idt, t, t] \ t" ("(3SUM _:_./ _)" 20) + "_sum" :: "[idt, t, t] \ t" ("(3\_:_./ _)" 20) + "_sum_ascii" :: "[idt, t, t] \ t" ("(3SUM _:_./ _)" 20) translations "\x:A. B" \ "CONST Sum A (\x. B)" "SUM x:A. B" \ "CONST Sum A (\x. B)" -text "Nondependent pair." - abbreviation Pair :: "[t, t] \ t" (infixr "\" 50) where "A \ B \ \_:A. B" +axiomatization where +\ \Type rules\ -section \Type rules\ + Sum_form: "\A: U i; B: A \ U i\ \ \x:A. B x: U i" and + + Sum_intro: "\B: A \ U i; a: A; b: B a\ \ : \x:A. B x" and -axiomatization where - Sum_form: "\A: U i; B: A \ U i\ \ \x:A. B x: U i" -and - Sum_intro: "\B: A \ U i; a: A; b: B a\ \ : \x:A. B x" -and Sum_elim: "\ p: \x:A. B x; - \x y. \x: A; y: B x\ \ f x y: C ; - C: \x:A. B x \ U i - \ \ ind\<^sub>\ f p: C p" (* What does writing \x y. f(x, y) change? *) -and + C: \x:A. B x \ U i; + \x y. \x: A; y: B x\ \ f x y: C \ \ ind\<^sub>\ (\x y. f x y) p: C p" and + Sum_comp: "\ a: A; b: B a; - \x y. \x: A; y: B(x)\ \ f x y: C ; B: A \ U i; - C: \x:A. B x \ U i - \ \ ind\<^sub>\ f \ f a b" - -text "Admissible inference rules for sum formation:" - -axiomatization where - Sum_wellform1: "(\x:A. B x: U i) \ A: U i" -and - Sum_wellform2: "(\x:A. B x: U i) \ B: A \ U i" + C: \x:A. B x \ U i; + \x y. \x: A; y: B(x)\ \ f x y: C \ \ ind\<^sub>\ (\x y. f x y) \ f a b" and +\ \Congruence rules\ -text "Rule attribute declarations:" + Sum_form_eq: "\A: U i; B: A \ U i; C: A \ U i; \x. x: A \ B x \ C x\ \ \x:A. B x \ \x:A. C x" -lemmas Sum_comp [comp] -lemmas Sum_wellform [wellform] = Sum_wellform1 Sum_wellform2 lemmas Sum_routine [intro] = Sum_form Sum_intro Sum_elim +lemmas Sum_comp [comp] end diff --git a/Unit.thy b/Unit.thy index 6760f27..61c6439 100644 --- a/Unit.thy +++ b/Unit.thy @@ -1,33 +1,31 @@ -(* Title: HoTT/Unit.thy - Author: Josh Chen +(* +Title: Unit.thy +Author: Joshua Chen +Date: 2018 Unit type *) theory Unit - imports HoTT_Base -begin +imports HoTT_Base +begin -section \Constants and type rules\ axiomatization - Unit :: Term ("\") and - pt :: Term ("\") and - indUnit :: "[Term, Term] \ Term" ("(1ind\<^sub>\)") + Unit :: t ("\") and + pt :: t ("\") and + indUnit :: "[t, t] \ t" ("(1ind\<^sub>\)") where - Unit_form: "\: U O" -and - Unit_intro: "\: \" -and - Unit_elim: "\C: \ \ U i; c: C \; a: \\ \ ind\<^sub>\ c a: C a" -and - Unit_comp: "\C: \ \ U i; c: C \\ \ ind\<^sub>\ c \ \ c" + Unit_form: "\: U O" and + Unit_intro: "\: \" and -text "Rule attribute declarations:" + Unit_elim: "\a: \; c: C \; C: \ \ U i\ \ ind\<^sub>\ c a: C a" and + + Unit_comp: "\c: C \; C: \ \ U i\ \ ind\<^sub>\ c \ \ c" -lemmas Unit_comp [comp] lemmas Unit_routine [intro] = Unit_form Unit_intro Unit_elim +lemmas Unit_comp [comp] end -- cgit v1.2.3 From 8e4ca285430c7bcdabbd4ea34da38e0770f4a832 Mon Sep 17 00:00:00 2001 From: Josh Chen Date: Mon, 17 Sep 2018 15:33:42 +0200 Subject: Tweak proof --- HoTT_Methods.thy | 4 ++-- Proj.thy | 13 +++++-------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/HoTT_Methods.thy b/HoTT_Methods.thy index 9849195..411176e 100644 --- a/HoTT_Methods.thy +++ b/HoTT_Methods.thy @@ -50,10 +50,10 @@ method derive uses lems = (routine add: lems | compute comp: lems)+ section \Induction\ -text " +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\. -" +\ end diff --git a/Proj.thy b/Proj.thy index f272224..e76e8d3 100644 --- a/Proj.thy +++ b/Proj.thy @@ -7,10 +7,7 @@ Projection functions \fst\ and \snd\ for the dependent *) theory Proj -imports - HoTT_Methods - Prod - Sum +imports HoTT_Methods Prod Sum begin @@ -28,12 +25,12 @@ unfolding fst_def by compute (derive lems: assms) lemma snd_type: assumes "A: U i" and "B: A \ U i" and "p: \x:A. B x" shows "snd p: B (fst p)" -unfolding snd_def proof - show "\p. p: \x:A. B x \ B (fst p): U i" by (derive lems: assms fst_type) - +unfolding snd_def proof (derive lems: assms) + show "\p. p: \x:A. B x \ fst p: A" using assms(1-2) by (rule fst_type) + fix x y assume asm: "x: A" "y: B x" show "y: B (fst )" by (derive lems: asm assms fst_comp) -qed fact +qed lemma snd_comp: assumes "A: U i" and "B: A \ U i" and "a: A" and "b: B a" shows "snd \ b" -- cgit v1.2.3 From 49c008ef405ab8d8229ae1d5b0737339ee46e576 Mon Sep 17 00:00:00 2001 From: Josh Chen Date: Mon, 17 Sep 2018 16:00:56 +0200 Subject: Clean up Equal.thy + some other tweaks --- Equal.thy | 59 ++++++++++++++++++++++------------------------------------- HoTT.thy | 7 +++++-- HoTT_Base.thy | 2 +- 3 files changed, 28 insertions(+), 40 deletions(-) diff --git a/Equal.thy b/Equal.thy index 7b6acb5..f9bc223 100644 --- a/Equal.thy +++ b/Equal.thy @@ -1,66 +1,51 @@ -(* Title: HoTT/Equal.thy - Author: Josh Chen +(* +Title: Equal.thy +Author: Joshua Chen +Date: 2018 Equality type *) theory Equal - imports HoTT_Base +imports HoTT_Base HoTT_Methods + begin -section \Constants and syntax\ +section \Basic definitions\ axiomatization - Equal :: "[t, t, t] \ t" and - refl :: "t \ t" and + Equal :: "[t, t, t] \ t" and + refl :: "t \ t" and indEqual :: "[t \ t, t] \ t" ("(1ind\<^sub>=)") syntax - "_EQUAL" :: "[t, t, t] \ t" ("(3_ =\<^sub>_/ _)" [101, 0, 101] 100) - "_EQUAL_ASCII" :: "[t, t, t] \ t" ("(3_ =[_]/ _)" [101, 0, 101] 100) + "_equal" :: "[t, t, t] \ t" ("(3_ =\<^sub>_/ _)" [101, 0, 101] 100) + "_equal_ascii" :: "[t, t, t] \ t" ("(3_ =[_]/ _)" [101, 0, 101] 100) + translations "a =[A] b" \ "CONST Equal A a b" "a =\<^sub>A b" \ "CONST Equal A a b" +axiomatization where + Equal_form: "\A: U i; a: A; b: A\ \ a =\<^sub>A b : U i" and -section \Type rules\ + Equal_intro: "a : A \ (refl a): a =\<^sub>A a" and -axiomatization where - Equal_form: "\A: U i; a: A; b: A\ \ a =\<^sub>A b : U i" -and - Equal_intro: "a : A \ (refl a): a =\<^sub>A a" -and Equal_elim: "\ + p: x =\<^sub>A y; x: A; y: A; - p: x =\<^sub>A y; - \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>= f p : C x y p" -and + \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 + Equal_comp: "\ a: 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>= f (refl a) \ f 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" -text "Admissible inference rules for equality type formation:" - -axiomatization where - Equal_wellform1: "a =\<^sub>A b: U i \ A: U i" -and - Equal_wellform2: "a =\<^sub>A b: U i \ a: A" -and - Equal_wellform3: "a =\<^sub>A b: U i \ b: A" - - -text "Rule attribute declarations:" - -lemmas Equal_comp [comp] -lemmas Equal_wellform [wellform] = Equal_wellform1 Equal_wellform2 Equal_wellform3 lemmas Equal_routine [intro] = Equal_form Equal_intro Equal_elim +lemmas Equal_comp [comp] end diff --git a/HoTT.thy b/HoTT.thy index 3f2d475..e2a7e35 100644 --- a/HoTT.thy +++ b/HoTT.thy @@ -6,7 +6,6 @@ Homotopy type theory theory HoTT imports - (* Basic theories *) HoTT_Base HoTT_Methods @@ -22,18 +21,22 @@ Unit (* Derived definitions and properties *) EqualProps -ProdProps Proj begin + lemmas forms = Nat_form Prod_form Sum_form Coprod_form Equal_form Unit_form Empty_form + lemmas intros = Nat_intro_0 Nat_intro_succ Prod_intro Sum_intro Equal_intro Coprod_intro_inl Coprod_intro_inr Unit_intro + lemmas elims = Nat_elim Prod_elim Sum_elim Equal_elim Coprod_elim Unit_elim Empty_elim + lemmas routines = Nat_routine Prod_routine Sum_routine Equal_routine Coprod_routine Unit_routine Empty_routine + end diff --git a/HoTT_Base.thy b/HoTT_Base.thy index efc6182..17e3142 100644 --- a/HoTT_Base.thy +++ b/HoTT_Base.thy @@ -77,7 +77,7 @@ Declare named theorems to be used by proof methods defined in @{file HoTT_Method These are used by the \compute\ method, and may also be passed to invocations of the method \subst\ to perform equational rewriting. \ -(* Todo: Set up the simplifier! *) +(* Todo: Set up the Simplifier! *) end -- cgit v1.2.3 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 From 6857e783fa5cb91f058be322a18fb9ea583f2aad Mon Sep 17 00:00:00 2001 From: Josh Chen Date: Tue, 18 Sep 2018 11:38:54 +0200 Subject: Overhaul of the theory presentations. New methods in HoTT_Methods.thy for handling universes. Commit for release 0.1.0! --- Coprod.thy | 1 + Empty.thy | 1 + Equal.thy | 1 + HoTT.thy | 9 +++-- HoTT_Base.thy | 29 ++++++++------- HoTT_Methods.thy | 25 ++++++++++++- Nat.thy | 1 + Prod.thy | 1 + Sum.thy | 1 + Unit.thy | 1 + ex/HoTT book/Ch1.thy | 47 +++++++++++------------ ex/Methods.thy | 73 ++++++++++++------------------------ ex/Synthesis.thy | 94 ++++++++++++++++++---------------------------- tests/Subgoal.thy | 63 ------------------------------- tests/Test.thy | 103 +++++++++++++++++++++++---------------------------- 15 files changed, 177 insertions(+), 273 deletions(-) delete mode 100644 tests/Subgoal.thy diff --git a/Coprod.thy b/Coprod.thy index d97228e..431e103 100644 --- a/Coprod.thy +++ b/Coprod.thy @@ -42,6 +42,7 @@ where \x. x: A \ c x: C (inl x); \y. y: B \ d y: C (inr y) \ \ ind\<^sub>+ (\x. c x) (\y. d y) (inr b) \ d b" +lemmas Coprod_form [form] lemmas Coprod_routine [intro] = Coprod_form Coprod_intro_inl Coprod_intro_inr Coprod_elim lemmas Coprod_comp [comp] = Coprod_comp_inl Coprod_comp_inr diff --git a/Empty.thy b/Empty.thy index 3060867..ee11045 100644 --- a/Empty.thy +++ b/Empty.thy @@ -20,6 +20,7 @@ where Empty_elim: "\a: \; C: \ \ U i\ \ ind\<^sub>\ a: C a" +lemmas Empty_form [form] lemmas Empty_routine [intro] = Empty_form Empty_elim diff --git a/Equal.thy b/Equal.thy index 7a31e37..19e3939 100644 --- a/Equal.thy +++ b/Equal.thy @@ -44,6 +44,7 @@ axiomatization where \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_form [form] lemmas Equal_routine [intro] = Equal_form Equal_intro Equal_elim lemmas Equal_comp [comp] diff --git a/HoTT.thy b/HoTT.thy index e2a7e35..0e7a674 100644 --- a/HoTT.thy +++ b/HoTT.thy @@ -1,5 +1,7 @@ -(* Title: HoTT/HoTT.thy - Author: Josh Chen +(* +Title: HoTT.thy +Author: Joshua Chen +Date: 2018 Homotopy type theory *) @@ -26,8 +28,7 @@ Proj begin -lemmas forms = - Nat_form Prod_form Sum_form Coprod_form Equal_form Unit_form Empty_form +text \Rule bundles:\ lemmas intros = Nat_intro_0 Nat_intro_succ Prod_intro Sum_intro Equal_intro Coprod_intro_inl Coprod_intro_inr Unit_intro diff --git a/HoTT_Base.thy b/HoTT_Base.thy index 7453883..2ad0ac5 100644 --- a/HoTT_Base.thy +++ b/HoTT_Base.thy @@ -7,7 +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 begin @@ -18,17 +18,14 @@ typedecl t \ \Type of object types and terms\ typedecl ord \ \Type of meta-level numerals\ axiomatization - O :: ord and + O :: ord and Suc :: "ord \ ord" and - lt :: "[ord, ord] \ prop" (infix "<" 999) + lt :: "[ord, ord] \ prop" (infix "<" 999) and + leq :: "[ord, ord] \ prop" (infix "\" 999) where lt_Suc [intro]: "n < (Suc n)" and lt_trans [intro]: "\m1 < m2; m2 < m3\ \ m1 < m3" and - Suc_monotone [simp]: "m < n \ (Suc m) < (Suc n)" - -method proveSuc = (rule lt_Suc | (rule lt_trans, (rule lt_Suc)+)+) - -text \Method @{method proveSuc} proves statements of the form \n < (Suc (... (Suc n) ...))\.\ + leq_min [intro]: "O \ n" section \Judgment\ @@ -42,15 +39,15 @@ axiomatization U :: "ord \ t" where U_hierarchy: "i < j \ U i: U j" and - U_cumulative: "\A: U i; i < j\ \ A: U j" + U_cumulative: "\A: U i; i < j\ \ A: U j" and + U_cumulative': "\A: U i; i \ j\ \ A: U j" text \ Using method @{method rule} with @{thm U_cumulative} is unsafe, if applied blindly it will typically lead to non-termination. One should instead use @{method elim}, or instantiate @{thm U_cumulative} suitably. -\ -method cumulativity = (elim U_cumulative, proveSuc) \ \Proves \A: U i \ A: U (Suc (... (Suc i) ...))\\ -method hierarchy = (rule U_hierarchy, proveSuc) \ \Proves \U i: U (Suc (... (Suc i) ...))\\ +@{thm U_cumulative'} is an alternative rule used by the method \lift\ in @{file HoTT_Methods.thy}. +\ section \Type families\ @@ -68,11 +65,15 @@ type_synonym tf = "t \ t" \ \Type of type families\< section \Named theorems\ named_theorems comp +named_theorems form text \ Declare named theorems to be used by proof methods defined in @{file HoTT_Methods.thy}. -@{attribute comp} declares computation rules. -These are used by the \compute\ method, and may also be passed to invocations of the method \subst\ to perform equational rewriting. + +@{attribute comp} declares computation rules, which are used by the \compute\ method, and may also be passed to invocations of the method \subst\ to perform equational rewriting. + +@{attribute form} declares type formation rules. +These are mainly used by the \cumulativity\ method, which lifts types into higher universes. \ (* Todo: Set up the Simplifier! *) diff --git a/HoTT_Methods.thy b/HoTT_Methods.thy index 8929f69..f0cee6c 100644 --- a/HoTT_Methods.thy +++ b/HoTT_Methods.thy @@ -12,6 +12,26 @@ imports HoTT_Base "HOL-Eisbach.Eisbach" "HOL-Eisbach.Eisbach_Tools" begin +section \Handling universes\ + +method provelt = (rule lt_Suc | (rule lt_trans, (rule lt_Suc)+)+) + +method hierarchy = (rule U_hierarchy, provelt) + +method cumulativity declares form = ( + ((elim U_cumulative' | (rule U_cumulative', rule form)), rule leq_min) | + ((elim U_cumulative | (rule U_cumulative, rule form)), provelt) +) + +text \ +Methods @{method provelt}, @{method hierarchy}, and @{method cumulativity} prove statements of the form +\<^item> \n < (Suc (... (Suc n) ...))\, +\<^item> \U i: U (Suc (... (Suc i) ...))\, and +\<^item> @{prop "A: U i \ A: U j"}, where @{prop "i \ j"} +respectively. +\ + + section \Deriving typing judgments\ method routine uses add = (assumption | rule add | rule)+ @@ -38,14 +58,15 @@ Method @{method compute} performs single-step simplifications, using any rules d 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. -Also handle universes using methods @{method hierarchy} and @{method cumulativity} defined in @{file HoTT_Base.thy}. +Also handle universes using @{method hierarchy} and @{method cumulativity}. \ -method derive uses lems = (routine add: lems | compute comp: lems | cumulativity | hierarchy)+ +method derive uses lems = (routine add: lems | compute comp: lems | cumulativity form: lems | hierarchy)+ section \Induction\ diff --git a/Nat.thy b/Nat.thy index 46b1af5..8a55852 100644 --- a/Nat.thy +++ b/Nat.thy @@ -41,6 +41,7 @@ where C: \ \ U i; \n c. \n: \; c: C n\ \ f n c: C (succ n) \ \ ind\<^sub>\ (\n c. f n c) a (succ n) \ f n (ind\<^sub>\ f a n)" +lemmas Nat_form [form] lemmas Nat_routine [intro] = Nat_form Nat_intro_0 Nat_intro_succ Nat_elim lemmas Nat_comps [comp] = Nat_comp_0 Nat_comp_succ diff --git a/Prod.thy b/Prod.thy index 4aa7119..f90ee9c 100644 --- a/Prod.thy +++ b/Prod.thy @@ -61,6 +61,7 @@ Note that this is a separate rule from function extensionality. Note that the bold lambda symbol \\<^bold>\\ used for dependent functions clashes with the proof term syntax (cf. \
2.5.2 of the Isabelle/Isar Implementation). \ +lemmas Prod_form [form] lemmas Prod_routine [intro] = Prod_form Prod_intro Prod_elim lemmas Prod_comps [comp] = Prod_comp Prod_uniq diff --git a/Sum.thy b/Sum.thy index 422e01b..463a9d4 100644 --- a/Sum.thy +++ b/Sum.thy @@ -51,6 +51,7 @@ axiomatization where Sum_form_eq: "\A: U i; B: A \ U i; C: A \ U i; \x. x: A \ B x \ C x\ \ \x:A. B x \ \x:A. C x" +lemmas Sum_form [form] lemmas Sum_routine [intro] = Sum_form Sum_intro Sum_elim lemmas Sum_comp [comp] diff --git a/Unit.thy b/Unit.thy index 61c6439..7c221f0 100644 --- a/Unit.thy +++ b/Unit.thy @@ -25,6 +25,7 @@ where Unit_comp: "\c: C \; C: \ \ U i\ \ ind\<^sub>\ c \ \ c" +lemmas Unit_form [form] lemmas Unit_routine [intro] = Unit_form Unit_intro Unit_elim lemmas Unit_comp [comp] diff --git a/ex/HoTT book/Ch1.thy b/ex/HoTT book/Ch1.thy index a577fca..263f43d 100644 --- a/ex/HoTT book/Ch1.thy +++ b/ex/HoTT book/Ch1.thy @@ -1,55 +1,50 @@ -(* Title: HoTT/ex/HoTT book/Ch1.thy - Author: Josh Chen +(* +Title: ex/HoTT book/Ch1.thy +Author: Josh Chen +Date: 2018 A formalization of some content of Chapter 1 of the Homotopy Type Theory book. *) theory Ch1 - imports "../../HoTT" +imports "../../HoTT" + begin chapter \HoTT Book, Chapter 1\ -section \1.6 Dependent pair types (\-types)\ +section \1.6 Dependent pair types (\-types)\ -text "Propositional uniqueness principle:" +paragraph \Propositional uniqueness principle.\ schematic_goal - assumes "(\x:A. B(x)): U(i)" and "p: \x:A. B(x)" - shows "?a: p =[\x:A. B(x)] " + assumes "A: U i" and "B: A \ U i" and "p: \x:A. B x" + shows "?a: p =[\x:A. B x] " -text "Proof by induction on \p: \x:A. B(x)\:" +text \Proof by induction on @{term "p: \x:A. B x"}:\ proof (rule Sum_elim[where ?p=p]) - text "We just need to prove the base case; the rest will be taken care of automatically." - - fix x y assume asm: "x: A" "y: B(x)" show - "refl(): =[\x:A. B(x)] , snd >" - proof (subst (0 1) comp) - text " - The computation rules for \fst\ and \snd\ require that \x\ and \y\ have appropriate types. - The automatic proof methods have trouble picking the appropriate types, so we state them explicitly, - " - show "x: A" and "y: B(x)" by (fact asm)+ - - text "...twice, once each for the substitutions of \fst\ and \snd\." - show "x: A" and "y: B(x)" by (fact asm)+ + text \We prove the base case.\ + fix x y assume asm: "x: A" "y: B x" show "refl : =[\x:A. B x] , snd >" + proof compute + show "x: A" and "y: B x" by (fact asm)+ \ \Hint the correct types.\ + text \And now @{method derive} takes care of the rest. +\ qed (derive lems: assms asm) - qed (derive lems: assms) section \Exercises\ -text "Exercise 1.13" +paragraph \Exercise 1.13\ -abbreviation "not" ("\'(_')") where "\(A) \ A \ \" +abbreviation "not" ("\_") where "\A \ A \ \" text "This proof requires the use of universe cumulativity." -proposition assumes "A: U(i)" shows "\<^bold>\f. f`(inr(\<^bold>\a. f`inl(a))): \(\(A + \(A)))" -by (derive lems: assms U_cumulative[where ?A=\ and ?i=O and ?j=i]) +proposition assumes "A: U i" shows "\<^bold>\f. f`(inr(\<^bold>\a. f`(inl a))): \(\(A + \A))" +by (derive lems: assms) end diff --git a/ex/Methods.thy b/ex/Methods.thy index c78af14..09975b0 100644 --- a/ex/Methods.thy +++ b/ex/Methods.thy @@ -1,76 +1,49 @@ -(* Title: HoTT/ex/Methods.thy - Author: Josh Chen +(* +Title: ex/Methods.thy +Author: Joshua Chen +Date: 2018 -HoTT method usage examples +Basic HoTT method usage examples. *) theory Methods - imports "../HoTT" -begin +imports "../HoTT" +begin -text "Wellformedness results, metatheorems written into the object theory using the wellformedness rules." lemma assumes "A : U(i)" "B: A \ U(i)" "\x. x : A \ C x: B x \ U(i)" - shows "\x:A. \y:B x. \z:C x y. \w:A. x =\<^sub>A w : U(i)" -by (routine lems: assms) - - -lemma - assumes "\x:A. \y: B x. \z: C x y. D x y z: U(i)" - shows - "A : U(i)" and - "B: A \ U(i)" and - "\x. x : A \ C x: B x \ U(i)" and - "\x y. \x : A; y : B x\ \ D x y: C x y \ U(i)" -proof - - show - "A : U(i)" and - "B: A \ U(i)" and - "\x. x : A \ C x: B x \ U(i)" and - "\x y. \x : A; y : B x\ \ D x y: C x y \ U(i)" - by (derive lems: assms) -qed - - -text "Typechecking and constructing inhabitants:" + shows "\x:A. \y:B x. \z:C x y. \w:A. x =\<^sub>A w: U(i)" +by (routine add: assms) -\ \Correctly determines the type of the pair\ +\ \Correctly determines the type of the pair.\ schematic_goal "\A: U(i); B: U(i); a : A; b : B\ \ : ?A" by routine \ \Finds pair (too easy).\ schematic_goal "\A: U(i); B: U(i); a : A; b : B\ \ ?x : A \ B" -apply (rule Sum_intro) +apply (rule intros) apply assumption+ done - -text " - Function application. - The proof methods are not yet automated as well as I would like; we still often have to explicitly specify types. -" - -lemma - assumes "A: U(i)" "a: A" - shows "(\<^bold>\x. )`a \ " +\ \Function application. We still often have to explicitly specify types.\ +lemma "\A: U i; a: A\ \ (\<^bold>\x. )`a \ " proof compute show "\x. x: A \ : A \ \" by routine -qed (routine lems: assms) - +qed -lemma - assumes "A: U(i)" "B: A \ U(i)" "a: A" "b: B(a)" - shows "(\<^bold>\x y. )`a`b \ " -proof compute - show "\x. x: A \ \<^bold>\y. : \y:B(x). \x:A. B(x)" by (routine lems: assms) +text \ +The proof below takes a little more work than one might expect; it would be nice to have a one-line method or proof. +\ - show "(\<^bold>\b. )`b \ " +lemma "\A: U i; B: A \ U i; a: A; b: B a\ \ (\<^bold>\x y. )`a`b \ " +proof (compute, routine) + show "\A: U i; B: A \ U i; a: A; b: B a\ \ (\<^bold>\y. )`b \ " proof compute - show "\b. b: B(a) \ : \x:A. B(x)" by (routine lems: assms) - qed fact -qed fact + show "\b. \A: U i; B: A \ U i; a: A; b: B a\ \ : \x:A. B x" by routine + qed +qed end diff --git a/ex/Synthesis.thy b/ex/Synthesis.thy index a5e77ec..3ee973c 100644 --- a/ex/Synthesis.thy +++ b/ex/Synthesis.thy @@ -1,78 +1,58 @@ -(* Title: HoTT/ex/Synthesis.thy - Author: Josh Chen +(* +Title: ex/Synthesis.thy +Author: Joshua Chen +Date: 2018 -Examples of synthesis. +Examples of synthesis *) theory Synthesis - imports "../HoTT" +imports "../HoTT" + begin section \Synthesis of the predecessor function\ -text " - In this example we construct, with the help of Isabelle, a predecessor function for the natural numbers. - - This is also done in \CTT.thy\; there the work is easier as the equality type is extensional, and also the methods are set up a little more nicely. -" +text \ +In this example we construct a predecessor function for the natural numbers. +This is also done in @{file "~~/src/CTT/ex/Synthesis.thy"}, there the work is much easier as the equality type is extensional. +\ -text "First we show that the property we want is well-defined." +text \First we show that the property we want is well-defined.\ -lemma pred_welltyped: "\pred:\\\ . ((pred`0) =\<^sub>\ 0) \ (\n:\. (pred`(succ n)) =\<^sub>\ n): U(O)" +lemma pred_welltyped: "\pred: \\\. (pred`0 =\<^sub>\ 0) \ (\n:\. pred`(succ n) =\<^sub>\ n): U O" by routine -text " - Now we look for an inhabitant of this type. - Observe that we're looking for a lambda term \pred\ satisfying \(pred`0) =\<^sub>\ 0\ and \\n:\. (pred`(succ n)) =\<^sub>\ n\. - What if we require **definitional** equality instead of just propositional equality? -" +text \ +Now we look for an inhabitant of this type. +Observe that we're looking for a lambda term @{term pred} satisfying @{term "pred`0 =\<^sub>\ 0"} and @{term "\n:\. pred`(succ n) =\<^sub>\ n"}. +What if we require *definitional* instead of just propositional equality? +\ schematic_goal "?p`0 \ 0" and "\n. n: \ \ (?p`(succ n)) \ n" apply compute prefer 4 apply compute -prefer 3 apply compute -apply (rule Nat_routine Nat_elim | compute | assumption)+ -done - -text " - The above proof finds a candidate, namely \\<^bold>\n. ind\<^sub>\ (\a b. a) 0 n\. - We prove this has the required type and properties. -" - -definition pred :: Term where "pred \ \<^bold>\n. ind\<^sub>\ (\a b. a) 0 n" - -lemma pred_type: "pred: \ \ \" unfolding pred_def by routine - -lemma pred_props: "\n. refl(n)>: ((pred`0) =\<^sub>\ 0) \ (\n:\. (pred`(succ n)) =\<^sub>\ n)" -proof (routine lems: pred_type) - have *: "pred`0 \ 0" unfolding pred_def - proof compute - show "\n. n: \ \ ind\<^sub>\ (\a b. a) 0 n: \" by routine - show "ind\<^sub>\ (\a b. a) 0 0 \ 0" - proof compute - show "\: U(O)" .. - qed routine - qed rule - then show "refl(0): (pred`0) =\<^sub>\ 0" by (subst *) routine - - show "\<^bold>\n. refl(n): \n:\. (pred`(succ(n))) =\<^sub>\ n" - unfolding pred_def proof - show "\n. n: \ \ refl(n): ((\<^bold>\n. ind\<^sub>\ (\a b. a) 0 n)`succ(n)) =\<^sub>\ n" - proof compute - show "\n. n: \ \ ind\<^sub>\ (\a b. a) 0 n: \" by routine - show "\n. n: \ \ refl(n): ind\<^sub>\ (\a b. a) 0 (succ n) =\<^sub>\ n" - proof compute - show "\: U(O)" .. - qed routine - qed rule - qed rule -qed - -theorem - "\n. refl(n)>>: \pred:\\\ . ((pred`0) =\<^sub>\ 0) \ (\n:\. (pred`(succ n)) =\<^sub>\ n)" -by (routine lems: pred_welltyped pred_type pred_props) +apply (rule Nat_routine | compute)+ +oops +\ \Something in the original proof broke when I revamped the theory. The completion of this derivation is left as an exercise to the reader.\ + +text \ +The above proof finds a candidate, namely @{term "\n. ind\<^sub>\ (\a b. a) 0 n"}. +We prove this has the required type and properties. +\ + +definition pred :: t where "pred \ \<^bold>\n. ind\<^sub>\ (\a b. a) 0 n" + +lemma pred_type: "pred: \ \ \" +unfolding pred_def by routine + +lemma pred_props: "\n. refl n>: (pred`0 =\<^sub>\ 0) \ (\n:\. pred`(succ n) =\<^sub>\ n)" +unfolding pred_def by derive + +theorem "\n. refl(n)>>: \pred:\\\ . ((pred`0) =\<^sub>\ 0) \ (\n:\. (pred`(succ n)) =\<^sub>\ n)" +by (derive lems: pred_type pred_props) end diff --git a/tests/Subgoal.thy b/tests/Subgoal.thy deleted file mode 100644 index 82d7e5d..0000000 --- a/tests/Subgoal.thy +++ /dev/null @@ -1,63 +0,0 @@ -theory Subgoal - imports "../HoTT" -begin - - -text " - Proof of \rpathcomp_type\ (see EqualProps.thy) in apply-style. - Subgoaling can be used to fix variables and apply the elimination rules. -" - -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 -apply standard - subgoal premises 1 for x \ \\subgoal\ is the proof script version of \fix-assume-show\.\ - apply standard - subgoal premises 2 for y - apply standard - subgoal premises 3 for p - apply (rule Equal_elim[where ?x=x and ?y=y and ?A=A]) - \ \specifying \?A=A\ is crucial here to prevent the next \subgoal\ from binding a schematic ?A which should be instantiated to \A\.\ - prefer 4 - apply standard - apply (rule Prod_intro) - subgoal premises 4 for u z q - apply (rule Equal_elim[where ?x=u and ?y=z]) - apply (routine lems: assms 4) - done - apply (routine lems: assms 1 2 3) - done - apply (routine lems: assms 1 2) - done - apply fact - done -apply fact -done - - -text " - \subgoal\ converts schematic variables to fixed free variables, making it unsuitable for use in \schematic_goal\ proofs. - This is the same thing as being unable to start a ``sub schematic-goal'' inside an ongoing proof. - - This is a problem for syntheses which need to use induction (elimination rules), as these often have to be applied to fixed variables, while keeping any schematic variables intact. -" - -schematic_goal rpathcomp_synthesis: - assumes "A: U(i)" - shows "?a: \x:A. \y:A. x =\<^sub>A y \ (\z:A. y =\<^sub>A z \ x =\<^sub>A z)" - -text " - Try (and fail) to synthesize the constant for path composition, following the proof of \rpathcomp_type\ below. -" - -apply (rule intros) - apply (rule intros) - apply (rule intros) - subgoal 123 for x y p - apply (rule Equal_elim[where ?x=x and ?y=y and ?A=A]) - oops - - -end diff --git a/tests/Test.thy b/tests/Test.thy index de65dbd..6f9f996 100644 --- a/tests/Test.thy +++ b/tests/Test.thy @@ -1,121 +1,110 @@ -(* Title: HoTT/tests/Test.thy - Author: Josh Chen - Date: Aug 2018 +(* +Title: tests/Test.thy +Author: Joshua Chen +Date: 2018 -This is an old "test suite" from early implementations of the theory. -It is not always guaranteed to be up to date, or reflect most recent versions of the theory. +This is an old test suite from early implementations. +It is not always guaranteed to be up to date or to reflect most recent versions of the theory. *) theory Test - imports "../HoTT" +imports "../HoTT" + begin -text " - A bunch of theorems and other statements for sanity-checking, as well as things that should be automatically simplified. - - Things that *should* be automated: - - Checking that \A\ is a well-formed type, when writing things like \x : A\ and \A : U\. - - Checking that the argument to a (dependent/non-dependent) function matches the type? Also the arguments to a pair? -" +text \ +A bunch of theorems and other statements for sanity-checking, as well as things that should be automatically simplified. + +Things that *should* be automated: +\<^item> Checking that @{term A} is a well-formed type, when writing things like @{prop "x: A"} and @{prop "A: U i"}. +\<^item> Checking that the argument to a (dependent/non-dependent) function matches the type? Also the arguments to a pair? +\ declare[[unify_trace_simp, unify_trace_types, simp_trace, simp_trace_depth_limit=5]] - \ \Turn on trace for unification and the simplifier, for debugging.\ +\ \Turn on trace for unification and the Simplifier, for debugging.\ section \\-type\ subsection \Typing functions\ -text " - Declaring \Prod_intro\ with the \intro\ attribute (in HoTT.thy) enables \standard\ to prove the following. -" +text \Declaring @{thm Prod_intro} with the @{attribute intro} attribute enables @{method rule} to prove the following.\ -proposition assumes "A : U(i)" shows "\<^bold>\x. x: A \ A" by (routine lems: assms) +proposition assumes "A : U(i)" shows "\<^bold>\x. x: A \ A" +by (routine add: assms) proposition assumes "A : U(i)" and "A \ B" shows "\<^bold>\x. x : B \ A" proof - have "A \ A \ B \ A" using assms by simp - moreover have "\<^bold>\x. x : A \ A" by (routine lems: assms) + moreover have "\<^bold>\x. x : A \ A" by (routine add: assms) ultimately show "\<^bold>\x. x : B \ A" by simp qed proposition assumes "A : U(i)" and "B : U(i)" shows "\<^bold>\x y. x : A \ B \ A" -by (routine lems: assms) - +by (routine add: assms) subsection \Function application\ -proposition assumes "a : A" shows "(\<^bold>\x. x)`a \ a" by (derive lems: assms) - -text "Currying:" +proposition assumes "a : A" shows "(\<^bold>\x. x)`a \ a" +by (derive lems: assms) lemma assumes "a : A" and "\x. x: A \ B(x): U(i)" shows "(\<^bold>\x y. y)`a \ \<^bold>\y. y" -proof compute - show "\x. x : A \ \<^bold>\y. y : B(x) \ B(x)" by (routine lems: assms) -qed fact +by (derive lems: assms) -lemma "\A: U(i); B: U(i); a : A; b : B\ \ (\<^bold>\x y. y)`a`b \ b" by derive +lemma "\A: U(i); B: U(i); a : A; b : B\ \ (\<^bold>\x y. y)`a`b \ b" +by derive -lemma "\A: U(i); a : A \ \ (\<^bold>\x y. f x y)`a \ \<^bold>\y. f a y" -proof compute - show "\x. \A: U(i); x: A\ \ \<^bold>\y. f x y: \y:B(x). C x y" - proof - oops +lemma "\A: U(i); a : A\ \ (\<^bold>\x y. f x y)`a \ \<^bold>\y. f a y" +proof derive +oops \ \Missing some premises.\ lemma "\a : A; b : B(a); c : C(a)(b)\ \ (\<^bold>\x. \<^bold>\y. \<^bold>\z. f x y z)`a`b`c \ f a b c" - oops +proof derive +oops subsection \Currying functions\ proposition curried_function_formation: - fixes A B C - assumes - "A : U(i)" and - "B: A \ U(i)" and - "\x. C(x): B(x) \ U(i)" + assumes "A : U(i)" and "B: A \ U(i)" and "\x. C(x): B(x) \ U(i)" shows "\x:A. \y:B(x). C x y : U(i)" - by (routine lems: assms) - +by (routine add: assms) proposition higher_order_currying_formation: assumes - "A: U(i)" and - "B: A \ U(i)" and + "A: U(i)" and "B: A \ U(i)" and "\x y. y: B(x) \ C(x)(y): U(i)" and "\x y z. z : C(x)(y) \ D(x)(y)(z): U(i)" shows "\x:A. \y:B(x). \z:C(x)(y). D(x)(y)(z): U(i)" - by (routine lems: assms) - +by (routine add: assms) lemma curried_type_judgment: - assumes "A: U(i)" "B: A \ U(i)" "\x y. \x : A; y : B(x)\ \ f x y : C x y" + assumes "A: U(i)" and "B: A \ U(i)" and "\x y. \x : A; y : B(x)\ \ f x y : C x y" shows "\<^bold>\x y. f x y : \x:A. \y:B(x). C x y" - by (routine lems: assms) +by (routine add: assms) -text " - Polymorphic identity function is now trivial due to lambda expression polymorphism. - (Was more involved in previous monomorphic incarnations.) -" +text \ +Polymorphic identity function is now trivial due to lambda expression polymorphism. +It was more involved in previous monomorphic incarnations. +\ -definition Id :: "Term" where "Id \ \<^bold>\x. x" - -lemma "\x: A\ \ Id`x \ x" -unfolding Id_def by (compute, routine) +lemma "x: A \ id`x \ x" +by derive section \Natural numbers\ -text "Automatic proof methods recognize natural numbers." +text \Automatic proof methods recognize natural numbers.\ + +proposition "succ(succ(succ 0)): \" by routine -proposition "succ(succ(succ 0)): Nat" by routine end -- cgit v1.2.3