eyelang 1.1.16 → 1.1.18

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.
Files changed (120) hide show
  1. package/docs/guide.md +13 -4
  2. package/docs/language-reference.md +1 -1
  3. package/examples/ackermann.pl +6 -5
  4. package/examples/age.pl +4 -6
  5. package/examples/aliases-and-namespaces.pl +7 -9
  6. package/examples/ancestor.pl +5 -4
  7. package/examples/backward.pl +6 -7
  8. package/examples/bayes-therapy.pl +7 -0
  9. package/examples/beam-deflection.pl +3 -5
  10. package/examples/binomial-vandermonde.pl +49 -0
  11. package/examples/blocks-world-planning.pl +4 -2
  12. package/examples/buck-converter-design.pl +5 -0
  13. package/examples/cache-performance.pl +4 -2
  14. package/examples/canary-release.pl +4 -2
  15. package/examples/catalan-convolution.pl +37 -0
  16. package/examples/chart-parser.pl +8 -2
  17. package/examples/clinical-trial-screening.pl +5 -0
  18. package/examples/combinatorics-findall-sort.pl +7 -6
  19. package/examples/complex.pl +5 -0
  20. package/examples/continued-fraction-sqrt2.pl +36 -0
  21. package/examples/control-system.pl +4 -0
  22. package/examples/critical-path-schedule.pl +7 -2
  23. package/examples/cyclic-path.pl +8 -6
  24. package/examples/d3-group.pl +3 -4
  25. package/examples/dairy-energy-balance.pl +7 -6
  26. package/examples/data-negotiation.pl +3 -4
  27. package/examples/deontic-logic.pl +3 -3
  28. package/examples/dijkstra-findall-sort.pl +3 -4
  29. package/examples/dijkstra-risk-path.pl +9 -8
  30. package/examples/dijkstra.pl +11 -7
  31. package/examples/dining-philosophers.pl +11 -4
  32. package/examples/dog.pl +7 -7
  33. package/examples/dpv-odrl-purpose-mapping.pl +3 -1
  34. package/examples/drone-corridor-planner.pl +5 -8
  35. package/examples/easter-computus.pl +4 -5
  36. package/examples/electrical-rc-filter.pl +5 -4
  37. package/examples/epidemic-policy.pl +3 -4
  38. package/examples/equivalence-classes-overlap-implies-same-class.pl +8 -8
  39. package/examples/eulerian-path.pl +8 -6
  40. package/examples/ev-range-worlds.pl +10 -5
  41. package/examples/existential-rule.pl +9 -6
  42. package/examples/exoplanet-validation-worlds.pl +8 -2
  43. package/examples/expression-eval.pl +8 -6
  44. package/examples/family-cousins.pl +4 -2
  45. package/examples/fastpow.pl +14 -6
  46. package/examples/fft8-numeric.pl +9 -7
  47. package/examples/fibonacci.pl +12 -5
  48. package/examples/field-nitrogen-balance.pl +9 -6
  49. package/examples/floating-point.pl +11 -6
  50. package/examples/four-color-map.pl +6 -0
  51. package/examples/fundamental-theorem-arithmetic.pl +6 -0
  52. package/examples/gd-step-certified.pl +4 -0
  53. package/examples/gdpr-compliance.pl +4 -4
  54. package/examples/good-cobbler.pl +4 -2
  55. package/examples/gps.pl +5 -11
  56. package/examples/graph-reachability.pl +3 -6
  57. package/examples/gray-code-counter.pl +4 -5
  58. package/examples/greatest-lower-bound-uniqueness.pl +9 -7
  59. package/examples/group-inverse-uniqueness.pl +4 -2
  60. package/examples/hamiltonian-path.pl +4 -2
  61. package/examples/hamming-code.pl +4 -0
  62. package/examples/hanoi.pl +3 -4
  63. package/examples/heat-loss.pl +10 -5
  64. package/examples/heron-theorem.pl +11 -5
  65. package/examples/ideal-gas-law.pl +4 -2
  66. package/examples/integer-partitions.pl +35 -0
  67. package/examples/intuitionistic-logic-kripke.pl +69 -0
  68. package/examples/job-shop-scheduling.pl +6 -2
  69. package/examples/knapsack-optimization.pl +7 -1
  70. package/examples/knowledge-engineering-alignment-flow.pl +9 -3
  71. package/examples/law-of-cosines.pl +12 -6
  72. package/examples/least-squares-regression.pl +4 -0
  73. package/examples/linear-logic-resources.pl +51 -0
  74. package/examples/list-collection.pl +4 -2
  75. package/examples/lldm.pl +4 -2
  76. package/examples/matrix-chain-order.pl +79 -0
  77. package/examples/microgrid-dispatch.pl +4 -0
  78. package/examples/missionaries-cannibals.pl +7 -1
  79. package/examples/modal-logic-kripke.pl +45 -0
  80. package/examples/modular-exponentiation.pl +35 -0
  81. package/examples/n-queens-8.pl +7 -3
  82. package/examples/newton-raphson.pl +3 -4
  83. package/examples/observability-log-correlation.pl +9 -3
  84. package/examples/odrl-dpv-fpv-trust-flow.pl +9 -1
  85. package/examples/odrl-dpv-healthcare-risk-ranked.pl +8 -4
  86. package/examples/orbital-transfer-design.pl +3 -0
  87. package/examples/output/binomial-vandermonde.pl +4 -0
  88. package/examples/output/catalan-convolution.pl +4 -0
  89. package/examples/output/continued-fraction-sqrt2.pl +4 -0
  90. package/examples/output/integer-partitions.pl +4 -0
  91. package/examples/output/intuitionistic-logic-kripke.pl +5 -0
  92. package/examples/output/linear-logic-resources.pl +2 -0
  93. package/examples/output/matrix-chain-order.pl +4 -0
  94. package/examples/output/modal-logic-kripke.pl +4 -0
  95. package/examples/output/modular-exponentiation.pl +4 -0
  96. package/examples/output/pell-equation.pl +4 -0
  97. package/examples/output/stirling-bell-numbers.pl +4 -0
  98. package/examples/output/totient-summatory.pl +4 -0
  99. package/examples/peano-arithmetic.pl +4 -2
  100. package/examples/peasant.pl +4 -5
  101. package/examples/pell-equation.pl +34 -0
  102. package/examples/quadratic-formula.pl +4 -2
  103. package/examples/radioactive-decay.pl +6 -4
  104. package/examples/reusable-builtins.pl +5 -1
  105. package/examples/send-more-money.pl +6 -1
  106. package/examples/stable-marriage.pl +7 -1
  107. package/examples/statistics-summary.pl +4 -2
  108. package/examples/stirling-bell-numbers.pl +32 -0
  109. package/examples/sudoku-4x4.pl +7 -1
  110. package/examples/term-tools.pl +10 -1
  111. package/examples/totient-summatory.pl +33 -0
  112. package/examples/trust-flow-provenance-threshold.pl +8 -1
  113. package/examples/turing.pl +5 -3
  114. package/examples/vector-similarity.pl +7 -3
  115. package/examples/vulnerability-impact.pl +4 -5
  116. package/examples/weighted-interval-scheduling.pl +6 -1
  117. package/examples/zebra.pl +5 -4
  118. package/package.json +1 -1
  119. package/playground.html +12 -0
  120. package/test/run-regression.mjs +10 -0
