eyemind 0.5.16 → 0.5.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -7,7 +7,7 @@ eyemind is a **JavaScript rule language** with forward and backward reasoning an
7
7
 
8
8
  [Playground](https://eyereasoner.github.io/eyemind/playground/) · [Specification](https://eyereasoner.github.io/eyemind/SPEC) · [Conformance](https://eyereasoner.github.io/eyemind/conformance/) · [Examples](https://eyereasoner.github.io/eyemind/examples/)
9
9
 
10
- The playground runs programs in your browser; the specification defines the language, its canonical text, the proof format and the C1–C10 checks. The examples are 135 runnable programs, each with a card deck and saved conclusions, proofs and check reports. The conformance suite has 1371 cases that test any implementation of the specification through its command line; run it [in your browser](https://eyereasoner.github.io/eyemind/playground/conformance).
10
+ The playground runs programs in your browser; the specification defines the language, its canonical text, the proof format and the C1–C10 checks. The examples are 135 runnable programs, each with a card deck and saved conclusions, proofs and check reports. The conformance suite has 1376 cases that test any implementation of the specification through its command line; run it [in your browser](https://eyereasoner.github.io/eyemind/playground/conformance).
11
11
 
12
12
  ## Contents
13
13
 
@@ -480,6 +480,7 @@ A negation `not(G)` concludes from what is *absent* and a collection `findall(T,
480
480
  - **Negate only what is bound.** The variables of `not(G)` must be bound when it runs; write `not(q(X, _))` for "no value at all".
481
481
  - **Check the search, not just its result.** A proof ends with a search certificate: `searched(Call, Answers)` lists each call's answers and `derived(Pattern, Facts)` each consulted relation. The checker expands each call one level against the program, so a wrong table shows up as a disagreement.
482
482
  - **Say what was taken on trust.** Anything the certificate cannot settle becomes an obligation, and evidence in the proof can still refute it (C6).
483
+ - **Certify relational negation.** Supported, closed listings can establish the original calls of ground relational rules with bound negations, including inside conjunctions and disjunctions. A proof within this fragment can be `checked` with no obligation, even under `--strict-proof`. Collections of derived facts, whose order a listing cannot show, and dependencies on `restricted` rules with new witnesses keep an obligation.
483
484
 
484
485
  ## Checking the translation
485
486
 
package/SPEC.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ```text
4
4
  Title: The eyemind Rule Language and Proof Format
5
- Version: eyemind 0.5.16
5
+ Version: eyemind 0.5.17
6
6
  ```
7
7
 
8
8
  This document specifies the syntax and meaning of eyemind programs and data
@@ -1005,6 +1005,12 @@ concludes `man('bob')` and invents no father for `'jo'`, since `'bob'`
1005
1005
  already satisfies the heads once the third rule has run. A restricted
1006
1006
  rule's display omits its guard ([Section 10.2](#102-clause-displays)).
1007
1007
 
1008
+ A `restricted` call states a clause and is no rule value: a `restricted`
1009
+ call nested in another statement MUST be rejected. Its premise MUST bind
1010
+ every variable of its heads other than the head-only ones when the guard is
1011
+ solved; a solution that leaves one unbound, as a fact with variables can,
1012
+ is an error.
1013
+
1008
1014
  This gives the specified Skolemized reading of existential conclusions.
1009
1015
  The original existential rule need not have a least model over its original
1010
1016
  vocabulary. A witness is an ordinary compound in subsequent reasoning; it
@@ -1039,6 +1045,20 @@ holds when `G` has no solution, with the binding restrictions of [Section
1039
1045
  4.2](#42-controls). This is absence relative to the program, not falsity in the world.
1040
1046
  For relational goals this gives the stratified least-model reading.
1041
1047
 
1048
+ A chain-stratified program ([Section 6.4](#64-chain-stratification)) has no such ranks. Its meaning
1049
+ is the set of facts [Section 8.2](#82-forward-evaluation-and-witnesses)'s chain strata derive. When no
1050
+ contradiction holds, that set is a **stable model**: the least model of
1051
+ the program's rules with every negation decided by the set itself. Chain
1052
+ stratification is what makes it the only one, so the order of rule
1053
+ applications cannot change it.
1054
+
1055
+ A restricted rule ([Section 7.2](#72-variables-and-witnesses)) reads its conclusion existentially: for each
1056
+ solution of its premise, some values satisfy its heads. A result is **lean**
1057
+ when each witness a restricted rule made is needed, no other values
1058
+ satisfying those heads. [Section 8.2](#82-forward-evaluation-and-witnesses) derives one lean result or fails;
1059
+ another order of rule applications could derive another, so a lean result
1060
+ is not determined by the program alone.
1061
+
1042
1062
  Collection also waits for its dependencies. `findall` collects ordered
1043
1063
  search solutions, including repeated derivations and nonground instances;
1044
1064
  its meaning is not determined by a set of ground atoms alone. Bindings
@@ -1631,6 +1651,16 @@ boundary is established by its search certificate. An unconditional
1631
1651
  `checked` verdict also establishes operational query fidelity
1632
1652
  ([Section 11.2](#112-operational-query-fidelity)).
1633
1653
 
1654
+ For a program with negation, "follows" is relative to the facts the
1655
+ certificate lists: C9 establishes that they are supported by steps, closed
1656
+ under the forward rules and consistent with every settled negation. In the
1657
+ ground relational fragment of [Section 11.13](#1113-c10-call-fidelity), a stratified or
1658
+ chain-stratified program has only one such result ([Section 7.4](#74-negation-and-collection)). With restricted
1659
+ witnesses, different lean results can have these properties. A claim whose
1660
+ forward dependency closure includes a restricted rule with head-only
1661
+ variables therefore retains a call-fidelity obligation, and a strict check
1662
+ rejects it. Independent claims may still check strictly.
1663
+
1634
1664
  It does not establish:
1635
1665
 
1636
1666
  - that the proof contains all conclusions of the program;
@@ -2125,8 +2155,8 @@ with these differences:
2125
2155
  4. A comparison `compare/3` with either compared term nonground is not
2126
2156
  supported by this certificate format: alpha renaming of a table need
2127
2157
  not preserve the order of variable names. Such a search leaves call fidelity unproved.
2128
- 5. A consulted forward listing MUST have a dependency closure in the ground
2129
- positive fragment described below. A final listing alone MUST NOT certify
2158
+ 5. A consulted forward listing MUST have a dependency closure in the
2159
+ supported fragment described below. A final listing alone MUST NOT certify
2130
2160
  binding-sensitive or order-sensitive forward firings outside that fragment.
2131
2161
 
2132
2162
  For the `once` example in [Section 11.2](#112-operational-query-fidelity),
@@ -2144,14 +2174,18 @@ first, and `once` selects it. Thus `q('a')` is an answer and `q('b')` is
2144
2174
  excluded. Substituting `called(p('b'), [p('b')])` cannot establish the
2145
2175
  different call `p(X)`.
2146
2176
 
2147
- **Supported forward listings.** A forward listing's **ground positive
2148
- dependency closure** contains its relation and each ordinary body relation
2149
- of every source fact, backward rule or forward rule defining any relation
2150
- in that closure. To use a listing for C10:
2177
+ **Supported forward listings.** A forward listing's **ground dependency
2178
+ closure** contains its relation and each ordinary body relation, inside a
2179
+ negation or not, of every source fact, backward rule or forward rule
2180
+ defining any relation in that closure. To use a listing for C10:
2151
2181
 
2152
2182
  - All source facts in the closure MUST be ground.
2153
- - Rule bodies MUST contain only ordinary calls, `'true'`, conjunction and
2154
- disjunction. Templates, captures and source inspection are excluded.
2183
+ - Rule bodies MUST contain only ordinary calls, `'true'`, conjunction,
2184
+ disjunction and negations of these. Templates, captures and source
2185
+ inspection are excluded.
2186
+ - A negation grounds nothing. Each of its variables other than anonymous
2187
+ ones MUST be grounded by the body goals before it, and it MUST NOT contain
2188
+ a negation.
2155
2189
  - A body call to an ordinary relation grounds its variables. Conjunction
2156
2190
  accumulates the grounded variables of its parts; disjunction grounds only
2157
2191
  those grounded by both alternatives.
@@ -2163,8 +2197,13 @@ in that closure. To use a listing for C10:
2163
2197
  restricted rule makes can depend on the order of rule applications.
2164
2198
 
2165
2199
  Supported facts and closed listings then establish the least ground
2166
- positive closure. More general forward execution requires publication
2167
- evidence this format does not supply, leaving call fidelity unproved.
2200
+ positive closure and, with negations, a set of facts that is supported,
2201
+ closed under the rules and consistent with each negation, every negation
2202
+ being decided by the listed facts alone. A stratified or chain-stratified
2203
+ program has exactly one such set ([Section 7.4](#74-negation-and-collection)), its result, so the
2204
+ listings are the facts the original calls consult. More general forward
2205
+ execution requires publication evidence this format does not supply,
2206
+ leaving call fidelity unproved.
2168
2207
 
2169
2208
  **Deciding claims.** Every relevant call certificate MUST be valid. Each
2170
2209
  claim MUST be identical, up to variable renaming, to an answer of at least
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eyemind",
3
- "version": "0.5.16",
3
+ "version": "0.5.17",
4
4
  "description": "A dependency-free JavaScript rule language with forward and backward reasoning and checkable proofs.",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
package/src/engine.js CHANGED
@@ -165,8 +165,10 @@ function unboundNegation(goal, env) {
165
165
  const shown = write(resolved, null, naming);
166
166
  const unbound = [...new Set([...variables(resolved).values()]
167
167
  .filter((variable) => !isAnonymous(variable)).map((variable) => naming.get(variable.name)))];
168
- return new EyemindError('negation requires a goal whose variables are bound, except for anonymous ones: ' +
168
+ const error = new EyemindError('negation requires a goal whose variables are bound, except for anonymous ones: ' +
169
169
  `${unbound.join(', ')} ${unbound.length === 1 ? 'is' : 'are'} unbound in ${shown}`);
170
+ error.goal = goal;
171
+ return error;
170
172
  }
171
173
 
172
174
  // Resolve a proof forest with an explicit stack: a derivation chain is as deep
@@ -768,6 +770,22 @@ export class Solver {
768
770
  return first < order.length && order[first] < now.get(goalKey);
769
771
  }
770
772
 
773
+ // The solutions of a rule's body. A restricted rule's guard is a negation
774
+ // the program did not write: when its premise leaves a variable of its
775
+ // heads unbound, the error names the rule rather than the guard.
776
+ *guarded(clause, guard, solutions) {
777
+ if (clause.guard === null) {
778
+ yield* solutions;
779
+ return;
780
+ }
781
+ try {
782
+ yield* solutions;
783
+ } catch (error) {
784
+ if (!(error instanceof EyemindError) || error.goal !== guard) throw error;
785
+ throw new EyemindError(`restricted rule ${clause.id} needs its premise to bind the variables of its conclusion other than its new values`);
786
+ }
787
+ }
788
+
771
789
  // Each solution of a renamed rule's body, as what it concludes, with the
772
790
  // alternatives its goals took when the body is searched in a window.
773
791
  // Bindings last only until the next answer is requested, and adding facts
@@ -775,7 +793,7 @@ export class Solver {
775
793
  // first and concluded afterwards.
776
794
  scan(clause, head, body, names, env, prefix) {
777
795
  const found = [];
778
- for (const [answerEnv, nodes] of this.solve(body, env)) {
796
+ for (const [answerEnv, nodes] of this.guarded(clause, body[body.length - 1], this.solve(body, env))) {
779
797
  const mark = answerEnv.mark();
780
798
  // Head variables the body leaves unbound become Skolem terms, shared
781
799
  // between the heads of one conclusion.
package/src/fidelity.js CHANGED
@@ -6,7 +6,7 @@ import { text, variant } from './common.js';
6
6
  import { goalTerm } from './goals.js';
7
7
  import { INSPECTION_KEYS } from './inspection.js';
8
8
  import {
9
- Env, conjunction, copyResolved, freshTerm, isCallable, isGround, isTerm, key, unify, variables,
9
+ Env, conjunction, copyResolved, freshTerm, isAnonymous, isCallable, isGround, isTerm, key, unify, variables,
10
10
  } from './terms.js';
11
11
 
12
12
  function instance(goal, pattern) {
@@ -34,27 +34,39 @@ export function callQuestions(program, goals, claims) {
34
34
  });
35
35
  }
36
36
 
37
- // C9's support plus closure establishes the least ground positive model.
38
- // For forward rules that observe bindings or order, a final listing alone
39
- // does not establish which firings occurred. Refuse that stronger promise.
37
+ // C9's support plus closure establishes the least ground positive model,
38
+ // and with negations the one stable model of a stratified or
39
+ // chain-stratified program: a negation whose named variables earlier goals
40
+ // bind is decided by the listed facts alone. For forward rules that observe
41
+ // bindings or order, and for restricted rules, whose guard another order of
42
+ // firings could decide otherwise, a final listing alone does not establish
43
+ // which firings occurred. Refuse that stronger promise.
40
44
  export function positiveListings(program, listings) {
41
45
  const pending = [...listings];
42
46
  const seen = new Set();
43
- function bound(goal) {
44
- if (goal === 'true') return new Set();
47
+ function bound(goal, grounded, negated = false) {
48
+ if (goal === 'true') return grounded;
45
49
  if (isTerm(goal, 'and', 2) || isTerm(goal, 'or', 2)) {
46
- const left = bound(goal.args[0]);
47
- const right = bound(goal.args[1]);
48
- if (left === null || right === null) return null;
49
- return goal.name === 'and' ? new Set([...left, ...right])
50
+ const left = bound(goal.args[0], grounded, negated);
51
+ if (left === null) return null;
52
+ const right = bound(goal.args[1], goal.name === 'and' ? left : grounded, negated);
53
+ if (right === null) return null;
54
+ return goal.name === 'and' ? right
50
55
  : new Set([...left].filter((name) => right.has(name)));
51
56
  }
57
+ if (isTerm(goal, 'not', 1)) {
58
+ if (negated) return null;
59
+ for (const [name, variable] of variables(goal)) {
60
+ if (!isAnonymous(variable) && !grounded.has(name)) return null;
61
+ }
62
+ return bound(goal.args[0], grounded, true) === null ? null : grounded;
63
+ }
52
64
  if (!isCallable(goal)) return null;
53
65
  const goalKey = key(goal);
54
66
  if (PRIMITIVE_KEYS.has(goalKey) || INSPECTION_KEYS.has(goalKey) ||
55
67
  ['not/1', 'findall/3', 'once/1', 'call/1'].includes(goalKey)) return null;
56
68
  pending.push(goalKey);
57
- return new Set(variables(goal).keys());
69
+ return new Set([...grounded, ...variables(goal).keys()]);
58
70
  }
59
71
  while (pending.length) {
60
72
  const goalKey = pending.pop();
@@ -63,16 +75,15 @@ export function positiveListings(program, listings) {
63
75
  const clauses = [...(program.groups.get(goalKey) || []), ...program.forward.filter((clause) =>
64
76
  clause.plainHeads.some((head) => isCallable(head) && key(head) === goalKey))];
65
77
  for (const clause of clauses) {
66
- if (clause.parentId !== null || clause.templates.length || clause.captures !== null) return false;
78
+ if (clause.parentId !== null || clause.templates.length || clause.captures !== null || clause.guard !== null) return false;
67
79
  if (!clause.forward && !clause.body.length) {
68
80
  if (!isGround(clause.head)) return false;
69
81
  continue;
70
82
  }
71
- const grounded = new Set();
83
+ let grounded = new Set();
72
84
  for (const goal of clause.body) {
73
- const names = bound(goal);
74
- if (names === null) return false;
75
- for (const name of names) grounded.add(name);
85
+ grounded = bound(goal, grounded);
86
+ if (grounded === null) return false;
76
87
  }
77
88
  const witnesses = new Set(clause.forward ? clause.witnessNames : []);
78
89
  for (const name of variables(clause.head).keys()) {
package/src/lang.js CHANGED
@@ -183,6 +183,11 @@ class Builder {
183
183
  const term = pending.pop();
184
184
  if (!(term instanceof Struct)) continue;
185
185
  const source = this.rules.get(term);
186
+ // A restricted rule is a statement only: nested, it would be read as
187
+ // a term and its rule dropped.
188
+ if (source !== undefined && source.kind === 'restricted') {
189
+ throw new EyemindError('restricted() states a rule and cannot be nested in another statement');
190
+ }
186
191
  if (source !== undefined) this.embedded.add(source);
187
192
  pending.push(...term.args);
188
193
  }
package/src/version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // The release this checkout is; ./release keeps it in step with package.json.
2
- export const VERSION = '0.5.16';
2
+ export const VERSION = '0.5.17';