Safety and conservativity of definitions in HOL and Isabelle/HOL

Definitions are traditionally considered to be a safe mechanism for introducing concepts on top of a logic known to be consistent. In contrast to arbitrary axioms, definitions should in principle be treatable as a form of abbreviation, and thus compiled away from the theory without losing provability. In particular, definitions should form a conservative extension of the pure logic. These properties are crucial for modern interactive theorem provers, since they ensure the consistency of the logic, as well as a valid environment for total/certified functional programming. We prove these properties, namely, safety and conservativity, for Higher-Order Logic (HOL), a logic implemented in several mainstream theorem provers and relied upon by thousands of users. Some unique features of HOL, such as the requirement to give non-emptiness proofs when defining new types and the impossibility to unfold type definitions, make the proof of these properties, and also the very formulation of safety, nontrivial. Our study also factors in the essential variation of HOL definitions featured by Isabelle/HOL, a popular member of the HOL-based provers family. The current work improves on recent results which showed a weaker property, consistency of Isabelle/HOL's definitions.

In addition to supporting the development of formalized mathematics, most modern interactive theorems provers also include a functional programming language, supporting the paradigm of 24:2 Ondřej Kunčar and Andrei Popescu total programming [Turner 2004]. For example, in provers based on type theory such as Agda [Bove et al. 2009], Coq [Bertot and Casteran 2004] and Matita [Asperti et al. 2011], totality is ensured by a global strong normalization property. There is a tight relationship between this property, allowing functions/programs to be reduced to a normal form by recursively unfolding all definitions and reducing all redexes, and the logical consistency of these systems.
In HOL-based provers, programming is supported by a different mechanism: All recursive datatype specifications and all recursive specifications of functions on these datatypes are translated into nonrecursive HOL primitives, i.e., constant and type definitions; then the recursive specifications are proved automatically as theorems in the logic. This scheme involves a massive background compilation and proof process (supported by tools consisting of tens of thousands of lines of code, e.g., [Blanchette et al. 2014;Krauss 2009;Melham 1989]). It ensures a high degree of trustworthinessgiven that all constructions must pass through the "firewall" of HOL's minimalistic kernel. In particular, a potential bug in the compilation tools could cause correct user specifications to fail, but will not introduce logical inconsistencies unless the kernel has a bug.
In this paper, we turn our attention to the HOL kernel itself, which is the guarantor of logical consistency and certified programming in the above scheme. In spite of extensive foundational studies and the relative simplicity of the logic, the normalization process underlying the HOL kernel, i.e., the process of unfolding the HOL definitions, remains less understood than the corresponding "normalization" process in type theory, and occasionally leads to controversial design decisions and heated debates-as we are about to show, after recalling some background information.
While its ideas go back a long way (to the work of Alonzo Church [Church 1940] and beyond), HOL contains a unique blend of features proposed by Mike Gordon at the end of the eighties, inspired by practical verification needs: Its type system is the rank-one polymorphic extension of simple types, generated using the function-space constructor from two base types, bool and ind; its terms have built-in equality (from which all the usual connectives and quantifiers are derived); deduction, operating on terms of type bool called formulas, is regulated by the built-in axioms of Equality, (Hilbert) Choice and Infinity (for the type ind). In addition to this purely logical layer, which we shall refer to as initial HOL, users can perform constant and type declarations and definitions. Type definitions proceed by indicating a predicate on an existing type and carving out the new type from the subset satisfying the predicate. For accepting a type definition, the system requires a proof that the subset is nonempty (the predicate has a witness). This is because HOL types are required to be nonempty-a major design decision, with practical and theoretical ramifications [Gordon and Melham 1993;Paulson 1990]. No new axioms are accepted (more precisely, they are strongly discouraged), besides the aforementioned definitions. This minimalistic, definitional approach offers good protection against the accidental introduction of inconsistency (the possibility to prove False).
Isabelle/HOL is a notable member of the HOL family, and a maverick to some extent. It implements an essential variation of HOL, where constant definitions can be overloaded in an ad hoc manner, for different instances of their types. This flexibility forms the basis of Haskell-style type classes [Nipkow and Snelting 1991], 1 a feature that allows for lighter, suppler formalizations and should probably be credited, together with the high-level structured proof language [Wenzel 1999], the powerful automation [Paulson 2010] and the convenient user interface [Wenzel 2014], for Isabelle/HOL's wide popularity and prolificness: thousands of users in both academia and industry, a large library of formalized results [Isabelle 2016;Klein et al. 2016], major verification success stories [Esparza et al. 2013;Klein et al. 2010;Lochbihler 2010].
The founders of HOL have paid special attention to consistency and related properties. Andrew Pitts designed a custom notion of standard model [Pitts 1993], aimed at smoothly accommodating both polymorphism and type definitions. He proved that constant and type definitions are modeltheoretically conservative w.r.t. standard models: Any standard model of a theory can be expanded to a standard model of the theory plus the definitions. This of course implies consistency of HOL with definitions. Surprisingly, the HOL founders have not looked into the more customary notion of proof-theoretic conservativity, which we shall simply call conservativity. It states that, by adding new constants and types and their definitions, nothing new can be proved in the old language. This does not follow from the model-theoretic version (because of the restriction to standard models, for which deduction is not complete). In fact, as we discuss below, it does not even hold in general.
In Isabelle/HOL, the foundational problem is more challenging. Here, even the consistency of definitions has not been fully understood until very recently (Section 2.2). The culprit is precisely the feature that contributes to Isabelle/HOL's popularity-ad hoc overloading-which has a delicate interaction with type definitions [Kunčar and Popescu 2015, Section 1].
Motivated by the desire to settle the Isabelle foundations, in early work Wenzel formulates criteria for safety of definitions in HOL-like logics [Wenzel 1997]. For a theory extension Θ 1 ⊆ Θ 2 , he considers (proof-theoretic) conservativity, a property much stronger than preservation of consistency, to be a minimum requirement for deeming a theory extension truly definitional [Wenzel 1997, p.7]. In fact, he argues for an even stronger notion, meta-safety. Let Σ 1 and Σ 2 be the languages (signatures) of Θ 1 and Θ 2 , respectively. (Thus, Σ 1 ⊆ Σ 2 .) Meta-safety requires that, whenever a Σ 2 -formula φ is deducible from Θ 2 , there exists a Σ 1 -formula φ[. . . , t/c, . . .], obtained by replacing all the items c ∈ Σ 2 ∖ Σ 1 with some suitable Σ 1 -terms t, which is deducible from Θ 1 . This way, the items c can be considered to be "defined" because they can always be compiled away without losing provability. He also shows that, under appropriate well-formedness restrictions, a set of constant definitions forms a meta-safe extension.
However, as formulated, meta-safety does not apply to type definitions, because in HOL it is impossible to replace a defined type with its defining expression. In fact, Wenzel makes the following observation: In general, type definitions in HOL are not even consistency-preserving, let alone conservative (let alone meta-safe in any reasonable way), as witnessed by the following example. Consider the HOL theory consisting of a single formula φ stating that no type has precisely three elements (i.e, for all types α, if α has at most three elements x, y, z then two of them must be equal): The theory {φ} is consistent since there exists a model that satisfies it-the full-frame model of initial HOL, where all finite types are function-space combinations over bool, hence their cardinality is a power of two, in particular, no type has cardinality three. On the other hand, the extension of {φ} with the definition of a type having three elements, τ = {0, Suc 0, Suc(Suc 0)}, is clearly inconsistent-which exhibits a type definition that does not preserve consistency. This analysis has led Wenzel, who is Isabelle's long-standing lead developer and release manager, to deem type definitions axiomatic (i.e., having zero consistency or conservativity guarantees attached) rather than definitional. This departure from a well-established HOL tradition has generated confusion and misunderstanding amongst Isabelle/HOL's users and developers [Wolff 2015]. But the above counterexample involves a non-definitional theory-φ is not a definition, but merely an axiom that happens to be consistent. Thus, the counterexample only shows that, unlike constant definitions, type definitions do not preserve consistency, a fortiori, are not conservative, over an arbitrary (axiomatic) theory. Nonetheless, it is still legitimate to ask: Are arbitrary combinations of constant and type definitions conservative over initial HOL? And are they even meta-safe (again, over initial HOL) in a suitable sense? We believe these are important questions for deepening our understanding of the nature of HOL and Isabelle/HOL definitions. Conservativity also provides the most compelling way of witnessing consistency: Any proof of False using definitions can be traced down to a proof of False in initial HOL (the latter being manifestly consistent thanks to its standard set-theoretic semantics). This is especially relevant for the brittle foundational terrain of Isabelle/HOL, where it should help rehabilitating type definitions as genuine, safe definitions. In this paper, we provide a positive answer to both questions. Figure 1 shows in bold our new conservativity results in the context of similar known facts. For Isabelle/HOL constant definitions, ad hoc overloading immediately causes both (proof-theoretic) conservativity and model-theoretic conservativity over arbitrary base theories to fail. On the other hand, Wenzel [Wenzel 1997] argues by a proof sketch that any set of Isabelle/HOL constant definitions is conservative over any base theory provided the latter's signature does not contain these constants-in particular, this covers the case of initial HOL, which later Obua settles by a rigorous proof [Obua 2006]. Moreover, for (HOL and Isabelle/HOL) constant definitions over initial HOL, it is known that we can infer modeltheoretic conservativity from conservativity by replacing the defined constants with existentially quantified variables. However, this trick no longer works when we consider combinations of constant and type definitions-hence the empty slot in the figure's table, meaning we don't know whether model-theoretic conservativity holds in this case. (This is an open problem only for the case of Isabelle/HOL, since for standard HOL the fact even holds for arbitrary base theories, as shown by Pitts's well-known model-theoretic argument.) At the end of Section 5, we briefly come back to these aspects concerning model-theoretic conservativity, and suggest a possible positive answer to fill the figure's empty slot in the light of our techniques. Until then, we will focus entirely on conservativity in the proof-theoretic sense.
Here is an overview of the rest of this paper. First, we focus on traditional HOL, where we formulate meta-safety by defining translation operators for types and terms that unfold the definitions (Section 4). Unfolding a type definition has to be done in an indirect fashion, since HOL does not support comprehension/refinement types (of the form {x : σ | t x }). Namely, a formula operating on defined types will be relativized to a formula on the original, built-in types that hosted the type definitions; so the "unfolding" of a defined type will be a predicate on its host type. Since type definitions are paired with nonemptiness proofs (in the current contexts, having available all the previously introduced definitions), we are forced to proceed gradually, one definition at a time. Consequently, the proof of meta-safety (also leading to conservativity) is itself gradual, in a feedback loop between preservation of deduction, commutation with substitution, and nonemptiness of the relativization predicates.
We organized the proof development for traditional HOL modularly, separating lemmas about termination of the definitional dependency relation. This allows a smooth upgrade to the more complex case of Isabelle/HOL (Section 5), where termination is no longer ensured by the historic order of definitions, but via a more global approach. Due to ad hoc overloading, here the translations no longer commute with type substitution. We recover from this "anomaly" by mining the proofs and weakening the commutation lemma-leading to an Isabelle/HOL version of the results.
Our constructions have a logical-relation flavor [Reynolds 1983], but with some non-standard (and non-parametric) aspects due to the need to ensure non-emptiness of the representation predicates and, for Isabelle/HOL, to cope with ad hoc polymorphism.
The extended technical report [Kunčar and Popescu 2017b] has an appendix where we give more details on the HOL logic concepts and show some omitted proofs. We implemented for Isabelle/HOL the unfolding and relativization functions presented in this paper, and used them to check the paper's examples. The documented implementation is available from [Kunčar and Popescu 2017c].

