Motivated by the non-standard interpretations of if-then-else in probabilistic and quantum programs we review the different semantics of conditional branching and propose a unifying categorical structure for the interpretation of if-then-else. We show that many semantically important categories possess this structure, covering inter alia classical, probabilistic, quantum or non-deterministic computations. We examine algebraic structures related to and generated by this categorical structure, in particular on collections of predicates. In this setting we show that the skew-associativity rules of GKATs and barycentric algebras are two instances of a common skew-associativity rule.
Motivation. The ideas and results presented in this work originate from a simple observation about the semantics of probabilistic programs. If one follows the classic semantics proposed by Kozen either in terms of forward state (i.e. measure) transformer [22], or in terms of backwards predicate (i.e. function) transformer [23], one inevitably lands in a semantic world of vector spaces and operators. This naturally leads to a linear perspective on probabilistic programs where states cannot be copied, or at least not in a way that is compatible with higher order computations [10]. In other words, randomness is seen as a resource.
However, there is one fundamental construct with respect to which randomness does not behave as a resource: conditional branching, that is to say if-then-else statements. Consider for example the following simple imperative program {lstlisting} if x¿0 then x = x+1 else x = x-1 Following [22], this program is interpreted as a linear operator on the Banach space of input distributions on x. Given such an input state μ, the semantics of the program will:
(i) split μ into two subdistributions, one satisfying the guard and the other its complement,
(ii) apply the if branch (+1) to the first subdistribution, the else branch (−1) to the second,
(iii) finally, recombine the two branches (via pointwise addition) to produce the output.
The remarkable fact is that, despite being a fundamentally linear semantics, the initial state μ is not consumed by the evaluation of the guard x>0. In fact, the guard is not evaluated at all in the sense that no boolean value or even convex combination thereof is produced. The splitting-recombining mechanism provides a linear alternative to guard evaluation that allows each branch to access the (relevant part of the) input state.
The situation is very similar in the quantum case, although it is complicated by the existence of two fundamentally different notions of conditional branching. The first is coherent or quantum branching, where the guard is itself a quantum system and no measurement is performed. A canonical example is the CNOT gate, where the control qubit determines which branch is taken while remaining available and un-measured. Semantically, this type of branching can be understood as an instance of the mechanism we have just described: the quantum state is split and then recombined as a superposition of two control paths (the if and else branches), each transformed independently. The other notion is measurement-based branching, where the guard is evaluated by measuring a quantum system and the branch is selected by the resulting classical outcome. Here the measurement irreversibly changes the observed qubits and may alter any entanglement between them and the rest of the system.
The state-splitting mechanism of probabilistic and coherent control is different both from the classical interpretation of conditional branching [15] where the state/context is copied, with one copy used to evaluate the guard and the other to continue the computation, and from the linear interpretation of conditional branching where evaluating the guard consumes the state/context making it unavailable for the rest of the computation (as is the case in measurement-based quantum control [28]). There are thus at least three incomparable ways of interpreting if-then-else statements, which raises the following questions:
Can we reconcile these different interpretations of conditional branching?
More generally, what is the ‘minimal’ structure needed to interpret if-then-else ?
What program equivalences can we expect of a general interpretation of conditionals?
Answering these questions is about a lot more than clarifying an interesting quirk of probabilistic program semantics, if-then-else statements are fundamental to the practice of programming and we should endeavour to interpret and understand them in the widest possible context. Concretely, this means that given any programming paradigm, say probabilistic hybrid computations with exceptions, we should be able to work out (a) what (if any) interpretations of conditional branching it can support, and (b) what kind of program equivalences can be shown for these interpretations. For instance does ifbthenpelseq≡ifnotbthenqelsep hold? What does not even mean?
The objective of this work is to provide tools for answering these questions. As a short slogan: we aim to provide a semantic structure that does for conditional branching what traced monoidal categories did for recursion and iteration.
Contributions and structure of the paper. In § 2 we review the various semantics of conditional branching that can be found ‘in the wild’: the classical interpretation via copying and distributing (§ 2.1), the linear and mixed interpretations (§ 2.2), the probabilistic ‘state-splitting’ approach (§ 2.3), and coherent control (§ 2.4). In § 3 we introduce and justify the notion of conditionally branching category as a semantic structure in which if-then-else statements can be interpreted in a way that follows (some of) the standard axioms governing the behaviour of if-then-else statements. In § 4 we provide examples of conditionally branching categories including domain-theoretic models of call-by-value computations, Markov categories [14], models of effectful computations [27], and the motivating vector-space models for which we present a very general state-splitting result (§ 4.2). Finally, in § 5 we will see that a lot of structural mileage can be obtained from the humble coproduct. We study the structure of the set of branching morphisms, i.e. morphisms of the shape X→X+X in § 5.1 and of the set of tests, i.e. morphisms of the shape X→1+1 in § 5.2. Finally, in § 5.3 we examine the skew-associativity rule associated with one of the more complex behaviours of conditional branching that sometimes allows us to re-write nested if-then-else statements. We show that the skew-associativity axiom of Guarded Kleene Algebras with Tests [34] and the seemingly unrelated skew-associativity axiom of barycentric algebras [26] are two instances of a general skew-associativity rule.
Notation and terminology. We will be using a generic typed functional language and consider typing judgements Γ⊢s:T interpreted as morphisms [[s]]:[[Γ]]→[[T]] in a category C. We will be concerned with such a small language fragment (just what is needed to talk about if-then-else) that we choose not to specify a full syntax and semantics but rather introduce constructs if and when needed. We assume that the type grammar contains a unit type 1 and coproduct types S+T. Term formation thus includes the typing rules:
The pattern-matching rule above is linear: contexts are consumed by computations. We will not assume that the categories in which programs are interpreted are Cartesian, we will only assume that they are monoidal, as is the case for vector-space models of probabilistic and quantum computations, as well as many examples of effectful computations. However, guided by the probabilistic and quantum examples given in the introduction, this paper will revolve around understanding the semantics of the following if-then-else-rule:
where the context Γ is now used in a non-linear manner: the program p does not consume the context in (2), it is still available to s and t. In other words, we will not view ifpthenselset as syntactic sugar for instances of the pattern-matching rule (1) of the shape Γ,Δ⊢casepof(in(1,x)⇒s,in(2,x)⇒t) with a guard Γ⊢p:1+1. Note that this context-consuming type of branching will nevertheless always be available to us as well, by virtue of the existence of (1). We will call programs of type 1+1 predicates [18] or tests [24]. In the context of a program ifpthenselset, the predicate p will be referred to as the guard.
We assume basic knowledge of category theory and use the standard notations π1,π2 and in1,in2 for the first and second projection and coprojections respectively, ⟨f,g⟩ and [f,g] for the pairing and copairing of morphisms, f×g≜⟨f∘π1,g∘π2⟩ and f+g≜[in1∘f,in2∘g], and finally ΔX≜⟨idX,idX⟩:X→X×X and ∇X≜[idX,idX]:X+X→X for the diagonal and codiagonal morphisms respectively.
2 Semantics of if-then-else in the wild
2.1 Classical branching by copying and distributing
Vanilla flavour. The standard way of interpreting the if-then-else rule (2) involves copying the context, using one copy to evaluate the guard and the other to continue the computation. This can be formalised in any distributive category [15], that is to say in any category C with finite products and coproducts such that for any C-objects A,B,C the canonical morphism
[idA×in1,idA×in2]:(A×B)+(A×C)→A×(B+C)
is an isomorphism. We write ldistrA,B,C:A×(B+C)→(A×B)+(A×C) for its inverse. Similarly, we will write rdistrA,B,C:(B+C)×A→(B×A)+(C×A) for the right-distributivity isomorphism. In the case that interests us the most B=C=1 and we will therefore simply write ldistrA:A×(1+1)→(A×1)+(A×1)≃A+A. In this non-linear/Cartesian context (2) simplifies to
Whilst this is a natural and intuitive semantics, many categories that are important for the semantics of programs fail to be distributive.
Example 1.
Non-deterministic computations are often interpreted in the Kleisli category of the powerset monad on Set, which is equivalent to the category Rel of sets and relations. In Rel, products and coproducts are both given by disjoint union [7, §5.4.7] and the category is therefore not distributive: 1×(1+1) has three elements whereas (1×1)+(1×1) has four.
Example 2.
Another important example is the category ωCPO of pointed ω-complete partial order, or ω-cpos, and monotone maps. This category does not have coproducts [35] and in particular cannot be distributive. If we restrict ourselves to the sub-category ωCPO⊥ of ω-cpos and strict morphisms, then coproducts do exist and are given by the carriers A+B=(A∖{⊥A})+(B∖{⊥B})+{⊥} with the order inherited from A,B (sometimes known as the coalesced sum). Products are constructed by taking the Cartesian product of the carriers together with the pointwise order. However, ωCPO⊥ is not distributive as a cardinality argument shows: if we consider the chain \mathbbm2 then \mathbbm2×(\mathbbm2+\mathbbm2) has 2×((2−1)+(2−1)+1)=6 elements but (\mathbbm2×\mathbbm2)+(\mathbbm2×\mathbbm2) has ((2×2)−1)+((2×2)−1)+1=7 elements.
Example 3.
Real-weighted (including probabilistic) computations can be interpreted in the category Vec of vector spaces and linear maps. Vec is not distributive for a reason that is similar to Rel, namely because the coproduct is given by the direct sum which is isomorphic to the Cartesian product in finite dimensions.
We show in § 4 that these non-distributive examples do support a semantics for if-then-else.
Monadic flavour. The copy-and-distribute approach can be extended straightforwardly to effectful computations à la Moggi [27]. This is done in [18, 19] which is probably the line of research that is closest to this work, although it focuses exclusively on Cartesian categories. Given a distributive category C and a strong monad T:C→C, we can consider predicates in the Kleisli category of T, i.e. C-morphisms p:X→T(1+1). Given such a predicate, [18, 19] defines the associated instrument as the morphism instrp:X→T(X+X) defined as
With this special morphism (that we generalise in § 3), the semantics of (3) is given by [[ifpthenselset]]≜[[[s]],[[t]]]∘instr[[p]] (where composition is taken in the Kleisli category). We return to this construction in more detail in § 4.1.
2.2 Linear and mixed branching
The linear case. In the context of a linear language equipped with the injections and pattern-matching rules (1), if-then-else is often understood in the context-consuming sense described in § 1, that is to say as syntactic sugar for pattern-matching (e.g. [28, 36]):
ifpthenselset≜casepof(in(1,x)⇒s,in(2,x)⇒t)
One can interpret (6) in any distributive monoidal category (C,⊗,I,+), i.e. a monoidal category that has coproducts and isomorphisms ldistrA,B,C:A⊗(B+C)→(A⊗B)+(A⊗C) and rdistrA,B,C:(B+C)⊗A→(B⊗A)+(C⊗A) via:
Since (2.2) interprets an instance of (1), the variables used by the programs s,t are not available to the guard p. This is arguably not how if-then-else statements are intuitively understood or used in practice. Indeed, the point of conditional branching is typically to apply different procedures to variables depending on a predicate on these same variables. Thus whilst we acknowledge that (6) provides a possible interpretation for if-then-else statements – and as discussed in the introduction this interpretation will always be available to us – we will be concerned with the interpretation of the non-linear branching rule (2).
The mixed case. There exists a half-way house between the non-linear copy-and-distribute mechanism and the purely linear one that is used when both non-linear (duplicable) and linear (non-duplicable) types coexist. Formally, consider a distributive monoidal category (C,⊗,I,+) that is equipped with an exponential comonad ! satisfying the usual requirements and defining copiable types !A. The rule (2) can then be modified into:
This is the semantics of the measurement-based branching of quantum computing, as defined for the quantum lambda calculus of [31, 32, 37] and interpreted in [28] and [37] (which specifically discusses branching). The context of the guard p consists of classical data that can be copied (!Γ) and quantum data (Δ) that cannot. In this model of measurement-based control, the quantum part of the input state gets collapsed by the measurement (i.e. by evaluating the guard) and is lost; only the result of the evaluation of the guard (which has type 1+1) is available to continue the computation.
Concretely, let us assume ground types qubit and bit≜1+1 and built-in functions meas:qubit→bit and Z:qubit→qubit interpreted in the category CPM⊕ whose objects are direct sums of finite-dimensional Hilbert spaces and whose morphisms are completely positive linear maps in the sense of [33, §3.2]. We can then consider the semantics of the instance of (9) (feed-forward correction) on two qubits x,y that measures the state of x, leaves y unchanged if ∣0⟩ is measured, or applies the Z gate to y if ∣1⟩ is measured:
Note the disappearance of the entanglement (represented by the blocks B,C) due to the measurement of x. We will see in § 4.2 that the non-linear if-then-else rule (2) can alternatively be used and satisfactorily interpreted to describe measurement-based control.
2.3 Branching by splitting and merging
The motivating example presented in the introduction was that of probabilistic programs, a computational paradigm which is linear (at least in its vector-space interpretation) yet comes with a meaningful mechanism for interpreting (2).
Following [22], we sketch parts of the semantics for first-order probabilistic programs in the category Ban of Banach spaces (over R) and linear contractions. This category is monoidal w.r.t. to the projective tensor product (which we will not need here) and has I=R as unit object. The coproduct in this category is given by the direct sum equipped with the ℓ1-norm, thus I+I is the vector space R2 equipped with the norm ∥(u,v)∥1=∣u∣+∣v∣, and Ban is distributive monoidal for these two operations. Each ground type T is first associated with an object X(T) in the category Meas of measurable spaces and measurable functions. For instance the unit type 1 is associated with the singleton space X(1)={∗} and the numeric type Real is associated with X(Real)=R, with the usual Borel σ-algebras. Given a measurable space X we will write MX for the Banach space of finite measures on X. For a context Γ=x1:T1,…,xn:Tn, a judgement Γ⊢t:T is interpreted as a linear operator
[[t]]:[[Γ]]≜M(X(T1)×…×X(Tn))→[[T]]≜MX(T)
The linear operator [[t]] transforms a joint probability distribution on the input variables of the context into an output distribution on the output type. A deterministic predicate Γ⊢p:1+1 is a predicate whose interpretation is of the shape
[[p]]=f∗:M(X(T1)×…×X(Tn))→MX(1+1)≃R2
where f∗ is the pushforward associated with a measurable map f:X(T1)×…×X(Tn)→X(1+1)=2. From p we can define the linear ‘decomposition’ operator splitting a distribution into a pair of subdistributions:
That this non-context-consuming branching mechanism can coexist with a linear system is remarkable and rests on the ability to define the splitting operator [[p]] as a contractive linear operator. We will show in § 4.2 that this construction can be extended to arbitrary guards for a very large class of input spaces [[Γ]].
2.4 Coherent branching in quantum programs
Our last example of conditional branching found in the wild is coherent/superposed control, a type of branching found in quantum computation, for example in the CNOT gate and described as the ‘elusive quantum control’ in [37, §4.2] as it is harder to account for both type-theoretically and semantically. We follow the formalism for QML [6, 5] and refer the reader to [37] for a detailed discussion. In QML the typing rule for coherent control is
where if∘ is meant to distinguish superposed control from measurement-based control and we have introduced the self-explanatory type qubit. The semantics of this rule assumes the existence of products, of a natural transformation δA,B:A⊗B→A×B, and for any pair f,g:A→B a mechanism for combining them into a morphism (f∣g):(1+1)×A→B selecting f or g according to the value of the ‘coordinate’ 1+1. With this structure [5] defines
We refer the reader to op.cit. for the specific denotational semantics that is based on finite sets; the structural components required to define it are sufficient for our purpose. Note that neither the category CPM⊕ nor the category Hilb of finite-dimensional vector spaces possesses this structure (there cannot exist an operator A⊗B→A×B), and so the semantics above does not yield the standard semantics of well-known examples of coherent control such as the CNOT or Toffoli gates. A recent approach axiomatises a notion of coherent control over Props [17] and shows that this corresponds to certain rig categories. We show in § 4.2 that coherent control can also be understood as an instance of (2) and interpreted accordingly.
3 Conditionally branching categories
In the previous section we have seen four mechanisms for interpreting if-then-else statements. None subsumes the others, they are incomparable. It is therefore natural to ask: what exactly is needed to interpret conditional branching in a general setting?
To answer this question we draw inspiration from the axiomatisation of conditional branching found in the theory of (Guarded) Kleene Algebras with Tests, i.e. (G)KATs [24, 34]. From this perspective, conditional branching is a collection of binary operations +b indexed by the elements b∈B of a Boolean algebra of ‘test programs’ and axiomatized by:
Skew-commutativity: e+bf=f+be
True test: e+1f=e
Idempotence: e+be=e
Skew-associativity: (e+bf)+cg=e+bc(f+cg)
where b stands for the negation of b, 1 is the top element of B and bc the conjunction of b,c∈B. Our first task is to adapt these ideas to typed computations with a categorical semantics. In particular, can we generalise the negation operation, the idea of a test returning ‘true’ or even the conjunction operation? As we shall see in § 5, while we cannot replicate the full boolean structure of deterministic tests in general, the humble coproduct provides us with a lot of the necessary machinery to adapt the axioms above. We therefore assume throughout that our target semantic universe is a symmetric and distributive monoidal category (C,⊗,I,+) in order to interpret the pattern-matching rule (1) as (2.2).
Following our terminology for programs, we also call morphisms of the type X→I+I predicates or tests. Note that I is in general not the terminal object, in contrast with [18] which is otherwise similar in spirit to a lot of what follows. We will call morphisms of the type X→X+X branching morphisms and since the first branch of an if-then-else statement is the branch corresponding to ‘true’, we will think of the first summand of a coproduct X+X as corresponding to ‘true’. In particular, we will use the convention that the first summand of I+I represents the truth value ‘true’, somewhat contrary to convention. Given an object X, the following special morphisms X+X→X+X will be important:
We omit subscripts when X=I and write \strueXf for \strueX∘f and similarly for \sfalse and \snot. Objects of the shape X+X+X+X will represent pairs of truth values. The four summands will intuitively correspond to, in order, (true,true), (true, false), (false, true) and (false,false). This justifies the notation for the following special morphisms X+X+X+X→X+X
We can now define the categorical structure that will interpret if-then-else statements.
Definition 5.
A conditionally branching category is a symmetric distributive monoidal category (C,⊗,I,+) equipped with a family of functions \choX:C(X,I+I)→C(X,X+X) that we will call choice functions and which satisfy for every test p:X→I+I
Beyond the simplicity of this semantics, let us provide some justification for our definition.
Structural similarity with traces. Our definition uses the same basic data as that of a traced monoidal category: a monoidal category together with a collection of functions between hom-sets of a particular shape and satisfying certain axioms. This echoes our stated aim to do for if-then-else what traced monoidal categories did for recursion and iteration.
Connection with iteration. Our definition gives a semantic basis for the interpretation of while loops in the context of Elgot theories and Elgot monads [13, 1, 2]. To interpret x:T⊢whilepdos:T one first needs a morphism e:[[T]]→[[T]]+[[T]] (possibly effectful) from which to compute the conditional iterate [13] e†:[[T]]→[[T]] interpreting the while loop. This is always available in a conditionally branching category via e=([[s]]+id[[T]])∘\cho[[T]](p). The fact that our definition is designed to interpret the if-then-else rule (2), in which the context can be shared by the guard and the branches, makes it possible to consider iteration even in linear cases (e.g. the semantics of probabilistic iteration of [22]). Thus a conditionally branching category is always ‘iteration ready’. This connects to the previous point via the well-know correspondence between iteration and traces for the cocartesian structure [16].
Connection with instruments. The shape of our definition has a precedent in quantum control in the shape of the notion of instrument, later generalised in e.g. [18, 19]. Given a predicate Γ⊢p:bit defining two orthogonal projections the Lüders instrument [25] provides a splitting operator [[Γ]]→[[Γ]]⊕[[Γ]] allowing a semantics of measurement-based control, precisely what a conditionally branching structure provides too (see § 4.2).
GKAT axioms. The definition enforces the GKAT axioms (1)-(2) given above. To see this, let us define programs that are syntactic counterparts of morphisms defined above:
The reader may wonder why skew-associativity has been left out of Theorem 6. The reason is that the obvious generalisation of skew-associativity does not hold in general. We will look at nested conditional branchings and skew-associativity in detail in § 5.3, but we can give a simple example to illustrate the problem. For purely probabilistic tests like flip\nicefrac12, it is in general impossible to find an r∈[0,1] playing the role on the conjunction of guards in GKAT’s skew-associativity and making the following skew-associativity identity hold:
The reason is that, semantically, this would require the probability of reaching s3 to be (1−q)=(1−q)(1−r) which does not hold in general. This suggests that the skew-associativity rule from GKAT, if it is to hold in more generality, must be a special case of a more general rule (e+bf)+cg=e+bc(f+b∙cg) for some operation b∙c yet to be determined and evaluating to c in the case of deterministic boolean tests. We return to this question in § 5.3. We can however show the identity corresponding to the GKAT axiom eg+bfg=(e+bf)g. For this we will use the standard let-binding rule
(where let bindings are interpreted in the usual way).
Remark 8.
It would seem natural to require that choice functions satisfy some naturality condition (no pun intended). The only one that makes sense is to ask that for all f:Y→X,
\choX(p)∘f=(f+f)∘\choY(p∘f).
Although this condition does hold for many conditionally branching categories, it does not hold in some important situations, for example non-deterministic computations. Unlike the definition of a trace, the conditionally branching structure doesn’t seem to demand any naturality conditions. However, the skew-commutativity and true test axioms do imply a kind of ‘combinatorial naturality’ in I+I in the sense that every ‘combinatorial’ endomorphism, that is to say the 4 endomorphisms fI:I+I→I+I generated by the coproduct structure, must be reflected on X+X via \choX(fI∘p)=fX∘\choX(p).
Remark 9.
It follows from Definition 5 that if a category C is equipped with a conditional branching structure, so is every subcategory D of C containing I and closed under ⊗ and +.
We conclude this section by considering the notion of short-circuiting (e.g. [29, p.222]). Short-circuiting is a behaviour of conditional branching characterised by the fact that classically only one of the branches ever needs to be evaluated: the if-branch when the guard evaluates to true, and the else-branch otherwise. In both cases, the remaining branch is ‘short-circuited’ i.e. not evaluated.
Definition 10.
A conditionally branching structure on a category C will be called short-circuiting if for every state s:I→X and every test p:X→I+I, if p∘s factors through in1:I→I+I, then the morphism \choX(p)∘s factors through in1:X→X+X, and similarly for in2. Diagrammatically:
I\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespacessX\ignorespaces\ignorespaces\ignorespaces\ignorespacespI\ignorespaces\ignorespaces\ignorespaces\ignorespacesin1 or in2I+II\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespacessX\ignorespaces\ignorespaces\ignorespaces\ignorespaces\choX(p)X\ignorespaces\ignorespaces\ignorespaces\ignorespacesin1 or in2X+X
The definition guarantees that whenever a predicate factors through \strue in a state s, then the semantics of the if-then-else statement can be written by only evaluating the semantics of the if-branch (since [[[s]],[[t]]]∘in1=[[s]]), and similarly for the else-branch.
4 Examples of conditionally branching categories
4.1 Distributive copy-categories
We first present a large class of categories in which the copy-and-distribute strategy discussed in § 2.1 can be used to define a conditionally branching structure. We do not need (Cartesian) distributive categories – as we saw in § 2.1 this excludes semantically important categories – but we do need categories that are distributive monoidal as a prerequisite to Definition 5.
Example 11.
We saw in Example 1 that the category Rel of non-deterministic computations is not distributive w.r.t. the Cartesian product of Rel. It is however distributive w.r.t. the monoidal structure given by the Cartesian product in Set with I={∗} the singleton set.
Example 12.
Similarly, we showed in Example 2 that the category ωCPO⊥ of pointed ω-cpos and strict morphisms is not distributive w.r.t. the Cartesian product. It is however distributive w.r.t. the smash product with carrier A⊗B=(A∖{⊥A})×(B∖{⊥B})∪{⊥} and the pointwise order. The unit of this product is the chain {⊥≤∗}.
In order to apply the copy-and-distribute method of § 2.1 we also need to be able to copy (a functionality that comes for free with the Cartesian product). The two examples above are examples of distributive copy categories [9], i.e. symmetric monoidal categories where every object comes equipped with a cocommutative and coassociative copying morphism copyA:A→A⊗A. In Rel the copy map is given by the diagonal map copyA(x)=(x,x), in ωCPO⊥ it is given by copyA(x)=(x,x) if x=⊥ and ⊥ else.
Theorem 13.
Every distributive copy category has a commutative conditionally branching structure given by the choice functions
This structure is short-circuiting in all deterministic states s:I→X (i.e. states such that copyX∘s=(s⊗s)∘copyI, see [14]).
The conditionally branching structure of (17) is in general not idempotent, therefore it does not support the rewriting schema [[Γ⊢ifpthenselses:T]]=[[Γ⊢s:T]]. To recover this behaviour, we need more structure on C. A copy-discard category [8] is a copy category such that every object also comes equipped with a deletion morphism delA:A→I which, together with the copy morphism copyA:A→A⊗A, equips it with a comonoid structure. If the unit I is terminal, then a copy-delete category is called a Markov category [14].
Theorem 14.
The conditionally branching structure given by (17) is idempotent whenever the distributive copy category C is Markov, in particular when it is distributive (§ 2.1).
Example 15.
The category Stoch [14, §4] of measurable spaces and Markov kernels is a Markov category, and can therefore be equipped with an idempotent and commutative conditionally branching structure following (17). It sends a stochastic test p:X→G(1+1), where G is the Giry monad, to \choX(p):X→G(X+X) given by
\choX(p)(x)=p(x)(1)δin1x+p(x)(2)δin2x
Example 16.
The category Rel is a copy category but it is not a Markov category as the terminal object (which is also the initial object by self-duality) is the empty set which is not the unit of the monoidal product described above. Rel therefore supports a commutative conditional branching structure, but not an idempotent one. This comes from the fact that the empty relation ∅:X→I+I semantically represents a crashing/divergent test, and for such a test it cannot be the case that [[Γ⊢ifpthenselses:T]]=[[Γ⊢s:T]].
Example 17.
Similarly, the category ωCPO⊥ is a copy category but not a Markov category as the unit of the smash product is not terminal. The commutative conditional branching structure of ωCPO⊥ given by (17) cannot be idempotent for the same reason as in the previous example: predicates p:X→I+I allow for divergence (that is the point of the bottom element ⊥) and it therefore cannot be the case that [[Γ⊢ifpthenselses:T]]=[[Γ⊢s:T]].
Remark 18.
The example above illustrates the fact that for a call-by-value semantics allowing divergence, e.g. in the category ωCPO⊥, a conditionally branching structure can never be idempotent, and [[Γ⊢ifpthenselses:T]]=[[Γ⊢s:T]] will not hold. It is however also worth noting that even in a call-by-name semantics (where f⊥=⊥ needn’t hold), guards behave in a call-by-value way. Specifically, the call-by-name small-step operational semantics of an if-then-else statement forces the evaluation of the guard and only starts evaluating one of the branches if the guard evaluates to true or false (in particular it is short-circuiting). This means that if the guard diverges, so does the entire if-then-else statement, in contrast with f⊥=⊥ in general. The idempotence of a conditionally branching structure is thus prevented by partiality, no matter what the evaluation strategy is.
Proposition 19.
The conditionally branching structure of (17) is short-circuiting in any copy-discard category C where the following diagram is a pullback:
This result does not require the copy-discard category to be Markov. In the Cartesian case it is a special case of [18, (4.4)] and therefore holds more generally in any effectus [18, §4]. Effectful Computations interpreted in the Kleisli categories CT of monads T:C→C provide a rich collection of examples of conditionally branching structures given by (17). Let us start by examining when CT is distributive monoidal – the prerequisite for Definition 5 – assuming that C is. First, CT always has coproducts when the base category C does, with inclusions given by ηT∘in1,ηT∘in2 and copairings A+B→TC built in the base category. To define a monoidal structure on CT we start by recalling that a left strength for a monad T on (C,⊗,I) is a natural transformation strA,B:A⊗TB→T(A⊗B) satisfying axioms found in e.g. [21, 27]. If C has a symmetry transformation γA,B:A⊗B→B⊗A, we can define the right strength strA,B′=T(γB,A)∘strB,A∘γTA,B:TA⊗B→T(A⊗B). Finally, a monad with a left strength is commutative whenever the following diagram commutes:
The transformation TA⊗TB→T(A⊗B) makes T a monoidal monad (there is a one-to-one correspondence between commutative monads and symmetric monoidal monads [21, 11]). It follows that the Kleisli category of a commutative monad on a symmetric monoidal category is symmetric monoidal in a canonical way [30, Cor. 4.3]. Finally, it is not hard to check that:
Proposition 20.
If (C,⊗,I,+) is a symmetric distributive monoidal category and T:C→C is a commutative monad, then CT is symmetric distributive monoidal with the distributivity maps given by the C-morphisms ηT∘ldistr and ηT∘rdistr.
With this in place, we can apply the copy-and-distribute approach to defining conditionally branching structures on Kleisli categories. Assuming that (C,⊗,I,copy) is a distributive copy category and that T is commutative, we can define copy morphisms on CT by post-composition with the unit: ηXT∘copyX:X→T(X⊗X). This gives us a commutative conditionally branching structure on CT via (17) and Theorem 13. After some simplifications the choice function associated with a CT-predicate p:X→I+I is explicitly given by
The question of the conditionally branching structure’s idempotence is once again more subtle and we require quite a bit more structure on the base category and on the monad to establish it. This question is discussed in some detail in [19, §5] where idempotence is called side-effect-freeness and the monoidal structure is given by the Cartesian product and the terminal object. We generalise this discussion to the monoidal case. Recall that a monad on a category C with a terminal object 1 is called affine if T1≃1.
Theorem 21 ([14]).
Let C be a Markov category, and let T be a commutative monad on C that is also affine. Then the Kleisli category CT is also a Markov category where deleting is given by delAT=delA:A→1≃T1.
Corollary 22.
Let C be a Markov category, and let T be a symmetric monoidal affine monad on C, then the conditionally branching structure defined in (18) is idempotent.
Most useful monads are not affine, and therefore do not support an idempotent conditionally branching structure. We can however prove idempotence for pure tests (tests factoring through the unit ηT), whenever the base category is idempotent conditionally branching.
Theorem 23.
Let C be an idempotent conditionally branching category, and T:C→C be a monad with unit ηT. For pure tests ηT∘p:X→I+I→T(I+I), the branching morphisms
\choX(p)=ηX+XT∘\choX(p):X→X+X→T(X+X)
satisfy axioms (1)-(3) of Definition 5.
4.2 Categories of Vector Spaces
In this section we present a second class of categories with a conditionally branching structure, this time based on the ability to define choice functions as ‘splitting morphisms’.
Probabilistic Program Semantics. We start with our motivating example and prove the existence of a conditionally branching structure for a large class of real Banach spaces which includes the denotation of types in [22]. The intuition behind the construction is that a predicate p:X→R⊕R defines a linear functional evp:∇R∘p:X→R. Using a generalisation of the Radon-Nikodym theorem, one can compute the ‘densities’ of the true and false components π1∘p,π2∘p w.r.t. evp, and use these to split any positive input vector.
Theorem 24.
Let X be a σ-order complete ordered Banach space and let p:X→R⊕R be a norm-preserving σ-order continuous positive operator. For any 0≤x∈X there exist 0≤xt,xf∈X s.th.
x=xt+xf
x↦(xt,xf) defines a positive linear operator \choX:X→X⊕X
\choX satisfies the axioms (1)-(4) of Definition 5 and is short-circuiting
If X is an AL-space, then ∥xt∥=π1∘p(x) and ∥xf∥=π2∘p(x)
This result generalises the semantics of [22] to arbitrary probabilistic guards (and corrects an erroneous splitting in [10]). For a deterministic guard f∗:M(X1×…×Xn)→M(1+1) and an input distribution μ we recover the split μ↦(\mathbbm1f−1(0)⋅μ,\mathbbm1f−1(1)⋅μ), where f⋅μ is the measure with density f w.r.t. to μ. For an arbitrary guard we get the split μ↦(fif⋅μ,felse⋅μ) where fif(x1,…,xn)=p(δx1⊗…⊗δxn)(1), the probability of ‘true’ at (x1,…,xn), and similarly for felse. Thus [[flip\nicefrac12]]:M(X1×…×Xn)→M(1+1) yields μ↦(\nicefracμ2,\nicefracμ2).
Measurement-based quantum control can be understood as an instance of our main if-then-else rule (2) interpreted by a conditionally branching structure on the category CPM⊕ provided by the notion of Lüders instrument [25]. Given a predicate p:X→C⊕C, we can define two operators X→X via Ip=p†π1p and Ep=p†π2p where p† is the adjoint of p and πi:C⊕C→C⊕C is the projection onto the ith component. The notion of Lüders instrument then provides us the splitting map \choX(p):X→X⊕X,ρ↦(IpρIp,EpρEp). With this, we can revisit Example 4 and type the program as
The instrument corresponding to meas(x) is given by the projections Imeas(x)=∣0⟩⟨0∣ and Emeas(x)=∣1⟩⟨1∣ yielding the semantics [[ifmeas(x)thenx⊗yelsex⊗Zy]] given by (3):
The key difference with the semantics of § 2.2 is that the qubit x remains accessible (in its collapsed state) to the computation. The guard modifies its context, it does not consume it.
Remark 25.
The construction above relies on the fact that Hilbert spaces are self-dual. With some care one can build adjoint pairs between L1(X,μ) and L∞(X,μ) for a measured space (X,μ) [12]. The construction above can then be applied to probabilistic semantics involving measured spaces, e.g. spaces with a prior [10]. In that case, Ip would condition on observing ‘true’ (w.r.t. a prior μ), relating conditional branching with probabilistic conditioning.
Coherent quantum control can also be understood as an instance of rule (2) interpreted via a conditionally branching structure, but unfortunately not in the same category as above (CPM⊕ is in some sense designed to tackle measurements). Consider the category Hilb of finite-dimensional Hilbert spaces and bounded operators (we cannot restrict to contractions as coproducts would then not exist). We interpret coherent control in this category in much the same way as we did above: given p:X→C⊕C, define Ip,Ep as above and the choice functions \choX(p):X→X⊕X as x↦(Ipx,Epx). With this ‘instrument’ we can interpret the CNOT gate represented as the program
where we tacitly use the trivial/identity test x:qubit⊢x:bit which exploits the fact that [[qubit]]=[[bit]]=C2 in Hilb. The semantics is then given by [id⊗id,id⊗[[not]]]∘⟨Ip,Ep⟩ that splits a00∣00⟩+a01∣01⟩+a10∣10⟩+a11∣11⟩ into (a00∣00⟩+a01∣01⟩,a10∣10⟩+a11∣11⟩) and then applies both branches in superposition to yield a00∣00⟩+a01∣01⟩+a10∣11⟩+a11∣10⟩ as expected. Note that unlike (12), the context of the guard is shared with the branches.
Proposition 26.
The choice functions defined above define a commutative and idempotent conditionally branching structure on Hilb for sharp predicates, i.e. predicates satisfying im(Ip)=ker(Ep).
Remark 27.
Unifying the two types of control semantically is notoriously difficult [37]. Hilb cannot deal with measurements and, conversely, applying the Lüders instrument of CPM⊕ to coherent control yields the wrong semantics, e.g. in the CNOT case it would ignore the cross-terms B,C. We settle for the structural unification provided by (2) and (3).
5 Structure of branching morphisms and tests
Having defined conditionally branching categories as a simple categorical structure in which to interpret if-then-else statements via ‘branching morphisms’, we now turn our attention to studying the algebraic structure of branching morphisms and of tests in a conditionally branching category.
5.1 Structure of the sets C(X,X+X) of branching morphisms
In § 3 we defined three special morphisms: \strueX,\sfalseX,\snotX:X+X→X+X which can be viewed as defining unary operations on C(X,X+X) by post-composition. We can also define two constants on C(X,X+X): ⊤X=in1:X→X+X and ⊥X=in2:X→X+X. What about binary operations on branching morphisms? Such operations seem essential if we are to understand nested if-then-else statements branching from X to X+X+X+X.
If we view branching morphisms X→X+X as morphisms X→TX for the functor T=Id+Id and manage to equip T with a monad structure, then this would also equip the set C(X,X+X) – viewed as the set CT(X,X) – with an operation for combining nested branchings. To see which monad structures on T=Id+Id are useful, we list all such structures in the case of the category Set.
Theorem 28.
The following unit-multiplication pairs define monad structures on the functor T=Id+Id in any category with coproducts.
η=in1,μ=[id,\snot]
η=in1,μ=∧
η=in2,μ=[\snot,id]
η=in2,μ=∨
In Set these are the only possible monad structures on T.
It follows that C(X,X+X) can always be equipped with four monoidal structures. For f,g∈C(X,X+X) we write f∧g for the branching morphism ∧∘(g+g)∘f (we drop subscripts in the interest of clarity), and similarly for ∨. For branching morphisms generated by tests in a conditionally branching category ∨,∧ have the following algebraic structure.
Proposition 29.
For any tests p,q,r:X→I+I in a conditionally branching category,
If the conditionally branching structure is idempotent then
⊤∨\cho(p)=\cho(p)∨⊤=⊤
⊥∧\cho(p)=\cho(p)∧⊥=⊥
If the conditionally branching structure is commutative then
\cho(p)∨\cho(q)=\cho(q)∨\cho(p)
\cho(p)∧\cho(q)=\cho(q)∧\cho(p)
Remark 30.
Since \snot is involutive and relates ∨ and ∧ via de Morgan laws, ∧ can be defined in terms of ∨ and vice-versa. The basic structure (items 1-5) of branching morphisms is thus that of an involutive magma. It is tempting to assume that the operators ∨ and ∧ satisfy other boolean identities. Probabilistic computations provides some easy counter-examples. Let p,q,r:X→D(1+1) be probabilistic tests and let us write p for p(x)(1).
\cho(p)∧\cho(p)=\cho(p) doesn’t hold since it would imply pp=p which isn’t generally true.
Similarly, \cho(p)∨\cho(p)=\cho(p) doesn’t hold since it would imply (1−p)(1−p)=(1−p).
\cho(p)∨\cho(\snotp)=⊤ and \cho(p)∧\cho(\snotq)=⊥ do not hold since p(1−p)=0 in general.
\cho(p)∧(\cho(q)∨\cho(r))=(\cho(p)∧\cho(q))∨(\cho(p)∧\cho(r)) does not hold as it would imply that p(1−(1−q)(1−r))=pqpr+pr(1−pr)+(1−pq)pr which does not hold in general. The other distributivity laws similarly does not hold.
5.2 Structure of the sets C(X,I+I) of predicates
We can use the conditionally branching structure on a category C to define binary operations on the set of tests C(X,I+I) as follows. For p,q:X→I+I, we overload ∨,∧ and define:
p∨q≜∨∘(q+q)∘\choX(p)p∧q≜∧∘(q+q)∘\choX(p)
With these operations we recover part of a familiar algebraic structure on sets of predicates.
Proposition 31.
Predicates on an object X in a conditionally branching category form an involutive magma (C(X,I+I),∧,\snot) (resp. (C(X,I+I),∨,\snot)). If the conditionally branching structure is commutative, so is ∧ (resp. ∨).
Example 32 (The boolean algebra of non-deterministic tests).
Consider finitely branching non-deterministic computations given by the finite powerset monad Pf on Set. The corresponding choice functions are given by (18). It is straightforward to compute (19)-(20) and we get for p,q:X→Pf(1+1) that 1∈(p∨q)(x)⇔1∈p(x)∪q(x) and 1∈(p∧q)(x)⇔1∈p(x)∩q(x), and dually for 2 (i.e. false) 2∈(p∨q)(x)⇔2∈p(x)∩q(x) and 2∈(p∧q)(x)⇔2∈p(x)∪q(x).
Example 33 (The involutive magma of probabilistic tests).
Consider now finitely branching probabilistic computations given by the distribution monad D on Set, again with the choice functions defined by (18). Given probabilistic tests p,q:X→D(1+1), we compute
Thus probabilistic tests carry the standard probabilistic structure on [0,1] (sometimes know as product t-norm and sum t-conorm in fuzzy logic, pointwise, when evaluated at 1, and the dual structure when evaluated at 2.
By Definition 5, choice functions \choX:C(X,I+I)→C(X,X+X) always commute with the unary operators \strue,\snot. In some instance we can also prove that they act as monoid homomorphisms between the ∨- and ∧-structures described in Propositions 29 and 31.
Proposition 34.
If \choX(p∨q)=\choX(p)∨\choX(q) and \choX(p∧q)=\choX(p)∧\choX(q) then both (C(X,I+I),∧,\snot) and (C(X,I+I),∨,\snot) form involutive magmas. If the conditionally branching structure is commutative, they are also commutative. This holds for the conditionally branching structures defined by (17).
Not all the structure of C(X,X+X) can carry over to C(X,I+I). The constant branching morphisms ⊤,⊥ have in general no test equivalents since there is in general no distinguished morphism X→I; some objects in Ban for example have no such morphisms.
5.3 Skew-associativity
When the structure on the set of tests is sufficiently rich, we can generalise the skew-associativity rule of GKAT to more general types of computations. The extra structure needed is the following. We define the relation ≲ on (C(X,I+I),∧) by p≲q⇔∃r:p=q∧r. The relation is transitive whenever ∧ is associative, i.e. whenever (C(X,I+I),∧) is a magma. We will say that (C(X,I+I),∧) is conditionally divisible if for all tests p,q∈C(X,I+I) such that p≤q there exists a test qp∈C(X,I+I) such that q∧qp=p.
Interestingly, we will need the same technical condition on the base category C as made in [18, Eq. (4.3)], namely that the maps [idX,∇X],[\snotX,idX]:X+X+X→X+X are jointly monic. This condition is satisfied in Set and therefore in any concrete category.
Theorem 35.
Let C be a conditionally branching category satisfying the condition above and the identities of Proposition 34. Whenever (C(X,1+1),∧) is conditionally divisible and p∧\snotq≲\snot(p∧q) we have:
It is straightforward to check that the previous theorem implies that if the tests p∧q and \snot(p∧q)p∧\snotq can be realised as the semantics of programs p&q and p∙q then the following generalisation of GKAT’s skew-associativity rule holds:
The (pointwise) boolean structure on non-deterministic tests is conditionally divisible. The relation ≲ is the standard lattice order, we trivially have that p∧\snotq≲\snot(p∧q), and we can take \snot(p∧q)p∧\snotq=((\snot(p∧q)→p∧\snotq) which is just equivalent to p and recover exactly the skew-associativity of GKAT stated in § 3.
Example 37.
The (pointwise) involutive magma structure of probabilistic tests is conditionally divisible. The relation ≲ is the standard order on [0,1], we trivially have p(1−q)≤(1−pq), and we take \snot(p∧q)p∧\snotq=(1−pq)p(1−q) (with the convention that 00=0, no other zeroes in the denominator are possible by definition of conditional divisibility). We then recover the skew-associativity rule of barycentric algebras discussed in e.g. [26]:
(e+qf)+pg=epq(f+1−pqp−pqg)
6 Conclusion
We have surveyed several inequivalent semantics for conditional branching found in the literature, covering a range of computational paradigms (classical, effectful, probabilistic, quantum). We saw that even in linear (i.e. resource-sensitive) semantics, such as those of probabilistic, quantum or effectful computations, it is possible to interpret non-linear if-then-else statements whose guards do not consume their context, cf. typing rule (2). The variety of existing semantics begs the question: is there a unifying ‘minimal’ structure required to interpret the if-then-else rule (2)?
To answer this question we have focused on the central construct required to interpret conditional branching, the coproduct. Fundamentally, this is the structure that allows us to combine the interpretations of the if-branch and of the else-branch into a single program. The question is then to construct a branching behaviour into this coproduct based on a guard. This is where we introduce our notion of conditionally branching category, a monoidal distributive category equipped with a way of turning guards – i.e. predicates – into branching behaviours. Our definition echoes that of traced monoidal category and is ‘minimal’ in the sense that it is as parsimonious as possible, with only two combinatorially obvious requirements enforcing the equivalences ifpthenselset≡ifnotpthentelses and iftruethenselset≡s. These are purely combinatorial in the sense that they refer only to the basic combinatorial properties of the coproduct (via the maps \snot,\strue:I+I→I+I). Additional program equivalences follow from additional demands on the conditionally branching structure (e.g. idempotence, commutativity).
We have shown that a wide range of semantically important categories possess canonical conditionally branching structures, and in particular categories supporting the two types of branching found in quantum computing: measurement-based control and coherent control. It would be nice to find a category that could cover both at the same time, either through a unifying conditionally branching structure, or through two dedicated conditionally branching structures (but defined on the same category).
We have also shown that a conditionally branching structure gives rise to algebraic structures on sets C(X,X+X) of branching morphisms and on sets C(X,I+I) of predicates. The richness of these structures depends on the requirements put on the conditionally branching structure, but in most cases, we obtain an involutive magma. For non-deterministic and probabilistic computations, we recover know structures and show program equivalences for nested branching corresponding to the skew-associativity rules of GKAT and barycentric algebras respectively. We believe that a lot more can be said about the structure of predicates in conditionally branching categories, both in general and in interesting special cases.
References
[1] J. Adámek, S. Milius, and J. Velebil (2006) Iterative algebras at work. Mathematical Structures in Computer Science 16 (6), pp. 1085–1131. Cited by: §3.
[2] J. Adámek, S. Milius, and J. Velebil (2009) Elgot theories: a new perspective of iteration theories. Electronic Notes in Theoretical Computer Science 249, pp. 407–427. Cited by: §3.
[3] C. D. Aliprantis and K. C. Border (2006) Infinite dimensional analysis: a hitchhiker’s guide. Springer. Cited by: 1st item, 3rd item, 4th item, Appendix B.
[4] C. D. Aliprantis and O. Burkinshaw (2006) Positive operators. Vol. 119, Springer Science & Business Media. Cited by: 3rd item, 3rd item, 3rd item, Appendix B.
[5] T. Altenkirch, J. Grattage, J. K. Vizzotto, and A. Sabry (2007) An algebra of pure quantum programming. Electronic Notes in Theoretical Computer Science 170, pp. 23–47. Cited by: §2.4, §2.4.
[6] T. Altenkirch and J. Grattage (2005) A functional quantum programming language. In 20th Annual IEEE Symposium on Logic in Computer Science (LICS’05), pp. 249–258. Cited by: §2.4.
[7] M. Barr and C. Wells (1990) Category theory for computing science. Vol. 1, Prentice Hall New York. Cited by: Example 1.
[8] K. Cho and B. Jacobs (2019) Disintegration and bayesian inversion via string diagrams. Mathematical Structures in Computer Science 29 (7), pp. 938–971. Cited by: §4.1.
[9] J. R. B. Cockett and S. Lack (2002) Restriction categories i: categories of partial maps. Theoretical computer science 270 (1-2), pp. 223–259. Cited by: §4.1.
[10] F. Dahlqvist and D. Kozen (2020) Semantics of higher-order probabilistic programs with conditioning. In Proc. 47th ACM SIGPLAN Symp. Principles of Programming Languages (POPL’20), New Orleans, pp. 57:1–29. Cited by: §1, §4.2, Remark 25.
[11] F. Dahlqvist, L. Parlant, and A. Silva (2018) Layer by layer–combining monads. In Theoretical Aspects of Computing–ICTAC 2018: 15th International Colloquium, Stellenbosch, South Africa, October 16–19, 2018, Proceedings 15, pp. 153–172. Cited by: §4.1.
[12] F. Dahlqvist, A. Silva, V. Danos, and I. Garnier (2018) Borel kernels and their approximation, categorically. Electronic Notes in Theoretical Computer Science 341, pp. 91–119. Cited by: Remark 25.
[13] C. C. Elgot (1975) Monadic computation and iterative algebraic theories. In Studies in Logic and the Foundations of Mathematics, Vol. 80, pp. 175–230. Cited by: §3.
[14] T. Fritz (2020) A synthetic approach to markov kernels, conditional independence and theorems on sufficient statistics. Advances in Mathematics 370, pp. 107239. Cited by: §1, §4.1, Theorem 13, Example 15, Theorem 21.
[15] J. Gibbons (1997) Conditionals in distributive categories. Technical report CMS-TR-97-01, School of Computing and Mathematical Sciences, Oxford Brookes. Cited by: §1, §2.1.
[16] M. Hasegawa (2004) The uniformity principle on traced monoidal categories. Publications of the Research Institute for Mathematical Sciences 40 (3), pp. 991–1014. Cited by: §3.
[17] C. Heunen, R. Kaarsgaard, and L. Lemonnier (2025) One rig to control them all. arXiv preprint arXiv:2510.05032. Cited by: §2.4.
[18] B. Jacobs (2015) New directions in categorical logic, for classical, probabilistic and quantum logic. Logical Methods in Computer Science 11. Cited by: §1, §2.1, §3, §3, §4.1, §5.3.
[19] B. Jacobs (2016) Affine monads and side-effect-freeness. In Coalgebraic Methods in Computer Science: 13th IFIP WG 1.3 International Workshop, CMCS 2016, Colocated with ETAPS 2016, Eindhoven, The Netherlands, April 2-3, 2016, Revised Selected Papers 13, pp. 53–72. Cited by: §2.1, §3, §4.1.
[20] G. M. Kelly (1982) Basic concepts of enriched category theory. Vol. 64, CUP Archive. Cited by: Appendix C.
[21] A. Kock (1972) Strong functors and monoidal monads. Archiv der Mathematik 23, pp. 113–120. Cited by: §4.1, §4.1.
[22] D. Kozen (1979) Semantics of probabilistic programs. In Proc. 20th Symp. Found. Comput. Sci., pp. 101–114. Cited by: §1, §1, §2.3, §3, §4.2, §4.2.
[23] D. Kozen (1985) A probabilistic PDL. J. Comput. Syst. Sci. 30 (2), pp. 162–178. Cited by: §1.
[24] D. Kozen (1997) Kleene algebra with tests. ACM Transactions on Programming Languages and Systems (TOPLAS) 19 (3), pp. 427–443. Cited by: §1, §3.
[25] G. Lüders (2006) Concerning the state-change due to the measurement process. Annalen der Physik 518 (9), pp. 663–670. Cited by: §3, §4.2.
[26] R. Mardare, P. Panangaden, and G. Plotkin (2016) Quantitative algebraic reasoning. In Proceedings of the 31st Annual ACM/IEEE Symposium on Logic in Computer Science, pp. 700–709. Cited by: §1, Example 37.
[27] E. Moggi (1991) Notions of computation and monads. Information and computation 93 (1), pp. 55–92. Cited by: §1, §2.1, §4.1.
[28] M. Pagani, P. Selinger, and B. Valiron (2014) Applying quantitative semantics to higher-order quantum computing. In Proceedings of the 41st ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, pp. 647–658. Cited by: §1, §2.2, Example 4.
[29] B. C. Pierce (2002) Types and programming languages. MIT press. Cited by: §3.
[30] J. Power and E. Robinson (1997) Premonoidal categories and notions of computation. Mathematical structures in computer science 7 (5), pp. 453–468. Cited by: §4.1.
[31] P. Selinger and B. Valiron (2006) A lambda calculus for quantum computation with classical control. Mathematical Structures in Computer Science 16 (3), pp. 527–552. Cited by: Example 4.
[32] P. Selinger B. Valiron et al. (2009) Quantum lambda calculus. Semantic techniques in quantum computation, pp. 135–172. Cited by: Example 4.
[33] P. Selinger (2004) Towards a semantics for higher-order quantum computation. In Proceedings of the 2nd International Workshop on Quantum Programming Languages, TUCS General Publication, Vol. 33, pp. 127–143. Cited by: Example 4.
[34] S. Smolka, N. Foster, J. Hsu, T. Kappé, D. Kozen, and A. Silva (2020) Guarded Kleene algebra with tests: verification of uninterpreted programs in nearly linear time. In Proc. 47th ACM SIGPLAN Symp. Principles of Programming Languages (POPL’20), New Orleans, pp. 61:1–28. Cited by: §1, §3, footnote 1, footnote 2.
[35] M. B. Smyth and G. D. Plotkin (1982) The category-theoretic solution of recursive domain equations. SIAM Journal on Computing 11 (4), pp. 761–783. Cited by: Example 2.
[36] S. Staton (2017) Commutative semantics for probabilistic programming. In Programming Languages and Systems: 26th European Symposium on Programming, ESOP 2017, Held as Part of the European Joint Conferences on Theory and Practice of Software, ETAPS 2017, Uppsala, Sweden, April 22–29, 2017, Proceedings 26, pp. 855–879. Cited by: §2.2.
[37] B. Valiron (2022) Semantics of quantum programming languages: classical control, quantum control. Journal of Logical and Algebraic Methods in Programming 128, pp. 100790. Cited by: §2.4, Remark 27, Example 4.
[38] A. C. Zaanen (2012) Introduction to operator theory in riesz spaces. Springer Science & Business Media. Cited by: Appendix B.
Appendix A Proofs for Section 3
Lemma 38.
The following diagram commutes in any distributive category
Skew-commutativity follows from the commutativity of this diagram: \textstyle{\llbracket\Gamma\rrbracket\otimes\llbracket\Delta\rrbracket\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\cho_{\llbracket\Gamma\rrbracket}(\llbracket p\rrbracket)\otimes\mathrm{id}_{\llbracket\Delta\rrbracket}}$$\scriptstyle{\cho_{\llbracket\Gamma\rrbracket}(\snot p)\otimes\mathrm{id}_{\llbracket\Delta\rrbracket}}$$\textstyle{(\llbracket\Gamma\rrbracket+\llbracket\Gamma\rrbracket)\otimes\Delta\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\mathrm{rdistr}}$$\scriptstyle{\snot_{\llbracket\Gamma\rrbracket}\otimes\mathrm{id}_{\llbracket\Delta\rrbracket}}$$\textstyle{\llbracket\Gamma\rrbracket\otimes\llbracket\Delta\rrbracket+\llbracket\Gamma\rrbracket\otimes\llbracket\Delta\rrbracket\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{~~~\snot_{\llbracket\Gamma\rrbracket\otimes\llbracket\Delta\rrbracket}}$$\scriptstyle{[\llbracket s\rrbracket,\llbracket t\rrbracket]}$$\textstyle{(\llbracket\Gamma\rrbracket+\llbracket\Gamma\rrbracket)\otimes\llbracket\Delta\rrbracket\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\mathrm{rdistr}}$$\textstyle{\llbracket\Gamma\rrbracket\otimes\llbracket\Delta\rrbracket+\llbracket\Gamma\rrbracket\otimes\llbracket\Delta\rrbracket\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{[\llbracket t\rrbracket,\llbracket s\rrbracket}$$\textstyle{\llbracket\mathtt{T}\rrbracket} where the left-hand triangle commutes by the skew-commutativity axiom. The bottom right-hand triangle commutes trivially and the central square can also be seen to commute by considering the inverse of rdistr, namely [in1⊗id[[Δ]],in2⊗id[[Δ]]].
The proof for the true test is the essentially the same of the previous case but with \snot replaced by \strue.
Idempotence follows from the commutativity of the following diagram \textstyle{\llbracket\Gamma\rrbracket\otimes\llbracket\Delta\rrbracket\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\cho_{\llbracket\Gamma\rrbracket}(\llbracket p\rrbracket)\otimes\mathrm{id}_{\llbracket\Delta\rrbracket}}$$\textstyle{(\llbracket\Gamma\rrbracket+\llbracket\Gamma\rrbracket)\otimes\Delta\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\mathrm{rdistr}}$$\scriptstyle{\nabla_{\llbracket\Gamma\rrbracket}\otimes\mathrm{id}_{\llbracket\Delta\rrbracket}}$$\textstyle{\llbracket\Gamma\rrbracket\otimes\llbracket\Delta\rrbracket+\llbracket\Gamma\rrbracket\otimes\llbracket\Delta\rrbracket\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{~~~\nabla_{\llbracket\Gamma\rrbracket\otimes\llbracket\Delta\rrbracket}}$$\scriptstyle{[\llbracket s\rrbracket,\llbracket s\rrbracket]}$$\textstyle{\llbracket\Gamma\rrbracket\otimes\llbracket\Delta\rrbracket\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\llbracket s\rrbracket}$$\textstyle{\llbracket\mathtt{T}\rrbracket} The left-hand triangle commutes by virtue of the idempotence axiom. The top triangle of the right-hand square commutes by Lemma 38, the bottom one commutes trivially.
Commutativity follows immediately from the definitions.
∎
Proof of Proposition 7.
The morphism [[Γ,Δ⊢ifpthenletx=s1intelseletx=s2int:T]] is given by the top path of the diagram below whilst the morphism [[Γ′,Δ′⊢letx=(ifpthens1elses2)int:T]] follows the path below it. Commutativity follows directly from the definitions.
To simplify the notation we will often omit the right unitors in what follows and consider X and X⊗I interchangeably.
Skew-commutativity: This identity holds by virtue of the definition of \choX and the commutativity of the following diagram: \textstyle{X\otimes(I+I)\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\mathrm{id}_{X}\otimes\snot}$$\scriptstyle{\mathrm{ldistr}_{X}}$$\textstyle{X+X\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\snot_{X}=[\mathrm{in}_{2},\mathrm{in}_{1}]}$$\scriptstyle{[\mathrm{id}_{X}\otimes\mathrm{in}_{1},\mathrm{id}_{X}\otimes\mathrm{in}_{2}]}$$\textstyle{X\otimes(I+I)\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\mathrm{ldistr}_{X}}$$\textstyle{X+X\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{[\mathrm{id}_{X}\otimes\mathrm{in}_{1},\mathrm{id}_{X}\otimes\mathrm{in}_{2}]} which holds since [idX⊗in1,idX⊗in2]∘\snotX∘in1=[idX⊗in1,idX⊗in2]∘in2=idX⊗in2=(idX⊗\snot)∘(idX⊗in1)=(idX⊗\snot)∘[idX⊗in1,idX⊗in2]∘in1 and similarly for the pre-composition with in2. The commutativity of the square with left-to-right horizontal arrows now follows by the universal property of the coproduct, and the commutativity of the square with right-to-left horizontal arrows follows from the fact that the horizontal arrows are inverse of one another.
True test: This identity can be shown to hold in the same way as the previous one. Consider the diagram \textstyle{X\otimes(I+I)\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\mathrm{id}_{X}\otimes\strue}$$\scriptstyle{\mathrm{ldistr}_{X}}$$\textstyle{X+X\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\strue_{X}=[\mathrm{in}_{1},\mathrm{in}_{1}]}$$\scriptstyle{[\mathrm{id}_{X}\otimes\mathrm{in}_{1},\mathrm{id}_{X}\otimes\mathrm{in}_{2}]}$$\textstyle{X\otimes(I+I)\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\mathrm{ldistr}_{X}}$$\textstyle{X+X\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{[\mathrm{id}_{X}\otimes\mathrm{in}_{1},\mathrm{id}_{X}\otimes\mathrm{in}_{2}]} We have [idX⊗in1,idX⊗in2]∘\strueX∘in1=[idX⊗in1,idX⊗in2]∘in1=idX⊗in1=(idX⊗\strue)∘(idX⊗in1)=(idX⊗\strue)∘[idX⊗in1,idX⊗in2]∘in1 and similarly for the pre-composition with in2. The result follows as in the previous case.
Commutativity: The proof hinges on the commutativity of the following diagram connecting distributivity, the symmetry transformations γA,B:A⊗B→B⊗A of the symmetric monoidal category, and the permutation [in1,in3,in2,in4] of the commutativity definition \textstyle{A\otimes C+B\otimes C+A\otimes D+B\otimes D\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{[\mathrm{in}_{1}\otimes\mathrm{in}_{1},\mathrm{in}_{2}\otimes\mathrm{in}_{1},\mathrm{in}_{2}\otimes\mathrm{in}_{1},\mathrm{in}_{2}\otimes\mathrm{in}_{2}]}$$\scriptstyle{=(\mathrm{rdistr}+\mathrm{rdistr}\circ\mathrm{ldistr})^{-1}}$$\scriptstyle{[\mathrm{in}_{1}\circ\gamma,\mathrm{in}_{3}\circ\gamma,\mathrm{in}_{2}\circ\gamma,\mathrm{in}_{4}\circ\gamma]}$$\textstyle{C\otimes A+D\otimes A+C\otimes B+D\otimes B\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{(\mathrm{rdistr}+\mathrm{rdistr}\circ\mathrm{ldistr})^{-1}}$$\textstyle{(A+B)\otimes(C+D)\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\gamma_{(A+B),(C+D)}}$$\textstyle{(C+D)\otimes(A+B)} The commutativity of this diagram can be checked straightforwardly by examining each summand of the top-left-hand corner individually and using the universal property of coproducts. This establishes the commutativity of the central square in the following diagram \textstyle{X\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\mathrm{copy}_{X}}$$\scriptstyle{\mathrm{copy}_{X}}$$\textstyle{X\otimes X\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\gamma}$$\scriptstyle{q\otimes p}$$\scriptstyle{\mathrm{id}\otimes p}$$\textstyle{X\otimes X\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{p\otimes q}$$\scriptstyle{\mathrm{id}\otimes q}$$\textstyle{X\otimes(I+I)\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\mathrm{ldistr}}$$\scriptstyle{q\otimes\mathrm{id}}$$\textstyle{(I+I)\otimes(I+I)\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\gamma}$$\scriptstyle{\mathrm{ldistr}}$$\textstyle{(I+I)\otimes(I+I)\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\mathrm{ldistr}}$$\textstyle{X\otimes(I+I)\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\mathrm{rdistr}}$$\scriptstyle{p\otimes\mathrm{id}}$$\textstyle{(X\otimes I)+(X\otimes I)\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{(q\otimes\mathrm{id})+(q\otimes\mathrm{id})}$$\scriptstyle{\rho_{X}+\rho_{X}}$$\textstyle{(I+I)\otimes I+(I+I)\otimes I\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\mathrm{rdistr}+\mathrm{rdistr}}$$\textstyle{(I+I)\otimes I+(I+I)\otimes I\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\mathrm{rdistr}+\mathrm{rdistr}}$$\textstyle{(X\otimes I)+(X\otimes I)\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{(p\otimes\mathrm{id})+(p\otimes\mathrm{id})}$$\scriptstyle{\rho_{X}+\rho_{X}}$$\textstyle{X+X\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{q+q}$$\textstyle{I\otimes I+I\otimes I+I\otimes I+I\otimes I\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{[\mathrm{in}_{1},\mathrm{in}_{3},\mathrm{in}_{2},\mathrm{in}_{4}]}$$\scriptstyle{[\rho,\rho]+[\rho,\rho]}$$\textstyle{I\otimes I+I\otimes I+I\otimes I+I\otimes I\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{[\rho,\rho]+[\rho,\rho]}$$\textstyle{X+X\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{p+p}$$\textstyle{I+I+I+I\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{[\mathrm{in}_{1},\mathrm{in}_{3},\mathrm{in}_{2},\mathrm{in}_{4}]}$$\textstyle{I+I+I+I} The left- and right-hand pentagons can be seen to commute by showing [ρI,ρI]∘rdistr=ρI+I using the definition of rdistr as the inverse of the canonical morphism and then applying naturality of the unitor. The result now follows immediately.
Short-circuiting. Assume that \textstyle{I\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{s}$$\scriptstyle{h}$$\textstyle{X\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{p}$$\textstyle{I\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\mathrm{in}_{i}}$$\textstyle{I+I} with s deterministic. Now consider the following diagram; \textstyle{I\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{s}$$\scriptstyle{\mathrm{copy}_{I}}$$\textstyle{X\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\mathrm{copy}_{X}}$$\scriptstyle{\cho_{X}(p)}$$\textstyle{I\otimes I\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{s\otimes s}$$\scriptstyle{s\otimes h}$$\textstyle{X\otimes X\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\mathrm{id}\otimes p}$$\textstyle{X\otimes I\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\mathrm{id}\otimes\mathrm{in}_{i}}$$\scriptstyle{\mathrm{in}_{i}}$$\textstyle{X\otimes(I+I)\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\mathrm{ldistr}_{X}}$$\textstyle{(X\otimes I)+(X\otimes I)\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\textstyle{X\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\mathrm{in}_{i}}$$\textstyle{X+X} The top square commutes by definition of deterministic morphisms. The bottom triangle is seen to commute by using the fact that ldistrX is the inverse of [id⊗in1,id⊗in2].
Idempotence: We now assume a Markov category, in particular I=1 is terminal. As the following diagram shows, it follows from the universal property of the coproduct that (idX⊗∇1)∘[idX⊗in1,idX⊗in2]=∇X: \textstyle{X\otimes I}$$\textstyle{X\otimes(I+I)\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\mathrm{id}_{X}\otimes\nabla_{1}}$$\textstyle{X\otimes I\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\mathrm{in}_{1}}$$\scriptstyle{\mathrm{id}_{X}\otimes\mathrm{id}_{I}=\mathrm{id}_{X\otimes I}}$$\textstyle{X\otimes I+X\otimes I\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{[\mathrm{id}_{X}\otimes\mathrm{in}_{1},\mathrm{id}_{X}\otimes\mathrm{in}_{2}]}$$\scriptstyle{\nabla_{X}}$$\textstyle{X\otimes I\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\mathrm{in}_{2}}$$\scriptstyle{\mathrm{id}_{X}\otimes\mathrm{id}_{I}=\mathrm{id}_{X\otimes I}} We now have (ignoring the trivial role of the right unitor X⊗I≃X) ∇X∘\choX(p)=(idX⊗∇1)∘[idX⊗in1,idX⊗in2]∘\choX(p)=(idX⊗∇1)∘[idX⊗in1,idX⊗in2]∘ldistrX∘(idX⊗p)∘(copyX⊗idI)=(idX⊗∇1)∘(idX⊗p)∘(copyX⊗idI)=(idX⊗!X⊗I)∘(copyX⊗idI)≃idX⊗I where the penultimate step follows from the fact that I is terminal (and thus ∇1∘p=!X⊗I) and the last step follows from the copy-discard interaction (up to a unitor, hence the ≃).
∎
Proof of Proposition 19.
Let us first show that if a map I⟶fX+X⟶del+delI+I factors through in1:I→I+I then f factors through in1:X→X+X. By the weak pullback assumption we have a unique mediating morphism
Note that the CD-category structure is essential for the diagram above to commute ∎
Proof of Theorem 23.
The proof follows from the fact that the copairing of f:X→Z,g:Y→Z in C(T) is given by μ∘T[f,g] in the base category, and the commutativity of the following diagrams:
Skew-commutativity: \textstyle{X\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\widehat{\cho}_{X}(p)}$$\scriptstyle{\cho_{X}(\snot p)}$$\scriptstyle{\cho_{X}(p)}$$\textstyle{X+X\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\hskip 16.38895pt[T\mathrm{in}_{2}\circ\eta_{X},T\mathrm{in}_{1}\circ\eta_{X}]}$$\scriptstyle{\snot_{X}=[\mathrm{in}_{2},\mathrm{in}_{1}]}$$\scriptstyle{\eta_{X}}$$\textstyle{T(X+X)\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{T[T\mathrm{in}_{2}\circ\eta_{X},T\mathrm{in}_{1}\circ\eta_{X}]}$$\textstyle{T(X+X)\ignorespaces\ignorespaces\ignorespaces\ignorespaces]\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\eta_{T(X+X)}}$$\textstyle{T^{2}(X+X)\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\mu_{X+X}}$$\textstyle{X+X\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\eta_{X}}$$\textstyle{T(X+X)} The bottom-left triangle commutes by naturality of ηX applied to both component of the copairing. Again the right-hand-vertical path is the copairing [in2,in1], that is to say \snotX, in the category CT.
True test: The proof is the same as for skew-commutativity with \snot replaced by \strue.
Idempotence: \textstyle{X\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\widehat{\cho}_{X}(p)}$$\scriptstyle{\cho_{X}(p)}$$\textstyle{X+X\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\nabla_{X}}$$\scriptstyle{\eta_{X+X}}$$\scriptstyle{[\eta_{X},\eta_{X}]}$$\textstyle{T(X+X)\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{T[\eta_{X},\eta_{X}]}$$\textstyle{TX\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\eta_{TX}}$$\textstyle{T^{2}X\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\mu_{X}}$$\textstyle{X\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\eta_{X}}$$\textstyle{TX} Where the right-hand-side vertical path is the codiagonal morphism in CT and the bottom path the unit in CT.
∎
For the following proof we must assume some familiarity with the theory of Riesz spaces, Banach lattices and positive operators, see [3, Chapters 8,9] for a gentle introduction and [4] or [38] for a more in-depth account.
Proof of Theorem 24.
Let us write evp for the functional ∇R∘p (an evaluation functional in the probabilistic case), pt for π1∘p (which measures how true the guard is for a given vector) and pf for π2∘p. If pt=evp (and thus pf=0) then take x=xt and xf=0 and conversely if pf=evp.
Now assume that pt≜π1∘p and pf≜π2∘p are strictly positive and proceed in steps.
X is Archimedean and has the countable sup property: See [3, Thm 8.22]
X is Dedekind complete: This follows immediately from the fact that it is σ-Dedekind complete and has the countable sup property.
X has the Principal Projection Property: Let x∈X and let Bx be the principal band generated by x. For 0≤y we define the projection Px:X→Bx as follows: Px(y)=⋁{0≤u≤y∣u∈Bx}. Since 0 is certainly in the set above, and since it is bounded from above by y, the sup above exists by Dedekind-completeness. Since Bx is a band, it is closed under joins of directed sets and {0≤u≤y∣u∈Bx} is certainly a directed set of elements of Bx. It follows that Px(y)∈Bx and thus that Px2=Px, i.e. Px is a projection. To see that Px is linear let y,z∈X and note first that since Px(y),Px(z)∈Bx then Px(y)+Px(z)∈Bx, moreover Px(y)≤y and Px(z)≤z thus Px(y)+Px(z)≤y+z and thus Px(y)+Px(z)≤Px(y+z). For the other direction we use the fact that X is necessarily a Riesz space (since {u,v} is bounded above by u+v it follows that ⋁{u,v} necessarily exists) and therefore has the Riesz decomposition property: for every 0≤w≤y+z, there exists 0≤w1≤y,0≤w2≤z such that w=w1+w2. It follows that for any element w in the set defining Px(y+z) we can find a pair of elements w1,w2 in the sets defining Px(y) and Px(z) in particular w1+w2≤Px(y)+Px(z). Since this holds for every element in the set defining Px(y+z) we get Px(y+z)≤Px(y)+Px(z). Finally, we need to show that y−Px(y) is disjoint from Px(y). If 0<(y−Px(y)∧y)≤Px(y) then 0<(y−Px(y)∧y)∈Bx and thus (y−Px(y)∧y)+Px(y)∈Bx. Since (y−Px(y)∧y)+Px(y)≤y−Px(y)+Px(y)=Px(y)≤y it belongs to the set defining Px(y) but also Px(y)<(y−Px(y)∧y)+Px(y) which contradicts the definition of Px(y) as the supremum of such elements. Construction of xt and xf. Note first that pt≤evp and therefore pt belongs to the ideal Eevp generated by evp in X∼, the space of order-bounded linear functionals on X. Since R is a Dedekind-complete Riesz space, X∼ is a Dedekind-complete Riesz space [4, Thm.1.18], in particular it has the principal projection property as shown above. We therefore have all the conditions required to apply Freudenthal’s Spectral Theorem [4, Thm.2.8] to pt∈Eevp. This guarantees the existence of an increasing sequence ξn↑pt of evp-simple functions, that is to say linear combinations of components of evpξn=∑iNnαiξn,i where ∑iξn,i=evp and ξn,i∧ξn,j=0,i=j. Since X is Dedekind complete we can define for every ξn,i the vector yn,i=⋀{0≤u≤x∣ξn,i(u)=ξn,i(x)} We now associate to ξn the vector yn=∑iNnαiyn,i∈X. We claim that yn≤x. If this is the case, and since X is σ-Dedekind complete we can define xt≜⋁nyn. The null ideal of ξn,i is defined as the set Nn,i={x∈X∣ξn,i(∣x∣)=0}. Its disjoint complemented Nn,id={x∈X∣∣x∣⊥∣y∣ for all y∈Nn,i} is called the carrier Cn,i of ξn,i. Like the disjoint complement of any subset it is a band [3, §8.9] and since every band is a projection band in a Dedekind complete Riesz [4, Thm.1.41] X=Cn,1⊕Cn,1d. We can then decompose Cn,1d according to ξn,2 in the same way and decompose the entire space X into bands X=Cn,1⊕…⊕Cn,Nn⊕Brest since ξn,i⊥ξn,j is equivalent to Cn,i⊥Cn,j [4, Thm.1.67]. Thus for any x∈X we can find 0≤xi∈Cn,i such that x1+…+xNn≤x and ξn,i(xi)=ξn,i(x). Clearly yn,i≤xi. Since ξn=∑iαiξn,i≤∑iξn,i=evp and the ξn,i are pairwise disjoint (ξn,i⊥ξn,i), it follows that each αi≤1. We therefore have yn=∑iαiyn,i≤∑iyn,i≤∑ixi≤x as claimed, i.e. xt∈Bx. We now define xf≜x−xt∈Bx which proves the first two assertions. Now we need to show that the assignment x↦(xt,xf) is linear (it is clearly positive). To do this we just need to check that x↦xt is linear. To define xt+xt′ at stage n we consider the sets {0≤u≤x∣ξn,i(u)=ξn,i(x)}{0≤u′≤x∣ξn,i(u′)=ξn,i(x′)} For any such u,u′ξn,i(u+u′)≤ξn,i(x+x′) and thus these u,u′ are elements in {0≤u≤x∣ξn,i(u)=ξn,i(x+x′)} and it follows that ⋀{0≤u≤x∣ξn,i(u)=ξn,i(x+x′)}≤⋀{0≤u≤x∣ξn,i(u)=ξn,i(x)}+⋀{0≤u′≤x∣ξn,i(u′)=ξn,i(x′)}=⋀{0≤u+u′≤x+x′∣ξn,i(u+u′)≤ξn,i(x+x′)} For the converse we use the Riesz decomposition property as above. Thus the sequence defining (x+x′)t is constructed as the sum of the sequences defining xt,xt′ and thus (x+x′)t=⋁n(yn+yn′)=⋁nyn+⋁nyn′=xt+xt′.
Case of AL-spaces: Every AL-space has an order continuous norm [3, §9.5] and thus ∥xt∥=∥n⋁yn∥=n⋁∥i∑αiyn,i∥ Norm is order-continuous =n⋁i∑αi∥yn,i∥ AL-space =n⋁i∑αievp(yn,i)evp norm-preserving=n⋁i∑αiξn,i(yn,i)yn,i∈Cn,i=n⋁i∑αiξn,i(x)definition of yn,i,ξn,i order-continuous=n⋁ξn(x)=pt(x)
Conditionally branching structure. The skew-commutativity, true test axioms, idempotence and short-circuiting property follow directly from the definition of xf as x−xt and xt=x when pf=evp.
∎
Proof of Proposition 26.
Both the Hilb and CPM⊕ case can be treated simultaneously by reasoning directly on the if and else operators Ip and Ep.
Skew-associativity: We show that I\snotp=Ep and the result follows immediately. Note that \snot:C2→C2 is given by (0110), π1:C2→C2 by (1000), and π2:C2→C2 by (0001) in the computational basis. I\snotp≜(\snotp)†π1(\snotp)=p†\snot†π1\snotp=p†π2p=Ep
True test: we show that I\struep=idp and E\struep=0 and the result then follows from the fact that \strue∘(Ep,Ip)T=(1010)(EpIp)=(Ep+Ip0)=(idX0). I\struep≜(\struep)†π1(\struep)=p†\strue†π1\struep=p†(1111)p=idX Conversely, E\struep≜(\struep)†π2(\struep)=p†\strue†π2\struep=0
Idempotence for sharp predicates follows immediately from the fact that Ip,Ep are then orthogonal projections, and Ep=id−Ip. The result then follows from the fact that the codiagonal map sums the two components.
Commutativity is a trivial combinatorial consequence of the choice function definitions in terms of Ip,Ep.
∎
Appendix C Proofs for Section 5
The following lemma is a direct consequence of the enriched Yoneda lemma [20, §1.9].
Lemma 39.
Let (C,⊗,I) be a closed symmetric monoidal category with coproducts which is enriched over itself and such that Id=C(I,−), and let T=Id+Id. The set of natural transformations Id→T is in bijective correspondence with C(I,I+I). The set of natural transformations T2→T is in bijective correspondence with (C(I,I+I))4.
Proof of Theorem 28.
It follows from Lemma 39 that there are only two possible units for T given respectively by η=in1 and η=in2. Let’s consider each of these options in turn.
Case η=in1: again from Lemma 39 there exists 16 different possible multiplication μ:T2→T that are all of the shape
The unit axiom μ∘ηT=IdT implies that i1=1 and i2=2. The other unit axiom μ∘Tη=idT implies that i1=1 and i3=2. This leaves two options open. The associativity axiom μ∘μT=μ∘Tμ looks like this
i4=1. Clockwise we get the map [in1,in2,in2,in1,in2,in1,in1,in2]. Anti-clockwise we get the map [in1,in2,in2,in1,in2,in1,in1,in2]. These are the same maps, and thus this option is possible.
i4=2. Clockwise we get the map [in1,in2,in2,in2,in2,in2,in2,in2]. Anti-clockwise we also get the map [in1,in2,in2,in2,in2,in2,in2,in2], and so this option is possible too.
Case η=in2: the proof is dual to the case where η=in1. ∎
Proof of Proposition 29.
To see that ⊤∨\cho(p)=\cho(p)∨⊤=⊤ holds, consider first the following two commutative diagrams: \textstyle{X\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\top=\mathrm{in}_{1}}$$\scriptstyle{\cho(p)}$$\textstyle{X+X\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\cho(p)+\cho(p)}$$\textstyle{X+X+X+X\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\vee}$$\textstyle{X+X\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\mathrm{in}_{1}+\mathrm{in}_{1}}$$\scriptstyle{\strue}$$\textstyle{X+X}\textstyle{X\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\cho(p)}$$\textstyle{X+X\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\mathrm{in}_{1}+\mathrm{in}_{1}}$$\scriptstyle{\strue}$$\textstyle{X+X+X+X\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\wedge}$$\textstyle{X+X} Now note that thanks to idempotency we have \textstyle{X\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\cho(p)}$$\textstyle{X+X\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\strue}$$\scriptstyle{\nabla}$$\textstyle{X+X}$$\textstyle{X\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\top=\mathrm{in}_{1}}
The proof of ⊥∧\cho(p)=\cho(p)∧⊥=⊥ is dual to the previous case.
For the identity \snot(\cho(p)∧\cho(q))=\cho(\snotp)∨\cho(\snotq) consider the following diagram \textstyle{X\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\cho(p)}$$\scriptstyle{\cho(\snot p)}$$\textstyle{X+X\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\cho(q)+\cho(q)}$$\scriptstyle{\snot}$$\textstyle{X+X+X+X\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\wedge}$$\scriptstyle{\snot}$$\textstyle{X+X\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\snot}$$\textstyle{X+X\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\cho(q)+\cho(q)}$$\scriptstyle{\cho(\snot q)+\cho(\snot q)\hskip 15.94449pt}$$\textstyle{X+X+X+X\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\snot+\snot}$$\textstyle{X+X+X+X\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\vee}$$\textstyle{X+X} To see that the right-hand side square commutes we simply compute the maps in both directions. Clockwise the map is [in2,in1,in1,in1], anticlockwise it is given by ∨∘[in4,in3,in2,in1] which is also equal to [in2,in1,in1,in1].
The proof of \snot(\cho(p)∨\cho(q))=\cho(\snotp)∧\cho(\snotq) is dual to the one above. \textstyle{X\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\cho(p)}$$\scriptstyle{\cho(\snot p)}$$\textstyle{X+X\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\cho(q)+\cho(q)}$$\scriptstyle{\snot}$$\textstyle{X+X+X+X\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\vee}$$\scriptstyle{\snot}$$\textstyle{X+X\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\snot}$$\textstyle{X+X\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\cho(q)+\cho(q)}$$\scriptstyle{\cho(\snot q)+\cho(\snot q)\hskip 15.94449pt}$$\textstyle{X+X+X+X\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\snot+\snot}$$\textstyle{X+X+X+X\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\wedge}$$\textstyle{X+X} Again, the commutativity of the right-hand square follows by computing both morphisms which are equal to [in2,in2,in2,in1].
The commutativity \cho(p)∨\cho(q)=\cho(q)∨\cho(p) follows immediately from the fact that ∨=∨∘[in1,in3,in2,in4].
Similarly, the commutativity \cho(p)∧\cho(q)=\cho(q)∧\cho(p) follows from the fact that ∧=∧∘[in1,in3,in2,in4].
∎
Proof of Proposition 31.
The de Morgan relations follow from the fact that \choX(\snotp)=\snotX∘(p) holds in any conditionally branching category and diagram chasing around permutations of coproducts. For commutativity the proof follows immediately from noticing that
∨=∨∘[in1,in3,in2,in4]:I+I+I+I→I+I
and similarly for ∧. ∎
Proof of Proposition 34.
For notational convenience we use a conditionally branching structure defined by (17) in the special case where ⊗ is the Cartesian product. The general proof can then be obtained by making all copying explicit and replacing all instances of Δ below with copy, although this is laborious for pairings. Consider the following diagram which encodes the property for ∨ (the proof for ∧ is dual).
The top triangle with base ⟨id,p∨q⟩ commute by definition of p∨q. The left-most triangle commutes trivially and the square to the bottom-right of it commutes by naturality of ldistr as does the other square to its right involving two ldistr-labelled vertical arrows. The lowest triangle involving Δ+Δ commutes trivially and the half-moon diagram commutes by Lemma 38. The central triangle involving only ldistr also commutes by virtue of Lemma 38 by considering the inverses of the two diagonal edges (the inverse of the long edge is [idX×(idX×in1),idX×(idX×in2)]). Finally we can check explicitly that the right-most square (with the bendy vertical arrow) commutes by again considering the inverse of ldistr. Starting from the first summand of the bottom-right-hand object we get
The identity for the second summand is trivial and the commutativity of the final square follows. ∎
Proof of Theorem 35.
We prove the equality of these morphisms by showing that they are equal when post-composed with the jointly monic arrows [idX,∇X] and [\snotX,idX]. In the following diagram we write r for the test \snot(p∧q)p∧\snotq. That it commutes is a direct consequence of the fact that C(X,1+1) is residuated.