UNPKG

@alexo/lambda

Version:
94 lines (73 loc) 1.7 kB
\apply[a, b] { /* Apply beta reduction. */ this.debug.b(); } \lambda[a, b]; \apply[\fanin_{i}(a, b), \fanout_{i}(c, d)] { /* Duplicate application. */ this.debug.o(); } \fanout_{i}[\apply(a, c), \apply(b, d)]; \fanin_{i}[\lambda(a, b), \lambda(c, d)] { /* Duplicate abstraction. */ this.debug.o(); } \lambda[\fanout_{i}(a, c), \fanin_{i}(b, d)]; \fanin_{i}[\fanout_{this.phi(j, i)}(a, b), \fanout_{j}(c, d)] { /* Duplicate different fans. */ if (!this.match(i, j)) this.debug.d(); else return false; } \fanout_{j}[\fanin_{this.phi(i, j)}(a, c), \fanin_{i}(b, d)]; \fanin_{i}[a, b] { /* Annihilate matching fans. */ if (this.match(i, j)) this.debug.a(); else return false; } \fanout_{j}[a, b]; \read_{C}[\fanout_{i}(a, b)] { /* Duplicate context. */ this.debug.o(); } \fanout_{i}[\read_{C}(a), \read_{this.clone(C)}(b)]; \print { /* Output results of read-back. */ this.nf = M; this.debug.o(); } \atom_{M}; \read_{C}[a] { /* Read back abstraction. */ this.debug.o(); } \lambda[\atom_{this.mkid()}, \read_{this.abst(C)}(a)]; \apply[\read_{this.appl(M)}(a), a] { /* Read back application. */ this.debug.o(); } \atom_{M}; \read_{C}[\atom_{this.atom(C, M)}] { /* Read back an atom. */ this.debug.o(); } \atom_{M}; \fanin_{i}[\atom_{M}, \atom_{M}] { /* Duplicate an atom. */ this.debug.o(); } \atom_{M}; $$ INCONFIG $$ READBACK const map = new Map(); let nonce = 0; function decide(i, j) { const key = `${i},${j}`; if (map.has(key)) return; map.set(key, ++nonce); map.set(`${j},${i}`, j); } this.uniq = () => ++nonce; this.phi = (i, j) => map.get(`${i},${j}`); this.match = (i, j) => { if (i == j) return true; decide(i, j); return false; };