package/docs/guide.md CHANGED
@@ -197,7 +197,7 @@ The default output is then:
197
197
  answer(case1, accepted).
198
198
  ```
199
199
 
200
- `materialize/2` is a declaration, not a logical rule to prove. It affects which predicates the CLI prints, not the meaning of the rules themselves.
200
+ `materialize/2` is a declaration, not a logical rule to prove. It affects which predicates the CLI prints, not the meaning of the rules themselves. Materialized output facts are not inserted back into the running program for later goals; if later output predicates reuse the same derived helper relation, eyelang proves it again unless that helper is declared with `memoize/2`. Source facts are indexed and reused normally, and memoized solved goals are reused inside the same solver run.
201
201
 
202
202
  ## Writing programs
203
203
 
@@ -321,6 +321,7 @@ Each example has a checked golden output in `examples/output`.
321
321
  | [`bayes-diagnosis.pl`](../examples/bayes-diagnosis.pl) | Computes scaled Bayesian diagnosis posteriors. | [`output/bayes-diagnosis.pl`](../examples/output/bayes-diagnosis.pl) |
322
322
  | [`bayes-therapy.pl`](../examples/bayes-therapy.pl) | Ranks therapies using Bayesian disease likelihoods. | [`output/bayes-therapy.pl`](../examples/output/bayes-therapy.pl) |
323
323
  | [`beam-deflection.pl`](../examples/beam-deflection.pl) | Computes cantilever beam deflection. | [`output/beam-deflection.pl`](../examples/output/beam-deflection.pl) |
324
+ | [`binomial-vandermonde.pl`](../examples/binomial-vandermonde.pl) | Computes binomial coefficients and checks Vandermonde's identity. | [`output/binomial-vandermonde.pl`](../examples/output/binomial-vandermonde.pl) |
324
325
  | [`blocks-world-planning.pl`](../examples/blocks-world-planning.pl) | Searches a finite blocks-world plan. | [`output/blocks-world-planning.pl`](../examples/output/blocks-world-planning.pl) |
325
326
  | [`bmi.pl`](../examples/bmi.pl) | Normalizes BMI inputs and classifies weight. | [`output/bmi.pl`](../examples/output/bmi.pl) |
326
327
  | [`braking-safety-worlds.pl`](../examples/braking-safety-worlds.pl) | Classifies braking safety under alternative worlds. | [`output/braking-safety-worlds.pl`](../examples/output/braking-safety-worlds.pl) |
@@ -328,6 +329,7 @@ Each example has a checked golden output in `examples/output`.
328
329
  | [`cache-performance.pl`](../examples/cache-performance.pl) | Summarizes cache latency performance. | [`output/cache-performance.pl`](../examples/output/cache-performance.pl) |
329
330
  | [`canary-release.pl`](../examples/canary-release.pl) | Decides canary rollout or rollback. | [`output/canary-release.pl`](../examples/output/canary-release.pl) |
330
331
  | [`cat-koko.pl`](../examples/cat-koko.pl) | Demonstrates named existential witnesses from a Cat Koko rule pattern. | [`output/cat-koko.pl`](../examples/output/cat-koko.pl) |
332
+ | [`catalan-convolution.pl`](../examples/catalan-convolution.pl) | Computes Catalan numbers by memoized convolution. | [`output/catalan-convolution.pl`](../examples/output/catalan-convolution.pl) |
331
333
  | [`chart-parser.pl`](../examples/chart-parser.pl) | Parses small sentences with a memoized chart parser. | [`output/chart-parser.pl`](../examples/output/chart-parser.pl) |
332
334
  | [`clinical-trial-screening.pl`](../examples/clinical-trial-screening.pl) | Screens candidates for a trial. | [`output/clinical-trial-screening.pl`](../examples/output/clinical-trial-screening.pl) |
333
335
  | [`collatz-1000.pl`](../examples/collatz-1000.pl) | Materializes Collatz trajectories for starts 1000 down to 1. | [`output/collatz-1000.pl`](../examples/output/collatz-1000.pl) |
@@ -337,6 +339,7 @@ Each example has a checked golden output in `examples/output`.
337
339
  | [`composition-of-injective-functions-is-injective.pl`](../examples/composition-of-injective-functions-is-injective.pl) | Encodes composition and injectivity of finite functions. | [`output/composition-of-injective-functions-is-injective.pl`](../examples/output/composition-of-injective-functions-is-injective.pl) |
338
340
  | [`context-association.pl`](../examples/context-association.pl) | Associates named contexts with their contents. | [`output/context-association.pl`](../examples/output/context-association.pl) |
339
341
  | [`context-schema-audit.pl`](../examples/context-schema-audit.pl) | Audits mixed-arity context members with `holds/3`. | [`output/context-schema-audit.pl`](../examples/output/context-schema-audit.pl) |
342
+ | [`continued-fraction-sqrt2.pl`](../examples/continued-fraction-sqrt2.pl) | Computes sqrt(2) continued-fraction convergents and Pell errors. | [`output/continued-fraction-sqrt2.pl`](../examples/output/continued-fraction-sqrt2.pl) |
340
343
  | [`control-system.pl`](../examples/control-system.pl) | Evaluates control-system measurements and targets. | [`output/control-system.pl`](../examples/output/control-system.pl) |
341
344
  | [`critical-path-schedule.pl`](../examples/critical-path-schedule.pl) | Computes earliest starts and the critical path for a project network. | [`output/critical-path-schedule.pl`](../examples/output/critical-path-schedule.pl) |
342
345
  | [`cyclic-path.pl`](../examples/cyclic-path.pl) | Computes paths in a cyclic graph. | [`output/cyclic-path.pl`](../examples/output/cyclic-path.pl) |
@@ -393,16 +396,22 @@ Each example has a checked golden output in `examples/output`.
393
396
  | [`heron-theorem.pl`](../examples/heron-theorem.pl) | Computes triangle area by Heron's theorem. | [`output/heron-theorem.pl`](../examples/output/heron-theorem.pl) |
394
397
  | [`ideal-gas-law.pl`](../examples/ideal-gas-law.pl) | Applies the ideal gas law. | [`output/ideal-gas-law.pl`](../examples/output/ideal-gas-law.pl) |
395
398
  | [`illegitimate-reasoning.pl`](../examples/illegitimate-reasoning.pl) | Detects suspect reasoning patterns. | [`output/illegitimate-reasoning.pl`](../examples/output/illegitimate-reasoning.pl) |
399
+ | [`integer-partitions.pl`](../examples/integer-partitions.pl) | Counts integer partitions with memoized dynamic programming. | [`output/integer-partitions.pl`](../examples/output/integer-partitions.pl) |
400
+ | [`intuitionistic-logic-kripke.pl`](../examples/intuitionistic-logic-kripke.pl) | Emulates intuitionistic Kripke forcing and constructive implication. | [`output/intuitionistic-logic-kripke.pl`](../examples/output/intuitionistic-logic-kripke.pl) |
396
401
  | [`job-shop-scheduling.pl`](../examples/job-shop-scheduling.pl) | Searches a small job-shop schedule and minimizes makespan. | [`output/job-shop-scheduling.pl`](../examples/output/job-shop-scheduling.pl) |
397
402
  | [`knapsack-optimization.pl`](../examples/knapsack-optimization.pl) | Optimizes a finite 0/1 knapsack pack with aggregation. | [`output/knapsack-optimization.pl`](../examples/output/knapsack-optimization.pl) |
398
403
  | [`knowledge-engineering-alignment-flow.pl`](../examples/knowledge-engineering-alignment-flow.pl) | Specializes reusable alignment rules into a target-shaped flow view. | [`output/knowledge-engineering-alignment-flow.pl`](../examples/output/knowledge-engineering-alignment-flow.pl) |
399
404
  | [`law-of-cosines.pl`](../examples/law-of-cosines.pl) | Computes a triangle side by cosine law. | [`output/law-of-cosines.pl`](../examples/output/law-of-cosines.pl) |
400
405
  | [`least-squares-regression.pl`](../examples/least-squares-regression.pl) | Fits a least-squares regression line. | [`output/least-squares-regression.pl`](../examples/output/least-squares-regression.pl) |
406
+ | [`linear-logic-resources.pl`](../examples/linear-logic-resources.pl) | Emulates linear logic resource consumption with explicit state threading. | [`output/linear-logic-resources.pl`](../examples/output/linear-logic-resources.pl) |
401
407
  | [`list-collection.pl`](../examples/list-collection.pl) | Demonstrates list and collection built-ins. | [`output/list-collection.pl`](../examples/output/list-collection.pl) |
402
408
  | [`lldm.pl`](../examples/lldm.pl) | Calculates leg-length discrepancy measurements. | [`output/lldm.pl`](../examples/output/lldm.pl) |
403
409
  | [`manufacturing-quality-control.pl`](../examples/manufacturing-quality-control.pl) | Evaluates process capability and quality. | [`output/manufacturing-quality-control.pl`](../examples/output/manufacturing-quality-control.pl) |
410
+ | [`matrix-chain-order.pl`](../examples/matrix-chain-order.pl) | Finds an optimal matrix-chain multiplication order. | [`output/matrix-chain-order.pl`](../examples/output/matrix-chain-order.pl) |
404
411
  | [`microgrid-dispatch.pl`](../examples/microgrid-dispatch.pl) | Plans microgrid dispatch and reserve. | [`output/microgrid-dispatch.pl`](../examples/output/microgrid-dispatch.pl) |
405
412
  | [`missionaries-cannibals.pl`](../examples/missionaries-cannibals.pl) | Solves the missionaries-and-cannibals river crossing puzzle. | [`output/missionaries-cannibals.pl`](../examples/output/missionaries-cannibals.pl) |
413
+ | [`modal-logic-kripke.pl`](../examples/modal-logic-kripke.pl) | Emulates modal box and diamond operators over a finite Kripke frame. | [`output/modal-logic-kripke.pl`](../examples/output/modal-logic-kripke.pl) |
414
+ | [`modular-exponentiation.pl`](../examples/modular-exponentiation.pl) | Computes modular powers by repeated squaring. | [`output/modular-exponentiation.pl`](../examples/output/modular-exponentiation.pl) |
406
415
  | [`monkey-bananas.pl`](../examples/monkey-bananas.pl) | Solves the monkey-and-bananas puzzle. | [`output/monkey-bananas.pl`](../examples/output/monkey-bananas.pl) |
407
416
  | [`n-queens-8.pl`](../examples/n-queens-8.pl) | Solves the 8-queens search problem with diagonal constraints. | [`output/n-queens-8.pl`](../examples/output/n-queens-8.pl) |
408
417
  | [`network-sla.pl`](../examples/network-sla.pl) | Checks network path SLA compliance. | [`output/network-sla.pl`](../examples/output/network-sla.pl) |
@@ -416,6 +425,7 @@ Each example has a checked golden output in `examples/output`.
416
425
  | [`path-discovery.pl`](../examples/path-discovery.pl) | Discovers bounded air-route paths. | [`output/path-discovery.pl`](../examples/output/path-discovery.pl) |
417
426
  | [`peano-arithmetic.pl`](../examples/peano-arithmetic.pl) | Computes Peano addition, multiplication, and factorial. | [`output/peano-arithmetic.pl`](../examples/output/peano-arithmetic.pl) |
418
427
  | [`peasant.pl`](../examples/peasant.pl) | Performs peasant multiplication and exponentiation. | [`output/peasant.pl`](../examples/output/peasant.pl) |
428
+ | [`pell-equation.pl`](../examples/pell-equation.pl) | Generates Pell-equation solutions by recurrence. | [`output/pell-equation.pl`](../examples/output/pell-equation.pl) |
419
429
  | [`pendulum-period.pl`](../examples/pendulum-period.pl) | Computes simple pendulum periods. | [`output/pendulum-period.pl`](../examples/output/pendulum-period.pl) |
420
430
  | [`polynomial.pl`](../examples/polynomial.pl) | Finds complex integer polynomial roots. | [`output/polynomial.pl`](../examples/output/polynomial.pl) |
421
431
  | [`proof-contrapositive.pl`](../examples/proof-contrapositive.pl) | Models proof by contrapositive. | [`output/proof-contrapositive.pl`](../examples/output/proof-contrapositive.pl) |
@@ -433,9 +443,11 @@ Each example has a checked golden output in `examples/output`.
433
443
  | [`socrates.pl`](../examples/socrates.pl) | Derives that Socrates is mortal. | [`output/socrates.pl`](../examples/output/socrates.pl) |
434
444
  | [`stable-marriage.pl`](../examples/stable-marriage.pl) | Finds stable matchings by excluding blocking pairs. | [`output/stable-marriage.pl`](../examples/output/stable-marriage.pl) |
435
445
  | [`statistics-summary.pl`](../examples/statistics-summary.pl) | Computes population statistics for a sample. | [`output/statistics-summary.pl`](../examples/output/statistics-summary.pl) |
446
+ | [`stirling-bell-numbers.pl`](../examples/stirling-bell-numbers.pl) | Computes Stirling numbers and Bell numbers. | [`output/stirling-bell-numbers.pl`](../examples/output/stirling-bell-numbers.pl) |
436
447
  | [`sudoku-4x4.pl`](../examples/sudoku-4x4.pl) | Solves a compact 4x4 Sudoku by finite constraint search. | [`output/sudoku-4x4.pl`](../examples/output/sudoku-4x4.pl) |
437
448
  | [`superdense-coding.pl`](../examples/superdense-coding.pl) | Models superdense-coding bit transmission. | [`output/superdense-coding.pl`](../examples/output/superdense-coding.pl) |
438
449
  | [`term-tools.pl`](../examples/term-tools.pl) | Inspects, builds, renders, and validates terms with reusable term/control builtins. | [`output/term-tools.pl`](../examples/output/term-tools.pl) |
450
+ | [`totient-summatory.pl`](../examples/totient-summatory.pl) | Computes Euler totients and their summatory function. | [`output/totient-summatory.pl`](../examples/output/totient-summatory.pl) |
439
451
  | [`trust-flow-provenance-threshold.pl`](../examples/trust-flow-provenance-threshold.pl) | Classifies message trust from provenance confidence scores. | [`output/trust-flow-provenance-threshold.pl`](../examples/output/trust-flow-provenance-threshold.pl) |
440
452
  | [`turing.pl`](../examples/turing.pl) | Simulates a binary-increment Turing machine. | [`output/turing.pl`](../examples/output/turing.pl) |
441
453
  | [`vector-similarity.pl`](../examples/vector-similarity.pl) | Computes dot product, norm, and cosine similarity. | [`output/vector-similarity.pl`](../examples/output/vector-similarity.pl) |
@@ -444,9 +456,6 @@ Each example has a checked golden output in `examples/output`.
444
456
  | [`witch.pl`](../examples/witch.pl) | Derives the classic “burn the witch” rule chain. | [`output/witch.pl`](../examples/output/witch.pl) |
445
457
  | [`wolf-goat-cabbage.pl`](../examples/wolf-goat-cabbage.pl) | Solves the wolf-goat-cabbage river crossing. | [`output/wolf-goat-cabbage.pl`](../examples/output/wolf-goat-cabbage.pl) |
446
458
  | [`zebra.pl`](../examples/zebra.pl) | Solves the zebra logic puzzle. | [`output/zebra.pl`](../examples/output/zebra.pl) |
447
-
448
-
449
-
450
459
  ## Golden outputs, tests, and conformance
451
460
 
452
461
  Golden answer outputs live in [`examples/output`](../examples/output). `npm run test:eyelang` covers the eyelang integration check, conformance cases, regression checks, runnable examples, and proof-output examples. A curated proof-output suite for `.pl` examples lives in [`examples/proof`](../examples/proof). Example tests pin `local_time/1` to `2026-05-30` so date-dependent examples stay deterministic. Regenerate them after an intentional output or explanation change:
@@ -534,7 +534,7 @@ materialize(status, 2).
534
534
  materialize(reason, 2).
535
535
  ```
