<p>This is NOT a complete answer yet, as I provide no proof. But, my rough understanding right now is that we can check if two <strong>ports</strong> are identical by moving a &quot;signal&quot; forward until the root node is reached, and checking if the paths traversed are the same. This (should?) correspond computationally to Mazza's notion of observational equivalence, where 2 nets are equal if they produce the same observable axioms under any context.</p>
<p>The way a signal moves is similar to the machine described by Lafont in the original paper. When entering an aux port, the signal moves to the main port and adds the entered direction to a deque. When entering a main port, it pops a direction from the deque, and moves to it. If there is no direction to pop, it instead moves to both directions, <strong>and prepends them to the other argument's deque</strong>. For example, if the signal 'a' is entering a main port, and if its deque is empty, then it splits, recurses towards both aux ports, and prepends the chosen direction to the 'b' deque. This creates a &quot;debt&quot; that forces 'b' to follow the same path as 'a', and vice-versa. When reaching the root, the deques (i.e., unconsumed paths) are compared for equality. For example, below are 2 equivalent nets:</p>
<p><a href="https://i.sstatic.net/AFHqE.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/AFHqE.png" alt="identical" /></a></p>
<p>Highlighted in red are signals traversing through the nets, starting from the same port, and ending on the root. On the left net, the signal splits and traverses two paths. On the right, it traverses only one path. Regardless, the unconsumed paths are the same. This is true for all possible signals, thus, these nets are equivalent. Here is another example:</p>
<p><a href="https://i.sstatic.net/nqewf.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/nqewf.png" alt="other" /></a></p>
<p>In this case, in both nets the signal splits, yet the leftover paths on both branches are still identical. Note I'm not drawing the complete path, I'm stopping at the first aux port, but it should extend towards root. Also keep in mind there are actually two roots: where the signal started (local root), and the network global root. Reaching the local root is akin to reaching the top of the terms you want to compare. Reaching the global root is akin to finding a free variable.</p>
<p>Here is a pseudocode of how the algorithm would look like:</p>
<pre><code>Equality on Interaction Combinators

A Path is a deque of aux slots (1 or 2)

&gt; type Slot = 1 | 2
&gt; type Path = [Slot]

A cursor has a root port, a prev port, and a map of paths

&gt; type Cursor = { root: Port, prev: Port, path: Map&lt;Kind, Path&gt; }

The equality function returns if two nets are equal

&gt; eq : INet -&gt; Cursor -&gt; Cursor -&gt; Bool

If we're on root, compare both deque maps

&gt; eq a am b bm = am == bm

If main port, non-empty deque: pop_back a slot from this deque, and move to it

&gt; eq ak#[*a0 a1 a2] {[ak]:(1,ap),..am} b bm = eq a1 {[ak]:ap,..am} b bm
&gt; eq ak#[*a0 a1 a2] {[ak]:(2,ap),..am} b bm = eq a2 {[ak]:ap,..am} b bm

If main port, empty deque: push_front [1,2] slots to the other deque, and move to both

&gt; eq ak#[*a0 a1 a2] {[ak]:ap,..am} b {[ak]:bs,..bm} = eq a1 ap b {[ak]:(bs,1),..bm}
                                                    &amp; eq a2 ap b {[ak]:(bs,2),..bm}

If aux port, push_back it to this deque, and move to main port

&gt; eq ak[a0 *a1 a2] {[ak]:ap,..am} b bm = eq a1 {[ak]:(1,ap),..am} b bm
&gt; eq ak[a0 a1 *a2] {[ak]:ap,..am} b bm = eq a1 {[ak]:(2,ap),..am} b bm

