Eliminating Binders for Easier Operational Semantics
Posted by John Baez
guest post by Mike Stay
Last year, my son’s math teacher introduced the kids to the concept of a function. One of the major points of confusion in the class was the idea that it didn’t matter whether he wrote or , but it did matter whether he wrote or . The function declaration binds some of the variables appearing on the right to the ones appearing on the left; the ones that don’t appear on the left are “free”. In a few years when he takes calculus, my son will learn about the quantifiers “for all” and “there exists” in the “epsilon-delta” definition of limit; quantifiers also bind variables in expressions.
Reasoning formally about languages with binders is hard:
“The problem of representing and reasoning about inductively-defined structures with binders is central to the PoplMark challenges. Representing binders has been recognized as crucial by the theorem proving community, and many different solutions to this problem have been proposed. In our (still limited) experience, none emerge as clear winners.” – Aydemir, Bohannon, Fairbairn, Foster, Pierce, Sewell, Vytiniotis, Washburn, Weirich, and Zdancewic, Mechanized metatheory for the masses: The PoplMark challenge. (2005)
The paper quoted above reviews around a dozen approaches in section 2.3, and takes pains to point out that their review is incomplete. However, recently Andrew Pitts and his students (particularly Murdoch Gabbay) developed the notion of a nominal set (introductory slides, book) that has largely solved this problem. Bengston and Barrow use a nominal datatype package in Isabell/HOL to formalize -calculus, and Clouston defined nominal Lawvere theories. It’s my impression that pretty much everyone now agrees that using nominal sets to formally model binders is the way forward.
Sometimes, though, it’s useful to look backwards; old techniques can lead to new ways of looking at a problem. The earliest approach to the problem of formally modeling bound variables was to eliminate them.
Abstraction elimination
-calculus is named for the binder in that language. The language itself is very simple. We start with an infinite set of variables and then define the terms to be
Schönfinkel’s idea was roughly to “sweep the binders under the rug”. We’ll allow binders, but only in the definition of a “combinator”, one of a finite set of predefined terms. We don’t allow binders in any expression using the combinators themselves; the binders will all be hidden “underneath” the name of the combinator.
To eliminate all the binders in a term, we start at the “lowest level”, a term of the form where only has variables, combinators, and applications; no abstractions! Then we’ll try to find a way of rewriting using combinators instead. Since the lambda term behaves the same as itself, if we can find some such that , then the job’s done.
Suppose . What term can we apply to and get itself back? The identity function, obviously, so our first combinator is
What if doesn’t contain at all? We need a “konstant” term such that just discards and returns At the same time, we don’t want to have to specify a different combinator for each that doesn’t contain , so we define our second combinator to first read in which to return, then read in , throw it away, and return
Finally, suppose is an application The variable might occur in or in or both. Note that if we recurse on each of the terms in the application, we’ll have terms such that and , so we can write This suggests our final combinator should read in , and and “share” with them:
If we look at the types of the terms and , we find something interesting:
The types correspond exactly to the axiom schemata for positive implicational logic!
The -calculus is a lot easier to model formally than the -calculus; we can use a tiny Gph-enriched Lawvere theory (see the appendix) to capture the operational semantics and then derive the denotational semantics from it.
-Calculus
As computers got smaller and telephony became cheaper, people started to connect them to each other. ARPANET went live in 1969, grew dramatically over the next twenty years, and eventually gave rise to the internet. ARPANET was decommissioned in 1990; that same year, Robin Milner published a paper introducing the -calculus. He designed it to model the new way computation was occurring in practice: instead of serially on a single computer, concurrently on many machines via the exchange of messages. Instead of applying one term to another, as in the lambda and SK calculi, terms (now called “processes”) get juxtaposed and then exchange messages. Also, whereas in -calculus a variable can be replaced by an entire term, in the -calculus names can only be replaced by other names.
Here’s a “good parts version” of the asynchronous -calculus; see the appendix for a full description.
There are six term constructors for -calculus instead of the three in -calculus. Concurrency is represented with a vertical bar |, which forms a commutative monoid with 0 as the monoidal unit. There are two binders, one for input and one for introducing a new name into scope. The rewrite rule is reminiscent of a trace in a compact closed category: appears in an input term and an output term on the left-hand side, while on the right-hand side doesn’t appear at all. I’ll explore that relationship in another post.
The syntax we use for the input prefix is not Milner’s original syntax. Instead, we borrowed from Scala, where the same syntax is syntactic sugar for for some monad that describes a collection. We read it as “for a message drawn from the set of messages sent on , do with it”.
For many years after Milner proposed the -calculus, researchers tried to come up with a way to eliminate the bound names from a -calculus term. Yoshida was able to give an algorithm for eliminating the bound names that come from input prefixes, but not those from new names. Like the abstraction elimination algorithm above, Yoshida’s algorithm produced a set of concurrent combinators. There’s one combinator for sending a message on the name , and several others that interact with ’s to move the computation forward (see the appendix for details):
Unlike the combinators, no one has shown a clear connection between some notion of type for these combinators and a system of logic.
Reflection
Several years ago, Greg Meredith had the idea to combine the set of -calculus names and the set of -calculus terms recursively. In a paper with Radestock he introduced a “quoting” operator I’ll write & that turns processes into names and a “dereference” operator I’ll write * that turns names into processes. They also made the calculus higher-order: they send processes on a name and receive the quoted process on the other side.
The smallest process is 0, so the smallest name is &0. The next smallest processes are
which in turn can be quoted to produce more names, and so on.
Together, these two changes let them demonstrate a -elimination transformation from calculus to their reflective higher-order (RHO) calculus: since a process never contains its own name ( cannot occur in ), one can use that fact to generate names that are fresh with respect to a process.
Another benefit of reflection is the concept of “namespaces”: since the names have internal structure, we can ask whether they satisfy propositions. This lets Meredith and Radestock define a spatial-behavioral type system like that of Caires, but more powerful. Greg demonstrated that the type system is strong enough to prevent attacks on smart contracts like the $50M one last year that caused the fork in Ethereum.
In our most recent pair of papers, Greg and I consider two different reflective higher-order concurrent combinator calculi where we eliminate all the bound variables. In the first paper, we present a reflective higher-order version of Yoshida’s combinators. In the second, we note that we can think of each of the term constructors as combinators and apply them to each other. Then we can use combinators to eliminate binders from input prefixes and Greg’s reflection idea to eliminate those from Both calculi can be expressed concisely using Gph-enriched Lawvere theories.
In future work, we intend to present a type system for the resulting combinators and show how the types give axiom schemata.
Appendix
Gph-theory of -calculus
- objects
- morphisms
- equations
- none
- edges
-calculus
- grammar
- structural equivalence
- free names
- 0 and | form a commutative monoid
- replication
- -equivalence
- where is not free in
- new names
- when is not free in
- free names
- rewrite rules
- if , then
- if , then
To be clear, the following is not an allowed reduction, because it occurs under an input prefix:
Yoshida’s combinators
- grammar
- atom:
- process:
- structural congruence
- free names
- 0 and | form a commutative monoid
- replication
- new names
- when is not free in
- free names
- rewrite rules
- (fanout)
- (drop)
- (forward)
- (branch right)
- (branch left)
- (synchronize)
- if then for any term context , .
Gph-theory of RHO Yoshida combinators
- objects
- morphisms
- equations
- 0 and | form a commutative monoid
- 0 and | form a commutative monoid
- edges
Gph-theory of RHO -like combinators
- objects
- morphisms
- equations
- 0 and | form a commutative monoid
- 0 and | form a commutative monoid
- edges
Re: Eliminating Binders for Easier Operational Semantics
has a bogus link which should be http://cs.au.dk/~ranald/Clouston_WoLLIC.pdf.
that link goes to the wrong paper already linked above.