Structuring Theories with Implicit Morphisms

. We introduce implicit morphisms as a concept in formal systems based on theories and theory morphisms. The idea is that there may be at most one implicit morphism from a theory S to a theory T , and if S -expressions are used in T their semantics is obtained by automatically inserting the implicit morphism. The practical appeal of implicit morphisms is that they hit the sweet-spot of being extremely simple to understand and implement while signiﬁcantly helping with structuring large collections of theories. Concrete applications include elegantly identifying isomorphic theories and extending theories with deﬁnitions and theorems as well as eﬃciently building and maintaining large, ﬁne-granular, and heterogeneous hierarchies of theories. Our results are formulated and implemented in the Mmt language and system, and we expect they can be transfered to other morphism-based formalisms relatively easily.


Introduction
Motivation Theory morphisms have proved an essential tool for managing collections of theories in logics and related formal systems.They can be used to structure theories and build large theories modularly from small components or to relate different theories to each other [SW83,AHMS99,FGT92].Areas in which tools based on theories and theory morphisms have been developed include specification [GWM + 93,MML07], rewriting [CELM96], theorem proving [FGT93,KWP99], and knowledge representation [RK13].Closely related concepts are used in both object-oriented (classes) and functional (type classes) programming languages.
These systems usually use a logic L for the low-level formalization of domain knowledge, and a diagram D in the category of L-theories and L-morphisms for the high-level structure of large bodies of knowledge.
For example, a document might reference an existing theory Monoid, define a new theory Group that extends Monoid, define a theory DivGroup (providing an alternative formulation of groups based on the division operation), and then define two theory morphisms G2DG : Group ↔ DivGroup : DG2G that witness an isomorphism between these theories.This would result in the diagram below. 3

G2DG DG2G
The key idea behind implicit morphisms is very simple: We maintain an additional diagram I, which is a commutative subdiagram of D and whose morphisms we call implicit.The condition of commutativity guarantees that I has at most one morphism i from theory S to theory T , in which case we write S i → T .
Commutativity makes the following language extension well-defined: if S i → T , then any identifier c that is visible to S may also be used in T -expressions, with the semantics being that c abbreviates i(c).For example, in the diagram above, we may choose to label DG2G implicit.Immediately, every abbreviation or theorem that we have formulated in the theory DivGroup becomes available for use in Group without any syntactic overhead.We can even label G2DG implicit as well if we prove the isomorphism property to ensure that I remains commutative, thus capturing the mathematical intuition that Group and DivGroup are just different formalizations of the same concept.While these morphisms must be labeled manually, any inclusion morphism like the one from Monoid to Group can be made implicit automatically.
Contribution At the highest level, our contribution is the observation that implicit morphisms form a sweet spot of a very simple language feature that has substantial practical uses.We recommend using implicit morphisms in all theory morphism-based formalisms.More concretely, we present a formal system for developing structured theories with implicit morphisms based on the Mmt language [RK13].We choose Mmt because it provides a simple framework for working with theories and morphisms while remaining logic-independent: Mmt allows embedding a large variety of declarative languages L (logics, type-theories, etc.) so that our results immediately yield an implementation of implicit morphisms for any such L. We also expect but do not describe here that other morphism-based systems can be easily extended to allow for implicit morphisms.
We describe several example applications of implicit morphisms in detail: the identification of isomorphic theories, definitional extensions of theories, building large hierarchies of theories with many rarely used intermediate theories, seam-lessly moving theories across logic morphisms, and transparently refactoring theory hierarchies.
Previous Work Implicit morphism were first conceived by Rabe in 2010 and implemented as part of the Twelf system [PS99] (which implements the dependent type theory LF).The theory behind this implementation was never written up and not published.But the implementation already scaled well, and implicit morphisms were used in the LATIN logic atlas [CHK + 11] built by Rabe and others in 2009-2012.The LATIN atlas already has around a 1000 theories and atomic morphisms, and about 50 of the latter are marked as implicit.It also has a few hundred inclusions, each of which induces another implicit morphism.
Since then, MMT has been developed, and implicit morphisms were generalized from LF to the logic-independent level of MMT, their theory was worked out, they were reimplemented from scratch as a part of MMT.MMT is backwards-compatible with Twelf, and the LATIN atlas including its implicit morphisms can be used from within MMT.The present paper introduces these results in their final, most elegant form.
Overview In Sect.2, we present the syntax and semantics of Mmt.Even though the Mmt language is not new, our presentation is an entirely novel contribution in itself: it is much simpler and more elegant than the original one in [RK13].Crucially, this increase in simplicity allows spelling out the syntax and semantics of implicit morphisms, which we do in Sect.3, within a few pages.In Sect.4, we present applications.Finally we discuss related and future work in Sect. 5.

