Skip to content

Commit 4548ec8

Browse files
committed
Simulate multiplexers in 'hybrid'
1 parent 43e0089 commit 4548ec8

File tree

4 files changed

+47
-36
lines changed

4 files changed

+47
-36
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ The following is output of the `test.sh` script provided in the package:
3636

3737
```
3838
SAMPLE CLOSED OPTIMAL ABSTRACT HYBRID
39-
counter 58/6 143/4 N/A N/A
40-
w2eta 137/16 205/7 37/7 N/A
39+
counter 58/6 143/4 N/A 58/4
40+
w2eta 137/16 205/7 37/7 130/7
4141
22210ii 1740/182 7886/70 731/70 N/A
4242
3222ii 5896/545 164197/43 1182/43 N/A
4343
1022ii 23026/2085 2489461/59 4298/59 N/A
4444
4222ii 1442259/131124 N/A 262401/64 N/A
4545
222210ii 6685119/655415 N/A 2359812/201 N/A
46-
cfact4 15506/887 56890/691 3711/691 N/A
47-
yfact4 24150/1741 526971/760 4168/760 N/A
46+
cfact4 15506/887 56890/691 3711/691 77944/691
47+
yfact4 24150/1741 526971/760 4168/760 349585/760
4848
cfact5 799868/16170 3074471/13462 69147/13462 N/A
4949
yfact5 857864/22267 N/A 69780/13550 N/A
5050
```

encoding/hybrid/index.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,24 @@ const template = fs.readFileSync(path.join(__dirname, "template.txt"), "utf8");
77

88
let mkwire, bv;
99

10-
function rho(id, list)
10+
function rho(id, list, lvl)
1111
{
1212
bv[id].forEach(entry => {
1313
const wire = entry.wire;
14-
const lvl = entry.index;
14+
const delta = entry.lvl - lvl - 1;
1515
const next = mkwire();
16-
const agent = `\\fan_{${lvl}}(${next}, ${wire})`;
16+
const agent = `\\fan_{[${lvl}, ${delta}]}`;
17+
const tree = `${agent}(${next}, ${wire})`;
1718

18-
list.push(`${id} = ${agent}`);
19+
list.push(`${id} = ${tree}`);
1920

2021
id = next;
2122
});
2223

2324
list.push(`${id} = \\nil`);
2425
}
2526

26-
function gamma(obj, root, list)
27+
function gamma(obj, root, list, lvl)
2728
{
2829
const node = obj.node;
2930

@@ -38,40 +39,42 @@ function gamma(obj, root, list)
3839
const id = obj.name;
3940

4041
bv[id].push({
41-
index: obj.index,
42+
lvl: lvl,
4243
wire: root
4344
});
4445
}
4546
} else if ("abst" == node) {
4647
const id = obj.var;
4748
const body = obj.body;
4849
const wire = mkwire();
49-
let tree = "\\lam(%s, %s)";
50+
let tree = "\\lam_{%s}(%s, %s)";
5051

52+
tree = tree.replace("%s", lvl);
5153
tree = tree.replace("%s", id);
5254
tree = tree.replace("%s", wire);
5355

5456
list.push(root + " = " + tree);
5557

5658
bv[id] = [];
5759

58-
gamma(body, wire, list);
60+
gamma(body, wire, list, lvl);
5961

60-
rho(id, list);
62+
rho(id, list, lvl);
6163
} else if ("appl" == node) {
6264
const wleft = mkwire();
6365
const wright = mkwire();
6466
const left = obj.left;
6567
const right = obj.right;
66-
let agent = "\\app(%s, %s)";
68+
let agent = "\\app_{%s}(%s, %s)";
6769

70+
agent = agent.replace("%s", lvl);
6871
agent = agent.replace("%s", wright);
6972
agent = agent.replace("%s", root);
7073

7174
list.push(wleft + " = " + agent);
7275

73-
gamma(left, wleft, list);
74-
gamma(right, wright, list);
76+
gamma(left, wleft, list, lvl);
77+
gamma(right, wright, list, lvl + 1);
7578
}
7679
}
7780

@@ -84,7 +87,7 @@ function encode(generic, term)
8487
mkwire = generic.mkwire;
8588

8689
bv = {};
87-
gamma(term, "root", inconfig);
90+
gamma(term, "root", inconfig, 0);
8891