The rules above that match on 'a' are repeated for 'b'.
</code></pre>
<p>In the notation above, <code>k#[a b c]</code> stands for an interaction combinator node with label <code>k</code> and ports <code>a</code>, <code>b</code>, <code>c</code>, with <code>a</code> being the main port. The <code>*</code> stands for the port we're entering from on the recursive call. The <code>{...}</code> notation represents a map of deques, using a JS-like spread operator notation. I use <code>(1,ad)</code> to prepend <code>1</code> to the deque <code>ad</code>, and <code>(ad,1)</code> to append <code>1</code> to it. A complete implementation of interaction combinators, including this equality function, is available on <a href="https://gist.github.com/VictorTaelin/cdd2e9573e7c498611b53cd6a83ca268" rel="nofollow noreferrer">this</a> Rust file.</p>
<p>Also, I suspect this is essentially just constructing an edifice, so, there is nothing new here - but I don't understand edifices well enough to say for sure. Yet, by moving both signals alternatively, we can attempt to synchronize them and &quot;untie the knot&quot; to check equality on fixed points (<a href="https://pbs.twimg.com/media/FwiG4ExWwAAPFCd?format=jpg&amp;name=medium" rel="nofollow noreferrer">example</a>). Moreover, this algorithm can be made more flexible by simply considering only the deques with a specific label (ex: 0) on the base case. This allows us to have &quot;duplication-invariant&quot; equality, which is interesting because it imples same λ-calculus read-back, answering my <a href="https://cstheory.stackexchange.com/questions/52873/is-there-an-efficient-algorithm-to-check-for-duplicator-invariant-equivalence-on">earlier</a> question.</p>
<p>Again, keep in mind this is an initial idea and could be wrong. I provide no proof yet, but it seems to work in initial tests, and make logical sense.</p>
<p>Edit: since the explanation above is a little bit confusing, here is a simplified algorithm in pseudocode:</p>
<pre><code>def equal(a: Cursor, b: Cursor) -&gt; Bool:
  s = a.target_slot()
  k = a.target_kind()

  // If both loops are complete, compare deques
  if a.done() &amp;&amp; b.done():
    return a.deque[0] == b.deque[0] // [0] for con equality

  // if 'a' loop is complete, swap (to move 'b')
  if a.done():
    return equal(b, a)

  // If 'a' on main and deque is empty, split the signal
  if s == 0 &amp;&amp; a.deque[k].empty():
    a1 = a.clone().move(1)
    a2 = a.clone().move(2)
    b1 = b.clone()
    b2 = b.clone()
    b.deque[k].prepend(1)
    b.deque[k].prepend(2)
    return equal(a1, b1) &amp;&amp; equal(a2, b2)

  // If 'a' on main and deque is full, pop and move down
  if s == 0 &amp;&amp; !a.deque[k].empty():
    a.move(a.deque[k].pop())
    return equal(a, b)

  // If 'a' is an aux port, push and move up
  if s &gt; 0:
    a.deque[k].push(s)
    a.move(0)
    return equal(a, b)
</code></pre>
<p>For discussions on how this can be done, please check <a href="https://discord.com/channels/912426566838013994/915345481675186197/1109236255662821457" rel="nofollow noreferrer">https://discord.com/channels/912426566838013994/915345481675186197/1109236255662821457</a></p>

CC BY-SA 4.0
2023-05-31T03:19:14.670Z
2023-06-03T22:14:11.330Z
2023-06-03T22:14:11.330Z
MaiaVictor
<p>Symmetric interaction combinators are a graph-rewriting model of deterministic computation derived from Lafont's interaction nets. In the paper &quot;Observational Equivalence and Full Abstraction in the Symmetric Interaction Combinators&quot; [<a href="https://i.sstatic.net/HZTG2.png" rel="nofollow noreferrer">1</a>], a notion of observational equivalence is defined, identifying two interaction nets when they produce the same set of observable axioms in any context. Interestingly, and as on the λ-calculus, this notion admits a set of η-equivalence rules:</p>
<p><a href="https://i.sstatic.net/HZTG2.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/HZTG2.png" alt="n-equiv" /></a></p>
<p>Unlike the λ-calculus, though, η-equivalence isn't trivial, and can demand a complex series of rewrites to equate two sides. For example, both nets below are η-equivalent, even though it isn't immediately obvious:</p>
<p><a href="https://i.sstatic.net/4DslL.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/4DslL.png" alt="equivalent_nets" /></a></p>
<p><strong>Is there an efficient algorithm for determining whether two normalized symmetric interaction nets are observationally equivalent?</strong></p>
<p>[<a href="https://i.sstatic.net/HZTG2.png" rel="nofollow noreferrer">1</a>] Mazza, D. (2012). Observational Equivalence and Full Abstraction in the Symmetric Interaction Combinators. Logical Methods in Computer Science, Volume 5, Issue 4, lmcs:1150. <a href="https://arxiv.org/pdf/0906.0380.pdf" rel="nofollow noreferrer">link</a></p>

