eyemind 0.5.30 → 0.5.32

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 CHANGED
@@ -7,7 +7,7 @@ eyemind is a **JavaScript rule language** with forward and backward reasoning an
7
7
 
8
8
  [Playground](https://eyereasoner.github.io/eyemind/playground/) · [Specification](https://eyereasoner.github.io/eyemind/SPEC) · [Conformance](https://eyereasoner.github.io/eyemind/conformance/) · [Examples](https://eyereasoner.github.io/eyemind/examples/)
9
9
 
10
- The playground runs programs in your browser; the specification defines the language, its canonical text, the proof format and the C1–C10 checks. The examples are 135 runnable programs, each with a card deck and saved conclusions, proofs and check reports. The conformance suite has 1388 cases that test language and proof behavior through a command adapter, together with implementation interface checks; run it [in your browser](https://eyereasoner.github.io/eyemind/playground/conformance).
10
+ The playground runs programs in your browser; the specification defines the language, its canonical text, the proof format and the C1–C10 checks. The examples are 135 runnable programs, each with a card deck and saved conclusions, proofs and check reports. The conformance suite has 1390 cases that test language and proof behavior through a command adapter, together with implementation interface checks; run it [in your browser](https://eyereasoner.github.io/eyemind/playground/conformance).
11
11
 
12
12
  ## Contents
13
13
 
@@ -24,7 +24,6 @@ The playground runs programs in your browser; the specification defines the lang
24
24
  - [SPARQL 1.2 RL](#sparql-12-rl)
25
25
  - [How eyemind reasons](#how-eyemind-reasons)
26
26
  - [Proofs, and what checking one means](#proofs-and-what-checking-one-means)
27
- - [Native proof data](#native-proof-data)
28
27
  - [JSON check reports](#json-check-reports)
29
28
  - [Why negation and collection are safe](#why-negation-and-collection-are-safe)
30
29
  - [Checking the translation](#checking-the-translation)
@@ -148,7 +147,7 @@ for (let level = 1; level <= 10; level++) {
148
147
  - **Arithmetic is a term, not an operator.** `is(Y, add(X, 1))` computes and `gt(X, 1)` compares. `X + 1` or `X > 1` stops the program with a message saying what to write instead, and operators on plain numbers are JavaScript's own (`2 ** 60 + 1` arrives already rounded). The primitives are listed in [SPEC §4](https://eyereasoner.github.io/eyemind/SPEC#4-goals-and-primitives) and the arithmetic functions in [SPEC §5](https://eyereasoner.github.io/eyemind/SPEC#5-arithmetic).
149
148
  - **Numbers are exact.** An integral number is an integer, `2` and `2.0` alike, and `float(2)` is a float; write integers beyond 2^53 as a `BigInt`, `9007199254740993n`. `1` and `float(1)` do not unify, yet compare equal.
150
149
  - **Something exists.** A variable only a forward rule's conclusion mentions becomes a Skolem term of that firing: `implies(person(X), has_parent(X, P))` concludes `has_parent('ann', skolem(2, 'P', ['ann']))`.
151
- - **Data is not a program.** eyemind's term documents are plain expressions. `facts_from` reads one as facts and never executes it, so it is the safe way to take in data you do not trust, and lets one run reason over another's proof, as [audited-grants](https://github.com/eyereasoner/eyemind/blob/main/examples/audited-grants.js) does. Native N3 and SRL proofs are RDF data too.
150
+ - **Data is not a program.** eyemind's term documents are plain expressions. `facts_from` reads one as facts and never executes it, so it is the safe way to take in data you do not trust, and lets one run reason over another's proof, as [audited-grants](https://github.com/eyereasoner/eyemind/blob/main/examples/audited-grants.js) does.
152
151
 
153
152
  ### Deriving rules
154
153
 
@@ -293,7 +292,7 @@ Whole-log replay gives N3 or JavaScript rules an ordered view of the messages:
293
292
  ```sh
294
293
  eyemind examples/message-boundaries-n3.n3 examples/data/message-boundaries-n3.trig
295
294
  eyemind --proof examples/message-boundaries-n3.n3 examples/data/message-boundaries-n3.trig
296
- eyemind --check-proof examples/proof/message-boundaries-n3.n3 examples/message-boundaries-n3.n3 examples/data/message-boundaries-n3.trig
295
+ eyemind --check-proof examples/proof/message-boundaries-n3.js examples/message-boundaries-n3.n3 examples/data/message-boundaries-n3.trig
297
296
  ```
298
297
 
299
298
  The replay vocabulary is `eymsg:`, with namespace
@@ -403,29 +402,19 @@ The two work together: a forward rule's premise can call a backward definition,
403
402
  ## Proofs, and what checking one means
404
403
 
405
404
  A proof holds the claims, the source clauses it cites, and each recorded
406
- inference. JavaScript programs write `step(...)` records. N3 inputs write
407
- N3 proofs, and SRL inputs write SRL `DATA` proofs:
405
+ inference as `step(...)` records. Every input writes the same JavaScript
406
+ proof: an N3 document or SRL rule set is compiled to an eyemind program, and
407
+ its proof cites that program's clauses, with triples as `rdf(S, P, O)` (an
408
+ SRL inference as `inf(S, P, O)`) over `iri(...)` and `literal(...)` terms:
408
409
 
409
410
  ```sh
410
- eyemind --proof examples/socrates-n3.n3 > /tmp/socrates-proof.n3
411
- eyemind --check-proof /tmp/socrates-proof.n3 examples/socrates-n3.n3
412
- eyemind --proof examples/socrates-srl.srl > /tmp/socrates-proof.srl
413
- eyemind --check-proof /tmp/socrates-proof.srl examples/socrates-srl.srl
411
+ eyemind --proof examples/socrates-n3.n3 > /tmp/socrates-proof.js
412
+ eyemind --check-proof /tmp/socrates-proof.js examples/socrates-n3.n3
413
+ eyemind --proof examples/socrates-srl.srl > /tmp/socrates-proof.js
414
+ eyemind --check-proof /tmp/socrates-proof.js examples/socrates-srl.srl
414
415
  ```
415
416
 
416
- Native proofs use `pe:`, `https://eyereasoner.github.io/pe#`, for the claims,
417
- conclusions, rule numbers, bindings and ordered uses. N3 displays statements
418
- as quoted formulas; SRL displays them as RDF triple terms. Rule numbers name
419
- clauses of the compiled eyemind program. The `em:` vocabulary,
420
- `https://eyereasoner.github.io/eyemind/proof#`, keeps the exact terms and
421
- ordered records, including all C9 search and C10 call tables. The checker
422
- validates the displays against those records, then checks the certificate
423
- against the source program. Altered displays, duplicate properties and extra
424
- assertions fail checking. Proofs can be read as data by other N3 or SRL rules.
425
-
426
- `--check-proof` recognizes the content, independently of the filename, and
427
- continues to accept JavaScript certificates for native inputs. Check reports
428
- remain JavaScript term documents, or JSON with `--json`.
417
+ Check reports are JavaScript term documents too, or JSON with `--json`.
429
418
 
430
419
  Checking applies ten conditions:
431
420
 
@@ -476,69 +465,6 @@ verdict('checked')
476
465
 
477
466
  A `checked` verdict thus establishes two things: every claim follows from the program, and the claims are every answer of the original questions. The `called/2` table of each question lists all its answers and is checked against the program, so a proof that omits one fails C10, and a question with no claims is shown to have no answers. A failed check gives `failure(Condition, Conclusion, Detail)` facts, `verdict(failed(N))` and exit code 2. What a certificate cannot settle stays an `obligation(...)` with the verdict `checked_with_obligations`, among them `obligation('call_fidelity', 'all_answers', Question)` for a question whose answers it cannot show complete; `--strict-proof` rejects those. To check answers to `--goal` questions, pass the same goals when checking. [SPEC §11](https://eyereasoner.github.io/eyemind/SPEC#11-proof-checking) defines every condition.
478
467
 
479
- ### Native proof data
480
-
481
- These N3 and SRL encodings are implementation extensions to the canonical
482
- proof documents. Language and proof conformance does not require them.
483
-
484
- The native proof resource is `<urn:eyemind:proof>`, of type `pe:Proof`, where
485
- `pe:` is `https://eyereasoner.github.io/pe#` and `em:` is
486
- `https://eyereasoner.github.io/eyemind/proof#`. It has `em:format` equal to
487
- `"n3"` or `"srl"`, `pe:claims` as an ordered collection of claim displays,
488
- and `em:records` as an ordered collection of record IRIs. Record `N`, counted
489
- from 1, is `<urn:eyemind:proof#recordN>` and has one `em:term` containing its
490
- [Section 10](https://eyereasoner.github.io/eyemind/SPEC#10-proof-documents) statement, encoded as a tagged collection:
491
-
492
- | Term | Collection |
493
- | --- | --- |
494
- | Atom | `(em:atom "text")` |
495
- | Integer | `(em:integer "digits")`, with a minus for a negative integer |
496
- | Float | `(em:float "number")`, preserving signed zero as `"-0"` |
497
- | Variable | `(em:variable "name")`, including anonymous-variable status |
498
- | `iri(I)` with an RDF-compatible IRI | `(em:iri <I>)` |
499
- | Nonempty proper list | `(em:list (EncodedItem ...))` |
500
- | Compound | `(em:compound "name" (EncodedArgument ...))` |
501
-
502
- The empty list is the atom `"[]"`. Other compounds, including open lists,
503
- quoted graphs and Skolem terms, use the compound encoding. A string field
504
- containing a character RDF cannot represent uses an `em:utf16` typed literal
505
- whose lexical form is four lowercase hexadecimal digits per UTF-16 code
506
- unit. This retains every atom and variable name accepted by
507
- [Section 9.2](https://eyereasoner.github.io/eyemind/SPEC#92-canonical-atoms-numbers-variables-and-lists).
508
-
509
- A triple goal's display is an N3 quoted formula, or an SRL RDF triple term.
510
- Other goals use their tagged encoding. A step record also displays
511
- `pe:conclusion`, `pe:rule` for a `clause(N)` justification, `pe:source` for
512
- `source(N)`, or `pe:justification` for another justification. `pe:binding`
513
- is an ordered collection of `(VariableName Value)` pairs, and `pe:uses` an
514
- ordered collection of premise displays. Non-native binding values retain
515
- their tagged encoding. Search records display `pe:derived`, `pe:searched`
516
- or `pe:called` and an ordered `pe:answers` collection. Clause numbers name
517
- the compiled program's clauses, whose authority is still the source input.
518
- SRL proofs contain only `DATA` and declarations, never rules or imports.
519
-
520
- When an SRL rule set uses `NOW`, `UUID` or `STRUUID`, its compiled program
521
- includes one ground `srl_execution(Now, Seed)` fact. `Now` is an ISO UTC
522
- timestamp with milliseconds and `Seed` contains 64 lowercase hexadecimal
523
- digits. The compiler captures these external inputs once per compilation;
524
- they remain fixed throughout evaluation. To check a saved SRL proof, the
525
- format loader may recover this fact from its clause records, validate its
526
- two fields, and recompile the source with that execution context. All other
527
- clauses still come from the source, and all displays undergo C1–C10 as
528
- usual. This establishes consequences of the recorded context, without
529
- certifying a clock observation or the entropy of the seed.
530
-
531
- The reader decodes every record, verifies all displays and properties against
532
- those records, and applies the unchanged checks of
533
- [Section 11](https://eyereasoner.github.io/eyemind/SPEC#11-proof-checking) to the decoded
534
- certificate. A missing, extra, duplicate or inconsistent property fails C3.
535
- Numeric literal displays retain their decimal digits during this comparison;
536
- distinct decimal literals do not agree merely by rounding to binary64.
537
- Prefix aliases and reordering top-level properties are accepted, as is
538
- consistent blank-node renaming; the order of collections and formula triples
539
- is retained. Displayed claims cannot replace encoded claims, and neither
540
- representation can change the source authority or supply missing evidence.
541
-
542
468
  ### JSON check reports
543
469
 
544
470
  With `--json`, checking modes write a JSON report instead of a term document.
@@ -562,7 +488,7 @@ A negation `not(G)` concludes from what is *absent* and a collection `findall(T,
562
488
  - **Negate only what is bound.** The variables of `not(G)` must be bound when it runs; write `not(q(X, _))` for "no value at all".
563
489
  - **Check the search, not just its result.** A proof ends with a search certificate: `searched(Call, Answers)` lists each call's answers and `derived(Pattern, Facts)` each consulted relation. The checker expands each call one level against the program, so a wrong table shows up as a disagreement.
564
490
  - **Say what was taken on trust.** Anything the certificate cannot settle becomes an obligation, and evidence in the proof can still refute it (C6).
565
- - **Certify the original questions.** Supported, closed listings establish the original calls, and that the claims are all their answers, when no rule they depend on can observe bindings or evaluation order. A mode analysis checks this: primitives such as arithmetic run with their inputs bound, negations with their variables bound, and `once` and `findall` bind nothing other goals use. Where it does not apply, as for tests of whether a variable is bound, the checker replays each derived fact's recorded firing in source order instead. A proof within these bounds can be `checked` with no obligation, even under `--strict-proof`. Rules generated by templates are checked through their instances, and source rule inspection through the program's catalogue of rules. A `findall_sorted` of ground items is certified from the set of derived facts alone. `findall` and first answers over derived facts, whose order a listing cannot show, and `restricted` rules with new witnesses keep an obligation.
491
+ - **Certify the original questions.** Closed listings establish the original calls and all their answers when every listed fact's recorded firing replays. The checker follows the source rule and the recorded premise evidence in order, starting with no bindings, so a state test sees the bindings of its actual call and `once` takes the actual first answer. It does not call the reasoner or supply missing evidence. Rules generated by templates are checked through their instances, and source rule inspection through the program's catalogue. A proof within these bounds can be `checked` with no obligation, even under `--strict-proof`. A `findall_sorted` of ground items is certified from the set of derived facts alone. `findall` and first answers over derived facts, whose order a listing cannot show, and `restricted` rules with new witnesses keep an obligation.
566
492
 
567
493
  ## Checking the translation
568
494
 
@@ -640,8 +566,7 @@ before exhaustion.
640
566
  | 2 | An invalid proof check; the report is printed as usual. |
641
567
  | 65 | The run concluded `'false'` and halted. |
642
568
 
643
- The command line, JSON output, additional input formats, native proof
644
- encodings, library API and browser interface describe this implementation.
569
+ The command line, JSON output, additional input formats, library API and browser interface describe this implementation.
645
570
  They are outside the language and proof specification.
646
571
 
647
572
  ### Resource limits
@@ -722,13 +647,6 @@ console.log(checkProof(socrates, result.proof, { goals }).valid);
722
647
 
723
648
  `run()` returns `conclusions`, `answers`, `bindings`, `inferred`, `stdout`, `proof`, `proofReport`, `stats` and `haltCode`, and takes `goal`, `goals`, `proof`, `maxDepth`, `maxIterations` and `maxInferences`; exceeding a bound throws an `EyemindError`. `conclusions` holds the answer terms; `answers`, `bindings` and `stdout` are rendered when first read. Ground N3 conclusions are written directly from their terms. `loadSources([[text, filename], ...], io)` loads several sources as one program; pass `nodeIO` from `eyemind/node` as `io` to let `facts_from(path)` read files. `checkProof(program, document, { goals, allowTrusted })` checks C1–C10, and `allowTrusted: false` rejects every obligation. `checkReport`, `readTerm`, `readTerms` and `write` format reports and read and write the canonical text.
724
649
 
725
- The core library's `result.proof` is the JavaScript certificate.
726
- `writeNativeProof(result.proof, { format: 'n3', prefixes })` writes its N3
727
- representation; use `format: 'srl'` for SRL. `readNativeProof(document)`
728
- returns the decoded terms, and `readProofTerms(document)` reads any supported
729
- proof as `[term, line]` pairs. Native records have line 0. `checkProof`
730
- accepts all three representations and never evaluates proof text.
731
-
732
650
  ## What is deliberately absent
733
651
 
734
652
  Cut, conditional commitment, mutable databases, attributed variables, constraint libraries, tabling, and filesystem or network built-ins. Without cut and a mutable database, a derivation is a function of the program and its input, which is what makes a certificate meaningful. Undefined predicates fail.
package/SPEC.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ```text
4
4
  Title: The eyemind Rule Language and Proof Format
5
- Version: eyemind 0.5.30
5
+ Version: eyemind 0.5.32
6
6
  ```
7
7
 
8
8
  This document specifies the syntax and meaning of eyemind programs and data
@@ -1666,9 +1666,9 @@ certified answer set, and every answer in it is claimed.
1666
1666
 
1667
1667
  For a program with negation, "follows" is relative to the facts the
1668
1668
  certificate lists: C9 establishes that they are supported by steps, closed
1669
- under the forward rules and consistent with every settled negation. In the
1670
- ground relational fragment of [Section 11.13](#1113-c10-call-fidelity), a stratified or
1671
- chain-stratified program has only one such result ([Section 7.4](#74-negation-and-collection)). With restricted
1669
+ under the forward rules and consistent with every settled negation. Under
1670
+ the call-fidelity requirements of [Section 11.13](#1113-c10-call-fidelity),
1671
+ a stratified or chain-stratified program has only one such result ([Section 7.4](#74-negation-and-collection)). With restricted
1672
1672
  witnesses, different lean results can have these properties. A claim whose
1673
1673
  forward dependency closure includes a restricted rule with head-only
1674
1674
  variables therefore retains a call-fidelity obligation, and a strict check
@@ -2064,6 +2064,10 @@ including those consulted transitively by table expansions and listing
2064
2064
  closure checks. No table it rests on may depend on itself through the
2065
2065
  tables consulted by its expansion.
2066
2066
 
2067
+ The same dependency graph establishes **answer order**. A table has
2068
+ certified answer order exactly when its expansion consults no forward
2069
+ listing and every table it depends on has certified answer order.
2070
+
2067
2071
  **Supporting and closing listings.** Every listed fact MUST have a step,
2068
2072
  have the listing's name and arity, and be ground, unless the program
2069
2073
  inspects source rules and the fact is a derived pattern
@@ -2095,13 +2099,12 @@ requires:
2095
2099
 
2096
2100
  **Certificate limits.** Settlement also requires all of the following:
2097
2101
 
2098
- - No `findall`, `once`, or `findall_sorted` collecting an item that is not
2099
- ground, in the boundary's search, a relied-on table or a closure check,
2100
- uses a table whose answers rest on a forward listing. This format checks
2101
- support and closure of derived facts, but cannot establish their
2102
- publication order for order-sensitive operations. A `findall_sorted` of
2103
- ground items depends on the solutions and how often each occurs, not on
2104
- their order.
2102
+ - Every table used by `findall` or `once`, or by `findall_sorted` whose
2103
+ results include a nonground item, MUST have certified answer order. This
2104
+ applies in the boundary's search, relied-on tables and closure checks.
2105
+ Support and closure do not establish the publication order of forward
2106
+ facts. A `findall_sorted` of ground items depends on the solutions and
2107
+ how often each occurs, not on their order.
2105
2108
  - No consulted listing's relation is concluded by a forward rule within a
2106
2109
  template's scope ([Section 6.2](#62-inline-rule-templates)) that
2107
2110
  introduces witnesses, or whose generators have a guard or introduce
@@ -2200,9 +2203,9 @@ with these differences:
2200
2203
  4. A comparison `compare/3` with either compared term nonground is not
2201
2204
  supported by this certificate format: alpha renaming of a table need
2202
2205
  not preserve the order of variable names. Such a search leaves call fidelity unproved.
2203
- 5. A consulted forward listing MUST have a dependency closure in the
2204
- supported fragment described below. A final listing alone MUST NOT certify
2205
- binding-sensitive or order-sensitive forward firings outside that fragment.
2206
+ 5. Each fact of every consulted forward listing MUST replay its recorded
2207
+ firing as specified below. Support and closure alone MUST NOT certify
2208
+ bindings or control choices that the recorded firing never makes.
2206
2209
 
2207
2210
  For the `once` example in [Section 11.2](#112-operational-query-fidelity),
2208
2211
  the call certificate contains:
@@ -2219,80 +2222,21 @@ first, and `once` selects it. Thus `q('a')` is an answer and `q('b')` is
2219
2222
  excluded. Substituting `called(p('b'), [p('b')])` cannot establish the
2220
2223
  different call `p(X)`.
2221
2224
 
2222
- **Supported forward listings.** A listing supports C10 when a search of
2223
- each rule body it depends on, in source order, finds exactly the ground
2224
- instances of that body that hold. Its steps, whose primitives C5 re-decides
2225
- on their ground instances, then show firings that a search makes. This holds
2226
- when no goal can observe the bindings or the order in which it runs. The
2227
- checker establishes it by a **mode analysis** of the rules the listing
2228
- depends on. A **mode** of a call gives, for each argument, whether it is
2229
- ground when the call runs: an argument is ground when every variable in it
2230
- is **grounded** at that point.
2231
-
2232
- The analysis starts from the listed relation and its forward rules, and
2233
- follows each ordinary body call, inside a negation or not, to the called
2234
- relation in the mode of that call: its forward rules once, and its backward
2235
- rules once in each mode. A forward rule's body starts with no grounded
2236
- variable. A backward rule's body starts with the variables of the head
2237
- arguments that are ground in the mode. Body goals are taken in order, each
2238
- with the variables grounded before it:
2239
-
2240
- - `'true'` grounds nothing. Conjunction accumulates the grounded variables
2241
- of its parts. Disjunction grounds only those grounded by both
2242
- alternatives. `call(G)` is `G`.
2243
- - A call to an ordinary relation grounds its variables when every source
2244
- fact of the relation is ground once the arguments ground in the mode are
2245
- unified with it, and the relation is not **loose** in that mode;
2246
- otherwise it grounds nothing.
2247
- - A negation grounds nothing. Each of its variables other than anonymous
2248
- ones MUST be grounded before it, and it MUST NOT contain a negation.
2249
- - `once(G)` grounds nothing. `G` MUST satisfy these conditions. Each named
2250
- variable of `G` that occurs elsewhere in the clause MUST be grounded before
2251
- it, so the choice of a first answer binds nothing another goal uses.
2252
- - A collection `findall(T, G, L)` or `findall_sorted(T, G, L)` follows the
2253
- same rule for `T` and `G`. It grounds the variables of `L` when `G`
2254
- grounds every variable of `T`.
2255
- - A primitive whose variables are all grounded before it is a test, and
2256
- grounds nothing. `unify/2` with one side ground grounds the other, and
2257
- with neither ground grounds nothing. Otherwise the primitive MUST be
2258
- called in one of the modes below, its input arguments ground, and it
2259
- grounds its variables.
2260
- - Source inspection, templates, captures and restricted rules are not
2261
- supported. A restricted rule's guard is a negation, but which firings the
2262
- rule makes can depend on the order of rule applications.
2263
-
2264
- After its body, every head variable of a forward rule MUST be grounded or
2265
- be a head-only witness checked by C8. If a head variable of a backward rule
2266
- is not grounded, the relation is loose in that mode, and the analysis
2267
- starts again with that call grounding nothing.
2268
-
2269
- | Primitive | Inputs → outputs |
2270
- | --- | --- |
2271
- | `is/2` | expression → result |
2272
- | `compare/3` | both compared terms → order |
2273
- | `atom_chars/2`, `atom_codes/2` | atom → list, or list → atom |
2274
- | `number_chars/2` | list → number |
2275
- | `atom_length/2`, `atom_lower/2`, `atom_upper/2`, `term_text/2` | first → second |
2276
- | `atom_concat/3` | both parts → whole, or whole → both parts |
2277
- | `regex_find/3`, `digest/3` | first two → third |
2278
- | `float64/4` | first three → fourth |
2279
-
2280
- In each listed mode, a call with ground inputs has exactly the solutions
2281
- whose ground instances C5 re-decides as holding. `number_chars/2` re-decides
2282
- a ground instance by reading its characters, so only that direction is
2283
- listed. A host-math result accepted by C5 only within its tolerance
2284
- ([Section 11.8](#118-c5-re-decision)) need not be the result a search
2285
- finds. A proof with such a step therefore supports no listing for C10 by
2286
- this analysis.
2287
-
2288
- **Replayed listings.** A listing the mode analysis does not support still
2289
- supports C10 when every fact of every consulted listing **replays**. A fact
2290
- replays when its step cites a forward rule that is not restricted, does
2291
- not introduce witnesses within a template's scope, and, if appended by a
2292
- template, has all its enclosing generators in the program, none with a
2293
- guard or witnesses; and when a search of that rule's body in
2294
- source order, starting with no bindings, solves each body goal as the
2295
- step's corresponding use records:
2225
+ **Replaying forward listings.** In addition to the support and closure
2226
+ checks of C9, every fact of every consulted listing MUST replay. Replay
2227
+ follows the source rule and the step's uses in order, starting with no
2228
+ bindings. It checks the bindings at each premise, rather than assuming
2229
+ the proof's final substitution was already available. It MUST NOT call a
2230
+ reasoner or supply a missing derivation.
2231
+
2232
+ A listing with a fact that does not replay is unsupported for C10 and
2233
+ leaves the obligations specified below. C1–C9 still check its steps normally.
2234
+
2235
+ A fact's step MUST cite a forward rule that is not restricted and introduces
2236
+ no witnesses within a template's scope. For a rule appended by a template,
2237
+ every enclosing generator MUST belong to the program and have no guard or
2238
+ witnesses. Replay checks each body goal against the step's corresponding
2239
+ use as follows:
2296
2240
 
2297
2241
  - A primitive runs on the bindings of that point of the search. Its first
2298
2242
  solution under which the goal can still unify with the use is taken.
@@ -2313,8 +2257,8 @@ step's corresponding use records:
2313
2257
  against its step's uses. For a backward rule appended by a template, the
2314
2258
  generator's part of the body replays first, before the head meets the
2315
2259
  goal, and the template's part after. A use with no step is unified with a source fact
2316
- of the relation, renamed apart. A replay that meets the same use under
2317
- the same call again does not replay.
2260
+ of the relation, renamed apart. A cycle through recorded uses does not
2261
+ replay, as required by C2.
2318
2262
  - An inspection follows its use's `source(N)` step: rule `N` of the
2319
2263
  catalogue, renamed apart, is unified with the goal.
2320
2264
  - After each goal, the goal MUST still unify with its use, since a step
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eyemind",
3
- "version": "0.5.30",
3
+ "version": "0.5.32",
4
4
  "description": "A dependency-free JavaScript rule language with forward and backward reasoning and checkable proofs.",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
package/src/cli.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // The eyemind command line.
2
2
  import { run, unusedClauses } from './engine.js';
3
- import { OUTPUT_FORMATS, defaultFormat, inputKind, loadInputs, rdfMessageFormat, scopeOf, writeConclusions, writeProof } from './formats.js';
3
+ import { OUTPUT_FORMATS, defaultFormat, inputKind, loadInputs, rdfMessageFormat, scopeOf, writeConclusions } from './formats.js';
4
4
  import { isRdfMessageLog, replayMessages, RdfMessageReader } from './messages.js';
5
5
  import { checkProof, checkReport, publicReport } from './proof.js';
6
6
  import { EyemindError } from './terms.js';
@@ -210,7 +210,7 @@ export function main(argv, io) {
210
210
  return report.valid ? result.haltCode || 0 : 2;
211
211
  }
212
212
  // Answers to goals are eyemind terms unless an output format is asked.
213
- const written = options.proof ? writeProof(loaded, result, { goals }) : writeConclusions(loaded, result, {
213
+ const written = options.proof ? result.proof : writeConclusions(loaded, result, {
214
214
  format: format ?? (goals.length ? 'eyemind' : defaultFormat(loaded.kind)), all, blankNodePrefix: io.blankNodePrefix,
215
215
  });
216
216
  stdout(written ?? result.stdout);
package/src/closure.js CHANGED
@@ -153,12 +153,12 @@ export class Settler {
153
153
  }
154
154
  outcome.tables = [...tables];
155
155
  outcome.listings = [...listings];
156
- const circular = this.circularity(tables);
156
+ const circular = this.checkDependencies(tables);
157
157
  if (circular !== null) {
158
158
  outcome.failures.push([`search certificate is circular at ${text(circular.call)}`, circular.call]);
159
159
  }
160
160
  if (outcome.failures.length || outcome.failed) return { ...outcome, status: 'failed' };
161
- if (unsettled || [...ordered].some((item) => !this.exact(item))) return { ...outcome, status: 'unsettled' };
161
+ if (unsettled || [...ordered].some((item) => !this.exactness.get(item))) return { ...outcome, status: 'unsettled' };
162
162
  if (answering) return { ...outcome, answers: found };
163
163
  if (!collecting && found.length) {
164
164
  outcome.failures.push([`absence contradicted by its search: ${text(boundary)}`, boundary]);
@@ -460,52 +460,32 @@ export class Settler {
460
460
  return null;
461
461
  }
462
462
 
463
- // The first table found on a cycle of tables, or null: a search that met
464
- // its own call again would never have finished.
465
- circularity(tables) {
466
- const state = new Map();
463
+ // Check the table dependency graph once: detect a cycle, or cache in
464
+ // dependency order which tables are independent of forward listings.
465
+ checkDependencies(tables) {
466
+ const exact = this.exactness ??= new Map();
467
+ const open = new Set();
468
+ const frame = (item) => [item, [...this.tables.get(item).reliance.tables], 0];
467
469
  for (const start of tables) {
468
- if (state.has(start)) continue;
469
- const stack = [[start, [...this.tables.get(start).reliance.tables], 0]];
470
- state.set(start, 'open');
470
+ if (exact.has(start)) continue;
471
+ const stack = [frame(start)];
472
+ open.add(start);
471
473
  while (stack.length) {
472
474
  const top = stack[stack.length - 1];
473
475
  if (top[2] >= top[1].length) {
474
- state.set(top[0], 'done');
476
+ const reliance = this.tables.get(top[0]).reliance;
477
+ exact.set(top[0], !reliance.listings.size && top[1].every((item) => exact.get(item)));
478
+ open.delete(top[0]);
475
479
  stack.pop();
476
480
  continue;
477
481
  }
478
482
  const next = top[1][top[2]++];
479
- if (state.get(next) === 'open') return this.tables.get(next);
480
- if (state.has(next)) continue;
481
- state.set(next, 'open');
482
- const entry = this.tables.get(next);
483
- stack.push([next, entry.reliance ? [...entry.reliance.tables] : [], 0]);
483
+ if (open.has(next)) return this.tables.get(next);
484
+ if (exact.has(next)) continue;
485
+ open.add(next);
486
+ stack.push(frame(next));
484
487
  }
485
488
  }
486
489
  return null;
487
490
  }
488
-
489
- // Whether a table's answers keep the order a search finds them in: none of
490
- // them, through any table it rests on, came from a listing.
491
- exact(callKey) {
492
- const memo = this.exactness ??= new Map();
493
- if (memo.has(callKey)) return memo.get(callKey);
494
- // Finish each dependency before caching its parent. Reversing discovery
495
- // order is insufficient when two branches share a dependency.
496
- const frame = (item) => [item, [...this.tables.get(item).reliance.tables], 0];
497
- const stack = [frame(callKey)];
498
- while (stack.length) {
499
- const top = stack[stack.length - 1];
500
- if (top[2] < top[1].length) {
501
- const next = top[1][top[2]++];
502
- if (!memo.has(next)) stack.push(frame(next));
503
- continue;
504
- }
505
- const reliance = this.tables.get(top[0]).reliance;
506
- memo.set(top[0], !reliance.listings.size && top[1].every((item) => memo.get(item)));
507
- stack.pop();
508
- }
509
- return memo.get(callKey);
510
- }
511
491
  }
package/src/engine.js CHANGED
@@ -3,7 +3,7 @@ import { PRIMITIVE_KEYS, STATE_TESTS, primitive } from './builtins.js';
3
3
  import { Reliance, Settler, Unsettled } from './closure.js';
4
4
  import { freshClause, matchHead, renaming, text, variant } from './common.js';
5
5
  import { goalTerm, subgoals } from './goals.js';
6
- import { callQuestions, positiveListings, replayed } from './fidelity.js';
6
+ import { callQuestions, replayed } from './fidelity.js';
7
7
  import { INSPECTION_KEYS } from './inspection.js';
8
8
  import { checkRendered, clauseDisplay, renderProof } from './proof.js';
9
9
  import { CONTROL_KEYS, Program } from './program.js';
@@ -1156,7 +1156,7 @@ function certify(solver, boundaries, operational = false) {
1156
1156
  }
1157
1157
  }
1158
1158
  // The recorded derivation of a listed fact or one of its premises, for the
1159
- // replay that supports a listing beyond the mode analysis.
1159
+ // replay that supports the original calls.
1160
1160
  let recorded = null;
1161
1161
  const stepOf = (goal) => {
1162
1162
  if (recorded === null) {
@@ -1192,8 +1192,7 @@ function certify(solver, boundaries, operational = false) {
1192
1192
  }
1193
1193
  }
1194
1194
  }
1195
- if (outcome.status === 'settled' && (!operational || positiveListings(program, outcome.listings) ||
1196
- replayed(program, settler, outcome.listings, stepOf))) {
1195
+ if (outcome.status === 'settled' && (!operational || replayed(program, settler, outcome.listings, stepOf))) {
1197
1196
  for (const item of outcome.tables) tables.add(item);
1198
1197
  for (const item of outcome.listings) listings.add(item);
1199
1198
  } else if (outcome.status === 'failed' && solver.haltCode === null) {