MORE RELATED WORK
There is a vast literature on the logical foundations of theorem provers, which we will not attempt to survey here. We focus on work that is directly relevant to our present contribution, from the point of view of either the object logic or the techniques used.

HOL Foundations
Wiedijk [2009] defines stateless HOL, a version of HOL where terms and types carry in their syntax information about the defined constants and type constructors. Kumar et al. [2014] define a settheoretic (Pitts-style) model for stateless HOL and a translation from standard (stateful) HOL with definitions to stateless HOL, thus proving the consistency of both. Their stateful to stateless HOL translation is similar to our translation, in that they both internalize the definitions (which are part of "the state") into "stateless" formulas; however, for conservativity, we need to appeal to pure HOL entities, not to syntactically enriched ones. In a subsequent paper [Kumar et al. 2016], the same authors renounce the stateless HOL detour and prove model-theoretic conservativity directly on initial HOL.
Kumar et al. 's work, which has been mechanized in HOL4, is based on pioneering self-verification work by Harrison [Harrison 2006], who uses HOL Light to give semantic proofs of soundness of the HOL logic without definitional mechanisms, in two flavors: either after removing the infinity axiom from the object HOL logic, or after adding a "universe" axiom to the meta-logic.

Isabelle/HOL Foundations
Wenzel's work cited in the introduction [Wenzel 1997] sketched proofs of meta-safety and conservativity of constant definitions but left type definitions aside. In spite of Wenzel's theoretical observation that orthogonality and termination are required to ensure meta-safety, overloading of constants remained unchecked in Isabelle/HOL for many years-until Obua looked into the problem and proposed a way to implement Wenzel's observation with an external termination checker [Obua 2006]. Obua also aimed to extend the scope of consistency by factoring in type definitions. But his syntactic proof missed out possible inconsistencies through delayed overloading intertwined with type definitions. Soon after, Wenzel designed and implemented a more structural solution based on work of Haftmann, Obua and Urban (parts of which are reported in [Haftmann and Wenzel 2006]).
The foundational work on Isabelle/HOL was resumed by us in 2014, after the aforementioned inconsistencies caused by delayed overloading and type definitions were discovered. To address the problem, we defined a new dependency relation [Kunčar and Popescu 2015], operating on constants 24:6 Ondřej Kunčar and Andrei Popescu and types (which became part of the system starting from Isabelle2016). Employing a nonstandard semantics, we proved that, after these modifications, any definitional theory is consistent. In more recent work, we gave an alternative syntactic proof, based on translating HOL to a richer logic, HOLC, having comprehension types as first-class citizens [Kunčar and Popescu 2017a]. The current paper improves on these results, by proving properties much stronger than consistency.

