eyemind 0.8.51 → 0.9.0

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
@@ -1,574 +1,273 @@
1
1
  # Logical English
2
2
 
3
- eyemind reads `.le` files as the language defined here and compiles
4
- them to ordinary Logic Script (LS). This is an input extension; the meaning of
5
- the compiled program is defined by the [LS specification](https://eyereasoner.github.io/eyemind/LS-SPEC).
6
- It supports statements and computations in a fixed grammar. It does not parse
7
- arbitrary mathematical prose or check textbook proof arguments.
8
-
9
- ## Documents and names
10
-
11
- A document is a sequence of sentences, each ending in `.`. Whitespace and line
12
- breaks separate tokens; a sentence can span lines. `#` starts a comment through
13
- the end of the line, except inside a quoted name. Examples separate their header
14
- comments from the body and put an empty line before each body comment block.
15
-
16
- Keywords are case-insensitive. Names are case-sensitive. Class and relation
17
- names start with a lowercase ASCII letter, followed by ASCII letters, digits or
18
- underscores. Names of LS primitives and controls are reserved as relation names.
19
- There is no implicit vocabulary, pluralization, pronoun resolution or spelling
20
- normalization. `integer`, for example, is a user-defined class whose facts supply
21
- its members; it does not enumerate all mathematical integers.
22
-
23
- An individual can be an unquoted name such as `Socrates` or `alice`. A variable
24
- is one capital ASCII letter optionally followed by digits, such as `X` or `Y1`.
25
- Variables must be declared in their sentence; a quoted `"X"` is an individual.
26
- Names containing spaces, punctuation or non-ASCII characters use JSON double
27
- quotes, as in `"René Descartes"`. JSON escapes retain their usual meanings.
28
- Quote names that would introduce a sentence, such as `"Every"` or `"If"`.
29
-
30
- Terms also include integers, floats, closed lists and compounds:
31
-
32
- ```text
33
- 9007199254740993
34
- -0.0
35
- [Alice, Bob, [1, 2]]
36
- pair(Alice, Bob)
37
- "a compound name"(Alice, 1)
38
- ```
39
-
40
- Integers have optional leading `-`, no leading zero except `0`, and arbitrary
41
- precision. A decimal point with digits on both sides, or an exponent, denotes a
42
- finite binary64 float: `1.0`, `0.25`, `1e3`. Integers and floats remain distinct
43
- terms. `1.` is integer `1` followed by the sentence terminator. Nonfinite numeric
44
- tokens are rejected. A compound has at least one argument. A closed list may be
45
- empty; there is no open-list surface syntax, although a `"."(Head, Tail)` compound
46
- can retain an LS list with a nonempty tail as data. Term and expression
47
- nesting is limited to 256 levels.
48
-
49
- ## Positive statements
50
-
51
- The following forms have the indicated LS meanings. `T`, `U` and the arguments
52
- stand for terms; `class` and `relation` stand for names as defined above.
53
-
54
- | LE form | LS term |
55
- | --- | --- |
56
- | `T is a class` | `class(T)` |
57
- | `T is an class` | `class(T)` |
58
- | `T is class` | `class(T)` |
59
- | `T is a relation of U` | `relation(T, U)` |
60
- | `T is an relation of U` | `relation(T, U)` |
61
- | `T has relation U` | `relation(T, U)` |
62
- | `relation(T, U, ...)` | The corresponding compound goal. |
63
- | `relation` | An atom used as a goal, with arity zero. |
64
-
65
- The articles `a` and `an` have the same semantics. They do not introduce an
66
- existential variable. For example, `Socrates is a human.` states
67
- `fact(human('Socrates'))`. Write an existential declaration to introduce an
68
- unnamed individual.
69
-
70
- `and` joins positive statements. A sentence containing only positive statements
71
- states them as facts. A universally quantified fact is explicit:
72
-
73
- ```text
74
- Ada is a human and Ada is a mathematician.
75
- For every X, matching(pair(X, X)).
76
- ```
77
-
78
- Variables declared by `For every` are universal within that sentence. Each
79
- sentence has its own scope. Repeating a declaration in one scope is an error.
80
-
81
- ## RDF vocabulary names
82
-
83
- Declare a prefix before using its names. ODRL, DPV and DPV extension
84
- namespaces can appear together in the same file.
85
-
86
- ```text
87
- Use prefix ex with namespace "https://example.org/research#".
88
- Use prefix odrl with namespace "http://www.w3.org/ns/odrl/2/".
89
- Use prefix dpv with namespace "https://w3id.org/dpv#".
90
-
91
- ex:agreement is an odrl:Agreement.
92
- ex:study is a dpv:Process.
93
- ex:study has dpv:hasPurpose dpv:AcademicResearch.
94
-
95
- Find every X such that X has dpv:hasPurpose dpv:AcademicResearch.
96
- ```
97
-
98
- Prefixes start with an ASCII letter and can also contain digits and
99
- underscores. Local names contain ASCII letters, digits, underscores and
100
- hyphens, and cannot start with a hyphen. Prefixes and local names are
101
- case-sensitive. A declaration binds a prefix to a quoted absolute IRI.
102
- Each file declares its own prefixes, at most once per prefix. Prefix
103
- expansion appends the local name to the namespace exactly as stated.
104
- `iri("...")` terms can express IRIs outside this abbreviation syntax.
105
-
106
- In facts, rules and questions, a qualified class or property uses the
107
- same `rdf/3` relation:
108
-
109
- | LE form | LS term |
3
+ [Logical English](https://github.com/LogicalContractsOrg/LogicalEnglish) (LE)
4
+ is the controlled natural language of Robert Kowalski, Jacinto Dávila, Miguel
5
+ Calejo, Galileo Sartor and their colleagues for writing legal and business
6
+ rules as English that a computer runs. eyemind reads `.le` files in the core
7
+ that the original implementation, LE 1.0 with its
8
+ [syntax document](https://github.com/LogicalContractsOrg/LogicalEnglish/blob/main/le_syntax.md),
9
+ and [Logical English 2](https://github.com/LogicalContractsOrg/LogicalEnglish2)
10
+ share, and compiles them to ordinary Logic Script (LS). This is an input
11
+ extension: the meaning of the compiled program is defined by the
12
+ [LS specification](https://eyereasoner.github.io/eyemind/LS-SPEC), and this
13
+ document says how eyemind reads LE and what it compiles each part to. Where the
14
+ two LE implementations differ, it says which reading eyemind follows.
15
+
16
+ ## Documents
17
+
18
+ A document is a sequence of sections. Each section starts with a header that
19
+ ends with `:`:
20
+
21
+ | Header | Section |
110
22
  | --- | --- |
111
- | `T is a ex:Class` | `rdf(T, iri("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"), iri("https://example.org/research#Class"))` |
112
- | `T has ex:property U` or `T is an ex:property of U` | `rdf(T, iri("https://example.org/research#property"), U)` |
113
- | `ex:item` in any term position | `iri("https://example.org/research#item")` |
114
-
115
- `Every` rules also accept qualified classes on either side. Qualified
116
- statements take a resource or variable as their subject. Objects can
117
- also be numbers and explicit RDF terms such as
118
- `literal("dataset", datatype("http://www.w3.org/2001/XMLSchema#string"))`.
119
- Ordinary unqualified class and relation names retain their LS meanings.
120
-
121
- The default LE output abbreviates IRIs using available prefixes and
122
- includes the declarations it uses. Other IRIs retain their explicit
123
- terms. When input files assign the same prefix to different namespaces,
124
- the final declaration supplies the output abbreviation. Earlier files'
125
- expanded IRIs retain their values. For triple conclusions, `--to turtle`
126
- writes the RDF graph and `--all` adds the stated RDF facts.
127
-
128
- Prefix declarations specify names. The facts and rules supply their
129
- meaning for a run. The research access example uses ODRL permissions,
130
- prohibitions, constraints and a duty with DPV purpose and consent
131
- evidence. Its ordinary LE rules specify the scenario's policy decisions; a
132
- Turtle companion decides similar requests with the ODRL snapshot evaluator.
133
- [Research access example](https://eyereasoner.github.io/eyemind/examples/deck/research-access-le) · [Turtle companion](https://eyereasoner.github.io/eyemind/examples/deck/research-access-odrl) · [ODRL Vocabulary](https://www.w3.org/TR/odrl-vocab/) · [Data Privacy Vocabulary 2.3](https://w3id.org/dpv/2.3/dpv/)
134
-
135
- ## Rules and calculations
23
+ | `the templates are:`, `the predicates are:` | Templates, separated by commas or full stops. |
24
+ | `the knowledge base NAME includes:`, `the contract NAME states that:` | Facts and rules. |
25
+ | `the ontology is:` | Facts and rules; a fact `a student is a person.` relates the kinds `student` and `person`. |
26
+ | `scenario NAME is:` | Facts and rules of one scenario, and its expected answers. |
27
+ | `query NAME is:` | One query. |
136
28
 
137
- ```text
138
- Every human is mortal.
139
- Every human is mortal and animal.
140
- For every X and Y, if X is a parent of Y then X is an ancestor of Y.
141
- If Alice is a person then Alice is a participant.
142
- ```
29
+ `the target language is: prolog.` is accepted and ignored. The sections can
30
+ come in any order, and a template can be used before it is declared. Several
31
+ `.le` files are read as one document.
143
32
 
144
- `Every A is B.` compiles to `implies(A(X), B(X))`, with a fresh clause-local
145
- variable; `a` or `an` may precede each class after `is`, as in
146
- `Every human is a mortal.`. An if/then sentence compiles its premises and conclusions to one
147
- forward LS rule. Both sides may contain conjunctions. A conclusion variable
148
- must be supplied by a premise or explicitly declared existentially. The
149
- compiler checks the stated order of premises for calculations and absence tests;
150
- actual values must also satisfy LS's runtime requirements.
33
+ Sentences end with a full stop followed by white space or the end of the file;
34
+ a sentence can span lines. `%` or `#` starts a comment through the end of the
35
+ line, and `/* ... */` is a block comment. Words are compared without case.
151
36
 
152
- These additional forms are available in premises and questions:
37
+ A token is a word (letters, digits and underscores, joined by hyphens or
38
+ apostrophes, as in `JE-201` and `don't`), a final `'s` as a word of its own, a
39
+ number (`42`, `3.14`, `1,000,000`), a date (`2021-10-09`), a quoted text
40
+ (`"..."` or `'...'`), or a punctuation sign. The indentation of a line counts a
41
+ space as one and a tab as four, as LE's editor shows it.
153
42
 
154
- | LE form | LS goal |
155
- | --- | --- |
156
- | `Y is the value of E` | `is(Y, E)` |
157
- | `X is greater than E` | `gt(X, E)` |
158
- | `X is less than E` | `lt(X, E)` |
159
- | `X is at least E` | `ge(X, E)` |
160
- | `X is at most E` | `le(X, E)` |
161
- | `X is equal to E` | `eq(X, E)` |
162
- | `X is different from E` | `ne(X, E)` |
163
-
164
- Expressions contain numbers, declared variables, parentheses, unary `-` and
165
- binary `+`, `-`, `*`, `/`. Unary minus binds most tightly, then multiplication
166
- and division, then addition and subtraction. Binary operators associate left.
167
- They compile to `neg`, `add`, `sub`, `mul` and `div`. Only the value-of form
168
- binds its left variable; comparisons require their inputs beforehand.
169
-
170
- An expression can also call an LS arithmetic function by name, with
171
- expressions as its arguments, and use the constants `pi`, `e` and `tau`:
43
+ ## Templates
172
44
 
173
- ```text
174
- For every X and Y, if X is a number and Y is the value of exp(log(X) * 3) + gcd(12, 18) * cos(pi)
175
- then Y is a result of X.
176
- ```
177
-
178
- The functions are those of [LS-SPEC Section 5.2](https://eyereasoner.github.io/eyemind/LS-SPEC#52-functions-and-arities),
179
- such as `pow`, `floordiv`, `mod`, `gcd`, `lcm`, `sqrt`, `exp`, `log`, `sin`,
180
- `cos`, `atan2`, `abs` and `hypot`, except `and`, `or` and `not`, which are LE
181
- words. A call with an arity the function does not take is an error naming
182
- its line. As in LS, `pow` and `floordiv` of integers stay exact, while
183
- `exp`, `log` and the trigonometric functions give floats.
45
+ A template is a sentence pattern: words and places. A place is a phrase between
46
+ asterisks, such as `*a person*`; LE1 also writes templates without asterisks,
47
+ and in a template without any, `a` or `an` and the word after it make a place.
184
48
 
185
49
  ```text
186
- 4 is an integer.
187
- For every X and Y, if X is an integer and Y is the value of X * X
188
- then Y is a square of X.
50
+ the templates are:
51
+ *a person* acquires British citizenship on *a date*,
52
+ *a person* says that *a sentence*,
53
+ a person has a balance.
189
54
  ```
190
55
 
191
- Arithmetic follows LS: integer addition, subtraction and multiplication are
192
- exact; division returns a float; mixed integer/float arithmetic returns a
193
- float. Numeric equality compares values, while ordinary relation matching
194
- keeps integer and float terms distinct. Calculations belong in premises,
195
- followed by relational conclusions. These calculations do not prove arbitrary
196
- algebraic identities or supply induction.
197
-
198
- ## Alternative premises
56
+ Each template is a relation whose name joins its words with underscores and
57
+ whose arguments are its places in order: `acquires_British_citizenship_on/2`,
58
+ `says_that/2`, `has/2`. A name that is an LS primitive or control, or `date`,
59
+ gets the prefix `le_`. Two templates with different words for one name and
60
+ arity are an error. A place after the word `that` holds a sentence.
61
+
62
+ ## Sentences
63
+
64
+ A sentence matches a template when it has the template's words in order, with
65
+ at least one token in each place and balanced brackets in each. eyemind tries
66
+ the templates with a `that` place first, as LE does, then the templates with the
67
+ most words, a declared template before a built-in one, and takes the first that
68
+ matches with a valid term in every place. A sentence that matches no template
69
+ is an error that quotes it.
70
+
71
+ The tokens in a place are a term:
72
+
73
+ - A number is an exact integer, or a float when it has a fraction or an
74
+ exponent; `-` before a number negates it. Commas may group thousands.
75
+ - A date is the compound `date(Year, Month, Day)`.
76
+ - A quoted text is a name.
77
+ - `[A, B, C]` is a list of terms.
78
+ - `a`, `an`, `some`, `each` or `which`, followed by at most six words,
79
+ introduces a variable: `a person`, `an other person`, `a second date`. The
80
+ same phrase again is the same variable.
81
+ - `the` followed by the words of a variable introduced earlier in the clause
82
+ refers to it: `the person`, `the other person`. A definite phrase that refers
83
+ to no variable is a name, written with its article: `the UK`, `the white
84
+ rabbit`. This follows LE2; the same phrase names the same thing everywhere.
85
+ - A phrase whose last word is an id names its variable by the id: `a person X`
86
+ is the variable `X`, and `X` alone then refers to it. An id is one capital
87
+ letter with optional digits, or a word of at most six capitals and digits
88
+ other than `UK`. eyemind does not read LE2's short proper names such as `Bob`
89
+ as ids: LE1 programs use them as names.
90
+ - A single capital letter with optional digits, such as `L` or `T1`, is a
91
+ variable even when no phrase introduced it. Longer ids need an introducing
92
+ phrase, because LE1 programs use acronyms such as `GST` as names.
93
+ - Other words are a name, written as they are, such as `Socrates` or
94
+ `cash at bank`.
95
+
96
+ In the place of a `that`, a sentence of a template is a term: the template's
97
+ relation with its arguments, as data.
98
+
99
+ ## Facts and rules
100
+
101
+ In a knowledge base or a scenario, a sentence is a fact, or a rule
102
+ `conclusion if conditions.` The conclusion matches a declared template or the
103
+ type template `*an object* is a *type*` (the relation `is_a/2`, whose type is a
104
+ name). A fact with a variable holds for every value. In an ontology, a fact
105
+ whose subject starts with `a` or `an` is about the kind: `a student is a person.`
106
+ states `is_a('student', 'person')`.
107
+
108
+ The conditions are joined by `and` and `or`. Each connective has the
109
+ indentation of its line; a connective in the middle of a line has the
110
+ indentation of that line, and a line break without a connective joins the lines
111
+ with `and` where both lines are conditions. eyemind reads the connectives as
112
+ LE's indentation does: the conditions are split at the least indented
113
+ connectives, joined from the top down, and each part is read in the same way.
114
+ So a deeper indentation binds tighter:
199
115
 
200
116
  ```text
201
- Every cat or dog is a pet.
202
- For every V, if V is registered or V is a provisionalVoter and V is verified
203
- then V is an eligibleVoter.
204
- For every X, it is impossible that X is a minor and X is a voter or X is barred.
117
+ a person is eligible a person is eligible
118
+ if the person is a resident if the person is a resident
119
+ or the person is a citizen or the person is a citizen
120
+ and the person is an adult. and the person is an adult.
205
121
  ```
206
122
 
207
- `or` separates alternative premises of a rule or contradiction. `and` binds
208
- more tightly, so each alternative is a conjunction; there are no parentheses
209
- around alternatives. Each alternative compiles to its own LS clause with the
210
- same conclusion, in the order written: `Every A or B is C.` is
211
- `implies(A(X), C(X))` followed by `implies(B(X), C(X))`. The sentence's
212
- declarations are shared, and an alternative need not use every declared
213
- variable, but each conclusion variable must be supplied by every alternative
214
- or introduced with `there exists`. An existential conclusion therefore has a
215
- witness per alternative and firing. The order of premises is checked within
216
- each alternative.
217
-
218
- Questions have no `or`: ask one question per alternative, or ask for a relation
219
- that an `or` rule derives. Conclusions are never disjunctive.
220
-
221
- ## Aggregates
222
-
223
- ```text
224
- For every M and T,
225
- if M is a member and T is the sum of F for every C and F such that charge(M, C, F)
226
- then T is an amountDue of M.
227
- For every V and N,
228
- if V is a participant and N is the number of C such that choice(V, C) and N is at least 2
229
- then V is a spoiledVoter.
230
- For every C and N,
231
- if C is a candidate and N is the number of V such that
232
- (choice(V, C) and V is an eligibleVoter and it is not known that V is a spoiledVoter)
233
- then N is a voteCount of C.
234
- ```
123
+ The left rule means *(resident or citizen) and adult*, the right one *resident
124
+ or (citizen and adult)*. LE1 rejects different connectives at one indentation;
125
+ eyemind reads them from the top down, as LE2 does. A body may start with `and`
126
+ after `if`, as some LE1 programs write it.
235
127
 
236
- These premise forms collect every solution of a condition:
128
+ A condition is a sentence of a template, a comparison, or one of the following,
129
+ each of which takes the lines that follow it up to the next line that starts
130
+ with a connective at the same or a lesser indentation:
237
131
 
238
- | LE form | Result |
132
+ | Condition | LS |
239
133
  | --- | --- |
240
- | `N is the number of X1 and ... such that C` | The number of distinct combinations of `X1 ...` satisfying `C`. |
241
- | `S is the sum of V for every X1 and ... such that C` | The sum of `V` over those combinations; `0` when there are none. |
242
- | `M is the maximum of V for every X1 and ... such that C` | The greatest `V` over those combinations; no result when there are none. |
243
- | `M is the minimum of V for every X1 and ... such that C` | The least `V` over those combinations; no result when there are none. |
244
-
245
- The variables after `the number of` or `for every` are declared by the
246
- aggregate, must be new in the sentence, and cannot be used after it. `V` must
247
- be one of them. The condition `C` is one statement, or a conjunction in
248
- parentheses; it can use calculations, comparisons and absence tests, but no
249
- `or` and no other aggregate. Any other variable of `C` must be supplied by an earlier premise. The
250
- left-hand side is a declared variable or a number, as in the value-of form:
251
- an unbound variable receives the result and a bound one is compared with it.
252
-
253
- Each distinct combination of the declared variables' values counts once, however
254
- many derivations it has. To count distinct values of one variable when the
255
- condition needs others, derive a relation of that variable first, as
256
- `choice(V, C)` above does for ballots. Values are summed with LS arithmetic, so
257
- integers stay exact and a float makes the sum a float; maximum and minimum
258
- compare numerically.
259
-
260
- An aggregate compiles to
261
- `findall_sorted(t(V, X1, ...), C, L)`, followed by goals of backward helper
262
- relations named `le:distinct`, `le:count`, `le:sum`, `le:max` and `le:min`,
263
- which remove repeated tuples and fold the rest. The helpers are added after
264
- the program's own clauses, only when used, so they do not change the rule
265
- numbers of witnesses; their names cannot be written as LE names. Like a
266
- negation, an aggregate waits until the relations of its condition are complete,
267
- so a program cannot aggregate over a relation that depends on the aggregate's
268
- own result. Questions cannot aggregate: derive the aggregate in a rule and ask
269
- for its conclusion.
270
-
271
- ## Absence and existential conclusions
272
-
273
- An absence test has exactly this form, followed by one positive statement:
274
-
275
- ```text
276
- For every X, if X is a person and it is not known that X is blocked
277
- then X is an applicant.
278
- ```
279
-
280
- It compiles to `not(blocked(X))`. Its variables must be supplied by earlier
281
- positive premises or calculations. LS stratification decides when the tested
282
- relation is complete. This means absence of a proof in this program, rather
283
- than classical mathematical negation. Ordinary `not` is rejected. Explicit
284
- negative evidence can use its own positive relation, such as `not_human`.
285
-
286
- ```text
287
- For every X, if X is a person then there exists Y such that
288
- Y is a record and X is an owner of Y.
289
- There exists X such that X is a record.
290
- ```
291
-
292
- `there exists` introduces fresh variables for a conclusion, after any universal
293
- declarations. Every introduced variable must occur in that conclusion. The
294
- compiler uses an ordinary LS forward rule with head-only variables; a standalone
295
- existential sentence uses premise `'true'`. LS supplies Skolem witnesses. The
296
- same variable shares one witness across the heads of that firing. A witness
297
- does not assert a distinct real-world object or a minimum number of objects.
298
-
299
- ## Questions and contradictions
300
-
301
- ```text
302
- Find every X such that X is mortal.
303
- Find every X and Y such that X is an ancestor of Y.
304
- Find whether Socrates is mortal.
305
- For every X, it is impossible that X is a person and X is blocked.
306
- It is impossible that Alice is blocked.
307
- Contradiction.
308
- ```
309
-
310
- Questions compile to `query(...)`; their declarations establish variable scope,
311
- and the answers are instances of the whole question, without a separate
312
- projection. `Find whether` introduces no variables. A question can use a
313
- conjunction, calculations and absence tests. Without questions the run reports
314
- derived conclusions, following LS's default; given facts alone are not printed.
315
-
316
- `It is impossible that` compiles to an LS contradiction with the stated body.
317
- `Contradiction.` is an unconditional contradiction, also used to serialize a
318
- run's `'false'` conclusion. Contradictions halt reasoning with exit code 65;
319
- they do not produce the continuing RDF conflict reports of `--owl2rl`.
320
-
321
- ## Examples combining features
322
-
323
- These programs use the grammar above without additional syntax:
324
-
325
- | Example | What it demonstrates |
134
+ | `it is not the case that C`, `not the case that C` | `not(C)` |
135
+ | `for all cases in which C it is the case that D` | `not([C, not(D)])` |
136
+ | `R is the sum of each X such that C` | `findall(X, C, L)` and the sum of `L`; `0` for none |
137
+ | `R is the count of each X such that C` | the length of `L`; `0` for none |
138
+ | `R is the average of each X such that C` | the sum divided by the count; none for none |
139
+ | `R is the min of each X such that C`, `minimum`, `max`, `maximum` | the least or greatest of `L`; none for none |
140
+ | `R is the list of each X such that C` | `L` itself |
141
+ | `R is a collection of X where C` | `L` itself, as LE1 writes it |
142
+
143
+ An aggregate collects one value for every solution of its conditions, in the
144
+ order they are found, as Prolog's `findall` does: a value found twice counts
145
+ twice. The result phrase of an aggregate is the phrase before `is the`, after any
146
+ connective.
147
+
148
+ ## Negation
149
+
150
+ Variables that occur only inside a negation stand for any value there; eyemind
151
+ renames them `_0`, `_1`, ..., which LS negation treats as anonymous. LE's rules
152
+ are written for Prolog, whose negation also succeeds when no instance of its
153
+ goal holds if one of its variables is unbound. LS requires the named variables
154
+ of a negation to be bound, so a negation with a variable no earlier condition
155
+ binds, up to three such variables, tests each one at run time: while it is
156
+ unbound (`is_var`), the negation stands for any value there; once bound
157
+ (`is_nonvar`), it is that value. When a fact or rule of the document leaves a
158
+ variable of its conclusion open, no condition surely binds a variable, and
159
+ every negation tests its variables in this way.
160
+
161
+ ## Arithmetic, comparisons and built-in templates
162
+
163
+ A comparison has `=`, `==`, `!=`, `\=`, `\==`, `<`, `>`, `<=`, `=<` or `>=`
164
+ between two sides. A side is a term, or a formula of terms with `+`, `-`, `*`,
165
+ `/`, `//`, `mod`, parentheses and the functions `ceiling`, `floor`, `round`,
166
+ `truncate`, `integer`, `abs` and `sqrt`. A term in a formula is any of the terms
167
+ above, such as `the gain = the proceeds - the cost base`.
168
+
169
+ | Comparison | LS |
326
170
  | --- | --- |
327
- | [Shortest paths](https://eyereasoner.github.io/eyemind/examples/deck/shortest-path-le) | Bounded recursive histories, exact costs and minimum selection by absence, retaining ties. |
328
- | [River crossing](https://eyereasoner.github.io/eyemind/examples/deck/river-crossing-le) | Compound states, repeated-variable matching, safety constraints and complete plans within a bound. |
329
- | [Pell equations](https://eyereasoner.github.io/eyemind/examples/deck/pell-equation-le) | Recursive arithmetic beyond binary64 integer precision and exact polynomial checks. |
330
- | [Course certificates](https://eyereasoner.github.io/eyemind/examples/deck/course-certificates-le) | Recursive requirements, absence of a counterexample, shared existential witnesses and witnesses containing earlier witnesses. |
331
- | [Symbolic differentiation](https://eyereasoner.github.io/eyemind/examples/deck/symbolic-derivative-le) | Structural recursion over expression trees, constructed derivatives and evaluation at separate points. |
332
- | [British citizenship](https://eyereasoner.github.io/eyemind/examples/deck/british-citizenship-le) | Section 1 of the British Nationality Act 1981: alternative premises, a presumption that holds unless the contrary is shown, date comparisons and citizenship through a derived parent. |
333
- | [Library fines](https://eyereasoner.github.io/eyemind/examples/deck/library-fines-le) | Charges from alternative rules, then the sum, number and maximum per member over distinct combinations. |
334
- | [Election tally](https://eyereasoner.github.io/eyemind/examples/deck/election-tally-le) | Eligibility by alternatives, distinct choices, an absence test inside a count, winners by maximum with ties, and a quorum. |
335
- | [International data transfers](https://eyereasoner.github.io/eyemind/examples/deck/data-transfers-le) | An ODRL snapshot with rules: GDPR Chapter V observations derived with alternative premises and absence tests over DPV, location and GDPR-extension names, decided by one permission per basis and a prohibition that wins. |
336
- | [Breach notification](https://eyereasoner.github.io/eyemind/examples/deck/breach-notification-le) | An ODRL snapshot with rules: GDPR Articles 33 and 34 as permissions and prohibitions, with requests, observations and a processor's duty evidence derived from breach records by comparisons over hours. |
337
-
338
- Their decks state the modeled assumptions and what the checked proofs establish.
339
- Bounds and finite expression domains are explicit in the programs.
340
-
341
- ## DPV hierarchies
171
+ | `A = B`, `A == B`, `A is equal to B` | `unify(A, B)` between terms; `is` when one side is a formula; `eq` between formulas |
172
+ | `A != B`, `A \= B`, `A is different from B`, `A is not equal to B` | `not_unify(A, B)` between terms; `ne` otherwise |
173
+ | `A \== B` | `not_identical(A, B)` |
174
+ | `<`, `>`, `<=` or `=<`, `>=`, and `is less than`, `is greater than`, `is less than or equal to`, `is greater than or equal to`, `is less or equal to`, `is greater or equal to` | `lt`, `gt`, `le`, `ge` |
342
175
 
343
- ```text
344
- Use DPV hierarchy logic.
345
- Use prefix ex with namespace "https://example.org/research#".
346
- Use prefix dpv with namespace "https://w3id.org/dpv#".
347
- Use prefix skos with namespace "http://www.w3.org/2004/02/skos/core#".
348
-
349
- ex:study has dpv:hasPurpose dpv:AcademicResearch.
350
- dpv:AcademicResearch has skos:broader dpv:ResearchAndDevelopment.
351
- Find whether ex:study has purposeWithin dpv:ResearchAndDevelopment.
352
- ```
176
+ `/` divides as Prolog does: integers that divide give an integer, other
177
+ operands a float. `//` is floor division. LE1's `A is B` equates or evaluates
178
+ as `=` does when a side is a variable or a formula; between two names no
179
+ template matches.
353
180
 
354
- The directive adds hierarchy rules to an ordinary LE program. The
355
- program supplies its observations and SKOS edges. DPV 2.3 uses SKOS
356
- broader and narrower relations for its default taxonomy representation.
357
- [DPV 2.3](https://w3id.org/dpv/2.3/dpv/)
358
-
359
- | Observation property | LE conclusion |
181
+ | Built-in template | LS |
360
182
  | --- | --- |
361
- | `dpv:hasPurpose` | `X has purposeWithin C` |
362
- | `dpv:hasData` | `X has dataWithin C` |
363
- | `dpv:hasPersonalData` | `X has personalDataWithin C` |
364
-
365
- Each conclusion matches an observed category itself and its ancestors
366
- reached by transitively following the supplied IRI-to-IRI
367
- `skos:broader` and `skos:broaderTransitive` edges, or the inverse of
368
- `skos:narrower` and `skos:narrowerTransitive`. A snapshot uses the same
369
- hierarchy through its `withinCategory` operator.
370
-
371
- ## ODRL snapshots
372
-
373
- An LE file can explicitly select the existing ODRL snapshot evaluator:
183
+ | `*a* is after *b*`, `is before`, `is after or equal to`, `is before or equal to`, `is not before` | the standard order with `compare`, so dates compare in time order |
184
+ | `*a* is *n* days after *b*`, `*a* is *n* day after *b*` | days in the proleptic Gregorian calendar; any two of the three give the third |
185
+ | `*a* is in *b*` | `a` is a member of the list `b` |
186
+ | `*a* is known` | `is_nonvar(a)` |
187
+ | `the minimum of *a* and *b* is *c*`, `the maximum of ...` | `is(c, min(a, b))`, `max` |
188
+ | `the length of *a* is *b*` | the length of the list `a` |
189
+ | `*a* is the reverse of *b*` | `a` is the list `b` reversed |
190
+ | `appending *a* then *b* gives *c*` | `c` is `a` followed by `b` |
191
+ | `*a* has *b* as head before *c*` | `unify(a, [b, ...c])` |
192
+
193
+ ## Scenarios, queries and expected answers
194
+
195
+ A query has one sentence of conditions, read as a rule's conditions are.
196
+ `which person`, like `a person`, introduces a variable, and LE1's prefix
197
+ `for which event:` introduces one too. A scenario has facts and rules, and
198
+ expectations:
374
199
 
375
200
  ```text
376
- Use ODRL snapshot logic with namespace "https://example.org/handicap-card#".
377
-
378
- evaluation is an evaluation.
379
- evaluation has policy eligibility.
380
- evaluation has request issueAlice.
381
- evaluation has conflictStrategy prohibit.
201
+ scenario alice is:
202
+ John is born in the UK on 2021-10-09.
203
+ one expects answers ["John acquires British citizenship on 2021-10-09"].
382
204
  ```
383
205
 
384
- This directive must be the first sentence of one file. The remainder contains
385
- facts using the snapshot vocabulary, and rules, but no questions: the report
386
- is the answer. The compiler maps the facts to RDF and includes the
387
- validation, evaluation and reporting LS of `src/odrl.js`.
206
+ `NAME expects answers [...]` and `NAME expects [...]` state the answers the
207
+ query `NAME` gives in the scenario; a trailing `and unknowns [...]` is ignored.
208
+ Each query is answered in each scenario, or once when the document has none.
388
209
 
389
- A snapshot's rules derive more of its input: their class and property
390
- statements, in premises and conclusions, are statements of the snapshot's
391
- RDF graph, with names mapped as for facts. A rule typically derives a state's
392
- observations or a request's duty evidence from other facts, so the
393
- evaluator decides on what the rules establish:
210
+ ## Compilation to LS
394
211
 
395
- ```text
396
- For every S and P,
397
- if S is a state and S has subject P and P has registeredIn civicDistrict
398
- then S has residenceVerified true.
399
- ```
212
+ Facts and rules compile to LS facts and backward rules (`implied_by`), as LE's
213
+ Prolog target runs them; a ground fact is `fact(...)`, a fact with a variable a
214
+ backward rule with the body `'true'`.
400
215
 
401
- Calculations, comparisons, absence tests and aggregates work as in ordinary
402
- LE; an absence test asks whether the graph, with the rules' conclusions,
403
- holds a statement. The rules precede the evaluator's own clauses, so they
404
- cannot read its report, and a snapshot without rules compiles to the same
405
- program as before. The evaluator validates what the rules derive as it
406
- validates stated facts: a request or state still has one type, for
407
- example. Derive an observation as both `true` and `false` where it matters,
408
- since a missing observation leaves a constraint unknown. The same
409
- [snapshot profile](https://eyereasoner.github.io/eyemind/#odrl-snapshots) applies
410
- to Turtle and LE, including missing observations, unsupported policy features
411
- and conflict strategies. Vocabulary by itself does not enable evaluation.
412
-
413
- Names expand as follows, with case preserved:
414
-
415
- | LE form or name | RDF mapping |
416
- | --- | --- |
417
- | An ordinary individual name | An IRI formed by appending it to the declared namespace. |
418
- | Classes `evaluation`, `request`, `state` | `eval:Evaluation`, `eval:Request`, `eval:State`. |
419
- | Classes `policy`, `agreement`, `permission`, `prohibition`, `constraint`, `logicalConstraint`, `duty`, `action` | `odrl:Set`, `odrl:Agreement`, `odrl:Permission`, `odrl:Prohibition`, `odrl:Constraint`, `odrl:LogicalConstraint`, `odrl:Duty`, `odrl:Action`. |
420
- | Classes `assetCollection`, `partyCollection` | ODRL collection classes, rejected by the snapshot profile. |
421
- | Properties `policy`, `request`, `state`, `subject`, `conflictStrategy` | The corresponding `eval:` properties. |
422
- | Properties `profile`, `permission`, `prohibition`, `assignee`, `assigner`, `action`, `target`, `constraint`, `leftOperand`, `operator`, `rightOperand`, `duty` | The corresponding `odrl:` properties. |
423
- | Properties `andOperands`, `orOperands`, `xoneOperands` | `odrl:and`, `odrl:or`, `odrl:xone`. LE lists become RDF collections. |
424
- | Properties `fulfilledDuty`, `unfulfilledDuty` | The corresponding `eval:` request evidence properties. |
425
- | Property `policyConflict` | `odrl:conflict`, the policy-local strategy. |
426
- | Property `type` | `rdf:type`. |
427
- | An otherwise unknown class or property | An IRI in the declared namespace; validation still applies. |
428
- | Values `snapshotProfile`, `perm`, `prohibit`, `invalid`, `eq`, `neq`, `gt`, `gteq`, `lt`, `lteq` | `eval:SnapshotProfile` or the corresponding ODRL strategy/operator IRIs. |
429
- | Value `withinCategory` | `eval:withinCategory`, the snapshot's DPV hierarchy operator. |
430
- | Values `true`, `false` | Boolean RDF literals. Quoting does not change an LE name into an RDF string literal. |
431
- | An integer or float | An exact RDF integer or an `xsd:double` literal. |
432
-
433
- The unsupported ODRL properties `obligation`, `inheritFrom`, `includedIn`,
434
- `partOf` and `refinement` retain their ODRL IRIs so the shared validator can
435
- report them. Explicit RDF values such as `iri("https://example.org/item")` and
436
- `literal("text", datatype("http://www.w3.org/2001/XMLSchema#string"))` retain
437
- their terms. `rdf(S, P, O)` facts allow any explicit RDF predicate without an
438
- abbreviation. A snapshot still has one default graph.
439
-
440
- The [handicap-card LE example](https://eyereasoner.github.io/eyemind/examples/deck/handicap-card-le)
441
- contains the complete policies, requests and SOTW. Run it without CLI switches:
442
-
443
- ```sh
444
- eyemind examples/handicap-card-le.le
445
- eyemind --program examples/handicap-card-le.le > /tmp/handicap-card-le.js
446
- eyemind --to turtle /tmp/handicap-card-le.js
447
- ```
216
+ When a document has scenarios, every relation gets the scenario as its first
217
+ argument, a scenario's clauses have the scenario's name there, and the
218
+ knowledge base's clauses have a variable there, bound by the facts
219
+ `'le:scenario'(NAME)`. A knowledge-base fact becomes a rule whose body is
220
+ `'le:scenario'(S)`. So the knowledge base holds in every scenario and a
221
+ scenario's facts in that one, and one program and one proof answer every query
222
+ in every scenario.
448
223
 
449
- Its default output is an LE report whose first sentence is
450
- `Use ODRL vocabulary with namespace "https://example.org/handicap-card#".`.
451
- That directive reads RDF data without evaluating policies. This makes the report
452
- readable as input again, preserving every RDF fact and witness. Report properties
453
- use `has`; for example `issueAlice has decision allowed.`. Status values
454
- `allowed`, `prohibited`, `notApplicable`, `undetermined`, `valid` and
455
- `invalidReport` name the corresponding `eval:` IRIs. Report classes include
456
- `evaluationReport`, `conflict`, `validationError` and `uncertainty`.
457
- `conflict` as a property means `eval:conflict`; `applicablePermission`,
458
- `applicableProhibition`, `reportConstraint` and `reportDuty` distinguish the
459
- report's `eval:permission`, `eval:prohibition`, `eval:constraint` and
460
- `eval:duty` links from ODRL input properties. Other report fields retain their `eval:` names. Other IRIs
461
- are written with the run's prefixes, declared after the directive: those the
462
- file declares, `odrl:` and `eval:`. Inside a witness key, where a bare name
463
- would read back as a name rather than an IRI, the snapshot namespace also
464
- needs a prefix: the file's own, or `ns` when it declares none. An IRI that no
465
- prefix abbreviates stays explicit.
466
-
467
- Prefix declarations can follow either ODRL directive, and the whole snapshot
468
- can be written with qualified names, as `ex:mayErase has odrl:action
469
- odrl:delete.` or `ex:evaluation is a eval:Evaluation.`. After an ODRL
470
- directive a qualified statement takes the subjects and values the short forms
471
- take: an ordinary name in the declared namespace, `true` and `false`, and an
472
- operand list, as `ex:scope has odrl:and [ex:purpose, ex:consent].`. A state
473
- property or value can use a DPV IRI, for example
474
- `state has dpv:hasPurpose dpv:AcademicResearch.`. An equality constraint
475
- can read `dpv:hasPurpose` as its left operand and use
476
- `dpv:AcademicResearch` as its right operand.
477
- [Right to erasure example](https://eyereasoner.github.io/eyemind/examples/deck/right-to-erasure-le)
224
+ A query `NAME` compiles to a backward rule for `'le:answer'(NAME, S, V1, ...)`,
225
+ whose body starts with `'le:scenario'(S)` when there are scenarios, and the
226
+ statement `query('le:answer'(NAME, S, V1, ...))`. `V1, ...` are the variables of
227
+ the query outside negations and collections, in the order they appear.
478
228
 
479
- ```text
480
- scope is a logicalConstraint and scope has andOperands [purpose, dataCategory].
481
- purpose is a constraint and purpose has leftOperand dpv:hasPurpose.
482
- purpose has operator withinCategory and purpose has rightOperand dpv:ResearchAndDevelopment.
483
- credit is a duty and credit has action odrl:attribute.
484
- researchUse has constraint scope and researchUse has duty credit.
485
- ready has fulfilledDuty credit.
486
- ```
229
+ Aggregates, divisions, lists and dates use backward helper rules whose names
230
+ start with `le:` (`le:sum`, `le:count`, `le:days_after`, ...); no template name
231
+ can contain `:`. The helpers follow the document's clauses. `--program` prints
232
+ the compiled program as a standalone LS script.
487
233
 
488
- A logical constraint has one operator and a proper RDF list of at least two
489
- distinct atomic constraints. `andOperands` requires all members,
490
- `orOperands` at least one and `xoneOperands` exactly one. The result is
491
- unknown when treating unknown members as satisfied or unsatisfied could
492
- change the outcome. Reports cite the group for an unmet or unknown logical
493
- constraint. The snapshot rejects nested groups and `odrl:andSequence`.
494
- [ODRL Logical Constraint Class](https://www.w3.org/TR/odrl-model/#constraint-logical)
495
-
496
- A permission can require several duties. Each is typed `odrl:Duty` and
497
- has one action IRI. A request records whether it has fulfilled each duty.
498
- An `unfulfilledDuty` record makes the permission inapplicable and gives
499
- an `unmetDuty` report link. A missing record or conflicting records give
500
- an uncertainty with `reportDuty` and a reason. The snapshot takes these
501
- records as evidence of fulfillment. Duties that specify additional action
502
- refinements, roles or consequences fail validation.
503
- [ODRL Duty with a Permission](https://www.w3.org/TR/odrl-model/#duties)
504
-
505
- `withinCategory` compares a single observed IRI with a required category IRI.
506
- It accepts the three DPV observation properties in the hierarchy table.
507
- An exact match or a supplied broader path satisfies the constraint. With
508
- a known observation and no such path the constraint is unmet. The snapshot
509
- reports missing, ambiguous or mistyped observations as unknown.
510
- The research snapshot demonstrates compound scope, two DPV hierarchies and
511
- request-local duty evidence; its Turtle twin, run with `--odrl`, reaches the
512
- same decisions. [Research snapshot](https://eyereasoner.github.io/eyemind/examples/deck/research-snapshot-le) · [Turtle twin](https://eyereasoner.github.io/eyemind/examples/deck/research-snapshot-odrl)
513
-
514
- Both ODRL directives take a single LE file and reject questions; the
515
- vocabulary directive also rejects rules. `--goal` can query their compiled LS program. The
516
- `--odrl` switch selects the Turtle snapshot compiler, which can also combine
517
- with `--owl2rl`, `--skos`, `--qudt` and `--shacl`; an LE run takes none of these
518
- switches, so an LE snapshot reads only the facts it states.
519
-
520
- ## Output, compilation and checking
521
-
522
- LE inputs default to `.le` conclusions. Each answer becomes a sentence:
234
+ ## Output
523
235
 
524
- ```text
525
- Socrates is a mortal.
526
- 16 is a square of 4.
527
- Alice is an owner of witness(rule 4, Y, Alice).
528
- ```
236
+ The default output of an LE run is LE text: for each scenario, in the order of
237
+ the document, and each query, a heading comment and the answers as sentences.
238
+ An answer is the query's words with each variable it found a value for
239
+ written as that value; an open variable is written `_`, as LE writes it. A date
240
+ is written `YYYY-MM-DD`, a list in brackets, and a sentence term through its
241
+ template.
529
242
 
530
- `witness(rule 4, Y, Alice)` names the witness for existential variable `Y` of
531
- rule 4 with argument Alice. It reads back as `skolem(4, 'Y', ['Alice'])` in LS.
532
- The label `Y` in this position is a name, independent of any declared LE
533
- variable. A label outside the variable-name syntax is quoted. Additional
534
- arguments follow as more comma-separated terms; a witness without arguments
535
- is `witness(rule 4, Y)`. The rule number, label and arguments all contribute
536
- to its identity. Ordinary compounds named witness retain their quoted spelling.
537
-
538
- Unary and binary relations use the class and relation-of forms; relations with
539
- more arguments use calls. Names are quoted when required to preserve their
540
- meaning. Compound names are quoted. Variable answers use `For every X0 and X1,
541
- ...`, consistently renaming their variables while retaining sharing. A conjunctive
542
- answer uses `and`. These sentences can be loaded as facts in another `.le`
543
- program. An empty answer set is `# No conclusions.`. The writer rejects goals
544
- outside these relational forms instead of silently changing their meaning.
545
-
546
- ```sh
547
- eyemind examples/socrates-le.le
548
- eyemind --program examples/socrates-le.le > /tmp/socrates-le.js
549
- eyemind --to le /tmp/socrates-le.js
550
- eyemind --proof examples/socrates-le.le > /tmp/socrates-le-proof.js
551
- eyemind --check-proof /tmp/socrates-le-proof.js examples/socrates-le.le
243
+ ```text
244
+ % query one with scenario alice
245
+ John acquires British citizenship on 2021-10-09.
552
246
  ```
553
247
 
554
- Multiple `.le` files form one program in file order; they do not mix with other
555
- input formats or the RDF logic switches. Standard input remains LS; `--to le`
556
- can write supported LS conclusions as LE. For an N3, SRL or RDF run, IRIs are
557
- abbreviated with that run's prefixes; a prefix LE cannot spell, such as
558
- Turtle's empty one, is declared as `ns`, or `ns2` and so on when taken. `--goal` uses LS goal syntax and
559
- defaults to LS output; add `--to le` for LE output. `--all` applies to RDF and N3
560
- output, without changing LE's selected conclusions.
561
-
562
- The compiler reads data without executing it and emits standalone `.js` LS
563
- using explicit constructors to retain names and numeric types. Comments in the
564
- compiled text identify the source file and sentence line. Parser errors name
565
- that location. LE runs use LS's usual work bounds, which can be overridden by
566
- the CLI. Existential or recursive rules can still have an infinite closure.
567
-
568
- Proofs and check reports are `.js` documents and use the existing LS checker.
569
- Checking establishes the compiled LS result. It does not independently validate
570
- the English-to-LS translation; that contract is this grammar and its tests.
571
-
572
- Supported sentences have no disjunctive conclusions, pronouns, implicit
573
- assumptions, set comprehension, higher-order quantification or proof blocks.
574
- Unsupported syntax is an error, with no approximate translation.
248
+ A query without answers has the line `% no answers`. When the scenario states
249
+ expected answers for the query and they differ from the answers, a line
250
+ `% not as expected: NAME expects answers [...]` follows. LE2 writes the
251
+ underscores of names as spaces and repeats an answer for each proof, so the
252
+ comparison reads underscores as spaces, ignores spaces around hyphens, and
253
+ compares the answers as a set.
254
+
255
+ `--to le` writes the answers of an LE run only; `--to eyemind` writes the
256
+ `'le:answer'` terms. Proofs and check reports are `.js` documents of the
257
+ compiled LS program, and check against it. That the program reads the English
258
+ as intended is a matter of the compiler and its tests; a checked proof
259
+ establishes the answers under the compiled rules.
260
+
261
+ ## Not supported
262
+
263
+ These belong to Logical English 2, or to the Prolog that LE1 can embed, and
264
+ are errors: template additions after `;`, `the constants are:`,
265
+ `the functions are:`, `the fluents are:`, `the events are:` and the other
266
+ dynamic and meta sections, included resources and scenarios, section markers,
267
+ rule labels, `it is unknown whether`, `it must not be true that`, negated
268
+ facts in scenarios, flip queries (`expects changes`), `otherwise`, `unless`,
269
+ `according to`, decision tables, services, LPS and s(CASP). eyemind does not
270
+ check types: the head noun of a place is not a type constraint. A program whose
271
+ negation lies on a dependency cycle compiles, and the LS program is then
272
+ rejected unless it is chain-stratified (LS-SPEC Section 6.4), where Prolog would
273
+ run it.