Category Theory
Zulip Server
Archive

You're reading the public-facing archive of the Category Theory Zulip server.
To join the server you need an invite. Anybody can get an invite by contacting Matteo Capucci at name dot surname at gmail dot com.
For all things related to this archive refer to the same person.


Stream: theory: category theory

Topic: Categorical models for abstract symbols


view this post on Zulip Ben Logsdon (Aug 21 2023 at 19:26):

I would like to find a categorical models for the programming langauge feature described below, which I call symbols. This idea is discussed in Part XIII of "Practical Foundations for Programming Languages" by Robert Harper, but I don't currently know whether my formulation below is equivalent to his.

There is some countably infinite type S\mathcal{S} of symbols. This type has decidable equality; there is some function _=_:SBool\_=\_ : \mathcal{S} \to \mathtt{Bool} which determines whether two symbols are the same. Besides this, symbols have no internal structure (i.e. no structure available to the user of the language). Since _=_\_=\_ is the only primitive function available which eliminates symbols, all deterministic functions SA\mathcal{S} \to A for any type AA should be almost-everywhere constant, i.e. constant on all but finitely many inputs.

There is a special (nondeterministic) function \bullet, which I pronounce "symbolgen". Each time \bullet is evaluated, it produces a fresh symbol (i.e. a symbol that has never been produced before). In this way, \bullet can be seen as an idealization of the process of generating a random string of bits---so idealized that it is downright impossible to generate the same symbol twice.

So...do you know of any categorical formulations of this feature or a similar one? Since it involves nondeterminism, it feels like it could be modeled by (something like) a Markov category, with \bullet interpreted as a single nondeterministic function 1S\mathbf{1} \to \mathcal{S}. I am especially interested in how this feature would interact with standard programming language features, such as inductive types.

To give a bit of context of this question...there are many purposes of this feature, but one of them is to serve as an abstract account of names (e.g. names of functions in a module system) which doesn't rely on some underlying structure, such as representing names as strings. Another application is to represent capabilities and access control explicitly---possession of a given symbol by a piece of code can indicate that that code is authorized to access certain information or modify data in a certain way. This is why it's important that \bullet never yields the same symbol twice; if I generate a symbol to serve as a guard for some data I want to protect, I want to be sure that no one else will be able to generate that symbol later.

If no references seem to surface, then I'll sit down and puzzle through it myself, but I'm wondering if there is any existing work on this or a similar problem.

view this post on Zulip Spencer Breiner (Aug 21 2023 at 19:40):

Maybe not quite what you're looking for, but if you haven't seen them already you should look at [[nominal sets]].

view this post on Zulip Ryan Wisnesky (Aug 23 2023 at 01:34):

perhaps obvious, but you could implement it with a monad on top of stlc

view this post on Zulip Tobias Fritz (Aug 23 2023 at 04:09):

You may be interested in @Dario Stein 's Probabilistic Programming Semantics for Name Generation and the references to Stark's ν\nu-calculus given there.

view this post on Zulip Tobias Fritz (Aug 23 2023 at 04:17):

Also very relevant could be Section 25 in Dario's thesis, which describes a Markov category of nominal sets.

view this post on Zulip Tobias Fritz (Aug 23 2023 at 05:11):

I've been toying around a bit myself with similar ideas and constructed a different Markov category of nominal sets. I'm not sure to what extent the following is reasonable from the programming perspective, so take it as merely an idea that may or may not be worth considering further.

Let me start with some background on nominal sets. Fix an infinite set A\mathbb{A}, whose elements are thought of as basic variable names. Let G:=S(A)G := S(\mathbb{A}) be its group of finite permutations. Then let's say that a pre-nominal set is simply a GG-set, i.e. a set XX together with a homomorphism from GG to permutations on XX. The idea is that XX could e.g. be a set of expressions in your language, where the GG-action keeps track of how these expressions change upon changing the names of variables. The support of an xXx \in X is the smallest BAB \subseteq \mathbb{A} such that πB=idB\pi|_B = \mathrm{id}_B for πG\pi \in G implies πx=x\pi x = x. If you think of xx as an expression in your language, then this means that the support is the set of names that actually appear in it. Now a nominal set is a pre-nominal set XX such that every xXx \in X has finite support. If XX is a nominal set, then for any x,yXx, y \in X, there is πG\pi \in G such that πx\pi x and yy have disjoint support: you can always rename the variables in an expression such that they become disjoint from those appearing in another one.