CC BY-SA 4.0
2023-05-27T15:14:49.747Z
Note: I've previously asked if there is an algorithm to check if two nets are equivalent, under a specific and incomplete equivalence relation that I defined on the post. Now, I realize that even the standard notion is lacking a published algorithm. Since the original thread was, admittedly, not very well written, and given it already received a great answer in the way it was asked, believe it is best to post this as a separate question. This is central problem that other people could need to solve a future.
MaiaVictor
CC BY-SA 4.0
2023-07-11T16:00:44.750Z
https://github.com/VictorTaelin/Interaction-Type-Theory
MaiaVictor
<type-theory><interaction-nets><equivalence><interaction-combinators>
What is an efficient algorithm to check for equivalence on symmetric interaction combinators?
MaiaVictor
# What is an efficient algorithm to check for equivalence on symmetric interaction combinators?

(Asked by: username_0 on 2023-05-27)

Symmetric interaction combinators are a graph-rewriting model of deterministic computation derived from Lafont's interaction nets. In the paper "Observational Equivalence and Full Abstraction in the Symmetric Interaction Combinators" [[1](https://i.sstatic.net/HZTG2.png)], a notion of observational equivalence is defined, identifying two interaction nets when they produce the same set of observable axioms in any context. Interestingly, and as on the λ-calculus, this notion admits a set of η-equivalence rules:

