+12
-34
@@ -7,16 +7,12 @@ "use strict"; | ||
| exports.rules = void 0; | ||
| var _env = require("deep6/env"); | ||
| var _system = require("./system.js"); | ||
| const rules = { | ||
| const rules = exports.rules = { | ||
| // bitwise operations | ||
| bitAnd: (X, Y, Z) => [(0, _system.head)(X, Y, Z), env => { | ||
| const isX = X.isBound(env), | ||
| isY = Y.isBound(env), | ||
| isZ = Z.isBound(env), | ||
| count = (isX ? 1 : 0) + (isY ? 1 : 0) + (isZ ? 1 : 0); | ||
| isY = Y.isBound(env), | ||
| isZ = Z.isBound(env), | ||
| count = (isX ? 1 : 0) + (isY ? 1 : 0) + (isZ ? 1 : 0); | ||
| if (count < 2) return false; | ||
| if (count == 3) { | ||
@@ -32,7 +28,5 @@ const x = X.get(env); | ||
| } | ||
| if (isX) { | ||
| const x = X.get(env); | ||
| if (typeof x != 'number') return false; | ||
| if (isY) { | ||
@@ -44,6 +38,4 @@ const y = Y.get(env); | ||
| } | ||
| return false; | ||
| } | ||
| return false; | ||
@@ -53,7 +45,6 @@ }], | ||
| const isX = X.isBound(env), | ||
| isY = Y.isBound(env), | ||
| isZ = Z.isBound(env), | ||
| count = (isX ? 1 : 0) + (isY ? 1 : 0) + (isZ ? 1 : 0); | ||
| isY = Y.isBound(env), | ||
| isZ = Z.isBound(env), | ||
| count = (isX ? 1 : 0) + (isY ? 1 : 0) + (isZ ? 1 : 0); | ||
| if (count < 2) return false; | ||
| if (count == 3) { | ||
@@ -69,7 +60,5 @@ const x = X.get(env); | ||
| } | ||
| if (isX) { | ||
| const x = X.get(env); | ||
| if (typeof x != 'number') return false; | ||
| if (isY) { | ||
@@ -81,6 +70,4 @@ const y = Y.get(env); | ||
| } | ||
| return false; | ||
| } | ||
| return false; | ||
@@ -90,8 +77,7 @@ }], | ||
| const isX = X.isBound(env), | ||
| isY = Y.isBound(env), | ||
| isZ = Z.isBound(env), | ||
| count = (isX ? 1 : 0) + (isY ? 1 : 0) + (isZ ? 1 : 0); | ||
| isY = Y.isBound(env), | ||
| isZ = Z.isBound(env), | ||
| count = (isX ? 1 : 0) + (isY ? 1 : 0) + (isZ ? 1 : 0); | ||
| if (count < 2) return false; | ||
| (0, _system.cut)(sys)(env, stack); | ||
| if (count == 3) { | ||
@@ -107,7 +93,5 @@ const x = X.get(env); | ||
| } | ||
| if (isX) { | ||
| const x = X.get(env); | ||
| if (typeof x != 'number') return false; | ||
| if (isY) { | ||
@@ -119,3 +103,2 @@ const y = Y.get(env); | ||
| } | ||
| const z = Z.get(env); | ||
@@ -126,3 +109,2 @@ if (typeof z != 'number') return false; | ||
| } | ||
| const y = Y.get(env); | ||
@@ -137,7 +119,6 @@ if (typeof y != 'number') return false; | ||
| const isX = X.isBound(env), | ||
| isY = Y.isBound(env); | ||
| isY = Y.isBound(env); | ||
| count = (isX ? 1 : 0) + (isY ? 1 : 0); | ||
| if (count < 1) return false; | ||
| (0, _system.cut)(sys)(env, stack); | ||
| if (count == 2) { | ||
@@ -152,3 +133,2 @@ const x = X.get(env); | ||
| } | ||
| if (isX) { | ||
@@ -160,3 +140,2 @@ const x = X.get(env); | ||
| } | ||
| const y = Y.get(env); | ||
@@ -167,3 +146,2 @@ if (typeof y != 'number') return false; | ||
| }], () => [(0, _system.head)(0, 0)]] | ||
| }; | ||
| exports.rules = rules; | ||
| }; |
+6
-10
@@ -7,7 +7,4 @@ "use strict"; | ||
| exports.rules = void 0; | ||
| var _env = require("deep6/env"); | ||
| var _system = require("./system.js"); | ||
| const comparable = { | ||
@@ -17,7 +14,7 @@ string: 1, | ||
| }; | ||
| const rules = { | ||
| const rules = exports.rules = { | ||
| // comparisons | ||
| lt: (X, Y) => [(0, _system.head)(X, Y), (0, _system.isBound)(X, Y), env => { | ||
| const x = X.get(env), | ||
| y = Y.get(env); | ||
| y = Y.get(env); | ||
| if (x === _env._) return y === _env._ || comparable[typeof y] === 1; | ||
@@ -29,3 +26,3 @@ if (y === _env._) return comparable[typeof x] === 1; | ||
| const x = X.get(env), | ||
| y = Y.get(env); | ||
| y = Y.get(env); | ||
| if (x === _env._) return y === _env._ || comparable[typeof y] === 1; | ||
@@ -37,3 +34,3 @@ if (y === _env._) return comparable[typeof x] === 1; | ||
| const x = X.get(env), | ||
| y = Y.get(env); | ||
| y = Y.get(env); | ||
| if (x === _env._) return y === _env._ || comparable[typeof y] === 1; | ||
@@ -45,3 +42,3 @@ if (y === _env._) return comparable[typeof x] === 1; | ||
| const x = X.get(env), | ||
| y = Y.get(env); | ||
| y = Y.get(env); | ||
| if (x === _env._) return y === _env._ || comparable[typeof y] === 1; | ||
@@ -53,3 +50,2 @@ if (y === _env._) return comparable[typeof x] === 1; | ||
| nz: [(...sys) => [(0, _system.head)(0), (0, _system.cut)(sys), _system.fail], (...sys) => [(0, _system.head)(_env._), (0, _system.cut)(sys)]] | ||
| }; | ||
| exports.rules = rules; | ||
| }; |
+20
-42
@@ -7,27 +7,21 @@ "use strict"; | ||
| exports.rules = void 0; | ||
| var _env = require("deep6/env"); | ||
| var _system = require("./system.js"); | ||
| const rules = { | ||
| const rules = exports.rules = { | ||
| // logical operations | ||
| logicalAnd: (X, Y, Z) => [(0, _system.head)(X, Y, Z), env => { | ||
| const isX = X.isBound(env), | ||
| isY = Y.isBound(env), | ||
| isZ = Z.isBound(env), | ||
| count = (isX ? 1 : 0) + (isY ? 1 : 0) + (isZ ? 1 : 0); | ||
| isY = Y.isBound(env), | ||
| isZ = Z.isBound(env), | ||
| count = (isX ? 1 : 0) + (isY ? 1 : 0) + (isZ ? 1 : 0); | ||
| if (count < 2) return false; | ||
| if (count == 3) { | ||
| const x = X.get(env), | ||
| y = Y.get(env), | ||
| z = X.get(env); | ||
| y = Y.get(env), | ||
| z = X.get(env); | ||
| if (x === _env._ || y === _env._ || z === _env._) return true; | ||
| return !(x && y) === !z; | ||
| } | ||
| if (isX) { | ||
| const x = X.get(env); | ||
| if (isY) { | ||
@@ -39,6 +33,4 @@ const y = Y.get(env); | ||
| } | ||
| return false; | ||
| } | ||
| return false; | ||
@@ -48,18 +40,15 @@ }], | ||
| const isX = X.isBound(env), | ||
| isY = Y.isBound(env), | ||
| isZ = Z.isBound(env), | ||
| count = (isX ? 1 : 0) + (isY ? 1 : 0) + (isZ ? 1 : 0); | ||
| isY = Y.isBound(env), | ||
| isZ = Z.isBound(env), | ||
| count = (isX ? 1 : 0) + (isY ? 1 : 0) + (isZ ? 1 : 0); | ||
| if (count < 2) return false; | ||
| if (count == 3) { | ||
| const x = X.get(env), | ||
| y = Y.get(env), | ||
| z = X.get(env); | ||
| y = Y.get(env), | ||
| z = X.get(env); | ||
| if (x === _env._ || y === _env._ || z === _env._) return true; | ||
| return !(x || y) === !z; | ||
| } | ||
| if (isX) { | ||
| const x = X.get(env); | ||
| if (isY) { | ||
@@ -71,6 +60,4 @@ const y = Y.get(env); | ||
| } | ||
| return false; | ||
| } | ||
| return false; | ||
@@ -80,18 +67,15 @@ }], | ||
| const isX = X.isBound(env), | ||
| isY = Y.isBound(env), | ||
| isZ = Z.isBound(env), | ||
| count = (isX ? 1 : 0) + (isY ? 1 : 0) + (isZ ? 1 : 0); | ||
| isY = Y.isBound(env), | ||
| isZ = Z.isBound(env), | ||
| count = (isX ? 1 : 0) + (isY ? 1 : 0) + (isZ ? 1 : 0); | ||
| if (count < 2) return false; | ||
| if (count == 3) { | ||
| const x = X.get(env), | ||
| y = Y.get(env), | ||
| z = X.get(env); | ||
| y = Y.get(env), | ||
| z = X.get(env); | ||
| if (x === _env._ || y === _env._ || z === _env._) return true; | ||
| return (!!x ^ !!y) === !!z; | ||
| } | ||
| if (isX) { | ||
| const x = X.get(env); | ||
| if (isY) { | ||
@@ -103,3 +87,2 @@ const y = Y.get(env); | ||
| } | ||
| const z = Z.get(env); | ||
@@ -110,5 +93,4 @@ if (x === _env._ || z === _env._) return true; | ||
| } | ||
| const y = Y.get(env), | ||
| z = Z.get(env); | ||
| z = Z.get(env); | ||
| if (y === _env._ || z === _env._) return true; | ||
@@ -120,13 +102,11 @@ env.bindVal(X.name, !!(!!y ^ !!z)); | ||
| const isX = X.isBound(env), | ||
| isY = Y.isBound(env); | ||
| isY = Y.isBound(env); | ||
| count = (isX ? 1 : 0) + (isY ? 1 : 0); | ||
| if (count < 1) return false; | ||
| if (count == 2) { | ||
| const x = X.get(env), | ||
| y = Y.get(env); | ||
| y = Y.get(env); | ||
| if (x === _env._ || y === _env._) return true; | ||
| return !x === !!y; | ||
| } | ||
| if (isX) { | ||
@@ -138,3 +118,2 @@ const x = X.get(env); | ||
| } | ||
| const y = Y.get(env); | ||
@@ -145,3 +124,2 @@ if (y === _env._) return true; | ||
| }] | ||
| }; | ||
| exports.rules = rules; | ||
| }; |
+15
-42
@@ -7,17 +7,13 @@ "use strict"; | ||
| exports.rules = void 0; | ||
| var _env = require("deep6/env"); | ||
| var _system = require("./system.js"); | ||
| const rules = { | ||
| const rules = exports.rules = { | ||
| // arithmetics | ||
| add: [(X, Y, Z, ...sys) => [(0, _system.head)(X, Y, Z), (env, stack) => { | ||
| const isX = X.isBound(env), | ||
| isY = Y.isBound(env), | ||
| isZ = Z.isBound(env), | ||
| count = (isX ? 1 : 0) + (isY ? 1 : 0) + (isZ ? 1 : 0); | ||
| isY = Y.isBound(env), | ||
| isZ = Z.isBound(env), | ||
| count = (isX ? 1 : 0) + (isY ? 1 : 0) + (isZ ? 1 : 0); | ||
| if (count < 2) return false; | ||
| (0, _system.cut)(sys)(env, stack); | ||
| if (count == 3) { | ||
@@ -33,7 +29,5 @@ const x = X.get(env); | ||
| } | ||
| if (isX) { | ||
| const x = X.get(env); | ||
| if (typeof x != 'number') return false; | ||
| if (isY) { | ||
@@ -45,3 +39,2 @@ const y = Y.get(env); | ||
| } | ||
| const z = Z.get(env); | ||
@@ -52,3 +45,2 @@ if (typeof z != 'number') return false; | ||
| } | ||
| const y = Y.get(env); | ||
@@ -63,8 +55,7 @@ if (typeof y != 'number') return false; | ||
| const isX = X.isBound(env), | ||
| isY = Y.isBound(env), | ||
| isZ = Z.isBound(env), | ||
| count = (isX ? 1 : 0) + (isY ? 1 : 0) + (isZ ? 1 : 0); | ||
| isY = Y.isBound(env), | ||
| isZ = Z.isBound(env), | ||
| count = (isX ? 1 : 0) + (isY ? 1 : 0) + (isZ ? 1 : 0); | ||
| if (count < 2) return false; | ||
| (0, _system.cut)(sys)(env, stack); | ||
| if (count == 3) { | ||
@@ -80,7 +71,5 @@ const x = X.get(env); | ||
| } | ||
| if (isX) { | ||
| const x = X.get(env); | ||
| if (typeof x != 'number') return false; | ||
| if (isY) { | ||
@@ -92,3 +81,2 @@ const y = Y.get(env); | ||
| } | ||
| const z = Z.get(env); | ||
@@ -99,3 +87,2 @@ if (typeof z != 'number') return false; | ||
| } | ||
| const y = Y.get(env); | ||
@@ -110,8 +97,7 @@ if (typeof y != 'number') return false; | ||
| const isX = X.isBound(env), | ||
| isY = Y.isBound(env), | ||
| isZ = Z.isBound(env), | ||
| count = (isX ? 1 : 0) + (isY ? 1 : 0) + (isZ ? 1 : 0); | ||
| isY = Y.isBound(env), | ||
| isZ = Z.isBound(env), | ||
| count = (isX ? 1 : 0) + (isY ? 1 : 0) + (isZ ? 1 : 0); | ||
| if (count < 2) return false; | ||
| (0, _system.cut)(sys)(env, stack); | ||
| if (count == 3) { | ||
@@ -127,7 +113,5 @@ const x = X.get(env); | ||
| } | ||
| if (isX) { | ||
| const x = X.get(env); | ||
| if (typeof x != 'number') return false; | ||
| if (isY) { | ||
@@ -139,3 +123,2 @@ const y = Y.get(env); | ||
| } | ||
| const z = Z.get(env); | ||
@@ -146,3 +129,2 @@ if (typeof z != 'number') return false; | ||
| } | ||
| const y = Y.get(env); | ||
@@ -157,8 +139,7 @@ if (typeof y != 'number') return false; | ||
| const isX = X.isBound(env), | ||
| isY = Y.isBound(env), | ||
| isZ = Z.isBound(env), | ||
| count = (isX ? 1 : 0) + (isY ? 1 : 0) + (isZ ? 1 : 0); | ||
| isY = Y.isBound(env), | ||
| isZ = Z.isBound(env), | ||
| count = (isX ? 1 : 0) + (isY ? 1 : 0) + (isZ ? 1 : 0); | ||
| if (count < 2) return false; | ||
| (0, _system.cut)(sys)(env, stack); | ||
| if (count == 3) { | ||
@@ -174,7 +155,5 @@ const x = X.get(env); | ||
| } | ||
| if (isX) { | ||
| const x = X.get(env); | ||
| if (typeof x != 'number') return false; | ||
| if (isY) { | ||
@@ -186,3 +165,2 @@ const y = Y.get(env); | ||
| } | ||
| const z = Z.get(env); | ||
@@ -193,3 +171,2 @@ if (typeof z != 'number') return false; | ||
| } | ||
| const y = Y.get(env); | ||
@@ -204,7 +181,6 @@ if (typeof y != 'number') return false; | ||
| const isX = X.isBound(env), | ||
| isY = Y.isBound(env); | ||
| isY = Y.isBound(env); | ||
| count = (isX ? 1 : 0) + (isY ? 1 : 0); | ||
| if (count < 1) return false; | ||
| (0, _system.cut)(sys)(env, stack); | ||
| if (count == 2) { | ||
@@ -219,3 +195,2 @@ const x = X.get(env); | ||
| } | ||
| if (isX) { | ||
@@ -227,3 +202,2 @@ const x = X.get(env); | ||
| } | ||
| const y = Y.get(env); | ||
@@ -234,3 +208,2 @@ if (typeof y != 'number') return false; | ||
| }], () => [(0, _system.head)(0, 0)]] | ||
| }; | ||
| exports.rules = rules; | ||
| }; |
+12
-47
@@ -6,38 +6,27 @@ "use strict"; | ||
| }); | ||
| exports.rules = exports.listHead = exports.list = exports.rest = exports.term = exports.head = exports.isBound = exports.call = exports.cut = exports.halt = exports.fail = void 0; | ||
| exports.term = exports.rules = exports.rest = exports.listHead = exports.list = exports.isBound = exports.head = exports.halt = exports.fail = exports.cut = exports.call = void 0; | ||
| var _env = require("deep6/env.js"); | ||
| // utilities | ||
| // utilities | ||
| const fail = () => false; | ||
| exports.fail = fail; | ||
| const halt = (env, goals, stack) => (stack.splice(0), false); | ||
| exports.halt = halt; | ||
| const cut = sys => (env, goals, stack) => { | ||
| const lastFrame = sys[0].get(env); | ||
| for (let i = stack.length - 1; i >= 0; --i) { | ||
| const frame = stack[i]; | ||
| if (frame.command === 2) { | ||
| frame.index = Infinity; | ||
| } | ||
| if (frame === lastFrame) break; | ||
| } | ||
| return true; | ||
| }; | ||
| exports.cut = cut; | ||
| const call = X => (env, goals) => { | ||
| let term = X, | ||
| name, | ||
| args; // TODO: add processing of arrays of goals | ||
| name, | ||
| args; | ||
| // TODO: add processing of arrays of goals | ||
| if ((0, _env.isVariable)(X)) { | ||
@@ -47,3 +36,2 @@ if (!X.isBound(env)) return false; | ||
| } | ||
| if (typeof term == 'string') { | ||
@@ -55,16 +43,11 @@ name = term; | ||
| args = term.args; | ||
| if ((0, _env.isVariable)(name)) { | ||
| name = name.get(env); | ||
| } | ||
| if (typeof name != 'string') return false; | ||
| if ((0, _env.isVariable)(args)) { | ||
| args = args.get(env); | ||
| } | ||
| if (args && !Array.isArray(args)) return false; | ||
| } | ||
| return { | ||
@@ -79,15 +62,9 @@ terms: [{ | ||
| }; | ||
| exports.call = call; | ||
| const isBound = (...args) => env => args.every(V => (0, _env.isVariable)(V) && V.isBound(env)); | ||
| exports.isBound = isBound; | ||
| const head = (...args) => ({ | ||
| args | ||
| }); | ||
| exports.head = head; | ||
| const term = (name, ...args) => ({ | ||
@@ -97,5 +74,3 @@ name, | ||
| }); | ||
| exports.term = term; | ||
| class Tail { | ||
@@ -105,15 +80,10 @@ constructor(value) { | ||
| } | ||
| } | ||
| const rest = list => new Tail(list); | ||
| exports.rest = rest; | ||
| const list = (...args) => { | ||
| if (!args.length) return null; | ||
| let list = null, | ||
| startFrom = args.length - 1; | ||
| startFrom = args.length - 1; | ||
| const last = args[startFrom]; | ||
| if (last instanceof Tail) { | ||
@@ -123,3 +93,2 @@ --startFrom; | ||
| } | ||
| for (let i = startFrom; i >= 0; --i) { | ||
@@ -133,13 +102,9 @@ const value = args[i]; | ||
| } | ||
| return list; | ||
| }; | ||
| exports.list = list; | ||
| const listHead = (...args) => { | ||
| if (args.length < 2) throw new Error('list constructor cannot have less then 2 elements'); | ||
| let startFrom = args.length - 1, | ||
| list = args[startFrom]; | ||
| list = args[startFrom]; | ||
| for (let i = startFrom - 1; i >= 0; --i) { | ||
@@ -151,9 +116,8 @@ list = { | ||
| } | ||
| return list; | ||
| }; // rules | ||
| }; | ||
| // rules | ||
| exports.listHead = listHead; | ||
| const rules = { | ||
| const rules = exports.rules = { | ||
| // types | ||
@@ -171,2 +135,3 @@ isVar: X => [head(X), env => !X.isBound(env)], | ||
| // unify is eq | ||
| // control predicates | ||
@@ -183,2 +148,3 @@ call: X => [head(X), call(X)], | ||
| // apply, applyp | ||
| // extended logic | ||
@@ -196,4 +162,3 @@ counterExample: (A, B) => [head(A, B), call(A), term('not', B)], | ||
| }; | ||
| exports.rules = rules; | ||
| rules.unify = rules.eq; | ||
| rules.notUnifiable = rules.notEq; |
+5
-30
@@ -7,19 +7,11 @@ "use strict"; | ||
| exports.default = void 0; | ||
| var _unify = _interopRequireWildcard(require("deep6/unify.js")); | ||
| function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
| function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
| function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } | ||
| function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } | ||
| let counter = 0; | ||
| const generateVariables = count => { | ||
| const t = []; | ||
| for (let i = 0; i < count; ++i) t.push(counter++); | ||
| return t.map(name => (0, _unify.variable)(Symbol(name))); | ||
| }; | ||
| const prove = (rules, goals, env) => { | ||
@@ -29,6 +21,4 @@ const stack = [{ | ||
| }]; | ||
| main: while (stack.length) { | ||
| const frame = stack.pop(); | ||
| if (frame.command) { | ||
@@ -39,9 +29,7 @@ if (frame.command === 1) { | ||
| } | ||
| while (frame.index < frame.ruleList.length) { | ||
| const rule = frame.ruleList[frame.index++], | ||
| vars = generateVariables(rule.length + 1), | ||
| terms = (typeof rule == 'function' ? rule : rule.goals)(...vars); | ||
| vars = generateVariables(rule.length + 1), | ||
| terms = (typeof rule == 'function' ? rule : rule.goals)(...vars); | ||
| env.push(); | ||
| if ((0, _unify.default)(terms[0].args || [], frame.args, env)) { | ||
@@ -61,22 +49,15 @@ const newGoals = { | ||
| } | ||
| env.pop(); | ||
| } | ||
| continue main; | ||
| } | ||
| let goals = frame.goals; | ||
| while (goals && goals.index >= goals.terms.length) { | ||
| goals = goals.next; | ||
| } | ||
| if (!goals) continue main; | ||
| let goal = goals.terms[goals.index++]; | ||
| if (typeof goal == 'function') { | ||
| env.push(); | ||
| let newGoals = goal(env, goals, stack); | ||
| if (newGoals || newGoals === null) { | ||
@@ -91,3 +72,2 @@ newGoals && !newGoals.terms && (newGoals = goals); | ||
| } | ||
| --goals.index; | ||
@@ -97,3 +77,2 @@ env.pop(); | ||
| } | ||
| if (typeof goal == 'string') { | ||
@@ -104,3 +83,2 @@ goal = { | ||
| } | ||
| let ruleList = rules[goal.name]; | ||
@@ -117,3 +95,2 @@ !Array.isArray(ruleList) && (ruleList = [ruleList]); | ||
| }; | ||
| const solve = (rules, name, args, callback) => { | ||
@@ -132,4 +109,2 @@ const env = new _unify.Env(); | ||
| }; | ||
| var _default = solve; | ||
| exports.default = _default; | ||
| var _default = exports.default = solve; |
+5
-30
@@ -7,19 +7,11 @@ "use strict"; | ||
| exports.default = void 0; | ||
| var _unify = _interopRequireWildcard(require("deep6/unify.js")); | ||
| function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
| function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
| function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } | ||
| function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } | ||
| let counter = 0; | ||
| const generateVariables = count => { | ||
| const t = []; | ||
| for (let i = 0; i < count; ++i) t.push(counter++); | ||
| return t.map(name => (0, _unify.variable)(Symbol(name))); | ||
| }; | ||
| const prove = async (rules, goals, env) => { | ||
@@ -29,6 +21,4 @@ const stack = [{ | ||
| }]; | ||
| main: while (stack.length) { | ||
| const frame = stack.pop(); | ||
| if (frame.command) { | ||
@@ -39,9 +29,7 @@ if (frame.command === 1) { | ||
| } | ||
| while (frame.index < frame.ruleList.length) { | ||
| const rule = frame.ruleList[frame.index++], | ||
| vars = generateVariables(rule.length + 1), | ||
| terms = (typeof rule == 'function' ? rule : rule.goals)(...vars); | ||
| vars = generateVariables(rule.length + 1), | ||
| terms = (typeof rule == 'function' ? rule : rule.goals)(...vars); | ||
| env.push(); | ||
| if ((0, _unify.default)(terms[0].args || [], frame.args, env)) { | ||
@@ -61,22 +49,15 @@ const newGoals = { | ||
| } | ||
| env.pop(); | ||
| } | ||
| continue main; | ||
| } | ||
| let goals = frame.goals; | ||
| while (goals && goals.index >= goals.terms.length) { | ||
| goals = goals.next; | ||
| } | ||
| if (!goals) continue main; | ||
| let goal = goals.terms[goals.index++]; | ||
| if (typeof goal == 'function') { | ||
| env.push(); | ||
| let newGoals = await goal(env, goals, stack); | ||
| if (newGoals || newGoals === null) { | ||
@@ -91,3 +72,2 @@ newGoals && !newGoals.terms && (newGoals = goals); | ||
| } | ||
| --goals.index; | ||
@@ -97,3 +77,2 @@ env.pop(); | ||
| } | ||
| if (typeof goal == 'string') { | ||
@@ -104,3 +83,2 @@ goal = { | ||
| } | ||
| let ruleList = rules[goal.name]; | ||
@@ -117,3 +95,2 @@ !Array.isArray(ruleList) && (ruleList = [ruleList]); | ||
| }; | ||
| const solve = async (rules, name, args, callback) => { | ||
@@ -132,4 +109,2 @@ const env = new _unify.Env(); | ||
| }; | ||
| var _default = solve; | ||
| exports.default = _default; | ||
| var _default = exports.default = solve; |
@@ -7,19 +7,11 @@ "use strict"; | ||
| exports.default = void 0; | ||
| var _unify = _interopRequireWildcard(require("deep6/unify.js")); | ||
| function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
| function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
| function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } | ||
| function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } | ||
| let counter = 0; | ||
| const generateVariables = count => { | ||
| const t = []; | ||
| for (let i = 0; i < count; ++i) t.push(counter++); | ||
| return t.map(name => (0, _unify.variable)(Symbol(name))); | ||
| }; | ||
| async function* prove(rules, goals, env) { | ||
@@ -29,6 +21,4 @@ const stack = [{ | ||
| }]; | ||
| main: while (stack.length) { | ||
| const frame = stack.pop(); | ||
| if (frame.command) { | ||
@@ -39,9 +29,7 @@ if (frame.command === 1) { | ||
| } | ||
| while (frame.index < frame.ruleList.length) { | ||
| const rule = frame.ruleList[frame.index++], | ||
| vars = generateVariables(rule.length + 1), | ||
| terms = (typeof rule == 'function' ? rule : rule.goals)(...vars); | ||
| vars = generateVariables(rule.length + 1), | ||
| terms = (typeof rule == 'function' ? rule : rule.goals)(...vars); | ||
| env.push(); | ||
| if ((0, _unify.default)(terms[0].args || [], frame.args, env)) { | ||
@@ -61,15 +49,10 @@ const newGoals = { | ||
| } | ||
| env.pop(); | ||
| } | ||
| continue main; | ||
| } | ||
| let goals = frame.goals; | ||
| while (goals && goals.index >= goals.terms.length) { | ||
| goals = goals.next; | ||
| } | ||
| if (!goals) { | ||
@@ -79,9 +62,6 @@ yield env; | ||
| } | ||
| let goal = goals.terms[goals.index++]; | ||
| if (typeof goal == 'function') { | ||
| env.push(); | ||
| let newGoals = await goal(env, goals, stack); | ||
| if (newGoals || newGoals === null) { | ||
@@ -96,3 +76,2 @@ newGoals && !newGoals.terms && (newGoals = goals); | ||
| } | ||
| --goals.index; | ||
@@ -102,3 +81,2 @@ env.pop(); | ||
| } | ||
| if (typeof goal == 'string') { | ||
@@ -109,3 +87,2 @@ goal = { | ||
| } | ||
| let ruleList = rules[goal.name]; | ||
@@ -122,5 +99,3 @@ !Array.isArray(ruleList) && (ruleList = [ruleList]); | ||
| } | ||
| ; | ||
| async function* generate(rules, name, args) { | ||
@@ -139,5 +114,3 @@ const env = new _unify.Env(); | ||
| } | ||
| ; | ||
| var _default = generate; | ||
| exports.default = _default; | ||
| var _default = exports.default = generate; |
+5
-32
@@ -7,19 +7,11 @@ "use strict"; | ||
| exports.default = void 0; | ||
| var _unify = _interopRequireWildcard(require("deep6/unify.js")); | ||
| function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
| function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
| function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } | ||
| function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } | ||
| let counter = 0; | ||
| const generateVariables = count => { | ||
| const t = []; | ||
| for (let i = 0; i < count; ++i) t.push(counter++); | ||
| return t.map(name => (0, _unify.variable)(Symbol(name))); | ||
| }; | ||
| function* prove(rules, goals, env) { | ||
@@ -29,6 +21,4 @@ const stack = [{ | ||
| }]; | ||
| main: while (stack.length) { | ||
| const frame = stack.pop(); | ||
| if (frame.command) { | ||
@@ -39,9 +29,7 @@ if (frame.command === 1) { | ||
| } | ||
| while (frame.index < frame.ruleList.length) { | ||
| const rule = frame.ruleList[frame.index++], | ||
| vars = generateVariables(rule.length + 1), | ||
| terms = (typeof rule == 'function' ? rule : rule.goals)(...vars); | ||
| vars = generateVariables(rule.length + 1), | ||
| terms = (typeof rule == 'function' ? rule : rule.goals)(...vars); | ||
| env.push(); | ||
| if ((0, _unify.default)(terms[0].args || [], frame.args, env)) { | ||
@@ -61,15 +49,10 @@ const newGoals = { | ||
| } | ||
| env.pop(); | ||
| } | ||
| continue main; | ||
| } | ||
| let goals = frame.goals; | ||
| while (goals && goals.index >= goals.terms.length) { | ||
| goals = goals.next; | ||
| } | ||
| if (!goals) { | ||
@@ -79,9 +62,6 @@ yield env; | ||
| } | ||
| let goal = goals.terms[goals.index++]; | ||
| if (typeof goal == 'function') { | ||
| env.push(); | ||
| let newGoals = goal(env, goals, stack); | ||
| if (newGoals || newGoals === null) { | ||
@@ -96,3 +76,2 @@ newGoals && !newGoals.terms && (newGoals = goals); | ||
| } | ||
| --goals.index; | ||
@@ -102,3 +81,2 @@ env.pop(); | ||
| } | ||
| if (typeof goal == 'string') { | ||
@@ -109,3 +87,2 @@ goal = { | ||
| } | ||
| let ruleList = rules[goal.name]; | ||
@@ -122,5 +99,3 @@ !Array.isArray(ruleList) && (ruleList = [ruleList]); | ||
| } | ||
| ; | ||
| function* generate(rules, name, args) { | ||
@@ -139,5 +114,3 @@ const env = new _unify.Env(); | ||
| } | ||
| ; | ||
| var _default = generate; | ||
| exports.default = _default; | ||
| var _default = exports.default = generate; |
+5
-5
| { | ||
| "name": "yopl", | ||
| "version": "1.1.3", | ||
| "version": "1.1.4", | ||
| "description": "No dependency mini-library: unification, deep equivalence, deep cloning, logical solver.", | ||
@@ -60,5 +60,5 @@ "type": "module", | ||
| "devDependencies": { | ||
| "@babel/cli": "^7.14.5", | ||
| "@babel/core": "^7.14.6", | ||
| "@babel/preset-env": "^7.14.7" | ||
| "@babel/cli": "^7.24.7", | ||
| "@babel/core": "^7.24.7", | ||
| "@babel/preset-env": "^7.24.7" | ||
| }, | ||
@@ -82,4 +82,4 @@ "files": [ | ||
| "dependencies": { | ||
| "deep6": "^1.1.3" | ||
| "deep6": "^1.1.4" | ||
| } | ||
| } |
+1
-0
@@ -26,2 +26,3 @@ # yopl [![NPM version][npm-image]][npm-url] | ||
| - 1.1.4 *updated dependencies.* | ||
| - 1.1.3 *updated dependencies.* | ||
@@ -28,0 +29,0 @@ - 1.1.2 *updated dependencies.* |
33
3.13%67784
-2.58%1950
-0.76%Updated