eyemind 0.3.0 → 0.3.2
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 +170 -80
- package/package.json +1 -1
- package/src/cli.js +1 -1
- package/src/closure.js +14 -13
- package/src/index.js +1 -1
- package/src/proof.js +196 -40
- package/src/version.js +1 -1
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–C9 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 1290 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.2
|
|
6
6
|
```
|
|
7
7
|
|
|
8
8
|
This document specifies the syntax and meaning of eyemind programs and data
|
|
@@ -74,8 +74,10 @@ proof.
|
|
|
74
74
|
- [11.7 C6 Boundary consistency](#117-c6-boundary-consistency)
|
|
75
75
|
- [11.8 C7 Relevance](#118-c7-relevance)
|
|
76
76
|
- [11.9 C8 Witness integrity](#119-c8-witness-integrity)
|
|
77
|
-
- [11.10
|
|
78
|
-
- [11.11
|
|
77
|
+
- [11.10 C9 Search closure](#1110-c9-search-closure)
|
|
78
|
+
- [11.11 Counts and validity](#1111-counts-and-validity)
|
|
79
|
+
- [11.12 Scope of a valid proof](#1112-scope-of-a-valid-proof)
|
|
80
|
+
- [11.13 Operational query fidelity](#1113-operational-query-fidelity)
|
|
79
81
|
- [12. Check Reports](#12-check-reports)
|
|
80
82
|
- [12.1 JSON form](#121-json-form)
|
|
81
83
|
- [13. Command-Line Interface](#13-command-line-interface)
|
|
@@ -809,7 +811,7 @@ infinite closure. A finite model does not ensure search termination:
|
|
|
809
811
|
recurs indefinitely. Exceeding a resource bound raises an error (Section
|
|
810
812
|
8.3). Contradictions halt without completing the closure (Section 8.5).
|
|
811
813
|
A valid proof establishes only its claims subject to its trusted boundaries
|
|
812
|
-
(Section 11.
|
|
814
|
+
(Section 11.12), not completeness of the model or the answers. Its search
|
|
813
815
|
certificate settles the negations and collections it can (Section 10.4).
|
|
814
816
|
|
|
815
817
|
## 8. Evaluation and Conclusions
|
|
@@ -954,7 +956,7 @@ justified: by a fact or rule of the program, by a derived fact (whose own
|
|
|
954
956
|
record is kept), by a primitive, by a control, by an absence (a negation) or
|
|
955
957
|
by a collection (`findall`). For each conclusion the first derivation found is
|
|
956
958
|
recorded. Each negation and collection of a proof gets the search certificate
|
|
957
|
-
that settles it (Sections 10.4 and 11.
|
|
959
|
+
that settles it (Sections 10.4 and 11.10) whenever Section 11.10 allows one. A
|
|
958
960
|
table holds every answer of its call, so it can search beyond where the run
|
|
959
961
|
stopped, as under `once`; a boundary whose tables would meet an error, or
|
|
960
962
|
exceed `max_inferences` calls and answers (Section 8.3), stays trusted. A
|
|
@@ -1193,7 +1195,7 @@ proof's negations and collections:
|
|
|
1193
1195
|
|
|
1194
1196
|
A table exists for each call to a relation that a backward rule defines or
|
|
1195
1197
|
forward rules conclude, made by those searches or by the closure checks of
|
|
1196
|
-
Section 11.
|
|
1198
|
+
Section 11.10; a call to a relation defined by facts alone needs none. A
|
|
1197
1199
|
listing exists for each relation forward rules conclude that a table or a
|
|
1198
1200
|
closure check consults. A reasoner writes only the tables and listings of
|
|
1199
1201
|
the boundaries it settles: listings first, in the order first consulted,
|
|
@@ -1210,8 +1212,8 @@ A checker is given a program, a proof document and, when the proof answers
|
|
|
1210
1212
|
goals asked from outside the program, those goals. It MUST NOT call a
|
|
1211
1213
|
reasoner to supply a missing step; it MAY recompute primitives, and it MAY
|
|
1212
1214
|
expand a call one level against the program with every inner call answered
|
|
1213
|
-
by the search certificate (Section 11.
|
|
1214
|
-
establishes
|
|
1215
|
+
by the search certificate (Section 11.10). It
|
|
1216
|
+
establishes nine conditions and records each failure with its condition, a
|
|
1215
1217
|
detail and, where there is one, the term concerned.
|
|
1216
1218
|
|
|
1217
1219
|
### 11.1 Reading the document
|
|
@@ -1270,7 +1272,7 @@ failure, whose conclusion is the goal of that step.
|
|
|
1270
1272
|
no bindings and no uses and a goal that is a primitive; an `'absent'` or
|
|
1271
1273
|
`'collected'` step MUST have no bindings and no uses and a goal that is a
|
|
1272
1274
|
negation or a `findall`, respectively. A step that fails C3 is not a trusted
|
|
1273
|
-
boundary: it counts in neither `trusted
|
|
1275
|
+
boundary: it counts in neither `trusted`, C6 nor C9.
|
|
1274
1276
|
|
|
1275
1277
|
### 11.5 C4 Coverage
|
|
1276
1278
|
|
|
@@ -1300,62 +1302,11 @@ proof fail on an implementation other than the one that made it.
|
|
|
1300
1302
|
|
|
1301
1303
|
### 11.7 C6 Boundary consistency
|
|
1302
1304
|
|
|
1303
|
-
A negation or collection is a **boundary**. A
|
|
1304
|
-
|
|
1305
|
-
|
|
1305
|
+
A negation or collection is a **boundary**. A boundary that its search
|
|
1306
|
+
certificate settles or refutes is checked by C9 (Section 11.10); C6
|
|
1307
|
+
confronts every other well-formed boundary step with the evidence at hand.
|
|
1306
1308
|
|
|
1307
|
-
|
|
1308
|
-
conclude is answered by the table whose call is identical to it up to
|
|
1309
|
-
renaming, each answer renamed apart in turn, and a call to a relation
|
|
1310
|
-
defined by facts alone by those facts, in clause order;
|
|
1311
|
-
- a negation inside the search treats its unbound variables as anonymous.
|
|
1312
|
-
|
|
1313
|
-
The **expansion** of a call is the search of Section 8.1 taken one level:
|
|
1314
|
-
the facts in the listing of its relation, in order, then the program's facts
|
|
1315
|
-
and backward rules of that name and arity, in clause order, each rule's body
|
|
1316
|
-
searched in its place, inner calls answered as above. The boundary's search
|
|
1317
|
-
**rests on** each table and listing it consults, and on those its tables and
|
|
1318
|
-
the closure checks of its listings consult, transitively. The boundary is
|
|
1319
|
-
settled when:
|
|
1320
|
-
|
|
1321
|
-
1. each table it rests on equals its expansion: the same number of answers,
|
|
1322
|
-
each identical up to renaming of variables to the answer in the same
|
|
1323
|
-
position;
|
|
1324
|
-
2. each listing it rests on has a step for each fact, every fact of the
|
|
1325
|
-
listed name and arity and ground, and is **closed**: for each forward
|
|
1326
|
-
rule with a head of that relation, each solution of the rule's body under
|
|
1327
|
-
the certificate, with the rule's witnesses bound to their Skolem terms
|
|
1328
|
-
(Section 8.2), gives head instances of that relation that are listed or
|
|
1329
|
-
are ground facts of the program;
|
|
1330
|
-
3. no table it rests on depends on itself through the tables its expansion
|
|
1331
|
-
consults;
|
|
1332
|
-
4. its outcome agrees: for a negation, `G` has no solution; for a collection
|
|
1333
|
-
`findall(T, G, L)`, `L` is an instance of the list of the instances of
|
|
1334
|
-
`T`, one per solution of `G`, in order, each renamed apart;
|
|
1335
|
-
5. no collection or `once` within its search, a table it rests on or a
|
|
1336
|
-
closure check uses a table whose answers rest on a listing, since the
|
|
1337
|
-
order of derived facts cannot be checked this way; and its search reaches
|
|
1338
|
-
no source inspection and no clause appended by a template, and it
|
|
1339
|
-
consults no listing whose relation a forward rule with a template head
|
|
1340
|
-
or captures concludes (Section 6.2).
|
|
1341
|
-
|
|
1342
|
-
For example, the absence `not(nonpacifist('ada'))` rests on the table
|
|
1343
|
-
`searched(nonpacifist('ada'), [])` and the listing `derived(nonpacifist(A),
|
|
1344
|
-
[nonpacifist('nixon')])`. The table equals its expansion: the listed fact
|
|
1345
|
-
does not match the call, and no backward rule defines `nonpacifist/1`. The
|
|
1346
|
-
listing is closed: the only rule concluding `nonpacifist/1` derives
|
|
1347
|
-
`nonpacifist('nixon')`, which is listed, and that fact has its own step.
|
|
1348
|
-
|
|
1349
|
-
A boundary fails C6 when its certificate is wrong: a table differs from its
|
|
1350
|
-
expansion, a listed fact has no step or another name or arity, a listing is
|
|
1351
|
-
not closed, tables depend on themselves, a search leads to an error, or a
|
|
1352
|
-
negation's goal has a solution. Each wrong table or listing is reported once,
|
|
1353
|
-
for the first boundary resting on it. A boundary whose certificate is
|
|
1354
|
-
missing, incomplete or not applicable under item 5, or a collection whose
|
|
1355
|
-
list does not agree, is not settled. A boundary that is not settled is
|
|
1356
|
-
trusted, including one that fails C6.
|
|
1357
|
-
|
|
1358
|
-
A trusted boundary that is not settled cannot be proved, but the evidence at
|
|
1309
|
+
A boundary that is not settled cannot be proved, but the evidence at
|
|
1359
1310
|
hand can refute it. The evidence for a goal is: when the goal is a ground
|
|
1360
1311
|
primitive, the goal itself if it holds, and otherwise the recomputed fact
|
|
1361
1312
|
that it fails; when it is a control, none, and the boundary is left
|
|
@@ -1397,8 +1348,48 @@ bound to `skolem(N, Name, Args)`, where:
|
|
|
1397
1348
|
- `Name` is the name of `V` as the program writes it (Section 8.2);
|
|
1398
1349
|
- `Args` is the same for every such variable of the step, and is the list of
|
|
1399
1350
|
the values of the heads' variables, in order of their first occurrence in
|
|
1400
|
-
the heads,
|
|
1401
|
-
|
|
1351
|
+
the heads, omitting a value only when it holds a fresh parameter of this
|
|
1352
|
+
firing, as established below. The spelling of a Skolem term alone MUST
|
|
1353
|
+
NOT establish that it is fresh.
|
|
1354
|
+
|
|
1355
|
+
A value containing `skolem(N, _, Args)` is a **candidate** for omission.
|
|
1356
|
+
Values of variables occurring only in the head hold the witnesses checked
|
|
1357
|
+
above. If any other head variable's value is omitted, the checker MUST
|
|
1358
|
+
establish its **parametric provenance**:
|
|
1359
|
+
|
|
1360
|
+
1. In the instantiated full head and premises, replace each distinct term
|
|
1361
|
+
`skolem(N, Name, Args)` by one fresh variable, using the same replacement
|
|
1362
|
+
throughout. Distinct such terms receive distinct variables, disjoint
|
|
1363
|
+
from all source and document variables. The abstracted head and premises
|
|
1364
|
+
together MUST still be an instance of the source clause, with all
|
|
1365
|
+
variable sharing preserved and without further instantiating their terms.
|
|
1366
|
+
A literal Skolem-shaped constant of the source is therefore fixed data,
|
|
1367
|
+
not a parameter the proof may abstract.
|
|
1368
|
+
2. Each affected premise MUST have evidence under this same abstraction.
|
|
1369
|
+
Follow the recorded uses: backward clauses MUST still satisfy C1,
|
|
1370
|
+
inspection steps the source-instance check of C1, primitives C5, and
|
|
1371
|
+
controls the composition check of C5. An unrecorded source fact is
|
|
1372
|
+
available as in C4. A previously derived forward fact is fixed evidence:
|
|
1373
|
+
the abstracted premise MUST be an instance of that fact, allowing only
|
|
1374
|
+
its existing universal variables to be instantiated. Its ground terms
|
|
1375
|
+
MUST NOT be generalized. Each original step remains subject to its own
|
|
1376
|
+
checks, including C8 and C2; this traversal supplies no missing derivation.
|
|
1377
|
+
3. Captured values and enclosing generator projections of a premise's
|
|
1378
|
+
derived backward rule instance are fixed before its use and MUST NOT
|
|
1379
|
+
change under abstraction. Likewise, this firing's captures MUST NOT
|
|
1380
|
+
change. A backward caller cannot make an earlier firing's data fresh.
|
|
1381
|
+
4. An unchanged boundary may use its original evidence or obligation. A
|
|
1382
|
+
changed boundary MUST already be settled in its original form, and its
|
|
1383
|
+
abstracted form MUST also be settled by Section 11.10, consulting only
|
|
1384
|
+
tables and listings the original boundary rests on. A missing or
|
|
1385
|
+
incomplete certificate fails provenance; an obligation for a specific
|
|
1386
|
+
boundary MUST NOT silently become an obligation for a stronger one.
|
|
1387
|
+
|
|
1388
|
+
Failure of this provenance check is C8, not C1: the original step may be a
|
|
1389
|
+
valid clause instance while proposing the wrong witness context. Provenance
|
|
1390
|
+
rechecks do not add steps or change the C1, C5 or C9 counts. They establish
|
|
1391
|
+
that the displayed firing's evidence permits fresh parameters, not that the
|
|
1392
|
+
firing is the one an original open call would select (Section 11.13).
|
|
1402
1393
|
|
|
1403
1394
|
When a forward clause has any such variables, its full head under the step's
|
|
1404
1395
|
substitution MUST be ground; a step that leaves such a variable unbound, or
|
|
@@ -1419,10 +1410,70 @@ template's capture list and the substitution, not from the witness term.
|
|
|
1419
1410
|
|
|
1420
1411
|
A variable of the head that also occurs in the body is not checked by C8,
|
|
1421
1412
|
even when the body leaves it unbound; its value comes from the uses, which
|
|
1422
|
-
other conditions check.
|
|
1423
|
-
|
|
1413
|
+
other conditions check. Its effect on a head-only variable's witness context
|
|
1414
|
+
is nevertheless subject to the provenance check above. A step with no
|
|
1415
|
+
witnesses in its own forward head or enclosing generators is not covered
|
|
1416
|
+
by C8.
|
|
1417
|
+
|
|
1418
|
+
### 11.10 C9 Search closure
|
|
1424
1419
|
|
|
1425
|
-
|
|
1420
|
+
A checker tries to **settle** each well-formed boundary step (Sections 11.4
|
|
1421
|
+
and 11.7) with the search certificate, by searching its goal `G` as Section
|
|
1422
|
+
8.1 does, except that:
|
|
1423
|
+
|
|
1424
|
+
- a call to a relation that a backward rule defines or forward rules
|
|
1425
|
+
conclude is answered by the table whose call is identical to it up to
|
|
1426
|
+
renaming, each answer renamed apart in turn, and a call to a relation
|
|
1427
|
+
defined by facts alone by those facts, in clause order;
|
|
1428
|
+
- a negation inside the search treats its unbound variables as anonymous.
|
|
1429
|
+
|
|
1430
|
+
The **expansion** of a call is the search of Section 8.1 taken one level:
|
|
1431
|
+
the facts in the listing of its relation, in order, then the program's facts
|
|
1432
|
+
and backward rules of that name and arity, in clause order, each rule's body
|
|
1433
|
+
searched in its place, inner calls answered as above. The boundary's search
|
|
1434
|
+
**rests on** each table and listing it consults, and on those its tables and
|
|
1435
|
+
the closure checks of its listings consult, transitively. The boundary is
|
|
1436
|
+
settled when:
|
|
1437
|
+
|
|
1438
|
+
1. each table it rests on equals its expansion: the same number of answers,
|
|
1439
|
+
each identical up to renaming of variables to the answer in the same
|
|
1440
|
+
position;
|
|
1441
|
+
2. each listing it rests on has a step for each fact, every fact of the
|
|
1442
|
+
listed name and arity and ground, and is **closed**: for each forward
|
|
1443
|
+
rule with a head of that relation, each solution of the rule's body under
|
|
1444
|
+
the certificate, with the rule's witnesses bound to their Skolem terms
|
|
1445
|
+
(Section 8.2), gives head instances of that relation that are listed or
|
|
1446
|
+
are ground facts of the program;
|
|
1447
|
+
3. no table it rests on depends on itself through the tables its expansion
|
|
1448
|
+
consults;
|
|
1449
|
+
4. its outcome agrees: for a negation, `G` has no solution; for a collection
|
|
1450
|
+
`findall(T, G, L)`, `L` is an instance of the list of the instances of
|
|
1451
|
+
`T`, one per solution of `G`, in order, each renamed apart;
|
|
1452
|
+
5. no collection or `once` within its search, a table it rests on or a
|
|
1453
|
+
closure check uses a table whose answers rest on a listing, since the
|
|
1454
|
+
order of derived facts cannot be checked this way; and its search reaches
|
|
1455
|
+
no source inspection and no clause appended by a template, and it
|
|
1456
|
+
consults no listing whose relation a forward rule with a template head
|
|
1457
|
+
or captures concludes (Section 6.2).
|
|
1458
|
+
|
|
1459
|
+
For example, the absence `not(nonpacifist('ada'))` rests on the table
|
|
1460
|
+
`searched(nonpacifist('ada'), [])` and the listing `derived(nonpacifist(A),
|
|
1461
|
+
[nonpacifist('nixon')])`. The table equals its expansion: the listed fact
|
|
1462
|
+
does not match the call, and no backward rule defines `nonpacifist/1`. The
|
|
1463
|
+
listing is closed: the only rule concluding `nonpacifist/1` derives
|
|
1464
|
+
`nonpacifist('nixon')`, which is listed, and that fact has its own step.
|
|
1465
|
+
|
|
1466
|
+
A boundary fails C9 when its certificate is wrong: a table differs from its
|
|
1467
|
+
expansion, a listed fact has no step or another name or arity, a listing is
|
|
1468
|
+
not closed, tables depend on themselves, a search leads to an error, or a
|
|
1469
|
+
negation's goal has a solution. Each wrong table or listing is reported once,
|
|
1470
|
+
for the first boundary resting on it. A boundary whose certificate is
|
|
1471
|
+
missing, incomplete or not applicable under item 5, or a collection whose
|
|
1472
|
+
list does not agree, is not settled. A boundary that is not settled is
|
|
1473
|
+
trusted, including one that fails C9; C6 confronts each boundary C9 neither
|
|
1474
|
+
settled nor refuted with the evidence (Section 11.7).
|
|
1475
|
+
|
|
1476
|
+
### 11.11 Counts and validity
|
|
1426
1477
|
|
|
1427
1478
|
| Condition | Covered |
|
|
1428
1479
|
| --- | --- |
|
|
@@ -1431,20 +1482,21 @@ not covered by C8.
|
|
|
1431
1482
|
| C3 justification | steps |
|
|
1432
1483
|
| C4 coverage | claims plus uses |
|
|
1433
1484
|
| C5 re_decision | `'builtin'` and `'control'` steps that passed C5 |
|
|
1434
|
-
| C6 boundary_consistency | boundaries settled
|
|
1485
|
+
| C6 boundary_consistency | boundaries not settled that the evidence decided |
|
|
1435
1486
|
| C7 relevance | claims plus steps |
|
|
1436
1487
|
| C8 witness_integrity | `clause` steps with witnesses in their forward head or enclosing generators that passed C8 |
|
|
1488
|
+
| C9 search_closure | boundaries their search certificate settled or refuted |
|
|
1437
1489
|
|
|
1438
1490
|
A check also counts the **steps** it read, the **claims**, the `clause` steps
|
|
1439
1491
|
**verified** by C1, the `source` inspection steps also **verified** by C1,
|
|
1440
1492
|
the `'builtin'` steps **recomputed** by C5, the
|
|
1441
1493
|
`'control'` steps **composed** by C5, and the `'absent'` and `'collected'`
|
|
1442
|
-
steps **trusted**, those
|
|
1494
|
+
steps **trusted**, those C9 did not settle.
|
|
1443
1495
|
|
|
1444
1496
|
A proof is **valid** when no condition failed. A valid proof with trusted
|
|
1445
1497
|
boundaries is valid *conditional on* them.
|
|
1446
1498
|
|
|
1447
|
-
### 11.
|
|
1499
|
+
### 11.12 Scope of a valid proof
|
|
1448
1500
|
|
|
1449
1501
|
A valid proof establishes that each of its claims follows from the program
|
|
1450
1502
|
by the recorded steps, given its trusted boundaries; a settled boundary is
|
|
@@ -1453,20 +1505,56 @@ that the claims are all the conclusions of the program, that the program
|
|
|
1453
1505
|
derives no `'false'`, or that the program is the one intended: a proof MAY
|
|
1454
1506
|
leave conclusions out, and a run's own proof holds exactly its conclusions.
|
|
1455
1507
|
|
|
1508
|
+
### 11.13 Operational query fidelity
|
|
1509
|
+
|
|
1510
|
+
**Operational query fidelity** means that a claimed answer can be reported
|
|
1511
|
+
for an original question under Section 8, retaining its original call-time
|
|
1512
|
+
bindings, control choices and applicable forward state. Each claimed answer
|
|
1513
|
+
must be reachable in that question's ordered search. This is distinct from
|
|
1514
|
+
completeness: a proof may omit other reachable answers without falsifying
|
|
1515
|
+
the answers it does give.
|
|
1516
|
+
|
|
1517
|
+
C1–C9 check the recorded instances and their evidence. They do not establish
|
|
1518
|
+
operational query fidelity for binding-sensitive or order-sensitive goals.
|
|
1519
|
+
In particular, a checker MUST NOT treat C7's instance test, or C5's
|
|
1520
|
+
composition of a `once` step, as proof that the original open call selected
|
|
1521
|
+
that instance. For example:
|
|
1522
|
+
|
|
1523
|
+
```js
|
|
1524
|
+
fact(p('a'), p('b'))
|
|
1525
|
+
implied_by(q(X), once(p(X)))
|
|
1526
|
+
```
|
|
1527
|
+
|
|
1528
|
+
The question `q(X)` answers only `q('a')`. Nevertheless, a C1–C9 proof may
|
|
1529
|
+
justify `q('b')` with `once(p('b'))` and `p('b')`, since the specialized
|
|
1530
|
+
call `q('b')` succeeds. A final substitution does not show that the original
|
|
1531
|
+
call was `once(p(X))` with `X` unbound, or that its first answer was `'a'`.
|
|
1532
|
+
Tests of current variable state have the same distinction (Section 7.5).
|
|
1533
|
+
|
|
1534
|
+
A checker claiming the additional property MUST validate evidence of the
|
|
1535
|
+
original call state, propagation of bindings between ordered premises,
|
|
1536
|
+
freshening and scope, and any first-solution choice or required search
|
|
1537
|
+
closure. A claimed call state or substitution is not authority: it must
|
|
1538
|
+
follow from the original question, source clauses and checked evidence.
|
|
1539
|
+
It MUST preserve generator captures independently of later caller bindings
|
|
1540
|
+
and MUST NOT invoke the reasoner to fill gaps. No additional condition or
|
|
1541
|
+
evidence format for that property is defined by this specification; a
|
|
1542
|
+
C1–C9 verdict alone MUST NOT be presented as establishing it.
|
|
1543
|
+
|
|
1456
1544
|
## 12. Check Reports
|
|
1457
1545
|
|
|
1458
1546
|
A check report is a document (Section 9.1) beginning with the proof's claims,
|
|
1459
1547
|
in proof order, in canonical text, one per line, followed by a blank line and
|
|
1460
1548
|
the following report facts, one per line:
|
|
1461
1549
|
|
|
1462
|
-
1. `condition(Id, Name, Outcome, Covered)` for C1 to
|
|
1550
|
+
1. `condition(Id, Name, Outcome, Covered)` for C1 to C9, where `Outcome` is
|
|
1463
1551
|
`'ok'` or `failed(N)`, `N` the number of that condition's failures;
|
|
1464
1552
|
2. `failure(Condition, Subject, Detail)` per failure, where `Subject` is the
|
|
1465
1553
|
term concerned or `'proof_document'`, and `Detail` an atom;
|
|
1466
1554
|
3. `obligation(Kind, 'theory_scoped', Goal)` per trusted boundary, in step
|
|
1467
1555
|
order, where `Kind` is `'absent'` or `'collected'`;
|
|
1468
1556
|
4. `steps(N)`, `verified(N)`, `recomputed(N)`, `composed(N)`, `trusted(N)`,
|
|
1469
|
-
`claims(N)`, the counts of Section 11.
|
|
1557
|
+
`claims(N)`, the counts of Section 11.11;
|
|
1470
1558
|
5. `verdict(V)`, where `V` is `failed(N)` when `N` failures were recorded,
|
|
1471
1559
|
otherwise `'checked_with_obligations'` when there are obligations,
|
|
1472
1560
|
otherwise `'checked'`.
|
|
@@ -1476,15 +1564,16 @@ report is valid with no obligations. A valid report with obligations MUST
|
|
|
1476
1564
|
label them as conditional on those obligations. A failed report MUST label
|
|
1477
1565
|
them as unverified claims; their inclusion does not validate them. A valid
|
|
1478
1566
|
report with no claims MUST say it establishes no conclusions. Comments also
|
|
1479
|
-
explain the C1-
|
|
1567
|
+
explain the C1-C9 order, failures and obligations when present, the statistics,
|
|
1480
1568
|
and that the verdict does not establish completeness. Comments are informative
|
|
1481
1569
|
and MAY be worded differently. They are ignored when the document is read.
|
|
1482
1570
|
|
|
1483
1571
|
Failures are listed in the order they are found: those of reading the
|
|
1484
1572
|
document (Section 11.1), in document order; C4 for each claim, in claim
|
|
1485
1573
|
order; then for each step, in document order, C4 for its uses and the C1, C3,
|
|
1486
|
-
C5 or C8 failure of its justification;
|
|
1487
|
-
|
|
1574
|
+
C5 or C8 failure of its justification; for each boundary, in step order, the
|
|
1575
|
+
C9 failures of its search certificate in the order found, or else its C6
|
|
1576
|
+
failure; C7 for each claim, then
|
|
1488
1577
|
for each step, then for each table and listing, in document order; and C2.
|
|
1489
1578
|
|
|
1490
1579
|
`Detail` is informative text identifying what failed; its wording is not
|
|
@@ -1659,7 +1748,7 @@ including proofs, reports, goals and `facts_from` input, MUST be read as data
|
|
|
1659
1748
|
without executing code. A deployment accepting untrusted documents SHOULD
|
|
1660
1749
|
bound their size, nesting depth, processing time and memory, in addition to
|
|
1661
1750
|
the reasoning bounds of Section 8.3. A valid proof establishes only the
|
|
1662
|
-
claims and assumptions described in Section 11.
|
|
1751
|
+
claims and assumptions described in Section 11.12.
|
|
1663
1752
|
|
|
1664
1753
|
## Appendix A. Document Grammar
|
|
1665
1754
|
|
|
@@ -1742,8 +1831,8 @@ Its check report (Section 12):
|
|
|
1742
1831
|
type('socrates', 'mortal')
|
|
1743
1832
|
type('socrates', 'human')
|
|
1744
1833
|
|
|
1745
|
-
// C1-
|
|
1746
|
-
//
|
|
1834
|
+
// C1-C9: resolution, acyclicity, justification, coverage, re-decision,
|
|
1835
|
+
// boundary consistency, relevance, witness integrity and search closure.
|
|
1747
1836
|
condition('C1', 'resolution', 'ok', 3)
|
|
1748
1837
|
condition('C2', 'well_founded', 'ok', 3)
|
|
1749
1838
|
condition('C3', 'justification', 'ok', 3)
|
|
@@ -1752,6 +1841,7 @@ condition('C5', 're_decision', 'ok', 0)
|
|
|
1752
1841
|
condition('C6', 'boundary_consistency', 'ok', 0)
|
|
1753
1842
|
condition('C7', 'relevance', 'ok', 5)
|
|
1754
1843
|
condition('C8', 'witness_integrity', 'ok', 0)
|
|
1844
|
+
condition('C9', 'search_closure', 'ok', 0)
|
|
1755
1845
|
|
|
1756
1846
|
// Proof statistics: recorded steps and how they were checked.
|
|
1757
1847
|
steps(3)
|
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -9,7 +9,7 @@ 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 C1-
|
|
12
|
+
--check-proof FILE Print checked answers and a C1-C9 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
|
package/src/closure.js
CHANGED
|
@@ -390,19 +390,20 @@ export class Settler {
|
|
|
390
390
|
exact(callKey) {
|
|
391
391
|
const memo = this.exactness ??= new Map();
|
|
392
392
|
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(
|
|
393
|
+
// Finish each dependency before caching its parent. Reversing discovery
|
|
394
|
+
// order is insufficient when two branches share a dependency.
|
|
395
|
+
const frame = (item) => [item, [...this.tables.get(item).reliance.tables], 0];
|
|
396
|
+
const stack = [frame(callKey)];
|
|
397
|
+
while (stack.length) {
|
|
398
|
+
const top = stack[stack.length - 1];
|
|
399
|
+
if (top[2] < top[1].length) {
|
|
400
|
+
const next = top[1][top[2]++];
|
|
401
|
+
if (!memo.has(next)) stack.push(frame(next));
|
|
402
|
+
continue;
|
|
403
|
+
}
|
|
404
|
+
const reliance = this.tables.get(top[0]).reliance;
|
|
405
|
+
memo.set(top[0], !reliance.listings.size && top[1].every((item) => memo.get(item)));
|
|
406
|
+
stack.pop();
|
|
406
407
|
}
|
|
407
408
|
return memo.get(callKey);
|
|
408
409
|
}
|
package/src/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// Facts and rules are JavaScript. Forward rules materialize conclusions until
|
|
4
4
|
// a fixpoint, backward rules are decided when a goal asks for them, and every
|
|
5
5
|
// answer can come with a proof that a separate checker verifies against the
|
|
6
|
-
// program, condition by condition (C1-
|
|
6
|
+
// program, condition by condition (C1-C9).
|
|
7
7
|
export { VERSION } from './version.js';
|
|
8
8
|
export { Result, run, unusedClauses } from './engine.js';
|
|
9
9
|
export { readGoal } from './goals.js';
|
package/src/proof.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Proof documents: rendering, and checking C1-
|
|
1
|
+
// Proof documents: rendering, and checking C1-C9 against the source program.
|
|
2
2
|
//
|
|
3
3
|
// A proof document is JavaScript source, one expression per line: first the
|
|
4
4
|
// claims, then clause(N, Display) for every source clause the proof cites,
|
|
@@ -300,7 +300,7 @@ export function checkRendered(program, checkable, goals = null, allowTrusted = t
|
|
|
300
300
|
}
|
|
301
301
|
|
|
302
302
|
// Settle each negation and collection that is well formed by its search
|
|
303
|
-
// certificate (
|
|
303
|
+
// certificate (C9), before the steps are checked: a settled one is no
|
|
304
304
|
// obligation.
|
|
305
305
|
function settleBoundaries(program, steps, certificate, spellings) {
|
|
306
306
|
const settler = new Settler(program, {
|
|
@@ -327,8 +327,9 @@ function check(program, claims, steps, certificate, goals, allowTrusted, fail, s
|
|
|
327
327
|
fail.add('C4', `unjustified claim ${text(claim)}`, claim);
|
|
328
328
|
}
|
|
329
329
|
}
|
|
330
|
-
const
|
|
331
|
-
const
|
|
330
|
+
const provenance = new WitnessProvenance(program, steps, certificate, settlement.outcomes, spellings);
|
|
331
|
+
const tally = checkSteps(program, steps, allowTrusted, fail, spellings, name, settlement.outcomes, provenance);
|
|
332
|
+
const [confronted, closed] = checkBoundaries(program, steps, tally.boundaries, fail, settlement.outcomes, spellings);
|
|
332
333
|
checkRelevance(program, claims, steps, goals || [], fail, spellings, settlement, certificate);
|
|
333
334
|
checkWellFounded(steps, fail, spellings);
|
|
334
335
|
let uses = 0;
|
|
@@ -343,6 +344,7 @@ function check(program, claims, steps, certificate, goals, allowTrusted, fail, s
|
|
|
343
344
|
{ id: 'C6', name: 'boundary_consistency', covered: confronted, failed: failed('C6') },
|
|
344
345
|
{ id: 'C7', name: 'relevance', covered: claims.length + steps.size, failed: failed('C7') },
|
|
345
346
|
{ id: 'C8', name: 'witness_integrity', covered: tally.witnessed, failed: failed('C8') },
|
|
347
|
+
{ id: 'C9', name: 'search_closure', covered: closed, failed: failed('C9') },
|
|
346
348
|
];
|
|
347
349
|
return {
|
|
348
350
|
valid: !fail.items.length,
|
|
@@ -459,7 +461,7 @@ const CONTROL_BY = 'control';
|
|
|
459
461
|
// C4, C1, C3 and C5 for each step: every use is justified, and the step is an
|
|
460
462
|
// instance of the clause it cites, a recomputed primitive, a control composed
|
|
461
463
|
// of its uses, or a trusted boundary the later checks confront.
|
|
462
|
-
function checkSteps(program, steps, allowTrusted, fail, spellings, name, outcomes) {
|
|
464
|
+
function checkSteps(program, steps, allowTrusted, fail, spellings, name, outcomes, provenance) {
|
|
463
465
|
const tally = { verified: 0, redecided: 0, composed: 0, witnessed: 0, boundaries: [], trusted: [] };
|
|
464
466
|
|
|
465
467
|
function covered(goal) {
|
|
@@ -477,7 +479,7 @@ function checkSteps(program, steps, allowTrusted, fail, spellings, name, outcome
|
|
|
477
479
|
if (!covered(use)) fail.add('C4', `unjustified use ${text(use)}`, goal);
|
|
478
480
|
}
|
|
479
481
|
if (isTerm(by, 'clause', 1)) {
|
|
480
|
-
if (checkResolution(program, step, fail, tally)) tally.verified++;
|
|
482
|
+
if (checkResolution(program, step, fail, tally, provenance)) tally.verified++;
|
|
481
483
|
} else if (isTerm(by, 'source', 1)) {
|
|
482
484
|
const clause = clauseNamed(program, by.args[0]);
|
|
483
485
|
const inspected = clause === null ? null : program.inspectedById.get(clause.id);
|
|
@@ -490,19 +492,7 @@ function checkSteps(program, steps, allowTrusted, fail, spellings, name, outcome
|
|
|
490
492
|
fail.add('C3', 'invalid builtin justification', goal);
|
|
491
493
|
continue;
|
|
492
494
|
}
|
|
493
|
-
|
|
494
|
-
try {
|
|
495
|
-
for (const env of primitive(goal, new Env())) {
|
|
496
|
-
if (resolvesTo(goal, env, goal)) {
|
|
497
|
-
agrees = true;
|
|
498
|
-
break;
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
} catch (error) {
|
|
502
|
-
// A primitive that cannot be recomputed does not pass C5.
|
|
503
|
-
if (!(error instanceof EyemindError)) throw error;
|
|
504
|
-
}
|
|
505
|
-
if (!agrees) agrees = nearHostMath(goal);
|
|
495
|
+
const agrees = redecides(goal);
|
|
506
496
|
if (!agrees) fail.add('C5', `primitive disagrees: ${text(goal)}`, goal);
|
|
507
497
|
else tally.redecided++;
|
|
508
498
|
} else if (by === CONTROL_BY) {
|
|
@@ -519,7 +509,10 @@ function checkSteps(program, steps, allowTrusted, fail, spellings, name, outcome
|
|
|
519
509
|
tally.composed++;
|
|
520
510
|
}
|
|
521
511
|
} else if ((by === 'absent' && isTerm(goal, 'not', 1)) || (by === 'collected' && isTerm(goal, 'findall', 3))) {
|
|
522
|
-
if (bindings.length || uses.length)
|
|
512
|
+
if (bindings.length || uses.length) {
|
|
513
|
+
fail.add('C3', 'trusted boundaries cannot have bindings or uses', goal);
|
|
514
|
+
continue;
|
|
515
|
+
}
|
|
523
516
|
tally.boundaries.push(goal);
|
|
524
517
|
// A boundary its search certificate settles is checked, not trusted.
|
|
525
518
|
if (outcomes.get(spellings.spell(goal))?.status === 'settled') continue;
|
|
@@ -532,6 +525,17 @@ function checkSteps(program, steps, allowTrusted, fail, spellings, name, outcome
|
|
|
532
525
|
return tally;
|
|
533
526
|
}
|
|
534
527
|
|
|
528
|
+
function redecides(goal) {
|
|
529
|
+
try {
|
|
530
|
+
for (const env of primitive(goal, new Env())) {
|
|
531
|
+
if (resolvesTo(goal, env, goal)) return true;
|
|
532
|
+
}
|
|
533
|
+
} catch (error) {
|
|
534
|
+
if (!(error instanceof EyemindError)) throw error;
|
|
535
|
+
}
|
|
536
|
+
return nearHostMath(goal);
|
|
537
|
+
}
|
|
538
|
+
|
|
535
539
|
const isConstant = (term) => typeof term === 'string' || typeof term === 'bigint' || typeof term === 'number';
|
|
536
540
|
|
|
537
541
|
// Shortcuts the checker may take; tests turn them off to compare with the
|
|
@@ -588,7 +592,7 @@ function flatResolution(clause, goal, bindings, uses) {
|
|
|
588
592
|
// variables of that clause, and under them one of the clause's heads is the
|
|
589
593
|
// step's goal and its body is exactly the step's uses. C8 is checked under
|
|
590
594
|
// the same substitution.
|
|
591
|
-
function checkResolution(program, step, fail, tally) {
|
|
595
|
+
function checkResolution(program, step, fail, tally, provenance = null) {
|
|
592
596
|
const { goal, by, bindings, uses } = step;
|
|
593
597
|
const clauseId = by.args[0];
|
|
594
598
|
const clause = clauseNamed(program, clauseId);
|
|
@@ -630,11 +634,11 @@ function checkResolution(program, step, fail, tally) {
|
|
|
630
634
|
if (matches && resolvesTo(candidate, env, goal) && body.every((item, i) => resolvesTo(item, env, uses[i]))) {
|
|
631
635
|
resolution = true;
|
|
632
636
|
// Any head the step can be an instance of decides; a verified witness wins.
|
|
633
|
-
let found = clause.forward ? checkWitnesses(clause, head, names, env) : null;
|
|
634
|
-
for (const parentId of clause.scopeIds) {
|
|
637
|
+
let found = clause.forward && provenance !== null ? checkWitnesses(clause, head, body, names, env, provenance) : null;
|
|
638
|
+
for (const parentId of provenance === null ? [] : clause.scopeIds) {
|
|
635
639
|
const parent = program.byId.get(parentId);
|
|
636
640
|
const scopeHead = freshTerm(parent.head, `check${clauseId}`, names);
|
|
637
|
-
const checked = checkWitnesses(parent, scopeHead, names, env);
|
|
641
|
+
const checked = checkWitnesses(parent, scopeHead, body.slice(0, parent.body.length), names, env, provenance);
|
|
638
642
|
if (checked === false) found = false;
|
|
639
643
|
else if (checked === true && found === null) found = true;
|
|
640
644
|
}
|
|
@@ -646,7 +650,7 @@ function checkResolution(program, step, fail, tally) {
|
|
|
646
650
|
fail.add('C1', `not an instance of source clause ${clauseId}: ${text(goal)}`, goal);
|
|
647
651
|
return false;
|
|
648
652
|
}
|
|
649
|
-
if (witnesses === false) fail.add('C8', `witnesses do not match the source scopes of clause ${clauseId}: ${text(goal)}`, goal);
|
|
653
|
+
if (witnesses === false) fail.add('C8', `witnesses or their premise provenance do not match the source scopes of clause ${clauseId}: ${text(goal)}`, goal);
|
|
650
654
|
else if (witnesses === true) tally.witnessed++;
|
|
651
655
|
return true;
|
|
652
656
|
}
|
|
@@ -654,11 +658,11 @@ function checkResolution(program, step, fail, tally) {
|
|
|
654
658
|
// C8: under a step's substitution, each witness of a forward rule is the
|
|
655
659
|
// Skolem term of this firing, skolem(Rule, Variable, Arguments), where
|
|
656
660
|
// Arguments are the ground values of the conclusions' other variables, in
|
|
657
|
-
// order of first occurrence, leaving out
|
|
658
|
-
//
|
|
661
|
+
// order of first occurrence, leaving out fresh parameters only when their
|
|
662
|
+
// premise evidence establishes that provenance. Returns null when the
|
|
659
663
|
// rule has no witnesses, else whether they all hold; head is the rule's
|
|
660
664
|
// renamed conclusions and names maps its variables to their renamed ones.
|
|
661
|
-
function checkWitnesses(clause, head, names, env) {
|
|
665
|
+
function checkWitnesses(clause, head, body, names, env, provenance) {
|
|
662
666
|
const witnessed = clause.witnessNames;
|
|
663
667
|
if (!witnessed.length) return null;
|
|
664
668
|
// An existential firing needs bound inspection values. A generic rule
|
|
@@ -687,19 +691,170 @@ function checkWitnesses(clause, head, names, env) {
|
|
|
687
691
|
const expected = clause.captures === null ? [] : [listFromItems(
|
|
688
692
|
clause.captures.map((name) => copyResolved(names.get(name), env)),
|
|
689
693
|
)];
|
|
694
|
+
const introduced = new Set(witnessed.map((name) => names.get(name).name));
|
|
695
|
+
let contextual = false;
|
|
690
696
|
for (const variable of variables(head).values()) {
|
|
691
697
|
const value = copyResolved(variable, env);
|
|
692
698
|
if (isGround(value) && !ofThisFiring(value)) expected.push(value);
|
|
699
|
+
else if (!introduced.has(variable.name)) contextual = true;
|
|
700
|
+
}
|
|
701
|
+
return text(listFromItems(expected)) === text(firing) &&
|
|
702
|
+
(!contextual || provenance.check(clause, head, body, names, env, firing));
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
// A value may be omitted from a firing's context only when its apparent
|
|
706
|
+
// fresh symbols really are parameters of the premise derivation. Abstract
|
|
707
|
+
// those symbols together, then check the recorded evidence against the
|
|
708
|
+
// source again. In particular, abstracting a literal input Skolem constant
|
|
709
|
+
// must fail; its spelling does not make it a fresh value of this firing.
|
|
710
|
+
class WitnessProvenance {
|
|
711
|
+
constructor(program, steps, certificate, outcomes, spellings) {
|
|
712
|
+
this.program = program;
|
|
713
|
+
this.steps = steps;
|
|
714
|
+
this.certificate = certificate;
|
|
715
|
+
this.outcomes = outcomes;
|
|
716
|
+
this.spellings = spellings;
|
|
717
|
+
this.serial = 0;
|
|
718
|
+
this.usedNames = null;
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
fresh() {
|
|
722
|
+
if (this.usedNames === null) {
|
|
723
|
+
this.usedNames = new Map();
|
|
724
|
+
for (const step of this.steps.values()) {
|
|
725
|
+
for (const term of [step.goal, ...step.bindings, ...step.uses]) variables(term, this.usedNames);
|
|
726
|
+
}
|
|
727
|
+
for (const clause of this.program.clauses) {
|
|
728
|
+
for (const term of [clause.head, ...clause.body, ...clause.extraTerms]) variables(term, this.usedNames);
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
let name;
|
|
732
|
+
do { name = `\0witness${++this.serial}`; } while (this.usedNames.has(name));
|
|
733
|
+
return new Var(name);
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
check(clause, head, body, names, env, firing) {
|
|
737
|
+
const argumentsId = text(firing);
|
|
738
|
+
const symbols = new Map();
|
|
739
|
+
const copied = new Map();
|
|
740
|
+
const abstract = (term) => {
|
|
741
|
+
if (!(term instanceof Struct)) return term;
|
|
742
|
+
if (copied.has(term)) return copied.get(term);
|
|
743
|
+
let result;
|
|
744
|
+
if (isTerm(term, 'skolem', 3) && term.args[0] === BigInt(clause.id) && text(term.args[2]) === argumentsId) {
|
|
745
|
+
const id = text(term);
|
|
746
|
+
if (!symbols.has(id)) symbols.set(id, this.fresh());
|
|
747
|
+
result = symbols.get(id);
|
|
748
|
+
} else {
|
|
749
|
+
const args = term.args.map(abstract);
|
|
750
|
+
result = args.every((arg, i) => arg === term.args[i]) ? term : new Struct(term.name, args);
|
|
751
|
+
}
|
|
752
|
+
copied.set(term, result);
|
|
753
|
+
return result;
|
|
754
|
+
};
|
|
755
|
+
// Captures belong to an already-created instance, before this firing.
|
|
756
|
+
for (const name of clause.captures || []) {
|
|
757
|
+
const value = copyResolved(names.get(name), env);
|
|
758
|
+
if (abstract(value) !== value) return false;
|
|
759
|
+
}
|
|
760
|
+
const projected = abstract(copyResolved(new Struct('scope', [head, ...body]), env));
|
|
761
|
+
const source = new Struct('scope', [clause.head, ...clause.body]);
|
|
762
|
+
if (!isInstance(projected, source, 'provenance')) return false;
|
|
763
|
+
const pending = body.map((goal) => copyResolved(goal, env));
|
|
764
|
+
const seen = new Set();
|
|
765
|
+
const fail = new Failures();
|
|
766
|
+
while (pending.length) {
|
|
767
|
+
const original = pending.pop();
|
|
768
|
+
if (isTerm(original, 'and', 2)) {
|
|
769
|
+
pending.push(...flattenConjunction(original));
|
|
770
|
+
continue;
|
|
771
|
+
}
|
|
772
|
+
const goal = abstract(original);
|
|
773
|
+
if (goal === original) continue;
|
|
774
|
+
const id = this.spellings.spell(original);
|
|
775
|
+
if (seen.has(id)) continue;
|
|
776
|
+
seen.add(id);
|
|
777
|
+
const step = this.steps.get(id);
|
|
778
|
+
if (step === undefined) {
|
|
779
|
+
if (!isCallable(goal) || !(this.program.groups.get(key(goal)) || []).some((given) =>
|
|
780
|
+
!given.body.length && isInstance(goal, given.head, 'provenanceFact'))) return false;
|
|
781
|
+
continue;
|
|
782
|
+
}
|
|
783
|
+
if (isTerm(step.by, 'clause', 1)) {
|
|
784
|
+
const cited = clauseNamed(this.program, step.by.args[0]);
|
|
785
|
+
if (cited === null) return false;
|
|
786
|
+
if (cited.forward) {
|
|
787
|
+
// A premise's derived fact already exists. Its ground values are
|
|
788
|
+
// data, and only its universal variables may be instantiated.
|
|
789
|
+
if (!isInstance(goal, step.goal, 'provenanceDerived')) return false;
|
|
790
|
+
continue;
|
|
791
|
+
}
|
|
792
|
+
if (!this.fixedScopes(cited, step, abstract)) return false;
|
|
793
|
+
const generalized = { ...step, goal, bindings: step.bindings.map(abstract), uses: step.uses.map(abstract) };
|
|
794
|
+
// Original steps receive their own C8 checks. Here only source
|
|
795
|
+
// resolution is repeated, under the one shared abstraction.
|
|
796
|
+
if (!checkResolution(this.program, generalized, fail, { witnessed: 0 })) return false;
|
|
797
|
+
pending.push(...step.uses);
|
|
798
|
+
} else if (isTerm(step.by, 'source', 1)) {
|
|
799
|
+
const cited = clauseNamed(this.program, step.by.args[0]);
|
|
800
|
+
const inspected = cited === null ? null : this.program.inspectedById.get(cited.id);
|
|
801
|
+
if (!inspected || step.bindings.length || step.uses.length || !isInspection(goal) ||
|
|
802
|
+
!isInstance(goal, inspected.term, 'provenanceInspection')) return false;
|
|
803
|
+
} else if (step.by === BUILTIN_BY) {
|
|
804
|
+
if (step.bindings.length || step.uses.length || !isCallable(goal) ||
|
|
805
|
+
!PRIMITIVE_KEYS.has(key(goal)) || !redecides(goal)) return false;
|
|
806
|
+
} else if (step.by === CONTROL_BY) {
|
|
807
|
+
const candidates = isTerm(goal, 'call', 1) || isTerm(goal, 'once', 1) ? [goal.args[0]]
|
|
808
|
+
: isTerm(goal, 'or', 2) ? goal.args : [];
|
|
809
|
+
const uses = step.uses.map(abstract);
|
|
810
|
+
if (step.bindings.length || !candidates.some((candidate) => {
|
|
811
|
+
const parts = flattenConjunction(candidate);
|
|
812
|
+
return parts.length === uses.length && parts.every((part, i) => text(part) === text(uses[i]));
|
|
813
|
+
})) return false;
|
|
814
|
+
pending.push(...step.uses);
|
|
815
|
+
} else if (isBoundary(step)) {
|
|
816
|
+
// Generalizing a trusted assumption would silently strengthen it.
|
|
817
|
+
// Only the already-consulted certificate may discharge a stronger
|
|
818
|
+
// boundary; missing evidence fails provenance instead.
|
|
819
|
+
const outcome = this.outcomes.get(id);
|
|
820
|
+
if (outcome?.status !== 'settled') return false;
|
|
821
|
+
const tables = new Set(outcome.tables);
|
|
822
|
+
const listings = new Set(outcome.listings);
|
|
823
|
+
const settler = new Settler(this.program, {
|
|
824
|
+
answers: (call) => tables.has(variant(call)) ? this.certificate.tables.get(variant(call)) : null,
|
|
825
|
+
facts: (goalKey) => listings.has(goalKey) ? this.certificate.listings.get(goalKey) : null,
|
|
826
|
+
supported: (fact) => this.steps.has(this.spellings.spell(fact)),
|
|
827
|
+
});
|
|
828
|
+
if (settler.settle(goal).status !== 'settled') return false;
|
|
829
|
+
} else return false;
|
|
830
|
+
}
|
|
831
|
+
return true;
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
fixedScopes(clause, step, abstract) {
|
|
835
|
+
if (!clause.scopeIds.length) return true;
|
|
836
|
+
const [head, body, names] = freshClause(clause, 'provenanceScope');
|
|
837
|
+
const env = new Env();
|
|
838
|
+
for (const pair of step.bindings) {
|
|
839
|
+
if (!names.has(pair.args[0]) || !unify(names.get(pair.args[0]), pair.args[1], env)) return false;
|
|
840
|
+
}
|
|
841
|
+
if (!unify(head, step.goal, env) || body.length !== step.uses.length ||
|
|
842
|
+
!body.every((goal, i) => unify(goal, step.uses[i], env))) return false;
|
|
843
|
+
for (const term of clause.extraTerms) {
|
|
844
|
+
const value = copyResolved(freshTerm(term, 'provenanceScope', names), env);
|
|
845
|
+
if (abstract(value) !== value) return false;
|
|
846
|
+
}
|
|
847
|
+
return true;
|
|
693
848
|
}
|
|
694
|
-
return text(listFromItems(expected)) === text(firing);
|
|
695
849
|
}
|
|
696
850
|
|
|
697
|
-
// C6
|
|
698
|
-
// fails
|
|
699
|
-
// evidence at hand can refute it. An absence fails
|
|
700
|
-
// of this certificate or a recomputed primitive is
|
|
701
|
-
// fails when such a solution is missing from its
|
|
702
|
-
//
|
|
851
|
+
// C9 and C6. A boundary its search certificate settles holds, and one whose
|
|
852
|
+
// certificate is wrong fails C9. Without a settling certificate a boundary
|
|
853
|
+
// cannot be proved, but evidence at hand can refute it (C6). An absence fails
|
|
854
|
+
// when a source fact, a step of this certificate or a recomputed primitive is
|
|
855
|
+
// a solution; a collection fails when such a solution is missing from its
|
|
856
|
+
// list. Returns how many boundaries the evidence could speak for, and how
|
|
857
|
+
// many their certificates settled or refuted.
|
|
703
858
|
function checkBoundaries(program, steps, boundaries, fail, outcomes, spellings) {
|
|
704
859
|
const stepGoals = new Map();
|
|
705
860
|
for (const step of steps.values()) {
|
|
@@ -711,6 +866,7 @@ function checkBoundaries(program, steps, boundaries, fail, outcomes, spellings)
|
|
|
711
866
|
}
|
|
712
867
|
let serial = 0;
|
|
713
868
|
let confronted = 0;
|
|
869
|
+
let closed = 0;
|
|
714
870
|
const nextSerial = () => ++serial;
|
|
715
871
|
|
|
716
872
|
// Each solution of a simple goal that the evidence shows, or null when the
|
|
@@ -746,8 +902,8 @@ function checkBoundaries(program, steps, boundaries, fail, outcomes, spellings)
|
|
|
746
902
|
for (const boundary of boundaries) {
|
|
747
903
|
const outcome = outcomes.get(spellings.spell(boundary));
|
|
748
904
|
if (outcome !== undefined && outcome.status !== 'unsettled') {
|
|
749
|
-
|
|
750
|
-
for (const [detail, term] of outcome.failures) fail.add('
|
|
905
|
+
closed++;
|
|
906
|
+
for (const [detail, term] of outcome.failures) fail.add('C9', detail, term);
|
|
751
907
|
continue;
|
|
752
908
|
}
|
|
753
909
|
if (isTerm(boundary, 'not', 1)) {
|
|
@@ -786,7 +942,7 @@ function checkBoundaries(program, steps, boundaries, fail, outcomes, spellings)
|
|
|
786
942
|
}
|
|
787
943
|
}
|
|
788
944
|
}
|
|
789
|
-
return confronted;
|
|
945
|
+
return [confronted, closed];
|
|
790
946
|
}
|
|
791
947
|
|
|
792
948
|
// C7: the certificate answers the question that was asked and carries nothing
|
|
@@ -923,8 +1079,8 @@ export function checkReport(report) {
|
|
|
923
1079
|
: report.trusted.length ? '// Answers checked subject to the obligations below.'
|
|
924
1080
|
: '// Checked answers: these follow from the input program.';
|
|
925
1081
|
const lines = [heading, ...report.answers, '',
|
|
926
|
-
'// C1-
|
|
927
|
-
'//
|
|
1082
|
+
'// C1-C9: resolution, acyclicity, justification, coverage, re-decision,',
|
|
1083
|
+
'// boundary consistency, relevance, witness integrity and search closure.'];
|
|
928
1084
|
let previous = null;
|
|
929
1085
|
for (const fact of facts) {
|
|
930
1086
|
if (fact.name === 'failure' && previous !== 'failure') {
|
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.3.
|
|
2
|
+
export const VERSION = '0.3.2';
|