536
536
 
537
- `materialize/2` affects host output selection only; it does not change the logical meaning of the program.
537
+ `materialize/2` affects host output selection only; it does not change the logical meaning of the program. Materialized output facts are not asserted as new source facts for subsequent output goals. A host MAY solve several materialized predicates in one solver run, and memoized predicate answers MAY be reused within that run, but this reuse is controlled by `memoize/2`, not by materialization.
538
538
 
539
539
  ## 12. Eyelang Sockets
540
540
 
@@ -1,12 +1,13 @@
1
1
  % Ackermann-style hyperoperation benchmark adapted from Eyeling ackermann.n3.
2
- % The two-argument entry point follows the Eyeling encoding:
3
- % ackermann(X, Y) = hyper(X, Y + 3, 2) - 3.
2
+ % The public ackermann/2 answers are small, but the helper relation exercises
3
+ % deeply nested arithmetic recursion: hyper/4 encodes successor, addition,
4
+ % multiplication, exponentiation, and then the Ackermann-style offset
5
+ % ackermann(X, Y) = hyper(X, Y + 3, 2) - 3.
6
+ % Keeping the selected inputs explicit avoids unbounded generation while still
7
+ % testing the solver's recursive numeric workload.
4
8
 
5
- % Output declarations: materialize/2 selects the relations written to this example's golden output.
6
9
  materialize(ackermann, 2).
