|
4 | 4 | ++this.total; |
5 | 5 | } \lambda[a, b]; |
6 | 6 |
|
7 | | -\apply[ |
8 | | - \fan_{[i[0], i[1] + 1]}(a, b), |
9 | | - \fan_{[i[0], i[1] + 1]}(c, d) |
10 | | -] { |
| 7 | +\apply[\fanin_{i}(a, b), \fanout_{i}(c, d)] { |
11 | 8 | /* Duplicate application. */ |
12 | 9 | ++this.total; |
13 | | -} \fan_{i}[\apply(a, c), \apply(b, d)]; |
| 10 | +} \fanout_{i}[\apply(a, c), \apply(b, d)]; |
14 | 11 |
|
15 | | -\fan_{i}[\lambda(a, b), \lambda(c, d)] { |
| 12 | +\fanin_{i}[\lambda(a, b), \lambda(c, d)] { |
16 | 13 | /* Duplicate abstraction. */ |
17 | 14 | ++this.total; |
18 | | -} \lambda[ |
19 | | - \fan_{[i[0], i[1] + 1]}(a, c), |
20 | | - \fan_{[i[0], i[1] + 1]}(b, d) |
21 | | -]; |
22 | | - |
23 | | -\fan_{i}[ |
24 | | - \fan_{[j[0], j[1] + 1]}(a, b), |
25 | | - \fan_{[j[0], j[1] + 1]}(c, d) |
26 | | -] { |
| 15 | +} \lambda[\fanout_{i}(a, c), \fanin_{i}(b, d)]; |
| 16 | + |
| 17 | +\fanin_{i}[\fanout_{this.int1(j, i)}(a, b), \fanout_{this.int2(j, i)}(c, d)] { |
27 | 18 | /* Duplicate different fans. */ |
28 | | - if ((i[0] != j[0]) && (i[1] < j[1])) |
| 19 | + if (!this.match(i, j)) |
29 | 20 | ++this.total; |
30 | 21 | else |
31 | 22 | return false; |
32 | | -} \fan_{j}[ |
33 | | - \fan_{[this.plus(i[0], j[0]), i[1]]}(a, c), |
34 | | - \fan_{[this.minus(i[0], j[0]), i[1]]}(b, d) |
35 | | -]; |
| 23 | +} \fanout_{j}[\fanin_{this.int1(i, j)}(a, c), \fanin_{this.int2(i, j)}(b, d)]; |
36 | 24 |
|
37 | | -\fan_{i}[a, b] { |
| 25 | +\fanin_{i}[a, b] { |
38 | 26 | /* Annihilate matching fans. */ |
39 | | - if ((i[0] == j[0]) || (i[1] == j[1])) |
| 27 | + if (this.match(i, j)) |
40 | 28 | ++this.total; |
41 | 29 | else |
42 | 30 | return false; |
43 | | -} \fan_{j}[a, b]; |
| 31 | +} \fanout_{j}[a, b]; |
44 | 32 |
|
45 | | -\read_{C}[\fan_{i}(a, b)] { |
| 33 | +\read_{C}[\fanout_{i}(a, b)] { |
46 | 34 | /* Duplicate context. */ |
47 | 35 | ++this.total; |
48 | | -} \fan_{i}[\read_{C}(a), \read_{this.clone(C)}(b)]; |
| 36 | +} \fanout_{i}[\read_{C}(a), \read_{this.clone(C)}(b)]; |
49 | 37 |
|
50 | 38 | \print { |
51 | 39 | /* Output results of read-back. */ |
|
68 | 56 | ++this.total; |
69 | 57 | } \atom_{M}; |
70 | 58 |
|
71 | | -\fan_{i}[\atom_{M}, \atom_{M}] { |
| 59 | +\fanin_{i}[\atom_{M}, \atom_{M}] { |
72 | 60 | /* Duplicate an atom. */ |
73 | 61 | ++this.total; |
74 | 62 | } \atom_{M}; |
|
81 | 69 |
|
82 | 70 | READBACK |
83 | 71 |
|
84 | | -const table = []; |
85 | | -let last = 0; |
| 72 | +const db = {}; |
| 73 | +let nonce = 0; |
86 | 74 |
|
87 | | -function uniq() |
| 75 | +function decide(i, j) |
88 | 76 | { |
89 | | - let fresh = ++last; |
90 | | - |
91 | | - fresh = fresh.toString(); |
92 | | - fresh = hash(fresh); |
93 | | - return [fresh, 1]; |
94 | | -} |
95 | | - |
96 | | -function cons(s, a, b) |
97 | | -{ |
98 | | - return hash(a + s + b); |
99 | | -} |
100 | | - |
101 | | -function mktable() |
102 | | -{ |
103 | | - for (let n = 0; n < 256; n++) { |
104 | | - let c = n; |
105 | | - |
106 | | - for (let k = 0; k < 8; k++) { |
107 | | - if (c & 1) |
108 | | - c = 0xEDB88320 ^ (c >>> 1); |
109 | | - else |
110 | | - c = c >>> 1; |
111 | | - } |
112 | | - |
113 | | - table[n] = c; |
114 | | - } |
115 | | -} |
116 | | - |
117 | | -function hash(str) |
118 | | -{ |
119 | | - const n = str.length; |
120 | | - let crc = 0 ^ (-1); |
121 | | - |
122 | | - for (let i = 0; i < n; i++) { |
123 | | - const b = str.charCodeAt(i); |
124 | | - |
125 | | - crc = (crc >>> 8) ^ table[(crc ^ b) & 0xFF]; |
126 | | - } |
| 77 | + if (db[`${i}-${j}`]) |
| 78 | + return; |
127 | 79 |
|
128 | | - return (crc ^ (-1)) >>> 0; |
| 80 | + db[`${i}-${j}`] = ++nonce; |
| 81 | + db[`${i}+${j}`] = ++nonce; |
| 82 | + db[`${j}-${i}`] = j; |
| 83 | + db[`${j}+${i}`] = j; |
129 | 84 | } |
130 | 85 |
|
131 | | -mktable(); |
| 86 | +this.uniq = () => ++nonce; |
| 87 | +this.int1 = (i, j) => db[`${i}-${j}`]; |
| 88 | +this.int2 = (i, j) => db[`${i}+${j}`]; |
| 89 | +this.match = (i, j) => { |
| 90 | + if (i == j) |
| 91 | + return true; |
132 | 92 |
|
133 | | -this.plus = cons.bind(this, "+"); |
134 | | -this.minus = cons.bind(this, "-"); |
135 | | -this.uniq = uniq; |
| 93 | + decide(i, j); |
| 94 | + return false; |
| 95 | +}; |
136 | 96 | this.beta = 0; |
137 | 97 | this.total = 0; |
0 commit comments