eyemind 0.9.1 → 0.9.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/LE-SPEC.md CHANGED
@@ -21,6 +21,7 @@ ends with `:`:
21
21
  | Header | Section |
22
22
  | --- | --- |
23
23
  | `the templates are:`, `the predicates are:` | Templates, separated by full stops, and by commas at the end of a line or before a place. |
24
+ | `the functions are:` | Templates of the form `... is *a value*`, also written without their value. |
24
25
  | `the knowledge base NAME includes:`, `the contract NAME states that:` | Facts and rules. |
25
26
  | `the ontology is:` | Facts and rules; a fact `a student is a person.` relates the kinds `student` and `person`. |
26
27
  | `the constants are:` | Named values, one sentence each: `the fee is 5.` |
@@ -36,10 +37,31 @@ order, and a template can be used before it is declared. Several `.le` files
36
37
  are read as one document.
37
38
 
38
39
  An included file is named as in LE2: a path relative to the file that
39
- includes it, without `.le` if one likes. It is read once, and a chain of
40
- includes stops at five. The command line reads included files; the library
41
- reads them through `io.readFile` when `compileLe(inputs, io)` is given one.
42
- Web addresses and Prolog resources (`.pl`) are not read.
40
+ includes it, or a web address, without `.le` if one likes. It is read once,
41
+ and a chain of includes stops at five. The command line reads included files
42
+ and web addresses; the library reads them through `io.readFile` and
43
+ `io.readDocument` when `compileLe(inputs, io)` is given them. A Prolog
44
+ resource, a file ending in `.pl`, gives its facts and rules: Prolog clauses
45
+ `Head.` and `Head :- Body.`, with the goals of an embedded Prolog goal (see
46
+ Embedded Prolog); its directives are left out.
47
+
48
+ `the facts background includes these resources: ...` names the programs that
49
+ help an assistant read facts from a text; as in LE2, the answers do not depend
50
+ on them, and eyemind reads past the section.
51
+
52
+ A fact or a rule's label may carry LE2's provenance, which changes nothing in
53
+ the proof but gives the fact its source:
54
+
55
+ - trailers after a fact, each after a comma: `, according to SOURCE`,
56
+ `, as stated in DOCUMENT at LOCATOR`, `, because "..."` and `, confer "..."`;
57
+ - `scenario NAME is, as stated in DOCUMENT:`, the default document of the
58
+ scenario's facts;
59
+ - `rule NAME with provenance DOCUMENT, confer "...":`;
60
+ - `DOCUMENT is published at "..."` and `the text of DOCUMENT is at "..."`,
61
+ which eyemind reads past.
62
+
63
+ A fact's source is its `according to`, else its document. It matters only to
64
+ source-scoped proof (see Negation).
43
65
 
44
66
  Sentences end with a full stop followed by white space or the end of the file;
45
67
  a sentence can span lines. `%` or `#` starts a comment through the end of the
@@ -54,8 +76,10 @@ space as one and a tab as four, as LE's editor shows it.
54
76
  ## Templates
55
77
 
56
78
  A template is a sentence pattern: words and places. A place is a phrase between
57
- asterisks, such as `*a person*`; LE1 also writes templates without asterisks,
58
- and in a template without any, `a` or `an` and the word after it make a place.
79
+ asterisks, such as `*a person*`; LE1 also writes templates without asterisks.
80
+ In a document without any, `a` or `an` and the word after it make a place in a
81
+ template that starts with `a` or `an`, such as `a person has a balance`; a
82
+ template such as `the applicant has a good credit score` keeps its words.
59
83
 
