Interaction nets

From HandWiki

Interaction nets are a graphical model of computation devised by Yves Lafont in 1990[1] as a generalisation of the proof structures of linear logic. An interaction net system is specified by a set of agent types and a set of interaction rules. Interaction nets are an inherently distributed model of computation in the sense that computations can take place simultaneously in many parts of an interaction net, and no synchronisation is needed. The latter is guaranteed by the strong confluence property of reduction in this model of computation. Thus interaction nets provide a natural language for massive parallelism. Interaction nets are at the heart of many implementations of the lambda calculus, such as efficient closed reduction[2] and optimal, in Lévy's sense, Lambdascope.[3]

Definitions

Interactions nets are graph-like structures consisting of agents and edges.

An agent of type [math]\displaystyle{ \alpha }[/math] and with arity [math]\displaystyle{ \text{ar}(\alpha) = n \ge 0 }[/math] has one principal port and [math]\displaystyle{ n }[/math] auxiliary ports. Any port can be connected to at most one edge. Ports that are not connected to any edge are called free ports. Free ports together form the interface of an interaction net. All agent types belong to a set [math]\displaystyle{ \Sigma }[/math] called signature.

An interaction net that consists solely of edges is called a wiring and usually denoted as [math]\displaystyle{ \omega }[/math]. A tree [math]\displaystyle{ t }[/math] with its root [math]\displaystyle{ x }[/math] is inductively defined either as an edge [math]\displaystyle{ x }[/math], or as an agent [math]\displaystyle{ \alpha }[/math] with its free principal port [math]\displaystyle{ x }[/math] and its auxiliary ports [math]\displaystyle{ x_i }[/math] connected to the roots of other trees [math]\displaystyle{ t_i }[/math].

Graphically, the primitive structures of interaction nets can be represented as follows:

Primitives of Interaction Nets

When two agents are connected to each other with their principal ports, they form an active pair. For active pairs one can introduce interaction rules which describe how the active pair rewrites to another interaction net. An interaction net with no active pairs is said to be in normal form. A signature [math]\displaystyle{ \Sigma }[/math] (with [math]\displaystyle{ \text{ar}: \Sigma \rightarrow \mathbb{N} }[/math] defined on it) along with a set of interaction rules defined for agents [math]\displaystyle{ \alpha \in \Sigma }[/math] together constitute an interaction system.

Interaction calculus

Textual representation of interaction nets is called the interaction calculus[4] and can be seen as a programming language.

Inductively defined trees correspond to terms [math]\displaystyle{ t ::= \alpha(t_1, \dots, t_n)\ |\ x }[/math] in the interaction calculus, where [math]\displaystyle{ x }[/math] is called a name.

Any interaction net [math]\displaystyle{ N }[/math] can be redrawn using the previously defined wiring and tree primitives as follows:

Interaction Net as Configuration

which in the interaction calculus corresponds to a configuration

[math]\displaystyle{ c \equiv \langle t_1, \dots, t_m \ |\ v_1 = w_1, \dots, v_n = w_n \rangle }[/math],

where [math]\displaystyle{ t_i }[/math], [math]\displaystyle{ v_i }[/math], and [math]\displaystyle{ w_i }[/math] are arbitrary terms. The ordered sequence [math]\displaystyle{ t_1,...,t_m }[/math] in the left-hand side is called an interface, while the right-hand side contains an unordered multiset of equations [math]\displaystyle{ v_i = w_i }[/math]. Wiring [math]\displaystyle{ \omega }[/math] translates to names, and each name has to occur exactly twice in a configuration.

Just like in the [math]\displaystyle{ \lambda }[/math]-calculus, the interaction calculus has the notions of [math]\displaystyle{ \alpha }[/math]-conversion and substitution naturally defined on configurations. Specifically, both occurrences of any name can be replaced with a new name if the latter does not occur in a given configuration. Configurations are considered equivalent up to [math]\displaystyle{ \alpha }[/math]-conversion. In turn, substitution [math]\displaystyle{ t[x := u] }[/math] is the result of replacing the name [math]\displaystyle{ x }[/math] in a term [math]\displaystyle{ t }[/math] with another term [math]\displaystyle{ u }[/math] if [math]\displaystyle{ x }[/math] has exactly one occurrence in the term [math]\displaystyle{ t }[/math].