If XX and YY are nominal sets, then the same considerations also apply to functions XYX \to Y, since these form a GG-set of their own. We can now define a Markov category as follows:

My hypothesis is that this Markov category provides a sensible way to talk about the sort of nondeterminism that you want to model. But I'm not sufficiently familiar with programming language theory to confidently assert this.

view this post on Zulip Sam Staton (Aug 23 2023 at 17:16):

Hi @Tobias Fritz, curious category. I've mainly considered the Kleisli category of the name generation monad on nominal sets for this kind of name generation. So I'm wondering whether your category has different properties as a Markov category? Or is there another reason that you propose it?

At first I thought your category might be very similar to the Kleisli category of the name generation monad, but Nom(A,T(2))=2\mathbf{Nom}(\mathbb{A},T(2))=2, whereas I think C(A,2)\mathcal C(\mathbb{A},2) has many elements for your category C\mathcal C.

Also. I tried calculating AidAA×A[=]2\mathbb{A}\xrightarrow{\bullet\otimes id_{\mathbb{A}}}\mathbb{A}\times\mathbb{A}\xrightarrow{[=]}2, to check whether it was equal to A!1false2\mathbb{A}\xrightarrow ! 1 \xrightarrow {false}2. I couldn't get it, but maybe I misunderstood your definition, or made a mistake. Or maybe you didn't want this?

view this post on Zulip Tobias Fritz (Aug 24 2023 at 02:53):

Hi Sam! The simple reason for me to come up with this category was that I had just learned about nominal sets and hadn't heard of the name generation monad :sweat_smile: So for anyone else reading this: @Sam Staton is the real expert here on these things!

So far, I haven't thought about this category at all other than its definition, so I don't know what properties it has. I agree with your calculations though. In particular, yes, the composite AidAA×A[=]2\mathbb{A}\xrightarrow{\bullet\otimes id_{\mathbb{A}}}\mathbb{A}\times\mathbb{A}\xrightarrow{[=]}2 is not constant false, and not even constant. So somehow this category keeps track of more fine-grained information than the Kleisli category of the name generation monad: the resulting composite morphism A2\mathbb{A} \to 2 remembers that you had picked one fresh name, but it doesn't remember which one.

view this post on Zulip Tobias Fritz (Aug 24 2023 at 03:00):

So I don't really know what to make of this category. But given that the definition is pretty simple and natural (to anyone who knows about nominal sets), I think that there has to be some sensible interpretation or operational account of it. Would you agree with this expectation?

Here's an incomplete attempt at finding such an interpretation. Think of A\mathbb{A} as the set of bank notes in circulation; this set is infinite for all practical purposes, so let's formalize it as an infinite set. Then a typical morphism A2\mathbb{A} \to 2 could be represented by something like "given a bank note xAx \in \mathbb{A}, answer yes if and only if xx has ever passed through my wallet". Then there is a definite fact of the matter about how many notes have passed through my wallet, but no definite fact of the matter about which ones, since the morphism really is the entire orbit of such a predicate.

In general, it looks like a morphism in this category has the power to treat finitely many names as special. But for every morphism, these finitely many special names are required to be fresh (due to composition being defined in terms of disjoint support).

view this post on Zulip Sam Staton (Aug 26 2023 at 16:53):

Thanks Tobias. It's an interesting that you can have this "intensional" model -- I haven't seen it before.

As you probably know there are two monoidal closed structures on nominal sets. You used the cartesian closed one (finitely supported functions) as part of your construction. But I think if you'd used the other one, it would have been close to the usual name generation monad.

