|
| 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