Any interaction rule can be graphically represented as follows:

Interaction Rule

where [math]\displaystyle{ \alpha, \beta \in \Sigma }[/math], and the interaction net [math]\displaystyle{ N }[/math] on the right-hand side is redrawn using the wiring and tree primitives in order to translate into the interaction calculus as [math]\displaystyle{ \alpha[v_1,\dots, v_m] \bowtie \beta[w_1,\dots, w_n] }[/math] using Lafont's notation.

The interaction calculus defines reduction on configurations in more details than seen from graph rewriting defined on interaction nets. Namely, if [math]\displaystyle{ \alpha[v_1,\dots, v_m] \bowtie \beta[w_1,\dots,w_n] }[/math], the following reduction:

[math]\displaystyle{ \langle \vec t\ |\ \alpha(t_1,\dots,t_m) = \beta(u_1,\dots,u_n), \Delta\rangle \rightarrow \langle \vec t\ |\ t_1 = v_1,\dots, t_m = v_m, u_1 = w_1,\dots, u_n = w_n, \Delta\rangle }[/math]

is called interaction. When one of equations has the form of [math]\displaystyle{ x = u }[/math], indirection can be applied resulting in substitution of the other occurrence of the name [math]\displaystyle{ x }[/math] in some term [math]\displaystyle{ t }[/math]:

[math]\displaystyle{ \langle \dots t \dots \ |\ x = u, \Delta\rangle \rightarrow \langle \dots t[x := u] \dots \ |\ \Delta\rangle }[/math] or [math]\displaystyle{ \langle \vec t\ |\ x = u, t = w, \Delta\rangle \rightarrow \langle \vec t\ |\ t[x := u] = w, \Delta \rangle }[/math].

An equation [math]\displaystyle{ x = t }[/math] is called a deadlock if [math]\displaystyle{ x }[/math] has occurrence in term [math]\displaystyle{ t }[/math]. Generally only deadlock-free interaction nets are considered. Together, interaction and indirection define the reduction relation on configurations. The fact that configuration [math]\displaystyle{ c }[/math] reduces to its normal form [math]\displaystyle{ c' }[/math] with no equations left is denoted as [math]\displaystyle{ c \downarrow c' }[/math].

Properties

