eyemind 0.9.6 → 0.9.8

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/LS-SPEC.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ```text
4
4
  Title: The Logic Script (LS) Language and Proof Format
5
- Version: eyemind 0.9.6
5
+ Version: eyemind 0.9.8
6
6
  ```
7
7
 
8
8
  This document specifies Logic Script (LS): the syntax and meaning of its
package/README.md CHANGED
@@ -13,7 +13,7 @@ program, a JavaScript library and a browser application.
13
13
  - [Playground](https://eyereasoner.github.io/eyemind/playground/): run any
14
14
  example or your own program in the browser, with its proof and check report.
15
15
  - [Examples](https://eyereasoner.github.io/eyemind/examples/): the
16
- 165 runnable programs, each with a card deck and saved conclusions; all but
16
+ 170 runnable programs, each with a card deck and saved conclusions; all but
17
17
  the two streamed examples also save proofs and check reports.
18
18
  - [Specification](https://eyereasoner.github.io/eyemind/LS-SPEC): the
19
19
  language, the proof format and how a proof is checked.
@@ -276,6 +276,11 @@ the [right to erasure](https://eyereasoner.github.io/eyemind/examples/deck/right
276
276
  [inheritance without a will](https://eyereasoner.github.io/eyemind/examples/deck/intestate-succession-le),
277
277
  [library fines](https://eyereasoner.github.io/eyemind/examples/deck/library-fines-le),
278
278
  an [election tally](https://eyereasoner.github.io/eyemind/examples/deck/election-tally-le),
279
+ [ABO blood groups](https://eyereasoner.github.io/eyemind/examples/deck/blood-groups-le),
280
+ [molar masses](https://eyereasoner.github.io/eyemind/examples/deck/molar-mass-le),
281
+ a [critical path](https://eyereasoner.github.io/eyemind/examples/deck/critical-path-le),
282
+ [Euclid's algorithm](https://eyereasoner.github.io/eyemind/examples/deck/euclid-le),
283
+ the [Pythagorean theorem](https://eyereasoner.github.io/eyemind/examples/deck/pythagoras-le),
279
284
  [shortest paths](https://eyereasoner.github.io/eyemind/examples/deck/shortest-path-le) or
280
285
  [river-crossing plans](https://eyereasoner.github.io/eyemind/examples/deck/river-crossing-le).
281
286
 
@@ -627,7 +632,7 @@ A clause is listed when no conclusion's proof uses it; a clause only a negation
627
632
 
628
633
  The [examples](https://eyereasoner.github.io/eyemind/examples/) range from classics (Ackermann, the zebra puzzle) to planning, policy reasoning, mathematics, RDF 1.2 data and a hundred-thousand-level taxonomy. Each has its conclusions saved in `examples/output/`, all but the two streamed examples their proof and check report in `examples/proof/` and `examples/check/`, and each a card deck for a wide audience. Change a fact, run it, and compare with the saved output.
629
634
 
630
- The [playground](https://eyereasoner.github.io/eyemind/playground/) runs eyemind in a worker in your browser, so **Stop** ends a long run. Choose an example, edit it, pick an output (conclusions, proof, checked answers, check of a saved proof, unused clauses, or independent RDF Messages) and press **Run** or Ctrl+Enter. A line an error names is marked red, the options panel shows the equivalent command, and **Share link** copies a link with the program and options.
635
+ The [playground](https://eyereasoner.github.io/eyemind/playground/) runs eyemind in a worker in your browser, so **Stop** ends a long run. Choose an example, edit it, pick an output (conclusions, proof, checked answers, check of a saved proof, unused clauses, Logical English answers explained, or independent RDF Messages) and press **Run** or Ctrl+Enter. A line an error names is marked red, the options panel shows the equivalent command, and **Share link** copies a link with the program and options.
631
636
 
632
637
  ## Command line
633
638
 
@@ -768,7 +773,7 @@ console.log(result.bindings);
768
773
  console.log(checkProof(socrates, result.proof, { goals }).valid);
769
774
  ```
770
775
 
771
- `run()` returns `conclusions`, `answers`, `bindings`, `inferred`, `stdout`, `proof`, `proofReport`, `stats` and `haltCode`, and takes `goal`, `goals`, `proof`, `maxDepth`, `maxIterations` and `maxInferences`; exceeding a bound throws an `EyemindError`. `conclusions` holds the answer terms; `answers`, `bindings` and `stdout` are rendered when first read. Ground N3 conclusions are written directly from their terms. `loadSources([[text, filename], ...], io)` loads several sources as one program; pass `nodeIO` from `eyemind/node` as `io` to let `facts_from(path)` read files. `checkProof(program, document, { goals })` checks a proof. `checkReport`, `readTerm`, `readTerms` and `write` format reports and read and write the canonical text. `compileLe([[text, filename], ...], io)` returns the compiled LS `program` and standalone JavaScript `text`, reading included files with `io.readFile` when given; `writeLe(run(loaded.program), loaded)` writes the answers as LE sentences, given the value `loaded` that `compileLe` returned.
776
+ `run()` returns `conclusions`, `answers`, `bindings`, `inferred`, `stdout`, `proof`, `proofReport`, `stats` and `haltCode`, and takes `goal`, `goals`, `proof`, `maxDepth`, `maxIterations` and `maxInferences`; exceeding a bound throws an `EyemindError`. `conclusions` holds the answer terms; `answers`, `bindings` and `stdout` are rendered when first read. Ground N3 conclusions are written directly from their terms. `loadSources([[text, filename], ...], io)` loads several sources as one program; pass `nodeIO` from `eyemind/node` as `io` to let `facts_from(path)` read files. `checkProof(program, document, { goals })` checks a proof. `checkReport`, `readTerm`, `readTerms` and `write` format reports and read and write the canonical text. `compileLe([[text, filename], ...], io)` returns the compiled LS `program` and standalone JavaScript `text`, reading included files with `io.readFile` when given; `writeLe(run(loaded.program), loaded)` writes the answers as LE sentences, given the value `loaded` that `compileLe` returned, and `explainLe(loaded, run(loaded.program, { proof: true }).proof)` explains each answer in English, as `--explain` does, after checking the proof.
772
777
 
773
778
  Further entry points serve applications built on the formats and profiles:
774
779
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eyemind",
3
- "version": "0.9.6",
3
+ "version": "0.9.8",
4
4
  "description": "A dependency-free Logic Script (LS) reasoner with forward and backward reasoning, checkable proofs, and RDF 1.2, Notation3 (N3), SPARQL 1.2 RL (SRL) and Logical English (LE) interoperability.",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
package/src/index.js CHANGED
@@ -15,3 +15,4 @@ export { EyemindError, Struct, Var } from './terms.js';
15
15
  export { write } from './writer.js';
16
16
  export { RdfMessageReader, parseRdfMessages } from './messages.js';
17
17
  export { compileLe, writeLe } from './le.js';
18
+ export { explainLe } from './le-explain.js';
package/src/le-explain.js CHANGED
@@ -19,6 +19,8 @@ const ANSWER = 'le:answer';
19
19
  const SILENT = new Set(['le:scenario/1', 'is_var/1', 'is_nonvar/1', 'true/0']);
20
20
  const AGGREGATE_WORDS = { 'le:sum': 'sum', 'le:count': 'count', 'le:average': 'average', 'le:min': 'min', 'le:max': 'max' };
21
21
  const OPERATORS = { add: '+', sub: '-', mul: '*', div: '/', floordiv: '//', mod: 'mod' };
22
+ const PRECEDENCE = { add: 1, sub: 1, mul: 2, div: 2, floordiv: 2, mod: 2 };
23
+ const ASSOCIATIVE = new Set(['add', 'mul']);
22
24
  const COMPARISONS = { lt: '<', gt: '>', le: '=<', ge: '>=', eq: '=', ne: '!=' };
23
25
 
24
26
  // The explanations of every answer of a Logical English run, as LE text: under
@@ -267,12 +269,16 @@ class Writer {
267
269
  term = deref(term, this.env);
268
270
  if (term instanceof Var) return this.pending.get(term) ?? this.phrase(term, noun);
269
271
  if (term instanceof Struct && OPERATORS[term.name] && term.args.length === 2) {
270
- const side = (arg) => {
272
+ // Brackets only where precedence needs them: around a lower operator,
273
+ // or an equal one on the right of a subtraction or division.
274
+ const side = (arg, right) => {
271
275
  const text = this.value(arg);
272
276
  const inner = deref(arg, this.env);
273
- return inner instanceof Struct && OPERATORS[inner.name] ? `(${text})` : text;
277
+ if (!(inner instanceof Struct && OPERATORS[inner.name] && inner.args.length === 2)) return text;
278
+ const [outer, own] = [PRECEDENCE[term.name], PRECEDENCE[inner.name]];
279
+ return own < outer || (right && own === outer && !ASSOCIATIVE.has(term.name)) ? `(${text})` : text;
274
280
  };
275
- return `${side(term.args[0])} ${OPERATORS[term.name]} ${side(term.args[1])}`;
281
+ return `${side(term.args[0], false)} ${OPERATORS[term.name]} ${side(term.args[1], true)}`;
276
282
  }
277
283
  if (term instanceof Struct && (term.name === 'min' || term.name === 'max') && term.args.length === 2) {
278
284
  return `the ${term.name === 'min' ? 'minimum' : 'maximum'} of ${this.value(term.args[0])} and ${this.value(term.args[1])}`;
@@ -343,8 +349,13 @@ class Writer {
343
349
  }
344
350
  if (name === 'le:days_after' && args.length === 3) return `${this.value(args[0])} is ${this.value(args[1])} days after ${this.value(args[2])}`;
345
351
  if (name === 'is' && args.length === 2) {
352
+ // The minimum and maximum read as their built-in templates do.
353
+ const formula = deref(args[1], this.env);
354
+ if (formula instanceof Struct && (formula.name === 'min' || formula.name === 'max') && formula.args.length === 2) {
355
+ return `${this.value(formula)} is ${this.value(args[0])}`;
356
+ }
346
357
  const right = this.value(args[1]);
347
- const left = leValue(copyResolved(args[0], this.env), this.compiled.templates);
358
+ const left = this.value(args[0]);
348
359
  return left === right ? null : `${left} = ${right}`;
349
360
  }
350
361
  if (name === 'compare' && args.length === 3) {
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.9.6';
2
+ export const VERSION = '0.9.8';