Overview
Flat Modules Flat theories are lists of constant declarations c : E[= e] where E and e are expressions, and the latter is optional.We write dom(T ) for the set of constant identifiers c in T .Every theory induces the set Obj(T ) for the set of closed expressions using only the symbols c ∈ dom(T ).Constant declarations subsume virtually all basic declarations common in formal systems such as type-/function/predicate symbols, axioms, theorems, inference rules, etc.In particular, theorems can be represented via the propositions-as-types correspondence as declarations c : F = P , which establish theorem F via proof P .Similarly, Mmt expressions subsume virtually all objects common in formal systems such as terms, types, formulas, proofs.
Flat morphisms from a theory S to a theory T are lists of assignments c := e where c ∈ dom(S) and e ∈ Obj(T ).Every morphism M induces a homomorphic extension M (−) : Obj(S) → Obj(T ), which replaces every c ∈ dom(S) in an S-expression with the T -expression e such that c := e in M .
A diagram consists of a set of theory and morphism declarations.For a given diagram, we write Thy for the set of declared theories.For theories S, T ∈ Thy, we write Mor(S, T ) for the set of morphisms defined by for every declaration m : S → T = {•}, we have m ∈ Mor(S, T ), for every T ∈ Thy, we have id T ∈ Mor(T, T ), for every M ∈ Mor(R, S) and N ∈ Mor(S, T ), we have M ; N ∈ Mor(R, T ) (where M ; N corresponds to the usual function composition).Thy and Mor(S, T ) form the category of theories and morphisms.
The theories and morphisms in a diagram may be structured (e.g., by using include declarations), and Mmt defines their semantics via flattening, which defines for each T ∈ Thy the flat theory T , and for each M ∈ Mor(S, T ) the flat morphism M from S to T .

Logics and Well-Formed Expressions
The logic and the definition of well-formed expressions are not a primary interest of this paper, and we only recap the essential structure needed in the sequel.We refer to [Rab17] for details.
Mmt is independent of the base logic and provides a theory and theory morphism layer on top of an arbitrary declarative language.Individual logics L arise as fragments of Mmt: they single out the well-formed expressions by defining the judgment T e = e : E for typing and equality.(We treat the plain typing judgment T e : E as the special case T e = e : E.) The logic L is itself represented as an Mmt theory, which we call the meta-theory of T .L provides, in particular, the primitive operators and typing rules that are used to form the well-formed expressions of T .L may and often has a meta-theory as well, usually a logical framework used to define the logic.Unless mentioned otherwise, all results in this paper apply for a fixed arbitrary meta-theory, which we will occasionally omit from the notation.
The declarations in theories and assignments in morphisms are subject to typing conditions, and the main theorem about Mmt is that under reasonable assumptions on L, the well-typed morphisms M : S → T preserve all judgments, i.e., if S e = e : E, then T M (e) = M (e ) : M (E).This includes the preservation of truth via the propositions-as-types principle if E is a proposition and e its proof.
We do not give all rules for these judgments.The only rule that is relevant to our purposes here is the one for constants: (Here, we merge the two cases where c has a/no definiens e into one rule for convenience.)Correspondingly, the definition of the homomorphic extension of a morphism with domain S includes the following case for constants: Here if c has a definiens in S, we expand it before applying M . 4hese base cases introduce a mutual recursion between well-formedness and flattening: the well-formedness of a declaration in a theory depends on the flattening of all preceding declarations; correspondingly, the well-formedness of an assignment in a morphism depends on the homomorphic extension of the morphism obtained by flattening of all preceding assignments.Vice versa, wellformedness is a precondition for defining the flattening -the definition of flattening may become nonsensical if applied to ill-formed modules.It might be desirable to define well-formedness independently of flattening.But our definition captures the typical behavior of practical systems, which first parse, check, and flatten one declaration entirely before moving on to the next one.
Therefore, we will make flattening a partial function, i.e., X is undefined if the module X is not well-formed.

Syntax
We start with the syntax for theories (which arises as a special case of the one given in [RK13]): Definition 1 (Theory).The grammar for theories and expressions is

. expressions built from constants
In a theory declaration T : L = { D}, the meta-theory L (if present) must be a previously declared theory, each symbol name n may be declared only once, and its type and definiens (if present) must be closed expressions over the previously introduced constants (including those of L).We omit the productions and typing rules for the remaining expressions, which include application, binding, variables, literals, etc.
Example 1.For the purposes of our running examples, we assume a fixed metatheory Log that provides a simple type system: type is the universe of types, A→B is the type of functions, and lambda abstraction is written [x:A] t x.We also use Mmt notations, which are attached to constant declarations as # <notation>; these are omitted from the formal grammar above because we only use them in the examples.
Then the (flat) theories Group and DivGroup from the introduction are: Example 2 (Morphisms).We give the morphism DG2G between the theories from Ex. 3:

assignments to axioms omitted
Here id Log maps the meta-theory to itself.Then universe and unit of a division group are mapped to the corresponding notions of a group.And we have DG2G(a/b) = a • b −1 .Additionally, the morphism maps every axiom of DivGroup to a proof in Group of the translated statement, but we omit those assignments.

Finally, we define diagrams as collections of modules:
Definition 3 (Diagram).A diagram is a list of theory and morphism declarations: Each theory/morphism declaration must have a unique name and be well-formed relative to the diagram preceding it.
At this point, the grammar only allows forming flat theories and morphisms.Structuring features can be added to the language incrementally and individually.
Example 3 (Includes).We extend the grammar with Dec ::= include T include a theory into a theory Ass ::= include M include a morphism into a morphism This allows writing the theory Group from Ex. 1 by extending a theory of monoids.Again omitting all axioms, this looks as follows:

Semantics
Flattening The definition of flattening is compositional in the sense that new modularity principles can be added independently of each other.
Definition 4 (Flattening).For the base case, of a theory t : L = {Σ}, we define t by induction on the declarations in Σ: Example 4 (Includes (continued from Ex. 3)).The include operator adds new declarations D to a theory, so we have to add cases to the definition of D .We do this as follows This has the effect of copying over all declarations from the included into the including theory.
There is some flexibility as to when the including and the included theory have different meta-theories L resp.L .We define that such an include is only allowed if L is also included into L.That way, an include declaration never changes the meta-theory of the including theory.
Note that, because S is a set of declarations, the include relation is transitive: if t includes s via two different paths, t only contains one copy of the declarations of s .
Because we use qualified identifiers t?n, includes can never lead to name clashes.The situation is slightly more complicated for morphisms: if a morphism σ out of t includes two different morphisms out of s, these have to agree.Therefore, flattening is not always defined: include M is well-formed and M agrees with σ on any constant that is in the domain of both.
Example 5 (Continuing Ex. 3).Group is obtained by copying all included symbols (from Monoid) over to Group, resulting in the theory as given in Ex. 1 except that the identifiers are now, e.g., Monoid?U instead of Group?U .
Remark 1 (Qualified Identifiers).According to the grammar, any occurrence of a constant c in an expression is of the form t?n, i.e., qualified by its theory name.
In the definition all declarations in t are qualified accordingly.This precludes any name clashes when constants of the same local name are declared in multiple theories that become part of t , e.g., via the meta-theory or includes.
The form t?n is abstract system-facing syntax.In concrete user-facing syntax (as used in our examples), it is usually sufficient to write n and let the Mmt parser infer which constant is meant.-It is very easy to maintain the implicit-diagram, e.g., as a partial map that assigns to a pair of theories the implicit morphism between them (if any).

