Guarded Traced Categories

Notions of guardedness serve to delineate the admissibility of cycles, e.g. in recursion, corecursion, iteration, or tracing. We introduce an abstract notion of guardedness structure on a symmetric monoidal category, along with a corresponding notion of guarded traces, which are defined only if the cycles they induce are guarded. We relate structural guardedness, determined by propagating guardedness along the operations of the category, to geometric guardedness phrased in terms of a diagrammatic language. In our setup, the Cartesian case (recursion) and the co-Cartesian case (iteration) become completely dual, and we show that in these cases, guarded tracedness is equivalent to presence of a guarded Conway operator, in analogy to an observation on total traces by Hasegawa and Hyland. Moreover, we relate guarded traces to unguarded categorical uniform fixpoint operators in the style of Simpson and Plotkin. Finally, we show that partial traces based on Hilbert-Schmidt operators in the category of Hilbert spaces are an instance of guarded traces.


Introduction
In models of computation, various notions of guardedness serve to control cyclic behaviour by allowing only guarded cycles, with the aim to ensure properties such as solvability of recursive equations or productivity. Typical examples are guarded process algebra specifications [29,6], coalgebraic guarded (co-)recursion [34,27], finite delay in online Turing machines [9], and productive definitions in intensional type theory [1,30], but also contractive maps in (ultra-)metric spaces [24]. A highly general model for unrestricted cyclic computations, on the other hand, are traced monoidal categories [22]; besides recursion and iteration, they cover further kinds of cyclic behaviour, e.g. in Girard's Geometry of Interaction [14,4] and quantum programming [3,35]. In the present paper we parametrize the framework of traced symmetric monoidal categories with a notion of guardedness, arriving at (abstractly) guarded traced categories, which effectively vary between two extreme cases: symmetric monoidal categories (nothing is guarded) and traced symmetric monoidal categories (everything is guarded). In terms of the standard diagrammatic language for traced monoidal categories, we decorate input and output gates of boxes to indicate guardedness; the diagram governing trace formation would then have the general form depicted in Figure 1 -that is, we can only form traces connecting guarded (black) output gates to input gates that are unguarded (black), i.e. not assumed to be already guarded.
We provide basic structural results on our notion of abstract guardedness, and identify a wide array of examples. Specifically, we establish a geometric characterization of guardedness in terms of paths in diagrams; we identify a notion of guarded ideal, along with a construction of guardedness structures from guarded ideals and simplifications of this construction for the (co-)Cartesian and the Cartesian closed case; and we describe 'vacuous' guardedness structures where traces do not actually generate proper diagrammatic cycles. In terms of examples, we begin with the case where the monoidal structure is either product (Cartesian), corresponding to guarded recursion, or coproduct (co-Cartesian), for guarded iteration; the axioms for guardedness allow for a basic duality that indeed makes these two cases precisely dual. For total traces in Cartesian categories, Hasegawa and Hyland observed that trace operators are in one-to-one correspondence with Conway fixpoint operators [18,19]; we extend this correspondence to the guarded case, showing that guarded trace operators on a Cartesian category are in one-to-one correspondence with guarded Conway operators. In a more specific setting, we relate guarded traces in Cartesian categories to unguarded categorical uniform fixpoints as studied by Crole and Pitts [11] and by Simpson and Plotkin [38,39]. Concluding with a case where the monoidal structure is a proper tensor product, we show that the partial trace operation on (infinitedimentional) Hilbert spaces is an instance of vacuous guardedness; this result relates to work by Abramsky, Blute, and Panangaden on traces over nuclear ideals, in this case over Hilbert-Schmidt operators [2].
Related work Abstract guardedness serves to determine definedness of a guarded trace operation, and thus relates to work on partial traces. We discuss work on nuclear ideals [2] in Section 6. In partial traced categories [17,26], traces are governed by a partial equational version (consisting of both strong and directed equations) of the Joyal-Street-Verity axioms; morphisms for which trace is defined are called trace class. A key difference to the approach via guardedness is that being trace class applies only to morphisms with inputs and outputs of matching types while guardedness applies to arbitrary morphisms, allowing for compositional propagation. Also, the axiomatizations are incomparable: Unlike for trace class morphisms [17,Remark 2.2], we require guardedness to be closed under composition with arbitrary morphisms (thus covering contractivity but not, e.g., monotonicity as in the modal µ-calculus); on the other hand, as noted by Jeffrey [21], guarded traces, e.g. of contractions, need not satisfy Vanishing II as a Kleene equality as assumed in partial traced categories. Some approaches treat traces as partial over objects [8,20]. In concrete algebraic categories, partial traces can be seen as induced by total traces in an ambient category of relations [5]. We discuss work on guardedness via endofunctors in Remark 23.
Symmetric Monoidal Categories A symmetric monoidal category pC, b, Iq consists of a category C (with object class |C|), a bifunctor b (tensor product), and a (tensor) unit I P |C|, and coherent isomorphisms witnessing that b is, up to isomorphism, a commutative monoid structure with unit I. For the latter, we reserve the notation α A,B,C : , and υ A : I b A -A (left unitor ); the right unitorυ A : A b I -A is expressible via the symmetry. A symmetric monoidal category is Cartesian if the monoidal structure is finite product (i.e. b "ˆ, and I " 1 is a terminal object), and, dually, co-Cartesian if the monoidal structure is finite coproduct (i.e. b "`, and I " ∅ is an initial object). Coproduct injections are written in i : X i Ñ X 1`X2 (i " 1, 2), and product projections pr i : X 1ˆX2 Ñ X i . Various notions of algebraic tensor products also induce symmetric monoidal structures; see Section 6 for the case of Hilbert spaces. One has an obvious expression language for objects and morphisms in symmetric monoidal categories [37], the former obtained by postulating basic objects and closing under I and b, and the latter by postulating basic morphisms of given profile and closing under b, I, composition, identities, and the monoidal isomorphisms, subject to the evident notion of well-typedness. Morphism expressions are conveniently represented as diagrams consisting of boxes representing the basic morphisms, with input and output gates corresponding to the given profile. Tensoring is represented by putting boxes on top of each other, and composition by wires connecting outputs to inputs [37]. In a traced symmetric monoidal category one has an additional operation (trace) that essentially enables the formation of loops in diagrams, as in Figure 1 (but without decorations).
Monads and (Co-)algebras A(n F -)coalgebra for a functor F : C Ñ C is a pair pX, f : X Ñ F Xq where X P |C|, thought of as modelling states and generalized transitions [34]. A final coalgebra is a final object in the category of coalgebras (with C-morphisms h : X Ñ Y such that pF hqf " gh as morphisms pX, f q Ñ pY, gq), denoted pνF, out : νF Ñ F νF q if it exists. Dually, an F -algebra has the form pX, f : F X Ñ Xq. A monad T " pT, µ, ηq on a category C consists of an endofunctor T on C and natural transformations η : Id Ñ T (unit) and µ : T 2 Ñ T (multiplication) subject to standard equations [25]. As observed by Moggi [32], monads can be seen as capturing computational effects of programs, with T X read as a type of computations with side effects from T and results in X. In this view, the Kleisli category C T of T, which has the same objects as C and Hom C T pX, Y q " Hom C pX, T Y q, is a category of side-effecting programs. A monad is strong if it is equipped with a strength, i.e. a natural transformation XˆT Y Ñ T pXˆY q satisfying evident coherence conditions (e.g. [32]). A Talgebra pA, aq is an (Eilenberg-Moore) T-algebra (for the monad T) if additionally a η " id and apT aq " aµ A ; the category of T-algebras is denoted C T .

Guarded Categories
We now introduce our notion of guarded structure. A standard example of guardedness are guarded definitions in process algebra. E.g. in the definition P " a.P , the right hand occurrence of P is guarded, ensuring unique solvability (by a process that keeps outputting a). A further example is contractivity of maps between complete metric spaces. We formulate abstract closure properties for partial guardedness where only some of the inputs and outputs of a morphism are guarded. Specifically, we distinguish guarded outputs and guarded inputs (D and B, respectively, in the following definition), with the intended reading that guarded outputs yield guarded data provided guarded data is already provided at guarded inputs, while unguarded inputs may be fed arbitrarily.
Definition 1 (Guarded category). An (abstractly) guarded category is a symmetric monoidal category pC, b, Iq equipped with distinguished subsets Dq of partially guarded morphisms for A, B, C, D P |C|, satisfying the following conditions: We emphasize that Hom ‚ pA b B, C b Dq is meant to depend individually on A, B, C, D and not just on A b B and C b D.
One easily derives a weakening rule stating that if f P Hom ‚ ppA b A 1 q b B, C b pD 1 bDqq, then the obvious transpose of f is in Hom ‚ pAbpA 1 bBq, pC bD 1 qbDq.
We extend the standard diagram language for symmetric monoidal categories (Section 2), representing morphisms f P Hom ‚ pAbB, C bDq by decorated boxes as shown on the right, with black bars marking the unguarded input gates A and the guarded output gates D. Weakening then corresponds to shrinking the black bars of decorated boxes. Figure 2 depicts the above axioms in this language. Solid boxes represent the assumptions, while dashed boxes represent the conclusions. The latter only occur in the derivation process and do not form part of the actual diagrams representing concrete morphisms. We silently identify object expressions and sets of gates in diagrams. Given a (well-typed) morphism expression e, a judgement e P Hom ‚ pA b B, C b Dq, called a guardedness typing of e, is derivable if it can be derived from the assumed guardedness typing of the constituent basic boxes of e using the rules in Definition 1. We have an obvious notion of (directed) paths in diagrams; a path is guarded if it passes some basic box f through an unguarded input gate and a guarded output gate (intuitively, guardedness is then introduced along the path as the passage through f will guarantee guarded output without assuming guarded input). We then have the following geometric characterization of guardedness typing: Theorem 2. For a well-typed morphism expression e P HompA b B, C b Dq, the guardedness typing e P Hom ‚ pA b B, C b Dq is derivable iff in the diagram of e, every path from an input gate in A to an output gate in D is guarded.
Every symmetric monoidal category has both a largest (Hom ‚ pA b B, C b Dq " HompA b B, C b Dq) and a least guarded structure: Lemma and Definition 3 (Vacuous guardedness). Every symmetric monoidal category is guarded under taking f P Hom ‚ pAbB, C bDq iff f factors as This is the least guarded structure on C, the vacuous guarded structure. E.g. the natural guarded structure on Hilbert spaces (Section 6) is vacuous.
Remark 4 (Duality). The rules and axioms in Figure 2 are stable under 180 0 -rotation, that is, under reversing arrows and applying the monoidal symmetry on both sides (this motivates decorating the unguarded inputs). Consequently, if C is guarded, then so is the dual category C op , with guardedness given by f P Hom ‚ C op pAbB, C bDq iff the obvious transpose of f is in Hom ‚ C pDbC, BbAq.
In case b is coproduct, we can simplify the description of partial guardedness: Proposition 5. Partial guardedness in a co-Cartesian category pC,`, ∅q is equivalently determined by distinguished subsets Hom σ pX, Y q Ď HompX, Y q with σ ranging over coproduct injections Y 2 Ñ Y 1`Y2 -Y , subject to the rules on the right hand side of Figure 3, where f : We have used the mentioned rules for Ñ σ in previous work on guarded iteration [16] (with (vacˆ) called (trv), and together with weakening, which as indicated above turns out to be derivable). By duality (Remark 4), we immediately have a corresponding description for the Cartesian case: Corollary 6. Partial guardedness in a Cartesian category pC,ˆ, 1q is equivalently determined by distinguished subsets Hom σ pX, Y q Ď HompX, Y q with σ ranging over product projections X -X 1ˆX2 Ñ X 1 , subject to the rules on the left hand side of Figure 3, where f : Remark 7. In a co-Cartesian category, vacuous guardedness (Lemma 3) can equivalently be described by f P Hom ‚ pA`B, C`Dq iff f decomposes as f " rin 1 h, gs (uniquely provided that in 1 is monic), or in terms of the description from Proposition 5, u P Hom in2 pX, Y`Zq iff u factors through in 1 . Of course, the dual situation obtains in Cartesian categories.
Example 8 (Process algebra). Fix a monad T on pC,`, ∅q and an endofunctor Σ : C Ñ C such that the generalized coalgebraic resumption transform T Σ " νγ. T p--`Σγq exists; we think of T Σ X as a type of processes that have side-effects in T and perform communication actions from Σ, seen as a generalized signature. The Kleisli category C T Σ of T Σ is again co-Cartesian. Putting (cf. Section 2 for notation), we make C T Σ into a guarded category [16]. The standard motivating example of finitely nondeterministic processes is obtained by taking T " P ω (finite powerset monad) and Σ " Aˆ--(action prefixing).
Example 9 (Metric spaces). Let C be the Cartesian category of metric spaces and non-expansive maps. Taking f : XˆY Ñ pr 2 Z iff λy. f px, yq is contractive for every x P X makes C into a guarded Cartesian category.

Guardedness via Guarded Ideals
Most of the time, the structure of a guarded category is determined by morphisms with only unguarded inputs and guarded outputs, which form an ideal : Iq is a guarded ideal if it is closed under b and under composition with arbitrary C-morphisms on both sides, and GpI, Iq " HompI, Iq.
There is always a least guarded ideal, GpX, Y q " {g f | f : X Ñ I, g : I Ñ Y }. Moreover, as indicated above: Lemma and Definition 12. In a guarded category, the sets Hom pX, Y q form a guarded ideal, the guarded ideal induced by the guarded structure.
Conversely, it is clear that every guarded ideal generates a guarded structure by just closing under the rules of Definition 1.
Definition 13 (Ideally guarded category). A guarded category is ideal or ideally guarded (over G) if it is generated by some guarded ideal (G).
We give a more concrete description: Theorem 14. Let pC, b, Iq be ideally guarded over G. Then Hom ‚ pAbB, C bDq consists of the morphisms of the form The transitions between guarded ideals and guarded structures are not in general mutually inverse: The guarded structure generated the guarded ideal induced by a guarded structure may be smaller than the original one (Example 21), and the guarded ideal induced by the guarded structure generated by a guarded ideal G may be larger than G (Remark 16). We proceed to analyse details.
Proposition 15. On every symmetric monoidal category, the least guarded structure (Lemma 3) is ideal.
Remark 16. Vacuously guarded categories need not induce the least guarded ideal (although by the next results, this does hold in the Cartesian and the co-Cartesian case). In fact, by Lemma 3, the guarded ideal induced by the vacuous guarded structure consists of the morphisms of the form phbid D qpid A bgq (eliding associativity and the unitor) where g : This ideal will resurface in the discussion of Hilbert spaces (Section 6).
The situation is simpler in the Cartesian and, dually, in the co-Cartesian case.
Lemma 17. Let C be ideally guarded over G, and suppose that every Then the guardedness structure of C induces G.
If b "`, the premise of the lemma is automatic, since f P GpX`Y, Zq can be represented as rf in 1 , f in 2 s " rid, f in 2 s pf in 1`i dq where f in 1 P GpX, Zq by the closure properties of guarded ideals. Hence, we obtain Theorem 18. The guarded structure generated by a guarded ideal G on a co-Cartesian category is equivalently described by Hom in2 pX, Y`Zq " {rin 1 , gsh | g P GpW, Y`Zq, h : X Ñ Y`W }, and hence induces G.
Corollary 19. The guarded structure generated by a guarded ideal G on a Cartesian category is equivalently described by Hom pr 1 pXˆY, Zq " {h g, pr 2 | g P GpXˆY, W q, h : WˆY Ñ Z}, and hence induces G.
The description can be further simplified in the Cartesian closed case. Corollary 20. Given a guarded ideal G on a Cartesian closed category, put The guarded structure on metric spaces from Example 9 fails to be ideal: It induces the guarded ideal of contractive maps, which however generates the (ideal) guarded structure described by f : XˆY Ñ pr 2 Z iff f px, yq is uniformly contractive in y, i.e. there is c ă 1 such that for every x, λy. f px, yq is contractive with contraction factor c.
A large class of ideally guarded structures arises as follows. Proposition 22. Let C be a Cartesian category equipped with an endofunctor : C Ñ C and a natural transformation next : Id Ñ . Then the following definition yields a guarded ideal in C: Remark 23. Proposition 22 connects our approach to previous work based precisely on the assumptions of the proposition [28] (in fact, the term guarded traced category is already used there, with different meaning). A limitation of the approach via a functor arises from the need to fix globally, so that, e.g., the ideal guarded structure on metric spaces (Example 21) is not coveredcapturing contractivity via requires fixing a single global contraction factor.
The following instance of Proposition 22 has received extensive recent interest in programming semantics: Example 24 (Topos of Trees). Let C be the topos of trees [7], i.e. the presheaf category Set ω op where ω is the preorder of natural numbers (starting from 1) ordered by inclusion. An object X of C is thus a family pXpnqq n"1,2... of sets with restriction maps r n : Xpn`1q Ñ Xpnq. The later -endofunctor : C Ñ C is defined by Xp1q " {‹} and Xpn`1q " Xpnq, and the natural transformation next X : X Ñ X by next X p1q " ! : Xp1q Ñ {‹}, next X pn`1q " r n`1 : Xpn`1q Ñ Xpnq. Guarded morphisms according to Proposition 22 are called contractive, generalizing the metric setup. Contractive morphisms form an exponential ideal, so partial guardedness is described as in Corollary 20, and hence agrees with contractivity in part of the input as in [7, Definition 2.2].

