eyemind 0.5.21 → 0.5.23

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 1376 cases that test any implementation of the specification through its command line; 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 1382 cases that test any implementation of the specification through its command line; run it [in your browser](https://eyereasoner.github.io/eyemind/playground/conformance).
11
11
 
12
12
  ## Contents
13
13
 
@@ -44,7 +44,7 @@ Prolog, Datalog, N3 and SRL already exist, and eyemind adds no new logic: rules
44
44
  - eyemind proofs include the hard parts:
45
45
  - "nothing matched" (negation and collections), backed by a search certificate whose listings must be closed (C9);
46
46
  - what a rule says exists, as the Skolem term of that rule firing (C8);
47
- - whether each answer really answers the question asked (C10).
47
+ - whether each answer really answers the question asked, and whether every answer of the question is there (C10).
48
48
  - A forged proof must never pass the check, so a result is something you can hand to someone who does not trust your engine.
49
49
  2. **Programs are plain JavaScript.**
50
50
  - There is no syntax to learn, no parser to install and no dependency.
@@ -436,7 +436,7 @@ Checking applies ten conditions:
436
436
  | **C7** | relevance | Every claim answers the question, and every step serves a claim |
437
437
  | **C8** | witness integrity | Every "something exists" uses the Skolem term of its own firing |
438
438
  | **C9** | search closure | Every absence and collection the search certificate settles holds |
439
- | **C10** | call fidelity | Each answer is an actual answer of the original question |
439
+ | **C10** | call fidelity | Each answer is an actual answer of the original question, and every answer of each question is claimed |
440
440
 
441
441
  **The checker follows the certificate:** it never calls the reasoner, so a missing step fails rather than being quietly re-derived. **The source is the authority:** clauses a proof displays cannot override the program. Proofs are read as data, so checking someone else's proof runs none of their code, and every proof eyemind generates is checked before it is returned. The report is a document too:
442
442
 
@@ -456,7 +456,7 @@ condition('C6', 'boundary_consistency', 'ok', 0)
456
456
  condition('C7', 'relevance', 'ok', 5)
457
457
  condition('C8', 'witness_integrity', 'ok', 0)
458
458
  condition('C9', 'search_closure', 'ok', 0)
459
- condition('C10', 'call_fidelity', 'ok', 2)
459
+ condition('C10', 'call_fidelity', 'ok', 3)
460
460
 
461
461
  // Proof statistics: recorded steps and how they were checked.
462
462
  steps(3)
@@ -466,11 +466,11 @@ composed(0)
466
466
  trusted(0)
467
467
  claims(2)
468
468
 
469
- // This verdict applies to the claims above; it does not establish completeness.
469
+ // This verdict also establishes that the claims above are every answer of the original questions.
470
470
  verdict('checked')
471
471
  ```
472
472
 
473
- 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`; `--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.
473
+ 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.
474
474
 
475
475
  ### Why negation and collection are safe
476
476
 
@@ -480,7 +480,7 @@ A negation `not(G)` concludes from what is *absent* and a collection `findall(T,
480
480
  - **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".
481
481
  - **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.
482
482
  - **Say what was taken on trust.** Anything the certificate cannot settle becomes an obligation, and evidence in the proof can still refute it (C6).
483
- - **Certify relational negation.** Supported, closed listings can establish the original calls of ground relational rules with bound negations, including inside conjunctions and disjunctions. A proof within this fragment can be `checked` with no obligation, even under `--strict-proof`. Collections of derived facts, whose order a listing cannot show, and dependencies on `restricted` rules with new witnesses keep an obligation.
483
+ - **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`. Collections and first answers over derived facts, whose order a listing cannot show, templates and `restricted` rules with new witnesses keep an obligation.
484
484
 
485
485
  ## Checking the translation
486
486
 
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.21
5
+ Version: eyemind 0.5.23
6
6
  ```
7
7
 
8
8
  This document specifies the syntax and meaning of eyemind programs and data
@@ -216,12 +216,16 @@ Proofs:
216
216
  certificate and checked by C10 ([Section 10.5](#105-call-fidelity-certificates)).
217
217
  - **Original question**: each external goal; without external goals, the
218
218
  body of each query; without queries, each ordinary forward head. C10
219
- checks the claims answering them ([Section 11.13](#1113-c10-call-fidelity)).
219
+ checks that the claims are exactly their answers ([Section 11.13](#1113-c10-call-fidelity)).
220
+ - **Answer completeness**: of a proof, that its claims include every answer
221
+ of every original question; an unconditional `checked` verdict
222
+ establishes it ([Section 11.1](#111-scope-of-a-valid-proof)).
220
223
  - **Settled**: established by its search certificate, as a boundary is when
221
224
  C9 accepts that certificate ([Section 11.12](#1112-c9-search-closure)).
222
225
  - **Trusted boundary**: a boundary that is not settled. A valid proof
223
226
  assumes it, and its check report lists it as an **obligation**, as it
224
- lists each claim whose call fidelity remains unproved (Sections [11.9](#119-c6-boundary-consistency),
227
+ lists each claim whose call fidelity and each question whose answer
228
+ completeness remains unproved (Sections [11.9](#119-c6-boundary-consistency),
225
229
  [11.13](#1113-c10-call-fidelity) and [12](#12-check-reports)).
226
230
  - **Check report**: what a checker writes: the claims, the outcome of each
227
231
  of C1–C10, failures, obligations, counts and a verdict ([Section 12](#12-check-reports)).
@@ -1090,8 +1094,10 @@ infinite closure. A finite model does not ensure search termination:
1090
1094
  `implied_by(p(X), p(X))` has an empty least model, but searching `p('a')`
1091
1095
  recurs indefinitely. Exceeding a resource bound raises an error ([Section
1092
1096
  8.3](#83-resource-bounds)). Contradictions halt without completing the closure ([Section 8.5](#85-contradictions)).
1093
- A valid proof establishes only its claims subject to its trusted boundaries
1094
- ([Section 11.1](#111-scope-of-a-valid-proof)), not completeness of the model or the answers. Its search
1097
+ A valid proof establishes its claims subject to its obligations and, when
1098
+ it checks without obligations, that they are every answer of the original
1099
+ questions ([Section 11.1](#111-scope-of-a-valid-proof)); it does not
1100
+ establish termination of the whole program. Its search
1095
1101
  certificate settles the negations and collections it can ([Section 10.4](#104-search-certificates)).
1096
1102
 
1097
1103
  ## 8. Evaluation and Conclusions
@@ -1288,8 +1294,8 @@ would extend: the run stopped before its fixpoint, so its derived facts need
1288
1294
  not be closed under the rules. A
1289
1295
  reasoner MUST check every proof it generates ([Section 11](#11-proof-checking)) before returning it,
1290
1296
  and MUST fail with an error rather than return a proof that does not pass. A
1291
- run without conclusions has a proof without claims, which is valid and
1292
- certifies nothing.
1297
+ run without conclusions has a proof without claims; its call tables, when
1298
+ they settle, certify that the original questions have no answers.
1293
1299
 
1294
1300
  A **state test** is `is_var/1`, `not_identical/2` or `compare/3`: a test a
1295
1301
  later binding can make false. A goal such as `is_var(X)` followed by
@@ -1620,7 +1626,7 @@ The ten conditions answer different questions:
1620
1626
  | [C7 Relevance](#1110-c7-relevance) | Does the evidence serve the claimed answers to the program's questions? |
1621
1627
  | [C8 Witness integrity](#1111-c8-witness-integrity) | Does each existential witness identify the correct rule firing? |
1622
1628
  | [C9 Search closure](#1112-c9-search-closure) | Does the certificate establish the recorded negation or collection? |
1623
- | [C10 Call fidelity](#1113-c10-call-fidelity) | Can the original question return this answer? |
1629
+ | [C10 Call fidelity](#1113-c10-call-fidelity) | Can the original question return this answer, and is each of its answers claimed? |
1624
1630
 
1625
1631
  C9 checks the search behind a recorded step; C10 checks the original call
1626
1632
  before the proof's final bindings. This distinction matters for negation,
@@ -1639,9 +1645,10 @@ can instead leave an obligation. The verdict distinguishes these outcomes:
1639
1645
  | `checked_with_obligations` | No condition failed, but the claims depend on the reported obligations. |
1640
1646
  | `failed(N)` | The checker recorded `N` failures. |
1641
1647
 
1642
- Strict checking forbids unresolved obligations. Even `checked` establishes
1643
- only the claimed answers, not that the proof contains every answer or that
1644
- the whole program terminates ([Section 11.1](#111-scope-of-a-valid-proof)).
1648
+ Strict checking forbids unresolved obligations. A `checked` verdict
1649
+ establishes the claimed answers and that they are every answer of the
1650
+ original questions, but not that the whole program terminates
1651
+ ([Section 11.1](#111-scope-of-a-valid-proof)).
1645
1652
 
1646
1653
  ### 11.1 Scope of a valid proof
1647
1654
 
@@ -1649,7 +1656,10 @@ A valid proof establishes that each claim follows from the source program
1649
1656
  by the recorded steps, conditional on any reported obligations. A settled
1650
1657
  boundary is established by its search certificate. An unconditional
1651
1658
  `checked` verdict also establishes operational query fidelity
1652
- ([Section 11.2](#112-operational-query-fidelity)).
1659
+ ([Section 11.2](#112-operational-query-fidelity)) and **answer
1660
+ completeness**: the claims include every answer of every original question
1661
+ ([Section 11.13](#1113-c10-call-fidelity)). Every question asked has a
1662
+ certified answer set, and every answer in it is claimed.
1653
1663
 
1654
1664
  For a program with negation, "follows" is relative to the facts the
1655
1665
  certificate lists: C9 establishes that they are supported by steps, closed
@@ -1663,14 +1673,16 @@ rejects it. Independent claims may still check strictly.
1663
1673
 
1664
1674
  It does not establish:
1665
1675
 
1666
- - that the proof contains all conclusions of the program;
1676
+ - answer completeness for a halted proof, whose claims contain `'false'`;
1667
1677
  - that the program derives no `'false'`;
1668
1678
  - that execution of the whole program terminates or reaches every question;
1669
1679
  - that the supplied program expresses the author's intended model.
1670
1680
 
1671
- A proof MAY omit conclusions. A run's own proof contains exactly that
1672
- run's conclusions. An empty proof establishes no answers, including no
1673
- claim that a question has no answers.
1681
+ A run's own proof contains exactly that run's conclusions. A proof that
1682
+ omits an answer its certificate establishes fails C10. One without the
1683
+ certificate to show its answers complete is valid only conditionally: an
1684
+ empty proof establishes no answers and leaves each original question whose
1685
+ answers need a call table as an obligation.
1674
1686
 
1675
1687
  ### 11.2 Operational query fidelity
1676
1688
 
@@ -1722,8 +1734,9 @@ MUST NOT invoke the reasoner to fill gaps.
1722
1734
 
1723
1735
  C10 supplies this certificate check in [Section 11.13](#1113-c10-call-fidelity).
1724
1736
  A C1–C9 verdict alone MUST NOT be presented as establishing operational
1725
- query fidelity. Fidelity does not establish completeness, avoidance of an
1726
- earlier contradiction, or termination of preceding questions.
1737
+ query fidelity. Fidelity alone does not establish answer completeness,
1738
+ which C10 checks separately, avoidance of an earlier contradiction, or
1739
+ termination of preceding questions.
1727
1740
 
1728
1741
  ### 11.3 Reading the document
1729
1742
 
@@ -1815,8 +1828,9 @@ C4 checks that the proof has no missing premises:
1815
1828
  as premises, but claims still require steps.
1816
1829
 
1817
1830
  For a missing use, the failure's conclusion is the goal of the step that
1818
- uses it. A document without claims certifies nothing; it is valid if no
1819
- condition fails.
1831
+ uses it. A document without claims establishes no answers; it is valid if
1832
+ no condition fails, and C10 decides whether it shows that the original
1833
+ questions have none.
1820
1834
 
1821
1835
  ### 11.8 C5 Re-decision
1822
1836
 
@@ -2127,13 +2141,13 @@ obligation rather than an unconditional `checked` verdict.
2127
2141
  Otherwise, if any forward rule has a head `'true'`, use those rules' bodies
2128
2142
  as conjunctions. Otherwise use the ordinary forward heads, excluding
2129
2143
  `'false'`. Do not instantiate these questions with the proof's final
2130
- bindings. Only questions of which a claim is an instance need a
2131
- certificate.
2144
+ bindings. Every question needs a certificate, including one of which no
2145
+ claim is an instance: its answers must still be shown to be claimed.
2132
2146
 
2133
2147
  When the claims contain `'false'`, C10 is inapplicable: it covers no
2134
2148
  answers and adds no call-fidelity obligations for that halted proof.
2135
- Empty proofs certify no answers and do not establish that a question has
2136
- none.
2149
+ A proof without claims certifies that a question has no answers only
2150
+ through that question's certificate.
2137
2151
 
2138
2152
  **Checking calls.** For each relevant original question, use the one-level
2139
2153
  expansion and closure checks of [Section 11.12](#1112-c9-search-closure),
@@ -2174,36 +2188,117 @@ first, and `once` selects it. Thus `q('a')` is an answer and `q('b')` is
2174
2188
  excluded. Substituting `called(p('b'), [p('b')])` cannot establish the
2175
2189
  different call `p(X)`.
2176
2190
 
2177
- **Supported forward listings.** A forward listing's **ground dependency
2178
- closure** contains its relation and each ordinary body relation, inside a
2179
- negation or not, of every source fact, backward rule or forward rule
2180
- defining any relation in that closure. To use a listing for C10:
2181
-
2182
- - All source facts in the closure MUST be ground.
2183
- - Rule bodies MUST contain only ordinary calls, `'true'`, conjunction,
2184
- disjunction and negations of these. Templates, captures and source
2185
- inspection are excluded.
2191
+ **Supported forward listings.** A listing supports C10 when a search of
2192
+ each rule body it depends on, in source order, finds exactly the ground
2193
+ instances of that body that hold. Its steps, whose primitives C5 re-decides
2194
+ on their ground instances, then show firings that a search makes. This holds
2195
+ when no goal can observe the bindings or the order in which it runs. The
2196
+ checker establishes it by a **mode analysis** of the rules the listing
2197
+ depends on. A **mode** of a call gives, for each argument, whether it is
2198
+ ground when the call runs: an argument is ground when every variable in it
2199
+ is **grounded** at that point.
2200
+
2201
+ The analysis starts from the listed relation and its forward rules, and
2202
+ follows each ordinary body call, inside a negation or not, to the called
2203
+ relation in the mode of that call: its forward rules once, and its backward
2204
+ rules once in each mode. A forward rule's body starts with no grounded
2205
+ variable. A backward rule's body starts with the variables of the head
2206
+ arguments that are ground in the mode. Body goals are taken in order, each
2207
+ with the variables grounded before it:
2208
+
2209
+ - `'true'` grounds nothing. Conjunction accumulates the grounded variables
2210
+ of its parts. Disjunction grounds only those grounded by both
2211
+ alternatives. `call(G)` is `G`.
2212
+ - A call to an ordinary relation grounds its variables when every source
2213
+ fact of the relation is ground once the arguments ground in the mode are
2214
+ unified with it, and the relation is not **loose** in that mode;
2215
+ otherwise it grounds nothing.
2186
2216
  - A negation grounds nothing. Each of its variables other than anonymous
2187
- ones MUST be grounded by the body goals before it, and it MUST NOT contain
2188
- a negation.
2189
- - A body call to an ordinary relation grounds its variables. Conjunction
2190
- accumulates the grounded variables of its parts; disjunction grounds only
2191
- those grounded by both alternatives.
2192
- - Every backward head variable MUST be grounded by its body.
2193
- - Every forward head variable MUST either be grounded by its body or be a
2194
- head-only witness checked by C8.
2195
- - A restricted rule's guard is a negation, so a closure with a restricted
2196
- rule that has head-only variables is not supported: which firings a
2197
- restricted rule makes can depend on the order of rule applications.
2217
+ ones MUST be grounded before it, and it MUST NOT contain a negation.
2218
+ - `once(G)` grounds nothing. `G` MUST satisfy these conditions. Each named
2219
+ variable of `G` that occurs elsewhere in the clause MUST be grounded before
2220
+ it, so the choice of a first answer binds nothing another goal uses.
2221
+ - `findall(T, G, L)` follows the same rule for `T` and `G`. It grounds the
2222
+ variables of `L` when `G` grounds every variable of `T`.
2223
+ - A primitive whose variables are all grounded before it is a test, and
2224
+ grounds nothing. `unify/2` with one side ground grounds the other, and
2225
+ with neither ground grounds nothing. Otherwise the primitive MUST be
2226
+ called in one of the modes below, its input arguments ground, and it
2227
+ grounds its variables.
2228
+ - Source inspection, templates, captures and restricted rules are not
2229
+ supported. A restricted rule's guard is a negation, but which firings the
2230
+ rule makes can depend on the order of rule applications.
2231
+
2232
+ After its body, every head variable of a forward rule MUST be grounded or
2233
+ be a head-only witness checked by C8. If a head variable of a backward rule
2234
+ is not grounded, the relation is loose in that mode, and the analysis
2235
+ starts again with that call grounding nothing.
2236
+
2237
+ | Primitive | Inputs → outputs |
2238
+ | --- | --- |
2239
+ | `is/2` | expression → result |
2240
+ | `compare/3` | both compared terms → order |
2241
+ | `atom_chars/2`, `atom_codes/2` | atom → list, or list → atom |
2242
+ | `number_chars/2` | list → number |
2243
+ | `atom_length/2`, `atom_lower/2`, `atom_upper/2`, `term_text/2` | first → second |
2244
+ | `atom_concat/3` | both parts → whole, or whole → both parts |
2245
+ | `regex_find/3`, `digest/3` | first two → third |
2246
+ | `float64/4` | first three → fourth |
2247
+
2248
+ In each listed mode, a call with ground inputs has exactly the solutions
2249
+ whose ground instances C5 re-decides as holding. `number_chars/2` re-decides
2250
+ a ground instance by reading its characters, so only that direction is
2251
+ listed. A host-math result accepted by C5 only within its tolerance
2252
+ ([Section 11.8](#118-c5-re-decision)) need not be the result a search
2253
+ finds. A proof with such a step therefore supports no listing for C10 by
2254
+ this analysis.
2255
+
2256
+ **Replayed listings.** A listing the mode analysis does not support still
2257
+ supports C10 when every fact of every consulted listing **replays**. A fact
2258
+ replays when its step cites a forward rule, other than a template, a rule
2259
+ with captures or a restricted rule, and a search of that rule's body in
2260
+ source order, starting with no bindings, solves each body goal as the
2261
+ step's corresponding use records:
2262
+
2263
+ - A primitive runs on the bindings of that point of the search. Its first
2264
+ solution under which the goal can still unify with the use is taken.
2265
+ `compare/3` with a nonground compared term does not replay.
2266
+ - `once/1`, `not/1` and `findall/3` take the answers of the goal, as it
2267
+ stands at that point, from the call tables and listings, as in checking
2268
+ the original calls. A negation with an unbound named variable does not
2269
+ replay, and neither does a first answer or a collection whose order rests
2270
+ on a listing. The first answer is taken, and the goal MUST still unify
2271
+ with the use.
2272
+ - `call/1` and a disjunction replay the goals their `'control'` step uses,
2273
+ for a disjunction from the side those uses form.
2274
+ - A call to an ordinary relation follows the use's step. A forward rule's
2275
+ conclusion MUST itself replay, and is then unified with the goal. A
2276
+ source fact, renamed apart, is unified with the goal. A backward rule,
2277
+ renamed apart, has its head unified with the goal and its body replayed
2278
+ against its step's uses. A use with no step is unified with a source fact
2279
+ of the relation, renamed apart. A replay that meets the same use under
2280
+ the same call again does not replay.
2281
+ - After each goal, the goal MUST still unify with its use, since a step
2282
+ shows its goals after the whole solution's bindings.
2283
+
2284
+ Each witness is then bound to its Skolem term
2285
+ ([Section 8.2](#82-forward-evaluation-and-witnesses)), and the fact MUST be
2286
+ identical to an instance of one of the rule's heads. Replay re-executes each
2287
+ recorded firing, so a test of whether a variable is bound sees what a search
2288
+ sees, a first answer is the search's first answer, and host math is
2289
+ computed rather than accepted within a tolerance. C2 keeps the steps a
2290
+ replay follows acyclic.
2198
2291
 
2199
2292
  Supported facts and closed listings then establish the least ground
2200
- positive closure and, with negations, a set of facts that is supported,
2201
- closed under the rules and consistent with each negation, every negation
2202
- being decided by the listed facts alone. A stratified or chain-stratified
2203
- program has exactly one such set ([Section 7.4](#74-negation-and-collection)), its result, so the
2204
- listings are the facts the original calls consult. More general forward
2205
- execution requires publication evidence this format does not supply,
2206
- leaving call fidelity unproved.
2293
+ closure and, with negations, a set of facts that is supported, closed under
2294
+ the rules and consistent with each negation, every negation being decided
2295
+ by the listed facts alone. A stratified or chain-stratified program has
2296
+ exactly one such set ([Section 7.4](#74-negation-and-collection)), its
2297
+ result, so the listings are the facts the original calls consult. A
2298
+ collection or first answer over facts that forward rules derive depends on
2299
+ their publication order, which this format does not establish, and a
2300
+ restricted rule's firings can depend on the order of rule applications:
2301
+ both leave call fidelity unproved.
2207
2302
 
2208
2303
  **Deciding claims.** Every relevant call certificate MUST be valid. Each
2209
2304
  claim MUST be identical, up to variable renaming, to an answer of at least
@@ -2227,6 +2322,30 @@ forbidden, each such obligation fails C10. C10 does not discharge C6/C9
2227
2322
  obligations: both the recorded boundary and the original call need their
2228
2323
  respective evidence.
2229
2324
 
2325
+ **Answer completeness.** A valid certificate for an original question
2326
+ gives all of its answers, so C10 also checks the converse: each answer is
2327
+ claimed. The **required answers** of a question are its certificate's
2328
+ answers when the conclusions answer goals or `query()` rules. When the
2329
+ conclusions are the derived facts ([Section 8.6](#86-reported-conclusions)),
2330
+ they are the facts of the question's relation in its consulted listing
2331
+ that are instances of the question, since a source fact or a backward
2332
+ answer is no derived fact. For each original question, in question order:
2333
+
2334
+ | Evidence for the question | C10 result |
2335
+ | --- | --- |
2336
+ | Its certificate is false. | Fail the question once, unless a claim that is an instance of it already failed for that certificate. |
2337
+ | Its certificate is valid and complete, and every required answer is identical, up to renaming, to a claim. | Establish answer completeness for the question. |
2338
+ | Its certificate is valid and complete, and a required answer is not claimed. | Fail once for each required answer not claimed. |
2339
+ | Its certificate is missing, incomplete or unsupported. | Leave `obligation('call_fidelity', 'all_answers', Question)`. |
2340
+
2341
+ For example, with `fact(p('a'), p('b'))` and `query(p(X))`, a proof that
2342
+ claims only `p('a')` fails C10 for `p('b')`, though `p('a')` follows. With
2343
+ `implied_by(r(X), p(X))` and `query(r('c'))`, the proof without claims
2344
+ holding `called(r('c'), [])` establishes that the question has no answers;
2345
+ an empty document leaves `r('c')` as an obligation. A question answered
2346
+ from source facts alone needs no table, so its required answers come from
2347
+ the facts.
2348
+
2230
2349
  **Limits and production of certificates.** The current format requires
2231
2350
  complete tables, even for a relation called under `once`. Later recursion
2232
2351
  or an error may prevent a table from closing although `once` itself
@@ -2245,13 +2364,14 @@ units of answer text.
2245
2364
  **Relevance and counts.** Call tables and their supporting listings serve
2246
2365
  the claims for C7; their listed facts are reachable through that evidence.
2247
2366
  C10 does not change C1–C9 covered counts. Its own covered count includes
2248
- claims whose call fidelity is established or refuted, excluding unresolved
2249
- claims. Report failures in claim order, after checking boundaries and
2250
- before C7 and C2 ([Section 12](#12-check-reports)).
2367
+ claims whose call fidelity is established or refuted and questions whose
2368
+ answer completeness is established or refuted, excluding unresolved ones.
2369
+ Report failures in claim order, then in question order, after checking
2370
+ boundaries and before C7 and C2 ([Section 12](#12-check-reports)).
2251
2371
 
2252
- These checks establish membership of claimed answers in an original
2253
- question's results. They do not establish that all answers were claimed
2254
- or that preceding distinct questions terminated.
2372
+ These checks establish that the claims are exactly the answers of the
2373
+ original questions, up to renaming. They do not establish that preceding
2374
+ distinct questions terminated.
2255
2375
 
2256
2376
  ### 11.14 Counts and validity
2257
2377
 
@@ -2270,7 +2390,7 @@ negation, collection or original call that remains an obligation.
2270
2390
  | C7 relevance | claims plus steps |
2271
2391
  | C8 witness_integrity | `clause` steps with witnesses in their forward head or enclosing generators that passed C8 |
2272
2392
  | C9 search_closure | boundaries their search certificate settled or refuted |
2273
- | C10 call_fidelity | claims whose call fidelity is established or refuted |
2393
+ | C10 call_fidelity | claims whose call fidelity, and questions whose answer completeness, is established or refuted |
2274
2394
 
2275
2395
  A check also records these totals:
2276
2396
 
@@ -2280,7 +2400,8 @@ A check also records these totals:
2280
2400
  - **recomputed**: the `'builtin'` and `called(Called)` steps that passed C5;
2281
2401
  - **composed**: the `'control'` steps that passed C5;
2282
2402
  - **trusted**: the `'absent'` and `'collected'` steps C9 did not settle,
2283
- plus each claim whose call fidelity remains unproved by C10.
2403
+ plus each claim whose call fidelity and each question whose answer
2404
+ completeness remains unproved by C10.
2284
2405
 
2285
2406
  A proof is **valid** when no condition failed. It is valid *conditional on*
2286
2407
  any obligations that remain. Section [12](#12-check-reports) specifies the
@@ -2299,7 +2420,8 @@ the following report facts, one per line:
2299
2420
  3. `obligation(Kind, 'theory_scoped', Goal)` per trusted boundary, in step
2300
2421
  order, where `Kind` is `'absent'` or `'collected'`, followed by
2301
2422
  `obligation('call_fidelity', 'original_call', Claim)` per unresolved claim,
2302
- in claim order;
2423
+ in claim order, then `obligation('call_fidelity', 'all_answers', Question)`
2424
+ per question whose answer completeness is unresolved, in question order;
2303
2425
  4. `steps(N)`, `verified(N)`, `recomputed(N)`, `composed(N)`, `trusted(N)`,
2304
2426
  `claims(N)`, the counts of [Section 11.14](#1114-counts-and-validity);
2305
2427
  5. `verdict(V)`, where `V` is `failed(N)` when `N` failures were recorded,
@@ -2310,9 +2432,11 @@ Comments MUST identify these initial terms as checked answers only when the
2310
2432
  report is valid with no obligations. A valid report with obligations MUST
2311
2433
  label them as conditional on those obligations. A failed report MUST label
2312
2434
  them as unverified claims; their inclusion does not validate them. A valid
2313
- report with no claims MUST say it establishes no conclusions. Comments also
2314
- explain the C1-C10 order, failures and obligations when present, the statistics,
2315
- and that the verdict does not establish completeness. Comments are informative
2435
+ report with no claims MUST say it establishes no conclusions, unless it is
2436
+ valid with no obligations: it then establishes that the original questions
2437
+ have no answers. Comments also explain the C1-C10 order, failures and
2438
+ obligations when present, the statistics, and whether the verdict
2439
+ establishes that the claims are every answer. Comments are informative
2316
2440
  and MAY be worded differently. They are ignored when the document is read.
2317
2441
 
2318
2442
  Failures are listed in the order they are found: those of reading the
@@ -2320,7 +2444,7 @@ document ([Section 11.3](#113-reading-the-document)), in document order; C4 for
2320
2444
  order; then for each step, in document order, C4 for its uses and the C1, C3,
2321
2445
  C5 or C8 failure of its justification; for each boundary, in step order, the
2322
2446
  C9 failures of its search certificate in the order found, or else its C6
2323
- failure; C10 for each claim; C7 for each claim, then
2447
+ failure; C10 for each claim, then for each question; C7 for each claim, then
2324
2448
  for each step, then for each table and listing, in document order; and C2.
2325
2449
 
2326
2450
  `Detail` is informative text identifying what failed; its wording is not
@@ -2338,7 +2462,8 @@ texts, including unverified claims when `valid` is false. It also has `valid` (b
2338
2462
  `claims`, `verified`, `redecided` (the count `recomputed`), `composed`,
2339
2463
  `uses` (the number of uses of all steps, integers), `trusted`
2340
2464
  (a list of `{kind, conclusion, reason?}`, with `reason: 'original_call'`
2341
- for call-fidelity obligations), `failures` (a list of
2465
+ for a claim's call-fidelity obligation and `reason: 'all_answers'` for a
2466
+ question's answer-completeness obligation), `failures` (a list of
2342
2467
  `{condition, detail, conclusion?}`) and `conditions` (a list of
2343
2468
  `{id, name, covered, failed}`), where `conclusion` is a canonical text.
2344
2469
  Its variables keep the names the document gives them, rather than being
@@ -2679,7 +2804,7 @@ condition('C6', 'boundary_consistency', 'ok', 0)
2679
2804
  condition('C7', 'relevance', 'ok', 5)
2680
2805
  condition('C8', 'witness_integrity', 'ok', 0)
2681
2806
  condition('C9', 'search_closure', 'ok', 0)
2682
- condition('C10', 'call_fidelity', 'ok', 2)
2807
+ condition('C10', 'call_fidelity', 'ok', 3)
2683
2808
 
2684
2809
  // Proof statistics: recorded steps and how they were checked.
2685
2810
  steps(3)
@@ -2689,6 +2814,6 @@ composed(0)
2689
2814
  trusted(0)
2690
2815
  claims(2)
2691
2816
 
2692
- // This verdict applies to the claims above; it does not establish completeness.
2817
+ // This verdict also establishes that the claims above are every answer of the original questions.
2693
2818
  verdict('checked')
2694
2819
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eyemind",
3
- "version": "0.5.21",
3
+ "version": "0.5.23",
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/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 } from './fidelity.js';
6
+ import { callQuestions, positiveListings, 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';
@@ -1130,7 +1130,6 @@ function certify(solver, boundaries, operational = false) {
1130
1130
  }
1131
1131
  },
1132
1132
  facts(goalKey) {
1133
- if (operational && !positiveListings(program, [goalKey])) throw new Unsettled();
1134
1133
  const nodes = solver.facts.get(goalKey) || NO_NODES;
1135
1134
  if (nodes.some((node) => node.generic)) throw new Unsettled();
1136
1135
  listed.set(goalKey, nodes);
@@ -1156,9 +1155,27 @@ function certify(solver, boundaries, operational = false) {
1156
1155
  }
1157
1156
  }
1158
1157
  }
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.
1160
+ let recorded = null;
1161
+ const stepOf = (goal) => {
1162
+ if (recorded === null) {
1163
+ recorded = new Map();
1164
+ const pending = [...listed.values()].flat();
1165
+ while (pending.length) {
1166
+ const node = pending.pop();
1167
+ const goalText = text(node.goal);
1168
+ if (recorded.has(goalText)) continue;
1169
+ recorded.set(goalText, { by: node.by, uses: node.children.map((child) => child.goal) });
1170
+ pending.push(...node.children);
1171
+ }
1172
+ }
1173
+ return recorded.get(text(goal));
1174
+ };
1159
1175
  const tables = new Set();
1160
1176
  const listings = new Set();
1161
1177
  for (const boundary of boundaries) {
1178
+ recorded = null;
1162
1179
  let outcome = null;
1163
1180
  budget = 0;
1164
1181
  volume = 0;
@@ -1175,7 +1192,8 @@ function certify(solver, boundaries, operational = false) {
1175
1192
  }
1176
1193
  }
1177
1194
  }
1178
- if (outcome.status === 'settled' && (!operational || positiveListings(program, outcome.listings))) {
1195
+ if (outcome.status === 'settled' && (!operational || positiveListings(program, outcome.listings) ||
1196
+ replayed(program, settler, outcome.listings, stepOf))) {
1179
1197
  for (const item of outcome.tables) tables.add(item);
1180
1198
  for (const item of outcome.listings) listings.add(item);
1181
1199
  } else if (outcome.status === 'failed' && solver.haltCode === null) {
package/src/fidelity.js CHANGED
@@ -1,13 +1,16 @@
1
- // C10: answers of the original questions, checked from source call tables.
2
- // Unlike logical steps, these searches start before a final substitution.
3
- import { PRIMITIVE_KEYS } from './builtins.js';
1
+ // C10: answers of the original questions, checked from source call tables:
2
+ // each claim is an answer, and each answer is claimed. Unlike logical steps,
3
+ // these searches start before a final substitution.
4
+ import { PRIMITIVE_KEYS, primitive } from './builtins.js';
4
5
  import { Settler } from './closure.js';
5
- import { text, variant } from './common.js';
6
+ import { freshClause, text, variant } from './common.js';
6
7
  import { goalTerm } from './goals.js';
7
8
  import { INSPECTION_KEYS } from './inspection.js';
8
9
  import {
9
- Env, conjunction, copyResolved, freshTerm, isAnonymous, isCallable, isGround, isTerm, key, unify, variables,
10
+ Env, EyemindError, Struct, Var, conjunction, copyResolved, deref, flattenConjunction, freshTerm, identity, isAnonymous, isCallable,
11
+ isGround, isTerm, key, listFromItems, unify, variables,
10
12
  } from './terms.js';
13
+ import { Lettering, write } from './writer.js';
11
14
 
12
15
  function instance(goal, pattern) {
13
16
  const renamed = freshTerm(pattern, 'callQuestion');
@@ -16,6 +19,7 @@ function instance(goal, pattern) {
16
19
  }
17
20
 
18
21
  // The original questions of Section 8.6, without specializing them to claims.
22
+ // A halted run answers none of them.
19
23
  export function callQuestions(program, goals, claims) {
20
24
  if (claims.includes('false')) return [];
21
25
  let questions = (goals || []).map(goalTerm);
@@ -28,22 +32,96 @@ export function callQuestions(program, goals, claims) {
28
32
  const seen = new Set();
29
33
  return questions.filter((question) => {
30
34
  const id = variant(question, true);
31
- if (seen.has(id) || !claims.some((claim) => instance(claim, question))) return false;
35
+ if (seen.has(id)) return false;
32
36
  seen.add(id);
33
37
  return true;
34
38
  });
35
39
  }
36
40
 
37
- // C9's support plus closure establishes the least ground positive model,
38
- // and with negations the one stable model of a stratified or
39
- // chain-stratified program: a negation whose named variables earlier goals
40
- // bind is decided by the listed facts alone. For forward rules that observe
41
- // bindings or order, and for restricted rules, whose guard another order of
42
- // firings could decide otherwise, a final listing alone does not establish
43
- // which firings occurred. Refuse that stronger promise.
41
+ // Primitives that compute their outputs from ground inputs, in each mode an
42
+ // argument's positions of the inputs, then of the outputs. With its inputs
43
+ // ground such a call has exactly the solutions whose ground instances hold,
44
+ // re-decided as C5 re-decides them, so a search finds what C5 accepts.
45
+ // number_chars/2 re-decides by reading its characters, so only that mode.
46
+ const MODES = new Map([
47
+ ['is/2', [[[1], [0]]]],
48
+ ['compare/3', [[[1, 2], [0]]]],
49
+ ['atom_chars/2', [[[0], [1]], [[1], [0]]]],
50
+ ['atom_codes/2', [[[0], [1]], [[1], [0]]]],
51
+ ['number_chars/2', [[[1], [0]]]],
52
+ ['atom_length/2', [[[0], [1]]]],
53
+ ['atom_lower/2', [[[0], [1]]]],
54
+ ['atom_upper/2', [[[0], [1]]]],
55
+ ['atom_concat/3', [[[0, 1], [2]], [[2], [0, 1]]]],
56
+ ['regex_find/3', [[[0, 1], [2]]]],
57
+ ['digest/3', [[[0, 1], [2]]]],
58
+ ['term_text/2', [[[0], [1]]]],
59
+ ['float64/4', [[[0, 1, 2], [3]]]],
60
+ ]);
61
+
62
+ // The variables of a head's arguments that a call in mode grounds.
63
+ function inputs(head, mode) {
64
+ const names = new Set();
65
+ if (head instanceof Struct) {
66
+ head.args.forEach((arg, i) => {
67
+ if (mode[i] === 'g') for (const name of variables(arg).keys()) names.add(name);
68
+ });
69
+ }
70
+ return names;
71
+ }
72
+
73
+ // How often each variable occurs in term, by name.
74
+ function occurrences(term, counts = new Map()) {
75
+ const pending = [term];
76
+ while (pending.length) {
77
+ const item = pending.pop();
78
+ if (item instanceof Struct) pending.push(...item.args);
79
+ else if (item instanceof Var) counts.set(item.name, (counts.get(item.name) || 0) + 1);
80
+ }
81
+ return counts;
82
+ }
83
+
84
+ // C9's support plus closure establishes the least ground model, and with
85
+ // negations the one stable model of a stratified or chain-stratified
86
+ // program, when a search of each rule body in source order finds exactly the
87
+ // ground instances that hold: then the steps that support a listed fact,
88
+ // re-decided on their ground instances, show a firing a search makes. That
89
+ // holds when no goal observes bindings: each primitive runs with its inputs
90
+ // ground, each negation with its named variables ground, and once/1 and
91
+ // findall/3 bind nothing other goals use. A backward rule is analyzed for
92
+ // each mode it is called in, the head arguments a call grounds being ground
93
+ // on entry, and must ground the rest of its head. A relation with a
94
+ // nonground source fact grounds nothing. Rules that observe bindings or
95
+ // order, templates, and restricted rules, whose guard another order of
96
+ // firings could decide otherwise, leave which firings occurred
97
+ // unestablished: refuse that promise.
44
98
  export function positiveListings(program, listings) {
45
- const pending = [...listings];
99
+ // Calls, by relation and mode, found to answer with nonground terms; the
100
+ // analysis starts again whenever it finds another, assuming fewer grounded.
101
+ const loose = new Set();
102
+ for (;;) {
103
+ const result = groundedListings(program, listings, loose);
104
+ if (result !== 'again') return result;
105
+ }
106
+ }
107
+
108
+ function groundedListings(program, listings, loose) {
109
+ // A listed relation and the forward rules concluding it, or a called
110
+ // relation and its mode: 'g' for each argument ground at the call, else 'f'.
111
+ const pending = listings.map((goalKey) => [goalKey, null]);
46
112
  const seen = new Set();
113
+ // Whether every source fact of a relation is ground once a call in this
114
+ // mode has unified it: only then does the call ground its arguments.
115
+ const groundsFacts = (goalKey, mode) => !loose.has(`${goalKey} ${mode}`) &&
116
+ (program.groups.get(goalKey) || []).every((clause) => clause.body.length ||
117
+ [...variables(clause.head).keys()].every((name) => inputs(clause.head, mode).has(name)));
118
+ let outside = null;
119
+ // The variables of goal used elsewhere in the clause, other than in goal.
120
+ const shared = (goal) => {
121
+ const inside = occurrences(goal);
122
+ return [...variables(goal)].filter(([name, variable]) => !isAnonymous(variable) && outside.get(name) > inside.get(name))
123
+ .map(([name]) => name);
124
+ };
47
125
  function bound(goal, grounded, negated = false) {
48
126
  if (goal === 'true') return grounded;
49
127
  if (isTerm(goal, 'and', 2) || isTerm(goal, 'or', 2)) {
@@ -61,49 +139,220 @@ export function positiveListings(program, listings) {
61
139
  }
62
140
  return bound(goal.args[0], grounded, true) === null ? null : grounded;
63
141
  }
142
+ if (isTerm(goal, 'call', 1)) return bound(goal.args[0], grounded, negated);
143
+ // A first answer or a collection binds nothing it shares, so which answer
144
+ // came first, or which bindings a later goal makes, cannot matter.
145
+ if (isTerm(goal, 'once', 1)) {
146
+ const inner = bound(goal.args[0], grounded, negated);
147
+ return inner === null || shared(goal).some((name) => !grounded.has(name)) ? null : grounded;
148
+ }
149
+ if (isTerm(goal, 'findall', 3)) {
150
+ const inner = bound(goal.args[1], grounded, negated);
151
+ const collected = new Struct('-', [goal.args[0], goal.args[1]]);
152
+ if (inner === null || shared(collected).some((name) => !grounded.has(name))) return null;
153
+ const items = [...variables(goal.args[0]).keys()].every((name) => inner.has(name));
154
+ return items ? new Set([...grounded, ...variables(goal.args[2]).keys()]) : grounded;
155
+ }
64
156
  if (!isCallable(goal)) return null;
65
157
  const goalKey = key(goal);
66
- if (PRIMITIVE_KEYS.has(goalKey) || INSPECTION_KEYS.has(goalKey) ||
67
- ['not/1', 'findall/3', 'once/1', 'call/1'].includes(goalKey)) return null;
68
- pending.push(goalKey);
69
- return new Set([...grounded, ...variables(goal).keys()]);
158
+ if (INSPECTION_KEYS.has(goalKey)) return null;
159
+ if (PRIMITIVE_KEYS.has(goalKey)) {
160
+ const free = (term) => [...variables(term).keys()].filter((name) => !grounded.has(name));
161
+ const args = goal instanceof Struct ? goal.args : [];
162
+ if (args.every((arg) => !free(arg).length)) return grounded;
163
+ if (goalKey === 'unify/2') {
164
+ // Unification is pure; a ground side grounds the other.
165
+ const [left, right] = args;
166
+ if (!free(left).length || !free(right).length) return new Set([...grounded, ...variables(goal).keys()]);
167
+ return grounded;
168
+ }
169
+ const modes = MODES.get(goalKey) || [];
170
+ if (!modes.some(([inputs]) => inputs.every((i) => !free(args[i]).length))) return null;
171
+ return new Set([...grounded, ...variables(goal).keys()]);
172
+ }
173
+ const args = goal instanceof Struct ? goal.args : [];
174
+ const mode = args.map((arg) => ([...variables(arg).keys()].every((name) => grounded.has(name)) ? 'g' : 'f')).join('');
175
+ pending.push([goalKey, mode]);
176
+ return groundsFacts(goalKey, mode) ? new Set([...grounded, ...variables(goal).keys()]) : grounded;
70
177
  }
71
178
  while (pending.length) {
72
- const goalKey = pending.pop();
73
- if (seen.has(goalKey)) continue;
74
- seen.add(goalKey);
75
- const clauses = [...(program.groups.get(goalKey) || []), ...program.forward.filter((clause) =>
76
- clause.plainHeads.some((head) => isCallable(head) && key(head) === goalKey))];
179
+ const [goalKey, mode] = pending.pop();
180
+ const clauses = [];
181
+ if (!seen.has(goalKey)) {
182
+ seen.add(goalKey);
183
+ clauses.push(...(program.groups.get(goalKey) || []).filter((clause) => !clause.body.length),
184
+ ...program.forward.filter((clause) => clause.plainHeads.some((head) => isCallable(head) && key(head) === goalKey)));
185
+ }
186
+ if (mode !== null && !seen.has(`${goalKey} ${mode}`)) {
187
+ seen.add(`${goalKey} ${mode}`);
188
+ clauses.push(...(program.groups.get(goalKey) || []).filter((clause) => clause.body.length));
189
+ }
77
190
  for (const clause of clauses) {
78
191
  if (clause.parentId !== null || clause.templates.length || clause.captures !== null || clause.guard !== null) return false;
79
- if (!clause.forward && !clause.body.length) {
80
- if (!isGround(clause.head)) return false;
81
- continue;
82
- }
83
- let grounded = new Set();
192
+ if (!clause.forward && !clause.body.length) continue;
193
+ outside = occurrences(new Struct('-', [clause.head, listFromItems(clause.body)]));
194
+ let grounded = clause.forward ? new Set() : inputs(clause.head, mode);
84
195
  for (const goal of clause.body) {
85
196
  grounded = bound(goal, grounded);
86
197
  if (grounded === null) return false;
87
198
  }
199
+ // A call in a mode whose facts stay nonground grounds nothing, so its
200
+ // rules need not ground their heads either.
201
+ if (!clause.forward && !groundsFacts(goalKey, mode)) continue;
88
202
  const witnesses = new Set(clause.forward ? clause.witnessNames : []);
89
203
  for (const name of variables(clause.head).keys()) {
90
- if (!grounded.has(name) && !witnesses.has(name)) return false;
204
+ if (grounded.has(name) || witnesses.has(name)) continue;
205
+ if (clause.forward) return false;
206
+ loose.add(`${goalKey} ${mode}`);
207
+ return 'again';
91
208
  }
92
209
  }
93
210
  }
94
211
  return true;
95
212
  }
96
213
 
97
- export function checkCalls(program, claims, goals, certificate, steps, spellings, fail, allowTrusted, name) {
214
+ // Whether each fact of these listings is the conclusion of a firing that a
215
+ // search makes, replaying in source order the derivation its steps record.
216
+ // Primitives run on the bindings of that point of the search, so a test of
217
+ // whether a variable is bound sees what the search saw. A relation call
218
+ // follows its use's own step, which C2 keeps acyclic; a listed use is
219
+ // replayed in turn. once/1, not/1 and findall/3 are decided by the call
220
+ // tables, through Settler.answers, which refuses an order resting on a
221
+ // listing. A use is compared with what its goal can still become, since steps
222
+ // show goals after the whole solution's bindings. stepOf(goal) gives the
223
+ // recorded justification and uses of a goal, or nothing.
224
+ export function replayed(program, settler, listingKeys, stepOf) {
225
+ const confirmed = new Map();
226
+ const active = new Set();
227
+ let serial = 0;
228
+ const fresh = (term) => freshTerm(term, `replay${++serial}`);
229
+ const supportedRule = (clause) => clause && clause.parentId === null && !clause.templates.length &&
230
+ clause.captures === null && clause.guard === null;
231
+ function compatible(goal, use, env) {
232
+ const mark = env.mark();
233
+ const agrees = unify(goal, fresh(use), env);
234
+ env.undo(mark);
235
+ return agrees;
236
+ }
237
+ function all(goals, uses, env) {
238
+ return goals.length === uses.length && goals.every((goal, i) => one(goal, uses[i], env));
239
+ }
240
+ function one(goal, use, env) {
241
+ goal = deref(goal, env);
242
+ if (!isCallable(goal) || !isCallable(use)) return false;
243
+ const goalKey = key(goal);
244
+ if (goalKey !== key(use)) return false;
245
+ if (goalKey === 'call/1' || goalKey === 'or/2') {
246
+ const step = stepOf(use);
247
+ if (!step || step.by !== 'control') return false;
248
+ const used = step.uses.map((item) => text(item));
249
+ const sides = goalKey === 'call/1' ? [0] : [0, 1];
250
+ const side = sides.find((i) => {
251
+ const parts = flattenConjunction(use.args[i]);
252
+ return parts.length === used.length && parts.every((part, j) => text(part) === used[j]);
253
+ });
254
+ return side !== undefined && all(flattenConjunction(goal.args[side]), step.uses, env);
255
+ }
256
+ if (['once/1', 'not/1', 'findall/3'].includes(goalKey)) {
257
+ const outcome = settler.answers(copyResolved(goal, env));
258
+ if (outcome.status !== 'settled' || !outcome.answers.length) return false;
259
+ return unify(goal, fresh(outcome.answers[0]), env) && compatible(goal, use, env);
260
+ }
261
+ if (PRIMITIVE_KEYS.has(goalKey)) {
262
+ // A comparison of variables orders them by name, which renaming changes.
263
+ if (goalKey === 'compare/3' && (!isGround(goal.args[1], env) || !isGround(goal.args[2], env))) return false;
264
+ try {
265
+ for (const _ of primitive(goal, env)) { // eslint-disable-line no-unused-vars
266
+ if (compatible(goal, use, env)) return true;
267
+ }
268
+ } catch (error) {
269
+ if (!(error instanceof EyemindError)) throw error;
270
+ }
271
+ return false;
272
+ }
273
+ if (INSPECTION_KEYS.has(goalKey)) return false;
274
+ const step = stepOf(use);
275
+ if (!step) {
276
+ // A use without a step is an instance of a source fact.
277
+ for (const clause of program.groups.get(goalKey) || []) {
278
+ if (clause.body.length || clause.forward || clause.parentId !== null) continue;
279
+ const mark = env.mark();
280
+ const [head] = freshClause(clause, `replay${++serial}`);
281
+ if (unify(goal, head, env) && compatible(goal, use, env)) return true;
282
+ env.undo(mark);
283
+ }
284
+ return false;
285
+ }
286
+ if (!isTerm(step.by, 'clause', 1)) return false;
287
+ const clause = program.byId.get(Number(step.by.args[0]));
288
+ if (!supportedRule(clause)) return false;
289
+ if (clause.forward) return fact(use) && unify(goal, fresh(use), env);
290
+ const [head, body] = freshClause(clause, `replay${++serial}`);
291
+ if (!body.length) return unify(goal, head, env) && compatible(goal, use, env);
292
+ const call = `${text(use)} ${text(copyResolved(goal, env))}`;
293
+ if (active.has(call)) return false;
294
+ active.add(call);
295
+ const solved = unify(goal, head, env) && all(body, step.uses, env) && compatible(goal, use, env);
296
+ active.delete(call);
297
+ return solved;
298
+ }
299
+ // A listed fact: a firing of the forward rule its step cites.
300
+ function fact(goal) {
301
+ const id = text(goal);
302
+ if (confirmed.has(id)) return confirmed.get(id);
303
+ if (active.has(id)) return false;
304
+ const step = stepOf(goal);
305
+ const clause = step && isTerm(step.by, 'clause', 1) ? program.byId.get(Number(step.by.args[0])) : null;
306
+ let holds = false;
307
+ if (supportedRule(clause) && clause.forward) {
308
+ active.add(id);
309
+ const [head, body, names] = freshClause(clause, `replay${++serial}`);
310
+ const env = new Env();
311
+ holds = all(body, step.uses, env);
312
+ if (holds && clause.witnessNames.length) {
313
+ // Each witness is the Skolem term of this firing (Section 8.2).
314
+ const witnesses = new Set(clause.witnessNames.map((name) => names.get(name).name));
315
+ const values = [];
316
+ for (const variable of variables(head).values()) {
317
+ if (witnesses.has(variable.name)) continue;
318
+ const value = copyResolved(variable, env);
319
+ if (!isGround(value)) holds = false;
320
+ values.push(value);
321
+ }
322
+ for (const name of clause.witnessNames) {
323
+ unify(names.get(name), new Struct('skolem', [BigInt(clause.id), name, listFromItems(values)]), env);
324
+ }
325
+ }
326
+ holds = holds && flattenConjunction(head).some((item) => isCallable(item) &&
327
+ identity(copyResolved(item, env)) === identity(goal));
328
+ active.delete(id);
329
+ }
330
+ confirmed.set(id, holds);
331
+ return holds;
332
+ }
333
+ return listingKeys.every((goalKey) => (settler.listings.get(goalKey)?.facts || []).every(fact));
334
+ }
335
+
336
+ // Both directions of C10: each claim is an answer of an original question,
337
+ // and each answer of a certified question is claimed. When the conclusions
338
+ // are the derived facts, a question's answers that are not derived (source
339
+ // facts, backward answers) are no conclusions, so only its listed facts are.
340
+ // A proof with a primitive only within host-math tolerance (C5) supports no
341
+ // listing for C10: its derived facts need not be what a search here finds.
342
+ export function checkCalls(program, claims, goals, certificate, steps, spellings, fail, allowTrusted, name, inexact = false) {
98
343
  const settler = new Settler(program, {
99
344
  answers: (call) => certificate.calls.get(variant(call, true)) ?? null,
100
345
  facts: (goalKey) => certificate.listings.get(goalKey) ?? null,
101
346
  supported: (fact) => steps.has(spellings.spell(fact)),
102
347
  }, true);
103
348
  if (claims.includes('false')) return { settler, outcomes: [], unresolved: [], covered: 0 };
349
+ const stepOf = (goal) => steps.get(spellings.spell(goal));
350
+ // Replay runs host math exactly, so it needs no exclusion for tolerance.
351
+ const supported = (listings) => (!(inexact && listings.length) && positiveListings(program, listings)) ||
352
+ replayed(program, settler, listings, stepOf);
104
353
  const outcomes = callQuestions(program, goals, claims).map((question) => {
105
354
  const outcome = settler.answers(question);
106
- if (outcome.status === 'settled' && !positiveListings(program, outcome.listings)) {
355
+ if (outcome.status === 'settled' && !supported(outcome.listings)) {
107
356
  return { question, ...outcome, status: 'unsupported' };
108
357
  }
109
358
  return { question, ...outcome };
@@ -127,5 +376,31 @@ export function checkCalls(program, claims, goals, certificate, steps, spellings
127
376
  covered++;
128
377
  if (detail !== null) fail.add('C10', `${detail}: ${text(claim)}`, claim);
129
378
  }
379
+ const derivedOnly = !(goals || []).length && !program.forward.some((clause) => clause.heads.includes('true'));
380
+ const claimed = new Set(claims.map((claim) => variant(claim)));
381
+ for (const { question, status, answers } of outcomes) {
382
+ if (status === 'failed') {
383
+ // A claim of this question already failed with its certificate.
384
+ if (!claims.some((claim) => instance(claim, question))) {
385
+ fail.add('C10', `the original call has an invalid search certificate: ${text(question)}`, question);
386
+ }
387
+ covered++;
388
+ continue;
389
+ }
390
+ if (status !== 'settled') {
391
+ unresolved.push([{ kind: 'call_fidelity', reason: 'all_answers', conclusion: text(question) }, question]);
392
+ if (!allowTrusted) fail.add('C10', `answer completeness remains unproved: ${text(question)}`, question);
393
+ continue;
394
+ }
395
+ const required = derivedOnly
396
+ ? (settler.listings.get(key(question))?.facts || []).filter((fact) => instance(fact, question))
397
+ : answers;
398
+ covered++;
399
+ for (const answer of required) {
400
+ if (!claimed.has(variant(answer))) {
401
+ fail.add('C10', `the proof omits an answer of the original call: ${write(answer, null, new Lettering())}`, answer);
402
+ }
403
+ }
404
+ }
130
405
  return { settler, outcomes, unresolved, covered };
131
406
  }
package/src/proof.js CHANGED
@@ -208,11 +208,19 @@ export function renderProof(program, claims, roots, checkable = false, heading =
208
208
  }
209
209
  };
210
210
  walk(roots);
211
- const boundaries = [...steps.values()].filter((node) => node.by === 'absent' || node.by === 'collected')
211
+ const boundariesOf = () => [...steps.values()].filter((node) => node.by === 'absent' || node.by === 'collected')
212
212
  .map((node) => node.goal);
213
- const certificate = certify !== null ? certify(boundaries) : { tables: [], listings: [] };
213
+ let boundaries = boundariesOf();
214
+ let certificate = certify !== null ? certify(boundaries) : { tables: [], listings: [] };
214
215
  // A listed derived fact is shown by its own steps, after the claims' steps.
215
- walk(certificate.listings.flatMap(([, nodes]) => nodes));
216
+ // Their negations and collections need certificates too, which can list
217
+ // further facts: certify again until no new boundary appears.
218
+ for (;;) {
219
+ walk(certificate.listings.flatMap(([, nodes]) => nodes));
220
+ if (certify === null || boundariesOf().length === boundaries.length) break;
221
+ boundaries = boundariesOf();
222
+ certificate = certify(boundaries);
223
+ }
216
224
  // Variables are named A, B, ... in the order the document first shows
217
225
  // them, the claims written first, as in the run's conclusions.
218
226
  const lettering = new Lettering();
@@ -342,7 +350,7 @@ function check(program, claims, steps, certificate, goals, allowTrusted, fail, s
342
350
  const provenance = new WitnessProvenance(program, steps, certificate, settlement.outcomes, spellings);
343
351
  const tally = checkSteps(program, steps, allowTrusted, fail, spellings, name, settlement.outcomes, provenance);
344
352
  const [confronted, closed] = checkBoundaries(program, steps, tally.boundaries, fail, settlement.outcomes, spellings);
345
- settlement.calls = checkCalls(program, claims, goals, certificate, steps, spellings, fail, allowTrusted, name);
353
+ settlement.calls = checkCalls(program, claims, goals, certificate, steps, spellings, fail, allowTrusted, name, tally.inexact);
346
354
  tally.trusted.push(...settlement.calls.unresolved);
347
355
  checkRelevance(program, claims, steps, goals || [], fail, spellings, settlement, certificate);
348
356
  checkWellFounded(steps, fail, spellings);
@@ -381,13 +389,15 @@ function check(program, claims, steps, certificate, goals, allowTrusted, fail, s
381
389
 
382
390
  // The verdict allowTrusted false would give, from a report without it.
383
391
  // Without failures, strict checking adds C5 failures for trusted boundaries
384
- // and C10 failures for unresolved original calls, in obligation order. It
392
+ // and C10 failures for unresolved original calls and questions whose
393
+ // answers are not shown complete, in obligation order. It
385
394
  // needs no second reading. A report with failures returns null: check again.
386
395
  export function strict(report) {
387
396
  if (report.failures.length) return null;
388
397
  const failures = report.trusted.map((record) => ({
389
398
  condition: record.kind === 'call_fidelity' ? 'C10' : 'C5',
390
- detail: record.kind === 'call_fidelity' ? `call fidelity remains unproved: ${record.conclusion}` : `trusted boundary forbidden: ${record.kind}`,
399
+ detail: record.reason === 'all_answers' ? `answer completeness remains unproved: ${record.conclusion}`
400
+ : record.kind === 'call_fidelity' ? `call fidelity remains unproved: ${record.conclusion}` : `trusted boundary forbidden: ${record.kind}`,
391
401
  conclusion: record.conclusion,
392
402
  }));
393
403
  const conditions = report.conditions.map((condition) => (
@@ -480,7 +490,7 @@ const CONTROL_BY = 'control';
480
490
  // instance of the clause it cites, a recomputed primitive, a control composed
481
491
  // of its uses, or a trusted boundary the later checks confront.
482
492
  function checkSteps(program, steps, allowTrusted, fail, spellings, name, outcomes, provenance) {
483
- const tally = { verified: 0, redecided: 0, composed: 0, witnessed: 0, boundaries: [], trusted: [] };
493
+ const tally = { verified: 0, redecided: 0, composed: 0, witnessed: 0, boundaries: [], trusted: [], inexact: false };
484
494
 
485
495
  function covered(goal) {
486
496
  if (isTerm(goal, 'and', 2)) return flattenConjunction(goal).every(covered);
@@ -510,9 +520,11 @@ function checkSteps(program, steps, allowTrusted, fail, spellings, name, outcome
510
520
  fail.add('C3', 'invalid builtin justification', goal);
511
521
  continue;
512
522
  }
513
- const agrees = redecides(goal);
514
- if (!agrees) fail.add('C5', `primitive disagrees: ${text(goal)}`, goal);
523
+ const exact = redecidesExactly(goal);
524
+ if (!exact && !nearHostMath(goal)) fail.add('C5', `primitive disagrees: ${text(goal)}`, goal);
515
525
  else tally.redecided++;
526
+ // Host math within its tolerance is not the result a search here finds.
527
+ if (!exact) tally.inexact = true;
516
528
  } else if (isTerm(by, 'called', 1)) {
517
529
  if (bindings.length || uses.length || !isCallable(goal) || !STATE_TESTS.has(key(goal))) {
518
530
  fail.add('C3', 'invalid called justification', goal);
@@ -551,6 +563,10 @@ function checkSteps(program, steps, allowTrusted, fail, spellings, name, outcome
551
563
  }
552
564
 
553
565
  function redecides(goal) {
566
+ return redecidesExactly(goal) || nearHostMath(goal);
567
+ }
568
+
569
+ function redecidesExactly(goal) {
554
570
  try {
555
571
  for (const env of primitive(goal, new Env())) {
556
572
  if (resolvesTo(goal, env, goal)) return true;
@@ -558,7 +574,7 @@ function redecides(goal) {
558
574
  } catch (error) {
559
575
  if (!(error instanceof EyemindError)) throw error;
560
576
  }
561
- return nearHostMath(goal);
577
+ return false;
562
578
  }
563
579
 
564
580
  // A state test recorded as called: the called goal, renamed apart, holds as
@@ -1127,7 +1143,8 @@ export function checkReport(report) {
1127
1143
  }
1128
1144
  facts.push(new Struct('verdict', [verdict(report)]));
1129
1145
  const heading = !report.valid ? '// Unverified claims: proof checking failed.'
1130
- : !report.answers.length ? '// No answers claimed; this check establishes no conclusions.'
1146
+ : !report.answers.length && report.trusted.length ? '// No answers claimed; this check establishes no conclusions.'
1147
+ : !report.answers.length ? '// No answers: the original questions have none.'
1131
1148
  : report.trusted.length ? '// Answers checked subject to the obligations below.'
1132
1149
  : '// Checked answers: these follow from the input program.';
1133
1150
  const lines = [heading, ...report.answers, '',
@@ -1139,10 +1156,14 @@ export function checkReport(report) {
1139
1156
  lines.push('', '// Failures: the claims above have not passed every check.');
1140
1157
  }
1141
1158
  if (fact.name === 'obligation' && previous !== 'obligation') {
1142
- lines.push('', '// Obligations: absence, collection or original-call evidence remains unproved.');
1159
+ lines.push('', '// Obligations: absence, collection, original-call or all-answers evidence remains unproved.');
1143
1160
  }
1144
1161
  if (fact.name === 'steps') lines.push('', '// Proof statistics: recorded steps and how they were checked.');
1145
- if (fact.name === 'verdict') lines.push('', '// This verdict applies to the claims above; it does not establish completeness.');
1162
+ if (fact.name === 'verdict') {
1163
+ lines.push('', report.valid && !report.trusted.length && !report.answers.includes("'false'")
1164
+ ? '// This verdict also establishes that the claims above are every answer of the original questions.'
1165
+ : '// This verdict applies to the claims above; it does not establish that they are every answer.');
1166
+ }
1146
1167
  lines.push(text(lettered(fact)));
1147
1168
  previous = fact.name;
1148
1169
  }
package/src/version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // The release this checkout is; ./release keeps it in step with package.json.
2
- export const VERSION = '0.5.21';
2
+ export const VERSION = '0.5.23';