view this post on Zulip Tobias Fritz (Aug 27 2023 at 02:46):

Thanks, I didn't know this! I suppose that the "other one" is the monoidal structure called separated product, right? I'm not sure how this gives a Markov category, because there are no diagonals XXXX \to X \ast X?

view this post on Zulip Ben Logsdon (Aug 31 2023 at 19:37):

Thanks all for the responses and discussion! The references and ideas here seem to be exactly what I was looking for. It will take me some time to absorb all the details here, but I have a few follow-up questions:

  1. Is there a good reference (or section in one of the references mentioned above) that talks about the name-generation monad on the category of nominal sets? I haven't seen it so far in my reading.
  2. What is the other monoidal closed structure on nominal sets (alternatively, where can I read about it)?
    Thanks again; this was very helpful for me.

view this post on Zulip Tom Hirschowitz (Sep 04 2023 at 16:53):

What's a finitely supported function, concretely? Or maybe before that, what's the action of permutations on functions that you consider? (Sorry for the naive question...)

view this post on Zulip Tobias Fritz (Sep 04 2023 at 16:57):

If XX and YY are GG-sets, then the action on functions is such that a group element gGg \in G acts on a function f:XYf : X \to Y by producing the new function gfg \cdot f defined by (gf)(x)=gf(g1x)(g \cdot f)(x) = g \cdot f(g^{-1} \cdot x). This GG-set of functions is the exponential object YXY^X in the category of GG-sets, see Proposition 3.9.

view this post on Zulip Tobias Fritz (Sep 04 2023 at 17:00):

A function ff is finitely supported if there is finite SAS \subseteq \mathbb{A} such that if gg is any group element that acts like the identity outside of SS, then also gf=fg \cdot f = f. I think of this as saying something like "only the variable names in SS appear in the definition of ff".

view this post on Zulip Tobias Fritz (Sep 04 2023 at 17:01):

So, any equivariant function XYX \to Y is finitely supported, since we can even take S=S = \emptyset. For a non-equivariant example, any constant function AA\mathbb{A} \to \mathbb{A} is finitely supported.

view this post on Zulip Tom Hirschowitz (Sep 05 2023 at 07:58):

Thanks! Do you mean "acts like the identity on SS", or am I confused? Is it right that the point of your category is to include more morphisms than the usual equivariant maps?

view this post on Zulip Tobias Fritz (Sep 05 2023 at 08:34):

I do mean "identity outside of S". If you think of S as the set of variables names that occur in f, then permuting other variable names that do not occur in f doesn't do anything, but permuting those that do occur in f will generally result in a different expression.

view this post on Zulip Tobias Fritz (Sep 05 2023 at 08:35):

But yes, the idea is to include more morphisms than the equivariant ones, constructing an interesting-looking Markov category like that. The equivariant morphisms are precisely those that are deterministic in the Markov cats sense

view this post on Zulip Tom Hirschowitz (Sep 05 2023 at 09:02):

Tobias Fritz said:

I do mean "identity outside of S". If you think of S as the set of variables names that occur in f, then permuting other variable names that do not occur in f doesn't do anything, but permuting those that do occur in f will generally result in a different expression.

Sorry for being so thick, but "permuting variable names that do not occur in f" sounds to me like being identity on SS. Let me explain how I'm thinking so that maybe you can pinpoint where I'm derailing.

You seem to be saying that if g only permutes variable names that do not occur in f, then
gf=fg \cdot f = f, but

only permuting variable names that do not occur in f

is the same as

leaving variable names in $$S$$ unchanged

ie

being identity on $$S$$.

Where is this wrong?!

view this post on Zulip Tobias Fritz (Sep 05 2023 at 09:23):

D'oh, of course you're right, and I've been very confused :grimacing: Looks like my explanation was fine, but my statement of the condition was off. Thanks for the correction!

view this post on Zulip Tom Hirschowitz (Sep 05 2023 at 09:31):

Oh ok! Thanks for the explanation then :big_smile: