eyemind 0.2.4 → 0.2.6
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 +1 -1
- package/SPEC.md +114 -36
- package/package.json +1 -1
- package/src/builtins.js +4 -2
- package/src/lang.js +6 -4
- package/src/program.js +6 -1
- package/src/reader.js +1 -0
- package/src/version.js +1 -1
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ JavaScript library, and a browser application, with no dependencies.
|
|
|
18
18
|
- **[Examples](https://eyereasoner.github.io/eyemind/examples/)**:
|
|
19
19
|
94 runnable programs, each with a card deck and saved conclusions, proofs
|
|
20
20
|
and check reports.
|
|
21
|
-
- **[Conformance suite](conformance/)**:
|
|
21
|
+
- **[Conformance suite](conformance/)**: 1270 cases that test any
|
|
22
22
|
implementation of the specification through its command line.
|
|
23
23
|
Run the suite [in your browser](https://eyereasoner.github.io/eyemind/playground/conformance).
|
|
24
24
|
|
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.2.
|
|
5
|
+
Version: eyemind 0.2.6
|
|
6
6
|
```
|
|
7
7
|
|
|
8
8
|
This document specifies the syntax and meaning of eyemind programs and data
|
|
@@ -165,7 +165,8 @@ Lists use bracket syntax:
|
|
|
165
165
|
For example, `[1, 2]` and `[1, ...[2]]` denote the same list. A **proper
|
|
166
166
|
list** ends in `[]`. A tail left as a variable gives an **open list**;
|
|
167
167
|
a non-list tail gives an **improper list**. Only the final item may be a
|
|
168
|
-
spread tail
|
|
168
|
+
spread tail; a program that spreads a logical variable or compound before
|
|
169
|
+
the last item, as in `[...T, 1]`, MUST raise an error. In document syntax, `[...Tail]` denotes `Tail` itself.
|
|
169
170
|
Program spread expressions also follow Section 3.3.
|
|
170
171
|
|
|
171
172
|
The empty list is the atom whose text is `[]`, so `'[]'` denotes the same
|
|
@@ -211,7 +212,10 @@ A program consists of one or more non-strict JavaScript scripts. Each script
|
|
|
211
212
|
may use JavaScript declarations, expressions, functions and control flow to
|
|
212
213
|
construct its clauses. No import is required for the statements and term
|
|
213
214
|
constructors defined here. Clauses are stated in the order their statement
|
|
214
|
-
calls occur; multiple input scripts are processed in input order.
|
|
215
|
+
calls occur; multiple input scripts are processed in input order. Each
|
|
216
|
+
script runs in a scope of its own: a name one script declares is, in
|
|
217
|
+
another script, resolved as Section 3.2 specifies, so scripts share no
|
|
218
|
+
declarations.
|
|
215
219
|
|
|
216
220
|
The supplied names are the statements of Section 3.4, `forward`, `backward`,
|
|
217
221
|
`preds`, `vars`, `struct`, the controls and primitives of Section 4, the
|
|
@@ -247,7 +251,9 @@ names `step`, `clause`, `activated`, `forward`, `backward`, `struct`,
|
|
|
247
251
|
|
|
248
252
|
A top-level expression statement that calls a predicate supplied by rule 4,
|
|
249
253
|
such as a misspelled `fcat(p(1))`, states nothing; a loader MUST report it as
|
|
250
|
-
an error rather than ignore it.
|
|
254
|
+
an error rather than ignore it. Only statements at the top level of a script
|
|
255
|
+
are checked: inside a function or a block, such a call builds a term the
|
|
256
|
+
script discards, and a loader MAY accept it.
|
|
251
257
|
|
|
252
258
|
### 3.3 Term construction
|
|
253
259
|
|
|
@@ -268,6 +274,9 @@ reading a data document (Section 9.1).
|
|
|
268
274
|
| `[]`, `[T1, ..., Tn]`, `[Head, ...Tail]` | Lists (Section 2.2). |
|
|
269
275
|
|
|
270
276
|
Thus `2.0` in a program is an integer; use `float(2)` for the float `2.0`.
|
|
277
|
+
Applied to anything other than a JavaScript number, such as a `BigInt`, a
|
|
278
|
+
string or a variable, `float(...)` is the ordinary compound `float/1`, the
|
|
279
|
+
arithmetic function of Section 5.2: `is(Y, float(2n))` binds `Y` to `2.0`.
|
|
271
280
|
Use a `BigInt` literal for an integer outside JavaScript's exact number
|
|
272
281
|
range, for example `9007199254740993n`. Numeric expressions are evaluated by
|
|
273
282
|
JavaScript before conversion to terms.
|
|
@@ -353,7 +362,9 @@ statement call begins; facts read by `facts_from` use that call's line.
|
|
|
353
362
|
|
|
354
363
|
A clause MUST be rejected when:
|
|
355
364
|
|
|
356
|
-
- a head is not an atom or compound
|
|
365
|
+
- a head is not an atom or compound, or is a list, the atom `'[]'` or a
|
|
366
|
+
`'.'/2` compound, which as a goal would be a conjunction (Section 4.1) and
|
|
367
|
+
could never call the clause;
|
|
357
368
|
- a head uses `step/4` or `clause/2`, reserved for proof documents, or
|
|
358
369
|
explicitly states the reserved predicate `activated/2`;
|
|
359
370
|
- a head is a primitive or control, except the head `'true'` of a query or
|
|
@@ -373,7 +384,15 @@ specified in Section 6.
|
|
|
373
384
|
|
|
374
385
|
A goal is an atom, a compound, a variable to be bound to a callable term,
|
|
375
386
|
or a non-empty proper array of goals denoting their conjunction. A number,
|
|
376
|
-
an empty array or an open or improper list is not a goal.
|
|
387
|
+
an empty array or an open or improper list is not a goal. An array of one
|
|
388
|
+
goal denotes that goal: `[p(X)]` is `p(X)`. Arrays of several goals denote
|
|
389
|
+
the left-nested `and` chain, also in goal text, so the goal text
|
|
390
|
+
`once([p(X), q(X)])` is answered as `once(and(p(1), q(1)))`.
|
|
391
|
+
|
|
392
|
+
A variable called as a goal MUST be bound when it runs: an unbound variable,
|
|
393
|
+
or one bound to a number, MUST raise an error. A variable bound to an atom or
|
|
394
|
+
compound calls that term as it is; a list bound at run time is the compound
|
|
395
|
+
`'.'/2`, not a conjunction, and so has no solution.
|
|
377
396
|
|
|
378
397
|
Array-to-conjunction notation applies in these positions:
|
|
379
398
|
|
|
@@ -451,13 +470,13 @@ primitive called outside its patterns raises an error.
|
|
|
451
470
|
| `is_atom(@X)`, `is_number(@X)` | | `X` is an atom, or a number. |
|
|
452
471
|
| `is_int(@X)`, `is_float(@X)` | | `X` is an integer, or a float. |
|
|
453
472
|
| `is_compound(@X)` | | `X` is a compound; a non-empty list is one. |
|
|
454
|
-
| `functor` | `functor(+T, ?N, ?A)`, `functor(-T, +N, +A)` | Name and arity of `T`, or `T` built with fresh variable arguments. When constructing, `A` MUST be an integer from 0 to 1024. |
|
|
455
|
-
| `arg` | `arg(+N, +T, ?A)` | `A` is the `N`th argument of `T`, counting from 1. |
|
|
456
|
-
| `univ` | `univ(+T, ?L)`, `univ(-T, +L)` | `L` is the list of `T`'s name and arguments. |
|
|
473
|
+
| `functor` | `functor(+T, ?N, ?A)`, `functor(-T, +N, +A)` | Name and arity of `T`, or `T` built with fresh variable arguments. When constructing, `A` MUST be an integer from 0 to 1024; with `A` 0, `N` MUST be atomic and `T` is `N` itself, so `functor(T, 3, 0)` gives `3`; with `A` above 0, `N` MUST be an atom. |
|
|
474
|
+
| `arg` | `arg(+N, +T, ?A)` | `A` is the `N`th argument of `T`, counting from 1. `N` MUST be an integer from 1 to 1024. An atomic `T`, or an `N` above `T`'s arity, has no such argument, and `arg` fails. |
|
|
475
|
+
| `univ` | `univ(+T, ?L)`, `univ(-T, +L)` | `L` is the list of `T`'s name and arguments; for atomic `T`, `[T]`. When constructing, `L` MUST be a non-empty proper list whose first element is an atom, or a one-element list of a number; a partial list raises an error. |
|
|
457
476
|
| `atom_chars` | `atom_chars(+A, ?L)`, `atom_chars(-A, +L)` | `L` is the list of `A`'s characters as atoms. |
|
|
458
|
-
| `atom_codes` | `atom_codes(+A, ?L)`, `atom_codes(-A, +L)` | `L` is the list of `A`'s character code points. |
|
|
477
|
+
| `atom_codes` | `atom_codes(+A, ?L)`, `atom_codes(-A, +L)` | `L` is the list of `A`'s character code points. Each code MUST be an integer from 0 to 1114111 (0x10FFFF); a code of a lone surrogate gives that lone surrogate. |
|
|
459
478
|
| `atom_length` | `atom_length(+A, ?N)` | `N` is the number of characters of `A`. |
|
|
460
|
-
| `number_chars` | `number_chars(?N, +L)`, `number_chars(+N, -L)` | A bound `L` is read as a number: an optional sign and decimal digits give an integer, and with a fraction or an exponent a float, as in `'007'`, `'-21.5'`, `'.5'` and `'
|
|
479
|
+
| `number_chars` | `number_chars(?N, +L)`, `number_chars(+N, -L)` | A bound `L` is read as a number: an optional sign and decimal digits give an integer, and with a fraction or an exponent a float, as in `'007'`, `'-21.5'`, `'.5'`, `'1.'` and `'2E-2'`; other text fails, as does text whose value is too large for a finite float, such as `'1e400'`. Otherwise `L` spells `N` in its canonical text (Section 9.2). |
|
|
461
480
|
| `atom_concat` | `atom_concat(+A, +B, ?AB)`, `atom_concat(?A, ?B, +AB)` | `AB` is `A` followed by `B`; with `AB` given, every split, shortest `A` first. |
|
|
462
481
|
|
|
463
482
|
A character is a Unicode code point. Every primitive except `atom_concat` has
|
|
@@ -525,14 +544,16 @@ Integer arithmetic is exact and unbounded. Integer operands give an integer
|
|
|
525
544
|
result except for `div`, a negative exponent in `pow`, and functions defined
|
|
526
545
|
to return a float. Mixed `add`, `sub`, `mul`, `div`, `floordiv`, `mod` and
|
|
527
546
|
`pow` give a float. Integer-conversion functions return integers; `min` and
|
|
528
|
-
`max` return the selected operand with its original kind
|
|
547
|
+
`max` return the selected operand with its original kind, and among equal
|
|
548
|
+
operands the first: `min(1, 1.0)` is `1` and `min(1.0, 1)` is `1.0`. No operation
|
|
529
549
|
implicitly makes an integer and a float unify.
|
|
530
550
|
|
|
531
551
|
`floordiv` rounds down and `mod` has the divisor's sign:
|
|
532
552
|
`floordiv(-7, 3)` is -3 and `mod(-7, 3)` is 2. `div` of integers rounds
|
|
533
553
|
their exact quotient once to the nearest binary64 value, with halfway cases
|
|
534
554
|
rounded to even, including in the subnormal range. Underflow to zero keeps
|
|
535
|
-
the sign
|
|
555
|
+
the sign, and a zero quotient has the sign binary64 division gives it:
|
|
556
|
+
`div(0, -5)` is `-0.0`. `sqrt(-0.0)` is `-0.0`. `round(X)` gives an integer; `round(X, Digits)` rounds to the
|
|
536
557
|
specified number of decimal places. Float spelling is defined in Section 9.2.
|
|
537
558
|
|
|
538
559
|
Numeric comparison is exact across integers and floats. Bitwise operations
|
|
@@ -541,8 +562,10 @@ use unbounded two's-complement integers.
|
|
|
541
562
|
### 5.4 Arithmetic errors and limits
|
|
542
563
|
|
|
543
564
|
An evaluation MUST raise an error, rather than produce a value, on a division
|
|
544
|
-
or modulo by zero, a domain error (such as `sqrt(-1)
|
|
545
|
-
|
|
565
|
+
or modulo by zero, a domain error (such as `sqrt(-1)`, `log(0)`, or a
|
|
566
|
+
logarithm `log(X, B)` whose `X` or base `B` is not positive or whose `B` is
|
|
567
|
+
1), a bitwise operation, `isqrt`, `gcd` or `lcm` on a float, a negative shift
|
|
568
|
+
count, when the result
|
|
546
569
|
is not a finite real number,
|
|
547
570
|
or when a power or left shift would need more than 2^26 bits: for a power of
|
|
548
571
|
integers `pow(A, B)` with `B > 0` and `abs(A) > 1`, when `B` times the bit
|
|
@@ -637,7 +660,8 @@ intermediate enabling steps: the generator's premises are direct uses of
|
|
|
637
660
|
the derived rule's step. A nested instance retains all enclosing premises.
|
|
638
661
|
|
|
639
662
|
For witness construction, a generating head's **scope projection** replaces
|
|
640
|
-
each template conjunct by the list of its captured variables,
|
|
663
|
+
each template conjunct by the list of its captured variables, in order of
|
|
664
|
+
their first occurrence in the template as written, leaving ordinary
|
|
641
665
|
heads in place. These lists are compiler data and are never concluded as
|
|
642
666
|
facts. Only variables of this projection participate in that firing's witness
|
|
643
667
|
construction (Section 8.2). A witness introduced by the generator remains
|
|
@@ -812,7 +836,10 @@ In a round, clauses run in clause order. An appended clause runs its derived
|
|
|
812
836
|
instances in the order they were created; a potential clause with no instance
|
|
813
837
|
is skipped. Each instance searches only its own body with its captures bound.
|
|
814
838
|
All instances of one clause search the same current state, and all solutions
|
|
815
|
-
are collected before any conclusion of that clause is published
|
|
839
|
+
are collected before any conclusion of that clause is published. They are
|
|
840
|
+
published solution by solution, in the order found, and the heads of each
|
|
841
|
+
solution in their stated order: `implies(p(X), [a(X), b(X)])` over `p(1)`
|
|
842
|
+
and `p(2)` publishes `a(1)`, `b(1)`, `a(2)`, `b(2)`. For each head:
|
|
816
843
|
|
|
817
844
|
- a head variable the solution leaves unbound is bound to a **Skolem term**
|
|
818
845
|
`skolem(Rule, Variable, Arguments)`: `Rule` is the clause number of the
|
|
@@ -864,13 +891,30 @@ A run is bounded by `max_depth`, the depth of nested rule bodies (default
|
|
|
864
891
|
1000000), by `max_inferences`, the number of goals started (default
|
|
865
892
|
1000000), and by `max_iterations`, the rounds per stratum (default 1000).
|
|
866
893
|
Exceeding a bound MUST raise an error; a partial result MUST NOT be returned
|
|
867
|
-
as complete.
|
|
894
|
+
as complete. The bounds count as follows:
|
|
895
|
+
|
|
896
|
+
- A goal solved by a rule is one level deeper than the goal whose body it is
|
|
897
|
+
in, and a goal asked from outside or a forward rule's premise is at level
|
|
898
|
+
0; solving a goal through more than `max_depth` nested rule bodies exceeds
|
|
899
|
+
the bound. A goal solved by a fact adds no level.
|
|
900
|
+
- Every goal the search starts counts once toward `max_inferences`,
|
|
901
|
+
including each conjunction, control and primitive, in forward premises as
|
|
902
|
+
in goals: `[p(X), p(Y)]` against one fact starts three goals.
|
|
903
|
+
- Every forward round of a stratum counts toward `max_iterations`,
|
|
904
|
+
including the final round that adds nothing; a stratum without forward
|
|
905
|
+
rules has no rounds.
|
|
906
|
+
|
|
907
|
+
A run that exceeds a bound concludes nothing: the command line writes no
|
|
908
|
+
conclusions to standard output, even answers found before the bound was
|
|
909
|
+
reached, and exits with code 1 (Section 13.1).
|
|
868
910
|
|
|
869
911
|
Each supplied bound MUST be a positive integer no greater than 9007199254740991.
|
|
870
912
|
|
|
871
913
|
### 8.4 External goals
|
|
872
914
|
|
|
873
|
-
A run MAY be given goals.
|
|
915
|
+
A run MAY be given goals. Each goal is read on its own, so goals share no
|
|
916
|
+
variables: `p(X)` and `q(X)` given separately ask two unrelated questions.
|
|
917
|
+
After forward reasoning, each goal is solved in
|
|
874
918
|
turn, and each solution is reported as the instance of its goal, unless an
|
|
875
919
|
instance identical up to renaming of its variables was already reported for
|
|
876
920
|
this goal or an earlier one of the same run.
|
|
@@ -935,7 +979,8 @@ expression per line. Readers accept exactly:
|
|
|
935
979
|
float literal containing a point or exponent: a number;
|
|
936
980
|
- a name: the variable of that name, where each `_` is a new anonymous
|
|
937
981
|
variable (Section 4.2) and a name starting with `VAR_` is decoded
|
|
938
|
-
(Section 9.2), with malformed encodings rejected;
|
|
982
|
+
(Section 9.2), with malformed encodings rejected; a decoded name is a
|
|
983
|
+
named variable even when it is `_`, so `VAR___` twice is one variable;
|
|
939
984
|
- a call of a plain name: the compound, or the atom when there are no
|
|
940
985
|
arguments; `struct('name', ...)` as in Section 9.3; `and` and `or` with
|
|
941
986
|
more than two arguments as in Section 4.2;
|
|
@@ -951,7 +996,12 @@ outside these forms MUST be rejected, including operators other than a
|
|
|
951
996
|
numeric minus, property or subscript access, spread call arguments,
|
|
952
997
|
assignments, declarations, functions and template literals. Numeric literals
|
|
953
998
|
MUST be decimal without separators; integers other than `0` MUST NOT start
|
|
954
|
-
with `0
|
|
999
|
+
with `0`, and neither may the digits before a float's point or exponent, so
|
|
1000
|
+
`00.5` and `05.5` MUST be rejected while `0.5` and `0e1` are floats. A float
|
|
1001
|
+
literal denotes the nearest binary64 value: one that underflows reads as a
|
|
1002
|
+
zero of its sign, as `1e-400` reads as `0.0`, and one whose value is too
|
|
1003
|
+
large for a finite float MUST be rejected. Reading canonical text MUST
|
|
1004
|
+
recover the original term.
|
|
955
1005
|
|
|
956
1006
|
A call's name and opening `(` MUST NOT be separated by a line feed outside
|
|
957
1007
|
a comment. The same restriction applies between a numeric minus and its
|
|
@@ -967,7 +1017,9 @@ conjunction rules of Section 4.1.
|
|
|
967
1017
|
String escapes are `\\`, `\'`, `\"`, `\n`, `\r`, `\t`, `\b`, `\f`,
|
|
968
1018
|
`\v`, `\0` (not followed by a decimal digit), `\xHH`, `\uHHHH` and
|
|
969
1019
|
`\u{H...}` with one to six hexadecimal digits denoting a Unicode code point.
|
|
970
|
-
Other escapes and raw line breaks in strings MUST be rejected
|
|
1020
|
+
Other escapes and raw line breaks in strings MUST be rejected; a raw line
|
|
1021
|
+
break is a line feed or a carriage return, while the characters U+2028 and
|
|
1022
|
+
U+2029 are allowed in a string as themselves. Outside
|
|
971
1023
|
strings, layout consists of spaces, tabs, carriage returns, line feeds and
|
|
972
1024
|
the byte-order-mark character, plus comments. A line feed outside brackets
|
|
973
1025
|
ends the current expression statement.
|
|
@@ -1062,6 +1114,9 @@ array of heads, and `G1, ...` are the body goals themselves. Displays are not
|
|
|
1062
1114
|
authority: a checker MUST compare each with the program it checks against.
|
|
1063
1115
|
|
|
1064
1116
|
Each argument of a multi-argument `fact` has its own `fact(Head)` display.
|
|
1117
|
+
A body is displayed with its conjunctions flattened (Section 3.5), whether
|
|
1118
|
+
the program wrote them as arrays or with `and`: `implied_by(r, and(a, b))`
|
|
1119
|
+
has display `implied_by('r', ['a', 'b'])`.
|
|
1065
1120
|
Conjunctive query and contradiction bodies are displayed as separate goal
|
|
1066
1121
|
arguments: `query([p(X), q(X)])` has display `query(p(X), q(X))`.
|
|
1067
1122
|
|
|
@@ -1090,12 +1145,14 @@ order. `By` is one of:
|
|
|
1090
1145
|
| `clause(N)` | `Goal` is an instance of a head of clause `N`, a fact or a rule, whose body instance is `Uses`. | the clause's variables | the body instance, empty for a fact |
|
|
1091
1146
|
| `source(N)` | `Goal` is an instance of the inspectable source rule `N` as `implies(Body, Head)` or `implied_by(Head, Body)`. | empty | empty |
|
|
1092
1147
|
| `'builtin'` | `Goal` is a primitive that holds. | empty | empty |
|
|
1093
|
-
| `'control'` | `Goal` is `call`, `once` or a disjunction, solved by `Uses`. | empty | the solved goals |
|
|
1148
|
+
| `'control'` | `Goal` is `call`, `once` or a disjunction, solved by `Uses`. | empty | the solved goals; for a disjunction, the side that was solved, so `or(or(A, B), C)` solved by `A` uses `or(A, B)`, which has a step of its own |
|
|
1094
1149
|
| `'absent'` | `Goal` is a negation taken on trust. | empty | empty |
|
|
1095
1150
|
| `'collected'` | `Goal` is a `findall` taken on trust. | empty | empty |
|
|
1096
1151
|
|
|
1097
1152
|
`Bindings` is an object from each variable name of the cited clause, as
|
|
1098
|
-
the program wrote it, to its value in this step: `{X: 'socrates'}`. A
|
|
1153
|
+
the program wrote it, to its value in this step: `{X: 'socrates'}`. A key
|
|
1154
|
+
that is a plain name of Section 9.2 is written bare, and any other name as a
|
|
1155
|
+
string, such as `{'A-B': 1}`. A
|
|
1099
1156
|
reasoner writes every variable of the clause, in the order the clause display
|
|
1100
1157
|
first shows them (for `implies`, the premise first);
|
|
1101
1158
|
a checker MUST accept partial bindings when the goal and uses determine the
|
|
@@ -1118,22 +1175,25 @@ detail and, where there is one, the term concerned.
|
|
|
1118
1175
|
|
|
1119
1176
|
The document MUST read (Section 9.1); otherwise C3 fails and the document has
|
|
1120
1177
|
no claims and no steps. Each `clause(N, Display)` MUST name a clause of the
|
|
1121
|
-
program whose display (Section 10.2) is identical to `Display
|
|
1122
|
-
|
|
1178
|
+
program whose display (Section 10.2) is identical to `Display`, variable
|
|
1179
|
+
names included, so a display that merely renames the clause's variables
|
|
1180
|
+
differs; otherwise C1 fails. Each `step` MUST have bindings that read as a list of `'='/2` pairs,
|
|
1123
1181
|
as an object literal does, and a list of uses, and no two steps may have
|
|
1124
1182
|
identical goals; otherwise C3 fails and the step is set aside. Every other
|
|
1125
1183
|
statement is a claim (Section 10.1).
|
|
1126
1184
|
|
|
1127
1185
|
### 11.2 C1 Resolution
|
|
1128
1186
|
|
|
1129
|
-
For a `clause(N)` step, `N` MUST be a clause of the program
|
|
1187
|
+
For a `clause(N)` step, `N` MUST be a clause of the program; an `N` that is
|
|
1188
|
+
not such a clause number, such as `'x'` or `1.0`, fails C1. The clause,
|
|
1130
1189
|
renamed apart, MUST satisfy: each binding names a distinct variable of the
|
|
1131
1190
|
clause and unifies it with its value; and for one of the clause's heads
|
|
1132
1191
|
(each conjunct of a forward rule's head), the head unifies with `Goal` and
|
|
1133
1192
|
the body, of the same length as `Uses`, unifies with `Uses` pairwise, such
|
|
1134
1193
|
that afterwards the head is identical to `Goal` and each body goal to its
|
|
1135
1194
|
use. A step's own terms MUST NOT need further instantiation to match: a
|
|
1136
|
-
source clause `same(X, X)` cannot justify `same('a', 'b')`.
|
|
1195
|
+
source clause `same(X, X)` cannot justify `same('a', 'b')`. Identity keeps
|
|
1196
|
+
the sign of zero, so a fact `z(0.0)` cannot justify the goal `z(-0.0)`.
|
|
1137
1197
|
|
|
1138
1198
|
For a derived clause step, each enclosing generator MUST belong to the
|
|
1139
1199
|
program. Its bindings may name variables of those generators' scope
|
|
@@ -1150,20 +1210,28 @@ verified C1 steps and cite the usual source clause display.
|
|
|
1150
1210
|
|
|
1151
1211
|
### 11.3 C2 Well-foundedness
|
|
1152
1212
|
|
|
1153
|
-
No step MAY depend on itself through the uses of steps.
|
|
1213
|
+
No step MAY depend on itself through the uses of steps. A checker finds
|
|
1214
|
+
the dependencies by a depth-first search that starts from each step not yet
|
|
1215
|
+
visited, in document order, and follows each step's uses in order, each
|
|
1216
|
+
conjunct of a conjunctive use separately, to the steps whose goals they are.
|
|
1217
|
+
Each use that leads back to a step on the current search path is one C2
|
|
1218
|
+
failure, whose conclusion is the goal of that step.
|
|
1154
1219
|
|
|
1155
1220
|
### 11.4 C3 Justification
|
|
1156
1221
|
|
|
1157
1222
|
`By` MUST be one of the forms of Section 10.3. A `'builtin'` step MUST have
|
|
1158
1223
|
no bindings and no uses and a goal that is a primitive; an `'absent'` or
|
|
1159
1224
|
`'collected'` step MUST have no bindings and no uses and a goal that is a
|
|
1160
|
-
negation or a `findall`, respectively.
|
|
1225
|
+
negation or a `findall`, respectively. A step that fails C3 is not a trusted
|
|
1226
|
+
boundary: it counts in neither `trusted` nor C6.
|
|
1161
1227
|
|
|
1162
1228
|
### 11.5 C4 Coverage
|
|
1163
1229
|
|
|
1164
1230
|
Each conjunct of each claim MUST have a step. Each use, and each conjunct of
|
|
1165
1231
|
a use, MUST have a step or be identical to an instance of a fact of the
|
|
1166
|
-
program.
|
|
1232
|
+
program. The conclusion of a failure for a use without a step is the goal of
|
|
1233
|
+
the step that uses it. A document without claims is valid and certifies
|
|
1234
|
+
nothing.
|
|
1167
1235
|
|
|
1168
1236
|
### 11.6 C5 Re-decision
|
|
1169
1237
|
|
|
@@ -1229,7 +1297,8 @@ bound to `skolem(N, Name, Args)`, where:
|
|
|
1229
1297
|
the values that do contain one hold a witness of this firing.
|
|
1230
1298
|
|
|
1231
1299
|
When a forward clause has any such variables, its full head under the step's
|
|
1232
|
-
substitution MUST be ground
|
|
1300
|
+
substitution MUST be ground; a step that leaves such a variable unbound, or
|
|
1301
|
+
bound to anything but its Skolem term, fails C8 rather than C1. A generic inspection pattern cannot share one
|
|
1233
1302
|
existential witness across all its instances (Section 6.3).
|
|
1234
1303
|
|
|
1235
1304
|
For a generator, use its scope projection (Section 6.2) as the head for this
|
|
@@ -1329,6 +1398,8 @@ texts, including unverified claims when `valid` is false. It also has `valid` (b
|
|
|
1329
1398
|
(a list of `{kind, conclusion}`), `failures` (a list of
|
|
1330
1399
|
`{condition, detail, conclusion?}`) and `conditions` (a list of
|
|
1331
1400
|
`{id, name, covered, failed}`), where `conclusion` is a canonical text.
|
|
1401
|
+
Its variables keep the names the document gives them, rather than being
|
|
1402
|
+
renamed for each report fact as in the text form.
|
|
1332
1403
|
|
|
1333
1404
|
## 13. Command-Line Interface
|
|
1334
1405
|
|
|
@@ -1379,8 +1450,11 @@ without a clause leaves every other clause its number (Section 3.4), so the
|
|
|
1379
1450
|
Skolem terms of the other rules (Section 8.2) do not change.
|
|
1380
1451
|
|
|
1381
1452
|
Unused clauses are reported one per line, in clause order, as
|
|
1382
|
-
`unused(line(L), Display)`, where `L` is the clause's line (Section 3.4)
|
|
1383
|
-
`Display` as in Section 10.2
|
|
1453
|
+
`unused(line(L), Display)`, where `L` is the clause's line (Section 3.4) in
|
|
1454
|
+
the script that states it, and `Display` as in Section 10.2; with several
|
|
1455
|
+
scripts, clause order tells which script a line belongs to. The listing is
|
|
1456
|
+
the result whether or not the program halts with `'false'`, and the command
|
|
1457
|
+
exits with code 0 after it.
|
|
1384
1458
|
|
|
1385
1459
|
"Unused" is relative to the recorded derivations, which are the first ones
|
|
1386
1460
|
found (Section 8.7). A clause that only offers a second derivation of a
|
|
@@ -1388,7 +1462,9 @@ conclusion, such as a duplicate rule, is unused, though leaving out the
|
|
|
1388
1462
|
clause that offers the first one would make it used; leaving out several
|
|
1389
1463
|
unused clauses together can therefore change the conclusions. A
|
|
1390
1464
|
`contradiction` rule that never fires changes no conclusion and is unused,
|
|
1391
|
-
though it guards the program against data that would make it fire
|
|
1465
|
+
though it guards the program against data that would make it fire; so are
|
|
1466
|
+
the clauses only its negations or collections could consult, since they are
|
|
1467
|
+
not in the proof.
|
|
1392
1468
|
|
|
1393
1469
|
## 14. Conformance
|
|
1394
1470
|
|
|
@@ -1466,7 +1542,9 @@ and each expected line MUST equal the actual one, except that each `…`
|
|
|
1466
1542
|
line; this specification leaves such text, for example a failure detail, to
|
|
1467
1543
|
the implementation (Section 14). As JSON, both outputs MUST parse, and they
|
|
1468
1544
|
MUST be equal as JSON values: arrays element by element, objects with the
|
|
1469
|
-
same member names whatever their order,
|
|
1545
|
+
same member names whatever their order, numbers by their values, and
|
|
1546
|
+
strings as lines are, so that an expected string containing `…` matches any
|
|
1547
|
+
string of that form.
|
|
1470
1548
|
|
|
1471
1549
|
## 15. Security
|
|
1472
1550
|
|
package/package.json
CHANGED
package/src/builtins.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
import * as arith from './arith.js';
|
|
14
14
|
import {
|
|
15
15
|
EyemindError, Struct, Var, codePoints, compareTerms, copyResolved, deref, identical, isGround, key,
|
|
16
|
-
listFromItems,
|
|
16
|
+
listFromItems, properListItems, unify,
|
|
17
17
|
} from './terms.js';
|
|
18
18
|
import { floatText } from './writer.js';
|
|
19
19
|
|
|
@@ -49,6 +49,7 @@ function functor(args, resolved, env, bind) {
|
|
|
49
49
|
const count = boundedInteger(arity, 0, 1024);
|
|
50
50
|
if (name instanceof Var) throw new EyemindError('functor/3 needs a bound name');
|
|
51
51
|
if (count > 0 && typeof name !== 'string') throw new EyemindError('functor/3 needs an atom name');
|
|
52
|
+
if (name instanceof Struct) throw new EyemindError('functor/3 needs an atomic name');
|
|
52
53
|
// Unique names across primitive invocations preserve variable isolation.
|
|
53
54
|
functorSerial++;
|
|
54
55
|
if (count === 0) return bind(args[0], name);
|
|
@@ -129,7 +130,8 @@ function numberChars(args, resolved, env, bind) {
|
|
|
129
130
|
if (!match) return false;
|
|
130
131
|
if (match[1] !== undefined) return bind(args[0], BigInt(text));
|
|
131
132
|
const value = Number(text);
|
|
132
|
-
|
|
133
|
+
// Text too large for a finite float names no number term.
|
|
134
|
+
if (!Number.isFinite(value)) return false;
|
|
133
135
|
return bind(args[0], value);
|
|
134
136
|
}
|
|
135
137
|
|
package/src/lang.js
CHANGED
|
@@ -153,16 +153,18 @@ class Builder {
|
|
|
153
153
|
this.embedded = new Set();
|
|
154
154
|
}
|
|
155
155
|
|
|
156
|
-
|
|
156
|
+
// anonymous says whether the program's _ still needs numbering; a document's
|
|
157
|
+
// terms come numbered, and its variable decoded as _ is a named one.
|
|
158
|
+
add(kind, head, body, line = null, anonymous = true) {
|
|
157
159
|
if (line === null) line = statedLine !== null ? statedLine : this.locate();
|
|
158
160
|
const pending = [head, ...body];
|
|
159
161
|
const counter = new Anonymous(head, body);
|
|
160
162
|
// In the order the statement writes them: a forward rule, implies(),
|
|
161
163
|
// writes its premise first.
|
|
162
|
-
if (kind !== 'backward') {
|
|
164
|
+
if (anonymous && kind !== 'backward') {
|
|
163
165
|
body = body.map((goal) => renameAnonymous(goal, counter));
|
|
164
166
|
head = renameAnonymous(head, counter);
|
|
165
|
-
} else {
|
|
167
|
+
} else if (anonymous) {
|
|
166
168
|
head = renameAnonymous(head, counter);
|
|
167
169
|
body = body.map((goal) => renameAnonymous(goal, counter));
|
|
168
170
|
}
|
|
@@ -322,7 +324,7 @@ function exportsFor(io) {
|
|
|
322
324
|
}
|
|
323
325
|
// Each fact is stated by this call, so it records the call's line, as
|
|
324
326
|
// every clause records the line of the statement that states it.
|
|
325
|
-
for (const [term] of terms) builder.add('fact', term, [], line);
|
|
327
|
+
for (const [term] of terms) builder.add('fact', term, [], line, false);
|
|
326
328
|
},
|
|
327
329
|
struct: (name, ...args) => {
|
|
328
330
|
if (typeof name !== 'string') throw new EyemindError('struct() needs a name string first');
|
package/src/program.js
CHANGED
|
@@ -4,9 +4,10 @@ import { containsTemplate, expandTemplates } from './templates.js';
|
|
|
4
4
|
import { subgoals } from './goals.js';
|
|
5
5
|
import { hasInspection, inspectionTerm } from './inspection.js';
|
|
6
6
|
import {
|
|
7
|
-
Env, EyemindError, Struct, Var, deref, flattenConjunction, freshTerm, identity, isCallable,
|
|
7
|
+
EMPTY, Env, EyemindError, Struct, Var, deref, flattenConjunction, freshTerm, identity, isCallable,
|
|
8
8
|
isGround, isTerm, key, keyArity, unify, variables,
|
|
9
9
|
} from './terms.js';
|
|
10
|
+
import { write } from './writer.js';
|
|
10
11
|
|
|
11
12
|
export const CONTROL_KEYS = new Set(['and/2', 'or/2', 'not/1', 'call/1', 'once/1', 'findall/3']);
|
|
12
13
|
export const RESERVED_KEYS = new Set(['step/4', 'clause/2', 'activated/2', 'implies/2', 'implied_by/2', 'forward/2', 'backward/2']);
|
|
@@ -134,6 +135,10 @@ export class Program {
|
|
|
134
135
|
for (const [position, item] of heads.entries()) {
|
|
135
136
|
if (templatePositions.has(position)) continue;
|
|
136
137
|
if (!isCallable(item)) throw new EyemindError(`line ${source.line}: a head must be an atom or a compound term`);
|
|
138
|
+
// A list goal is a conjunction, so a clause with a list head could never be called.
|
|
139
|
+
if (item === EMPTY || isTerm(item, '.', 2)) {
|
|
140
|
+
throw new EyemindError(`line ${source.line}: a head cannot be a list; name the relation, such as items(${write(item)})`);
|
|
141
|
+
}
|
|
137
142
|
const itemKey = keys.of(item);
|
|
138
143
|
headKey = itemKey;
|
|
139
144
|
if (allowed.has(itemKey)) continue;
|
package/src/reader.js
CHANGED
|
@@ -79,6 +79,7 @@ class Tokens {
|
|
|
79
79
|
if (digits.length > 1 && digits[0] === '0') throw this.error(`an integer has no leading zero: ${digits}`, line);
|
|
80
80
|
return { kind: 'int', text: digits, line };
|
|
81
81
|
}
|
|
82
|
+
if (/^0\d/.test(match[2])) throw this.error(`a number has no leading zero: ${match[2]}`, line);
|
|
82
83
|
return { kind: 'float', text: match[2], line };
|
|
83
84
|
} else if (isNameStart(code)) {
|
|
84
85
|
const start = pos;
|
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.2.
|
|
2
|
+
export const VERSION = '0.2.6';
|