Implicit Morphisms
-We can generalize the visibility of identifiers: If S i → T , we can use all Sidentifiers in T as if S were included into T .Any c ∈ dom(S) is treated as a valid T -identifiers with definiens M (c).
-We can use canonical identifiers S?n without worrying about ambiguity.
Because there can be at most one implicit morphism S i → T , using S?n as an identifier in T is unambiguous.
In practice, the Mmt system searches for an implicit morphism S i → T whenever needed to make an expression well-formed, e.g., -An S-constant c is used in T : treat c as an abbreviation for i(c).
-A model M of T is used even though a model of S is expected: reduce M via i. -A morphism M : R → S is composed with a morphism M : T → U : treat M ; M like M ; i; M .

Syntax
We introduce the family of sets Mor i (S, T ) as a subset of Mor(S, T ), holding the implicit morphisms.The intuition is that Thy and Mor i (S, T ) (up to equality of morphisms) form a thin broad subcategory of Thy and Mor(S, T ).It remains to define which morphisms are implicit.For that purpose, we allow Mmt declarations to carry attributes: The set of attributes is itself extensible, and the above grammar only lists the one that we use to get started.Additional attributes can be added when adding modularity principles.
Example 6.We can now change the declaration of the morphism DG2G from Ex. 2 by adding the attribute implicit.

Semantics
We only have to make two minor changes to the semantics to accommodate implicit morphisms.The first change governs how we obtain implicit morphisms, the second one how we use them.
Definition 6 (Obtaining Implicit Morphisms).We define the set Mor i (S, T ) ⊆ Mor(S, T ) of implicit morphisms to contain the following elements: all declared morphisms m : S → T = {σ} whose declaration carries the attribute implicit, if t has meta-theory L, the identity map as an implicit morphism L → t, all identity morphisms id T , all compositions M ; N of implicit morphisms M and N , all morphisms that additional language features designate as implicit based on the use of additional attributes.
Adding an implicit attribute to a declaration is well-formed only if there is (up to equality of morphisms) at most one implicit morphism for any pair of theories.
Example 7 (Includes (continued from Ex. 4)).For include morphisms, we add the following definition: if a theory T contains the declaration include S, then the induced morphism from S to T is implicit.
Combined with composition morphisms, we see that all transitive includes between theories are implicit.That corresponds to the intuition that anything that is included is available by its original (i.e.qualified) name.
Example 8.For our morphism DG2G from Ex. 6, this means that all symbols declared in the theory DivGroup (see Ex. 1) are now visible in the theory Group with the definitions provided by DG2G.For example, we can write a/b in Group, where / refers to the identifier DivGroup?div.
(Note that notations are carried over by implicit morphisms as well) The intuition behind implicit morphisms is that all S-constants c : E that can be mapped into the current theory via an implicit morphism M : S → T are directly available in T .We can practically realize this by adding new defined constants c : M (E) = M (c) to T .However, physically adding definitions can be inefficient.It is more elegant to modify the typing rules such that T c : M (c) = M (E) holds without any changes to T .
To do that, we only have to make a small modification to the original rules of Mmt as presented in Sect. 2. To illustrate how simple the modification is, the following definition repeat the original rule first for comparison: Definition 7 (Using Implicit Morphisms).We replace the rule Note that the modified rule gives every constant a definiens.This is a technical trick to subsume the original rule: if c is already declared in T , we use M = id T and obtain T c = c : E.
The following theorem is our central theoretical result.It shows that the modification made in Def.7 has the intended properties: Theorem 1 (Conservativity of Implicit Morphisms).For well-formed diagrams and S, T ∈ Thy and M ∈ Mor i (S, T ): 1. Whenever the original system proves T e = e : E, so does the modified one.2. Whenever the modified system proves T e = e : E, then the original system proves T e = e : E.Here E is the expression that arises from E by recursively replacing every constant with its definiens.
Proof.For the first claim, we proceed by induction on derivations.We only need to consider the case where the original rule was applied.So assume it yields For the second claim, we proceed by induction on derivations.We only need to consider the case where the modified rule was applied.So assume it yields With implicit morphisms, we can also relax the semantics of many structuring features: Example 9 (Includes and Meta-Theories (continued from Ex. 4)).Consider t : L = {. . ., include S, . ..}where S has meta-theory L .Instead of requiring L → L as in Ex. 4, we require only In that case, we treat include S as an abbreviation for include i(S), where i(S) is the pushout of S along i (see [Rab17] for details on Mmt pushouts).If L → L, this reduces to the original semantics.