Guarded Traces
As indicated previously, the main purpose of our notion of abstract guardedness is to enable fine-grained control over the formation of feedback loops, viz, traces.
Definition 25 (Guarded traced category). We call a guarded category pC, b, Iq guarded traced if it is equipped with a guarded trace operator visually corresponding to the diagram formation rule in Figure 1, so that the adaptation of the Joyal-Street-Verity axiomatization of traced symmetric monoidal categories [22] shown in Figure 4 is satisfied. We proceed to investigate the geometric properties of guarded traced categories, partly extending Theorem 2. The syntactic setting extends the one for guarded categories by additionally closing morphism expressions under the trace operator (interpreted diagrammatically as in Figure 1), obtaining traced morphism expressions. Term formation thus becomes mutually recursive with guardedness typing: if e is a traced morphism expression such that e P Hom ‚ ppA b U q b B, C b pD b U qq is derivable, then tr A,B,C,D peq is a traced morphism expression, and tr A,B,C,D peq P Hom ‚ pAbB, C bDq is derivable. Traced diagrams consists of finitely many (decorated) basic boxes and wires connecting output gates of basic boxes to input gates, with each gate attached to at most one wire; open gates are regarded as inputs or outputs, respectively, of the whole diagram. Of course, acyclicity is not required. We first note that the easy direction of Theorem 2 adapts straightforwardly to the setting with traces: Proposition 27. Let e be a traced morphism expression such that e P Hom ‚ pA b B, C b Dq is derivable. Then in the diagram of e, all loops and all paths from input gates in A to output gates in D are guarded (p. 4).
Remarkably, the converse of Proposition 27 in general fails in several ways: shows that guardedness typing is not closed under equality of traced morphism expressions: Write e for the expression inducing the dashed box. By Proposition 27, e, and hence trpeq, fail to type as indicated. However, trpeq " gf , for which the overall guardedness typing indicated is easily derivable. Moreover, the diagram on the right above satisfies the necessary condition from Proposition 27 but is not induced by an expression for which the indicated guardedness typing is derivable, essentially because both ways of cutting the loop violate the necessary condition from Proposition 27.
However, if C is ideally guarded over a guarded ideal G, we do have a converse to Proposition 27: By Theorem 14, we can then restrict basic boxes in diagrams to be either guarded, i.e. have only black gates, or unguarded, i.e. have only white gates. We call the correspondingly restricted diagrams ideally guarded. (We emphasize that the guardedness typing of composite ideally guarded diagrams still needs to mix guarded and unguarded inputs and outputs.) A path in an ideally guarded diagram is guarded iff it passes through a guarded basic box.
The left-hand diagram in (2) is in fact ideally guarded, so guardedness typing fails to be closed under equality also in the ideally guarded case. However, for ideally guarded diagrams we have the following converse of Proposition 27.
Theorem 29. Let ∆ be an ideally guarded diagram, with sets of input and output gates disjointly decomposed as A Ÿ B and C Ÿ D, respectively. If every loop in ∆ and every path from a gate in A to a gate in D is guarded, then ∆ is induced by a traced morphism expression e such that e P Hom ‚ pA b B, C b Dq is derivable.
We next take a look at the Cartesian and co-Cartesian cases. Recall that by Proposition 5, the definition of guarded category can be simplified if b "`(and dually if b "ˆ). This simplification extends to guarded traced categories by generalizing Hyland-Hasegawa's equivalence between Cartesian trace operators and Conway fixpoint operators [18,19].
Definition 30 (Guarded Conway operators). Let C be a guarded co-Cartesian category. We call an operator p--q : of profile a guarded iteration operator if it satisfies fixpoint: f : " rid, f : sf for f : X Ñ in2 Y`X; and a Conway iteration operator if it additionally satisfies naturality: g f : " ppg`idq f q : for f : X Ñ in2 Y`X, g : Y Ñ Z; dinaturality: prin 1 , hsgq : " rid, prin 1 , gshq : sg for g : X Ñ in2 Y`Z and h : Z Ñ Y`X or g : X Ñ Y`Z and h : Z Ñ in2 Y`X; (co)diagonal: prid, in 2 sf q : " f :: for f : X Ñ in2`id pY`Xq`X.
Furthermore, we distinguish the following principles: squaring [12]: and call p--q : squarable or uniform if it satisfies squaring or uniformity, respectively.
Guarded (Conway) recursion operators p--q : on guarded Cartesian categories are defined dually in a straightforward manner. We collect the following facts about guarded iteration operators for further reference.
Lemma 31. Let p--q : be a guarded iteration operator on pC,`, ∅q.
1. If p--q : is uniform w.r.t. some co-Cartesian subcategory of C and satisfies the codiagonal identity then it is squarable. 2. If p--q : is squarable and uniform w.r.t. coproduct injections then it is dinatural. 3. If p--q : is Conway then it is uniform w.r.t. coproduct injections.
Proposition 32. A guarded co-Cartesian category C is traced iff it is equipped with a guarded Conway iteration operator p--q : , with mutual conversions like in the total case [18,19]. 1. In a vacuously guarded co-Cartesian category (Remark 7), f : X Ñ in2 Y`Z iff f " in 1 g for some g : X Ñ Y . If coproduct injections are monic, then g is uniquely determined, and f : " g defines a guarded Conway operator.
2. Every Cartesian category C is guarded under Hom π pX, Y q " HompX, Y q (making every morphism guarded). Then C has a guarded Conway recursion operator iff C is a Conway category [13], i.e. models standard total recursion.
3. The guarded Cartesian category of complete metric spaces as in Example 9 is traced: For f : XˆY Ñ pr 2 Y , define f : pxq as the unique fixpoint of λy. f px, yq according to Banach's fixpoint theorem. 4. Similarly, the topos of trees, ideally guarded as in Example 24, has a guarded Conway recursion operator obtained by taking unique fixpoints [7, Theorem 2.4].
5. The guarded co-Cartesian category C T Σ of side-effecting processes (Example 8) has a guarded Conway iteration operator obtained by taking unique fixpoints, thanks to the universal property of the final coalgebra T Σ X [33].
Guarded vs. unguarded recursion We proceed to present a class of examples relating guarded and unguarded recursion. For motivation, consider the category pCpo,ˆ, 1q of complete partial orders (cpos) and continuous maps. This category nearly supports recursion via least fixpoints, except that, e.g., id : X Ñ X only has a least fixpoint if X has a bottom. The following equivalent approaches involve the lifting monad p--q K , which adjoins a fresh bottom K to a given X P |Cpo|.
Classical approach [40,39]: Define a total recursion operator p´q ; on the category Cpo K of pointed cpos and continuous maps, using least fixpoints.
Pointed cpos happen to be always of the form X K with X P |Cpo|, which indicates that p--q ; is a special case of p--q : . This is no longer true in more general cases when the connection between p--q ; and p--q : is more intricate. We show that p--q ; and p--q : are nevertheless equivalent under reasonable assumptions.
The key requirement is the last one, satisfied, e.g., for Cpo and the lifting monad. Given a monad T on C, C T ‹ denotes the category of T-algebras and C-morphisms (instead of T-algebra homomorphisms).

Proposition 35 ([38, Theorem 4.6]
). Let pC, T, Ω, ωq be a let-ccc with a fixpoint object. Then C T ‹ has a unique C T -uniform recursion operator p--q ; . By [39,Theorem 4], the operator p--q ; in Proposition 35 is Conway, in particular, by Lemma 31, squarable, if C has a natural numbers object and T is an equational lifting monad [10], such as p´q K . There are however further squarable operators obtained via Proposition 35, e.g. for the partial state monad T X " pXˆSq S K [11]. By Lemma 31, the following result applies in particular in the setup of Proposition 35 under the additional assumption of squarability.

Vacuous Guardedness and Nuclear Ideals
We proceed to discuss traces in vacuously guarded categories (Lemma 3), and show that the partial trace operation in the category of (possibly infinite-dimensional) Hilbert spaces [2] in fact lives over the vacuous guarded structure. We first note that vacuous guarded structures are traced as soon as a simple rewiring operation satisfies a suitable well-definedness condition (similar to one defining traced nuclear ideals [2, Definition 8.14]): depends only on f , then C is guarded traced, with tr U A,B,C,D pf q defined as (6).
Diagrammatically, the trace in a vacuously guarded category is thus given by We proceed to instantiate the above to Hilbert spaces. On a more abstract level, a dagger symmetric monoidal category [36] (or tensored˚-category [2]) is a symmetric monoidal category pC, b, Iq equipped with an identity-on-objects strictly involutive functor p--q : : C Ñ C op coherently preserving the symmetric monoidal structure. The main motivation for dagger symmetric monoidal categories is to capture categories that are similar to (dagger) compact closed categories in that they admit a canonical trace construction for certain morphisms, but fail to be closed, much less compact closed. The "compact closed part" of a dagger symmetric monoidal category is axiomatized as follows.
Definition 38 (Nuclear Ideal, [2]). A nuclear ideal N in a dagger symmetric monoidal category pC, b, I, p--q : q is a family of subsets NpX, Y q Ď Hom C pX, Y q, X, Y P |C|, satisfying the following conditions: 1. N is closed under b, p--q : , and composition with arbitrary morphisms on both sides; 2. There is a bijection θ : NpX, Y q Ñ Hom C pI, X : b Y q, natural in X and Y , coherently preserving the dagger symmetric monoidal structure.
3. (Compactness) For f P NpB, Aq and g P NpB, Cq, the following diagram commutes: The above definition is slightly simplified in that we elide a covariant involutive functor p--q : C Ñ C, capturing, e.g. complex conjugation; i.e., we essentially restrict to spaces over the reals. We proceed to present a representative example of a nuclear ideal in the category of Hilbert spaces. Recall that a Hilbert space [23] H over the field R of reals is a vector space with an inner product --, --: HˆH Ñ R that is complete as a normed space under the induced norm ||x|| " x, x . Let Hilb be the category of Hilbert spaces and bounded linear operators.
Clearly, R itself is a Hilbert space; linear operators X Ñ R are conventionally called functionals. More generally, we consider (multi-)linear functionals X 1.
. .ˆX n Ñ R, i.e. maps that are linear in every argument. Such a functional is bounded if |f px 1 , . . . , x n q| ď c||x 1 ||¨¨¨||x n || for some constant c P R. We can move between bounded linear operators and bounded linear functionals, similarly as we can move between relations and functions to the Booleans: . , x n qq 2 is finite for some, and then any, orthonormal bases B 1 , . . . , B n of X 1 , . . . , X n , respectively. A bounded linear operator f : X Ñ Y is Hilbert-Schmidt if the induced functional f˝(Proposition 39) is Hilbert-Schmidt, equivalently if xPB ||f x|| 2 is finite for some, and then any, orthonormal basis B of X. We denote by HSpX, Y q the space of all Hilbert-Schmidt operators from X to Y . For X, Y P |Hilb|, the space of Hilbert-Schmidt functionals XˆY Ñ R is itself a Hilbert space, denoted X b Y , with the pointwise vector space structure and the inner product f, g " xPB yPB 1 f px, yqgpx, yq. where B and B 1 are orthonormal bases of X and Y , respectively. By virtue of the equivalence between f and f˝, this induces a Hilbert space structure on HSpX, Y q, with induced norm ||f || 2 " xPB ||f x|| 2 . The operator b forms part of a dagger symmetric monoidal structure on Hilb, with unit R. For a bounded linear operator f : X Ñ Y , f : : Y Ñ X is the adjoint operator uniquely determined by equation x, f : y " f x, y . The tensor product of f : A Ñ B and g : C Ñ D is the functional sending h : AˆC Ñ R to h pf :ˆg: q : BˆD Ñ R. Given a P A and c P C, let us denote by a b c P A b C the functional pa 1 , c 1 q Þ Ñ a, a 1 c, c 1 , and so, with the above f and g, pf b gqpa b cq " f paq b gpcq.
A crucial fact underlying the proof of Proposition 41 is that HSpX, Y q is isomorphic to X : b Y , naturally in X and Y . We emphasize that what makes the case of Hilb significant is that we do not restrict to finite-dimensional Hilbert spaces. In that case all bounded linear operators would be Hilbert-Schmidt and the corresponding category would be (dagger) compact closed [36]. In the infinitedimensional case, identities need not be Hilbert-Schmidt, so HS is indeed only an ideal and not a subcategory.
Let N 2 pX, Y q " {g : h : X Ñ Y | h P NpX, Zq, g P NpY, Zq} for any nuclear ideal N. The main theorem of the section now can be stated as follows.
1. The guarded ideal induced by the vacuous guarded structure on Hilb (see (1)) is precisely HS 2 , and Hilb is guarded traced over HS 2 .
2. Guarded traces in Hilb commute with p´q : in the sense that if f P [2,Theorem 8.16] to parametrized traces. Specifically, we obtain agreement with the conventional mathematical definition of trace: given f P HS 2 pX, Xq, trpf q " i f pe i q, e i for any choice of an orthonormal basis pe i q i , and HS 2 pX, Xq contains precisely those f for which this sum is absolutely convergent independently of the basis.

Conclusions and Further Work
We have presented and investigated a notion of abstract guardedness and guarded traces, focusing on foundational results and important classes of examples. We have distinguished a more specific notion of ideal guardedness, which in many respects appears to be better behaved than the unrestricted one, in particular ensures closer agreement between structural and geometric guardedness. An unexpectedly prominent role is played by 'vacuous' guardedness, characterized by the absence of paths connecting unguarded inputs to guarded outputs; e.g., partial traces in Hilbert spaces [2] turn out to be based on this form of guardedness. Further research will concern a coherence theorem for guarded traced categories generalizing the well-known unguarded case [22,35], and a generalization of the Int-construction [22], which would relate guarded traced categories to a suitable guarded version of compact closed categories. Also, we plan to investigate guarded traced categories as a basis for generalized Hoare logics, extending and unifying previous work [5,15].

A Appendix: Omitted Details and Proofs
A.1 Derivability of Weakening (Section 3) We show that we can weaken on the right (output) side; by duality, we can then also weaken on the input side, and the claim follows by weakening first on the output and then on the input side. That is, we assume that f P Hom ‚ pA b B, C b pD 1 b Dqq and derive f P Hom ‚ pA b B, pC b D 1 First note that by (cmp b ) and (vac b ), guardedness annotations are stable under rearranging guarded output gates via monoidal isomorphims, and similarly for the unguarded output gates and both types of input gates. We obtain by (vac b ) that id C b I P Hom ‚ pC b I, C b Iq and I b id D P Hom ‚ pI b D, I b Dq. By (uni b ), (par b ), and stability under monoidal isomorphisms, we derive (eliding associativity throughout) and hence, again using stability under monoidal isomorphisms, Our goal then follows by (cmp b ).

A.2 Proof of Theorem 2
For purposes of this proof, call a path leading from an input gate in A to an output gate in D as in the claim critical. That is, we are to show that e types as requested iff all critical paths in its diagram are guarded.
'Only if ': By induction on the derivation of e P Hom ‚ pA b B, C b Dq. The base case (introduction of morphism symbols) is trivial. The cases for the rules from Definition 1, diagrammatically represented according to Figure 2, are as follows. In the cases for rules (uni b ) and (vac b ), there are no critical paths. For rule (par b ), just note that every critical path in the diagram for f b g is either a critical path in the diagram for f or a critical path in the diagram for g. For (cmp b ), let π be a critical path in the diagram for gf . We distinguish cases on whether π leaves f through a guarded or an unguarded output gate. By the symmetry manifest in Figure 2, we can w.l.o.g. assume the latter. As can, again, be seen in Figure 2, π then enters g through an unguarded input gate and leaves g through a guarded output, so by the inductive hypothesis, the part of π that leads through g is guarded, and then of course π itself is guarded.
'If ': We can regard the diagrammatic rules in Figure 2 as a set of rules for establishing guardedness of diagrams (essentially, this lets us use the known coherence theorem for symmetric monoidal categories to avoid bookkeeping with associativity etc.). In terms of diagrams, object expressions (such as A and D in the claim) correspond to sets of gates, and we will henceforth conflate the two notions. Let us denote by G e pE, Oq the statement that the diagram of e is provably unguarded in a set E of input gates and simultaneously guarded in a set O of output gates (i.e. that the corresponding gates can be marked black according to the rules in Figure 2). We thus have to show G e pA, Dq. We proceed by structural induction over e. For the case where e is a basic box f , note that the assumption implies that the unguarded gates of the given diagram are contained in those given in the basic guardedness assumption for f , similarly for the guarded outputs, so that G e pA, Dq by weakening. The other base cases are straightforward, as they do not contain any basic boxes, so that the assumption implies that there are no critical paths; to make one example implicit: if e is an identity, then absence of critical paths implies that one of A and D is empty, so that G e pA, Dq by (vac b ). The other cases are as follows.
The expression e is a composite e 2 e 1 . Let M be the set of joint gates W of e 1 and e 2 such that all paths from W to gates in D in the diagram of e 2 are guarded, and analogously, let N be the set of joint gates W of e 1 and e 2 such that all paths from gates in A to W are guarded. Note that the union N Y M consists of all joint gates of e 1 and e 2 : If there was a joint gate W R N Y M , then there would be an unguarded path from some X in A to W and an unguarded path from W to some Y in D; then the concatenated path would be critical (for e 2 e 1 ) and also unguarded, contradicting the assumption. Now by induction G e1 pA, N q and G e2 pM, Dq, and by the above, the complement N of N is N " pM Y N qzN Ď M . By weakening, we therefore have G e2 pN , Dq, so G e pA, Dq by (the diagrammatic version of) (cmp b ).
The expression e is a tensor e 1 b e 2 . Then A and D are disjoint unions where the gates in A 1 and D 1 are contributed by e 1 and those in A 2 and D 2 by e 2 . Every path in the diagram of e 1 from a gate in A 1 to a gate in D 1 is a critical path in e 1 b e 2 , hence guarded by assumption; hence G e1 pA 1 , D 1 q by induction. Analogously, G e2 pA 2 , D 2 q, and thus G e pA, Dq by (the diagrammatic version of) (par b ).

A.3 Proof of Lemma 3
Any morphism that factors as ph b id D qpid A b gq as in the statement is guarded in any guarded structure by rules (vac b ) and (cmp b ) (plus weakening). This proves that the putative guarded structure described is contained in all guarded structures on C. It remains to show that the axioms of Definition 1 are satisfied. The rules (uni b ) and (vac b )) are clear, and closure under rule (par b ) is easily seen by rearranging boxes and gates using commutativity and associativity of b.
For closure under rule (cmp b ), finally, assume that f 1 " ph 1 b idqpid b g 1 q, Then f 2 f 1 factors, omitting associativity isomorphisms, into id b ppid b g 2 qg 1 q and ph 2 ph 1 b idqq b id.
[ \ The proof of Proposition 5 then proceeds as follows. Suppose that pC,`, ∅q is guarded and let us show first of all that the above condition uniquely determines the Hom in2 pX, Y`Zq. Indeed, on the one hand we obtain as the definition: f P Hom in2 pX, Y`Zq if rf, !s P Hom ‚ pX`∅, Y`Zq. On the other hand if f " g in 1 then g P Hom ‚ pX`X 1 , Y`Zq implies rf, !s " rg in 1 , !s " rg in 1 , ! in 2 s " g pid`!q P Hom ‚ pX`∅, Y`Zq by (vac b ) and (cmp b ), that is, decomposition of X different than X`∅ do not affect the definition of Hom in2 pX, Y`Zq.
We proceed to prove the required properties.
(vac`) Let f : X Ñ Z. Then by (vac b ), f`! : X`∅ Ñ in2,in2 Z`Y . Modulo the fact that X is a coproduct of X and ∅, this is equivalent to f in 1 : (cmp`) Suppose that f P Hom in2 pX, Y`Zq, g P Hom σ pY, V q and h : Z Ñ V . Then f : X Ñ !,in2 Y`Z and we would be done by Lemma 43 if we showed g : Y Ñ !,σ V and h : Z Ñ id,σ V . The former of these two judgements is an assumption. To prove the latter one, note that h : Z Ñ id,id V by (vac b ) and id : V Ñ id,σ V by (uni b ). Hence, indeed h : Z Ñ id,σ V by (cmp b ). (par`) The assumption read as f : X Ñ !,σ Z, g : Y Ñ !,σ Z. By Lemma 43, rf, gs : X`Y Ñ !,σ Z, which is the goal.
We proceed to show the converse implication.
(vac b ) Let f : A Ñ B and g : C Ñ D. Note that in 1 : A Ñ in2 A`C and in 1 f : A Ñ in2 B`D by (vac`), and therefore, by (cmp`), pf`gq in 1 " rin 1 f, in 2 gs in 1 : A Ñ in2 B`D, which is equivalent to the goal.
(cmp b ) Since f g in 1 " rf in 1 , f in 2 sg in 1 and by assumption g in 1 P Hom in2 pA, C`Dq, by (cmp`), we reduce the goal to f in 1 P Hom in2 pC, E`F q, which is again part of the assumption.
(par b ) By assumption, f in 1 P Hom in2 pA, C`Dq and g in 1 P Hom in2 pA 1 , C 1`D1 q. And we need to show that for rpin 1`i n 1 qf, pin 2`i n 2 qgspin 1`i n 1 q P Hom in2 pA`A 1 , pC`C 1 q`pD`D 1 qq. Indeed, by assumption f in 1 P Hom in2 pA, C`Dq and hence by (vac`) and (cmp`), pin 1`i n 1 q f in 1 " rin 1 in 1 , in 2 in 1 sf in 1 P Hom in2 pA, pC`C 1 q`pD`D 1 qq. Symmetrically, pin 2`i n 2 q g in 1 P Hom in2 pA 1 , pC`C 1 q`pD`D 1 qq, and thus we are done by (par`).

A.5 Proof of Lemma 12
Note that by (vac b ), Hom pI, Iq " HompI, Iq The closure conditions are instances of diagrams from Figure 2.

A.6 Existence of Non-Ideal Guarded Structures (Section 4)
Example 44. Let T be the monad on Set for the algebraic theory of commutative semigroups with the additional law x˚y " x. The Kleisli category Set T is co-Cartesian with coproducts inherited from Set, and so we put f : X Ñ 2 T pY`Zq iff f " pT in 1 q g for some g : X Ñ T Y . According to this definition, f P Hom pX, T Y q iff f factors through T ∅ " ∅, i.e. when X " ∅ and f " ! T Y . This induces a different guarded category structure on Set T : f : X Ñ 2 T pY`Zq iff Z " ∅. Consider the term x˚y P T pX`Y q (seen as a morphism 1 Ñ T pX`Y q) with x P X and y P Y . It is in 2 -guarded under the original definition, for it is equivalent to the term x P T pX`∅q, but not under the new definition unless Y " ∅.

A.7 Proof of Theorem 14
By the axioms of guarded categories (or more quickly by Theorem 2), it is clear that morphisms of the given form must be in Hom ‚ pA b B, C b Dq. It remains to check closure under the axioms of Definition 1. To that end, consider a generic morphism pq b idqw n . . . w 1 pid b pq where p : B Ñ B 1 b C 1 , q : B n b C n Ñ C, A 1 " A, C n " D and each w i : In order to capture (uni b ) and (vac b ) it suffices to take n " 0, and select p and q in the obvious way. Axiom (cmp b ) is clear by definition. Let us verify (par b ). Given f " pqbidq w n . . . w 1 pidbpq and f 1 " pq 1 bidq w 1 m . . . w 1 1 pidbp 1 q, we assume them to be an input to the (par b ) rule. W.l.o.g. we assume that n " m (missing sections of the form (7) with a middle wire of type I can obviously be added by need either to f or to f 1 ). Note that the tensor product of two sections of the form (7) can again be arranged in a diagram in the same form: where we make use of the fact that g i b g 1 i belongs to the guarded ideal, for g i and g 1 i individually do. By induction over n this implies that the combination of f and f 1 figuring in (par b ) rule has the specified format.

A.8 Proof of Lemma 17
Consider a composite of (7) with a diagram of the form We argue that this composite is equivalent to a diagram of the same form as on the right of (8). Indeed by the axioms of guarded ideals, we can replace the tensor product of g i and g with a single guarded morphism, and then compose the result with f i to obtain another guarded morphism, say h P GpX, Y b Zq.
By assumption, the latter can be represented as e pĥ b idq, i.e. in summary we obtain i ĥ e This is clearly reducible to the a diagram in the same form as on the right of (8). Now, assuming a morphism f P Hom ‚ pA b B, C b Dq as defined in clause (1) with B " C " I, note that pq b idq : pA n b B n q b D Ñ I b D falls into the format specified by the diagram on the right of (8) (one takes g " id : I Ñ I, which belongs to GpI, Iq). By inductively applying the above argument we contract f " pq b idq w n . . . w 1 pid b pq to the form ĥ p Here p is a guarded morphism because it factors through id : I Ñ I P GpI, Iq. The obtained diagram clearly yields a guarded morphism, and we are done. [ \

A.9 Proof of Proposition 15
Immediate from Lemma 45.1 below and the assumption that C is equipped with the least guarded structure.
1. The guarded structure on C induced by G is contained in the original one.
2. If C is ideally guarded, then G induces the guarded structure of C.
Proof. 1. Immediate from the fact that the guarded structure induced by G is the least one containing G. 2. The given guarded ideal inducing the guarded structure of C is contained in G, so the given guarded structure on C is contained in the one induced by C. Part 1 then implies equality.

A.10 Proof of Theorem 18
First of all, note that Lemma 17 applies to the case at hand, for any f P GpX`Y, Zq can be represented as follows f " rf in 1 , f in 2 s " rid, f in 2 s pf in 1`i dq where f in 1 P GpX, Zq, by closure properties of guarded ideals. It remains to prove (1) that the is a correct definition of a guardedness structure, and (2) that it is contained in the guardedness structure generated by G.
2. By Proposition 5 the general form of a partially guarded morphism induced by (9) is rrin 1 , gsh, us : A`B Ñ C`D with u : B Ñ C`D, h : A Ñ C`D 1 , g : D 1 Ñ C`D, which can be structured as follows: u and this indeed fits the format specified by Theorem 14.

A.11 Proof of Corollary 20
Record first of all that G is exponential iff f P GpXˆY, Zq implies curry f P GpX, Z Y q, for given f P GpXˆY, Zq, curry f " f Y currypid XˆY q, and given g P GpX, Y q, g V " currypg evq. The given construction produces a guarded category only if G is exponential, for f P GpXˆY, Zq must by weakening imply f : XˆY Ñ pr 1 Z, whence, by definition, curry f P GpX, Z Y q.
Conversely, suppose that G is exponential. We proceed to show that the description of the guarded structure on C according to Corollary 19 is equivalent to the current one, which will finish the argument. On the one hand, if curry f P GpX, Z Y q then f " ev pcurry fˆidq " ev pcurry f qpr 1 , pr 2 , i.e. f is pr 1 -guarded in the sense of Corollary 19; on the other hand, if f " h g, pr 2 for some g P GpXˆY, W q, then curry f " curryph ev, pr 2 q pcurry gq P GpX, Z Y q.

A.12 Proof of Proposition 22
The axioms of guarded ideals are easy to check. As an example let us verify closedness underˆ: given f : A Ñ B, g : C Ñ D, f nextˆg next " f next pr 1 , g next pr 2 " f p pr 1 q, g p pr 2 q next .

A.13 Proof of Proposition 27
Induction on e. All cases except the one for the trace operation are analogous to Theorem 2. So let e have the form tr A,B,C,D pe 1 q where e 1 P Hom ‚ ppA b U q b B, C b pD b U qq. Every path from an input gate in A to an output gate in D in the diagram of tr A,B,C,D pe 1 q is also such a path in e 1 , hence guarded by induction. The only new loops in the diagram of tr A,B,C,D pe 1 q are the ones generated by the current application of the trace operator. Every such loop π incorporates a path from an input gate in U to an output gate in U , which is guarded by induction; thus, π itself is guarded.

A.14 Details for Example 28 (Right Hand Diagram)
To see that the necessary condition from Proposition 27 holds, note that both the loop through f and g and the path from the unguarded input to the guarded output of the diagram are guarded. We show that the diagram is not induced by an expression for which the indicated overall guardedness typing of the diagram (one unguarded input, one guarded output) is derivable: The paths connecting the unguarded input and the guarded output of the diagram with the loop preclude a derivation using (vac b ); the only way that remains is to apply the rule for tr. But both ways of cutting the loop (in either case marking the newly open input gate of the diagram as unguarded and the new output gate as guarded in order to enable application of tr) lead to diagrams that have an unguarded path from an unguarded input to a guarded output, violating the necessary condition from Proposition 27.

A.15 Proof of Theorem 29
Induction on the number of loops in ∆, with Theorem 2 (plus the standard fact that, disregarding guardedness, every acyclic diagram is induced by some trace-free morphism expression) as the base case. The inductive step is as follows.
Recall that there are only two types of basic boxes regarding their decoration, the basic generic guards and boxes with only guarded inputs and only unguarded outputs. In reference to the colour of the decorations, we call the former black and the latter white.
Let U denote the set of nodes n in ∆ that have an unguarded path from their inputs to some output gate in D (i.e. the unguarded path includes n itself); dually, let V denote the set of nodes in ∆ that have an unguarded path from some input gate in A to their outputs. By the simplified characterization of guarded paths in ideally guarded diagrams, all nodes in U Y V must be white.
Then the assumption implies that Since we are in the inductive step, there exists a loop π in ∆.
Claim 1: There is some wire w belonging to π that connects an output gate O of a basic box f R V to an input gate I of a basic box g R U .
To see this, assume for a contradiction that w fails to exist, i.e. every wire in π is attached either to an output of a box in V or to an input of a box in U . Pick some wire v on π, and assume w.l.o.g. that v is attached to an input of a box in U . Then by (10), the same must hold for the next wire on π. Continuing around the loop, we find that all boxes on π are in U , in particular are white, contradicting the assumption that π is guarded. This proves Claim 1.
Now take w as in Claim 1. Briefly, we can cut w, apply the inductive assumption and then reintroduce w by means of the trace operator. In detail, let the diagram ∆ 1 arise from ∆ by cutting w, let A 1 consist of the gates in A and the newly open input gate I, and let D 1 consist of the gates in D and the newly open output gate O. Now since f R V and g R U , every path π 1 from an input gate in A 1 to an output gate in D 1 falls within one of the following cases. π 1 runs from a gate in A to a gate in D. Since π 1 is already present in ∆, π 1 is then guarded by assumption. π 1 runs from I to O. Then the nodes of π 1 form a loop in ∆, so that π 1 is guarded by assumption. π 1 runs from I to a gate in D. Since g R U , π 1 is guarded. Dually, π 1 is guarded if it runs from a gate in A to O.
Finally, all loops in ∆ 1 are already present in ∆, hence guarded by assumption. By the inductive hypothesis, we therefore have e P Hom ‚ pA 1 b B, C b D 1 q " Hom ‚ ppA b U q b B, C b pD b U qq inducing ∆ 1 , where U is the joint type of I and O. Then, ∆ is induced the expression trpe 1 q.