Other Work
The general-purpose interactive theorem proving community is largely dominated by two successful camps: provers based on type theory (Agda, Coq, Matita, etc.) and provers based on HOL. 2 For the former, the notion of normalizing terms is fairly well studied and well understood [Abel et al. 2007;Altenkirch 1993;Barras 2010;Coquand et al. 1990;Coquand and Spiwack 2006;Geuvers 1993]. Our notion of meta-safety can be seen as the HOL counterpart of type-theoretic normalization, hence as a foundation for HOL-based programming. Of course, the technical challenges we face in HOL are quite different-here, it is not the expressiveness of the logic or of its underlying type system (e.g., fancy dependent types or polymorphism) that complicates the argument, but to a large extent its lack of expressiveness: The logic disallows unfolding type definitions, which forces us into a labyrinth of relativization techniques. Another difference is that HOL is an inherently classical logic: Type definitions require possibly non-constructive proofs of nonemptiness, and the Hilbert Choice is paramount. This makes our proof translations less clean than in type theory.
Other foundational work for theorem provers includes Myreen and Davis's mechanized proof of consistency for Milawa [Myreen and Davis 2014], a prover based on first-order logic in the style of ACL2, and Owre and Shankar's set-theoretic semantics of PVS [Owre and Shankar 1999]-featuring a logic similar to HOL, but with dependent types.
Outside the world of theorem proving, conservative extensions are widely employed in mathematical logic, e.g., in the very popular Henkin technique for proving completeness [Henkin 1949]. They are also employed in algebraic specifications to achieve desirable modularity properties [Sannella and Tarlecki 2012]. However, in these fields, definitional extensions are often trivially conservative, thanks to their simple equational structure and freshness conditions.

HOL PRELIMINARIES
By HOL, we mean classical higher-order logic with Infinity, Choice and rank-one polymorphism, and mechanisms for constant and type definitions and declarations. This section explains all these concepts and features in detail.

Syntax
All throughout this paper, we fix the following: • an infinite set TVar, of type variables, ranged by α, β • an infinite set VarN, of (term) variable names, ranged by x, y, z A type structure is a pair (K, arOf) where: • K is a set of symbols, ranged by k, called type constructors, containing three special symbols: "bool", "ind" and "⇒" (aimed at representing the type of booleans, an infinite type of individuals and the function type constructor, respectively) • arOf : K ⇒ N is a function associating arities to the type constructors, such that arOf(bool) = arOf(ind) = 0 and arOf(⇒) = 2.

24:7
The types associated to (K, arOf), ranged by σ , τ , are defined as follows: Thus, a type is either a type variable or an n-ary type constructor k postfix-applied to a number of types corresponding to its arity. We write Type (K,arOf) for the set of types associated to (K, arOf).
A signature is a tuple Σ = (K, arOf, Const, tpOf), where: • (K, arOf) is a type structure • Const, ranged over by c, is a set of symbols called constants, containing four special symbols: "=", "ε", "zero" and "suc" (aimed at representing equality, Hilbert choice of some element from a type, zero and successor, respectively) • tpOf : Const ⇒ Type is a function associating a type to every constant, such that: For the rest of this section, we fix a signature Σ = (K, arOf, Const, tpOf). We usually write Type Σ , or simply Type, instead of Type (K,arOf) .
TV(σ ) is the set of type variables of a type σ . A type substitution is a function ρ : TVar ⇒ Type. We let TSubst denote the set of type substitutions. The application of ρ to a type σ , written σ We say that σ is an instance of τ , written σ ≤ τ , if there exists ρ ∈ TSubst such that σ ≤ ρ τ . Two types σ 1 and σ 2 are called orthogonal, written σ 1 # σ 2 , if they have no common instance; i.e., for all τ , τ ̸ ≤ σ 1 or τ ̸ ≤ σ 2 .
Given ρ 1 , ρ 2 ∈ TSubst, we write ρ 1 · ρ 2 for their composition, defined as (ρ 1 · ρ 2 )(α) = (ρ 1 (α))[ρ 2 ]. It is easy to see that, for all types σ , it holds that σ A (typed) variable is a pair of a variable name x and a type σ , written x σ . We let Var denote the set of variables. A constant instance is a pair of a constant and a type, written c σ , such that σ ≤ tpOf(c). We let CInst denote the set of constant instances. We extend the notions of being an instance (≤) and being orthogonal (#) from types to constant instances: The signature's terms, ranged over by s, t, are defined by the grammar: Thus, a term is either a variable, or a constant instance, or an application, or an abstraction. As usual, we identify terms modulo alpha-equivalence. We let Term Σ , or simply Term, ranged by s and t, denote the set of terms. Typing is defined as a binary relation between terms and types, written t : σ , inductively as follows: We can apply a type substitution ρ to a term t, written t[ρ], by applying it to the types of all variables and constant instances occurring in t with the usual renaming of bound variables if they get captured. FV(t) is the set of t's free variables. The term t is called closed if it has no free variables: We write t[s/x σ ] for the term obtained from t by capture-free substituting the term s for all free occurrences of x σ .
A formula is a term of type bool. We let Fmla Σ , or simply Fmla, ranged by φ and χ , denote the set of formulas. The formula connectives (e.g., ∧ and −→) and quantifiers (∀ and ∃) are defined in the usual way, starting from the equality primitive. For example, for any type σ , we write ∀x σ . t for all σ (λx σ . t), where all σ is the term λp σ ⇒bool . p = (λx σ . true). The appendix of our technical report [Kunčar and Popescu 2017b] gives details. Given terms b : bool, t 1 : σ and t 2 : σ , their if-then-else expression, written ). Its behavior is the expected one: It equals t 1 if b is true and equals t 2 if b is false.
To avoid confusion with the object-logic definitions discussed later, we treat the logical connectives and quantifiers and the if-then-else operator as mere abbreviations (i.e., meta-level definitions of certain HOL terms). When writing terms, we sometimes omit the types of variables if they can be inferred-e.g, we write λx σ . x instead of λx σ . x σ . A theory (over Σ) is a set of closed (Σ-)formulas.

Axioms and Deduction
The HOL axioms, forming the set Ax, are the usual Equality axioms, the Infinity axioms (stating that suc is different from 0 and is injective, which makes the type ind infinite), the classical Excluded Middle and the Choice axiom, which states that the Hilbert choice operator returns an element satisfying its argument predicate (if nonempty): A context Γ is a finite set of formulas. We write α Γ to indicate that the type variable α does not appear in any formula in Γ; similarly, x σ Γ will indicate that x σ does not appear free in any formula in Γ. We define deduction as a ternary relation ⊢ between theories D, contexts Γ and formulas φ, written D; Γ ⊢ φ.
The axioms and the deduction rules we gave here are (a variant of) the standard ones for HOL (as in, e.g., [Gordon and Melham 1993;Harrison 2009]). Different provers implementing standard HOL, such as HOL4, HOL Light, HOL-ProofPower and HOL Zero, may use slightly different sets of logical primitives and slightly different rules and axioms; moreover, they of course differ in their implementation details. However, they all implement the same logic, up to logical equivalence. We write D ⊢ φ instead of D; ∅ ⊢ φ and ⊢ φ instead of ∅; ∅ ⊢ φ (that is, we omit empty contexts and theories). Note that the HOL axioms are not part of the parameter theory D, but are wired together with D in the (Fact) axiom. So ⊢ φ indicates that φ is provable from the HOL axioms only.

HOL Definitions and Declarations
Besides deduction, another main component of the HOL logic is a mechanism for introducing new constants and types by spelling out their definitions.
The built-in type constructors are bool, ind and ⇒. The built-in constants are =, ε, zero and suc. Since the built-in items have an already specified behavior (by the HOL axioms), only non-built-in items can be defined.