Identifying Theories via Implicit Isomorphisms
A common need in developing large libraries (both in formal and informal developments) is to identify two theories S and T via a canonical choice of isomorphisms.In these cases, it is often desirable to use S-syntax and T -syntax interchangeably.But one of the major short-comings of formal theories over traditional informal developments is that formal systems usually need to spell out these isomorphisms everywhere.In this section, we show that implicit morphisms elegantly allow exactly that kind of intuitive identification: we mark the canonical isomorphisms as implicit.
In the sequel, we present several ways to obtain implicit isomorphisms conveniently.In general, note that because identity morphisms are implicit, our uniqueness requirement for implicit morphisms implies that two theories S and T must be isomorphic if there are implicit morphisms in both directions.Moreover, making a pair of isomorphisms implicit is only allowed if there are no other implicit morphisms between S and T yet.
Renamings We say that a named morphism r : S → T = {. ..} is a renaming if all assignments in its body are of the form c := c for T -constants c without definiens every T -constant c without definiens occurs in exactly one assignment.Clearly, every renaming is an isomorphism.The inverse morphisms contains the flipped assignments c := c.
We make the following extension to syntax and semantics: -A morphism declaration r : s → t = {. ..} may carry the attribute renaming.
-This is allowed if there are no implicit morphisms between s and t yet.
-In that case, we define r ∈ Mor i (s, t) and r −1 ∈ Mor(t, s).
Example 10 (Renaming).Consider a variation of the theory Monoid from Ex. 3 in a different library: This theory is isomorphic to the previously introduced theory Monoid under the trivial renaming Definitional Extensions We say that the named theory T is a definitional extension of S if T = S or the body of T contains only constant declarations with definiens, and include declarations of theories that are definitional extensions of S.
If T is a definitional extension of S, it is easy to prove that T and S are isomorphic: both isomorphisms map all constants without definiens to themselves.In particular, the isomorphism T → S maps S-constants to themselves and expands the definiens of all other constants.
We make the following extension to syntax and semantics: -An include declaration include S of a named theory S inside a theory T may carry the attribute definitional.-In that case, we define id S ∈ Mor i (T, S) (in addition to the implicit morphism id T ∈ Mor i (S, T ) that is induced by the inclusion).
Example 11 (Extension with a Theorem).We extend the theory Group from Ex. 3 with a theorem Inve rseInv olutio n : Log = definitional include Group inverse_invol : Remark 2 (Conservative Extensions).A definitional extension is a special case of a conservative extension.More generally, all retractable extensions are conservative, i.e., all extensions S → T such that there is a morphism r : T → S that is the identity on S. But we cannot make the retractions implicit morphisms in general because they are not necessarily isomorphisms.
Canonical Isomorphisms If we have isomorphisms m : S → T and n : T → S, we simply spell them out in morphism declarations and add the keyword implicit to both.This requires no language extensions.
Example 12. Having declared the morphism DG2G (as in Ex. 2) implicit, we do the same with the reverse morphism G2DG: While making one of these isomorphisms implicit is straightforward, doing it for both requires checking that m and n are actually isomorphisms.Otherwise, the uniqueness condition would be violated.Thus, we have to check m; n = id s and n; m = id t .In general, the equality of two morphisms f, g : for all (c : E) ∈ A .Thus, if equality of expressions is decidable in the logic that Mmt is instantiated with, then Mmt can check this directly.
However, this does not work in practice.Already elementary examples require stronger, undecidable equality relations: Example 13.Consider the isomorphism from Ex. 12.The result of mapping x • y from Group to DivGroup and back is x•(unit •y −1 ) −1 .Clearly, the group axioms imply that this is equal to x • y.But formally, that requires working with the undecidable equality of first-order logic.
Therefore, in our running example, we can only make one of the two isomorphisms implicit at this point.
In the sequel, we design a general solution to this problem.It allows systematically proving the equality of two morphisms and using that to make both isomorphisms implicit.This is novel work that requires significant prerequisites and is only peripherally related to implicit morphisms.Therefore, we only sketch the idea and leave the details to future work.
We add a language feature to Mmt to prove equalities between morphisms: We add the productions where the isomorphisms are as above and we omit all the equality proofs.
There is a subtle difficulty in marking G2DG as implicit: the implicit-diagram only commutes after proving the equalities, which are only declared later.One option is to delay the commutativity check until the equalities have been checked.In that case, care must be taken to avoid using the implicitness of G2DG while proving the equalities.But we obtain a more elegant solution from the observation that it is always sound and harmless to automatically make the inverse of an implicit isomorphism implicit as well.Thus, we can omit the attribute implicit on G2DG altogether and use an implementation that infers that G2DG is the inverse of an implicit isomorphism.