8992
inconfig.inet = template;
9093
return inconfig;

encoding/hybrid/template.txt

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,42 @@
1-
\app[\fan_{i}(a, b), \fan_{i}(c, d)] {
1+
\app_{i}[\fan_{j}(a, b), \fan_{j}(c, d)] {
22
/* Duplicate application. */
3-
++this.total;
4-
} \fan_{i}[\app(a, c), \app(b, d)];
3+
if (j[0] < i)
4+
++this.total;
5+
else
6+
return false;
7+
} \fan_{j}[\app_{i}(a, c), \app_{i + j[1]}(b, d)];
58

6-
\fan_{i}[\lam(a, b), \lam(c, d)] {
9+
\fan_{i}[\lam_{j}(a, b), \lam_{j + i[1]}(c, d)] {
710
/* Duplicate abstraction. */
8-
++this.total;
9-
} \lam[\fan_{i}(a, c), \fan_{i}(b, d)];
11+
if (i[0] < j)
12+
++this.total;
13+
else
14+
return false;
15+
} \lam_{j}[\fan_{i}(a, c), \fan_{i}(b, d)];
1016

1117
\fan_{i}[a, b] {
1218
/* Annihilate matching fans. */
13-
if (i == j)
19+
if (i[0] == j[0])
1420
++this.total;
1521
else
1622
return false;
1723
} \fan_{j}[a, b];
1824

19-
\fan_{i}[\fan_{j}(a, b), \fan_{j}(c, d)] {
25+
\fan_{i}[\fan_{j}(a, b), \fan_{[j[0] + i[1], j[1]]}(c, d)] {
2026
/* Duplicate different fans. */
21-
if (i != j)
27+
if (i[0] < j[0])
2228
++this.total;
2329
else
2430
return false;
2531
} \fan_{j}[\fan_{i}(a, c), \fan_{i}(b, d)];
2632

27-
\app[a, b] {
33+
\app_{i}[a, b] {
2834
/* Apply beta reduction. */
29-
++this.beta;
30-
++this.total;
31-
} \lam[a, b];
35+
if (i == j)
36+
++this.beta, ++this.total;
37+
else
38+
return false;
39+
} \lam_{j}[a, b];
3240

3341
\fan_{i}[\atom_{M}, \atom_{M}] {
3442
/* Duplicate an atom. */
@@ -49,9 +57,9 @@
4957
\read_{C}[a] {
5058
/* Read back abstraction. */
5159
++this.total;
52-
} \lam[\atom_{this.mkid()}, \read_{this.abst(C)}(a)];
60+
} \lam_{i}[\atom_{this.mkid()}, \read_{this.abst(C)}(a)];
5361

54-
\app[\read_{this.appl(M)}(a), a] {
62+
\app_{i}[\read_{this.appl(M)}(a), a] {
5563
/* Read back application. */
5664
++this.total;
5765
} \atom_{M};

test.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ printf "$TERMF$CELLF$CELLF$CELLF$CELLF\n" SAMPLE \
3434
CLOSED OPTIMAL ABSTRACT HYBRID
3535

3636
compare counter "v1: v1 (v2: v2 v2) (v3: v3 v3)" \
37-
closed optimal abstract HYBRID
37+
closed optimal abstract hybrid
3838

3939
compare w2eta "v1, v2: v1 (v1 (v1 (v1 v2)))" \
40-
closed optimal abstract HYBRID
40+
closed optimal abstract hybrid
4141

4242
compare 22210ii "v1: v1" \
4343
closed optimal abstract HYBRID
@@ -55,10 +55,10 @@ compare 222210ii "v1: v1" \
5555
closed OPTIMAL abstract HYBRID
5656

5757
compare cfact4 "v1, v2: v1 (v1 (v1 v2))" \
58-
closed optimal abstract HYBRID
58+
closed optimal abstract hybrid
5959

6060
compare yfact4 "v1, v2: v1 (v1 (v1 v2))" \
61-
closed optimal abstract HYBRID
61+
closed optimal abstract hybrid
6262

6363
compare cfact5 "v1, v2: v1 (v1 (v1 (v1 (v1 v2))))" \
6464
closed optimal abstract HYBRID

0 commit comments

Comments
 (0)