eyemind 0.5.32 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +72 -70
- package/SPEC.md +382 -1099
- package/package.json +1 -1
- package/src/cli.js +5 -10
- package/src/closure.js +81 -99
- package/src/common.js +36 -1
- package/src/engine.js +64 -51
- package/src/fidelity.js +141 -107
- package/src/index.js +1 -1
- package/src/program.js +1 -1
- package/src/proof.js +112 -958
- package/src/srl.js +11 -9
- package/src/version.js +1 -1
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
|
|
10
|
+
The playground runs programs in your browser; the specification defines the language, its canonical text, the proof format and how a proof is checked. The examples are 135 runnable programs, each with a card deck and saved conclusions, proofs and check reports. The conformance suite has 1246 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
|
|
|
@@ -45,9 +45,9 @@ Prolog, Datalog, N3 and SRL already exist, and eyemind adds no new logic: rules
|
|
|
45
45
|
1. **The proof covers everything that went into the answer.**
|
|
46
46
|
- Most engines show an answer, or at best a trace you have to trust.
|
|
47
47
|
- eyemind proofs include the hard parts:
|
|
48
|
-
- "nothing matched" (negation and collections),
|
|
49
|
-
- what a rule says exists, as the Skolem term of that rule firing
|
|
50
|
-
- whether each answer really answers the question asked, and whether every answer of the question is there
|
|
48
|
+
- "nothing matched" (negation and collections), decided from complete answer tables whose listings of derived facts must be closed;
|
|
49
|
+
- what a rule says exists, as the Skolem term of that rule firing;
|
|
50
|
+
- whether each answer really answers the question asked, and whether every answer of the question is there.
|
|
51
51
|
- A forged proof must never pass the check, so a result is something you can hand to someone who does not trust your engine.
|
|
52
52
|
2. **Programs are plain JavaScript.**
|
|
53
53
|
- There is no syntax to learn, no parser to install and no dependency.
|
|
@@ -275,8 +275,7 @@ Examples run directly from their N3 source in the playground and on the command
|
|
|
275
275
|
[invoice collection](https://eyereasoner.github.io/eyemind/examples/deck/invoice-n3),
|
|
276
276
|
[French cities](https://eyereasoner.github.io/eyemind/examples/deck/french-cities-n3), and
|
|
277
277
|
[Skolem IRI witnesses](https://eyereasoner.github.io/eyemind/examples/deck/witnesses-n3).
|
|
278
|
-
Each deck shows the N3 result and what its saved proof establishes
|
|
279
|
-
any remaining obligations.
|
|
278
|
+
Each deck shows the N3 result and what its saved proof establishes.
|
|
280
279
|
|
|
281
280
|
### RDF Messages
|
|
282
281
|
|
|
@@ -330,7 +329,7 @@ text with the same boundaries. Whole-log replay supports proofs;
|
|
|
330
329
|
unused-clause modes. The [message-boundaries](https://eyereasoner.github.io/eyemind/examples/deck/message-boundaries-n3),
|
|
331
330
|
[message-alerts](https://eyereasoner.github.io/eyemind/examples/deck/message-alerts-n3)
|
|
332
331
|
and [message-provenance](https://eyereasoner.github.io/eyemind/examples/deck/message-provenance-n3)
|
|
333
|
-
decks show the outputs and
|
|
332
|
+
decks show the outputs and what their proofs establish.
|
|
334
333
|
|
|
335
334
|
Library hosts can import `RdfMessageReader` and `parseRdfMessages` from
|
|
336
335
|
`eyemind`. The former accepts text chunks through `write(text)` and
|
|
@@ -401,9 +400,9 @@ The two work together: a forward rule's premise can call a backward definition,
|
|
|
401
400
|
|
|
402
401
|
## Proofs, and what checking one means
|
|
403
402
|
|
|
404
|
-
A proof holds the claims, the
|
|
405
|
-
|
|
406
|
-
proof: an N3 document or SRL rule set is compiled to an eyemind program, and
|
|
403
|
+
A proof holds the claims, the certificate that answers the program's
|
|
404
|
+
questions, and the recorded firings behind derived facts as `step(...)`
|
|
405
|
+
records. Every input writes the same JavaScript proof: an N3 document or SRL rule set is compiled to an eyemind program, and
|
|
407
406
|
its proof cites that program's clauses, with triples as `rdf(S, P, O)` (an
|
|
408
407
|
SRL inference as `inf(S, P, O)`) over `iri(...)` and `literal(...)` terms:
|
|
409
408
|
|
|
@@ -416,69 +415,74 @@ eyemind --check-proof /tmp/socrates-proof.js examples/socrates-srl.srl
|
|
|
416
415
|
|
|
417
416
|
Check reports are JavaScript term documents too, or JSON with `--json`.
|
|
418
417
|
|
|
419
|
-
|
|
418
|
+
The proof of `examples/socrates.js` shows its parts:
|
|
420
419
|
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
420
|
+
```js
|
|
421
|
+
// Answers: each instance of a query() that holds.
|
|
422
|
+
type('socrates', 'mortal')
|
|
423
|
+
type('socrates', 'human')
|
|
424
|
+
|
|
425
|
+
// Steps: each derived fact and what it rests on: the clause or control that
|
|
426
|
+
// justifies it, the bindings and the goals it uses.
|
|
427
|
+
step(type('socrates', 'mortal'), clause(3), {S: 'socrates', A: 'human', B: 'mortal'}, [type('socrates', 'human'), subclass_of('human', 'mortal')])
|
|
428
|
+
step(type('socrates', 'human'), clause(1), {}, [])
|
|
429
|
+
|
|
430
|
+
// Certificate: the derived facts and every answer of each call the questions make.
|
|
431
|
+
derived(type(A, B), [type('socrates', 'mortal')])
|
|
432
|
+
called(type(A, B), [type('socrates', 'mortal'), type('socrates', 'human')])
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
- **The claims** are the run's conclusions.
|
|
436
|
+
- **The call tables**, `called(Call, Answers)`, list every answer of each call
|
|
437
|
+
the original questions make: here the query `type(X, Y)`.
|
|
438
|
+
- **The listings**, `derived(Pattern, Facts)`, list every fact forward rules
|
|
439
|
+
derived for a relation those searches consult.
|
|
440
|
+
- **The steps** record the firing behind each listed fact: the rule, its
|
|
441
|
+
bindings and the goals it used; and, for a goal whose call rests on derived
|
|
442
|
+
facts, how that goal was derived. `type(_, _)` is a relation the rule
|
|
443
|
+
derives, so the stated fact `type('socrates', 'human')` has a step citing
|
|
444
|
+
clause 1.
|
|
445
|
+
|
|
446
|
+
Checking is one procedure. The checker answers each original question by
|
|
447
|
+
searching it against the program, one level at a time, with every inner call
|
|
448
|
+
answered from its call table, and checks each table the same way, so a wrong
|
|
449
|
+
table shows up as a disagreement. Each listing must be closed under the
|
|
450
|
+
forward rules, and each listed fact must **replay** its recorded firing: the
|
|
451
|
+
checker re-runs the rule from no bindings, with primitives computed and
|
|
452
|
+
negations, collections and first answers taken from the tables at the
|
|
453
|
+
bindings they had when they ran, and each witness bound to the Skolem term of
|
|
454
|
+
its firing. The claims must then be exactly the answers: a claim the question
|
|
455
|
+
does not return fails, and so does an answer the proof leaves out. A step,
|
|
456
|
+
table or listing the check does not use fails it too, so nothing in a proof
|
|
457
|
+
goes unchecked.
|
|
458
|
+
|
|
459
|
+
**The checker follows the certificate:** it never calls the reasoner, so missing evidence fails rather than being quietly re-derived. **The source is the authority:** the proof cites clauses by number, read from 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:
|
|
435
460
|
|
|
436
461
|
```js
|
|
437
|
-
// Checked answers: these follow from the input program.
|
|
462
|
+
// Checked answers: these follow from the input program and are every answer of its questions.
|
|
438
463
|
type('socrates', 'mortal')
|
|
439
464
|
type('socrates', 'human')
|
|
440
465
|
|
|
441
|
-
// C1-C10: resolution, acyclicity, justification, coverage, re-decision,
|
|
442
|
-
// boundary consistency, relevance, witness integrity, search closure and call fidelity.
|
|
443
|
-
condition('C1', 'resolution', 'ok', 3)
|
|
444
|
-
condition('C2', 'well_founded', 'ok', 3)
|
|
445
|
-
condition('C3', 'justification', 'ok', 3)
|
|
446
|
-
condition('C4', 'coverage', 'ok', 4)
|
|
447
|
-
condition('C5', 're_decision', 'ok', 0)
|
|
448
|
-
condition('C6', 'boundary_consistency', 'ok', 0)
|
|
449
|
-
condition('C7', 'relevance', 'ok', 5)
|
|
450
|
-
condition('C8', 'witness_integrity', 'ok', 0)
|
|
451
|
-
condition('C9', 'search_closure', 'ok', 0)
|
|
452
|
-
condition('C10', 'call_fidelity', 'ok', 3)
|
|
453
|
-
|
|
454
|
-
// Proof statistics: recorded steps and how they were checked.
|
|
455
|
-
steps(3)
|
|
456
|
-
verified(3)
|
|
457
|
-
recomputed(0)
|
|
458
|
-
composed(0)
|
|
459
|
-
trusted(0)
|
|
460
|
-
claims(2)
|
|
461
|
-
|
|
462
|
-
// This verdict also establishes that the claims above are every answer of the original questions.
|
|
463
466
|
verdict('checked')
|
|
464
467
|
```
|
|
465
468
|
|
|
466
|
-
A `checked` verdict thus establishes two things: every claim follows from the program, and the claims are every answer of the original questions.
|
|
469
|
+
A `checked` verdict thus establishes two things: every claim follows from the program, and the claims are every answer of the original questions. A question with no claims is shown to have no answers by its table. A failed check lists `failure(Detail)` facts, ends with `verdict(failed(N))` and exits with code 2. A halted run's proof establishes that its claims follow, not that they are every answer. To check answers to `--goal` questions, pass the same goals when checking. [SPEC §11](https://eyereasoner.github.io/eyemind/SPEC#11-proof-checking) defines the check.
|
|
470
|
+
|
|
471
|
+
Some results cannot be certified by this format, and `--proof` then reports an error while a plain run still gives the answers:
|
|
472
|
+
|
|
473
|
+
- a first answer or a collection whose order rests on derived facts with more than one answer, since a listing does not show the order facts were derived in (a `findall_sorted` of ground items does not depend on it);
|
|
474
|
+
- a firing of a `restricted` rule whose guard is a negation, which held before the firing but no longer does after it;
|
|
475
|
+
- `compare/3` on terms that are not ground, and rules appended by templates whose generators consult derived facts or introduce witnesses;
|
|
476
|
+
- a call table larger than the bound of [Resource limits](#resource-limits).
|
|
467
477
|
|
|
468
478
|
### JSON check reports
|
|
469
479
|
|
|
470
|
-
With `--json`, checking modes write a JSON report instead of a term document
|
|
471
|
-
|
|
472
|
-
texts, including unverified claims when `valid` is false
|
|
473
|
-
`
|
|
474
|
-
`
|
|
475
|
-
|
|
476
|
-
for a claim's call-fidelity obligation and `reason: 'all_answers'` for a
|
|
477
|
-
question's answer-completeness obligation), `failures` (a list of
|
|
478
|
-
`{condition, detail, conclusion?}`) and `conditions` (a list of
|
|
479
|
-
`{id, name, covered, failed}`), where `conclusion` is a canonical text.
|
|
480
|
-
Its variables keep the names the document gives them, rather than being
|
|
481
|
-
renamed for each report fact as in the text form.
|
|
480
|
+
With `--json`, checking modes write a JSON report instead of a term document:
|
|
481
|
+
`valid` (boolean), `claims` and `steps` (the numbers read), `answers` (the
|
|
482
|
+
claims' canonical texts, including unverified claims when `valid` is false),
|
|
483
|
+
`halted` (whether the claims contain `'false'`) and `failures` (a list of
|
|
484
|
+
`{detail, subject?}`, where `subject` is the canonical text of the term
|
|
485
|
+
concerned). Its variables keep the names the document gives them.
|
|
482
486
|
|
|
483
487
|
### Why negation and collection are safe
|
|
484
488
|
|
|
@@ -486,9 +490,8 @@ A negation `not(G)` concludes from what is *absent* and a collection `findall(T,
|
|
|
486
490
|
|
|
487
491
|
- **Ask only once the answer is final.** Rules are ranked so that everything a negation or collection inspects reaches its fixpoint first; a program with no such ranking, such as `implies(not(q), p)` with `implies(p, q)`, is rejected.
|
|
488
492
|
- **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".
|
|
489
|
-
- **Check the search, not just its result.** A proof ends with
|
|
490
|
-
- **
|
|
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.
|
|
493
|
+
- **Check the search, not just its result.** A proof ends with its certificate: `called(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, and requires each listing to be closed under the rules, so an omitted fact shows up too.
|
|
494
|
+
- **Decide at the actual call.** Replay runs each recorded firing from its source rule with the bindings of each point of the search, so a negation sees the goal as it was called, a state test sees the bindings of its actual call, and `once` takes the actual first answer.
|
|
492
495
|
|
|
493
496
|
## Checking the translation
|
|
494
497
|
|
|
@@ -531,7 +534,6 @@ eyemind [OPTION ...] [FILE ...]
|
|
|
531
534
|
| `--check-proof FILE` | Check a saved proof (`-` for standard input) against the program. |
|
|
532
535
|
| `--json` | With a checking mode, print the report as JSON. |
|
|
533
536
|
| `--goal GOAL` | Ask `GOAL` after forward reasoning; may be repeated. |
|
|
534
|
-
| `--strict-proof` | With a checking mode, reject proofs with any obligation. |
|
|
535
537
|
| `--unused` | List the clauses that make no difference to the conclusions. |
|
|
536
538
|
| `--stream-messages` | Read an RDF Message Log and run the rules independently per message; Node reads files, stdin and HTTP(S) incrementally. |
|
|
537
539
|
| `--stats` | Print reasoning statistics as JSON to standard error. |
|
|
@@ -543,7 +545,7 @@ eyemind [OPTION ...] [FILE ...]
|
|
|
543
545
|
| `-v`, `--version`, `-h`, `--help` | Print the version or the usage. |
|
|
544
546
|
|
|
545
547
|
`--proof`, `--prove-and-check`, `--check-proof` and `--unused` are mutually
|
|
546
|
-
exclusive. `--json`
|
|
548
|
+
exclusive. `--json` needs a checking mode. `--goal` reads
|
|
547
549
|
each goal as a data document, with an array denoting conjunction. With
|
|
548
550
|
`--check-proof`, supply the original goals the proof answers.
|
|
549
551
|
|
|
@@ -582,10 +584,10 @@ Arithmetic also limits integer growth: `pow(A, B)` with integer `B > 0` and
|
|
|
582
584
|
2^26. An integer left shift `shl(A, B)` raises an error when `B` exceeds
|
|
583
585
|
2^26. These limits protect the process from excessively large allocations.
|
|
584
586
|
|
|
585
|
-
|
|
587
|
+
Making a proof's call tables is bounded per question by the smaller of the
|
|
586
588
|
run's inference limit and 500,000 calls plus answers, and by 8,388,608 UTF-16
|
|
587
|
-
code units of answer text.
|
|
588
|
-
does not change the run
|
|
589
|
+
code units of answer text. Exceeding these bounds makes `--proof` report an
|
|
590
|
+
error; it does not change the answers of a plain run.
|
|
589
591
|
|
|
590
592
|
### Unused clauses
|
|
591
593
|
|
|
@@ -645,7 +647,7 @@ console.log(result.bindings);
|
|
|
645
647
|
console.log(checkProof(socrates, result.proof, { goals }).valid);
|
|
646
648
|
```
|
|
647
649
|
|
|
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
|
|
650
|
+
`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 })` checks a proof. `checkReport`, `readTerm`, `readTerms` and `write` format reports and read and write the canonical text.
|
|
649
651
|
|
|
650
652
|
## What is deliberately absent
|
|
651
653
|
|