Fine-Granular and Flexible Theory Hierarchies
A common problem when defining modular theory hierarchies is that the most natural include-hierarchy for the most important theories is not necessarily the same as the most comprehensive hierarchy.For example, Ex. 3 defines Group with an include from Monoid.Instead, we could have used an intermediate theory and includes Monoid → CancellationMonoid → Group.
It is very common to have increasingly strong theories R, S, T , where a design with two includes R → S → T is not desirable: -Often R → T has been defined first and S only later.This is very common because people usually formalize the most important theories (e.g., Monoid and Group) first.But inserting S is not easy in retrospect -changing the theory hierarchy (which is one of the most fundamental structures of a library) usually presents a very expensive refactoring problem.And even if we systematically use includes for every known intermediate theory like S (as done in [CFO11]), we might later discover a new intermediate theory that should have been added.-Often the most natural axioms to use in T are the same independent of whether T includes R or S (e.g., users might prefer the usual inverse-element axioms in Group even if they have included CancellationMonoid).In that case, the axioms of S become provable in T if we use R → S → T .This either causes T to have redundant axioms or requires a more complex include mechanism that allows T to include S in a way that turns some of S-axioms into theorems.Therefore, it is common to use a commuting triangle consisting of two includes R → T and R → S and one morphism m : S → T .But this is awkward because the relation "every T is an S" is now mediated by m rather than being canonical.Implicit morphisms provide a simple solution to this problem: we keep the triangle but make the morphism m implicit.This captures exactly the canonical conversion from S to T .
Already the elementary algebraic hierarchy provides countless examples of such situations.For a small fragment of the hierarchy of magmas, Figure 1 shows one possible design using numerous implicit morphisms.In particular, it uses some of the examples and features from this paper, e.g., an implicit isomorphism to identify the order-theoretic and the algebraic development of semilattices.
It also uses multiple implicit morphisms to introduce the various intermediate theories between Band → SemiLattice.All of these are of the form t = {include Band, a : F }, e.g., LeftRegularBand uses F = ∀x, z.z•x•z .= z•x.The implicit morphisms map the constants from Band to themselves and the axiom a to a proof.It is straightforward to prove that this part of the diagram commutes: any two morphisms are identical except for the assignment to the axiom a, and these are equal due to proof irrelevance.5

