eyemind 0.9.7 → 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 +1 -1
- package/README.md +6 -1
- package/package.json +1 -1
- package/src/le-explain.js +15 -4
- package/src/version.js +1 -1
package/LS-SPEC.md
CHANGED
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
|
-
|
|
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
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eyemind",
|
|
3
|
-
"version": "0.9.
|
|
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/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
|
-
|
|
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
|
-
|
|
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 =
|
|
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.
|
|
2
|
+
export const VERSION = '0.9.8';
|