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