7
10
 
8
- % Program structure: facts set up the scenario, and rules derive the materialized conclusions.
9
- % Derivation rules: each rule below contributes one logical step toward the displayed results.
10
11
  ackermann(X, Y, A) :-
11
12
  add(Y, 3, B),
12
13
  hyper(X, B, 2, C),
package/examples/age.pl CHANGED
@@ -1,21 +1,19 @@
1
1
  % Age checker adapted from Eyeling.
2
- %
3
- % Is the age of a person above some duration?
2
+ % The example combines date literals, ISO-8601 duration values, local_time/1,
3
+ % difference/3, and duration comparison. It deliberately uses the current
4
+ % local date so the derived ageAbove/2 fact remains an executable temporal
5
+ % check rather than a precomputed constant.
4
6
 
5
- % Person data.
6
- % Output declarations: materialize/2 selects the relations written to this example's golden output.
7
7
  materialize(birthDay, 2).
8
8
  materialize(duration, 2).
9
9
  materialize(ageAbove, 2).
10
10
  materialize(is, 2).
11
11
 
12
- % Program structure: facts set up the scenario, and rules derive the materialized conclusions.
13
12
  birthDay(patH, "1944-08-21").
14
13
  duration(check, "P80Y").
15
14
 
16
15
  % A person is above a duration if the local date minus the birthday is greater