[![n-equiv](https://i.sstatic.net/HZTG2.png)](https://i.sstatic.net/HZTG2.png)

Unlike the λ-calculus, though, η-equivalence isn't trivial, and can demand a complex series of rewrites to equate two sides. For example, both nets below are η-equivalent, even though it isn't immediately obvious:

[![equivalent_nets](https://i.sstatic.net/4DslL.png)](https://i.sstatic.net/4DslL.png)

**Is there an efficient algorithm for determining whether two normalized symmetric interaction nets are observationally equivalent?**

[[1](https://i.sstatic.net/HZTG2.png)] Mazza, D. (2012). Observational Equivalence and Full Abstraction in the Symmetric Interaction Combinators. Logical Methods in Computer Science, Volume 5, Issue 4, lmcs:1150. [link](https://arxiv.org/pdf/0906.0380.pdf)

**Tags:** type-theory, interaction-nets, equivalence, interaction-combinators
> **Comments:**
> **username_0**: Note: I've previously asked if there is an algorithm to check if two nets are equivalent, under a specific and incomplete equivalence relation that I defined on the post. Now, I realize that even the standard notion is lacking a published algorithm. Since the original thread was, admittedly, not very well written, and given it already received a great answer in the way it was asked, believe it is best to post this as a separate question. This is central problem that other people could need to solve a future.  
> **username_0**: https://github.com/VictorTaelin/Interaction-Type-Theory  

---

## 1 answers

### Answer by username_0 on 2023-05-31. Score: 1

This is NOT a complete answer yet, as I provide no proof. But, my rough understanding right now is that we can check if two ports are identical by moving a "signal" forward until the root node is reached, and checking if the paths traversed are the same. This (should?) correspond computationally to Mazza's notion of observational equivalence, where 2 nets are equal if they produce the same observable axioms under any context.
The way a signal moves is similar to the machine described by Lafont in the original paper. When entering an aux port, the signal moves to the main port and adds the entered direction to a deque. When entering a main port, it pops a direction from the deque, and moves to it. If there is no direction to pop, it instead moves to both directions, and prepends them to the other argument's deque. For example, if the signal 'a' is entering a main port, and if its deque is empty, then it splits, recurses towards both aux ports, and prepends the chosen direction to the 'b' deque. This creates a "debt" that forces 'b' to follow the same path as 'a', and vice-versa. When reaching the root, the deques (i.e., unconsumed paths) are compared for equality. For example, below are 2 equivalent nets:

Highlighted in red are signals traversing through the nets, starting from the same port, and ending on the root. On the left net, the signal splits and traverses two paths. On the right, it traverses only one path. Regardless, the unconsumed paths are the same. This is true for all possible signals, thus, these nets are equivalent. Here is another example:

In this case, in both nets the signal splits, yet the leftover paths on both branches are still identical. Note I'm not drawing the complete path, I'm stopping at the first aux port, but it should extend towards root. Also keep in mind there are actually two roots: where the signal started (local root), and the network global root. Reaching the local root is akin to reaching the top of the terms you want to compare. Reaching the global root is akin to finding a free variable.
Here is a pseudocode of how the algorithm would look like:
Equality on Interaction Combinators

A Path is a deque of aux slots (1 or 2)

> type Slot = 1 | 2
> type Path = [Slot]

A cursor has a root port, a prev port, and a map of paths

> type Cursor = { root: Port, prev: Port, path: Map }

The equality function returns if two nets are equal

> eq : INet -> Cursor -> Cursor -> Bool

If we're on root, compare both deque maps

> eq a am b bm = am == bm

If main port, non-empty deque: pop_back a slot from this deque, and move to it

> eq ak#[*a0 a1 a2] {[ak]:(1,ap),..am} b bm = eq a1 {[ak]:ap,..am} b bm
> eq ak#[*a0 a1 a2] {[ak]:(2,ap),..am} b bm = eq a2 {[ak]:ap,..am} b bm

If main port, empty deque: push_front [1,2] slots to the other deque, and move to both

> eq ak#[*a0 a1 a2] {[ak]:ap,..am} b {[ak]:bs,..bm} = eq a1 ap b {[ak]:(bs,1),..bm}
                                                    & eq a2 ap b {[ak]:(bs,2),..bm}

If aux port, push_back it to this deque, and move to main port

> eq ak[a0 *a1 a2] {[ak]:ap,..am} b bm = eq a1 {[ak]:(1,ap),..am} b bm
> eq ak[a0 a1 *a2] {[ak]:ap,..am} b bm = eq a1 {[ak]:(2,ap),..am} b bm

The rules above that match on 'a' are repeated for 'b'.

In the notation above, k#[a b c] stands for an interaction combinator node with label k and ports a, b, c, with a being the main port. The * stands for the port we're entering from on the recursive call. The {...} notation represents a map of deques, using a JS-like spread operator notation. I use (1,ad) to prepend 1 to the deque ad, and (ad,1) to append 1 to it. A complete implementation of interaction combinators, including this equality function, is available on this Rust file.
Also, I suspect this is essentially just constructing an edifice, so, there is nothing new here - but I don't understand edifices well enough to say for sure. Yet, by moving both signals alternatively, we can attempt to synchronize them and "untie the knot" to check equality on fixed points (example). Moreover, this algorithm can be made more flexible by simply considering only the deques with a specific label (ex: 0) on the base case. This allows us to have "duplication-invariant" equality, which is interesting because it imples same λ-calculus read-back, answering my earlier question.
Again, keep in mind this is an initial idea and could be wrong. I provide no proof yet, but it seems to work in initial tests, and make logical sense.
Edit: since the explanation above is a little bit confusing, here is a simplified algorithm in pseudocode:
def equal(a: Cursor, b: Cursor) -> Bool:
  s = a.target_slot()
  k = a.target_kind()

  // If both loops are complete, compare deques
  if a.done() && b.done():
    return a.deque[0] == b.deque[0] // [0] for con equality

  // if 'a' loop is complete, swap (to move 'b')
  if a.done():
    return equal(b, a)

  // If 'a' on main and deque is empty, split the signal
  if s == 0 && a.deque[k].empty():
    a1 = a.clone().move(1)
    a2 = a.clone().move(2)
    b1 = b.clone()
    b2 = b.clone()
    b.deque[k].prepend(1)
    b.deque[k].prepend(2)
    return equal(a1, b1) && equal(a2, b2)

  // If 'a' on main and deque is full, pop and move down
  if s == 0 && !a.deque[k].empty():
    a.move(a.deque[k].pop())
    return equal(a, b)

  // If 'a' is an aux port, push and move up
  if s > 0:
    a.deque[k].push(s)
    a.move(0)
    return equal(a, b)

For discussions on how this can be done, please check https://discord.com/channels/912426566838013994/915345481675186197/1109236255662821457


---