Interaction nets benefit from the following properties:

  • locality (only active pairs can be rewritten);
  • linearity (each interaction rule can be applied in constant time);
  • strong confluence also known as one-step diamond property (if [math]\displaystyle{ c \rightarrow c_1 }[/math] and [math]\displaystyle{ c \rightarrow c_2 }[/math], then [math]\displaystyle{ c_1 \rightarrow c' }[/math] and [math]\displaystyle{ c_2 \rightarrow c' }[/math] for some [math]\displaystyle{ c' }[/math]).

These properties together allow massive parallelism.

Interaction combinators

One of the simplest interaction systems that can simulate any other interaction system is that of interaction combinators.[5] Its signature is [math]\displaystyle{ \Sigma = \{\epsilon, \delta, \gamma\} }[/math] with [math]\displaystyle{ \text{ar}(\epsilon) = 0 }[/math] and [math]\displaystyle{ \text{ar}(\delta) = \text{ar}(\gamma) = 2 }[/math]. Interaction rules for these agents are:

  • [math]\displaystyle{ \epsilon \bowtie \alpha[\epsilon,\dots, \epsilon] }[/math] called erasing;
  • [math]\displaystyle{ \delta[\alpha(x_1,\dots, x_n), \alpha(y_1,\dots, y_n)] \bowtie \alpha[\delta(x_1, y_1),\dots, \delta(x_n, y_n)] }[/math] called duplication;
  • [math]\displaystyle{ \delta[x, y] \bowtie \delta[x, y] }[/math] and [math]\displaystyle{ \gamma[x, y] \bowtie \gamma[y, x] }[/math] called annihilation.

Graphically, the erasing and duplication rules can be represented as follows:

Examples of Interaction Nets

with an example of a non-terminating interaction net that reduces to itself. Its infinite reduction sequence starting from the corresponding configuration in the interaction calculus is as follows:

[math]\displaystyle{ \begin{align} &\langle \varnothing\ |\ \delta(\epsilon, x) = \gamma(x, \epsilon)\rangle \rightarrow \\ &\langle \varnothing\ |\ \epsilon = \gamma(x_1, x_2),\ x = \gamma(y_1, y_2),\ x = \delta(x_1, y_1),\ \epsilon = \delta(x_2, y_2)\rangle \rightarrow^* \\ &\langle \varnothing\ |\ x_1 = \epsilon,\ x_2 = \epsilon,\ x = \gamma(y_1, y_2),\ x = \delta(x_1, y_1),\ x_2 = \epsilon,\ y_2 = \epsilon\rangle \rightarrow^* \\ &\langle \varnothing\ |\ \delta(\epsilon, x) = \gamma(x, \epsilon)\rangle \rightarrow \dots \end{align} }[/math]

Non-deterministic extension

Interaction nets are essentially deterministic and cannot model non-deterministic computations directly. In order to express non-deterministic choice, interaction nets need to be extended. In fact, it is sufficient to introduce just one agent [math]\displaystyle{ \text{amb} }[/math][6] with two principal ports and the following interaction rules:

Non-deterministic Agent

This distinguished agent represents ambiguous choice and can be used to simulate any other agent with arbitrary number of principal ports. For instance, it allows to define a [math]\displaystyle{ \text{ParallelOr} }[/math] boolean operation that returns true if any of its arguments is true, independently of the computation taking place in the other arguments.

See also

References

  1. Lafont, Yves (1990). "Interaction nets". Proceedings of the 17th ACM SIGPLAN-SIGACT symposium on Principles of programming languages - POPL '90. ACM. pp. 95–108. doi:10.1145/96709.96718. ISBN 0897913434. 
  2. Mackie, Ian (2008). "An Interaction Net Implementation of Closed Reduction". Implementation and Application of Functional Languages: 20th International Symposium. Lecture Notes in Computer Science 5836: 43–59. doi:10.1007/978-3-642-24452-0_3. ISBN 978-3-642-24451-3. 
  3. van Oostrom, Vincent; van de Looij, Kees-Jan; Zwitserlood, Marijn (2010). Lambdascope: Another optimal implementation of the lambda-calculus. http://www.phil.uu.nl/~oostrom/publication/pdf/lambdascope.pdf. 
  4. Fernández, Maribel; Mackie, Ian (1999). "A calculus for interaction nets". Principles and Practice of Declarative Programming. Lecture Notes in Computer Science (Springer) 1702: 170–187. doi:10.1007/10704567. ISBN 978-3-540-66540-3. 
  5. Lafont, Yves (1997). "Interaction Combinators". Information and Computation (Academic Press, Inc.) 137 (1): 69–101. doi:10.1006/inco.1997.2643. 
  6. Fernández, Maribel; Khalil, Lionel (2003). "Interaction Nets with McCarthy's Amb: Properties and Applications". Nordic Journal of Computing 10 (2): 134–162. https://www.researchgate.net/publication/220369522. 

Further reading

  • Asperti, Andrea; Guerrini, Stefano (1998). The Optimal Implementation of Functional Programming Languages. Cambridge Tracts in Theoretical Computer Science. 45. Cambridge University Press. ISBN 9780521621120. 
  • Fernández, Maribel (2009). "Interaction-Based Models of Computation". Models of Computation: An Introduction to Computability Theory. Springer Science & Business Media. pp. 107–130. ISBN 9781848824348. 

External links