Circuits via topoi

by   Arnaud Spiwack, et al.

Leveraging topos theory a semantics can be given to sequential circuits where time-sensitive gates, such as unit delay, are treated uniformly with combinational gates. Both kinds of gates are functions in a particular topos: the topos of presheaves over the natural ordering of N. This is used to show that sequential circuits validate the equational theory of traced categories.



There are no comments yet.


page 1

page 2

page 3

page 4


Investigating the Power of Circuits with MOD_6 Gates

We consider the power of Boolean circuits with MOD_6 gates. First, we in...

Circuit pedantry

Boolean and quantum circuits have commonalities and differences. To form...

Coin Flipping in Dynamic Programming is Almost Useless

We consider probabilistic circuits working over the real numbers, and us...

Multiparty Karchmer-Wigderson Games and Threshold Circuits

We suggest a generalization of Karchmer-Wigderson communication games to...

A Curious New Result of Resolution Strategies in Negation-Limited Inverters Problem

Generally, negation-limited inverters problem is known as a puzzle of co...

Symmetric Circuits for Rank Logic

Fixed-point logic with rank (FPR) is an extension of fixed-point logic w...

Monotonic and Non-Monotonic Solution Concepts for Generalized Circuits

Generalized circuits are an important tool in the study of the computati...

Code Repositories

This week in AI

Get the week's most popular data science and artificial intelligence research sent straight to your inbox every Saturday.

1 Constructive domain semantics

As good computer scientist ought to when faced with tricky fixed point (even in circuits, loops are, after all, fixed points), let us turn to domains. Before we give a formal description of our semantics, let me note that it is a straightforward variant of the rather venerable three-valued semantics of combinational boolean circuits [11], which, by the way, has been shown, with caveats, to be a good semantics for electronic circuits [12].

Boolean circuits have, of course, a special relevance in computing science due to their being the basic building block of computers. But we will not restrict ourselves so. Wires will be allowed to carry values of any type we wish. The Faust programming language, for instance, has wires of type and (floating point numbers, in practice). The types, which, for the purpose of this article, are simply sets of permitted values, allowed for the wires by a circuit language will be called base types.

Definition 1 (Bounded height domain).

A bounded height domain is a partially ordered set equipped with a number such that every increasing chain in with has a pair with (equivalently, for every , ).

Circuits will be given a semantics as increasing functions between such domains. To the extent that the material present in this section is different from the usual treatment it is to render this section constructive to be compatible with the topos of Section Circuits via topoi. This is the reason why we focus on bounded height domains rather than the more usual -cpos. Note also that , in Definition 1 is not the height of the domain but rather an upper bound on this height. The reason is that, constructively, there may not be an exact height (see also [4] for more thoughts on finiteness in constructive mathematics). Every proof, in this section, is constructive.

Bounded height domain have the fixed-point property, just like other kinds of domains. Note that the fixed-point property of cpos or -cpos are also constructive. The added value of bounded height domains is that there are really few constructive cpos or -cpos (see Remark 1 below). Another practical advantage of bounded height domain is that the fixed-point property applies to all increasing functions, which will free us from proving continuity.

Theorem 1 (Fixed-point property).

Every increasing function for a bounded height domain with a smallest element has a smallest fixed-point.


Let be a bound on the height of . The sequence has length . By definition, there is an such that hence is a fixed point.

It is the smallest since, by induction, for any fixed point of and every , . ∎

Remark that we can refine the proof to show that the least fixed point of is also its least pre-fixed point (i.e. such that ).

Base types, which are sets, can be naturally identified to bounded height domains (without a smallest element).

Definition 2 (Flat domains).

Given a set , the partially ordered set (also noted ) where is a domain of height bounded by , which we call a flat domain.

Continuing on the subject of constructiveness, notice that flat domains are an example of domain which can’t be assigned a height. Indeed, if is inhabited then has height , whereas when is empty then has height but it is not possible, in constructive mathematics to decide whether is empty or not, the height flat domains is, therefore, not well defined (it is, in fact, impossible to define a non-constant integer-valued function on sets [5]).

In order to use base types in conjunction with the fixed point property they need a smallest element which we add freely.

Definition 3 (Lifted domains).

Given a domain with a bound on its height, we construct a domain , called lifted, by adding a distinguished element to and considering it smaller than every element of : . The height of is bounded by