Definition 1.
Constant Definitions: Given a non-built-in constant c such that tpOf(c) = σ and a closed term t : σ , we let c σ ≡ t denote the formula c σ = t. We call c σ ≡ t a constant definition provided TV(t) ⊆ TV(c σ ) (i.e., TV(t) ⊆ TV(σ )).
Type Definitions: Given types τ and σ and a closed term t : σ ⇒ bool, we let τ ≡ t denote the formula where One_One rep is the formula stating that rep is one-to-one (injective), namely, ∀x τ , y τ . rep x = rep y −→ x = y. We call τ ≡ t a type definition, provided τ has the form (α 1 , . . . , α m ) k such that k is a non-built-in type constructor, the α i 's are all distinct type variables and A type definition expresses the following: The new type (α 1 , . . . , α m ) k is embedded in its host type σ via some one-to-one function rep, and the image of this embedding consists of the elements of σ for which t holds. Since types in HOL are required to be nonempty, the definition is only accepted if the user provides a proof that ∃x σ . t x holds. Thus, to perform a type definition, one must give a nonemptiness proof.
Type and Constant Declarations: Declarations in HOL are a logical extension mechanism which is significantly milder than definitions-they simply add new items to the signature as "uninterpreted, " without providing any definition.

Signature Extensions and the Initial Signature
In the remainder of this paper, when necessary for disambiguation, we will indicate the signature Σ as a subscript when denoting sets and relations associated to it: Given a signature Σ = (K, arOf, Const, tpOf) and an item u, we write u ∈ Σ to mean that u ∈ K or u ∈ Const. Given signatures Σ = (K, arOf, Const, tpOf) and Const ⊆ Const ′ and the functions arOf ′ and tpOf ′ are extensions of arOf and tpOf, respectively. We write u ∈ Σ ′ ∖ Σ to mean u ∈ Σ ′ and u Σ. If c Const and σ ∈ Type Σ , we write Σ ∪ {(c, σ )} for the extension of Σ with a new constant c of type σ . Similarly, if k K, we write Σ ∪ {(k, n)} for the extension of Σ with a new type constructor k of arity n.
We write Σ init for the initial signature, containing only built-in type constructors and constants. Note that, by definition, any signature extends the initial signature.

CONSERVATIVITY OF HOL DEFINITIONS
A HOL development, i.e., a session of interaction with the HOL logic from a user's perspective, consists of intertwining definitions, declarations and (statements and proofs of) theorems. Since theorems are merely consequences of definitions, we will not model them explicitly, but focus on definitions and declarations.
Let Σ = (K, arOf, Const, tpOf) be a signature and let D be a finite theory over Σ.
Definition 2. D is said to be a well-formed definitional theory if D = {def 1 , . . . , def n }, where each def i is a (type or constant) definition of the form u i ≡ t i , and there exist the signatures Σ 1 , . . . , Σ n and Σ 0 , Σ 1 , . . . , Σ n such that Σ 0 = Σ init , Σ n = Σ and the following hold for all i ∈ {1, . . . , n}: (1) t i ∈ Term Σ i and Σ i is the extension of Σ i with a fresh item defined by def i , namely:

24:10
Ondřej Kunčar and Andrei Popescu These conditions express that the theory D consists of intertwined definitions and declarations. The chain of extensions starting from the initial signature and ending with Σ, alternates sets of declarations (the items in As shown by condition (2), in the case of type definitions, we also require proofs of non-emptiness of the defining predicate t (from the definitions available so far).
In short, the above conditions state something very basic: Definitions are introduced one at a time and the defined symbols are fresh. This is clearly obeyed by correct implementations of standard HOL, such as HOL4 and HOL Light. (By contrast, the Isabelle/HOL-specific conditions in Section 5 will involve the more complex notions of orthogonality and termination.) Definition 3. A theory E over Σ is said to be a (proof-theoretic) conservative extension of initial HOL if any formula proved from E that belongs to the initial signature Σ init could have been proved without E or the types and constants from outside of Σ. Formally:

Roadmap
In what follows, we fix a well-formed definitional theory D and use for it the notations introduced in Def. 2, e.g., Σ, Σ i . We first sketch the main ideas of our development, motivating the choice of the concepts. The more formal definitions and proofs will be given in the following subsections.
Our two main goals are to formulate and prove D's meta-safety and to prove D's conservativity. As with any respectable notion of its kind, meta-safety will easily yield conservativity, so we concentrate our efforts on the former. 3 4.1.1 Unfolding the Definitions. Recall that, for a Σ-formula φ provable from D, meta-safety should allow us to replace all the defined items in φ with items in the initial signature without losing provability, i.e., obtaining a deducible Σ init -formula φ ′ . For constants, the procedure is clear: Any defined constant c appearing in φ is replaced with its defining term t, then any defined constant d appearing in t is replaced with its defining term, and so on, until (hopefully) the process terminates and we are left with built-in items only.
But how about for types τ occurring in φ? A HOL type definition τ ≡ t where t : σ ⇒ bool, is not an equality (there is no type equality in HOL), but a formula asserting the existence of a bijection between τ and the set of elements of σ for which the predicate t holds. So it cannot be "unfolded. " First, let us make the simplifying assumption that σ ∈ Type Σ init and t ∈ Term Σ init . Then the only reasonable Σ init -substitute for τ is its host type σ ; however, after the replacement of τ by σ , the formula needs to be adjusted not to refer to the whole σ , but only to the isomorphic copy of τ -in other words, the formula needs to be relativized to the predicate t. In general, σ or t may themselves contain defined types or constants, which will need to be processed similarly, and so on, recursively. In summary: • for each type τ , we define its host type HOST(τ ) ∈ Type Σ init and its relativization predicate on that type, REL(τ ) : HOST(τ ) ⇒ bool (where REL(τ ) ∈ Term Σ init ) • for each term t : τ , we define its unfolding UNF(t) : HOST(τ ) (where UNF(t) ∈ Term Σ init ) We will illustrate our design choices for the various cases in defining the above translation functions with the help of a running example.
Example 4. Let Σ be the extension of the initial signature with: • the nullary type constructors nat and zfun • the constants absnat : ind ⇒ nat and z : nat ind ⇒ bool is a predicate taking the intersection of all predicates that hold for 0 and are closed under Suc. Formally, t 1 is λi ind . (∀P ind⇒bool . P 0 ∧ (∀j ind . P j −→ P (Suc j))) −→ P i; but the precise form of t 1 will not be important in our discussion, beyond the fact that it is a term in the initial signature. • def 2 is absnat ≡ ε t 2 , where t 2 : (ind ⇒ nat) ⇒ bool is a predicate stating about its argument function that it is a bijection between the elements of ind that satisfy t 1 and nat. Formally, t 2 is λ f ind⇒nat . φ 1 ∧ φ 2 , where: -φ 1 states that f is one-to-one on the elements satisfying t 1 , namely ∀i ind j ind .
Thus, there are no (non-defined but) declared items, and the chain Σ init = Σ 0 ⊆ Σ 1 ⊆ Σ 1 ⊆ . . . ⊆ Σ 4 ⊆ Σ 4 = Σ consists of the following signatures, where we do not repeat the arities and the types: Incidentally, this example shows the standard procedure of bootstrapping natural numbers in HOL: The type nat is defined by carving out, from HOL's built-in infinite type ind, the smallest set closed under zero and successor. Using the Choice operator, we define the abstraction function absnat as a surjection whose restriction to nat's defining predicate t 1 is a bijection to nat. (The opposite injection can of course also be defined, but is omitted here.) The version of zero for naturals, z : nat, is defined by applying the abstraction to the built-in zero from ind. Subsequently, another type is introduced, zfun, of zero-preserving functions between naturals, defined by carving out from the type nat ⇒ nat the set of those functions that map z to z.
The simplest of the three translation functions will be HOST, which will track recursively, for each defined type, the built-in type that represents its defining ancestor. For example, following the type definitions def 1 and def 4 , we can compute the host of zfun: The UNF function will be more challenging to define. A clearly desirable feature is that UNF should leave built-in constants unchanged, e.g., UNF(=) should be =. Moreover, for instances c σ of constants c : τ defined by equations c τ ≡ t, UNF(c σ ) will naturally be recursively defined as UNF(t[ρ]) where ρ is the substitution that makes σ an instance of τ (i.e., σ ≤ ρ τ ). In other words, we unfold c σ with the appropriately substituted equation defining c. Since UNF is applied to arbitrary terms, not only to constants, we must indicate its recursive behavior for all term constructs. Abstraction and application are handled as expected, in that UNF distributes over them-with changing the type of the bound variables through the HOST function. For example, starting with t 4 which is λ f nat⇒nat . f nat⇒nat z = z, we have the following equalities, where UNF delves recursively into abstractions and applications, unfolds the definitions def 3 of z and def 2 of absnat, and leaves the built-in constants =, 0 and ε unchanged: Unlike applications and abstractions, variables raise a subtle issue, with global implications on our overall proof strategy. But before discussing them, we must look at how to define the relativization predicates. Clearly, REL should send a defined type such as nat to the unfolding of its defining predicate, here, UNF(t 1 ). (Note that in this case t 1 happens to contain only built-in items, meaning UNF(t 1 ) = t 1 .) Moreover, REL should "distribute" over ⇒ in that REL(σ 1 ⇒ σ 2 ) = REL(σ 1 ) ⇒ REL(σ 2 ) where, for p 1 : τ 1 ⇒ bool and p 2 : τ 2 ⇒ bool, p 1 ⇒ p 2 is the predicate on τ 1 ⇒ τ 2 stating about its argument function that it maps elements satisfying p 1 to elements satisfying p 2 -i.e., p 1 ⇒ p 2 is the lifting of p 1 and p 2 to the function space. For example: But what if a type is defined from a type that itself contains other defined types, as is the case of zfun defined from nat ⇒ nat (according to def 4 )? Then we must accumulate the defining predicates of all intermediate types, each lifted if necessary along the encountered function-space structure: Thus, REL(zfun) f ind⇒ind states that f preserves t 1 (the defining predicate of nat from ind) and that UNF(t 4 ) f holds, where t 4 is the defining predicate of zfun from nat ⇒ nat.
Back to the unfolding of variables, we are now ready to ask what should UNF(x σ ) be. An obvious candidate is x HOST(σ ) . However, this will not work, since a crucial property that we will need about our translation is that it observes membership to types, in that it maps terms of a given type to terms satisfying that type's representing predicate: (F1) The relativization predicates hold on translated items, i.e., REL(σ ) UNF(t) is deducible (in initial HOL) for each term t : σ .
(For our example, this would mean that there exists an element of ind ⇒ ind that preserves t 1 . ) Another way to regard this property is as a reflection of the HOL types being nonempty-a faithful relativization should of course follow suit.
With our chosen behavior of UNF on variables, the formula connectives and quantifiers will be treated as desired, i.e., yielding (modulo HOL deduction) standard relativization with respect to the REL predicates-for the universal and existential quantifiers, this means bounded quantification. For example, writing t 1 = HOL t 2 for ⊢ Σ init t 1 = t 2 , i.e., for the fact that the equality t 1 = t 2 is deducible in initial HOL, we have: The last = HOL step in the above chain follows from the non-emptiness of REL(σ ). Similarly, the unfolding of ∃x σ . φ x will be equal modulo HOL deduction to ∃x HOST(σ ) . REL(σ ) x ∧ UNF(φ) x.
We can take advantage of the above observation to obtain a palatable form for UNF(t 2 ): states about its argument f that, if it preserves t 1 , then it is in fact a bijection on the set of elements of ind that satisfy t 1 .
The above discussion suggests that the desired Σ init -formula φ ′ corresponding to a Σ-formula φ should be UNF(φ). Hence, for us meta-safety over initial HOL will mean: (MS) For all φ ∈ Fmla Σ , D ⊢ Σ φ implies ⊢ Σ init UNF(φ). This property is indeed a type-aware version of what Wenzel calls meta-safety: UNF(φ) replaces each defined constant with a term as in Wenzel's concept, and replaces each defined type with a tandem of a host type and a relativization predicate.
For our running example, we can prove D ⊢ Σ φ, where φ is ∀f nat⇒nat . ∃д nat⇒nat . ¬ f = д, which is a way of saying that nat ⇒ nat, if it is not empty (which is true for all HOL types) then it is not a singleton. By our meta-safety result, we will infer This is indeed a tautology (provable in initial HOL): It says that for any function that preserves the natural-number predicate (i.e., t 1 ) there exists a different function with the same property. This follows from the fact that there are two distinct elements of ind satisfying t 1 , e.g., 0 and Suc 0.
To help proving (MS), we will also have lemmas about the good behavior of the translation functions HOST, UNF and REL with respect to the main ingredients of HOL deduction: (F3) The translation functions preserve variable freshness and commute with substitution. The order in which we will have to prove these facts has superficially circular dependencies. As discussed, we need (F2) for proving (F1). Moreover, (F1) is needed to prove (F3), more precisely, to make sure that UNF commutes with substitution for the delicate case of variables x σ . In turn, (F3) is used for (MS). But to prove (F2), the nonemptiness of the relativization predicates, we seem to need (MS). Indeed, for the case of a type τ defined by τ ≡ t with t : σ ⇒ bool, REL(τ ) is the conjunction of REL(σ ) and UNF(t). So, in an inductive proof of (F2), we will need to deduce ∃x HOST(σ ) . REL(σ ) x ∧ UNF(t) x. The only fact that can help here is that this formula is (equivalent to) UNF(φ), where φ is ∃x σ . t x. Since φ is the non-emptiness claim for the new type τ , it is deducible (according to Def. 2 (2)). So we would like to apply (MS) here for obtaining that UNF(φ) is deducible.
Thus, we have the apparent dependency loop The way out of this loop is a gradual approach: We will not define a single version of the translation functions, but one version, HOST i , UNF i and REL i , for each subset {def 1 , . . . , def i } of D with i ≤ n. This way, we can use (MS) for i to prove (F2) for i + 1.

Dealing With
Declarations. Lastly, we must take into account a phenomenon we have ignored so far: the presence of declarations in addition to definitions. What should the unfolding UNF(c σ ) of the declared constant c : zfun be? A possibility is to acknowledge c as an irreducible entity, and define UNF(c zfun ) = c HOST(zfun) . However, this way our desirable property (F1), here, REL(zfun) c HOST(zfun) , will not be provable, since nothing prevents the "uninterpreted" items c HOST(zfun) from being outside of the relativization predicate. Another alternative is to define UNF(c zfun ) as an arbitrary element satisfying REL(zfun), via Choice, i.e., as ϵ REL(zfun). But this would mean that UNF will artificially identify several distinct constants, e.g., UNF(c σ ) = UNF(d σ ) for any two declared constants c σ and d σ -besides being unnatural, this situation would become difficult to handle later, for Isabelle/HOL, since it would introduce a breach in monotony: When declaring c σ and d σ , their unfoldings would be equal, but at a later stage one of them could get defined, breaking this equality.
Another subtlety concerning declared constants lies in the question: What should be the signature of UNF (c zfun )? Since c has no definition, it will not be compiled away by unfolding. However, its type zfun, which is a defined type, must be translated into its host ind ⇒ ind. But none of the existing signatures contains a constant c : ind ⇒ ind. Consequently, we must create a signature ∆ that extends Σ init with all the declared constants but having HOST-translated types, and, similarly, with all the declared type constructors. As for the declared (but not defined) types, these can be kept in the signature ∆ without causing any problems. Our translations, as well as the statement of (MS), will target this extended signature ∆ rather than Σ init .

Formal Definition of the Translations and Meta-Safety
We will write D i for the current definitional theory at moment i, {def 1 , . . . , def i }. Thus, we have D = D n . As discussed in the previous subsection, we will define deduction-preserving translations of the Σ-types and Σ-terms into ∆-types and ∆-terms, where ∆ will be a suitable signature that collects all the declared items-namely, for each Σ-type we define its host ∆-type and its relativization predicate (which is a ∆-term) and for each Σ-term we define its unfolding (which is a ∆-term). We proceed gradually, considering the Σ i 's one i at a time, eventually reaching Σ = Σ n .
For each i ∈ {1, . . . , n}, we define the signature ∆ i (collecting the declared items from Σ i with their types translated to their host types), together with the function HOST i : Type Σ i ⇒ Type ∆ i (producing the host types) as follows:

Fig. 2. Definition of the translation functions
all the type constructors k ∈ Σ i+1 ∖ Σ i for all constants c ∈ Σ i+1 ∖ Σ i of type σ , a constant c of type HOST i (σ ) • HOST i is defined as in Fig. 2, recursively on types On defined types (i.e., types having a defined type constructor on top), HOST i behaves as prescribed in Section 4.1, recursively calling itself for the defining type (clause (H3)). Upon encountering built-in or declared type constructors, i.e., belonging to some Σ i ′ for i ′ ≤ i, but not to the corresponding Σ i ′ −1 , HOST i delves into the subexpressions (clause (H2)).
Next, mutually recursively on Σ i -types and Σ i -terms, we define a function returning the relativization predicate of a type, REL i : Type Σ i → Term ∆ i , and one returning the unfolded term, UNF i : Term Σ i → Term ∆ i . Their definition is shown in Fig. 2 (where we again make use of the convention that we don't show the type labels of variables when they can be inferred). Again, they behave as prescribed in Section 4.1. In particular, REL i is naturally lifted to function spaces (clause (R2)) and accumulates defining predicates, as shown in clause (R4)-here, the substitution σ 1 /α 1 , . . . , σ m /α m stems from an instance of the defined type, (α 1 , . . . , α m ) k. Type variables and declared types are treated as black boxes, so REL i is vacuously true for them, just like for the built-in types bool and ind (clauses (R1) and (R3)). Note that, while (H2) refers to declared or built-in type constructors, (R3) only refers to declared ones-it explicitly excludes Σ init .
As discussed in Section 4.1, UNF i treats type variables and declared constants in a guarded fashion (clauses (U1) and (U3)), and distributes over application and abstraction (clauses (U5) and (U6)). Moreover, UNF i merely calls HOST i for built-in constants (clause (U2)). Finally, UNF i unfolds the definitions of defined constants, as shown in clause (U4). In that clause, c τ and ρ ↾ TV(c τ ) (the restriction of ρ to TV(c τ )) are uniquely determined by c σ ; and since TV(t) ⊆ TV(c σ ) (by Def. 1), it follows that t[ρ] is also uniquely determined by c σ .
Obviously, these functions can reach their purpose only if they are total functions. i.e., their recursive evaluation process terminates for all inputs. This is what we prove in the next subsection.
Assuming totality, we have all the prerequisites to formulate meta-safety. We let UNF be UNF n , the function that unfolds all definitions in D = D n , and ∆ be ∆ n , the signature collecting all the declared items in Σ.
Definition 6. D is said to be a meta-safe extension of HOL-with-declarations if, for all φ ∈ Fmla ∆ , it holds that D ⊢ Σ φ implies ⊢ ∆ UNF(φ).

Totality of the Translations
The goal of this subsection is to prove: Prop 7. The following hold: (1) The function HOST i is total, i.e., its recursive calls terminate.
(2) The functions REL i and UNF i are total, i.e., their mutually recursive calls terminate.
As discussed, these functions combine structural recursion with the unfolding of constant and type definitions. Roughly speaking, the reason why this recursion terminates is the following: The structural calls are clearly terminating, and the unfoldings are terminating thanks to the freshness condition imposed on the HOL definitional theories (Def. 2(1)), which means the new item on the left of the definition is reduced to existing items. But in order to make this rough intuition precise, we will also need to show that the structural calls and the unfoldings do not somehow interfere in a non-terminating manner.
Note that, if freshness is violated, the functions can become non-terminating. For example, a definition c σ ≡ c σ immediately makes UNF i non-terminating (due to clause (U4)), also leading to the non-termination of REL i (which depends on UNF i via clause (R4)); and similarly for type definitions. Of course, freshness is only a sufficient condition for termination. For example, defining c α list in terms of c α violates freshness, but locally exhibits a form of terminating recursion, since it descends on the constant's type. As we discuss in Section 5, Isabelle/HOL takes advantage of this observation to replace freshness by a weaker condition. We have designed the concepts we use in the following proof of termination, in particular, the definitional dependency relation, to also be relevant later, when we attend to Isabelle/HOL.
To prove (1), we must show that the call graph of HOST i , namely, the relation ▶ ▶ i defined by: is terminating. This is easily done by defining a lexicographic order based on the order in which the items were defined, i.e., the indexes of the definitions def i in which they appear. (Details are given in the appendix of our technical report [Kunčar and Popescu 2017b].) To prove (2), we will exhibit a terminating relation ▶ i that captures the mutual call graph of REL i and UNF i . We take ▶ i to be the union ≡ ↓ i ∪ ▷, where ≡ ↓ i and ▷ are defined below. The relation ▷ consists of the structurally recursive calls of REL i and UNF i , from clauses (R2), (U1), (U5) and (U6): Moreover, ≡ ↓ i captures the recursive calls corresponding to defined items, from (R4) and (U4). Given u, v ∈ Type Σ i ∪ Term Σ i , u ≡ ↓ i v states that there exists a definition u ′ ≡ v ′ in D i and a type substitution ρ such that u = ρ(u ′ ) and v = ρ(v ′ ).
Thus, the totality of REL i and UNF i is reduced to the termination of ▶ i . In order to prove the latter, we will introduce a more basic relation: the dependency relation between non-built-in items induced by definitions in D i . We let Type • Σ i be the set of Σ i -types that have a non-built-in type constructor at the top, and CInst • Σ i be the set of instances of non-built-in constants. Given any term t, we let types • (t) be the set of all types from Type • Σ i appearing in t and cinsts • (t) be the set of all constant instances from CInst • Σ i appearing in t. (The appendix of our technical report [Kunčar and Popescu 2017b] gives the formal definition of these operators.) We write ⇝ ↓ i for the (type-)substitutive closure of ⇝ i , defined as follows: Since HOL with definitions is well-known to be consistent, one would expect that definitions cannot introduce infinite (including cyclic) chains of dependencies. This can indeed be proved by a lexicographic argument, again taking advantage of the definitional order: Lemma 9. The relation ⇝ ↓ i is terminating.
The next observation connects ▶ i and ⇝ ↓ i , via ▷ * (the transitive closure of ▷): Now we can reduce the termination of ▶ i to that of ⇝ ↓ i , hence prove the former: Lemma 11. The relation ▶ i is terminating.
This concludes the proof of Prop. 7.

Basic Properties of the Translations
As envisioned in Section 4.1, the translations are extensions of each other and preserve type membership: Lemma 12. Assume i ≤ n − 1. The following hold: Lemma 13. If σ ∈ Type Σ i , t ∈ Type Σ i and t : σ , then REL i (σ ) : HOST i (σ ) ⇒ bool and UNF i (t) : For items in the initial signature, the behavior of the translations is either idle (for HOST i and UNF i ) or trivial (for REL i ): Lemma 14. The following hold: Other easy, but important properties state that the translations do not introduce new variables or type variables and commute with type substitution: Lemma 15. The following hold for all σ ∈ Type Σ i and t ∈ Term Σ i : (1) TV(HOST i (σ )) ⊆ TV(σ ) (2) TV(REL i (σ )) ⊆ TV(σ ) and FV(REL i (σ )) = ∅ x, as desired.
(2) i implies (3) i : Assume (2) i . Then (3) i follows by rule induction on the definition of typing. For the variable case, we use (2) i and the Choice axiom, which ensure us that (3) i implies (4) i : Assume (3) i . Then (4) i follows by well-founded induction on t w.r.t. ▶ i . The only interesting case is in the variable case (clause (U1)), when the variable coincides with the to-be substituted variable x σ . Thus, t = x τ . Here, we need to show ). This follows from the fact that, thanks to (3) (2) i and (4) i imply (5) i : Assume (2) i and (4) i . By induction on the definition of HOL deduction (⊢), we prove a slight generalization of (5) i , namely: We assume Γ ∪ {φ} ⊆ Fmla Σ i and D i ; Γ ⊢ Σ i φ, and prove ∅; UNF i (Γ) ⊢ ∆ i UNF i (φ). We distinguish different cases, according to the last applied And since UNF i (c σ ) and UNF i (t) are (syntactically) equal, the desired fact follows by the HOL reflexivity rule.
(B) u is a type τ of the form (α 1 , . . . , α m ) k and t : σ ⇒ bool. Then, by the definition of UNF i and of the ∀ and ∃ constructs, UNF i (φ) is equivalent (modulo HOL deduction) to the formula where the first conjunct comes from the relativization of τ ⇒ σ , the second from unfolding One_One rep , and the third from unfolding ∀y σ . t y ← → (∃x τ . y = rep x) (in Def. 1). This states the following (in a verbose fashion): There exists rep : HOST i (σ ) ⇒ HOST i (σ ) which is one-to-one on the intersection of REL i (σ ) and UNF i (t) and the image of this intersection through rep is the intersection itself. This is of course deducible in HOL, taking rep as the identity function. Now, assume φ ∈ Ax. Then φ ∈ Fmla Σ init , hence, by Lemma 14 (3), ⊢ ∆ i UNF i (φ) = φ. And since also ∅; UNF i (Γ) ⊢ ∆ i φ is true by (Fact), the desired fact follows using the HOL equality rules.
(5) i implies (1) i+1 : Assume (5) i and let σ , t be as in the formulation of (1) i+1 , namely, def i+1 = σ ≡ t. By the well-formedness of D (Def. 2), we have D i ⊢ Σ i ∃x σ . t x. Applying (5) i , we obtain ⊢ ∆ i UNF i (∃x σ . t x). By the definition of the ∃ quantifier and the definition of UNF i , the above is equiv- . By the definition of the if-then-else operator, we can replace t ′ by x. So the above is further equivalent to ⊢ ∆ i ∃x HOST i (σ ) . REL i (σ ) x ∧ UNF i (t) x. By Lemma 12 and the fact that Note that, in our sequence of translations, each translation unfolds not only the i'th definition, but all definitions up to the i'th. One might wonder if the proof could not go more smoothly if we unfolded only the i'th definition and worked with a base theory consisting of all previous definitions, on which we maintained an invariant. That would make a more elegant alternative, but we cannot find an invariant apart from "base theory is definitional, " which does not seem to help.
As a particular case of Lemma 17(5), we have: Theorem 18. D is a meta-safe extension of HOL-with-declarations.
Thus, we can compile away all the definitions of D, which leaves us with types and terms over the signature ∆ containing declarations only. With the definitions out of our way, it remains to show that declarations are conservative, which is much easier: Proof. Assume ⊢ ∆ φ. In the proof tree for this fact, we replace: (1) all occurrences of any declared constant instance c σ by a fresh variable x σ (2) all occurrences of any declared type constructor k of arity m by a built-in type expression of arity m, e.g., (σ 1 , . . . , σ m )k is replaced by σ 1 ⇒ . . . ⇒ σ m When performing the indicated replacements, all applications of the HOL rules remain valid; in particular, the application of (Fact) remains unchanged, since the underlying theory D is empty and no HOL axiom (in Ax) refers to declared-only constants or types. Hence these replacements yield a valid proof tree. Since φ, being in Fmla Σ init , is not affected by the replacements, this proof tree constitutes a proof of ⊢ Σ init φ. □ Finally, we can prove overall conservativity: Theorem 20. D is a conservative extension of initial HOL.

Abstract Constant Definition Mechanisms
As definitional schemes for constants, we have only looked into the traditional equational ones, implemented in most HOL provers. Two non-equational schemes have also been designed [Arthan 2014], and are available in HOL4, HOL Light and ProofPower-HOL: "new specification" and "gen new specification. " They allow for more abstract (under)specification of constants. However, these schemes have been shown not to increase expressiveness: "new specification" can be over-approximated by traditional definitions and the use of the Choice operator, and "gen new specification" is an admissible rule in HOL with "new specification" [Arthan 2014;Kumar et al. 2014]. Hence our results cater for them.

CONSERVATIVITY OF ISABELLE/HOL DEFINITIONS
As mentioned in the introduction, Isabelle/HOL allows more flexible constant definitions than HOL, in that it enables ad hoc overloaded definitions. For example, one can declare a polymorphic constant, such as ≤ : α ⇒ α bool, and at later times (perhaps after some other type and constant definitions and declarations have been performed) define different, non-overlapping instances of it: ≤ nat as the standard order on natural numbers, ≤ bool as implication, etc. Even recursive overloading is allowed, e.g., one can define ≤ α list as the component-wise extension of ≤ α to α list: xs ≤ α list ys ≡ length xs = length ys ∧ (∀i < length xs. xs i ≤ α ys i ) This means that now constant definitions no longer require the constant to be fresh. In fact, we are no longer speaking of constant definitions, but of constant instance definitions: The above examples do not define the overall constant ≤, but various instances of it, ≤ nat , ≤ bool and ≤ list .
Definition 21. Given a non-built-in constant c, a type σ ≤ tpOf(c) and a closed term t : σ , we let c σ ≡ t denote the formula c σ = t. We call c σ ≡ t a constant-instance definition provided TV(t) ⊆ TV(c σ ).
To compensate for the lack of freshness from constant-instance definitions, the Isabelle/HOL system performs some global syntactic checks, making sure that defined instances do not overlap (i.e., definitions are orthogonal) and that the dependency relation ⇝ n from Def. 8, terminates [Kunčar 2015;Kunčar andPopescu 2015, 2017a]. 4 (Recall that D = D n , hence ⇝ n is the dependency induced by D, i.e., by all the considered definitions.) Formally: Definition 22. An Isabelle/HOL-well-formed definitional theory is a set D of type and constantinstance definitions over Σ such that: • It satisfies all the conditions of Def. 2, except that it is not required that, in condition (1.2), c be fresh, i.e., it is not required that c Σ i • It is orthogonal: For all constants c, if c σ and c τ appear in two definitions in D, then σ # τ • Its induced dependency relation ⇝ n is terminating We wish to prove meta-safety and conservativity results similar to the ones for traditional HOL. To this end, we fix an Isabelle/HOL-well-formed definitional theory D and look into the results of Section 4 to see what can be reused-as it turns out, quite a lot.
First, the (type-translated) declaration signatures ∆ i and the translation functions HOST i , REL i and UNF i are defined in the same way. The orthogonality assumption in Def. 22 ensures that, in clause (U4) from the definition of UNF i , the choice of t is unique (whereas before, this was simply ensured by c appearing on the left in at most one definition). The notion of meta-safety is then defined in the same way. Thanks to ⇝ n being terminating, all the dependency relations ⇝ i , which are included in ⇝ n , are also terminating. Then all the results in Section 4.3 hold, leading to the totality of the translation functions. Furthermore, almost all the lemmas in Section 4.4 go through undisturbed, because they do not need the freshness assumption c Σ i .
The only losses are parts of Lemmas 12 (extension of the translations from i to i + 1) and 16 (commutation with type substitution), namely, points (2) and (3) of these lemmas-which deal with REL i and UNF i . We first look at Lemma 16.
Fortunately, we can amend this mismatch "after the fact" by replacing c HOST i (σ ′′ ) with UNF i (c σ ′′ ) in UNF i (σ )[HOST i (τ )/α] for all instances c σ ′′ (with σ ′′ ≤ σ ′ ) of all defined constant instances c σ ′ . In the above example, this means replacing c ind with UNF(c nat ), i.e., with UNF(z). To express this formally, we define a constant-instance substitution to be a function γ : is a closed term and TV(γ (c)) ⊆ TV(c)-thus assigning a term to any instance of a non-built-in, i.e., declared constant in ∆ i . Using a notation similar to variable substitution, we write σ [[γ ]] and t [[γ ]] for the effect of performing γ everywhere inside the type σ or the term t.
Lemma 24. There exists a constant-instance substitution γ such that: Now, the question is whether the partial consolation offered by Lemma 24, a quasi-commutativity property for REL i and UNF i , can replace full commutativity towards the central goal in Lemma 17, namely, point (5) (which ensures meta-safety). Answering this will require some proof mining.
The only usage of Lemma 16 was for (1) i implies (2) i (which is part of an implication chain leading to (4) i ; and both (2) i and (4) i are used for (5) i ). There, we used Lemma 16 m times to infer ⊢ ∆ i ∃x HOST i (σ ′ ) . REL i (σ ′ ) x ∧ UNF i (t ′ ) x from ⊢ ∆ i ∃x HOST i (σ ) . REL i (σ ) x ∧ UNF i (t) x. So we actually need a weaker statement: For Lemma 12, the situation is quite similar to that of Lemma 16. This time, it is not substitution that can enable additional unfoldings, but a newly added instance definition c σ ≡ t at layer i + 1 for a constant c that already existed at layer i. Moreover, when we look at how we employed Lemma 12 in the proof of our main chain of results in Lemma 17, we discover a similar pattern: We only use that UNF i+1 and REL i+1 extend UNF i and REL i in the proof of (5) i implies (1) i+1 , where we needed that deduction at layer i + 1 is implied by deduction at layer i. By a similar trick as before, this can be proved using a weaker quasi-commutativity property.
Lemma 25 and 26 reflect a concession made to Isabelle/HOL's ad hoc overloading: We can no longer exhibit a precise structural relationship between UNF i (φ) on the one hand and and UNF i (φ[σ /α]) or UNF i+1 (φ) on the other, but we can prove that the latter are "at least as deducible as the former." This would not have been possible had we not treated declared constants in a guarded fashion in the UNF i clause (U3) (see the discussion on page 14).
Thus, we were able to recover Lemma 17's point (5), leading to meta-safety. And since the other ingredients in the proof of Theorem 20 are also available (including Lemma 19, which is independent of the definitional mechanisms), we infer conservativity. We obtained: Theorem 27. Theorems 18 and 20 still hold if we assume that D is an Isabelle/HOL-well-formed definitional theory.

A Note on Model-Theoretic Conservativity
Let us revisit some of the aspects of model-theoretic conservativity listed in the introduction's Figure 1. The reason why, for Isabelle/HOL constant instance definitions, model-theoretic conservativity over arbitrary base theories fails is the following: Say we add a constant instance definition c σ ≡ t over a base theory Θ 1 with signature Σ 1 , such that Σ 1 contains the constant c : τ (with σ ≤ τ ) but the formulas in Θ 1 do not refer to c σ or to any instance of c that is non-orthogonal to c σ . Thus, Σ 2 = Σ 1 and Θ 2 = Θ 1 ∪ {c σ ≡ t }. Then we can easily build a standard model of Θ 1 where c σ ≡ t does not hold, implying that it cannot be extended to a model of Θ 2 -which contradicts model-theoretic conservativity. (And (proof-theoretic) conservativity fails for a similar reason: c σ ≡ t is provable from Θ 2 but not from Θ 1 .) We also mentioned in the introduction that, for constant definitions over initial HOL, modeltheoretic conservativity follows from conservativity. Here is how the argument goes: Say Θ is a conservative extension of initial HOL with a finite collection of constant (instance) definitions. Then Θ proves a formula φ that encodes these definitions as a conjunction of existentially quantified formulas, where the defined constants (or constant instances) become existentially quantified variables of corresponding types. By conservativity, initial HOL also proves φ. Then any standard model M (of initial HOL) satisfies φ, which implies that the desired constants and types can be defined in M, leading to an extension of M to a standard model of Θ-which proves model-theoretic conservativity.
When trying to apply a similar trick for the case of Θ extending initial HOL with constant and type definitions, we face the problem that in HOL we are not allowed to quantify existentially over type variables, to account for the defined types in Θ. Instead, we could appeal to the machinery developed in this paper to perform a more direct proof of model-theoretic conservativity. Namely, starting with a standard model (of initial HOL) M, we could build an extension to a standard model of Θ by well-founded recursion on the terminating relations underlying the definitions of HOST, REL and UNF. The necessary types in M would be introduced taking advantage of the fact that REL(σ ) : HOST(σ ) ⇒ bool and REL(σ ) is provably nonempty. Thus, for mixed constant-type definitions over initial HOL, model-theoretic conservativity would follow not from conservativity, but from the machinery we developed to prove conservativity. We leave a rigorous proof of this as future work-until then, we will not haste to declare the problem closed.
In very recent work, Gengelbach and Weber [2017] prove a form of model-theoretic conservativity for Isabelle/HOL over definitional base theories. However, they do not work with standard models, but employ the ground semantics we had developed for proving Isabelle/HOL's consistency [Kunčar and Popescu 2015]. The connection between ground-model conservativity and standard-model conservativity is yet to be understood.

CONCLUDING REMARKS
We have resolved an open problem, relevant for the foundation of HOL-based theorem provers, including our favorite one, Isabelle/HOL: We showed that the definitional mechanisms in such provers are meta-safe and conservative over pure HOL, i.e., are truly "definitional. " Our result has for HOL a foundational status analogous to strong normalization results for type theory.
Our translations compile away the constant and type definitions, the latter being significantly more problematic due to the lack of HOL infrastructure for unfolding them. In previous work [Kunčar and Popescu 2017a] we address this infrastructure problem by introducing HOLC, an extension of HOL with comprehension/refinement types. HOL type definitions can be naturally unfolded into HOLC types, yielding a HOL to HOLC translation that was sufficient for showing the consistency of Isabelle/HOL definitions. However, that translation would be too coarse for the