 Welcome everyone to this presentation hosted by MFPS 2020. My name is Niels Forneveld, and I would like to talk to you about combining all your back effects descriptions using the tensor of complete lattices. So normally when you look at the program, when it's a pure language, it will just behave deterministically. Every time you evaluate it, it will return the same thing and that will happen every time you do evaluate it. However, once you have algebraic effects, this might not be the case anymore. Different evaluations of a program might give different results. For instance, in randomized algorithms, different evaluations give different results with certain probabilities. Or another example is when a language or program is communicating with some global memory source, then whatever the program will do depends on whatever is stored in that global memory source. So if we ask it or want to describe a property of such a program, like we want to ask whether it behaves like the identity function, or you can ask, does it produce an even number? Then the answer to that question is not just a simple yes or no, it is more of like it has a certain degree of truth. It's like maybe like randomized program is maybe half the time it produces an even number. Or when you have a global store program, it depends on what is stored in the global memory. And so we have all these nuances of truth to which properties when we talk about the program satisfying the property, that they satisfy those to a certain degree of truth. And those are also called quantitative truths. And in most examples, that we look at these form complete lattices. So we're able to formulate the quantitative logic using this. Now, in order to actually extract from a program to what degree it satisfies the property, we want to be able to describe its behavior in a certain way. And that's done using an algebra, which is generated using local description, local functions on the other back effect operations. And then once we have this, so we have this degree, this notion of truth together with a way of computing the degree of truth for program effects for programs, then we can use these tools to formulate a notion of program equivalence. And that is the topic that was the topic of my talk last year at MFPS. The focus here is given that we have for certain effects a notion of truth and an algebra given by a local description. How is there a way to generically combine such descriptions? And so you have to kind of keep in mind that we can apply this to multiple effects like probability, global stored, non-determinism, error, cost and input output. However, for each particular effect, we need to specify a specific notion of truth and a specific algebra. And so that's also the case for each combination of effect. So wouldn't it be neat if we have the descriptions of the individual effects, we can actually just use a certain operation that combines these descriptions. And that is basically the aim of this talk to present you this method that I found and then argue how this method actually gives you the right interpretations of combinations of effects. So this is the overview of the talk. First, we'll just dive in and talk about how we can use these notions of truth and these algebras to describe effects. And so define what is a description of algebraic effects as seen in the title. Then in the second part, we'll define how we combine such descriptions and which then uses the tensor of complete lattices. And then lastly, in the third part, we'll look at what happens when we apply this method to the examples of effects and argue why it gives you the nice descriptions of combinations of effects. So first of all, as I said, affects alter the behavior of programs. And in a particular way, we look at algebraic effects which are implemented using algebraic operations. So in certain moments in the program, we have terms that combine other programs into an effectful term. For instance, for when we have randomized algorithm, we might use a probabilistic operation, the probabilistic or, which combines two different continuations into a single program, which we then can then see as it's kind of randomly, uniformly draws a bit, zero and one. And if it's a zero, it will continue one way. And if it's a one, it will continue another way. And so this operation has two different possible continuations. And so this has erity two. Another example that we'll look at is global store. So that is when we're actually can look at the memory source that has certain numbers stored in them. And so in that case, we have two types of operations. We can look up at a certain location, this natural number. And depending on what natural number is stored there, we have a continuation. So we have actually countably many continuations, erity is natural numbers. And which then tells you that you have, for each number it can draw, it has a continuation that the program will continue to go into. And then also for each natural number, we have an update which simply stores this particular natural number at that location. And so this has only as one continuation because it stores the number and then just gets on with the computation. And so in general, whenever we look at effects, we have this effect is implemented with a bunch of operations or only one operation. And we gather these together in a signature, an effect signature of operations. So for probabilistic computation, we have only one operation, but here we have countably many operations. All right, so now once we have all these operations, we can describe the free denotation of programs where we use this function which kind of gathers up all possible continuations that we have when you have a bunch of operations. So for each operation that we can encounter, we have all these continuations here. And then given this functor, we can take the limits and the co-limits over this functor in this way to generate two monads on the category of sets, post sets and omega CBOs. We have the finite trees, which kind of gives you a tree that has as nodes, basically internal nodes, the operations, and it leaves the possible values that the computation can return from set X. And we also have the infinite trees, which is the same, but the trees can be infinitely deep. And so here are two examples. For instance, for global story, I have here a tree that first updates at the location L to the number two, and then it looks it up and then continues on whatever direction depending on what it looks up. And so, and also here we have a probabilistic example, which you can kind of see is drawn to, drawn a random bit twice. If the first one is a zero, it will diverge. And if the first one is a one, it will draw another bit and then go either six or seven. Of course, these monads are free monads. So these in general contain much more information than you would want, right? So for instance, this tree here, we can see if we look up straight after we update, then obviously we're going to find the two. So we're going to go into this direction. So the rest of the tree is relevant. Similar for the probabilistic or the particular paths are not really relevant. They just kind of matters what the probability is, right? So we use these trees to kind of have a generic foundation describing limitations or effects, but we still need to interpret these effects. And so how do we interpret those? Well, like I said before, we start by establishing a notion of truth. So in general, when we ask of kind of deterministic question of a program, like does the program produce an even number? If the program is effectful, the answer is not simple yes or no, it's more nuanced. So randomized programs might probabilities that this property is satisfied and global store operation programs might, the answer might depend on the initial state. So only for certain initial states of the global store, this is true. And so gathering all these possible answers up for a particular effect, we find an order in space, which in our examples of effects form completely distributed, complete lattices. And if they are not like that, we can always make it like that in terms of completion, mathematical completion arguments. And so this is a set which has an order which kind of generalizes application like an higher element means it's true more often. And it's a complete lattice. So for each subset, we have a smallest upper bound, the suprema, and we have the largest lower bound. In particular, we have a maximum element which stands for always, this property is always true regardless of how effects are resolved. And we have a smallest element false, which says it's never true regardless of how the effects are resolved. And lastly, we want to complete lattices to be distributed with means that the infomer distributes over the suprema, which means that this is satisfied for any double family elements. All right, so now we need to describe how to extract from a program the degree of truth that it satisfies. And we do that using an algebra. These algebras are from the trees of true values into the true values. And in general, we use those to lift predicates on X to predicates on trees over X using this composition here. And the nice thing is that we can describe these, if we're careful, we can describe these by just locally describing these algebras over the effect operators. So in particular, we just need to function for each operation, we need function that gives the true value for each of the continuations combines that into a single true value. And in particular for the theory to work, these functions happen to be I linear. That means that a function here from some product of complete lattices into complete lattice is I linear. If we're any family non-empty subsets, we have F on the suprema of these sets is the same as the supremum of F applied to a family in this SI. Meaning that in each of the argument, we can pull out the supremum from the argument to the outside. This is a slide for the variation on linearity, which is basically the same property, but then for all subsets. So there's a slight difference here, where for instance, in the category of complete lattices, amorphism would be given by linear functions between complete lattices. However, when we describe effects that in general, they're not always linear, they in general are just I linear. Luckily, that doesn't give us a problem. So given a bunch of all of these local functions, we can immediately deductively generate an EM algebra on finer trees. Moreover, I linearity also implies omega continuity. So this can actually be extended to an algebra on infinities, right? But this is all motivation will not focus on the algebras in general and just look at motivate these local functions, right? So kind of to wrap it all together. When we're talking about effect, we give an effect description, which is made up of three ingredients, a signature of effect operations, a complete lattice of truth, quantitative truths, and a local description, which is given by these I linear functions over each of these operations. So quickly, two examples. So for probability, we just have a signature, only this binary operation four. Through space, we have to complete letters given by the real number integral from zero to one, which gives us probabilities of truth. And are we interpret, given the interpretation of an effect, given this local function here, where whenever we have two continuations that are determined by a random draw of a bit, what we do, we check the truth of the first continuation, we check the truth of the second continuation, and then we take the average because each of the two continuations is equally like. So that gives us a local description of probabilistic or operates. Right, so the second example is global store, where you have these operations here. In this case, like I said before, we have as truth space assertions on states. So basically it gives each truth value, gives you a set of states, where the state is given by a map from locations to the natural numbers, which tells you which natural number is stored at each location. And then property satisfied by saying, okay, it's satisfied when we start with these states, right? And so we give this interpretation of the weakest precondition, where, for instance, for lookup, local function is given by, well, a correct state of the over lookup is whenever the state is correct for the continuation that we're going into and the update state is correct if the state after being updated is correct for the continuation. All right, so we've seen how to describe all the back effects. Now we're going into how to use this particular formulation to combine effects. So the first question is, how do we combine these notions of truths? And it happens that the most natural way of combining truths is actually given by the tensor product of complete lattices. This is not the first formulation I came across, but in the end it happened to be the case that what the thing I found was isomorphic to the tensor product. And so in general, the general definition of the tensor product is the function that is universal with respect to linear functions. So the tensor product of two complete letters, A and B, is some complete letters A cross B, tensor B, such that there is a universal linear function, A times B to A tensor B, with the property that any linear function, A cross B to C into a complete letter C, is the composition of this universal map with some linear function from this tensor. Now that's very abstract. Luckily, we have various two concrete representations. We have the power set representation where, so this tensor here is isomorphic to this power set representation given by subsets of A cross B. And we also have a representation with respect to functions from A to B given some collision. And so one way to see these representations is by noting that when we ask a question of a program that has two effects, then we want to describe how much it satisfies this property by giving multiple pairs of truths, right? For certain beginning states, we have a certain probability that it's true. And for different states, we have different programs. So in particular, for instance, we have the example when we have a power set for instance states and we do tensor A, then we can actually immediately see that this tensor is isomorphic to this function space by this quick observation here. So in particular, when we look at probability in global store, then the tensor of their true space will give you a map from state to probability. Now, some quick properties. The tensor product is symmetric and associative and the unit is given, it has a unit given by the Booleans. So it gives us a symmetric model product. Secondly, because of the universal properties with respect to linearity, we have some nice things that we can use. In particular, we now know how to combine truths, but how do we combine the descriptions and in order to combine descriptions, we need to know how to combine functions. So in particular, because it's a tensor product by definition tensor product, we know that linear functions can be factored through linear functions on the tensor. So in particular, the linear functions on these families of maps to the I cross B to the I to C are precisely the linear functions of a tensor B to I to C given by, which is given by this map here. And so here you can see this I to be the arity of our operations, right? So that's what we're going to use it for. Now for two complete lettuces A and B and an indexing set I and two functions, we can basically needly compose them into this. So these must be two linear functions we can compose using this operation here, composing with universal map and then applying F, this is given like this. And the neat thing is that this operation immediately preserves linearity, but not only that, it also preserves I linearity, which is the property that we had on our local functions or local descriptions. And so in particular result is that if A and B are not only complete lettuces, but also completely distributed and F and G are both I linear, then the combination of F and G is I linear. Moreover, we can use this result to prove that if A and B are completely distributed lettuces, that the tensor is completely distributed. And that is a result of observing this by applying this to combining the infinite functions as complete distributivity is similar, is equivalent to saying for each indexing set that the infimum function is I linear. And so we can use the preservation of I linearity to prove that completely distributivity is preserved. All right, so we can use this to now finally define how to combine effect descriptions. So given two effect descriptions, given by these triples of effect operations, truths and these description, interpretation local functions. We create this combined description where the new signature has the operations over the both of the effects. The truth is the tensor and the I linear local functions are given by this where when we have an operation from one side, what we do, what we interpret, we give the I linear local function on the tensor with this rt op. What we do is we use on A on the left side, we use what we know, so description there. And on the right side, we use the infinite function. And so this implements precisely the idea that for each element in B, we basically apply the other function on the left. So we keep track for each element in B, we keep track of what happens on A on the left. And as we will see in the examples, this gives us a very natural, the results of these combinations gives us a natural interpretation. Okay, so let us look at some examples of this combination. So first of all, our two examples that we started off with, probability and global store. So if we combine these with these, these combinations of effect descriptions, then of course the combined effect signature is just the operations that we had before. Like this, the probabilistic core and these lookup and update operations. The combined true space is our interval, the tensor and the power set, which is given as we know before by states, the functions, just functions from state probability, which basically tells us for each state, there's a probability that the property holds. And then for the combined interpretation, we combine the expectation interpretation with the weakest precondition interpretation, which gives us a weakest precondition with extra probabilistic weights interpretation, basically. And so we apply in particular the definition that we've seen before to get this description here. So for instance, if we look at this combined thing and we look at the probabilistic order, then we see, okay, well, if we start with certain state, how much is the property satisfied? Well, what we do is we look into how much the state will yield the property when we go to the left continuation and how much we go when we go to the right continuation and take the average. So this is basically post composing with the average function. On the other hand, on the other side, we have the global store operations where lookup, when we want to know the precondition of how the probability for a certain initial state, what we do is we check what is stored in the state, we look at the appropriate continuation and we just check how much, what the probabilities is for that continuation. And similarly for the update, what we do is we want to check how much probability with what probability the property satisfied given a certain initial state, what we do is we update store by store an M in L and then we check how much is satisfied in the single continuation. Another example that we've not looked at before is non-determinism. So non-determinism can also be described using effect descriptions, where now we have again the binary choice operation or the non-deterministic or. But in this case, we do not have all degrees from zero up to one of truth because this is completely unreliable non-determinism. In this case, when we ask property of a non-determinist program, there are three answers, never, maybe or always, which is given by these three values. And the interpretation of possibility is before you can define the local function or possibility to be the appropriate thing. And then we can combine this basically with any other effects. So we combine non-determinism, say this effect description here, then the truth combined truth space is given by pairs of truths of this A here, where A is below B, which basically gives you the truth that must always be true and the truth that must be sometimes true. For instance, there might be two probabilities, right? The probability that this always holds and the probability that it sometimes holds. And so that gives you these pairs. And then when we combine these into the interpretation, there's all fallacy possibilities one, then we basically get these results. Like we applied operations to the two elements of the pair here. And when we do the look at non-deterministic one, we get to take the infimum of the must and the screen of the main light. Now, one big argument for why the effect descriptions we end up with for these combinations are actually the ones that we want is once we compare this to the more traditional ways of combining effects, which when we look at them using equations, so this comes the other way around, and we can quickly describe equations what equations look like in this setting. So in general, we have a set of variables and then we see an element of the infinite tree over these variables and algebraic expression. And then a pair of these algebraic expression can then be seen as equation. And then given this equation and given an algebra that is generated by a local interpretation, we can say that this algebra satisfies this equation if for any substitution of truths for the variables, we have that applying the algebra on the result is to give you the same thing. So for instance, if we do the expectation, the algebra for probabilistic randomized programs we have that these usual equations are satisfying. All right, so the first quick result is if we combine two effect descriptions into this one here, then if one of the former effect descriptions satisfies an equation, then the combined effect description still satisfies the equation. So it's kind of the bare minimum that we want. Equations are preserved. Given that, so that holds for any combination of effect descriptions, given that we see in literature that there are kind of two canonical two sides of the coin of the canonical ways of this combining equation of theories with the sum of theories, which just combines original axiomatic equations or if the tensor theories in which we take the original equations that also add interaction laws between the operations on the two sides. In particular, we add commutativity laws where we take for each operation one side and each operation on the other side, we say that this operation one side distributes over the operation other side, which is given by this equation here. All right, given these definitions, we actually have that what actually happens is so when we see looking literature, the way that we want to combine equation of theories depends whether we want to sum the tensor depends on which effects we combine and really depends on the case. However, in this, the method that I'm presenting in this talk here, it seems to kind of different combinations give you different way related to different ways of combining equation of theories and it seems to be that every time that you look at the combination of effects, it seems to choose the more natural one. So for instance, when we look at the combination of global store and probability, what we get is the tensor of equation theories with the one that we want, which is also the one that we want because we have this commutativity laws. Another example, a famous example is the combination of probability and non-determinism, which case we neither want to sum nor the tensor. And in fact, when you look at the combination of fact descriptions in this way, we get that indeed this combination of expectation and possibility interpretation gives us something in between the sum and the tensor for this interaction law here, which you don't have the full commutativity law. Lastly, there's also instances where we get the sum, the combination of effects that related to the sum of effects. For instance, when combined cost, the cost effect on error. And this is a very basic example of that. But we have that this combination, this commutativity law is not satisfied. So we get the sum. Okay, so in short, a quick summary. So we have seen how to give description of all the back effects using complete lattices and a linear local functions. These give rise to congruent notions of program equivalence. If you use these in my previous paper at MFPS. The second way we have seen, which is the main topic of this talk, we've seen a method of combining such descriptions using the tensor on complete lattices. This gives a natural description of combinations of effects. And then some related future research in the paper at MSFP, I talk about deriving description directly from equation of theory. So kind of belving deeper into this relation between equations and descriptions and algebas. Some other work I'm looking at is adding a co-effect productions to affect description. So being able to describe both co-effects and effects. And a potential future topic is to use these descriptions to actually define quantitative relations, not just program equivalences. Like for instance, a quantum relation like metrics. Thank you for listening.