Logic Morphisms
So far, we have assumed all theories use the same fixed meta-theory, e.g., Log in the running examples.But in practice, we usually develop theories heterogeneously by using the weakest possible meta-theory for each module.A strength of Mmt is that meta-theories are normal theories so that the same structuring formalism can be used for them, e.g., morphisms, includes, pushouts, and implicit morphisms are directly available for meta-theories.For example, consider the example from Figure 1.We could use first-order logic FOL as the common meta-theory of all theories.But actually the much weaker logic Horn (which uses restricted logical connectives that only allow creating Horn formulas) is sufficient for most of them.
We do not want to declare a direct include Horn → FOL for the same reasons as discussed in Section 4.2.Instead, we want to give a morphism EmbedHorn : Horn → FOL, which maps all Horn formula constructors to their FOL counterparts.We can now make EmbedHorn implicit, thus capturing the fact that Horn logic is a fragment of FOL.
Moreover, assume we have built the diagram in Figure 1 using the metatheory Horn where possible and FOL where necessary.An example for the latter is TotalOrder, which also uses ∨.Without implicit morphisms, we would have to write TotalOrder : FOL = {include EmbedHorn(PartialOrder), . ..}

Conclusion and Related Work
Implicit Conversions The need for implicit conversions has been recognized in many formal systems.In all cases, similar uniqueness constraints are employed as in ours.
Type-level conversions are functions between types such as the conversion from natural numbers to integers.Theory-level conversions are morphisms between theories, like in this paper, or similar constructs.The latter can be seen as a special case of the former: if every theory is seen as the type of its models (as in [MRK18]), then reduction along an implicit morphism S → T induces a conversion from T -models to S-models.Type-level conversions are present in many systems, e.g., the Coq proof assistant [Coq15] or the Scala programming language.The novelty in our approach is to restrict conversions two-fold: firstly to the theory level, secondly to those conversion functions that can be expressed as theory morphisms.This significantly reduces the complexity and permits an elegant logic-independent semantics, while still being practically useful.
Some formal systems support theory-level conversions without explicitly using theory morphisms.This is common in systems that use type classes as an analogue to theories.For example, the sublocale declarations of the proof assistant Isabelle [KWP99] or the deriving declarations of the programming language Haskell can be seen as implicit morphisms even though no primitive concept of morphism objects is employed.Our implicit morphisms yield a simpler and more expressive theory-level conversion system at the price of having an additional primitive concept.
Structuring Theories In systems that maintain large diagrams of theories, the problems solved by our approach have been recognized for some time.For example, the IMPS system [FGT93] allowed using theory morphisms to retroactively add defined constants to a previously declared theory.This corresponds to a definitional extension with an implicit retraction morphism as in Sect.4.1.
In [CFK14], the idea of realms was introduced as a way to bundle a set of isomorphic theories and their definitional extensions into a single interface.The paper called for an implementation of realms as a new primitive concept in addition to theories and morphisms.In contrast, the much simpler feature of implicit morphisms achieves very similar goals: realms can be recovered by marking all isomorphisms as implicit and all extensions as definitional.
It remains future to investigate the relationship between implicit morphisms and other generalizations of the set-theoretic notion of inclusion such as factorization or inclusion systems.
Scalability and Scoping Future work will focus on utilizing and evaluating implicit morphisms in large libraries, i.e., diagrams with thousands of theories and as many implicit morphisms as possible.
In doing so, we will pay particular attention to some problems that implicit conversions can cause at large scale.Users can be confused when implicit conversions are applied that they are not aware of, and different users may also have different preferences for which conversions should be implicit.Moreover, critically, different developments may be incompatible if they introduce different implicit morphisms between the same theories.For those reasons, Scala, for example, only applies implicit conversions that are imported into the current namespace.
We anticipate that these problems will lead to an evolution of our solution that allows more localized control over which morphisms are implicit.Thus, instead of a single global diagram of implicit morphisms, every context may carry its own local one.But we defer this until the current implementation has been used to conduct very large case studies.
axioms omitted We proceed accordingly for flat morphisms: Definition 2 (Morphism).The grammar for morphisms is M Dec ::= m : T → T = [M ] {Ass, . . ., Ass} flat morphism declaration Ass ::= c := E assignment to symbol M ::= m | id T | M ; M morphism expressions A morphism m : S → T = M { A} must contain exactly one assignment c := e for each (c : E) ∈ S , all of which must satisfy T e : m(E).Moreover, if S has a meta-theory L, then M must be present and must be a morphism from L to T .
t = Σ where • = L and (Σ, D) = Σ ∪ D , where • denotes the empty sequence.If L is not present, we can assume it to be the empty theory.Here D is the flattening of declaration D relative to Σ .At this point, we only have one case for declarations D, namely constant declarations.Their flattening is trivial: (n : E[= e]) = {t?n : E[= e]} where t is the name of the containing theory.Correspondingly, for a declared morphism m : S → T = [M ] {σ}, m is defined by induction on the assignments in σ: m = σ where • = M and (σ, A) = σ ∪ A with the trivial base case (c := e) = {c := e} If M is not present, we can assume it to be empty morphism.Moreover, for T ∈ Thy we define id T = {c := c | (c : E) ∈ T } And for M ; N ∈ Mor(R, T ), we define (M ; N ) = {c := N (M (c)) | (c : E) ∈ R }.Note that in both cases, we only have to consider constants without definiens.