Wires in circuits will be interpreted as taking value in the lifted flat domains corresponding to base types. Increasing functions between lifted flat domain are such that if , then for any , . In particular, if is such a function with several fixed points, then and the smallest fixed point is . So represents both the absence of a well-defined fixed point and the presence of several fixed points.

Obviously, in order for the smallest fixed point of to be non-, needs to ignore some of its input wires, for instance could be the well-know parallel or:

When one of the input of the parallel or is , then the output is , whatever the behaviour of the other input. In particular the following circuit is well defined (it outputs ):

More useful examples can be found in [11, 12].

Remark 1.

Lifted flat domains are an example of bounded-height domains which are not necessarily -cpos, constructively. Indeed consider , the singleton set, then is not constructively an -cpo. An -chain in is an infinite sequence of and (such that after a , every element is ). If an -chain has as an upper bound, then all of its elements are , if an -chain has as an upper bound, at least one of its elements must be 111Accomplished constructive mathematicians may noticed that I have made use of Markov’s principle in this statement: it’s a valid thing to do, though since if something is unprovable from Markov’s principle, it is certainly unprovable without. Alternatively, “must” in that sentence can be interpreted as the double-negation modality, in which case the statement is constructively true, and leads to a weaker, still non-constructive, version of the limited principle of omniscience.. If every -chain had an upper bound, it would give a way to decide whether they contain a or not, which is equivalent to the limited principle of omniscience: a known-to-be-non-constructive principle.

To formalise circuits with multiple wires we remark that bounded height domains are closed by cartesian products.

Lemma 1 (Cartesian product of domains).

The product of two bounded height domains of respective bound and , with order , is a domain whose height is bounded by .


A chain in is simply a list of pairs , with an constraint on consecutive pairs. However, chains can be represented differently as a list of pairs with a chain in , with the intent that the pair represents the chain . So that chains now have multiple representations depending on how successive pairs with the same first component are “contracted”.

We begin with the simplest representation where every pair is an . Now, as long as our list is of size longer than (without loss of generality we can suppose both and to be non-zero) we can use the fact that the first components describe a chain to find consecutive positions with the same which we can contract. Hence strictly reducing the size of our list. This process gives us a contracted representation of the long chain of length or less. But, since the total length of the chain is larger than , there must be at least one second-component list with length larger than . Applying the definition of the bound to this list concludes the proof. ∎

Combinational gates are, therefore, interpreted as increasing functions of type (with each being a base type).

2 Traced category

What is left is to use the fixed-point property to make precise the definition of feedback wires, the solution is given by Hasegawa [6, Theorem 3.1] who gives a method to transform fixed-point operators into traces.

Traced categories [8] provide a graphical language which is essentially the same as circuits with feedback. It is reassuring that circuits can be interpreted as arrows in such a traced category. It provides a natural equational theory on circuits which can be, among other things, leveraged to produce optimisation schemes [9].

Lemma 2 (Local fixed-point property).

Theorem 1 can be extended to produce a local fixed point function: let an increasing function ( and bounded height domain with a smallest element), there is an increasing function , such that for any , is the least fixed point of the increasing function .


The proof bulk of the proof is the same as Theorem 1, taking into account that, by definition of cartesian product is, indeed, increasing: let a bound on the height of X, .

We need to check the is indeed increasing. But since is increasing, for any and any ; by induction, we conclude that . ∎

Hasegawa tells us that there are three properties to verify for a fixed point operator to yield a trace (note that, reciprocally, all traces in a cartesian category yield such a fixed point operator). We shall write instead of . In addition and by definition, ; since the former is cumbersome, we will use the latter as a shorthand.

Lemma 3 (Naturality in ).

For any and , the following holds: .


Let , is, by definition, the least fixed point of . And, also by definition, so is . ∎

Lemma 4 (Naturality in ).

Let be an increasing function in . For any , .


Let us fix an .

  • []

  • Let us prove that is a fixed point of , and therefore . This follows immediately from the fact that and the fact that is increasing.

  • Conversely, we prove similarly that is a fixed point of . This yields , and then, by monotonicity of .

The two inequalities prove the lemma. ∎

Lemma 5 (Bekič).

Let and . Taking to be , the following holds


For , let us prove that is a fixed point of .

We also have that

This allows us to test both components for being fixed points or the corresponding function, which will suffice to conclude.

  • []

  • : by definition of it suffices to show that is a pre-fixed point of . After tedious calculations222So tedious, in fact, that I ended up formalising most of this section in the Coq proof assistant which, contrary to me, is not susceptible to calculation mistakes. Plus, I was getting lost and could use the help. This goes to prove that for certain mathematical proofs, proof assistant can be a productive way to develop proofs., it amounts to proving, calling , that . It is easily checked that is a fixed point of , which concludes this sub-proof.

  • . The argument is similar to above.

3 Causal sets

With that in mind, it makes sense to see streams not as a whole, but as a progression of prefixes . All of the , by virtue of being finite products of finite height domains, are finite height domains. A causal function can, then, be defined as a collection of functions such that is of the form .

To abstract over these notions, let us introduce a topos – i.e. a model of constructive mathematics – where such a presentation of streams and causal functions is natural.

Definition 4 (Causal sets).

The topos of causal sets is the topos of presheaves over the set of natural number with its standard ordering.

This topos has been extensively studied by Birkedal, Møgelberg, Schwinghammer & Støvring [2] under the name topos of trees to contribute to the related problem of step-indexing. Their article can serve as a reference.

A causal set is, therefore, given by a family of sets together with restriction functions . Causal functions are families of functions such that . Streams, seen, as above, as a progression of prefixes, form a causal set with and . Causal functions, in the sense of the topos of causal set, on are the same as causal arrows of streams; so that arrows in the topos of causal sets are, indeed, a generalisation of causal functions of streams.

By analogy with streams, the sets , constituting the causal set , are called the sets of prefixes of or just prefixes of . Since the indices of the functions can often be inferred from the context, they will often be omitted; for example: the compatibility of with restrictions may be written .

Topos are models of constructive mathematics, hence there is an interplay between internal statements of the topos of causal sets which are derived using the rules of constructive mathematics and external statements of ordinary mathematics. Internal statements are related to external statements via the Kripke-Joyal semantics [10, Section VI.6]: when is an internal proposition in context ( is a (conjunction of) causal set giving sense to the free variables of ), then for and an external proposition is defined. The proposition means that holds at least until and including time on . The main property being that if is provable in constructive mathematics (usually written ), then for all and , . And conversely, if is such that then is internally valid.

4 Causal domains

Let us now endeavour to give an external description of internal bounded height domain, so as to show that is an internal bounded height domain for some base type .

The ordering relation is reflexive: . That is, for any and . In other words, a reflexive causal relation, is a family of reflexive relations on each set of prefixes (compatible with restrictions). The same holds for symmetry and transitivity, such that an internal ordering relation is an ordering relation on each prefix333The reader may be worried about the implication in the statement of symmetry and transitivity, since the interpretation of implication is not direct in the Kripke-Joyal semantics. But it doesn’t matter at “toplevel”: translates to which is equivalent to ..

The translation of ordering relations illustrate the purpose of causal sets: to make it possible to reason on finite prefixes of infinite data. This is, indeed, what we were looking for, to be able to use the fact that prefixes of are bounded height domains. We should expect, at this point, that internal bounded height domains are exactly those causal sets where is a bounded height domain for each , which is indeed the case.

The key observation is that the casual which is the initial algebra of the functor can be defined as . The restriction functions act pointwise on the elements of each list. Therefore, since subsets are taken pointwise i.e. , chains internal to the topos of causal sets are chains on prefixes (compatible with restrictions).

Thanks to this observation, the internal definition of bounded height domain can be interpreted: is a bound on the height of at time if for all , is a bound on the height of in the ordinary sense. Since being a bound is a monotonous property on , an internal bounded-height domain is a causal set with all prefixes being externally bounded-height domains. An internal domain has a smallest element if each of the has and restrictions map smallest elements to smallest elements.

Lemma 6.

The causal set , for some ordinary set , is a finite height domain with a smallest element internal to the topos of causal sets.


Since the height is bounded by , which also bounds all the for . The smallest element of is . ∎

As a consequence, we can build circuits as causal increasing functions and feedback wires can be interpreted as internal least fixed point like in Section Circuits via topoi. The -th prefix of a causal increasing function is a sequence each of the being increasing, and such that .

What remains to be figured out is what a fixed point internal to the topos of causal set is. The internal formula for a fixed point is which translates to for any (note that , being an internal function, i.e. an element of , has prefixes , so ). Therefore is an internal fixed point if and only if it is a fixed point at each prefix.

5 Lifting traces

The results of the above section, while elegant, do not demonstrate effectively the usefulness of the topos-theoretic semantics: indeed, the treatment of the previous section could have been carried out directly just as easily without requiring topos-theoretic baggage. However, when all this material is developed, it becomes possible to easily lift more powerful theorems directly from the combinational semantics. Let us apply this principle to Hasegawa’s theorem from Section 2.

Hasegawa’s theorem being an external statement about categories, we will have to translate the statement (but, crucially, not the proofs) of all four lemmas and show that they correspond to the hypotheses of Hasegawa’s theorem. Fortunately, this is rendered easy thanks to some standard properties: causal functions are the same as global sections (where is the terminal causal set: is the singleton set for every ), internal equality is interpreted as external equality, and the terms and are interpreted as identity and composition, respectively. From these, we can immediatly deduce that it makes sense to speak of a causal function which is internally increasing, and therefore, that the causal bounded-height domains with a smallest elements and internally increasing causal functions form a subcategory of the topos of causal sets.

A slightly trickier property is the local fixed-point operator whose existence is proven internally. Remember that is interpreted by there are no connection between the chosen at each so there is not necessarily a global section that witnesses the existential. However, when the not only exists, but is also unique, then, since , then the necessarily respect the restriction maps of , hence form a global section. There is, of course, at most one local least fixed-point map, hence, internal existence guarantees external existence of a global section, which can be turned into an external map from causal functions to causal functions.

The rest of the properties: that is, indeed, a local fixed-point map, that it is natural in and and that it verifies Bekič’s lemma, are all universally quantified equalities involving composition of arrows (and ). They can be changed into their categorical counterparts with just a bit of fiddling.

We can, therefore, conclude, with barely any proof pertaining to time, that sequential circuits obey the laws of traced categories.


  • [1] John C Baez and Jason Erbele. Categories in control. 2015.
  • [2] Lars Birkedal, Rasmus Ejlers Møgelberg, Jan Schwinghammer, and Kristian Støvring. First steps in synthetic guarded domain theory: step-indexing in the topos of trees. Logical Methods in Computer Science, 8(4), 2012.
  • [3] Filippo Bonchi, Paweł Sobociński, and Fabio Zanasi. Full Abstraction for Signal Flow Graphs. ACM SIGPLAN Notices, 50(1):515–526, 2015.
  • [4] Thierry Coquand and Arnaud Spiwack. Constructively Finite? In Laureano Lambán Pardo, Ana Romero Ibáñez, and Julio Rubio García, editors, Contribuciones científicas en honor de Mirian Andrés Gómez, pages 217–230. Universidad de La Rioja, 2010.
  • [5] Martin H. Escardo and Thomas Streicher. The universe is indiscrete. 2013.
  • [6] Masahito Hasegawa. Recursion from cyclic sharing: traced monoidal categories and models of cyclic lambda calculi. Typed Lambda Calculi and Applications, 1997.
  • [7] Guilhem Jaber, Nicolas Tabareau, and Matthieu Sozeau. Extending Type Theory with Forcing. In 2012 27th Annual IEEE Symposium on Logic in Computer Science, pages 395–404. IEEE, June 2012.
  • [8] André Joyal, Ross Street, and Dominic Verity. Traced monoidal categories. Mathematical Proceedings of the Cambridge Philosophical Society, 119(03):447, 1996.
  • [9] Hai Liu, Eric Cheng, and Paul Hudak. Causal commutative arrows and their optimization. In Proceedings of the 14th ACM SIGPLAN international conference on Functional programming - ICFP ’09, page 35, 2009.
  • [10] Saunders Mac Lane and Ieke Moerdijk. Sheaves in geometry and logic: A first introduction to topos theory. Springer, 1992.
  • [11] Sharad Malik. Analysis of cyclic combinational circuits. Proceedings of 1993 International Conference on Computer Aided Design (ICCAD), pages 618–625, 1993.
  • [12] Michael Mendler, Thomas R. Shiple, and Gérard Berry. Constructive Boolean circuits and the exactness of timed ternary simulation. Formal Methods in System Design, 40:283–329, 2012.
  • [13] Yann Orlarey, Dominique Fober, and Stephane Letz. Syntactical and semantical aspects of Faust. Soft Computing, 8(9), July 2004.