# Symmetric λ-calculus

Symmetric λ-calculus is a generalization of λ-calculus to make contexts and terms more on par with each other, though it follows that one needs to leave terms alone (almost) and introduce ntexts instead (called “out contexts” vs. “in contexts” below). You should definitely blame User:arseniiv for making this essential thing in March, 2020. Here, a simply typed variant is given.

Parts marked as NB are notes to myself.

## Syntax

Variables ${\displaystyle x,y}$.

Types ${\displaystyle T,U::=\alpha ,\beta ,\ldots \mid \bullet \mid T\succ U\mid T\to U}$.

In and out contexts ${\displaystyle \Gamma ,\Delta ::=\varepsilon \mid \Gamma ,x:T}$.

Terms ${\displaystyle t,u::=x\mid t+u\mid tu\mid x.t\mid t\,{.}x}$.

Only well-typed terms ${\displaystyle t}$ are considered, for which a typing ${\displaystyle \Gamma \vdash t:T\dashv \Delta }$ is proven. Typing rules are the following:

• ${\displaystyle \Gamma ,x:T\vdash x:T\succ \bullet \dashv \Delta }$.
• ${\displaystyle \Gamma \vdash y:\bullet \to U\dashv \Delta ,y:U}$.
• ${\displaystyle \Gamma \vdash t+u:T\dashv \Delta }$ whether ${\displaystyle \Gamma \vdash t:T\dashv \Delta }$ and ${\displaystyle \Gamma \vdash u:T\dashv \Delta }$.
• ${\displaystyle \Gamma \vdash tu:U\dashv \Delta }$ whether ${\displaystyle \Gamma \vdash t:T\succ U\dashv \Delta }$ and ${\displaystyle \Gamma \vdash u:U\to T\dashv \Delta }$. [NB: I need to check if ${\displaystyle t,u}$ can have more general types or, conversely, even these two aren’t correct (vs. the case when ${\displaystyle T=\bullet }$.]
• ${\displaystyle \Gamma \vdash t\,{.}x:T\succ U\dashv \Delta }$ whether ${\displaystyle \Gamma ,x:T\vdash t:U\dashv \Delta }$.
• ${\displaystyle \Gamma \vdash y.t:U\to T\dashv \Delta }$ whether ${\displaystyle \Gamma \vdash t:T\dashv \Delta ,y:U}$.

## Semantics

There is a reduction akin to β-reduction from the usual calculus, ${\displaystyle (t\,{.}x)(y.u)\to _{\beta }[t,x;y,u]}$. Informally, ${\displaystyle [t,x;y,u]}$ is a plumbing of all free ${\displaystyle x}$ in ${\displaystyle t}$ to all free ${\displaystyle y}$ in ${\displaystyle u}$. I’ll define this function formally a bit later. [NB: do it!]

Note as we presuppose ${\displaystyle (t\,{.}x)(y.u)}$ well-typed, we should have ${\displaystyle \Gamma ,x:T\vdash t:U\dashv \Delta }$ and ${\displaystyle \Gamma \vdash u:U\dashv \Delta ,y:T}$.

I think this system is equivalent to λ-calculus if one restricts term formation in the following way: ${\displaystyle t+u}$ is a half-restricted term iff, inductively, ${\displaystyle t,u}$ each is a half-restricted term or is of form ${\displaystyle xy}$; and a half-restricted term is restricted iff it does have no two different ${\displaystyle xy,x'y}$ subterms for any ${\displaystyle y}$. A restricted term represents a mapping from out-variables to in-variables, i. e. each output gets a value from a single input. Now, only restricted ${\displaystyle t+u}$ terms are allowed (of those), and we should also forbid to abstract on an out-variable not occurring in a term (${\displaystyle y.t}$ is invalid if ${\displaystyle y}$ is not free in ${\displaystyle t}$).

How should one treat the unrestricted terms is up to the future. There are at least three possibilities: many simultaneous outputs and many alternative outputs, with choice being on a caller or a callee.

To be continued maybe.

## Compared to the usual calculus

With the current choice of syntax, the old abstraction ${\displaystyle \lambda x.t}$ corresponds to the backwards one ${\displaystyle t\,{.}x}$. All terms now have variables representing their value(s). For example, old ${\displaystyle x}$ is mapped to ${\displaystyle xy}$, old ${\displaystyle \lambda x.x}$ is mapped to ${\displaystyle y.xy\,{.}x}$ (there should be no need to distinguish the order in which complementary abstractions are added) [NB: make sure].

I added ${\displaystyle +}$ to be able to represent something like ${\displaystyle \lambda x.(fx)x}$, but now I can’t make anything out of it. Maybe I should rethink the way application is defined. [NB: ???]