17
16
  % than that duration.
18
- % Derivation rules: each rule below contributes one logical step toward the displayed results.
19
17
  ageAbove(S, A) :-
20
18
  birthDay(S, B),
21
19
  duration(check, A),
@@ -1,17 +1,15 @@
1
- % Built-ins use one native spelling each.
2
- % Vocabulary predicate names remain ordinary user predicates.
3
-
4
- % The materialized relations below show that built-ins can coexist with
5
- % ordinary vocabulary predicates that happen to look namespace-like.
6
- % Output declarations: materialize/2 selects the relations written to this example's golden output.
1
+ % Built-ins use one native spelling each, while vocabulary-style predicate names
2
+ % remain ordinary user predicates.
3
+ %
4
+ % This keeps the language small: add/3, lt/2, matches/3, and rest/2 are native
5
+ % operations, but labels such as nativeMath or vocabularyExample are just data.
7
6
  materialize(value, 2).
8
7
  materialize(ok, 2).
9
8
  materialize(tail, 2).
10
9
  materialize(label, 2).
11
10
 
12
- % Program structure: facts set up the scenario, and rules derive the materialized conclusions.
13
- % Native operations are called through their canonical predicate names.
14
- % Derivation rules: each rule below contributes one logical step toward the displayed results.
11
+ % The first four rules call native built-ins; the last two rules show that
12
+ % application vocabulary is modeled with ordinary facts and rules.
15
13
  value(nativeMath, X) :- add(0.125, 0.875, X).
16
14
  ok(nativeCompare, true) :- lt(2, 3).
17
15
  ok(nativeString, true) :- matches("scoped retail insight", "retail|medical").
@@ -1,17 +1,18 @@
1
1
  % Basic recursive relation example.
2
- % Both input facts and derived recursive answers are printed.
3
- % Output declarations: materialize/2 selects the relations written to this example's golden output.
2
+ % parent/2 facts form a small family chain. ancestor/2 has the classic two-rule
3
+ % shape: one base rule copies direct parents, and one recursive rule walks one
4
+ % parent edge before continuing through the chain. Both source and derived
5
+ % relations are materialized so the output shows the closure explicitly.
6
+
4
7
  materialize(parent, 2).
5
8
  materialize(ancestor, 2).
6
9
 
7
- % Program structure: facts set up the scenario, and rules derive the materialized conclusions.
8
10
  % Direct parent facts form a simple chain.
9
11
  parent(pat, jan).
10
12
  parent(jan, lies).
11
13
  parent(lies, emma).
12
14
 
13
15
  % Base case: every parent is also an ancestor.
14
- % Derivation rules: each rule below contributes one logical step toward the displayed results.
15
16
  ancestor(X, Y) :-
16
17
  parent(X, Y).
17
18
 
@@ -1,12 +1,11 @@
1
- % Output declarations: materialize/2 selects the relations written to this example's golden output.
2
- materialize(isIndeedMoreInterestingThan, 2).
1
+ % Backward-rule example adapted from Eyeling backward.n3.
2
+ % Eyeling writes the interestingness rule in a backward style; eyelang records
3
+ % the same dependency as an ordinary Horn rule. The example is intentionally
4
+ % tiny: it demonstrates that a derived fact can be justified by a numeric
5
+ % comparison in the rule body.
3
6
 
4
- % Program structure: facts set up the scenario, and rules derive the materialized conclusions.
5
- % Backward rule example adapted from Eyeling backward.n3.
6
- % Eyeling writes the interestingness rule backward; eyelang records the same
7
- % relation as an ordinary rule whose body is the numeric comparison.
7
+ materialize(isIndeedMoreInterestingThan, 2).
8
8
 
9
- % Derivation rules: each rule below contributes one logical step toward the displayed results.
10
9
  moreInterestingThan(X, Y) :- gt(X, Y).
11
10
 
12
11
  isIndeedMoreInterestingThan(5, 3) :- moreInterestingThan(5, 3).
@@ -1,6 +1,11 @@
1
1
  % Memoize shared inference layers: the score vector, disease likelihood tails,
2
2
  % and expected therapy success are reused by several report relations.
3
3
  % Output declarations: materialize/2 selects the relations written to this example's golden output.
4
+ %
5
+ % Read this as two stacked inference problems: first infer disease posterior
6
+ % probabilities from symptoms, then score each therapy by averaging outcomes
7
+ % over that posterior distribution. The memoized predicates are exactly the
8
+ % shared layers used by several materialized reports.
4
9
  materialize(diseases, 2).
5
10
  materialize(therapies, 2).
6
11
  materialize(evidence, 2).
@@ -95,6 +100,7 @@ likelihood(Disease, [Evidence|Rest], Likelihood) :-
95
100
  likelihood(Disease, Rest, TailLikelihood),
96
101
  mul(Factor, TailLikelihood, Likelihood).
97
102
 
103
+ % score/2 combines prior probability with the likelihood of the observed evidence.
98
104
  score(Disease, Score) :-
99
105
  prior(Disease, Prior),
