eyeling 1.32.1 → 1.33.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +86 -15
- package/bin/eyeling.cjs +56 -4
- package/dist/browser/eyeling.browser.js +1 -0
- package/examples/eyelang/INTEGRATION.md +13 -0
- package/examples/eyelang/README.md +628 -0
- package/examples/eyelang/SPEC.md +684 -0
- package/examples/eyelang/access-control-policy.pl +52 -0
- package/examples/eyelang/ackermann.pl +46 -0
- package/examples/eyelang/age.pl +28 -0
- package/examples/eyelang/aliases-and-namespaces.pl +22 -0
- package/examples/eyelang/alignment-demo.pl +44 -0
- package/examples/eyelang/allen-interval-calculus.pl +64 -0
- package/examples/eyelang/ancestor.pl +21 -0
- package/examples/eyelang/animal.pl +21 -0
- package/examples/eyelang/annotation-rdf12.ttl +12 -0
- package/examples/eyelang/annotation.pl +34 -0
- package/examples/eyelang/auroracare.pl +309 -0
- package/examples/eyelang/backward.pl +12 -0
- package/examples/eyelang/basic-monadic.pl +10018 -0
- package/examples/eyelang/bayes-diagnosis.pl +108 -0
- package/examples/eyelang/bayes-therapy.pl +182 -0
- package/examples/eyelang/beam-deflection.pl +50 -0
- package/examples/eyelang/blocks-world-planning.pl +75 -0
- package/examples/eyelang/bmi.pl +232 -0
- package/examples/eyelang/braking-safety-worlds.pl +69 -0
- package/examples/eyelang/buck-converter-design.pl +78 -0
- package/examples/eyelang/cache-performance.pl +54 -0
- package/examples/eyelang/canary-release.pl +49 -0
- package/examples/eyelang/cat-koko.pl +24 -0
- package/examples/eyelang/clinical-trial-screening.pl +92 -0
- package/examples/eyelang/collatz-1000.pl +14 -0
- package/examples/eyelang/combinatorics-findall-sort.pl +37 -0
- package/examples/eyelang/competitive-enzyme-kinetics.pl +78 -0
- package/examples/eyelang/complex-matrix-stability.pl +45 -0
- package/examples/eyelang/complex.pl +121 -0
- package/examples/eyelang/composition-of-injective-functions-is-injective.pl +50 -0
- package/examples/eyelang/context-association.pl +53 -0
- package/examples/eyelang/control-system.pl +72 -0
- package/examples/eyelang/cryptarithmetic-send-more-money.pl +49 -0
- package/examples/eyelang/cyclic-path.pl +16 -0
- package/examples/eyelang/d3-group.pl +100 -0
- package/examples/eyelang/dairy-energy-balance.pl +65 -0
- package/examples/eyelang/data-negotiation.pl +39 -0
- package/examples/eyelang/deep-taxonomy-10.pl +115 -0
- package/examples/eyelang/deep-taxonomy-100.pl +385 -0
- package/examples/eyelang/deep-taxonomy-1000.pl +3085 -0
- package/examples/eyelang/deep-taxonomy-10000.pl +30094 -0
- package/examples/eyelang/deep-taxonomy-100000.pl +300184 -0
- package/examples/eyelang/delfour.pl +281 -0
- package/examples/eyelang/dense-hamiltonian-cycle.pl +92 -0
- package/examples/eyelang/deontic-logic.pl +52 -0
- package/examples/eyelang/derived-backward-rule.pl +30 -0
- package/examples/eyelang/derived-rule.pl +27 -0
- package/examples/eyelang/diamond-property.pl +38 -0
- package/examples/eyelang/dijkstra-findall-sort.pl +44 -0
- package/examples/eyelang/dijkstra-risk-path.pl +86 -0
- package/examples/eyelang/dijkstra.pl +46 -0
- package/examples/eyelang/dining-philosophers.pl +140 -0
- package/examples/eyelang/directional-language.ttl +9 -0
- package/examples/eyelang/dog.pl +25 -0
- package/examples/eyelang/drone-corridor-planner.pl +51 -0
- package/examples/eyelang/easter-computus.pl +89 -0
- package/examples/eyelang/electrical-rc-filter.pl +36 -0
- package/examples/eyelang/epidemic-policy.pl +67 -0
- package/examples/eyelang/equivalence-classes-overlap-implies-same-class.pl +27 -0
- package/examples/eyelang/eulerian-path.pl +85 -0
- package/examples/eyelang/ev-range-worlds.pl +82 -0
- package/examples/eyelang/exact-cover-sudoku.pl +113 -0
- package/examples/eyelang/existential-rule.pl +18 -0
- package/examples/eyelang/exoplanet-validation-worlds.pl +88 -0
- package/examples/eyelang/expression-eval.pl +43 -0
- package/examples/eyelang/eyeling-ackermann.n3 +41 -0
- package/examples/eyelang/eyeling-age-threshold.n3 +12 -0
- package/examples/eyelang/eyeling-alignment-demo.n3 +11 -0
- package/examples/eyelang/eyeling-allen-interval-calculus-small.n3 +13 -0
- package/examples/eyelang/eyeling-backward-recursion.n3 +11 -0
- package/examples/eyelang/eyeling-backward.n3 +10 -0
- package/examples/eyelang/eyeling-basic-monadic-small.n3 +11 -0
- package/examples/eyelang/eyeling-bmi.n3 +10 -0
- package/examples/eyelang/eyeling-cat-koko.n3 +15 -0
- package/examples/eyelang/eyeling-collatz-small.n3 +11 -0
- package/examples/eyelang/eyeling-collection.n3 +11 -0
- package/examples/eyelang/eyeling-complex-arithmetic.n3 +10 -0
- package/examples/eyelang/eyeling-context-association.n3 +11 -0
- package/examples/eyelang/eyeling-control-system-small.n3 +11 -0
- package/examples/eyelang/eyeling-crypto-builtins-extra.n3 +10 -0
- package/examples/eyelang/eyeling-crypto-builtins.n3 +8 -0
- package/examples/eyelang/eyeling-deep-taxonomy-10.n3 +18 -0
- package/examples/eyelang/eyeling-derived-backward-rule-flat.n3 +10 -0
- package/examples/eyelang/eyeling-derived-rule-flat.n3 +9 -0
- package/examples/eyelang/eyeling-digital-product-passport-small.n3 +11 -0
- package/examples/eyelang/eyeling-dijkstra-tiny.n3 +14 -0
- package/examples/eyelang/eyeling-dog-license.n3 +13 -0
- package/examples/eyelang/eyeling-drone-corridor-planner-small.n3 +13 -0
- package/examples/eyelang/eyeling-equals.n3 +8 -0
- package/examples/eyelang/eyeling-equivalence-classes.n3 +11 -0
- package/examples/eyelang/eyeling-euler-identity.n3 +9 -0
- package/examples/eyelang/eyeling-existential-rule.n3 +9 -0
- package/examples/eyelang/eyeling-expression-eval.n3 +11 -0
- package/examples/eyelang/eyeling-family-cousins-extended.n3 +12 -0
- package/examples/eyelang/eyeling-fastpow.n3 +10 -0
- package/examples/eyelang/eyeling-fibonacci.n3 +44 -0
- package/examples/eyelang/eyeling-french-cities-reachability.n3 +22 -0
- package/examples/eyelang/eyeling-goldbach-small.n3 +22 -0
- package/examples/eyelang/eyeling-good-cobbler.n3 +9 -0
- package/examples/eyelang/eyeling-list-builtins.n3 +10 -0
- package/examples/eyelang/eyeling-list-collection-extra.n3 +9 -0
- package/examples/eyelang/eyeling-math-builtins.n3 +9 -0
- package/examples/eyelang/eyeling-string-builtins-extra.n3 +9 -0
- package/examples/eyelang/eyeling-string-builtins.n3 +10 -0
- package/examples/eyelang/eyeling-time-builtins.n3 +11 -0
- package/examples/eyelang/eyeling-time-components-extra.n3 +10 -0
- package/examples/eyelang/eyeling-witch.n3 +10 -0
- package/examples/eyelang/family-cousins.n3 +17 -0
- package/examples/eyelang/family-cousins.pl +65 -0
- package/examples/eyelang/fastpow.pl +53 -0
- package/examples/eyelang/fft8-numeric.pl +83 -0
- package/examples/eyelang/fibonacci.pl +53 -0
- package/examples/eyelang/field-nitrogen-balance.pl +70 -0
- package/examples/eyelang/flandor.pl +296 -0
- package/examples/eyelang/floating-point.pl +23 -0
- package/examples/eyelang/four-color-map.pl +127 -0
- package/examples/eyelang/fundamental-theorem-arithmetic.pl +113 -0
- package/examples/eyelang/gcd-bezout-identity.pl +48 -0
- package/examples/eyelang/gd-step-certified.pl +158 -0
- package/examples/eyelang/gdpr-compliance.pl +69 -0
- package/examples/eyelang/goldbach-1000.pl +185 -0
- package/examples/eyelang/good-cobbler.pl +14 -0
- package/examples/eyelang/gps.pl +152 -0
- package/examples/eyelang/graph-reachability.pl +36 -0
- package/examples/eyelang/gray-code-counter.pl +48 -0
- package/examples/eyelang/greatest-lower-bound-uniqueness.pl +28 -0
- package/examples/eyelang/group-inverse-uniqueness.pl +34 -0
- package/examples/eyelang/hamiltonian-cycle.pl +55 -0
- package/examples/eyelang/hamiltonian-path.pl +49 -0
- package/examples/eyelang/hamming-code.pl +105 -0
- package/examples/eyelang/hanoi.pl +20 -0
- package/examples/eyelang/heat-loss.pl +51 -0
- package/examples/eyelang/heron-theorem.pl +36 -0
- package/examples/eyelang/ideal-gas-law.pl +37 -0
- package/examples/eyelang/illegitimate-reasoning.pl +88 -0
- package/examples/eyelang/kaprekar.pl +32 -0
- package/examples/eyelang/law-of-cosines.pl +31 -0
- package/examples/eyelang/least-squares-regression.pl +81 -0
- package/examples/eyelang/list-collection.pl +33 -0
- package/examples/eyelang/lldm.pl +78 -0
- package/examples/eyelang/manufacturing-quality-control.pl +73 -0
- package/examples/eyelang/matrix.pl +296 -0
- package/examples/eyelang/microgrid-dispatch.pl +85 -0
- package/examples/eyelang/monkey-bananas.pl +45 -0
- package/examples/eyelang/n-queens.pl +23 -0
- package/examples/eyelang/n3-builtins.n3 +28 -0
- package/examples/eyelang/network-sla.pl +48 -0
- package/examples/eyelang/newton-raphson.pl +49 -0
- package/examples/eyelang/nixon-diamond.pl +37 -0
- package/examples/eyelang/odrl-dpv-healthcare-risk-ranked.pl +266 -0
- package/examples/eyelang/odrl-dpv-risk-ranked.pl +320 -0
- package/examples/eyelang/orbital-transfer-design.pl +113 -0
- package/examples/eyelang/output/access-control-policy.pl +2 -0
- package/examples/eyelang/output/ackermann.pl +12 -0
- package/examples/eyelang/output/age.pl +2 -0
- package/examples/eyelang/output/aliases-and-namespaces.pl +5 -0
- package/examples/eyelang/output/alignment-demo.pl +32 -0
- package/examples/eyelang/output/allen-interval-calculus.pl +154 -0
- package/examples/eyelang/output/ancestor.pl +6 -0
- package/examples/eyelang/output/animal.pl +4 -0
- package/examples/eyelang/output/annotation-rdf12.ttl +1 -0
- package/examples/eyelang/output/annotation.pl +4 -0
- package/examples/eyelang/output/auroracare.pl +117 -0
- package/examples/eyelang/output/backward.pl +1 -0
- package/examples/eyelang/output/basic-monadic.pl +1518 -0
- package/examples/eyelang/output/bayes-diagnosis.pl +13 -0
- package/examples/eyelang/output/bayes-therapy.pl +23 -0
- package/examples/eyelang/output/beam-deflection.pl +5 -0
- package/examples/eyelang/output/blocks-world-planning.pl +4 -0
- package/examples/eyelang/output/bmi.pl +32 -0
- package/examples/eyelang/output/braking-safety-worlds.pl +18 -0
- package/examples/eyelang/output/buck-converter-design.pl +6 -0
- package/examples/eyelang/output/cache-performance.pl +4 -0
- package/examples/eyelang/output/canary-release.pl +5 -0
- package/examples/eyelang/output/cat-koko.pl +3 -0
- package/examples/eyelang/output/clinical-trial-screening.pl +9 -0
- package/examples/eyelang/output/collatz-1000.pl +1000 -0
- package/examples/eyelang/output/combinatorics-findall-sort.pl +2 -0
- package/examples/eyelang/output/competitive-enzyme-kinetics.pl +6 -0
- package/examples/eyelang/output/complex-matrix-stability.pl +5 -0
- package/examples/eyelang/output/complex.pl +1 -0
- package/examples/eyelang/output/composition-of-injective-functions-is-injective.pl +2 -0
- package/examples/eyelang/output/context-association.pl +3 -0
- package/examples/eyelang/output/control-system.pl +6 -0
- package/examples/eyelang/output/cryptarithmetic-send-more-money.pl +6 -0
- package/examples/eyelang/output/cyclic-path.pl +16 -0
- package/examples/eyelang/output/d3-group.pl +2 -0
- package/examples/eyelang/output/dairy-energy-balance.pl +13 -0
- package/examples/eyelang/output/data-negotiation.pl +1 -0
- package/examples/eyelang/output/deep-taxonomy-10.pl +16 -0
- package/examples/eyelang/output/deep-taxonomy-100.pl +16 -0
- package/examples/eyelang/output/deep-taxonomy-1000.pl +16 -0
- package/examples/eyelang/output/deep-taxonomy-10000.pl +16 -0
- package/examples/eyelang/output/deep-taxonomy-100000.pl +16 -0
- package/examples/eyelang/output/delfour.pl +31 -0
- package/examples/eyelang/output/dense-hamiltonian-cycle.pl +4 -0
- package/examples/eyelang/output/deontic-logic.pl +4 -0
- package/examples/eyelang/output/derived-backward-rule.pl +3 -0
- package/examples/eyelang/output/derived-rule.pl +2 -0
- package/examples/eyelang/output/diamond-property.pl +4 -0
- package/examples/eyelang/output/dijkstra-findall-sort.pl +2 -0
- package/examples/eyelang/output/dijkstra-risk-path.pl +29 -0
- package/examples/eyelang/output/dijkstra.pl +16 -0
- package/examples/eyelang/output/dining-philosophers.pl +350 -0
- package/examples/eyelang/output/directional-language.ttl +1 -0
- package/examples/eyelang/output/dog.pl +1 -0
- package/examples/eyelang/output/drone-corridor-planner.pl +17 -0
- package/examples/eyelang/output/easter-computus.pl +30 -0
- package/examples/eyelang/output/electrical-rc-filter.pl +3 -0
- package/examples/eyelang/output/epidemic-policy.pl +14 -0
- package/examples/eyelang/output/equivalence-classes-overlap-implies-same-class.pl +18 -0
- package/examples/eyelang/output/eulerian-path.pl +3 -0
- package/examples/eyelang/output/ev-range-worlds.pl +19 -0
- package/examples/eyelang/output/exact-cover-sudoku.pl +3 -0
- package/examples/eyelang/output/existential-rule.pl +2 -0
- package/examples/eyelang/output/exoplanet-validation-worlds.pl +22 -0
- package/examples/eyelang/output/expression-eval.pl +1 -0
- package/examples/eyelang/output/eyeling-ackermann.n3 +12 -0
- package/examples/eyelang/output/eyeling-age-threshold.n3 +4 -0
- package/examples/eyelang/output/eyeling-alignment-demo.n3 +1 -0
- package/examples/eyelang/output/eyeling-allen-interval-calculus-small.n3 +3 -0
- package/examples/eyelang/output/eyeling-backward-recursion.n3 +9 -0
- package/examples/eyelang/output/eyeling-backward.n3 +1 -0
- package/examples/eyelang/output/eyeling-basic-monadic-small.n3 +8 -0
- package/examples/eyelang/output/eyeling-bmi.n3 +2 -0
- package/examples/eyelang/output/eyeling-cat-koko.n3 +3 -0
- package/examples/eyelang/output/eyeling-collatz-small.n3 +3 -0
- package/examples/eyelang/output/eyeling-collection.n3 +1 -0
- package/examples/eyelang/output/eyeling-complex-arithmetic.n3 +5 -0
- package/examples/eyelang/output/eyeling-context-association.n3 +4 -0
- package/examples/eyelang/output/eyeling-control-system-small.n3 +4 -0
- package/examples/eyelang/output/eyeling-crypto-builtins-extra.n3 +3 -0
- package/examples/eyelang/output/eyeling-crypto-builtins.n3 +2 -0
- package/examples/eyelang/output/eyeling-deep-taxonomy-10.n3 +32 -0
- package/examples/eyelang/output/eyeling-derived-backward-rule-flat.n3 +4 -0
- package/examples/eyelang/output/eyeling-derived-rule-flat.n3 +2 -0
- package/examples/eyelang/output/eyeling-digital-product-passport-small.n3 +3 -0
- package/examples/eyelang/output/eyeling-dijkstra-tiny.n3 +9 -0
- package/examples/eyelang/output/eyeling-dog-license.n3 +1 -0
- package/examples/eyelang/output/eyeling-drone-corridor-planner-small.n3 +5 -0
- package/examples/eyelang/output/eyeling-equals.n3 +1 -0
- package/examples/eyelang/output/eyeling-equivalence-classes.n3 +2 -0
- package/examples/eyelang/output/eyeling-euler-identity.n3 +3 -0
- package/examples/eyelang/output/eyeling-existential-rule.n3 +4 -0
- package/examples/eyelang/output/eyeling-expression-eval.n3 +3 -0
- package/examples/eyelang/output/eyeling-family-cousins-extended.n3 +6 -0
- package/examples/eyelang/output/eyeling-fastpow.n3 +4 -0
- package/examples/eyelang/output/eyeling-fibonacci.n3 +6 -0
- package/examples/eyelang/output/eyeling-french-cities-reachability.n3 +25 -0
- package/examples/eyelang/output/eyeling-goldbach-small.n3 +2 -0
- package/examples/eyelang/output/eyeling-good-cobbler.n3 +2 -0
- package/examples/eyelang/output/eyeling-list-builtins.n3 +6 -0
- package/examples/eyelang/output/eyeling-list-collection-extra.n3 +5 -0
- package/examples/eyelang/output/eyeling-math-builtins.n3 +5 -0
- package/examples/eyelang/output/eyeling-string-builtins-extra.n3 +3 -0
- package/examples/eyelang/output/eyeling-string-builtins.n3 +4 -0
- package/examples/eyelang/output/eyeling-time-builtins.n3 +4 -0
- package/examples/eyelang/output/eyeling-time-components-extra.n3 +5 -0
- package/examples/eyelang/output/eyeling-witch.n3 +2 -0
- package/examples/eyelang/output/family-cousins.n3 +8 -0
- package/examples/eyelang/output/family-cousins.pl +28 -0
- package/examples/eyelang/output/fastpow.pl +6 -0
- package/examples/eyelang/output/fft8-numeric.pl +4 -0
- package/examples/eyelang/output/fibonacci.pl +6 -0
- package/examples/eyelang/output/field-nitrogen-balance.pl +21 -0
- package/examples/eyelang/output/flandor.pl +43 -0
- package/examples/eyelang/output/floating-point.pl +9 -0
- package/examples/eyelang/output/four-color-map.pl +3 -0
- package/examples/eyelang/output/fundamental-theorem-arithmetic.pl +9 -0
- package/examples/eyelang/output/gcd-bezout-identity.pl +36 -0
- package/examples/eyelang/output/gd-step-certified.pl +79 -0
- package/examples/eyelang/output/gdpr-compliance.pl +6 -0
- package/examples/eyelang/output/goldbach-1000.pl +667 -0
- package/examples/eyelang/output/good-cobbler.pl +1 -0
- package/examples/eyelang/output/gps.pl +21 -0
- package/examples/eyelang/output/graph-reachability.pl +3 -0
- package/examples/eyelang/output/gray-code-counter.pl +1 -0
- package/examples/eyelang/output/greatest-lower-bound-uniqueness.pl +2 -0
- package/examples/eyelang/output/group-inverse-uniqueness.pl +2 -0
- package/examples/eyelang/output/hamiltonian-cycle.pl +4 -0
- package/examples/eyelang/output/hamiltonian-path.pl +121 -0
- package/examples/eyelang/output/hamming-code.pl +6 -0
- package/examples/eyelang/output/hanoi.pl +1 -0
- package/examples/eyelang/output/heat-loss.pl +5 -0
- package/examples/eyelang/output/heron-theorem.pl +4 -0
- package/examples/eyelang/output/ideal-gas-law.pl +3 -0
- package/examples/eyelang/output/illegitimate-reasoning.pl +15 -0
- package/examples/eyelang/output/kaprekar.pl +8 -0
- package/examples/eyelang/output/law-of-cosines.pl +3 -0
- package/examples/eyelang/output/least-squares-regression.pl +5 -0
- package/examples/eyelang/output/list-collection.pl +3 -0
- package/examples/eyelang/output/lldm.pl +6 -0
- package/examples/eyelang/output/manufacturing-quality-control.pl +6 -0
- package/examples/eyelang/output/matrix.pl +10 -0
- package/examples/eyelang/output/microgrid-dispatch.pl +6 -0
- package/examples/eyelang/output/monkey-bananas.pl +5 -0
- package/examples/eyelang/output/n-queens.pl +93 -0
- package/examples/eyelang/output/n3-builtins.n3 +6 -0
- package/examples/eyelang/output/network-sla.pl +4 -0
- package/examples/eyelang/output/newton-raphson.pl +3 -0
- package/examples/eyelang/output/nixon-diamond.pl +5 -0
- package/examples/eyelang/output/odrl-dpv-healthcare-risk-ranked.pl +42 -0
- package/examples/eyelang/output/odrl-dpv-risk-ranked.pl +120 -0
- package/examples/eyelang/output/orbital-transfer-design.pl +7 -0
- package/examples/eyelang/output/path-discovery.pl +3 -0
- package/examples/eyelang/output/peano-arithmetic.pl +3 -0
- package/examples/eyelang/output/peasant.pl +10 -0
- package/examples/eyelang/output/pendulum-period.pl +4 -0
- package/examples/eyelang/output/polynomial.pl +14 -0
- package/examples/eyelang/output/project-portfolio-optimization.pl +6 -0
- package/examples/eyelang/output/proof-contrapositive.pl +3 -0
- package/examples/eyelang/output/quadratic-formula.pl +6 -0
- package/examples/eyelang/output/quine-mccluskey.pl +3 -0
- package/examples/eyelang/output/radioactive-decay.pl +5 -0
- package/examples/eyelang/output/resilient-city-orchestration.pl +67 -0
- package/examples/eyelang/output/riemann-hypothesis.pl +12 -0
- package/examples/eyelang/output/sat-dpll.pl +5 -0
- package/examples/eyelang/output/security-incident-correlation.pl +3 -0
- package/examples/eyelang/output/service-impact.pl +11 -0
- package/examples/eyelang/output/sieve.pl +1 -0
- package/examples/eyelang/output/skolem-functions.pl +16 -0
- package/examples/eyelang/output/socket-age.pl +1 -0
- package/examples/eyelang/output/socket-family.pl +3 -0
- package/examples/eyelang/output/socrates.n3 +1 -0
- package/examples/eyelang/output/socrates.pl +2 -0
- package/examples/eyelang/output/statistics-summary.pl +4 -0
- package/examples/eyelang/output/sudoku.pl +2 -0
- package/examples/eyelang/output/superdense-coding.pl +6 -0
- package/examples/eyelang/output/traveling-salesman.pl +1 -0
- package/examples/eyelang/output/triple-term.n3 +2 -0
- package/examples/eyelang/output/turing.pl +12 -0
- package/examples/eyelang/output/vector-similarity.pl +4 -0
- package/examples/eyelang/output/witch.pl +7 -0
- package/examples/eyelang/output/wolf-goat-cabbage.pl +3 -0
- package/examples/eyelang/output/zebra.pl +3 -0
- package/examples/eyelang/path-discovery.pl +44998 -0
- package/examples/eyelang/peano-arithmetic.pl +31 -0
- package/examples/eyelang/peasant.pl +30 -0
- package/examples/eyelang/pendulum-period.pl +50 -0
- package/examples/eyelang/polynomial.pl +124 -0
- package/examples/eyelang/project-portfolio-optimization.pl +101 -0
- package/examples/eyelang/proof/age.pl +71 -0
- package/examples/eyelang/proof/aliases-and-namespaces.pl +78 -0
- package/examples/eyelang/proof/ancestor.pl +140 -0
- package/examples/eyelang/proof/animal.pl +68 -0
- package/examples/eyelang/proof/annotation.pl +80 -0
- package/examples/eyelang/proof/backward.pl +22 -0
- package/examples/eyelang/proof/cat-koko.pl +86 -0
- package/examples/eyelang/proof/data-negotiation.pl +76 -0
- package/examples/eyelang/proof/derived-rule.pl +43 -0
- package/examples/eyelang/proof/dog.pl +31 -0
- package/examples/eyelang/proof/electrical-rc-filter.pl +105 -0
- package/examples/eyelang/proof/existential-rule.pl +40 -0
- package/examples/eyelang/proof/floating-point.pl +160 -0
- package/examples/eyelang/proof/good-cobbler.pl +16 -0
- package/examples/eyelang/proof/group-inverse-uniqueness.pl +84 -0
- package/examples/eyelang/proof/list-collection.pl +52 -0
- package/examples/eyelang/proof/proof-contrapositive.pl +78 -0
- package/examples/eyelang/proof/socket-age.pl +32 -0
- package/examples/eyelang/proof/socket-family.pl +59 -0
- package/examples/eyelang/proof/socrates.pl +38 -0
- package/examples/eyelang/proof-contrapositive.pl +27 -0
- package/examples/eyelang/quadratic-formula.pl +54 -0
- package/examples/eyelang/quine-mccluskey.pl +143 -0
- package/examples/eyelang/radioactive-decay.pl +56 -0
- package/examples/eyelang/resilient-city-orchestration.pl +303 -0
- package/examples/eyelang/riemann-hypothesis.pl +110 -0
- package/examples/eyelang/sat-dpll.pl +80 -0
- package/examples/eyelang/security-incident-correlation.pl +69 -0
- package/examples/eyelang/service-impact.pl +41 -0
- package/examples/eyelang/sieve.pl +20 -0
- package/examples/eyelang/skolem-functions.pl +52 -0
- package/examples/eyelang/socket-age.pl +39 -0
- package/examples/eyelang/socket-family.pl +28 -0
- package/examples/eyelang/socrates.n3 +11 -0
- package/examples/eyelang/socrates.pl +19 -0
- package/examples/eyelang/statistics-summary.pl +54 -0
- package/examples/eyelang/sudoku.pl +20 -0
- package/examples/eyelang/superdense-coding.pl +84 -0
- package/examples/eyelang/traveling-salesman.pl +64 -0
- package/examples/eyelang/triple-term.n3 +9 -0
- package/examples/eyelang/turing.pl +67 -0
- package/examples/eyelang/vector-similarity.pl +56 -0
- package/examples/eyelang/witch.pl +38 -0
- package/examples/eyelang/wolf-goat-cabbage.pl +56 -0
- package/examples/eyelang/zebra.pl +44 -0
- package/eyelang.d.ts +92 -0
- package/eyeling.js +1 -0
- package/index.d.ts +50 -2
- package/index.js +95 -1
- package/lib/cli.js +1 -0
- package/lib/eyelang/bin.js +7 -0
- package/lib/eyelang/builtins/aggregation.mjs +81 -0
- package/lib/eyelang/builtins/alphametic.mjs +144 -0
- package/lib/eyelang/builtins/arithmetic.mjs +197 -0
- package/lib/eyelang/builtins/control.mjs +22 -0
- package/lib/eyelang/builtins/core.mjs +78 -0
- package/lib/eyelang/builtins/formula.mjs +42 -0
- package/lib/eyelang/builtins/lists.mjs +149 -0
- package/lib/eyelang/builtins/matrix.mjs +226 -0
- package/lib/eyelang/builtins/n3.mjs +483 -0
- package/lib/eyelang/builtins/number-theory.mjs +114 -0
- package/lib/eyelang/builtins/portfolio.mjs +73 -0
- package/lib/eyelang/builtins/registry.mjs +54 -0
- package/lib/eyelang/builtins/search.mjs +579 -0
- package/lib/eyelang/builtins/strings.mjs +41 -0
- package/lib/eyelang/builtins/sudoku.mjs +141 -0
- package/lib/eyelang/cli.mjs +192 -0
- package/lib/eyelang/explain.mjs +324 -0
- package/lib/eyelang/hash.mjs +294 -0
- package/lib/eyelang/index.mjs +48 -0
- package/lib/eyelang/parser.mjs +428 -0
- package/lib/eyelang/program.mjs +244 -0
- package/lib/eyelang/rdf.mjs +747 -0
- package/lib/eyelang/solver.mjs +237 -0
- package/lib/eyelang/term.mjs +328 -0
- package/package.json +12 -3
- package/test/eyelang/conformance/README.md +45 -0
- package/test/eyelang/conformance/cases/core/001_fact_output.pl +4 -0
- package/test/eyelang/conformance/cases/core/001_fact_query.query +1 -0
- package/test/eyelang/conformance/cases/core/002_rule_recursion.pl +7 -0
- package/test/eyelang/conformance/cases/core/002_rule_recursion.query +1 -0
- package/test/eyelang/conformance/cases/core/003_terms_and_readback.pl +16 -0
- package/test/eyelang/conformance/cases/core/003_terms_and_readback.query +1 -0
- package/test/eyelang/conformance/cases/core/004_conjunction_and_parentheses.pl +5 -0
- package/test/eyelang/conformance/cases/core/004_conjunction_and_parentheses.query +1 -0
- package/test/eyelang/conformance/cases/core/005_list_deconstruction.pl +6 -0
- package/test/eyelang/conformance/cases/core/005_list_deconstruction.query +1 -0
- package/test/eyelang/conformance/cases/core/006_comma_formula_data.pl +4 -0
- package/test/eyelang/conformance/cases/core/006_comma_formula_data.query +1 -0
- package/test/eyelang/conformance/cases/core/007_anonymous_variables.pl +5 -0
- package/test/eyelang/conformance/cases/core/007_anonymous_variables.query +1 -0
- package/test/eyelang/conformance/cases/core/008_graphic_atoms.pl +6 -0
- package/test/eyelang/conformance/cases/core/008_graphic_atoms.query +1 -0
- package/test/eyelang/conformance/cases/core/009_comments_and_whitespace.pl +5 -0
- package/test/eyelang/conformance/cases/core/009_comments_and_whitespace.query +1 -0
- package/test/eyelang/conformance/cases/core/010_variable_scope_and_reuse.pl +8 -0
- package/test/eyelang/conformance/cases/core/010_variable_scope_and_reuse.query +1 -0
- package/test/eyelang/conformance/cases/core/011_predicate_arity.pl +6 -0
- package/test/eyelang/conformance/cases/core/011_predicate_arity.query +1 -0
- package/test/eyelang/conformance/cases/core/012_nested_compound_unification.pl +5 -0
- package/test/eyelang/conformance/cases/core/012_nested_compound_unification.query +1 -0
- package/test/eyelang/conformance/cases/core/013_multiple_clauses_order.pl +6 -0
- package/test/eyelang/conformance/cases/core/013_multiple_clauses_order.query +1 -0
- package/test/eyelang/conformance/cases/core/014_failure_filters_answers.pl +7 -0
- package/test/eyelang/conformance/cases/core/014_failure_filters_answers.query +1 -0
- package/test/eyelang/conformance/cases/core/015_improper_list_unification.pl +6 -0
- package/test/eyelang/conformance/cases/core/015_improper_list_unification.query +1 -0
- package/test/eyelang/conformance/cases/core/016_zero_arity_compound.pl +4 -0
- package/test/eyelang/conformance/cases/core/016_zero_arity_compound.query +1 -0
- package/test/eyelang/conformance/cases/core/017_three_step_recursion.pl +8 -0
- package/test/eyelang/conformance/cases/core/017_three_step_recursion.query +1 -0
- package/test/eyelang/conformance/cases/core/018_quoted_atom_readback.pl +6 -0
- package/test/eyelang/conformance/cases/core/018_quoted_atom_readback.query +1 -0
- package/test/eyelang/conformance/cases/core/019_parenthesized_three_conjuncts.pl +7 -0
- package/test/eyelang/conformance/cases/core/019_parenthesized_three_conjuncts.query +1 -0
- package/test/eyelang/conformance/cases/core/020_nested_list_terms.pl +5 -0
- package/test/eyelang/conformance/cases/core/020_nested_list_terms.query +1 -0
- package/test/eyelang/conformance/cases/core/021_repeated_variable_head.pl +7 -0
- package/test/eyelang/conformance/cases/core/022_rule_head_structure.pl +5 -0
- package/test/eyelang/conformance/cases/core/023_quoted_escapes_readback.pl +5 -0
- package/test/eyelang/conformance/cases/core/024_numeric_literal_readback.pl +6 -0
- package/test/eyelang/conformance/cases/core/025_body_parentheses_with_formula_data.pl +5 -0
- package/test/eyelang/conformance/cases/core/026_underscore_named_variable_reuse.pl +5 -0
- package/test/eyelang/conformance/cases/extension/001_default_derived_output.pl +5 -0
- package/test/eyelang/conformance/cases/extension/002_materialize_focus.pl +5 -0
- package/test/eyelang/conformance/cases/extension/003_arithmetic_and_comparison.pl +12 -0
- package/test/eyelang/conformance/cases/extension/003_arithmetic_and_comparison.query +1 -0
- package/test/eyelang/conformance/cases/extension/004_strings_and_atoms.pl +6 -0
- package/test/eyelang/conformance/cases/extension/004_strings_and_atoms.query +1 -0
- package/test/eyelang/conformance/cases/extension/005_lists_aggregation_ordering.pl +10 -0
- package/test/eyelang/conformance/cases/extension/005_lists_aggregation_ordering.query +1 -0
- package/test/eyelang/conformance/cases/extension/006_formula_terms.pl +5 -0
- package/test/eyelang/conformance/cases/extension/006_formula_terms.query +1 -0
- package/test/eyelang/conformance/cases/extension/007_negation_once_generators.pl +7 -0
- package/test/eyelang/conformance/cases/extension/007_negation_once_generators.query +1 -0
- package/test/eyelang/conformance/cases/extension/008_equality_and_inequality.pl +6 -0
- package/test/eyelang/conformance/cases/extension/008_equality_and_inequality.query +1 -0
- package/test/eyelang/conformance/cases/extension/009_list_relations.pl +6 -0
- package/test/eyelang/conformance/cases/extension/009_list_relations.query +1 -0
- package/test/eyelang/conformance/cases/extension/010_append_splits.pl +3 -0
- package/test/eyelang/conformance/cases/extension/010_append_splits.query +1 -0
- package/test/eyelang/conformance/cases/extension/011_matching_and_comparison.pl +7 -0
- package/test/eyelang/conformance/cases/extension/011_matching_and_comparison.query +1 -0
- package/test/eyelang/conformance/cases/extension/012_memoize_declaration.pl +8 -0
- package/test/eyelang/conformance/cases/extension/012_memoize_declaration.query +1 -0
- package/test/eyelang/conformance/cases/extension/013_numeric_functions.pl +9 -0
- package/test/eyelang/conformance/cases/extension/013_numeric_functions.query +1 -0
- package/test/eyelang/conformance/cases/extension/014_between_enumeration.pl +3 -0
- package/test/eyelang/conformance/cases/extension/014_between_enumeration.query +1 -0
- package/test/eyelang/conformance/cases/extension/015_smallest_divisor.pl +3 -0
- package/test/eyelang/conformance/cases/extension/015_smallest_divisor.query +1 -0
- package/test/eyelang/conformance/cases/extension/016_negation_filter.pl +7 -0
- package/test/eyelang/conformance/cases/extension/016_negation_filter.query +1 -0
- package/test/eyelang/conformance/cases/extension/017_once_user_predicate.pl +5 -0
- package/test/eyelang/conformance/cases/extension/017_once_user_predicate.query +1 -0
- package/test/eyelang/conformance/cases/extension/018_findall_user_goal.pl +6 -0
- package/test/eyelang/conformance/cases/extension/018_findall_user_goal.query +1 -0
- package/test/eyelang/conformance/cases/extension/019_sort_deduplicates_atoms.pl +3 -0
- package/test/eyelang/conformance/cases/extension/019_sort_deduplicates_atoms.query +1 -0
- package/test/eyelang/conformance/cases/extension/020_append_bound_prefix_suffix.pl +4 -0
- package/test/eyelang/conformance/cases/extension/020_append_bound_prefix_suffix.query +1 -0
- package/test/eyelang/conformance/cases/extension/021_nth0_index_generation.pl +3 -0
- package/test/eyelang/conformance/cases/extension/021_nth0_index_generation.query +1 -0
- package/test/eyelang/conformance/cases/extension/022_set_nth0_edges.pl +4 -0
- package/test/eyelang/conformance/cases/extension/022_set_nth0_edges.query +1 -0
- package/test/eyelang/conformance/cases/extension/023_select_duplicate_occurrences.pl +3 -0
- package/test/eyelang/conformance/cases/extension/023_select_duplicate_occurrences.query +1 -0
- package/test/eyelang/conformance/cases/extension/024_not_member_filter.pl +6 -0
- package/test/eyelang/conformance/cases/extension/024_not_member_filter.query +1 -0
- package/test/eyelang/conformance/cases/extension/025_is_list_filter.pl +5 -0
- package/test/eyelang/conformance/cases/extension/025_is_list_filter.query +1 -0
- package/test/eyelang/conformance/cases/extension/026_nested_formula_terms.pl +5 -0
- package/test/eyelang/conformance/cases/extension/026_nested_formula_terms.query +1 -0
- package/test/eyelang/conformance/cases/extension/027_materialize_excludes_source_fact.pl +6 -0
- package/test/eyelang/conformance/cases/extension/028_numeric_and_lexical_comparison.pl +5 -0
- package/test/eyelang/conformance/cases/extension/028_numeric_and_lexical_comparison.query +1 -0
- package/test/eyelang/conformance/cases/extension/029_string_matching_filters.pl +6 -0
- package/test/eyelang/conformance/cases/extension/029_string_matching_filters.query +1 -0
- package/test/eyelang/conformance/cases/extension/030_string_and_atom_concat.pl +4 -0
- package/test/eyelang/conformance/cases/extension/030_string_and_atom_concat.query +1 -0
- package/test/eyelang/conformance/cases/extension/031_countall_empty_and_nonempty.pl +4 -0
- package/test/eyelang/conformance/cases/extension/031_countall_empty_and_nonempty.query +1 -0
- package/test/eyelang/conformance/cases/extension/032_sumall_numeric_template.pl +5 -0
- package/test/eyelang/conformance/cases/extension/032_sumall_numeric_template.query +1 -0
- package/test/eyelang/conformance/cases/extension/033_aggregate_min_template.pl +5 -0
- package/test/eyelang/conformance/cases/extension/033_aggregate_min_template.query +1 -0
- package/test/eyelang/conformance/cases/extension/034_aggregate_max_compound_key.pl +5 -0
- package/test/eyelang/conformance/cases/extension/034_aggregate_max_compound_key.query +1 -0
- package/test/eyelang/conformance/cases/extension/035_date_difference.pl +4 -0
- package/test/eyelang/conformance/cases/extension/036_extended_gcd.pl +3 -0
- package/test/eyelang/conformance/cases/extension/037_collatz_trajectory.pl +3 -0
- package/test/eyelang/conformance/cases/extension/038_kaprekar_steps.pl +3 -0
- package/test/eyelang/conformance/cases/extension/039_goldbach_pair.pl +3 -0
- package/test/eyelang/conformance/cases/extension/040_matrix_operations.pl +5 -0
- package/test/eyelang/conformance/cases/extension/041_atom_range_generators.pl +5 -0
- package/test/eyelang/conformance/cases/extension/042_n_queens_small.pl +3 -0
- package/test/eyelang/conformance/cases/extension/043_cnf_model.pl +3 -0
- package/test/eyelang/conformance/cases/extension/044_cover9_filter.pl +6 -0
- package/test/eyelang/conformance/cases/extension/045_alphametic_sum_small.pl +3 -0
- package/test/eyelang/conformance/cases/extension/046_bounded_subset.pl +4 -0
- package/test/eyelang/conformance/expected/core/001_fact_output.out +1 -0
- package/test/eyelang/conformance/expected/core/002_rule_recursion.out +2 -0
- package/test/eyelang/conformance/expected/core/003_terms_and_readback.out +13 -0
- package/test/eyelang/conformance/expected/core/004_conjunction_and_parentheses.out +1 -0
- package/test/eyelang/conformance/expected/core/005_list_deconstruction.out +2 -0
- package/test/eyelang/conformance/expected/core/006_comma_formula_data.out +1 -0
- package/test/eyelang/conformance/expected/core/007_anonymous_variables.out +1 -0
- package/test/eyelang/conformance/expected/core/008_graphic_atoms.out +3 -0
- package/test/eyelang/conformance/expected/core/009_comments_and_whitespace.out +2 -0
- package/test/eyelang/conformance/expected/core/010_variable_scope_and_reuse.out +2 -0
- package/test/eyelang/conformance/expected/core/011_predicate_arity.out +2 -0
- package/test/eyelang/conformance/expected/core/012_nested_compound_unification.out +2 -0
- package/test/eyelang/conformance/expected/core/013_multiple_clauses_order.out +2 -0
- package/test/eyelang/conformance/expected/core/014_failure_filters_answers.out +1 -0
- package/test/eyelang/conformance/expected/core/015_improper_list_unification.out +3 -0
- package/test/eyelang/conformance/expected/core/016_zero_arity_compound.out +1 -0
- package/test/eyelang/conformance/expected/core/017_three_step_recursion.out +3 -0
- package/test/eyelang/conformance/expected/core/018_quoted_atom_readback.out +3 -0
- package/test/eyelang/conformance/expected/core/019_parenthesized_three_conjuncts.out +1 -0
- package/test/eyelang/conformance/expected/core/020_nested_list_terms.out +2 -0
- package/test/eyelang/conformance/expected/core/021_repeated_variable_head.out +2 -0
- package/test/eyelang/conformance/expected/core/022_rule_head_structure.out +2 -0
- package/test/eyelang/conformance/expected/core/023_quoted_escapes_readback.out +2 -0
- package/test/eyelang/conformance/expected/core/024_numeric_literal_readback.out +3 -0
- package/test/eyelang/conformance/expected/core/025_body_parentheses_with_formula_data.out +1 -0
- package/test/eyelang/conformance/expected/core/026_underscore_named_variable_reuse.out +1 -0
- package/test/eyelang/conformance/expected/extension/001_default_derived_output.out +3 -0
- package/test/eyelang/conformance/expected/extension/002_materialize_focus.out +1 -0
- package/test/eyelang/conformance/expected/extension/003_arithmetic_and_comparison.out +10 -0
- package/test/eyelang/conformance/expected/extension/004_strings_and_atoms.out +4 -0
- package/test/eyelang/conformance/expected/extension/005_lists_aggregation_ordering.out +9 -0
- package/test/eyelang/conformance/expected/extension/006_formula_terms.out +4 -0
- package/test/eyelang/conformance/expected/extension/007_negation_once_generators.out +2 -0
- package/test/eyelang/conformance/expected/extension/008_equality_and_inequality.out +4 -0
- package/test/eyelang/conformance/expected/extension/009_list_relations.out +5 -0
- package/test/eyelang/conformance/expected/extension/010_append_splits.out +3 -0
- package/test/eyelang/conformance/expected/extension/011_matching_and_comparison.out +5 -0
- package/test/eyelang/conformance/expected/extension/012_memoize_declaration.out +2 -0
- package/test/eyelang/conformance/expected/extension/013_numeric_functions.out +7 -0
- package/test/eyelang/conformance/expected/extension/014_between_enumeration.out +3 -0
- package/test/eyelang/conformance/expected/extension/015_smallest_divisor.out +1 -0
- package/test/eyelang/conformance/expected/extension/016_negation_filter.out +2 -0
- package/test/eyelang/conformance/expected/extension/017_once_user_predicate.out +1 -0
- package/test/eyelang/conformance/expected/extension/018_findall_user_goal.out +1 -0
- package/test/eyelang/conformance/expected/extension/019_sort_deduplicates_atoms.out +1 -0
- package/test/eyelang/conformance/expected/extension/020_append_bound_prefix_suffix.out +2 -0
- package/test/eyelang/conformance/expected/extension/021_nth0_index_generation.out +1 -0
- package/test/eyelang/conformance/expected/extension/022_set_nth0_edges.out +2 -0
- package/test/eyelang/conformance/expected/extension/023_select_duplicate_occurrences.out +2 -0
- package/test/eyelang/conformance/expected/extension/024_not_member_filter.out +1 -0
- package/test/eyelang/conformance/expected/extension/025_is_list_filter.out +1 -0
- package/test/eyelang/conformance/expected/extension/026_nested_formula_terms.out +6 -0
- package/test/eyelang/conformance/expected/extension/027_materialize_excludes_source_fact.out +1 -0
- package/test/eyelang/conformance/expected/extension/028_numeric_and_lexical_comparison.out +3 -0
- package/test/eyelang/conformance/expected/extension/029_string_matching_filters.out +2 -0
- package/test/eyelang/conformance/expected/extension/030_string_and_atom_concat.out +2 -0
- package/test/eyelang/conformance/expected/extension/031_countall_empty_and_nonempty.out +1 -0
- package/test/eyelang/conformance/expected/extension/032_sumall_numeric_template.out +1 -0
- package/test/eyelang/conformance/expected/extension/033_aggregate_min_template.out +1 -0
- package/test/eyelang/conformance/expected/extension/034_aggregate_max_compound_key.out +1 -0
- package/test/eyelang/conformance/expected/extension/035_date_difference.out +2 -0
- package/test/eyelang/conformance/expected/extension/036_extended_gcd.out +1 -0
- package/test/eyelang/conformance/expected/extension/037_collatz_trajectory.out +1 -0
- package/test/eyelang/conformance/expected/extension/038_kaprekar_steps.out +1 -0
- package/test/eyelang/conformance/expected/extension/039_goldbach_pair.out +2 -0
- package/test/eyelang/conformance/expected/extension/040_matrix_operations.out +3 -0
- package/test/eyelang/conformance/expected/extension/041_atom_range_generators.out +8 -0
- package/test/eyelang/conformance/expected/extension/042_n_queens_small.out +2 -0
- package/test/eyelang/conformance/expected/extension/043_cnf_model.out +1 -0
- package/test/eyelang/conformance/expected/extension/044_cover9_filter.out +2 -0
- package/test/eyelang/conformance/expected/extension/045_alphametic_sum_small.out +4 -0
- package/test/eyelang/conformance/expected/extension/046_bounded_subset.out +5 -0
- package/test/eyelang/run-all.mjs +20 -0
- package/test/eyelang/run-conformance.mjs +80 -0
- package/test/eyelang/run-examples.mjs +126 -0
- package/test/eyelang/run-regression.mjs +640 -0
- package/test/eyelang/test-style.mjs +91 -0
- package/test/eyelang.test.js +58 -0
- package/test/run.js +1 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// Registry for builtins and their execution metadata.
|
|
2
|
+
// The solver uses the metadata to know when a builtin is deterministic, mode-ready, or should fall back to user clauses.
|
|
3
|
+
import { arithmeticBuiltins } from './arithmetic.mjs';
|
|
4
|
+
import { coreBuiltins } from './core.mjs';
|
|
5
|
+
import { stringBuiltins } from './strings.mjs';
|
|
6
|
+
import { listBuiltins } from './lists.mjs';
|
|
7
|
+
import { aggregationBuiltins } from './aggregation.mjs';
|
|
8
|
+
import { formulaBuiltins } from './formula.mjs';
|
|
9
|
+
import { controlBuiltins } from './control.mjs';
|
|
10
|
+
import { sudokuBuiltins } from './sudoku.mjs';
|
|
11
|
+
import { portfolioBuiltins } from './portfolio.mjs';
|
|
12
|
+
import { searchBuiltins } from './search.mjs';
|
|
13
|
+
import { numberTheoryBuiltins } from './number-theory.mjs';
|
|
14
|
+
import { matrixBuiltins } from './matrix.mjs';
|
|
15
|
+
import { alphameticBuiltins } from './alphametic.mjs';
|
|
16
|
+
import { n3Builtins } from './n3.mjs';
|
|
17
|
+
|
|
18
|
+
export class BuiltinRegistry {
|
|
19
|
+
constructor() {
|
|
20
|
+
this.defs = new Map();
|
|
21
|
+
}
|
|
22
|
+
add(name, arity, handler, options = {}) {
|
|
23
|
+
// ready() describes the argument mode in which the builtin is safe to run;
|
|
24
|
+
// fallbackWhenNotReady keeps user-defined clauses visible outside that mode.
|
|
25
|
+
this.defs.set(`${name}/${arity}`, {
|
|
26
|
+
name,
|
|
27
|
+
arity,
|
|
28
|
+
handler,
|
|
29
|
+
deterministic: options.deterministic ?? false,
|
|
30
|
+
ready: options.ready ?? null,
|
|
31
|
+
fallbackWhenNotReady: options.fallbackWhenNotReady ?? false,
|
|
32
|
+
shouldUse: options.shouldUse ?? null,
|
|
33
|
+
});
|
|
34
|
+
return this;
|
|
35
|
+
}
|
|
36
|
+
get(name, arity) {
|
|
37
|
+
return this.defs.get(`${name}/${arity}`) ?? null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function createDefaultRegistry() {
|
|
42
|
+
const registry = new BuiltinRegistry();
|
|
43
|
+
for (const mod of [coreBuiltins, arithmeticBuiltins, stringBuiltins, listBuiltins, aggregationBuiltins, formulaBuiltins, controlBuiltins, sudokuBuiltins, portfolioBuiltins, searchBuiltins, numberTheoryBuiltins, matrixBuiltins, alphameticBuiltins, n3Builtins]) {
|
|
44
|
+
mod.register(registry);
|
|
45
|
+
}
|
|
46
|
+
return registry;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
let defaultRegistry = null;
|
|
50
|
+
|
|
51
|
+
export function getDefaultRegistry() {
|
|
52
|
+
if (defaultRegistry == null) defaultRegistry = createDefaultRegistry();
|
|
53
|
+
return defaultRegistry;
|
|
54
|
+
}
|
|
@@ -0,0 +1,579 @@
|
|
|
1
|
+
// Reusable finite-search builtins for examples that would otherwise spend most
|
|
2
|
+
// of their time in small relational generators. These predicates are generic
|
|
3
|
+
// entry points (graph, CNF, QMC, range, and n-queens helpers), not compiled
|
|
4
|
+
// replacements for particular example predicate names.
|
|
5
|
+
import { atom, compound, deref, listFromItems, numberTerm, properListItems, unify } from '../term.mjs';
|
|
6
|
+
import { compareLexicalOrNumeric } from './arithmetic.mjs';
|
|
7
|
+
|
|
8
|
+
export const searchBuiltins = {
|
|
9
|
+
register(registry) {
|
|
10
|
+
registry.add('atom_range', 4, atomRange, { fallbackWhenNotReady: true, ready: atomRangeReady });
|
|
11
|
+
registry.add('atom_ranges', 4, atomRanges, { fallbackWhenNotReady: true, ready: atomRangesReady });
|
|
12
|
+
registry.add('n_queens', 2, nQueens, { fallbackWhenNotReady: true, ready: firstIntReady });
|
|
13
|
+
registry.add('weighted_hamiltonian_cycle', 4, weightedHamiltonianCycle, { fallbackWhenNotReady: true, ready: weightedGraphReady });
|
|
14
|
+
registry.add('weighted_hamiltonian_path', 4, weightedHamiltonianPath, { fallbackWhenNotReady: true, ready: weightedGraphReady });
|
|
15
|
+
registry.add('hamiltonian_cycle', 3, hamiltonianCycle, { fallbackWhenNotReady: true, ready: graphReady });
|
|
16
|
+
registry.add('fixed_length_cycle', 4, fixedLengthCycle, { fallbackWhenNotReady: true, ready: fixedCycleReady });
|
|
17
|
+
registry.add('bounded_path', 5, boundedPath, { fallbackWhenNotReady: true, ready: boundedPathReady });
|
|
18
|
+
registry.add('cnf_model', 3, cnfModel, { fallbackWhenNotReady: true, ready: cnfReady });
|
|
19
|
+
registry.add('qm_prime_implicants', 4, qmPrimeImplicants, { deterministic: true, ready: qmReady });
|
|
20
|
+
registry.add('qm_minimal_cover', 4, qmMinimalCover, { deterministic: true, ready: qmReady });
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
function firstIntReady(goal, env) { return intTerm(goal.args[0], env) !== null; }
|
|
25
|
+
function graphReady(goal, env) { return atomKey(deref(goal.args[0], env)) !== null && properListItems(goal.args[1], env) !== null; }
|
|
26
|
+
function weightedGraphReady(goal, env) { return graphReady(goal, env); }
|
|
27
|
+
function fixedCycleReady(goal, env) { return atomKey(deref(goal.args[0], env)) !== null && intTerm(goal.args[1], env) !== null; }
|
|
28
|
+
function boundedPathReady(goal, env) { return atomKey(deref(goal.args[0], env)) !== null && atomKey(deref(goal.args[1], env)) !== null && atomKey(deref(goal.args[2], env)) !== null && intTerm(goal.args[3], env) !== null; }
|
|
29
|
+
function atomRangeReady(goal, env) { return atomKey(deref(goal.args[0], env)) !== null && intTerm(goal.args[1], env) !== null && intTerm(goal.args[2], env) !== null; }
|
|
30
|
+
function atomRangesReady(goal, env) { return atomList(goal.args[0], env) !== null && intTerm(goal.args[1], env) !== null && intTerm(goal.args[2], env) !== null; }
|
|
31
|
+
function cnfReady(goal, env) { return atomList(goal.args[0], env) !== null && clauseList(goal.args[1], env) !== null; }
|
|
32
|
+
function qmReady(goal, env) { return numberList(goal.args[0], env) !== null && numberList(goal.args[1], env) !== null && bitTable(goal.args[2], env) !== null; }
|
|
33
|
+
|
|
34
|
+
function* atomRange({ goal, env }) {
|
|
35
|
+
// atom_range(Prefix, Low, High, Atom) is a compact generator for atoms such
|
|
36
|
+
// as n1, n2, ...; it replaces between/3 + atom_concat/3 in large generated
|
|
37
|
+
// data sets without committing to any domain-specific predicate name.
|
|
38
|
+
const prefix = atomKey(deref(goal.args[0], env));
|
|
39
|
+
const low = intTerm(goal.args[1], env);
|
|
40
|
+
const high = intTerm(goal.args[2], env);
|
|
41
|
+
if (prefix == null || low == null || high == null) return;
|
|
42
|
+
const output = deref(goal.args[3], env);
|
|
43
|
+
if (output.type !== 'var') {
|
|
44
|
+
const text = atomKey(output);
|
|
45
|
+
const n = parsePrefixedInteger(prefix, text);
|
|
46
|
+
if (n == null || n < low || n > high) return;
|
|
47
|
+
yield env;
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
for (let i = low; i <= high; i++) {
|
|
51
|
+
const next = env.clone();
|
|
52
|
+
next.bind(output.name, atom(`${prefix}${i}`));
|
|
53
|
+
yield next;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function parsePrefixedInteger(prefix, text) {
|
|
58
|
+
if (text == null || !text.startsWith(prefix)) return null;
|
|
59
|
+
const suffix = text.slice(prefix.length);
|
|
60
|
+
if (!/^\d+$/.test(suffix)) return null;
|
|
61
|
+
const n = Number(suffix);
|
|
62
|
+
return Number.isSafeInteger(n) ? n : null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function* atomRanges({ goal, env }) {
|
|
66
|
+
// atom_ranges([p, q], Low, High, Atom) is the multi-prefix companion to
|
|
67
|
+
// atom_range/4. It is useful when several generated atom families feed the
|
|
68
|
+
// same relation.
|
|
69
|
+
const prefixes = atomList(goal.args[0], env);
|
|
70
|
+
const low = intTerm(goal.args[1], env);
|
|
71
|
+
const high = intTerm(goal.args[2], env);
|
|
72
|
+
if (!prefixes || low == null || high == null) return;
|
|
73
|
+
const output = deref(goal.args[3], env);
|
|
74
|
+
if (output.type !== 'var') {
|
|
75
|
+
const text = atomKey(output);
|
|
76
|
+
for (const prefix of prefixes) {
|
|
77
|
+
const n = parsePrefixedInteger(prefix, text);
|
|
78
|
+
if (n != null && n >= low && n <= high) { yield env; return; }
|
|
79
|
+
}
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
for (const prefix of prefixes) {
|
|
83
|
+
for (let i = low; i <= high; i++) {
|
|
84
|
+
const next = env.clone();
|
|
85
|
+
next.bind(output.name, atom(`${prefix}${i}`));
|
|
86
|
+
yield next;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function* nQueens({ goal, env }) {
|
|
92
|
+
// n_queens(N, Solution) performs the same finite search as the declarative
|
|
93
|
+
// select/not_member version, but keeps occupied diagonals in sets.
|
|
94
|
+
const n = intTerm(goal.args[0], env);
|
|
95
|
+
if (n == null || n < 0 || n > 14) return;
|
|
96
|
+
const cols = Array.from({ length: n }, (_, i) => i + 1);
|
|
97
|
+
const chosen = [];
|
|
98
|
+
const down = new Set();
|
|
99
|
+
const up = new Set();
|
|
100
|
+
function* place(row, remaining) {
|
|
101
|
+
if (remaining.length === 0) { yield chosen.slice(); return; }
|
|
102
|
+
for (let i = 0; i < remaining.length; i++) {
|
|
103
|
+
const q = remaining[i];
|
|
104
|
+
const d = row + q;
|
|
105
|
+
const u = row - q;
|
|
106
|
+
if (down.has(d) || up.has(u)) continue;
|
|
107
|
+
chosen.push(q); down.add(d); up.add(u);
|
|
108
|
+
const rest = remaining.slice(0, i).concat(remaining.slice(i + 1));
|
|
109
|
+
yield* place(row + 1, rest);
|
|
110
|
+
up.delete(u); down.delete(d); chosen.pop();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
for (const solution of place(1, cols)) {
|
|
114
|
+
const next = env.clone();
|
|
115
|
+
if (unify(goal.args[1], listFromItems(solution.map(numberTerm)), next)) yield next;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function* weightedHamiltonianCycle({ solver, goal, env }) {
|
|
120
|
+
// weighted_hamiltonian_cycle(EdgePred, Cities, Cycle, Cost) treats
|
|
121
|
+
// EdgePred/3 facts as undirected weighted edges and enumerates
|
|
122
|
+
// symmetry-broken cycles beginning at the first city.
|
|
123
|
+
const predicate = atomKey(deref(goal.args[0], env));
|
|
124
|
+
const cities = properListItems(goal.args[1], env);
|
|
125
|
+
if (!predicate || !cities || cities.length < 2) return;
|
|
126
|
+
const weights = edgeWeightMap(solver.program, predicate);
|
|
127
|
+
if (!weights) return;
|
|
128
|
+
const start = cities[0];
|
|
129
|
+
const rest = cities.slice(1);
|
|
130
|
+
for (const order of permutations(rest)) {
|
|
131
|
+
if (compareLexicalOrNumeric(atomKey(order[0]), atomKey(order[order.length - 1])) >= 0) continue;
|
|
132
|
+
const cost = weightedPathCost([start, ...order, start], weights);
|
|
133
|
+
if (cost == null) continue;
|
|
134
|
+
const next = env.clone();
|
|
135
|
+
if (unify(goal.args[2], listFromItems([start, ...order, start]), next) && unify(goal.args[3], numberTerm(cost), next)) yield next;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function* weightedHamiltonianPath({ solver, goal, env }) {
|
|
140
|
+
// weighted_hamiltonian_path(EdgePred, Cities, Path, Cost) enumerates paths
|
|
141
|
+
// from the first city through every remaining city exactly once.
|
|
142
|
+
const predicate = atomKey(deref(goal.args[0], env));
|
|
143
|
+
const cities = properListItems(goal.args[1], env);
|
|
144
|
+
if (!predicate || !cities || cities.length < 1) return;
|
|
145
|
+
const weights = edgeWeightMap(solver.program, predicate);
|
|
146
|
+
if (!weights) return;
|
|
147
|
+
const start = cities[0];
|
|
148
|
+
const rest = cities.slice(1);
|
|
149
|
+
for (const order of permutations(rest)) {
|
|
150
|
+
const path = [start, ...order];
|
|
151
|
+
const cost = weightedPathCost(path, weights);
|
|
152
|
+
if (cost == null) continue;
|
|
153
|
+
const next = env.clone();
|
|
154
|
+
if (unify(goal.args[2], listFromItems(path), next) && unify(goal.args[3], numberTerm(cost), next)) yield next;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function weightedPathCost(path, weights) {
|
|
159
|
+
let cost = 0;
|
|
160
|
+
for (let i = 1; i < path.length; i++) {
|
|
161
|
+
const w = weights.get(`${atomKey(path[i - 1])}\x1f${atomKey(path[i])}`);
|
|
162
|
+
if (w == null) return null;
|
|
163
|
+
cost += w;
|
|
164
|
+
}
|
|
165
|
+
return cost;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function edgeWeightMap(program, predicate) {
|
|
169
|
+
const map = new Map();
|
|
170
|
+
let count = 0;
|
|
171
|
+
for (const clause of program.clauses) {
|
|
172
|
+
if (clause.body.length !== 0) continue;
|
|
173
|
+
const h = clause.head;
|
|
174
|
+
if (h.type !== 'compound' || h.name !== predicate || h.arity !== 3) continue;
|
|
175
|
+
const a = atomKey(h.args[0]), b = atomKey(h.args[1]);
|
|
176
|
+
const w = intTerm(h.args[2], null);
|
|
177
|
+
if (a == null || b == null || w == null) continue;
|
|
178
|
+
map.set(`${a}\x1f${b}`, w);
|
|
179
|
+
map.set(`${b}\x1f${a}`, w);
|
|
180
|
+
count++;
|
|
181
|
+
}
|
|
182
|
+
return count ? map : null;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function* hamiltonianCycle({ solver, goal, env }) {
|
|
186
|
+
// hamiltonian_cycle(EdgePred, Vertices, Cycle) treats EdgePred/2 facts as an
|
|
187
|
+
// undirected graph and enumerates cycles starting at Vertices[0].
|
|
188
|
+
const predicate = atomKey(deref(goal.args[0], env));
|
|
189
|
+
const vertices = properListItems(goal.args[1], env);
|
|
190
|
+
if (!predicate || !vertices || vertices.length < 2) return;
|
|
191
|
+
const graph = undirectedGraph(solver.program, predicate);
|
|
192
|
+
if (!graph) return;
|
|
193
|
+
const start = atomKey(vertices[0]);
|
|
194
|
+
if (start == null) return;
|
|
195
|
+
const rest = vertices.slice(1).map(atomKey);
|
|
196
|
+
if (rest.some((v) => v == null)) return;
|
|
197
|
+
const path = [start];
|
|
198
|
+
function* dfs(current, remaining) {
|
|
199
|
+
if (remaining.length === 0) {
|
|
200
|
+
if (!graph.has(`${current}\x1f${start}`)) return;
|
|
201
|
+
const next = env.clone();
|
|
202
|
+
if (unify(goal.args[2], listFromItems([...path, start].map(atom)), next)) yield next;
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
for (let i = 0; i < remaining.length; i++) {
|
|
206
|
+
const v = remaining[i];
|
|
207
|
+
if (!graph.has(`${current}\x1f${v}`)) continue;
|
|
208
|
+
path.push(v);
|
|
209
|
+
yield* dfs(v, remaining.slice(0, i).concat(remaining.slice(i + 1)));
|
|
210
|
+
path.pop();
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
yield* dfs(start, rest);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function undirectedGraph(program, predicate) {
|
|
217
|
+
const edges = new Set();
|
|
218
|
+
let count = 0;
|
|
219
|
+
for (const clause of program.clauses) {
|
|
220
|
+
if (clause.body.length !== 0) continue;
|
|
221
|
+
const h = clause.head;
|
|
222
|
+
if (h.type !== 'compound' || h.name !== predicate || h.arity !== 2) continue;
|
|
223
|
+
const a = atomKey(h.args[0]), b = atomKey(h.args[1]);
|
|
224
|
+
if (a == null || b == null) continue;
|
|
225
|
+
edges.add(`${a}\x1f${b}`);
|
|
226
|
+
edges.add(`${b}\x1f${a}`);
|
|
227
|
+
count++;
|
|
228
|
+
}
|
|
229
|
+
return count ? edges : null;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function* fixedLengthCycle({ solver, goal, env }) {
|
|
233
|
+
// fixed_length_cycle(EdgePred, Length, Relation, Cycle) is useful for RDF-like
|
|
234
|
+
// edge(Source, Relation, Target) data. It enumerates closed walks of exactly
|
|
235
|
+
// Length steps and returns the relation label and node list.
|
|
236
|
+
const predicate = atomKey(deref(goal.args[0], env));
|
|
237
|
+
const length = intTerm(goal.args[1], env);
|
|
238
|
+
if (!predicate || length == null || length < 0) return;
|
|
239
|
+
const graph = labelledGraph(solver.program, predicate);
|
|
240
|
+
if (!graph) return;
|
|
241
|
+
|
|
242
|
+
const requestedRelation = atomKey(deref(goal.args[2], env));
|
|
243
|
+
const requestedCycle = fixedLengthCycleRequestedPath(goal, env, length);
|
|
244
|
+
if (requestedRelation && requestedCycle) {
|
|
245
|
+
const byStart = graph.byRelation.get(requestedRelation);
|
|
246
|
+
if (byStart && fixedLengthCyclePathExists(byStart, requestedCycle)) {
|
|
247
|
+
const next = env.clone();
|
|
248
|
+
if (unify(goal.args[2], atom(requestedRelation), next) && unify(goal.args[3], listFromItems(requestedCycle.map(atom)), next)) yield next;
|
|
249
|
+
}
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
const relations = requestedRelation
|
|
254
|
+
? [[requestedRelation, graph.byRelation.get(requestedRelation)]].filter(([, byStart]) => byStart)
|
|
255
|
+
: graph.byRelation.entries();
|
|
256
|
+
for (const [relation, byStart] of relations) {
|
|
257
|
+
for (const start of byStart.keys()) {
|
|
258
|
+
const path = [atom(start)];
|
|
259
|
+
yield* fixedLengthCycleDfs(goal, env, byStart, relation, start, start, length, path);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function fixedLengthCycleRequestedPath(goal, env, length) {
|
|
265
|
+
const items = properListItems(goal.args[3], env);
|
|
266
|
+
if (!items || items.length !== length + 1) return null;
|
|
267
|
+
const nodes = items.map((item) => atomKey(deref(item, env)));
|
|
268
|
+
if (nodes.some((node) => node == null)) return null;
|
|
269
|
+
if (nodes[0] !== nodes[nodes.length - 1]) return null;
|
|
270
|
+
return nodes;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function fixedLengthCyclePathExists(byStart, nodes) {
|
|
274
|
+
for (let i = 0; i < nodes.length - 1; i++) {
|
|
275
|
+
if (!(byStart.get(nodes[i]) ?? []).includes(nodes[i + 1])) return false;
|
|
276
|
+
}
|
|
277
|
+
return true;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
function* fixedLengthCycleDfs(goal, env, byStart, relation, start, current, remaining, path) {
|
|
281
|
+
if (remaining === 0) {
|
|
282
|
+
if (current !== start) return;
|
|
283
|
+
const next = env.clone();
|
|
284
|
+
if (unify(goal.args[2], atom(relation), next) && unify(goal.args[3], listFromItems(path), next)) yield next;
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
const nexts = byStart.get(current) ?? [];
|
|
288
|
+
for (const dst of nexts) {
|
|
289
|
+
path.push(atom(dst));
|
|
290
|
+
yield* fixedLengthCycleDfs(goal, env, byStart, relation, start, dst, remaining - 1, path);
|
|
291
|
+
path.pop();
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
function labelledGraph(program, predicate) {
|
|
296
|
+
let count = 0;
|
|
297
|
+
const byRelation = new Map();
|
|
298
|
+
for (const clause of program.clauses) {
|
|
299
|
+
if (clause.body.length !== 0) continue;
|
|
300
|
+
const h = clause.head;
|
|
301
|
+
if (h.type !== 'compound' || h.name !== predicate || h.arity !== 3) continue;
|
|
302
|
+
const src = atomKey(h.args[0]), rel = atomKey(h.args[1]), dst = atomKey(h.args[2]);
|
|
303
|
+
if (src == null || rel == null || dst == null) continue;
|
|
304
|
+
let byStart = byRelation.get(rel);
|
|
305
|
+
if (!byStart) byRelation.set(rel, byStart = new Map());
|
|
306
|
+
let arr = byStart.get(src);
|
|
307
|
+
if (!arr) byStart.set(src, arr = []);
|
|
308
|
+
arr.push(dst); count++;
|
|
309
|
+
}
|
|
310
|
+
return count ? { byRelation } : null;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
function* boundedPath({ solver, goal, env }) {
|
|
315
|
+
// bounded_path(EdgePred, Source, Target, MaxEdges, Path) enumerates simple
|
|
316
|
+
// directed paths with at most MaxEdges edges. EdgePred is read from EdgePred/2
|
|
317
|
+
// facts in source order so declarative examples retain stable answer order.
|
|
318
|
+
const predicate = atomKey(deref(goal.args[0], env));
|
|
319
|
+
const source = atomKey(deref(goal.args[1], env));
|
|
320
|
+
const target = atomKey(deref(goal.args[2], env));
|
|
321
|
+
const maxEdges = intTerm(goal.args[3], env);
|
|
322
|
+
if (!predicate || source == null || target == null || maxEdges == null || maxEdges < 0) return;
|
|
323
|
+
const graph = directedAdjacency(solver.program, predicate);
|
|
324
|
+
if (!graph) return;
|
|
325
|
+
const path = [source];
|
|
326
|
+
const visited = new Set([source]);
|
|
327
|
+
function* dfs(current, remaining) {
|
|
328
|
+
if (current === target) {
|
|
329
|
+
const next = env.clone();
|
|
330
|
+
if (unify(goal.args[4], listFromItems(path.map(atom)), next)) yield next;
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
if (remaining <= 0) return;
|
|
334
|
+
for (const dst of graph.get(current) ?? []) {
|
|
335
|
+
if (visited.has(dst)) continue;
|
|
336
|
+
visited.add(dst);
|
|
337
|
+
path.push(dst);
|
|
338
|
+
yield* dfs(dst, remaining - 1);
|
|
339
|
+
path.pop();
|
|
340
|
+
visited.delete(dst);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
yield* dfs(source, maxEdges);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
function directedAdjacency(program, predicate) {
|
|
347
|
+
const map = new Map();
|
|
348
|
+
let count = 0;
|
|
349
|
+
for (const clause of program.clauses) {
|
|
350
|
+
if (clause.body.length !== 0) continue;
|
|
351
|
+
const h = clause.head;
|
|
352
|
+
if (h.type !== 'compound' || h.name !== predicate || h.arity !== 2) continue;
|
|
353
|
+
const a = atomKey(h.args[0]), b = atomKey(h.args[1]);
|
|
354
|
+
if (a == null || b == null) continue;
|
|
355
|
+
let arr = map.get(a);
|
|
356
|
+
if (!arr) map.set(a, arr = []);
|
|
357
|
+
arr.push(b);
|
|
358
|
+
count++;
|
|
359
|
+
}
|
|
360
|
+
return count ? map : null;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
function* cnfModel({ goal, env }) {
|
|
364
|
+
// cnf_model(Variables, Clauses, Assignment) enumerates finite truth
|
|
365
|
+
// assignments in false-before-true order. It deliberately preserves the
|
|
366
|
+
// proof multiplicity of the declarative clause_true/2 + cnf_true/2 program:
|
|
367
|
+
// a clause with two true literals has two derivations.
|
|
368
|
+
const variables = atomList(goal.args[0], env);
|
|
369
|
+
const clauses = clauseList(goal.args[1], env);
|
|
370
|
+
if (!variables || !clauses) return;
|
|
371
|
+
for (const assignment of enumerateAssignments(variables)) {
|
|
372
|
+
const derivations = cnfDerivationCount(clauses, assignment);
|
|
373
|
+
if (derivations === 0) continue;
|
|
374
|
+
const terms = variables.map((v) => compound('value', [atom(v), atom(assignment.get(v) ? 'true' : 'false')]));
|
|
375
|
+
for (let i = 0; i < derivations; i++) {
|
|
376
|
+
const next = env.clone();
|
|
377
|
+
if (unify(goal.args[2], listFromItems(terms), next)) yield next;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
function* enumerateAssignments(vars, index = 0, assignment = new Map()) {
|
|
383
|
+
if (index >= vars.length) { yield new Map(assignment); return; }
|
|
384
|
+
const v = vars[index];
|
|
385
|
+
assignment.set(v, false); yield* enumerateAssignments(vars, index + 1, assignment);
|
|
386
|
+
assignment.set(v, true); yield* enumerateAssignments(vars, index + 1, assignment);
|
|
387
|
+
assignment.delete(v);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
function cnfDerivationCount(clauses, assignment) {
|
|
391
|
+
let count = 1;
|
|
392
|
+
for (const clause of clauses) {
|
|
393
|
+
let trueLiterals = 0;
|
|
394
|
+
for (const lit of clause) if (assignment.get(lit.var) === lit.positive) trueLiterals++;
|
|
395
|
+
if (trueLiterals === 0) return 0;
|
|
396
|
+
count *= trueLiterals;
|
|
397
|
+
}
|
|
398
|
+
return count;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
function* qmPrimeImplicants({ goal, env }) {
|
|
402
|
+
const data = qmDataFromArgs(goal, env);
|
|
403
|
+
if (!data) return;
|
|
404
|
+
const primes = computePrimeImplicants(data).map(patternTerm);
|
|
405
|
+
const next = env.clone();
|
|
406
|
+
if (unify(goal.args[3], listFromItems(primes), next)) yield next;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
function* qmMinimalCover({ goal, env }) {
|
|
410
|
+
const data = qmDataFromArgs(goal, env);
|
|
411
|
+
if (!data) return;
|
|
412
|
+
const primes = computePrimeImplicants(data);
|
|
413
|
+
const cover = computeMinimalCover(primes, data.minterms);
|
|
414
|
+
if (!cover) return;
|
|
415
|
+
const next = env.clone();
|
|
416
|
+
if (unify(goal.args[3], listFromItems(cover.map(patternTerm)), next)) yield next;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
function qmDataFromArgs(goal, env) {
|
|
420
|
+
const minterms = numberList(goal.args[0], env);
|
|
421
|
+
const dontCares = numberList(goal.args[1], env);
|
|
422
|
+
const bits = bitTable(goal.args[2], env);
|
|
423
|
+
if (!minterms || !dontCares || !bits?.size) return null;
|
|
424
|
+
return { minterms, dontCares, bits };
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
function computePrimeImplicants(data) {
|
|
428
|
+
const initial = [...data.minterms, ...data.dontCares].map((n) => data.bits.get(n)).filter(Boolean);
|
|
429
|
+
const once = [];
|
|
430
|
+
for (const a of initial) for (const b of initial) { const c = combinePatterns(a, b); if (c) once.push(c); }
|
|
431
|
+
const twice = [];
|
|
432
|
+
for (const a of once) for (const b of once) { const c = combinePatterns(a, b); if (c) twice.push(c); }
|
|
433
|
+
const raw = [];
|
|
434
|
+
for (const p of initial) if (!initial.some((q) => combinePatterns(p, q))) raw.push(p);
|
|
435
|
+
for (const p of once) if (!once.some((q) => combinePatterns(p, q))) raw.push(p);
|
|
436
|
+
raw.push(...twice);
|
|
437
|
+
return uniqueSortedPatterns(raw);
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
function combinePatterns(a, b) {
|
|
441
|
+
if (a.length !== b.length) return null;
|
|
442
|
+
let diffs = 0;
|
|
443
|
+
const out = [];
|
|
444
|
+
for (let i = 0; i < a.length; i++) {
|
|
445
|
+
if (a[i] === b[i]) out.push(a[i]);
|
|
446
|
+
else {
|
|
447
|
+
diffs++;
|
|
448
|
+
if (diffs > 1) return null;
|
|
449
|
+
out.push('x');
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
return diffs === 1 ? out : null;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
function uniqueSortedPatterns(patterns) {
|
|
456
|
+
const map = new Map();
|
|
457
|
+
for (const p of patterns) map.set(patternKey(p), p);
|
|
458
|
+
return [...map.values()].sort(comparePattern);
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
function comparePattern(a, b) {
|
|
462
|
+
for (let i = 0; i < a.length; i++) {
|
|
463
|
+
const ra = a[i] === 'x' ? 2 : 1;
|
|
464
|
+
const rb = b[i] === 'x' ? 2 : 1;
|
|
465
|
+
if (ra !== rb) return ra - rb;
|
|
466
|
+
if (a[i] !== b[i]) return a[i] < b[i] ? -1 : 1;
|
|
467
|
+
}
|
|
468
|
+
return 0;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
function computeMinimalCover(primes, minterms) {
|
|
472
|
+
const sortedMinterms = [...new Set(minterms)].sort((a, b) => a - b);
|
|
473
|
+
const candidates = [];
|
|
474
|
+
for (let i = 0; i < primes.length; i++) {
|
|
475
|
+
for (let j = i + 1; j < primes.length; j++) {
|
|
476
|
+
const cover = uniqueSortedPatterns([primes[i], primes[j]]);
|
|
477
|
+
if (sortedMinterms.every((m) => cover.some((p) => patternCoversInt(p, m)))) candidates.push(cover);
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
candidates.sort((a, b) => comparePatternList(a, b));
|
|
481
|
+
return candidates[0] ?? null;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
function patternCoversInt(pattern, n) {
|
|
485
|
+
const bits = n.toString(2).padStart(pattern.length, '0').split('').map(Number);
|
|
486
|
+
return pattern.every((v, i) => v === 'x' || v === bits[i]);
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
function comparePatternList(a, b) {
|
|
490
|
+
const len = Math.min(a.length, b.length);
|
|
491
|
+
for (let i = 0; i < len; i++) { const c = comparePattern(a[i], b[i]); if (c) return c; }
|
|
492
|
+
return a.length - b.length;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
function patternTerm(pattern) {
|
|
496
|
+
return listFromItems(pattern.map((v) => v === 'x' ? atom('x') : numberTerm(v)));
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
function patternKey(pattern) { return pattern.join(''); }
|
|
500
|
+
|
|
501
|
+
function* permutations(items, start = 0) {
|
|
502
|
+
if (start >= items.length) { yield items.slice(); return; }
|
|
503
|
+
for (let i = start; i < items.length; i++) {
|
|
504
|
+
[items[start], items[i]] = [items[i], items[start]];
|
|
505
|
+
yield* permutations(items, start + 1);
|
|
506
|
+
[items[start], items[i]] = [items[i], items[start]];
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
function atomKey(term) {
|
|
511
|
+
if (!term) return null;
|
|
512
|
+
return (term.type === 'atom' || term.type === 'string' || term.type === 'number') ? term.name : null;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
function intTerm(term, env) {
|
|
516
|
+
const t = env ? deref(term, env) : term;
|
|
517
|
+
if (!t || t.type !== 'number' || !/^-?\d+$/.test(t.name)) return null;
|
|
518
|
+
const n = Number(t.name);
|
|
519
|
+
return Number.isSafeInteger(n) ? n : null;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
function numberList(term, env) {
|
|
523
|
+
const items = properListItems(term, env);
|
|
524
|
+
if (!items) return null;
|
|
525
|
+
const out = [];
|
|
526
|
+
for (const item of items) {
|
|
527
|
+
const n = intTerm(item, env);
|
|
528
|
+
if (n == null) return null;
|
|
529
|
+
out.push(n);
|
|
530
|
+
}
|
|
531
|
+
return out;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
function atomList(term, env) {
|
|
535
|
+
const items = properListItems(term, env);
|
|
536
|
+
if (!items) return null;
|
|
537
|
+
const out = [];
|
|
538
|
+
for (const item of items) {
|
|
539
|
+
const v = atomKey(deref(item, env));
|
|
540
|
+
if (v == null) return null;
|
|
541
|
+
out.push(v);
|
|
542
|
+
}
|
|
543
|
+
return out;
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
function bitTable(term, env) {
|
|
547
|
+
const items = properListItems(term, env);
|
|
548
|
+
if (!items) return null;
|
|
549
|
+
const map = new Map();
|
|
550
|
+
for (const item of items) {
|
|
551
|
+
const entry = deref(item, env);
|
|
552
|
+
if (entry.type !== 'compound' || entry.name !== 'bit' || entry.arity !== 2) return null;
|
|
553
|
+
const n = intTerm(entry.args[0], env);
|
|
554
|
+
const bits = numberList(entry.args[1], env);
|
|
555
|
+
if (n == null || !bits) return null;
|
|
556
|
+
map.set(n, bits);
|
|
557
|
+
}
|
|
558
|
+
return map;
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
function clauseList(term, env) {
|
|
562
|
+
const clauses = properListItems(term, env);
|
|
563
|
+
if (!clauses) return null;
|
|
564
|
+
const out = [];
|
|
565
|
+
for (const clause of clauses) {
|
|
566
|
+
const lits = properListItems(clause, env);
|
|
567
|
+
if (!lits) return null;
|
|
568
|
+
const row = [];
|
|
569
|
+
for (const litTerm of lits) {
|
|
570
|
+
const lit = deref(litTerm, env);
|
|
571
|
+
if (lit.type !== 'compound' || lit.arity !== 1 || (lit.name !== 'pos' && lit.name !== 'neg')) return null;
|
|
572
|
+
const v = atomKey(deref(lit.args[0], env));
|
|
573
|
+
if (v == null) return null;
|
|
574
|
+
row.push({ var: v, positive: lit.name === 'pos' });
|
|
575
|
+
}
|
|
576
|
+
out.push(row);
|
|
577
|
+
}
|
|
578
|
+
return out;
|
|
579
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// String and atom conversion builtins.
|
|
2
|
+
// They mostly project from already-ground terms to avoid guessing string domains.
|
|
3
|
+
import { atom, lexicalValue, stringTerm, unify } from '../term.mjs';
|
|
4
|
+
|
|
5
|
+
export const stringBuiltins = {
|
|
6
|
+
register(registry) {
|
|
7
|
+
for (const name of ['atom_concat', 'str_concat']) registry.add(name, 3, concat(name), { deterministic: true });
|
|
8
|
+
for (const name of ['contains', 'not_contains', 'matches', 'not_matches']) registry.add(name, 2, contains(name), { deterministic: true });
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
function concat(name) {
|
|
14
|
+
return function* ({ goal, env }) {
|
|
15
|
+
const left = lexicalValue(goal.args[0], env);
|
|
16
|
+
const right = lexicalValue(goal.args[1], env);
|
|
17
|
+
if (left == null || right == null) return;
|
|
18
|
+
const result = name === 'str_concat' ? stringTerm(left + right) : atom(left + right);
|
|
19
|
+
const next = env.clone();
|
|
20
|
+
if (unify(goal.args[2], result, next)) yield next;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function contains(name) {
|
|
25
|
+
return function* ({ goal, env }) {
|
|
26
|
+
const haystack = lexicalValue(goal.args[0], env);
|
|
27
|
+
const needle = lexicalValue(goal.args[1], env);
|
|
28
|
+
if (haystack == null || needle == null) return;
|
|
29
|
+
const has = haystack.includes(needle);
|
|
30
|
+
const matches = simpleAlternationMatch(haystack, needle);
|
|
31
|
+
const pass = (name === 'contains' && has) ||
|
|
32
|
+
(name === 'not_contains' && !has) ||
|
|
33
|
+
(name === 'matches' && matches) ||
|
|
34
|
+
(name === 'not_matches' && !matches);
|
|
35
|
+
if (pass) yield env;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function simpleAlternationMatch(haystack, pattern) {
|
|
40
|
+
return pattern.split('|').some((part) => part === '' || haystack.includes(part));
|
|
41
|
+
}
|