3. 1
OverviewOur key idea is to use a commutative subdiagram of the Mmt diagram, which we call the implicit diagram.It contains all theories but only some of the morphisms -the ones designated as implicit.Because the implicit-diagram commutes, there can be at most one implicit morphism from S to T -if this morphism is i, we write S i → T .The implicit-diagram generalizes the inclusion relation: All identity and inclusion morphisms are implicit, and we recover the inclusion relation S → T as the special case S id S → T .And just like inclusion, the relation "exists i such that S i → T " is a preorder.Consequently, many of the advantages of inclusions carry over to implicit morphisms:

T
c[= e] : E, i.e., (c : E[= e]) in T .We apply the modified rule for the special case T id T → T .The conclusion reduces to if e is absent: T c = c : E, which is equivalent to T c : E, if e is present: T c = e : E because M (c) = M (e) according to the definition of M (−).

T
c = M (c) : M (E) for (c : E[= e]) in S and S M → T .We distinguish two cases: -M (c) = c, i.e., e is absent, and c = c.According to the definition of S , this is only possible if S → T (including the special case S = T ).In that case, S ⊆ T and M is the include/identity morphism that maps all S-constants to themselves.Now applying the induction hypothesis to the well-formedness derivation of E yields T c : E as needed.-M (c) = c, i.e., e is present or M assigns a non-trivial value to c. Definition expansion eliminates c in favor of M (c), and thus c = M (c).We only have to show that T M (c) : M (E).That follows from the judgment preservation of morphisms.
Dia ::= (T Dec | M Dec | M Eq) * M Eq ::= equal M = M : T → T by{Ass * } We define the declaration equal M = N : S → T by{σ} to be well-formed iff -M : S → T and N : S → T are well-formed morphisms σ contains exactly one assignment c := p for every (c : E) ∈ S for each of these assignments c := p, the term p is a proof of T M (c) = N (c).Example 14 (Isomorphisms).With the above extension in place, we can make both isomorphisms m and n from above implicit: implicit : DG2G : DivGroup → Group = (as above) implicit : G2DG : Group → DivGroup = (as above) equal G2DG; DG2G = id Group : Group → Group = (omitted) equal DG2D; G2DG = id DivGroup : DivGroup → DivGroup = (omitted)