100
106
  evidence(case, Evidence),
@@ -131,6 +137,7 @@ expected_success(Therapy, ExpectedSuccess) :-
131
137
  success_by_disease(Therapy, SuccessByDisease),
132
138
  dot_product(Posteriors, SuccessByDisease, ExpectedSuccess).
133
139
 
140
+ % utility/2 turns expected success and adverse effects into a ranking score.
134
141
  utility(Therapy, Utility) :-
135
142
  expected_success(Therapy, ExpectedSuccess),
136
143
  adverse(Therapy, Adverse),
@@ -1,22 +1,20 @@
1
1
  % Engineering example: cantilever beam tip deflection.
2
- %
3
- % The tip deflection for a point load at the free end is F*L^3/(3*E*I).
2
+ % The beam is modeled with load, span length, elastic modulus, and second moment
3
+ % of area. The rules compute F*L^3/(3*E*I), convert meters to millimeters, and
4
+ % classify the design against a deflection limit.
4
5
 
5
- % Output declarations: materialize/2 selects the relations written to this example's golden output.
6
6
  materialize(type, 2).
7
7
  materialize(tipDeflection_m, 2).
8
8
  materialize(tipDeflection_mm, 2).
9
9
  materialize(limit_mm, 2).
10
10
  materialize(status, 2).
11
11
 
12
- % Program structure: facts set up the scenario, and rules derive the materialized conclusions.
13
12
  beam(beam1, force_N, 1200.0).
14
13
  beam(beam1, length_m, 2.5).
15
14
  beam(beam1, elasticModulus_Pa, 200000000000.0).
16
15
  beam(beam1, secondMoment_m4, 0.000008).
17
16
  limit(beam1, maxDeflection_mm, 5.0).
18
17
 
19
- % Derivation rules: each rule below contributes one logical step toward the displayed results.
20
18
  tip_deflection_m(Beam, Deflection) :-
21
19
  beam(Beam, force_N, Force),
22
20
  beam(Beam, length_m, Length),
@@ -0,0 +1,49 @@
1
+ % Binomial coefficients and Vandermonde's identity.
2
+ %
3
+ % choose(N,K,C) is computed by a multiplicative recurrence, then vandermonde/5 checks
4
+ % the finite convolution sum: sum_i C(R,i) C(S,N-i) = C(R+S,N). Memoization keeps
5
+ % the binomial-row prefixes shared across both sides of the identity.
6
+ % choose_step/5 uses the multiplicative recurrence
7
+ % C(N, I+1) = C(N, I) * (N-I) / (I+1)
8
+ % and is memoized because row sums and identities reuse prefixes.
9
+ materialize(binomial_answer, 2).
10
+
11
+ memoize(choose_step, 5).
12
+
13
+ choose(N, K, C) :-
14
+ ge(K, 0),
15
+ le(K, N),
16
+ choose_step(N, K, 0, 1, C).
17
+
18
+ choose_step(_N, K, K, Acc, Acc).
19
+ choose_step(N, K, I, Acc, C) :-
20
+ lt(I, K),
21
+ add(I, 1, I1),
22
+ sub(N, I, Factor),
23
+ mul(Acc, Factor, Numerator),
24
+ div(Numerator, I1, NextAcc),
25
+ choose_step(N, K, I1, NextAcc, C).
26
+
27
+ symmetric(N, K) :-
28
+ choose(N, K, C),
29
+ sub(N, K, OtherK),
30
+ choose(N, OtherK, C).
31
+
32
+ vandermonde_sum(N, M, R, Sum) :-
33
+ sumall(Product,
34
+ (between(0, R, K),
35
+ sub(R, K, RK),
36
+ choose(N, K, A),
37
+ choose(M, RK, B),
38
+ mul(A, B, Product)),
39
+ Sum).
40
+
41
+ vandermonde(N, M, R, Sum) :-
42
+ add(N, M, TotalN),
43
+ choose(TotalN, R, Sum),
44
+ vandermonde_sum(N, M, R, Sum).
45
+
46
+ binomial_answer(choose_24_12, C) :- choose(24, 12, C).
47
+ binomial_answer(symmetry_24_7, true) :- symmetric(24, 7).
48
+ binomial_answer(vandermonde_12_10_8, Sum) :- vandermonde(12, 10, 8, Sum).
49
+ binomial_answer(row_12_sum, Sum) :- sumall(C, (between(0, 12, K), choose(12, K, C)), Sum).
@@ -10,7 +10,8 @@ materialize(plan, 2).
10
10
  materialize(finalState, 2).
11
11
  materialize(blockCount, 2).
12
12
 
13
- % Program structure: facts set up the scenario, and rules derive the materialized conclusions.
13
+ % The initial and goal states are lists of on/2 facts. Sorting successor states
14
+ % gives canonical terms for equality and visited-state checks.
14
15
  initial([on(a, table), on(b, a), on(c, b), on(d, c), on(e, d)]).
15
16
  goal([on(a, table), on(b, a), on(c, table), on(d, c), on(e, d)]).
16
17
 
@@ -21,7 +22,8 @@ block(d).
21
22
  block(e).
22
23
 
23
24
  support(table, _State).
24
- % Derivation rules: each rule below contributes one logical step toward the displayed results.
25
+ % move/3 chooses a clear block and a clear support; the bounded planner chains
26
+ % those legal moves while avoiding previously seen states.
25
27
  support(Block, State) :-
26
28
  block(Block),
27
29
  member(on(Block, _Below), State).
@@ -4,6 +4,10 @@
4
4
  % inductor ripple current, capacitor ripple voltage, and checks design limits.
5
5
 
6
6
  % Output declarations: materialize/2 selects the relations written to this example's golden output.
7
+ %
8
+ % The constants describe one regulator design. The rules intentionally keep
9
+ % each engineering equation separate so proof output can point to the exact
10
+ % calculation that made the design pass or fail.
7
11
  materialize(dutyCycle, 2).
8
12
  materialize(inductorRipple_A, 2).
9
13
  materialize(rippleRatio, 2).
@@ -51,6 +55,7 @@ capacitor_ripple_voltage(Converter, RippleVoltage) :-
51
55
  mul(EightF, Capacitance, Denominator),
52
56
  div(RippleCurrent, Denominator, RippleVoltage).
