






























































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Interaction Nets is a programming language based on graph reduction. Programming ... Also, reducing such active links at definition-time could.
Typology: Lecture notes
1 / 70
This page cannot be seen from the preview
Don't miss anything!































































Name Simon Gay
College Queens’
Project Title Interaction Nets
Examination Diploma in Computer Science 1991
Word Count Approximately 11200
Originator Dr. A. Pitts
Supervisor F.J.M. Davey
Aims of Project
To implement an interactive interpreter for the Interaction Nets language; also to investigate extensions to the basic language, understand the foundation of the language in Girard’s Linear Logic, and develop examples of programming in it.
Work Completed
The original aims of the project have been realised, with the exception of a couple of things (modularity, investigation of performance) which were in the category of areas which it might have been interesting to look at.
Special Difficulties
None.
This document describes a project based on the ideas in [1], in which Lafont proposes the language of Interaction Nets based on the proof nets of Girard’s Linear Logic [2]. The project consisted of implementing an interactive interpreter for the language, experimenting with extensions to it, developing examples of practical programming, and investigating the theoretical framework of Linear Logic and how Interaction Nets fits into it.
Firstly, the language is described, and illustrated with some simple examples. Then Linear Logic is presented via Sequent Calculus, and the connection with Interaction Nets is explained. Three classes of extension to the language are described, dealing with providing an analogue of macros in addition to functions, providing functions with side-effects, and polymorphic typing. Next, the implementation is discussed, and some example programs presented. Finally there are some further thoughts on possible future directions. A more complete description of the facilities provided by the system, formal syntax definitions, an extract from the actual program, and a copy of the original proposal can be found in the appendices.
distinguished by arrows. In a symbol definition, the first port listed is the principal port; the above definitions correctly specify the principal port of each symbol. By convention, the rest of the ports are listed in the order obtained by moving anticlockwise round the agent. Given a set of symbol definitions, a complete set of interaction rules includes just one rule for each pair of symbols whose principal ports can be connected together. For 0, S and Add, the rules are
Add
x
x
y
y
Add
Add
x x
y y z
z
Diagrams like this are the most natural way to understand interaction rules, but a textual syntax is also used. In fact, the current system only works with textual descriptions. The form of type and symbol definitions is described above, and is easily readable. It is essentially the same as the notation described by Lafont. The textual description of a net is obtained by labelling all its edges, including both free edges and internal edges, and listing the agents. Each agent appears in the list as its name followed by the labels on the edges emanating from it, in brackets. The edge labels are listed in the order in which the corresponding ports appear in the symbol definition. So the net
Add
x
y
z
is described by
Add(u,z,x),S(u,y)
or
S(u,y),Add(u,z,x).
An edge which has a free variable at each end is described by the names of the variables separated by a -.
The empty net, represented graphically by
is described textually by the single character @.
In this notation, an interaction rule consists of a pair of net descriptions separated by an arrow. The net on the left of the arrow must consist of a pair of agents connected only by their principal ports. This is different from Lafont's notation for rules, which is described in Appendix A; it is intended to be more readable than his. The rules for addition are defined by
rule Add(u,y,x),0(u) -> x-y Add(u,y,x),S(u,z) -> S(x,w),Add(z,y,w);
With the definitions given so far, the Interaction Nets system can be used to do simple calculations. For example, to calculate 2+2, the command
net Add(u,v,x),S(u,a),S(a,b),0(b),S(v,c),S(c,d),0(d);
loads the given net into the system, and the command
reduce
applies interaction rules until there are no more active links (principal ports connected together) and then produces the output
S(x,y),S(y,z),S(z,u),S(u,v),0(v)
The language of Interaction Nets is based on Linear Logic; nets generalise the proof nets of Linear Logic. The main implication of this connection is that there are linearity constraints on nets and interaction rules. In a net, all free variables must be distinct, that is, all free edges must have distinct labels. In a rule, the two sides must have precisely the same free variables. To see the impact that linearity has in practice, consider defining multiplication for unary arithmetic. Similarly to addition, the necessary symbol definition is
symbol Mult : Nat - , Nat - , Nat - ;
and rules are needed to capture the usual recursive equations
0.x = 0 (y+1).x = y.x + x.
The obvious rule for the first equation is
Mult
x
y 0
x
but this is wrong because the left side has more free variables than the right side. The problem is that the multiplication function uses its second argument non-linearly; if the first argument is zero, the second argument is discarded. To express the equations in the form of linear interaction rules, this discarding of the second argument must be made explicit by means of an agent Erase which is defined by
symbol Erase : Nat - ;
and interacts according to the rules
Erase
Dupl
x y
z
Dupl
z
x y
which allow the correct form of the second rule for Mult to be given:
Mult
x
y
z
Add
x
Mult
y
z
Dupl
Linearity is really about control of resources. Explicit duplication and deletion mean that an implementation of Interaction Nets needs no garbage collector, since no sharing of substructures is allowed.
Interaction rules must also be well-typed in that as well as the two nets in a rule being well-typed, a free variable must be attached to ports of the same type and direction on both sides of the rule. If the right hand side of a rule contains an isolated edge, the variables on thet edge must be attached in the left hand side of the rule to ports of the same type and opposite directions. It is clear that with these constraints on interaction rules, well-typed nets remain well-typed after any reductions.
It is possible to define rules which lead to non-terminating computations, such as Lafont's ‘turnstile’ example:
Stile
Turn
x
Stile
x Turn
Stile
Turn
Turn
Stile
Turn
Turn
but further constraints on nets can ensure that when a sequence of reductions terminates, the result can be interpreted as a meaningful answer rather than a deadlock situation. When reduction stops, the net reached has no active links. Consider starting from some agent and following principal ports around the net. Eventually, either a free variable is reached, or the path loops. If it is always the first case which arises, then the net represents an 'answer' and the free variables are the 'handles' which were attached
to the original problem. The net is ready to interact with its environment - if additional agents are attached to the free variables, reduction might be able to continue. But if the net contains cycles, the situation is a deadlock, and it is these cases which should be eliminated. One possibility would be to forbid the construction of any net containing cycles, but this is unnecessarily restrictive as it makes it impossible to define rules which use duplication, such as the second rule for unary multiplication. However, it is possible to distinguish betweem innocuous and pathological cycles - the programmer knows that a cycle containing a Dupl agent will be broken after a number of applications of the rules for Dupl. The solution is to divide the ports of each agent into partitions which are used in the following way. If a net is built up from the empty net by successively adding agents, which may or may not be connected to existing agents, then at any time the net consists of a number of connected components. Connecting two or more ports of a new agent to a single component forms a cycle in the net. The rule is that this can only be done if all the ports being connected to the same component are in the same partition. This guarantees that nets containing bad cycles cannot be constructed; and, since the same constraint applies to the net on the right hand side of an interaction rule, that no bad cycles can be introduced by reductions.
The default is for partitions to be discrete; non-discrete partitions are specified in a symbol definition by enclosing the relevant ports in curly brackets. So the correct definition for Dupl is
symbol Dupl : Nat - , {Nat + , Nat +} ;
This means that a partition must consist of a group of adjacent ports, so the order of the ports must be chosen in such a way that this is true. Also, when describing a net containing cycles to the Interaction Nets system, the agent which makes a cycle legal (the agent with a non-discrete partition) must be the last agent in the cycle to be listed, otherwise the system cannot check the partitioning.
Lafont specifies the ‘optimisation’ condition that the right-hand side of an interaction rule should not contain any active links; if it did, they could be reduced at definition- time to save work when reducing nets later. This condition is not enforced in the present system, because if the natural form of a rule contains active links, leaving them in makes the program clearer. Also, reducing such active links at definition-time could lead to non-termination in the parser.
Because they are used in a later example, it is worth mentioning here that lists can be represented in Interaction Nets by means of the agents
Cons
List +
Nat - List -
Nil
List +
(for lists of natural numbers); it is straightforward to write rules for list operations such as appending, as for example in the following sample run.
$ inets -pure Interaction Nets
S : Nat + , Nat - Nil : List + Cons : List + , Nat - , List - Append : List - , List - , List + ;
In this section Linear Logic is presented, and the connection with Interaction Nets explained. The exposition of Sequent Calculus, Linear Sequent Calculus and proof nets follows but expands that in [2]. The explicit description of how Interaction Nets fits in is new, although from hints in various papers it seems certain that Lafont has developed it previously.
2.1 Sequent calculus
Logical axioms and rules of inference can be presented by in Sequent Calculus, where a sequent A 1 ,..,An | B 1 ,..,Bn with the Ai and Bi logical formulae means that B 1 ∨B 2 ∨..∨Bn is the consequence of A 1 ∧A 2 ∧..∧An (where ∧ and ∨ in this context are ‘meta-connectives’, not part of logic); consequence, that is, in the sense of syntactic entailment (hence the use of the single turnstile | ); there is no notion of ‘truth’. A system in which the right-hand side of a sequent can contain several formulae is a classical system, whereas restricting sequents to be of the form A 1 ,..,An | B yields an intuitionistic system. This is the distinction between the philosophy that it is meaningful to prove A∨B without specifying which has been proved, and the intuitionist philosophy which only admits constructive proofs. In the rules below Γ, ∆,.. stand for sequences of formulae, and are used to represent the context in which a rule is being used. The interpretation of a rule of Sequent Calculus is that the sequent below the horizontal line can be deduced from those above. Thus Sequent Calculus rules are statements about how valid proofs may be constructed, for example “If from the assumptions Γ, I can prove A, and from the assumptions ∆, I can prove B, then from the assumptions Γ,∆, I can prove A∧B by ‘anding’ together the proofs of A and B”.
When the rule for ∧ described above is put into Sequent Calculus, it takes the form
Γ | A , ∆ Γ ' | B , ∆ ' Γ ,Γ ' | A∧B,∆,∆'
and there is also a slightly different rule
Γ | A , ∆ Γ | B,∆ Γ | A∧B,∆
There are also rules for introducing ∧ on the left-hand side of sequents:
Γ,A | ∆
which formalise the idea that if A∧B is known then both A and B are known individually. The rules for ∨ are similar:
Γ,A | ∆ Γ ' , B | ∆ '
Γ,Γ',A ∨B| ∆ ,∆ '
in fact, ∨ being dual to ∧, the rules are the same as those for ∧ but with left and right interchanged. There is some redundancy in this formulation of the logical rules, which will be discussed later.
There is also the identity axiom
Id
and the cut rule
Γ | A , ∆ Γ ' , A | ∆ '
Γ ,Γ ' | ∆ ,∆ '
Cut
In addition to these logical rules, the use of certain structural rules is made explicit. These rules control how hypotheses are used in a proof. The exchange rules express the fact that formulae may be written in any order:
Γ,A,B,Γ' | ∆
The weakening rule on the left allows additional hypotheses to be introduced, which may not necessarily be used in the proof (if A is not listed in Γ):
Γ | ∆
and on the right, in the classical case, allows deductions in the style of ‘If I can prove that 2+2=4, then I can prove that either 2+2=4 or the moon is made of green cheese’:
The contraction rule on the left states that a hypothesis need only be introduced into a proof once, and can then be used any number of times:
and on the right, that proving A∨A is no better than proving A:
Γ | A,A,∆ Γ | A,∆
We will not discuss quantifiers here, but it is reasonable to ask how negation and implication fit into this scheme. In particular, one might expect to introduce ⇒ together with rules
derive the rules ∨1 and ∨2 from ∨3; * is weakening, with an exchange in the first proof. Finally the proof
| A,B,Γ | A∨B,B,Γ
recovers ∨3 from ∨1 and ∨2. Thus it is sufficient to have just two logical rules, ∨3 and either ∧1 or ∧2.
Going back to the question of how to include implication, A⇒B can be introduced as a
which is obtained from the existing rules by the proof
I d (^) | A,Γ
| A∧¬B,B,Γ
Cut
This recovering of an elimination rule by using the cut rule is a general feature; the cut rule is an alternative to specifying elimination rules for each connective.
The Cut Elimination Theorem, due to Gentzen, states that occurrences of the cut rule can be eliminated from any Sequent Calculus proof which has no hypotheses (that is, from any proof of a tautology). A proof can be found in [5]. It will be seen later that cut elimination has an interesting computational interpretation.
2.2 Linear Sequent Calculus
Linear Logic will now be introduced, via Linear Sequent Calculus. Linear Logic was discovered by Girard, who noticed that in a certain model (coherence semantics) of ordinary logic, implication can be broken down into simpler operations. This view will not be discussed here; more details can be found in [2] and [3]. We just note that Linear Logic is lower-level than traditional logic in that it allows finer control of resources.
The appropriate step leading from Sequent Calculus to Linear Sequent Calculus is to discard the structural rules of weakening and contraction. The result is a system in which a proof must use each of its hypotheses exactly once; thus there is a sort of ‘conservation of propositions’ going on. The lack of weakening and contraction means that the alternative formulations of the logical rules for ∧ and ∨ are no longer equivalent. To reflect the fact that there are now two essentially different ways of using
each connective, two conjunctions and two disjunctions are introduced. The tensor product (cumulative conjunction) ⊗ (times) combines contexts:
| A , Γ | B,∆ | A⊗B,Γ,∆
while the direct product (alternative conjunction) & (with) works within a single context:
| A , Γ | B,Γ | A&B,Γ
The dual connectives
(par) for ⊗ and ⊕ (plus) for & have rules
| A,B,Γ | A
and are related to the conjunctions by de Morgan’s laws:
(A ⊗ B)⊥^ = A⊥
where ⊥^ is linear negation. As before, the introduction of negation and the use of asymmetrical sequents are purely for convenience.
Incidentally, another way to look at the splitting of each intuitionistic connective into multiplicative and additive versions, pointed out by Davey (private communication) is that if both introduction and elimination rules are given the multiplicatives are introduced like intuitionistic connectives and the additives are eliminated like them.
Units can also be introduced: 1 for ⊗, ⊥ for
, T for & and 0 for ⊕. They form two pairs of mutually linearly negated formulae, with
1 ⊥= ⊥ ⊥⊥= 1 T⊥= 0 0 ⊥= T
and rules
1 (no rule for 0 ) | T ,Γ
Discarding the contraction and weakening rules represents a significant loss of power in the logic. To recover it, contraction and weakening are brought back in a controlled form, via the introduction of the modality! (of course) and its dual? (why not):
(!A)⊥= ?A⊥^ (?A)⊥= !A⊥
with the structural rules appearing in the form of logical rules for the modalities:
where the W, C and D stand for contraction, weakening and dereliction.
2.3 Proof Nets
A proof written in Sequent Calculus contains a lot of redundancy, as contexts are rewritten without change each time a logical rule is used. The interesting features of a proof can displayed in the form of a proof net. Proof nets apply only to the so-called multiplicative fragment of Linear Logic, containing ⊗, 1,
and ⊥. These are the connectives for which the sequent rules have the property that the contexts in the
If A and B are conclusions of the same proof net ν, then
ν
is a proof net.
If ν is a proof net, then
ν ⊥
is a proof net.
And finally, 1 is a proof net.
Cut elimination in a proof net consists of rewrites:
1 ⊥ (^) (nothing)
For example, the proof net
reduces in three steps to
It can already be seen that there is a similarity between proof nets and Interaction Nets. In the next section, the connection is described in detail.
2.4 From Linear Logic to Interaction Nets
A correspondence between proofs in a constructive logic and programs in a typed programming language can be set up via the Curry-Howard Isomorphism. Logical propositions are interpreted as types, and a proof of a proposition corresponds to a
program computing a value of the corresponding type. Cut elimination, which reduces a proof to a simpler proof (one without cuts) corresponds to evaluating the program to eliminate function calls. As cut elimination proceeds, extra information is accumulated on the computational side of the correspondence, leading to the value of the final term (rather than its type) being interpreted as the result of the program. In a traditional functional programming language based on lambda calculus, the correspondence with Intuitionistic Logic can be seen; cut elimination corresponds to beta-conversion.
In this way, the relationship between the multiplicative fragment of Linear Logic and Interaction Nets can be obtained. Types of ports (of agents) correspond to propositions, and symbol definitions correspond to logical rules. An agent in a net corresponds to the use of some logical rule in a proof; a net is a proof of the propositions corresponding to the types of its free variables. In fact, the net is a graphical representation of the corresponding proof, in the way that proof nets are. Interaction between agents corresponds to cut elimination; a complete set of interaction rules is a collection of convresions making a proof of the cut elimination theorem for the logic described by the type and symbol definitions possible. Of course, this proof may not work; the non-terminating turnstile example is a logic for which the cut elimination theorem fails.
Partitioning of the ports of an agent reflects the way in which logical rules can combine different contexts (as for ⊗) or work within a single context (as for
). In the rules for constructing proof nets,
must connect twice to the same proof net, whereas a non- discrete partition of an agent’s ports merely allows the possibility. This is related to the distinction drawn by Lafont [1] between simple and semi-simple nets. A simple net is constructed by using the rules LINK (an edge), CUT (a single connection between two nets) and GRAFT (connecting a new agent to nets, according to its partition). The partitioning rule in this case demands that all ports in a partition must be connected to the same net (which will be connected, viewed as a graph); in addition, an agent such as Erase can only be introduced without a connection if its non-principal ports are all in a partition together (an empty partition, of course). This means that when Erase interacts with 0 (say), what is left is not an empty net but a lone empty partition, a distinction which is not made in the present system. But some agents of the same ‘shape’, such as 0, do not have an empty partition. This difference is clearly similar to the difference between the Sequent Calculus rules for 1 and ⊥; the rule for ⊥ involves a context (which may be empty) while that for 1 does not. A semi-simple net can be constructed using the above rules, together with the extra rules EMPTY (an empty net) and MIX (juxtaposing two nets without a connection). The present system allows semi- simple nets. It is interesting to observe that the MIX rule for constructing nets corresponds to a structural rule
| Γ | ∆
| Γ ,∆
which is not a rule of Linear Sequent Calculus. The question of whether to include this rule is discussed in [3], and decided in the negative.
More generally, Interaction Nets can be seen as corresponding to the ‘proof nets’ of multiplicative logics (in which logical rules combine contexts), not just Linear Logic. While interaction rules are linear in terms of occurrences of free variables, when the types are considered an agent such as Dupl seems to correspond to contraction. It is not clear exactly what is going on here; maybe Dupl implicitly applies modalities to its arguments.
The Interaction Nets language as described up to now allows only atomic types, and a program in it describes a logic with no connectives. But the language has been extended to allow the definition of polymorphic type constructors, corresponding to logical connectives. This extension is described, with others, in the next section.