theory HoTT imports Pure begin section \Setup\ text "For ML files, routines and setup." section \Basic definitions\ text "A single meta-level type \Term\ suffices to implement the object-level types and terms. We do not implement universes, but simply follow the informal notation in the HoTT book." typedecl Term subsection \Judgments\ consts is_a_type :: "Term \ prop" ("(_ : U)" [0] 1000) is_of_type :: "[Term, Term] \ prop" ("(3_ :/ _)" [0, 0] 1000) subsection \Type families\ text "Type families are implemented as meta-level lambda terms of type \Term \ Term\ that further satisfy the following property." abbreviation is_type_family :: "[(Term \ Term), Term] \ prop" ("(3_:/ _ \ U)") where "P: A \ U \ (\x::Term. x : A \ P(x) : U)" theorem constant_type_family: "\B : U; A : U\ \ \_. B: A \ U" proof - assume "B : U" then show "\_. B: A \ U" . qed subsection \Definitional equality\ text "We take the meta-equality \\\, defined by the Pure framework for any of its terms, and use it additionally for definitional/judgmental equality of types and terms in our theory. Note that the Pure framework already provides axioms and results for various properties of \\\, which we make use of and extend where necessary." theorem equal_types: assumes "A \ B" and "A : U" shows "B : U" using assms by simp theorem equal_type_element: assumes "A \ B" and "x : A" shows "x : B" using assms by simp lemmas type_equality [intro] = equal_types equal_types[rotated] equal_type_element equal_type_element[rotated] subsection \Basic types\ subsubsection \Dependent function/product\ consts Prod :: "[Term, (Term \ Term)] \ Term" lambda :: "[Term, (Term \ Term)] \ Term" syntax "_Prod" :: "[idt, Term, Term] \ Term" ("(3\_:_./ _)" 10) "__lambda" :: "[idt, Term, Term] \ Term" ("(3\<^bold>\_:_./ _)" 10) translations "\x:A. B" \ "CONST Prod A (\x. B)" "\<^bold>\x:A. b" \ "CONST lambda A (\x. b)" (* The above syntax translations bind the x in the expressions B, b. *) abbreviation Function :: "[Term, Term] \ Term" (infixr "\" 30) where "A\B \ \_:A. B" axiomatization appl :: "[Term, Term] \ Term" (infixl "`" 60) where Prod_form: "\(A::Term) (B::Term \ Term). \A : U; B : A \ U\ \ \x:A. B(x) : U" and Prod_intro [intro]: "\(A::Term) (B::Term \ Term) (b::Term \ Term). (\x::Term. x : A \ b(x) : B(x)) \ \<^bold>\x:A. b(x) : \x:A. B(x)" and Prod_elim [elim]: "\(A::Term) (B::Term \ Term) (f::Term) (a::Term). \f : \x:A. B(x); a : A\ \ f`a : B(a)" and Prod_comp [simp]: "\(A::Term) (B::Term \ Term) (b::Term \ Term) (a::Term). \\x::Term. x : A \ b(x) : B(x); a : A\ \ (\<^bold>\x:A. b(x))`a \ b(a)" and Prod_uniq [simp]: "\(A::Term) (B::Term \ Term) (f::Term). f : \x:A. B(x) \ \<^bold>\x:A. (f`x) \ f" text "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)." lemmas Prod_formation = Prod_form Prod_form[rotated] subsubsection \Dependent pair/sum\ consts Sum :: "[Term, Term \ Term] \ Term" syntax "_Sum" :: "[idt, Term, Term] \ Term" ("(3\_:_./ _)" 10) translations "\x:A. B" \ "CONST Sum A (\x. B)" abbreviation Pair :: "[Term, Term] \ Term" (infixr "\" 50) where "A\B \ \_:A. B" axiomatization pair :: "[Term, Term] \ Term" ("(1'(_,/ _'))") and indSum :: "[Term \ Term, Term \ Term, Term] \ Term" where Sum_form: "\(A::Term) (B::Term \ Term). \A : U; B: A \ U\ \ \x:A. B(x) : U" and Sum_intro [intro]: "\(A::Term) (B::Term \ Term) (a::Term) (b::Term). \A : U; B: A \ U; a : A; b : B(a)\ \ (a, b) : \x:A. B(x)" and Sum_elim [elim]: "\(A::Term) (B::Term \ Term) (C::Term \ Term) (f::Term \ Term) (p::Term). \A : U; B: A \ U; C: \x:A. B(x) \ U; \x y::Term. \x : A; y : B(x)\ \ f((x,y)) : C((x,y)); p : \x:A. B(x)\ \ (indSum C f p) : C(p)" and Sum_comp [simp]: "\(A::Term) (B::Term \ Term) (C::Term \ Term) (f::Term \ Term) (a::Term) (b::Term). \A : U; B: A \ U; C: \x:A. B(x) \ U; \x y::Term. \x : A; y : B(x)\ \ f((x,y)) : C((x,y)); a : A; b : B(a)\ \ (indSum C f (a,b)) \ f((a,b))" text "A choice had to be made for the elimination rule: we formalize the function \f\ taking \a : A\ and \b : B(x)\ and returning \C((a,b))\ as a meta level \f::Term \ Term\ instead of an object logic dependent function \f : \x:A. B(x)\. However we should be able to later show the equivalence of the formalizations." \ \Projection onto first component\ (* definition proj1 :: "Term \ Term \ Term" ("(proj1\_,_\)") where "\A B x y. proj1\A,B\ \ rec_Product(A, B, A, \<^bold>\x:A. \<^bold>\y:B. (\x. x))" *) subsubsection \Empty type\ axiomatization Null :: Term and ind_Null :: "Term \ Term \ Term" ("(ind'_Null'(_,/ _'))") where Null_form: "Null : U" and Null_elim: "\C x a. \x : Null \ C(x) : U; a : Null\ \ ind_Null(C(x), a) : C(a)" subsubsection \Natural numbers\ axiomatization Nat :: Term and zero :: Term ("0") and succ :: "Term \ Term" and (* how to enforce \succ : Nat\Nat\? *) ind_Nat :: "Term \ Term \ Term \ Term \ Term" where Nat_form: "Nat : U" and Nat_intro1: "0 : Nat" and Nat_intro2: "\n. n : Nat \ succ n : Nat" (* computation rules *) subsubsection \Equality type\ axiomatization Equal :: "Term \ Term \ Term \ Term" ("(_ =_ _)") and refl :: "Term \ Term" ("(refl'(_'))") where Equal_form: "\A a b. \a : A; b : A\ \ a =A b : U" and Equal_intro: "\A x. x : A \ refl x : x =A x" end