53
57
 
58
+ % within_ripple_limits/1 is the design gate for ripple current and output voltage.
54
59
  within_ripple_limits(Converter) :-
55
60
  ripple_ratio(Converter, Ratio),
56
61
  limit(Converter, maxRippleRatio, MaxRatio),
@@ -10,12 +10,14 @@ materialize(averageLatency_ms, 2).
10
10
  materialize(status, 2).
11
11
  materialize(reason, 2).
12
12
 
13
- % Program structure: facts set up the scenario, and rules derive the materialized conclusions.
13
+ % cache_sample/5 contains hits, misses, and the two latency classes; threshold/3
14
+ % contains the operational targets used by the status rule.
14
15
  cache_sample(api_cache, 8600.0, 1400.0, 5.0, 80.0).
15
16
  threshold(api_cache, minimum_hit_rate, 0.80).
16
17
  threshold(api_cache, maximum_average_latency_ms, 20.0).
17
18
 
18
- % Derivation rules: each rule below contributes one logical step toward the displayed results.
19
+ % The rules compute total requests, hit rate, and weighted latency before
20
+ % applying both acceptance thresholds together.
19
21
  total_requests(Cache, Total) :-
20
22
  cache_sample(Cache, Hits, Misses, _HitLatency, _MissLatency),
21
23
  add(Hits, Misses, Total).
@@ -10,12 +10,14 @@ materialize(latencyCheck, 2).
10
10
  materialize(status, 2).
11
11
  materialize(reason, 2).
12
12
 
13
- % Program structure: facts set up the scenario, and rules derive the materialized conclusions.
13
+ % canary/4 records request count, error count, and p95 latency; thresholds
14
+ % make the rollout policy explicit data rather than constants hidden in rules.
14
15
  canary(canary42, 5000.0, 75.0, 180.0).
15
16
  threshold(canary42, maximum_error_rate, 0.01).
16
17
  threshold(canary42, maximum_p95_latency_ms, 200.0).
17
18
 
18
- % Derivation rules: each rule below contributes one logical step toward the displayed results.
19
+ % The latency and error-budget checks are independent so the final rollback
20
+ % reason can point to the failing guard.
19
21
  error_rate(Release, Rate) :-
20
22
  canary(Release, Requests, Errors, _P95Latency),
21
23
  div(Errors, Requests, Rate).
@@ -0,0 +1,37 @@
1
+ % Catalan numbers by memoized convolution.
2
+ %
3
+ % catalan(N,C) sums all splits of N-1 into left and right substructures. The same
4
+ % Catalan values appear in binary tree shapes, parenthesizations, and polygon
5
+ % triangulations, shown here with small wrapper predicates.
6
+ materialize(catalan_answer, 2).
7
+
8
+ memoize(catalan, 2).
9
+
10
+ % C_0 = 1; higher values are computed by the convolution sum.
11
+ catalan(0, 1).
12
+ catalan(N, C) :-
13
+ gt(N, 0),
14
+ sub(N, 1, N1),
15
+ sumall(Product,
16
+ (between(0, N1, I),
17
+ sub(N1, I, J),
18
+ catalan(I, A),
19
+ catalan(J, B),
20
+ mul(A, B, Product)),
21
+ C).
22
+
23
+ % An n-gon has C_(n-2) triangulations.
24
+ polygon_triangulations(Sides, Count) :-
25
+ ge(Sides, 3),
26
+ sub(Sides, 2, N),
27
+ catalan(N, Count).
28
+
29
+ parenthesizations(Factors, Count) :-
30
+ ge(Factors, 1),
31
+ sub(Factors, 1, N),
32
+ catalan(N, Count).
33
+
34
+ catalan_answer(catalan_12, C) :- catalan(12, C).
35
+ catalan_answer(triangulations_14_gon, Count) :- polygon_triangulations(14, Count).
36
+ catalan_answer(parenthesizations_13_factors, Count) :- parenthesizations(13, Count).
37
+ catalan_answer(first_ten_sum, Sum) :- sumall(C, (between(0, 9, N), catalan(N, C)), Sum).
@@ -1,10 +1,14 @@
1
1
  % A tiny memoized chart parser for a context-free grammar.
2
- % span/4 is the dynamic-programming chart relation: sentence, category,
3
- % start index, and end index.
2
+ %
3
+ % span(Sentence, Category, Start, End) is the dynamic-programming chart item:
4
+ % Category covers a half-open token interval. Memoizing span/4 turns recursive
5
+ % grammar recognition into chart parsing, so ambiguous phrases share subparses.
4
6
  materialize(chart_parser_answer, 2).
5
7
 
6
8
  memoize(span, 4).
7
9
 
10
+ % Two sample sentences share the same tiny grammar but have different parse counts.
11
+
8
12
  sentence(command, 5).
9
13
  sentence(ambiguous_pp, 8).
10
14
 
@@ -38,10 +42,12 @@ rule(vp, verb, np).
38
42
  rule(vp, vp, pp).
39
43
  rule(pp, prep, np).
40
44
 
45
+ % Lexical chart items come directly from words and terminal categories.
41
46
  span(Sentence, Category, Start, End) :-
42
47
  word(Sentence, Start, Token),
43
48
  terminal(Category, Token),
44
49
  add(Start, 1, End).
50
+ % Nonterminal chart items split the interval at a Middle point.
45
51
  span(Sentence, Category, Start, End) :-
46
52
  rule(Category, Left, Right),
47
53
  span(Sentence, Left, Start, Middle),
@@ -5,6 +5,10 @@
5
5
  % public relation report.
6
6
 
7
7
  % Output declarations: materialize/2 selects the relations written to this example's golden output.
8
+ %
9
+ % Inclusion criteria are positive requirements; exclusion criteria veto a
10
+ % candidate even when the inclusion checks pass. The emitted reason/2 facts are
11
+ % the audit trail a coordinator would need for a screen-failure report.
8
12
  materialize(type, 2).
9
13
  materialize(status, 2).
10
14
  materialize(reason, 2).
@@ -58,6 +62,7 @@ exclusion_renal(Patient) :-
58
62
  exclusion_pregnancy(Patient) :-
59
63
  condition(Patient, pregnant).
60
64
 
