Skip to content

Commit 08bb555

Browse files
committed
Compare 'abstract' with 'optimal'
1 parent 625c29a commit 08bb555

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ all: compile.js
33
node lambda -e 'eval(1 << 3) f x'
44
node lambda -t 'S hello bye world'
55
node lambda -d 'x: (x: x) v1 x'
6+
node debug.js 1000 M 1 5
67
sh bad.sh
78
sh test.sh
89

debug.js

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
"use strict";
2+
3+
const mlc = require(".");
4+
5+
const argv = process.argv;
6+
const max = parseInt(argv.pop());
7+
const min = parseInt(argv.pop());
8+
const ctx = argv.pop();
9+
const lim = parseInt(argv.pop());
10+
11+
function* sub(len, nv)
12+
{
13+
if (len) {
14+
--len;
15+
16+
for (const t of sub(len, nv + 1))
17+
yield `(v${nv}: ${t})`;
18+
19+
for (let l = 0; l <= len; l++)
20+
for (const t of sub(len - l, nv))
21+
for (const u of sub(l, nv))
22+
yield `(${t} ${u})`;
23+
} else {
24+
for (let i = 0; i < nv; i++)
25+
yield `v${i}`;
26+
}
27+
}
28+
29+
function* wrap(ctx, len)
30+
{
31+
for (const m of sub(len, 0))
32+
yield ctx.replace("M", m);
33+
}
34+
35+
function* exhaust(ctx, min, max)
36+
{
37+
for (let len = min; len <= max; len++)
38+
yield* wrap(ctx, len);
39+
}
40+
41+
function compute(term, algo)
42+
{
43+
const abd = [];
44+
const cb = {
45+
a: () => abd.push("a"),
46+
b: () => abd.push("b"),
47+
d: () => abd.push("d")
48+
};
49+
let result;
50+
51+
try {
52+
result = mlc(term, algo, lim, cb);
53+
result.abd = abd.join("");
54+
} catch (error) {
55+
result = {};
56+
}
57+
58+
return result;
59+
}
60+
61+
function diff(term)
62+
{
63+
const abstract = compute(term, "abstract");
64+
const optimal = compute(term, "optimal");
65+
66+
if (!optimal.nf)
67+
return;
68+
69+
if (abstract.nf != optimal.nf)
70+
return true;
71+
72+
if (abstract.abd != optimal.abd)
73+
return true;
74+
}
75+
76+
for (const term of exhaust(ctx, min, max))
77+
if (diff(term))
78+
console.info(term);

0 commit comments

Comments
 (0)