60
84
  ```text
61
85
  the templates are:
@@ -78,7 +102,7 @@ LE2's additions follow a template after `;`:
78
102
  | --- | --- |
79
103
  | `; synonym TEMPLATE` | A second wording of the same relation, with its places in the same order. |
80
104
  | `; opposite: TEMPLATE`, `; opposite TEMPLATE` | The wording of a separate relation, concluded only by its own rules and by `only if` rules. |
81
- | `; assumable`, `; unknown`, `; assumed`, `; judged`, `; open textured`, `; evaluative` | eyemind makes no assumptions: a sentence that is not stated or concluded is false. A negated assumable sentence is an error, because it would hold only as an assumption. |
105
+ | `; assumable`, `; unknown`, `; assumed`, `; judged`, `; open textured`, `; evaluative` | A sentence that the program cannot prove can be assumed; see Abduction. |
82
106
  | `; memorable`, `; memoised`, `; memoized`, `; cached`, `; undefined`, `; scenario element`, `; one value`, `; single valued`, `; image ...` | Nothing that eyemind computes changes. |
83
107
 
84
108
  Other additions, such as `; prepositional` and `; via service NAME`, are errors.
@@ -177,11 +201,50 @@ with a connective at the same or a lesser indentation:
177
201
  | `R is the list of each X such that C` | `L` itself |
178
202
  | `R is a collection of X where C` | `L` itself, as LE1 writes it |
179
203
 
204
+ LE2 also groups conditions without connectives. `any of`, `either` or
205
+ `at least one of`, and `all of`, each followed by `:` or a line break, join the
206
+ conditions on the lines below them, one per line at the least indentation,
207
+ with `or` or with `and`.
208
+
209
+ A rule whose `if` is followed by `:` has a numbered body, as LE2 writes one
210
+ after a statute:
211
+
212
+ ```text
213
+ an entity must register for GST if:
214
+ 1. the entity is a not-for-profit; and
215
+ 2. either:
216
+ 2.1. the entity has a turnover
217
+ 2.2. all of:
218
+ 2.2.1. the entity projected turnover is a projection; and
219
+ 2.2.2. the projection >= 150000.
220
+ ```
221
+
222
+ A designator such as `2.2.1.` begins its line. An item's trailing `and` or
223
+ `or`, after an optional `;`, joins it to the next item of its level, and an
224
+ item without one joins with `and`. An item `either:`, `any of:`,
225
+ `at least one of:`, `all of:` or `it is not the case that:` stands for the
226
+ items numbered below it, joined as the group says, or denied.
227
+
180
228
  An aggregate collects one value for every solution of its conditions, in the
181
229
  order they are found, as Prolog's `findall` does: a value found twice counts
182
230
  twice. The result phrase of an aggregate is the phrase before `is the`, after any
183
231
  connective.
184
232
 
233
+ ## Functions
234
+
235
+ A template of `the functions are:` is an ordinary template whose last place
236
+ follows `is`, such as `the price of a cup with capacity *a number* ml is *an
237
+ amount*`. Wherever a value is needed (a place of another template, a side of a
238
+ comparison, an operand of a formula or the conclusion of a rule), the template
239
+ can be written without `is` and its last place:
240
+ `the price of a cup with capacity the capacity ml > 10`. That phrase is a
241
+ variable that a call of the function binds, asked before the condition that
242
+ uses it, or after the conditions of a rule for its conclusion; a fact whose
243
+ conclusion calls a function is such a rule. One clause asks one call once. A
244
+ variable or a constant of the same name comes first. In a formula, an operand
245
+ is the words up to the next operator, and a function's last argument may be a
246
+ formula in brackets: `the double of (the fee + 1)`.
247
+
185
248
  ## Negation
186
249
 
187
250
  Variables that occur only inside a negation stand for any value there; eyemind
@@ -195,6 +258,40 @@ unbound (`is_var`), the negation stands for any value there; once bound
195
258
  variable of its conclusion open, no condition surely binds a variable, and
196
259
  every negation tests its variables in this way.
197
260
 
261
+ LE runs a rule top-down, so a negation or a collection may reach the rule's own
262
+ relation, through other rules, as long as the data never closes the cycle. LS
263
+ stratifies statically, so eyemind unfolds such a group of relations into eight
264
+ levels: a negation or collection at level k calls level k + 1, a relation of
265
+ its own, `NAME#k`. The answers are exact up to eight levels; a program that
266
+ needs more stops with an error that says so.
267
+
268
+ `C according to S`, written at the end of a condition or on a line indented
269
+ below it, is LE2's source-scoped proof: C must follow from the knowledge base
270
+ and only the scenario facts whose source is admissible under S. Every relation
271
+ C can reach compiles to a second relation, `NAME:sc`, with the scope as one
272
+ more argument, in which a scenario fact holds when its source is admissible
273
+ under the scope; a scenario fact without a source is never admissible. The
274
+ built-in template `*a source* is admissible under *a scope*` holds for a source
275
+ under itself and as the program's facts and rules say. When a template's own
276
+ words contain `according to`, a condition is read as that template first.
277
+
278
+ ## Embedded Prolog
279
+
280
+ A condition `prolog GOAL` runs a Prolog goal, as LE2 writes one: goals joined
281
+ by `,` and `;`, `\+ GOAL` for negation, `Module:GOAL`, and the tests `=`,
282
+ `\=`, `==`, `\==`, `<`, `>`, `=<`, `>=`, `atom/1`, `number/1`, `integer/1`,
283
+ `var/1`, `nonvar/1`, `true` and `fail`. An argument is a Prolog variable, atom,
284
+ number, list or compound, or an LE phrase such as `the person`; a definite
285
+ phrase that refers to no variable starts one. Other goals call the relations of
286
+ Prolog resources. LE2's system predicates are:
287
+
288
+ | Goal | Holds for |
289
+ | --- | --- |
290
+ | `le_my_kb(K)`, `le_kb(K)` | the name of the rule's knowledge base |
291
+ | `le_my_id(L)` | the rule's label |
292
+ | `le_source_element(L, D, G)` | the label of a rule with a numbered body, and each designator `D` of its conditions |
293
+ | `le_source_section(S, L)` | the section of a labelled rule: `main`, `annexes`, or the name of `section NAME is:` |
294
+
198
295
  ## Arithmetic, comparisons and built-in templates
199
296
 
200
297
  A comparison has `=`, `==`, `!=`, `\=`, `\==`, `<`, `>`, `<=`, `=<` or `>=`
@@ -243,21 +340,88 @@ scenario alice is:
243
340
  `NAME expects answers [...]` and `NAME expects [...]` state the answers the
244
341
  query `NAME` gives in the scenario. The answers may be quoted sentences or, as
245
342
  some examples write them, words up to a comma. An expectation with
246
- `and unknowns [...]` that lists unknowns, or with `and any unknowns`, rests on
247
- assumptions and is not compared; `and unknowns []` is.
248
- Each query is answered in each scenario, or once when the document has none.
343
+ `and unknowns [...]` also states the union of the unknowns the answers rest
344
+ on, and one with `and any unknowns` compares only the answers; one without
345
+ `and unknowns` wants answers that rest on none. Each query is answered in each
346
+ scenario, or once when the document has none.
347
+
348
+ ## Abduction
349
+
350
+ When the program cannot prove a sentence of an assumable template, an answer
351
+ can rest on the assumption that the sentence holds, as in LE2. The sentence is
352
+ then one of the answer's unknowns. `it is unknown whether SENTENCE.`, in the
353
+ knowledge base or in one scenario, makes the sentences that SENTENCE describes
354
+ assumable there, as in `it is unknown whether a payment is approved.`
355
+
356
+ Every relation that can reach an assumable sentence also compiles to a second
357
+ relation, `NAME:ab`, with one more argument: the list of the sentences it
358
+ assumes. Its rules are those of `NAME`, each condition that can reach an
359
+ assumable sentence called through its own `:ab` relation, and the lists
360
+ appended. An assumable relation also has the rule that assumes its sentence.
361
+ Each answer, `'le:answer'(..., U)`, gets the list `U` of its assumptions,
362
+ without each ground sentence that the facts and rules prove after all, through
363
+ `'le:unknowns'` and `'le:holds'`. An answer that holds with no assumption is
364
+ definite; otherwise each of its sets of assumptions is written after it:
365
+
366
+ ```text
367
+ % query explain with scenario observation
368
+ the grass is wet.
369
+ % assuming that it rained
370
+ % or assuming that the sprinkler was on
371
+ ```
372
+
373
+ A negation of a sentence that can rest on an assumption follows LE2. It finds
374
+ every way the sentence holds, with its assumptions; it fails when one way needs
375
+ none, and otherwise assumes, for each way, one of its assumptions false,
376
+ leaving out a way that contradicts what the answer assumes already. A
377
+ negative assumption is written `it is not the case that S`. A collection, and
378
+ the conditions of a universal, count every way with all its assumptions, as
379
+ LE2's maximal reading does. An assumption is not made when, at the time it is
380
+ asked, its sentence is proved, or a scenario denies it with
381
+ `it is not the case that S.`
382
+
383
+ An answer is rejected when it assumes a sentence and its negation, or assumes
384
+ false a sentence that the facts and rules prove. `it must not be true that C.`
385
+ is an integrity constraint: with the answer's assumptions as the only ones,
386
+ C must not hold. A violation whose missing piece is a negated assumable
387
+ sentence, as in `... and it is not the case that the second person is married
388
+ to the person`, is repaired by assuming that sentence too; another violation
389
+ rejects the answer. Facts that break a constraint alone leave the scenario
390
+ without answers. The constraints compile to `NAME:w` relations, in which an
391
+ assumable sentence holds when proved or assumed, and `'le:violation'`.
392
+
393
+ ## Flip queries
394
+
395
+ `query NAME is: which minimal change to the scenario makes it the case that
396
+ GOAL.` asks, for each scenario, for the smallest sets of changes after which
397
+ GOAL holds without assumptions. A change adds or removes a fact of a template
398
+ marked `; undefined` or `; judged`, or, in a program without such marks, of a
399
+ template that no rule concludes and that is no function. A place is filled with
400
+ the individuals the scenario names as of the place's type, or with all its
401
+ individuals when it names none; a kind is no individual, and a template of more
402
+ than two places is not filled. A set has at most three changes. Each changed
403
+ world `'le:flip'(S, CHANGES)` states its facts as ground facts, so a search
404
+ whose worlds would need more than 200000 facts is refused. An answer is written
405
+ `add: S and remove: T`, or `no change is needed`, and
406
+ `NAME expects changes [["add: S"], ...]` states the expected sets.
249
407
 
250
408
  ## Compilation to LS
251
409
 
252
410
  Facts and rules compile to LS facts and backward rules (`implied_by`), as LE's
253
411
  Prolog target runs them; a ground fact is `fact(...)`, a fact with a variable a
254
- backward rule with the body `'true'`.
412
+ backward rule with the body `'true'`. LE1 runs recursive rules with tabling and
413
+ LE2 with a loop check, so a group of relations that depend on themselves
414
+ compiles to forward rules (`implies`), which reach the least fixpoint, when
415
+ each of its rules binds every variable of its conclusion through the relations
416
+ of its conditions; a rule that depends on how it is called, such as a counter
417
+ that goes down, stays backward.
255
418
 
256
419
  When a document has scenarios, every relation gets the scenario as its first
257
420
  argument, a scenario's clauses have the scenario's name there, and the
258
421
  knowledge base's clauses have a variable there, bound by the facts
259
- `'le:scenario'(NAME)`. A knowledge-base fact becomes a rule whose body is
260
- `'le:scenario'(S)`. So the knowledge base holds in every scenario and a
422
+ `'le:scenario'(NAME)`. A ground knowledge-base fact is stated once in each
423
+ scenario, and another becomes a rule whose body is `'le:scenario'(S)`. So the
424
+ knowledge base holds in every scenario and a
261
425
  scenario's facts in that one, and one program and one proof answer every query
262
426
  in every scenario.
263
427
 
@@ -266,6 +430,11 @@ whose body starts with `'le:scenario'(S)` when there are scenarios, and the
266
430
  statement `query('le:answer'(NAME, S, V1, ...))`. `V1, ...` are the variables of
267
431
  the query outside negations and collections, in the order they appear.
268
432
 
433
+ A sum, count, average, minimum or maximum collects its values with
434
+ `findall_sorted`, since it does not depend on their order, and a proof can
435
+ then certify it even when the values rest on derived facts; `list` and
436
+ `collection` keep the order found, with `findall`.
437
+
269
438
  Aggregates, divisions, lists and dates use backward helper rules whose names
270
439
  start with `le:` (`le:sum`, `le:count`, `le:days_after`, ...); no template name
271
440
  can contain `:`. The helpers follow the document's clauses. `--program` prints
@@ -294,23 +463,25 @@ compares the answers as a set.
294
463
 
295
464
  `--to le` writes the answers of an LE run only; `--to eyemind` writes the
296
465
  `'le:answer'` terms. Proofs and check reports are `.js` documents of the
297
- compiled LS program, and check against it. That the program reads the English
466
+ compiled LS program, and check against it; with abduction, a checked proof
467
+ establishes each answer with the assumptions it lists. That the program reads the English
298
468
  as intended is a matter of the compiler and its tests; a checked proof
299
469
  establishes the answers under the compiled rules.
300
470
 
301
471
  ## Not supported
302
472
 
303
473
  These belong to Logical English 2, or to the Prolog that LE1 can embed, and
304
- are errors: the template additions the table above leaves out,
305
- `the functions are:`, `the fluents are:`, `the events are:` and the other
306
- dynamic and meta sections, facts backgrounds, included web addresses and
307
- Prolog resources, embedded `prolog` goals, numbered conditions, provenance
308
- trailers and document locations, `it is unknown whether`,
309
- `it must not be true that`, negated facts in scenarios, negated assumable
310
- sentences (abduction), flip queries (`expects changes`), scenario headers with
311
- provenance, `otherwise`, `unless`, `according to`, decision tables, services,
312
- LPS and s(CASP). eyemind does not
313
- check types: the head noun of a place is not a type constraint. A program whose
314
- negation lies on a dependency cycle compiles, and the LS program is then
315
- rejected unless it is chain-stratified (LS-SPEC Section 6.4), where Prolog would
316
- run it.
474
+ are errors: the template additions the table above leaves out, such as
475
+ `; prepositional` and `; via service`, `the fluents are:`, `the events are:`
476
+ and the other dynamic and meta sections, Prolog goals other than those of
477
+ Embedded Prolog, `otherwise`, `unless`, decision tables, services, views, LPS
478
+ and s(CASP). eyemind does not check types: the head noun of a place is not a
479
+ type constraint, except that a flip query fills a place with individuals of
480
+ its type.
481
+
482
+ Some of LE2's readings are lenient, and eyemind follows them: a name's
483
+ underscores are spaces (`Sales Associates` refers to `a Sales_Associates`); a
484
+ formula over a name, which Prolog stops with an error, fails; a scenario fact
485
+ `A is B` that no template matches states the relation `le_is`; after a type, a
486
+ short capitalized word is an id, as in `a number MyD`; and an expected number
487
+ with decimals matches an answer rounded to as many decimals.
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.1
5
+ Version: eyemind 0.9.2
6
6
  ```
7
7
 
8
8
  This document specifies Logic Script (LS): the syntax and meaning of its
package/README.md CHANGED
@@ -253,10 +253,12 @@ the program reads the English as intended is a matter of the compiler. Several
253
253
  `.le` files form one document, without other input formats or RDF logic
254
254
  switches.
255
255
 
256
- Of Logical English 2, eyemind also reads constants, included files, rule labels,
257
- `only if` rules and the template additions `synonym`, `opposite` and those that
258
- change nothing it computes. Abduction (assumptions and constraints), functions,
259
- type checking, embedded Prolog, LPS and s(CASP) are reported as unsupported. Every `npm test` scores the
256
+ Of Logical English 2, eyemind also reads constants, functions, included files
257
+ and web addresses, Prolog resources and embedded Prolog goals with LE2's system
258
+ predicates, rule labels, numbered and grouped conditions, `only if` rules, the
259
+ template additions `synonym` and `opposite`, provenance with source-scoped
260
+ proof, abduction with negation and integrity constraints, and flip queries.
261
+ LPS, s(CASP), decision tables and services are reported as unsupported. Every `npm test` scores the
260
262
  [Logical English 2 examples](test/UPSTREAM.md) that state their expected
261
263
  answers, as coverage: a wrong answer fails the run, a file that uses an
262
264
  unsupported feature is counted as not passed.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eyemind",
3
- "version": "0.9.1",
3
+ "version": "0.9.2",
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",