eyemind 0.3.1 → 0.3.3
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 +2 -2
- package/SPEC.md +248 -26
- package/package.json +1 -1
- package/src/cli.js +2 -2
- package/src/closure.js +41 -21
- package/src/common.js +3 -3
- package/src/engine.js +24 -12
- package/src/fidelity.js +120 -0
- package/src/index.js +1 -1
- package/src/lang.js +1 -1
- package/src/program.js +1 -1
- package/src/proof.js +227 -54
- package/src/version.js +1 -1
- package/src/writer.js +4 -3
package/README.md
CHANGED
|
@@ -14,9 +14,9 @@ JavaScript library, and a browser application, with no dependencies.
|
|
|
14
14
|
The guide shows how to run programs, write rules, check proofs, use the
|
|
15
15
|
library and develop eyemind; the playground runs programs in your browser;
|
|
16
16
|
the specification defines the language, its canonical text, the proof format
|
|
17
|
-
and the C1–
|
|
17
|
+
and the C1–C10 checks. The examples are 94 runnable programs, each with a card
|
|
18
18
|
deck and saved conclusions, proofs and check reports. The conformance suite
|
|
19
|
-
has
|
|
19
|
+
has 1303 cases that test any implementation of the specification through its
|
|
20
20
|
command line; run it [in your browser](https://eyereasoner.github.io/eyemind/playground/conformance).
|
|
21
21
|
|
|
22
22
|
```js
|
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.3.
|
|
5
|
+
Version: eyemind 0.3.3
|
|
6
6
|
```
|
|
7
7
|
|
|
8
8
|
This document specifies the syntax and meaning of eyemind programs and data
|
|
@@ -64,6 +64,7 @@ proof.
|
|
|
64
64
|
- [10.2 Clause displays](#102-clause-displays)
|
|
65
65
|
- [10.3 Steps](#103-steps)
|
|
66
66
|
- [10.4 Search certificates](#104-search-certificates)
|
|
67
|
+
- [10.5 Call-fidelity certificates](#105-call-fidelity-certificates)
|
|
67
68
|
- [11. Proof Checking](#11-proof-checking)
|
|
68
69
|
- [11.1 Reading the document](#111-reading-the-document)
|
|
69
70
|
- [11.2 C1 Resolution](#112-c1-resolution)
|
|
@@ -77,6 +78,8 @@ proof.
|
|
|
77
78
|
- [11.10 C9 Search closure](#1110-c9-search-closure)
|
|
78
79
|
- [11.11 Counts and validity](#1111-counts-and-validity)
|
|
79
80
|
- [11.12 Scope of a valid proof](#1112-scope-of-a-valid-proof)
|
|
81
|
+
- [11.13 Operational query fidelity](#1113-operational-query-fidelity)
|
|
82
|
+
- [11.14 C10 Call fidelity](#1114-c10-call-fidelity)
|
|
80
83
|
- [12. Check Reports](#12-check-reports)
|
|
81
84
|
- [12.1 JSON form](#121-json-form)
|
|
82
85
|
- [13. Command-Line Interface](#13-command-line-interface)
|
|
@@ -367,7 +370,7 @@ A clause MUST be rejected when:
|
|
|
367
370
|
- a head is not an atom or compound, or is a list, the atom `'[]'` or a
|
|
368
371
|
`'.'/2` compound, which as a goal would be a conjunction (Section 4.1) and
|
|
369
372
|
could never call the clause;
|
|
370
|
-
- a head uses `step/4`, `clause/2`, `searched/2
|
|
373
|
+
- a head uses `step/4`, `clause/2`, `searched/2`, `derived/2`, `called/2`, reserved
|
|
371
374
|
for proof documents, or explicitly states the reserved predicate
|
|
372
375
|
`activated/2`;
|
|
373
376
|
- a head is a primitive or control, except the head `'true'` of a query or
|
|
@@ -954,7 +957,8 @@ When a proof is requested, each solution records how each of its goals was
|
|
|
954
957
|
justified: by a fact or rule of the program, by a derived fact (whose own
|
|
955
958
|
record is kept), by a primitive, by a control, by an absence (a negation) or
|
|
956
959
|
by a collection (`findall`). For each conclusion the first derivation found is
|
|
957
|
-
recorded. Each
|
|
960
|
+
recorded. Each original question gets call-fidelity evidence (Sections 10.5 and 11.14),
|
|
961
|
+
when supported. Each negation and collection of a proof gets the search certificate
|
|
958
962
|
that settles it (Sections 10.4 and 11.10) whenever Section 11.10 allows one. A
|
|
959
963
|
table holds every answer of its call, so it can search beyond where the run
|
|
960
964
|
stopped, as under `once`; a boundary whose tables would meet an error, or
|
|
@@ -1090,6 +1094,8 @@ the conclusions of a run and in a proof document, the variables are named
|
|
|
1090
1094
|
first shows them, across the whole document, the conclusions written first;
|
|
1091
1095
|
the clause displays of a proof keep the program's names. A check report
|
|
1092
1096
|
names the variables of each fact anew (Section 12).
|
|
1097
|
+
Call tables have a separate naming scope and preserve anonymous-variable
|
|
1098
|
+
status as specified in Section 10.5.
|
|
1093
1099
|
|
|
1094
1100
|
## 10. Proof Documents
|
|
1095
1101
|
|
|
@@ -1108,13 +1114,16 @@ A proof document is a document (Section 9.1) holding, in this order:
|
|
|
1108
1114
|
`step(Goal, By, Bindings, Uses)` per justified goal;
|
|
1109
1115
|
6. when it has a search certificate (Section 10.4), an empty line, comment
|
|
1110
1116
|
lines introducing it, then one `derived(Pattern, Facts)` per listed
|
|
1111
|
-
relation, then one `searched(Call, Answers)` per table
|
|
1117
|
+
relation, then one `searched(Call, Answers)` per table;
|
|
1118
|
+
7. then any `called(Call, Answers)` tables (Section 10.5), in first-consulted
|
|
1119
|
+
order and with their own variable naming scope.
|
|
1112
1120
|
|
|
1113
1121
|
Comments are informative and MAY be worded differently; they are ignored when
|
|
1114
1122
|
the document is read.
|
|
1115
1123
|
|
|
1116
1124
|
A checker MUST treat every statement that is neither `clause/2`, `step/4`,
|
|
1117
|
-
`searched/2` nor `
|
|
1125
|
+
`searched/2`, `derived/2` nor `called/2` as a claim, whatever its position.
|
|
1126
|
+
Call tables follow the other search certificate statements (Section 10.5).
|
|
1118
1127
|
|
|
1119
1128
|
### 10.2 Clause displays
|
|
1120
1129
|
|
|
@@ -1205,6 +1214,37 @@ derived(nonpacifist(A), [nonpacifist('nixon')])
|
|
|
1205
1214
|
searched(nonpacifist('ada'), [])
|
|
1206
1215
|
```
|
|
1207
1216
|
|
|
1217
|
+
### 10.5 Call-fidelity certificates
|
|
1218
|
+
|
|
1219
|
+
`called(Call, Answers)` is a **call table**. Its shape and answer ordering
|
|
1220
|
+
are those of `searched/2` (Section 10.4), but it certifies calls made from
|
|
1221
|
+
the original questions. C10 is always checked, including when the document
|
|
1222
|
+
has no call tables. External questions remain inputs to the checker: a
|
|
1223
|
+
table cannot supply or specialize the question to which a claim must answer.
|
|
1224
|
+
Missing call evidence remains an explicit obligation, never an unconditional
|
|
1225
|
+
`checked` verdict (Section 11.14).
|
|
1226
|
+
|
|
1227
|
+
Two calls identify the same call table only when they are identical up to
|
|
1228
|
+
renaming **that preserves anonymous-variable status** (Section 4.2), including
|
|
1229
|
+
inside nested compounds. There MUST NOT be two such tables. An anonymous
|
|
1230
|
+
variable cannot be renamed to a named one, or vice versa, when comparing
|
|
1231
|
+
call-table answers either. These restrictions matter because a named unbound
|
|
1232
|
+
variable makes a negation an error. A malformed or duplicate call table
|
|
1233
|
+
fails C3 as a malformed or duplicate search table does.
|
|
1234
|
+
|
|
1235
|
+
Call-table variables have their own naming scope. Writers name named
|
|
1236
|
+
variables `A`, `B`, ..., counting variables in first-occurrence order, and
|
|
1237
|
+
anonymous ones `_0`, `_1`, ... using their position in the same order.
|
|
1238
|
+
For example, a named call returning an anonymous parameter may be:
|
|
1239
|
+
|
|
1240
|
+
```js
|
|
1241
|
+
called(p(A), [p(_1)])
|
|
1242
|
+
```
|
|
1243
|
+
|
|
1244
|
+
Each answer is freshened separately when used, as in Section 10.4. C10 call
|
|
1245
|
+
tables and C9 search tables are distinct, even for textually identical calls.
|
|
1246
|
+
They share any applicable `derived/2` listings, whose facts require steps.
|
|
1247
|
+
|
|
1208
1248
|
## 11. Proof Checking
|
|
1209
1249
|
|
|
1210
1250
|
A checker is given a program, a proof document and, when the proof answers
|
|
@@ -1212,7 +1252,7 @@ goals asked from outside the program, those goals. It MUST NOT call a
|
|
|
1212
1252
|
reasoner to supply a missing step; it MAY recompute primitives, and it MAY
|
|
1213
1253
|
expand a call one level against the program with every inner call answered
|
|
1214
1254
|
by the search certificate (Section 11.10). It
|
|
1215
|
-
|
|
1255
|
+
checks C1–C10 and records each failure with its condition, a
|
|
1216
1256
|
detail and, where there is one, the term concerned.
|
|
1217
1257
|
|
|
1218
1258
|
### 11.1 Reading the document
|
|
@@ -1294,8 +1334,10 @@ Host math is the one exception to identical re-decision. A `'builtin'` step
|
|
|
1294
1334
|
`log10`, a trigonometric or hyperbolic function, or `pow`, also passes C5
|
|
1295
1335
|
when `E` evaluates to a float at most 4 units in the last place from `V`,
|
|
1296
1336
|
that is, with at most 3 floats between them. Such results may differ between
|
|
1297
|
-
conforming implementations (Section 14)
|
|
1298
|
-
|
|
1337
|
+
conforming implementations (Section 14). C5 therefore accepts this bounded
|
|
1338
|
+
variation. C10 still compares actual answers of the original question;
|
|
1339
|
+
when those answers depend on host math, a proof MAY fail C10 on another
|
|
1340
|
+
implementation even when its primitive steps pass C5. Every other recomputed result MUST be identical; a difference
|
|
1299
1341
|
that grows beyond this bound, for example through cancellation, MAY make a
|
|
1300
1342
|
proof fail on an implementation other than the one that made it.
|
|
1301
1343
|
|
|
@@ -1347,8 +1389,48 @@ bound to `skolem(N, Name, Args)`, where:
|
|
|
1347
1389
|
- `Name` is the name of `V` as the program writes it (Section 8.2);
|
|
1348
1390
|
- `Args` is the same for every such variable of the step, and is the list of
|
|
1349
1391
|
the values of the heads' variables, in order of their first occurrence in
|
|
1350
|
-
the heads,
|
|
1351
|
-
|
|
1392
|
+
the heads, omitting a value only when it holds a fresh parameter of this
|
|
1393
|
+
firing, as established below. The spelling of a Skolem term alone MUST
|
|
1394
|
+
NOT establish that it is fresh.
|
|
1395
|
+
|
|
1396
|
+
A value containing `skolem(N, _, Args)` is a **candidate** for omission.
|
|
1397
|
+
Values of variables occurring only in the head hold the witnesses checked
|
|
1398
|
+
above. If any other head variable's value is omitted, the checker MUST
|
|
1399
|
+
establish its **parametric provenance**:
|
|
1400
|
+
|
|
1401
|
+
1. In the instantiated full head and premises, replace each distinct term
|
|
1402
|
+
`skolem(N, Name, Args)` by one fresh variable, using the same replacement
|
|
1403
|
+
throughout. Distinct such terms receive distinct variables, disjoint
|
|
1404
|
+
from all source and document variables. The abstracted head and premises
|
|
1405
|
+
together MUST still be an instance of the source clause, with all
|
|
1406
|
+
variable sharing preserved and without further instantiating their terms.
|
|
1407
|
+
A literal Skolem-shaped constant of the source is therefore fixed data,
|
|
1408
|
+
not a parameter the proof may abstract.
|
|
1409
|
+
2. Each affected premise MUST have evidence under this same abstraction.
|
|
1410
|
+
Follow the recorded uses: backward clauses MUST still satisfy C1,
|
|
1411
|
+
inspection steps the source-instance check of C1, primitives C5, and
|
|
1412
|
+
controls the composition check of C5. An unrecorded source fact is
|
|
1413
|
+
available as in C4. A previously derived forward fact is fixed evidence:
|
|
1414
|
+
the abstracted premise MUST be an instance of that fact, allowing only
|
|
1415
|
+
its existing universal variables to be instantiated. Its ground terms
|
|
1416
|
+
MUST NOT be generalized. Each original step remains subject to its own
|
|
1417
|
+
checks, including C8 and C2; this traversal supplies no missing derivation.
|
|
1418
|
+
3. Captured values and enclosing generator projections of a premise's
|
|
1419
|
+
derived backward rule instance are fixed before its use and MUST NOT
|
|
1420
|
+
change under abstraction. Likewise, this firing's captures MUST NOT
|
|
1421
|
+
change. A backward caller cannot make an earlier firing's data fresh.
|
|
1422
|
+
4. An unchanged boundary may use its original evidence or obligation. A
|
|
1423
|
+
changed boundary MUST already be settled in its original form, and its
|
|
1424
|
+
abstracted form MUST also be settled by Section 11.10, consulting only
|
|
1425
|
+
tables and listings the original boundary rests on. A missing or
|
|
1426
|
+
incomplete certificate fails provenance; an obligation for a specific
|
|
1427
|
+
boundary MUST NOT silently become an obligation for a stronger one.
|
|
1428
|
+
|
|
1429
|
+
Failure of this provenance check is C8, not C1: the original step may be a
|
|
1430
|
+
valid clause instance while proposing the wrong witness context. Provenance
|
|
1431
|
+
rechecks do not add steps or change the C1, C5 or C9 counts. They establish
|
|
1432
|
+
that the displayed firing's evidence permits fresh parameters, not that the
|
|
1433
|
+
firing is the one an original open call would select (Section 11.13).
|
|
1352
1434
|
|
|
1353
1435
|
When a forward clause has any such variables, its full head under the step's
|
|
1354
1436
|
substitution MUST be ground; a step that leaves such a variable unbound, or
|
|
@@ -1369,8 +1451,10 @@ template's capture list and the substitution, not from the witness term.
|
|
|
1369
1451
|
|
|
1370
1452
|
A variable of the head that also occurs in the body is not checked by C8,
|
|
1371
1453
|
even when the body leaves it unbound; its value comes from the uses, which
|
|
1372
|
-
other conditions check.
|
|
1373
|
-
|
|
1454
|
+
other conditions check. Its effect on a head-only variable's witness context
|
|
1455
|
+
is nevertheless subject to the provenance check above. A step with no
|
|
1456
|
+
witnesses in its own forward head or enclosing generators is not covered
|
|
1457
|
+
by C8.
|
|
1374
1458
|
|
|
1375
1459
|
### 11.10 C9 Search closure
|
|
1376
1460
|
|
|
@@ -1443,37 +1527,168 @@ settled nor refuted with the evidence (Section 11.7).
|
|
|
1443
1527
|
| C7 relevance | claims plus steps |
|
|
1444
1528
|
| C8 witness_integrity | `clause` steps with witnesses in their forward head or enclosing generators that passed C8 |
|
|
1445
1529
|
| C9 search_closure | boundaries their search certificate settled or refuted |
|
|
1530
|
+
| C10 call_fidelity | claims whose call fidelity is established or refuted |
|
|
1446
1531
|
|
|
1447
1532
|
A check also counts the **steps** it read, the **claims**, the `clause` steps
|
|
1448
1533
|
**verified** by C1, the `source` inspection steps also **verified** by C1,
|
|
1449
1534
|
the `'builtin'` steps **recomputed** by C5, the
|
|
1450
1535
|
`'control'` steps **composed** by C5, and the `'absent'` and `'collected'`
|
|
1451
|
-
steps **trusted**, those C9 did not settle
|
|
1536
|
+
steps **trusted**, those C9 did not settle, plus each claim whose call
|
|
1537
|
+
fidelity remains unproved by C10.
|
|
1452
1538
|
|
|
1453
|
-
A proof is **valid** when no condition failed. A valid proof with
|
|
1454
|
-
boundaries is valid *conditional on* them.
|
|
1539
|
+
A proof is **valid** when no condition failed. A valid proof with obligations is valid *conditional on* them.
|
|
1455
1540
|
|
|
1456
1541
|
### 11.12 Scope of a valid proof
|
|
1457
1542
|
|
|
1458
1543
|
A valid proof establishes that each of its claims follows from the program
|
|
1459
|
-
by the recorded steps, given its
|
|
1460
|
-
established by its search certificate
|
|
1544
|
+
by the recorded steps, given its obligations; a settled boundary is
|
|
1545
|
+
established by its search certificate, and an unconditional verdict also
|
|
1546
|
+
establishes operational query fidelity (Section 11.13). It does not establish
|
|
1461
1547
|
that the claims are all the conclusions of the program, that the program
|
|
1462
1548
|
derives no `'false'`, or that the program is the one intended: a proof MAY
|
|
1463
1549
|
leave conclusions out, and a run's own proof holds exactly its conclusions.
|
|
1464
1550
|
|
|
1551
|
+
### 11.13 Operational query fidelity
|
|
1552
|
+
|
|
1553
|
+
**Operational query fidelity** means that a claimed answer can be reported
|
|
1554
|
+
for an original question under Section 8, retaining its original call-time
|
|
1555
|
+
bindings, control choices and applicable forward state. Each claimed answer
|
|
1556
|
+
must be reachable in that question's ordered search. This is distinct from
|
|
1557
|
+
completeness: a proof may omit other reachable answers without falsifying
|
|
1558
|
+
the answers it does give. Fidelity concerns the question's search; it does
|
|
1559
|
+
not certify that execution of the whole program reaches that question,
|
|
1560
|
+
avoids a prior contradiction, or terminates preceding questions.
|
|
1561
|
+
|
|
1562
|
+
C1–C9 check the recorded instances and their evidence. They do not establish
|
|
1563
|
+
operational query fidelity for binding-sensitive or order-sensitive goals.
|
|
1564
|
+
In particular, a checker MUST NOT treat C7's instance test, or C5's
|
|
1565
|
+
composition of a `once` step, as proof that the original open call selected
|
|
1566
|
+
that instance. For example:
|
|
1567
|
+
|
|
1568
|
+
```js
|
|
1569
|
+
fact(p('a'), p('b'))
|
|
1570
|
+
implied_by(q(X), once(p(X)))
|
|
1571
|
+
```
|
|
1572
|
+
|
|
1573
|
+
The question `q(X)` answers only `q('a')`. Nevertheless, a C1–C9 proof may
|
|
1574
|
+
justify `q('b')` with `once(p('b'))` and `p('b')`, since the specialized
|
|
1575
|
+
call `q('b')` succeeds. A final substitution does not show that the original
|
|
1576
|
+
call was `once(p(X))` with `X` unbound, or that its first answer was `'a'`.
|
|
1577
|
+
Tests of current variable state have the same distinction (Section 7.5).
|
|
1578
|
+
|
|
1579
|
+
A checker claiming the additional property MUST validate evidence of the
|
|
1580
|
+
original call state, propagation of bindings between ordered premises,
|
|
1581
|
+
freshening and scope, and any first-solution choice or required search
|
|
1582
|
+
closure. A claimed call state or substitution is not authority: it must
|
|
1583
|
+
follow from the original question, source clauses and checked evidence.
|
|
1584
|
+
It MUST preserve generator captures independently of later caller bindings
|
|
1585
|
+
and MUST NOT invoke the reasoner to fill gaps. C10 provides the certificate
|
|
1586
|
+
check of Section 11.14. A C1–C9 verdict alone MUST NOT be presented as
|
|
1587
|
+
establishing it.
|
|
1588
|
+
|
|
1589
|
+
### 11.14 C10 Call fidelity
|
|
1590
|
+
|
|
1591
|
+
Every proof check includes C10. A false original-call certificate or an
|
|
1592
|
+
answer excluded by a complete certificate fails C10. Missing, incomplete or
|
|
1593
|
+
unsupported evidence leaves an explicit
|
|
1594
|
+
`obligation('call_fidelity', 'original_call', Claim)`. Such a claim MUST NOT
|
|
1595
|
+
receive an unconditional `checked` verdict. When trusted obligations are
|
|
1596
|
+
forbidden, each such obligation also fails C10.
|
|
1597
|
+
|
|
1598
|
+
The **original questions** are the external goals, if any. Otherwise, when
|
|
1599
|
+
the program has a forward head `'true'`, they are those rules' bodies as
|
|
1600
|
+
conjunctions; otherwise they are its ordinary forward heads, excluding
|
|
1601
|
+
`'false'`. The questions are not instantiated with a proof's final bindings.
|
|
1602
|
+
Only questions of which a claim is an instance need a certificate. Empty
|
|
1603
|
+
proofs certify no answers and do not establish that a question has none.
|
|
1604
|
+
When the claims contain `'false'`, C10 is inapplicable: it covers no answers
|
|
1605
|
+
and adds no call-fidelity obligations for that halted proof.
|
|
1606
|
+
|
|
1607
|
+
For each such question a checker searches its answers by Section 11.10's
|
|
1608
|
+
one-level expansion and closure checks, with the following differences:
|
|
1609
|
+
|
|
1610
|
+
1. Inner relation calls use `called/2` rather than `searched/2`. Call and
|
|
1611
|
+
answer comparison preserves anonymous-variable status (Section 10.5).
|
|
1612
|
+
Facts alone and primitives need no table, as in C9. Source clauses,
|
|
1613
|
+
freshened apart, determine the bindings passed between ordered premises;
|
|
1614
|
+
the final values displayed by a logical step are not inputs to that search.
|
|
1615
|
+
2. Negation MUST enforce Section 4.2's binding restriction at the actual
|
|
1616
|
+
call. C9's treatment of an unbound named variable as anonymous MUST NOT
|
|
1617
|
+
be used. A source search that raises an error fails its certificate.
|
|
1618
|
+
3. `once` and `findall` keep their Section 4.2 meanings, so the first answer
|
|
1619
|
+
or collected answers come from the actual inner call. Section 11.10's
|
|
1620
|
+
restriction on order-sensitive uses of derived listings still applies.
|
|
1621
|
+
The order of unrelated answers of an ordinary question need not be
|
|
1622
|
+
established to check membership of a claim.
|
|
1623
|
+
4. A comparison `compare/3` with either compared term nonground is not
|
|
1624
|
+
supported by this certificate format: alpha renaming of a table need
|
|
1625
|
+
not preserve the order of variable names. Such a search leaves call fidelity unproved.
|
|
1626
|
+
5. A consulted forward listing MUST have a dependency closure in the ground
|
|
1627
|
+
positive fragment described below. A final listing alone MUST NOT certify
|
|
1628
|
+
binding-sensitive or order-sensitive forward firings outside that fragment.
|
|
1629
|
+
|
|
1630
|
+
For this check, a forward listing's **ground positive dependency closure**
|
|
1631
|
+
contains its relation and each ordinary body relation of every source fact,
|
|
1632
|
+
backward rule or forward rule defining any relation in that closure. All
|
|
1633
|
+
source facts in the closure MUST be ground. Rule bodies MUST contain only
|
|
1634
|
+
ordinary calls, `'true'`, conjunction and disjunction; templates, captures
|
|
1635
|
+
and source inspection are excluded. A body call to an ordinary relation
|
|
1636
|
+
grounds its variables. Conjunction accumulates the grounded variables of its
|
|
1637
|
+
parts; disjunction grounds only those grounded by both alternatives. Every
|
|
1638
|
+
backward head variable MUST be grounded by its body. Every forward head
|
|
1639
|
+
variable MUST either be grounded by its body or be a head-only witness
|
|
1640
|
+
checked by C8. Supported facts plus a closed listing then establish the
|
|
1641
|
+
least ground positive closure. More general forward execution requires
|
|
1642
|
+
publication evidence not supplied by this format, and leaves call fidelity
|
|
1643
|
+
unproved.
|
|
1644
|
+
|
|
1645
|
+
Every relevant call certificate MUST be valid. Each claim MUST be identical,
|
|
1646
|
+
up to renaming, to an answer of at least one corresponding original question;
|
|
1647
|
+
merely being an instance of a more general answer does not suffice. For
|
|
1648
|
+
example, `q('b')` fails C10 for the question in Section 11.13 even though
|
|
1649
|
+
its ground logical derivation passes C1–C9. A proof of `p('a')` likewise
|
|
1650
|
+
cannot replace an original call's actual universal answer `p(A)`.
|
|
1651
|
+
|
|
1652
|
+
A claim fails C10 once when a corresponding question has a false
|
|
1653
|
+
certificate or complete certificates for every matching question exclude its
|
|
1654
|
+
answer. An unresolved alternative question leaves an obligation unless
|
|
1655
|
+
another question certifies the answer. With no applicable complete
|
|
1656
|
+
certificate, its call fidelity likewise remains an obligation. C10 does not discharge earlier C6/C9 obligations.
|
|
1657
|
+
|
|
1658
|
+
The current format requires complete tables, including for a relation
|
|
1659
|
+
called under `once`. A later error or recursion may prevent that table
|
|
1660
|
+
from closing even when `once` itself terminates. C10 then cannot be
|
|
1661
|
+
established; a search-prefix certificate is not defined here. A reasoner
|
|
1662
|
+
MUST attempt call-fidelity certification for every generated proof and check
|
|
1663
|
+
the resulting proof before returning it. Unresolved evidence remains an
|
|
1664
|
+
obligation. The implementation bounds this auxiliary production per question
|
|
1665
|
+
by the smaller of `max_inferences` and 50,000 calls plus answers, and by
|
|
1666
|
+
8,388,608 UTF-16 code units of answer text. Exceeding either bound leaves call
|
|
1667
|
+
fidelity unproved; it does not change the run's answers.
|
|
1668
|
+
|
|
1669
|
+
Call tables and their supporting listings consulted for C10 serve the claims
|
|
1670
|
+
for C7, and their listed facts are reachable through that evidence. C10's
|
|
1671
|
+
auxiliary search does not change C1–C9 covered counts. Its own covered count
|
|
1672
|
+
counts claims whose call fidelity is established or refuted, excluding
|
|
1673
|
+
unresolved claims. Failures are reported in
|
|
1674
|
+
claim order after checking boundaries and before C7 and C2 (Section 12).
|
|
1675
|
+
The answer checks are per original question; they do not establish that all
|
|
1676
|
+
answers were claimed or that preceding distinct questions terminated.
|
|
1677
|
+
|
|
1465
1678
|
## 12. Check Reports
|
|
1466
1679
|
|
|
1467
1680
|
A check report is a document (Section 9.1) beginning with the proof's claims,
|
|
1468
1681
|
in proof order, in canonical text, one per line, followed by a blank line and
|
|
1469
1682
|
the following report facts, one per line:
|
|
1470
1683
|
|
|
1471
|
-
1. `condition(Id, Name, Outcome, Covered)` for C1 to
|
|
1684
|
+
1. `condition(Id, Name, Outcome, Covered)` for C1 to C10, where `Outcome` is
|
|
1472
1685
|
`'ok'` or `failed(N)`, `N` the number of that condition's failures;
|
|
1473
1686
|
2. `failure(Condition, Subject, Detail)` per failure, where `Subject` is the
|
|
1474
1687
|
term concerned or `'proof_document'`, and `Detail` an atom;
|
|
1475
1688
|
3. `obligation(Kind, 'theory_scoped', Goal)` per trusted boundary, in step
|
|
1476
|
-
order, where `Kind` is `'absent'` or `'collected'
|
|
1689
|
+
order, where `Kind` is `'absent'` or `'collected'`, followed by
|
|
1690
|
+
`obligation('call_fidelity', 'original_call', Claim)` per unresolved claim,
|
|
1691
|
+
in claim order;
|
|
1477
1692
|
4. `steps(N)`, `verified(N)`, `recomputed(N)`, `composed(N)`, `trusted(N)`,
|
|
1478
1693
|
`claims(N)`, the counts of Section 11.11;
|
|
1479
1694
|
5. `verdict(V)`, where `V` is `failed(N)` when `N` failures were recorded,
|
|
@@ -1485,7 +1700,7 @@ report is valid with no obligations. A valid report with obligations MUST
|
|
|
1485
1700
|
label them as conditional on those obligations. A failed report MUST label
|
|
1486
1701
|
them as unverified claims; their inclusion does not validate them. A valid
|
|
1487
1702
|
report with no claims MUST say it establishes no conclusions. Comments also
|
|
1488
|
-
explain the C1-
|
|
1703
|
+
explain the C1-C10 order, failures and obligations when present, the statistics,
|
|
1489
1704
|
and that the verdict does not establish completeness. Comments are informative
|
|
1490
1705
|
and MAY be worded differently. They are ignored when the document is read.
|
|
1491
1706
|
|
|
@@ -1494,7 +1709,7 @@ document (Section 11.1), in document order; C4 for each claim, in claim
|
|
|
1494
1709
|
order; then for each step, in document order, C4 for its uses and the C1, C3,
|
|
1495
1710
|
C5 or C8 failure of its justification; for each boundary, in step order, the
|
|
1496
1711
|
C9 failures of its search certificate in the order found, or else its C6
|
|
1497
|
-
failure; C7 for each claim, then
|
|
1712
|
+
failure; C10 for each claim; C7 for each claim, then
|
|
1498
1713
|
for each step, then for each table and listing, in document order; and C2.
|
|
1499
1714
|
|
|
1500
1715
|
`Detail` is informative text identifying what failed; its wording is not
|
|
@@ -1511,7 +1726,8 @@ The JSON form includes `answers`, an array of the initial claims' canonical
|
|
|
1511
1726
|
texts, including unverified claims when `valid` is false. It also has `valid` (boolean), `steps`,
|
|
1512
1727
|
`claims`, `verified`, `redecided` (the count `recomputed`), `composed`,
|
|
1513
1728
|
`uses` (the number of uses of all steps, integers), `trusted`
|
|
1514
|
-
(a list of `{kind, conclusion
|
|
1729
|
+
(a list of `{kind, conclusion, reason?}`, with `reason: 'original_call'`
|
|
1730
|
+
for call-fidelity obligations), `failures` (a list of
|
|
1515
1731
|
`{condition, detail, conclusion?}`) and `conditions` (a list of
|
|
1516
1732
|
`{id, name, covered, failed}`), where `conclusion` is a canonical text.
|
|
1517
1733
|
Its variables keep the names the document gives them, rather than being
|
|
@@ -1533,7 +1749,7 @@ eyemind [OPTION ...] [FILE ...]
|
|
|
1533
1749
|
| `--check-proof FILE` | Check the proof in `FILE` (`-` for standard input) against the program and print its answers and report. |
|
|
1534
1750
|
| `--json` | With either checking mode, print the report, including `answers`, as JSON. |
|
|
1535
1751
|
| `--goal GOAL` | Ask `GOAL`, read as in Section 9.1, where an array is a conjunction; MAY be repeated. With `--check-proof`, the goals the proof answers. |
|
|
1536
|
-
| `--strict-proof` | With either checking mode, forbid trusted
|
|
1752
|
+
| `--strict-proof` | With either checking mode, forbid trusted obligations. |
|
|
1537
1753
|
| `--unused` | Print the unused clauses (Section 13.2). |
|
|
1538
1754
|
| `--stats` | Print reasoning statistics as JSON to standard error: `inferences`, the goals started, which `--max-inferences` bounds; `rounds`, the forward rounds run over all strata; and `derived`, the facts forward rules added, not counting a conclusion the program states as a fact, a query's answers or `'false'`. |
|
|
1539
1755
|
| `--max-depth N`, `--max-iterations N`, `--max-inferences N` | The bounds of Section 8.3; `N` MUST be a positive safe integer, at most 9007199254740991. |
|
|
@@ -1545,7 +1761,7 @@ exclusive. `--json` and `--strict-proof` need a checking mode. With
|
|
|
1545
1761
|
`--prove-and-check`, reasoning bounds and `--stats` apply to proof generation;
|
|
1546
1762
|
an invalid check returns 2, otherwise the run's halt code is retained
|
|
1547
1763
|
(65 for a contradiction, 0 otherwise). A program
|
|
1548
|
-
text that has a line starting with `step(` is a proof document; given one as
|
|
1764
|
+
text that has a line starting with `step(` or `called(` is a proof document; given one as
|
|
1549
1765
|
a program, the command line MUST say how to check it instead.
|
|
1550
1766
|
|
|
1551
1767
|
| Exit code | Meaning |
|
|
@@ -1743,6 +1959,11 @@ clause(3, implies([type(S, A), subclass_of(A, B)], type(S, B)))
|
|
|
1743
1959
|
step(type('socrates', 'mortal'), clause(3), {S: 'socrates', A: 'human', B: 'mortal'}, [type('socrates', 'human'), subclass_of('human', 'mortal')])
|
|
1744
1960
|
step(type('socrates', 'human'), clause(1), {}, [])
|
|
1745
1961
|
step(subclass_of('human', 'mortal'), clause(2), {}, [])
|
|
1962
|
+
|
|
1963
|
+
// Search certificate: derived facts and complete answers used to check
|
|
1964
|
+
// negations, collections and the original questions.
|
|
1965
|
+
derived(type(A, B), [type('socrates', 'mortal')])
|
|
1966
|
+
called(type(A, B), [type('socrates', 'mortal'), type('socrates', 'human')])
|
|
1746
1967
|
```
|
|
1747
1968
|
|
|
1748
1969
|
Its check report (Section 12):
|
|
@@ -1752,8 +1973,8 @@ Its check report (Section 12):
|
|
|
1752
1973
|
type('socrates', 'mortal')
|
|
1753
1974
|
type('socrates', 'human')
|
|
1754
1975
|
|
|
1755
|
-
// C1-
|
|
1756
|
-
// boundary consistency, relevance, witness integrity and
|
|
1976
|
+
// C1-C10: resolution, acyclicity, justification, coverage, re-decision,
|
|
1977
|
+
// boundary consistency, relevance, witness integrity, search closure and call fidelity.
|
|
1757
1978
|
condition('C1', 'resolution', 'ok', 3)
|
|
1758
1979
|
condition('C2', 'well_founded', 'ok', 3)
|
|
1759
1980
|
condition('C3', 'justification', 'ok', 3)
|
|
@@ -1763,6 +1984,7 @@ condition('C6', 'boundary_consistency', 'ok', 0)
|
|
|
1763
1984
|
condition('C7', 'relevance', 'ok', 5)
|
|
1764
1985
|
condition('C8', 'witness_integrity', 'ok', 0)
|
|
1765
1986
|
condition('C9', 'search_closure', 'ok', 0)
|
|
1987
|
+
condition('C10', 'call_fidelity', 'ok', 2)
|
|
1766
1988
|
|
|
1767
1989
|
// Proof statistics: recorded steps and how they were checked.
|
|
1768
1990
|
steps(3)
|
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -9,11 +9,11 @@ export const HELP = `Usage: eyemind [OPTION ...] [FILE ...]
|
|
|
9
9
|
Programs are JavaScript; forward rules run to a fixpoint.
|
|
10
10
|
-p, --proof Print the claims with clause(...) and step(...) records
|
|
11
11
|
-c, --prove-and-check Generate a proof and check it against the input program
|
|
12
|
-
--check-proof FILE Print checked answers and a
|
|
12
|
+
--check-proof FILE Print checked answers and a proof check report (- for stdin)
|
|
13
13
|
--json Print the check report as JSON instead
|
|
14
14
|
--goal GOAL Ask a backward goal after forward reasoning; with
|
|
15
15
|
--check-proof, the goal the proof answers
|
|
16
|
-
--strict-proof Reject proofs
|
|
16
|
+
--strict-proof Reject proofs with unresolved obligations
|
|
17
17
|
--unused List the clauses that make no difference to the conclusions
|
|
18
18
|
--stats Print reasoning statistics to stderr
|
|
19
19
|
--max-depth N Bound backward recursion (default 1000000)
|
package/src/closure.js
CHANGED
|
@@ -20,7 +20,7 @@ import { freshClause, text, variant } from './common.js';
|
|
|
20
20
|
import { INSPECTION_KEYS } from './inspection.js';
|
|
21
21
|
import {
|
|
22
22
|
Env, EyemindError, Struct, Var, copyResolved, deref, flattenConjunction, freshTerm, identity, isCallable, isGround, isTerm, key,
|
|
23
|
-
listFromItems, unify, variables,
|
|
23
|
+
isGroundButAnonymous, listFromItems, unify, variables,
|
|
24
24
|
} from './terms.js';
|
|
25
25
|
|
|
26
26
|
// A search the certificate cannot vouch for: its boundary stays an obligation.
|
|
@@ -60,13 +60,21 @@ export function forwardKeys(program) {
|
|
|
60
60
|
// supported(fact) whether the proof has a step for a listed fact. Tables and
|
|
61
61
|
// listings are checked once, however many boundaries rest on them.
|
|
62
62
|
export class Settler {
|
|
63
|
-
constructor(program, source) {
|
|
63
|
+
constructor(program, source, operational = false) {
|
|
64
64
|
this.program = program;
|
|
65
65
|
this.source = source;
|
|
66
66
|
this.derivedKeys = forwardKeys(program);
|
|
67
67
|
this.tables = new Map();
|
|
68
68
|
this.listings = new Map();
|
|
69
69
|
this.serial = 0;
|
|
70
|
+
this.operational = operational;
|
|
71
|
+
this.variant = (term) => variant(term, operational);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// All answers of an original call, rather than a final substituted step.
|
|
75
|
+
// This is the C10 root; inner calls still come only from the certificate.
|
|
76
|
+
answers(call) {
|
|
77
|
+
return this.settle(new Struct('answers', [call]));
|
|
70
78
|
}
|
|
71
79
|
|
|
72
80
|
// The outcome for one negation or collection: status 'settled',
|
|
@@ -75,6 +83,7 @@ export class Settler {
|
|
|
75
83
|
// rests on.
|
|
76
84
|
settle(boundary) {
|
|
77
85
|
const collecting = isTerm(boundary, 'findall', 3);
|
|
86
|
+
const answering = isTerm(boundary, 'answers', 1);
|
|
78
87
|
const goal = collecting ? boundary.args[1] : boundary.args[0];
|
|
79
88
|
const root = new Reliance(collecting);
|
|
80
89
|
const outcome = { status: 'settled', failures: [], boundaryOnly: false, tables: [], listings: [] };
|
|
@@ -82,10 +91,10 @@ export class Settler {
|
|
|
82
91
|
try {
|
|
83
92
|
const env = new Env();
|
|
84
93
|
const copied = freshTerm(collecting ? new Struct('-', [boundary.args[0], goal]) : goal, `root${++this.serial}`);
|
|
85
|
-
const [template, searched] = collecting ? copied.args : [null, copied];
|
|
94
|
+
const [template, searched] = collecting ? copied.args : [answering ? copied : null, copied];
|
|
86
95
|
for (const _ of this.solve(searched, env, root)) { // eslint-disable-line no-unused-vars
|
|
87
|
-
found.push(collecting ? freshTerm(copyResolved(template, env), `item${++this.serial}`) : null);
|
|
88
|
-
if (!collecting) break;
|
|
96
|
+
found.push(collecting || answering ? freshTerm(copyResolved(template, env), `item${++this.serial}`) : null);
|
|
97
|
+
if (!collecting && !answering) break;
|
|
89
98
|
}
|
|
90
99
|
} catch (error) {
|
|
91
100
|
if (error instanceof Unsettled) return { ...outcome, status: 'unsettled' };
|
|
@@ -126,6 +135,7 @@ export class Settler {
|
|
|
126
135
|
}
|
|
127
136
|
if (outcome.failures.length || outcome.failed) return { ...outcome, status: 'failed' };
|
|
128
137
|
if (unsettled || [...ordered].some((item) => !this.exact(item))) return { ...outcome, status: 'unsettled' };
|
|
138
|
+
if (answering) return { ...outcome, answers: found };
|
|
129
139
|
if (!collecting && found.length) {
|
|
130
140
|
outcome.failures.push([`absence contradicted by its search: ${text(boundary)}`, boundary]);
|
|
131
141
|
return { ...outcome, status: 'failed', boundaryOnly: true };
|
|
@@ -157,6 +167,9 @@ export class Settler {
|
|
|
157
167
|
// A negation's unbound variables stand for any value, as anonymous
|
|
158
168
|
// ones do; a reasoner would not have run one with a named variable.
|
|
159
169
|
const once = goalKey === 'once/1';
|
|
170
|
+
if (this.operational && !once && !isGroundButAnonymous(goal.args[0], env)) {
|
|
171
|
+
throw new EyemindError('call fidelity: negation has an unbound named variable');
|
|
172
|
+
}
|
|
160
173
|
if (once) reliance.inner++;
|
|
161
174
|
const inner = this.solve(goal.args[0], env, reliance);
|
|
162
175
|
const first = inner.next();
|
|
@@ -175,6 +188,10 @@ export class Settler {
|
|
|
175
188
|
env.undo(mark);
|
|
176
189
|
if (unify(goal.args[2], listFromItems(items), env)) yield;
|
|
177
190
|
} else if (PRIMITIVE_KEYS.has(goalKey)) {
|
|
191
|
+
// Relative names of unbound variables are not preserved by alpha
|
|
192
|
+
// renaming of a table. A name-dependent comparison needs more evidence.
|
|
193
|
+
if (this.operational && goalKey === 'compare/3' &&
|
|
194
|
+
(!isGround(goal.args[1], env) || !isGround(goal.args[2], env))) throw new Unsettled();
|
|
178
195
|
for (const _ of primitive(goal, env)) { // eslint-disable-line no-unused-vars
|
|
179
196
|
yield;
|
|
180
197
|
env.undo(mark);
|
|
@@ -187,7 +204,7 @@ export class Settler {
|
|
|
187
204
|
yield* this.expand(goal, env, reliance);
|
|
188
205
|
} else {
|
|
189
206
|
const call = copyResolved(goal, env);
|
|
190
|
-
const callKey = variant(call);
|
|
207
|
+
const callKey = this.variant(call);
|
|
191
208
|
let entry = this.tables.get(callKey);
|
|
192
209
|
if (entry === undefined) {
|
|
193
210
|
const answers = this.source.answers(call);
|
|
@@ -219,7 +236,9 @@ export class Settler {
|
|
|
219
236
|
env.undo(mark);
|
|
220
237
|
}
|
|
221
238
|
}
|
|
222
|
-
|
|
239
|
+
const clauses = this.program.hasTemplates ? this.program.groups.get(goalKey) || []
|
|
240
|
+
: this.program.candidates(call, env, goalKey);
|
|
241
|
+
for (const clause of clauses) {
|
|
223
242
|
// A derived rule instance answers only through the run that made it.
|
|
224
243
|
if (clause.parentId !== null) throw new Unsettled();
|
|
225
244
|
const [head, body] = freshClause(clause, `clause${++this.serial}`);
|
|
@@ -260,7 +279,7 @@ export class Settler {
|
|
|
260
279
|
for (const _ of this.expand(call, env, entry.reliance)) found.push(copyResolved(call, env)); // eslint-disable-line no-unused-vars
|
|
261
280
|
const listed = entry.answers;
|
|
262
281
|
let i = 0;
|
|
263
|
-
while (i < found.length && i < listed.length && variant(found[i]) === variant(listed[i])) i++;
|
|
282
|
+
while (i < found.length && i < listed.length && this.variant(found[i]) === this.variant(listed[i])) i++;
|
|
264
283
|
if (i < found.length && i < listed.length) {
|
|
265
284
|
entry.failure = `the search of ${text(entry.call)} answers ${text(found[i])} where its table lists ${text(listed[i])}`;
|
|
266
285
|
} else if (i < found.length) {
|
|
@@ -390,19 +409,20 @@ export class Settler {
|
|
|
390
409
|
exact(callKey) {
|
|
391
410
|
const memo = this.exactness ??= new Map();
|
|
392
411
|
if (memo.has(callKey)) return memo.get(callKey);
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
const
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
const reliance = this.tables.get(
|
|
405
|
-
memo.set(
|
|
412
|
+
// Finish each dependency before caching its parent. Reversing discovery
|
|
413
|
+
// order is insufficient when two branches share a dependency.
|
|
414
|
+
const frame = (item) => [item, [...this.tables.get(item).reliance.tables], 0];
|
|
415
|
+
const stack = [frame(callKey)];
|
|
416
|
+
while (stack.length) {
|
|
417
|
+
const top = stack[stack.length - 1];
|
|
418
|
+
if (top[2] < top[1].length) {
|
|
419
|
+
const next = top[1][top[2]++];
|
|
420
|
+
if (!memo.has(next)) stack.push(frame(next));
|
|
421
|
+
continue;
|
|
422
|
+
}
|
|
423
|
+
const reliance = this.tables.get(top[0]).reliance;
|
|
424
|
+
memo.set(top[0], !reliance.listings.size && top[1].every((item) => memo.get(item)));
|
|
425
|
+
stack.pop();
|
|
406
426
|
}
|
|
407
427
|
return memo.get(callKey);
|
|
408
428
|
}
|
package/src/common.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Helpers shared by the engine and the proof checker.
|
|
2
|
-
import { Struct, Var, deref, freshTerm, unify } from './terms.js';
|
|
2
|
+
import { Struct, Var, deref, freshTerm, isAnonymous, unify } from './terms.js';
|
|
3
3
|
import { write } from './writer.js';
|
|
4
4
|
|
|
5
5
|
// The canonical spelling of a term, which also serves as its identity.
|
|
@@ -184,11 +184,11 @@ function build(term, values, fresh) {
|
|
|
184
184
|
}
|
|
185
185
|
|
|
186
186
|
// A key that preserves sharing while forgetting variable names.
|
|
187
|
-
export function variant(term) {
|
|
187
|
+
export function variant(term, anonymous = false) {
|
|
188
188
|
const names = new Map();
|
|
189
189
|
function visit(t) {
|
|
190
190
|
if (t instanceof Var) {
|
|
191
|
-
if (!names.has(t.name)) names.set(t.name, new Var(
|
|
191
|
+
if (!names.has(t.name)) names.set(t.name, new Var(`${anonymous && isAnonymous(t) ? '_' : 'V'}${names.size}`));
|
|
192
192
|
return names.get(t.name);
|
|
193
193
|
}
|
|
194
194
|
if (t instanceof Struct) return new Struct(t.name, t.args.map(visit));
|