65
+ % A patient is eligible only when all inclusion checks pass and no exclusion is proven.
61
66
  screen_eligible(Patient) :-
62
67
  inclusion_adult(Patient),
63
68
  inclusion_diagnosis(Patient),
@@ -1,15 +1,16 @@
1
1
  % Eyelet-inspired combinations example using findall/3 and sort/2.
2
- % The source-level select/3 relation remains an ordinary eyelang rule.
3
-
4
- % Output declarations: materialize/2 selects the relations written to this example's golden output.
2
+ %
3
+ % combination/3 generates the same subset in several selection orders. findall/3
4
+ % collects those candidates, and sort/2 canonicalizes the list so each unordered
5
+ % 3-combination of five items is reported once.
5
6
  materialize(combinations, 2).
6
7
  materialize(count, 2).
7
8
  materialize(reason, 2).
8
9
 
9
- % Program structure: facts set up the scenario, and rules derive the materialized conclusions.
10
- % select/3 nondeterministically removes one item from a list.
10
+ % select/3 nondeterministically removes one item from a list; because it is an
11
+ % ordinary rule, the example also demonstrates user-level list recursion.
11
12
  select(Item, [Item | Rest], Rest).
12
- % Derivation rules: each rule below contributes one logical step toward the displayed results.
13
+ % The recursive clause keeps the non-selected head and searches the tail.
13
14
  select(Item, [Head | Tail], [Head | Rest]) :-
14
15
  select(Item, Tail, Rest).
15
16
 
@@ -4,6 +4,10 @@
4
4
  % the pair-shaped pair lists used by the Eyeling source.
5
5
 
6
6
  % Output declarations: materialize/2 selects the relations written to this example's golden output.
7
+ %
8
+ % The example derives arithmetic identities, polar conversions, powers, roots,
9
+ % exponential/trigonometric functions, and distance/normalization results from
10
+ % a small complex-number toolkit.
7
11
  materialize(is, 2).
8
12
 
9
13
  % Program structure: facts set up the scenario, and rules derive the materialized conclusions.
@@ -11,6 +15,7 @@ pi(3.141592653589793).
11
15
  e(2.718281828459045).
12
16
 
13
17
  % Derivation rules: each rule below contributes one logical step toward the displayed results.
18
+ % z^w is evaluated through polar/log form, exposing useful intermediate proof steps.
14
19
  complex_exponentiation([A, B], [C, D], [E, F]) :-
15
20
  complex_polar([A, B], [R, T]),
16
21
  pow(R, C, Z1),
@@ -0,0 +1,36 @@
1
+ % Convergents of sqrt(2) by memoized recurrence.
2
+ %
3
+ % conv(N, P, Q) gives the Nth numerator/denominator pair for [1; 2, 2, ...].
4
+ % Because each convergent depends on the previous two, memoization avoids the
5
+ % exponential recomputation that the direct Horn-clause recurrence would have.
6
+ % pell_error/2 connects the approximation sequence with P^2 - 2Q^2 = +/-1.
7
+ materialize(convergent_answer, 2).
8
+
9
+ memoize(conv, 3).
10
+
11
+ % Base convergents are 1/1 and 3/2.
12
+ conv(0, 1, 1).
13
+ conv(1, 3, 2).
14
+ conv(N, P, Q) :-
15
+ gt(N, 1),
16
+ sub(N, 1, N1),
17
+ sub(N, 2, N2),
18
+ conv(N1, P1, Q1),
19
+ conv(N2, P2, Q2),
20
+ mul(2, P1, TwiceP1),
21
+ add(TwiceP1, P2, P),
22
+ mul(2, Q1, TwiceQ1),
23
+ add(TwiceQ1, Q2, Q).
24
+
25
+ % The signed error alternates between +1 and -1 for these convergents.
26
+ pell_error(N, Error) :-
27
+ conv(N, P, Q),
28
+ mul(P, P, P2),
29
+ mul(Q, Q, Q2),
30
+ mul(2, Q2, TwiceQ2),
31
+ sub(P2, TwiceQ2, Error).
32
+
33
+ convergent_answer(convergent_10, fraction(P, Q)) :- conv(10, P, Q).
34
+ convergent_answer(convergent_15, fraction(P, Q)) :- conv(15, P, Q).
35
+ convergent_answer(pell_error_15, Error) :- pell_error(15, Error).
36
+ convergent_answer(numerator_sum_0_to_10, Sum) :- sumall(P, (between(0, 10, N), conv(N, P, _Q)), Sum).
@@ -4,6 +4,10 @@
4
4
  % feedforward compensation, square-root normalization, and nonlinear feedback.
5
5
 
6
6
  % Output declarations: materialize/2 selects the relations written to this example's golden output.
7
+ %
8
+ % Each derived quantity is represented as its own predicate rather than a single
9
+ % formula blob, making the proof trace useful for debugging a failed actuator
10
+ % normalization or control-signal calculation.
7
11
  materialize(controlSignal, 2).
8
12
  materialize(status, 2).
9
13
  materialize(normalizedMeasurement, 2).
@@ -1,11 +1,15 @@
1
1
  % Critical-path scheduling for a small project network.
2
- % earliest_start/2 and finish_time/2 are memoized because many schedule and
3
- % critical-path queries reuse the same predecessor subproblems.
2
+ %
3
+ % earliest_start/2 is the maximum finish time over all predecessors; finish_time/2
4
+ % adds task duration. Critical tasks are reconstructed by following predecessors
5
+ % that attain those maxima. Memoization lets the schedule, finish date, and path
6
+ % queries share the same project-network subproblems.
4
7
  materialize(critical_path_answer, 2).
5
8
 
6
9
  memoize(earliest_start, 2).
7
10
  memoize(finish_time, 2).
8
11
 
12
+ % Durations are in arbitrary project time units.
9
13
  task(requirements, 2).
10
14
  task(architecture, 3).
11
15
  task(api_design, 2).
@@ -47,6 +51,7 @@ finish_time(Task, Finish) :-
47
51
  earliest_start(Task, Start),
48
52
  add(Start, Duration, Finish).
49
53
 
54
+ % For each task, choose a predecessor that determines its earliest start.
50
55
  critical_predecessor(Task, Pred) :-
51
56
  depends(Task, _AnyPred),
52
57
  aggregate_max(Finish, P,