eyemind 0.8.47 → 0.8.48
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 +16 -0
- package/LS-SPEC.md +1 -1
- package/README.md +1 -1
- package/package.json +1 -1
- package/src/arith.js +6 -0
- package/src/le.js +15 -1
- package/src/version.js +1 -1
package/LE-SPEC.md
CHANGED
|
@@ -167,6 +167,21 @@ and division, then addition and subtraction. Binary operators associate left.
|
|
|
167
167
|
They compile to `neg`, `add`, `sub`, `mul` and `div`. Only the value-of form
|
|
168
168
|
binds its left variable; comparisons require their inputs beforehand.
|
|
169
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`:
|
|
172
|
+
|
|
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.
|
|
184
|
+
|
|
170
185
|
```text
|
|
171
186
|
4 is an integer.
|
|
172
187
|
For every X and Y, if X is an integer and Y is the value of X * X
|
|
@@ -316,6 +331,7 @@ These programs use the grammar above without additional syntax:
|
|
|
316
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. |
|
|
317
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. |
|
|
318
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
|
+
| [The zeta function](https://eyereasoner.github.io/eyemind/examples/deck/zeta-le) | Exact Bernoulli numbers with `pow`, `floordiv`, `gcd` and `lcm`; zeta at the negative and even integers; Borwein's series with `exp`, `log`, `cos` and `sin` checking zeros on the critical line. |
|
|
319
335
|
| [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. |
|
|
320
336
|
| [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. |
|
|
321
337
|
| [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. |
|
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
|
+
169 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.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eyemind",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.48",
|
|
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/arith.js
CHANGED
|
@@ -365,6 +365,12 @@ const ARITIES = {
|
|
|
365
365
|
};
|
|
366
366
|
export const CONSTANTS = { pi: Math.PI, e: Math.E, tau: 2 * Math.PI };
|
|
367
367
|
|
|
368
|
+
// Whether name/arity is an arithmetic function, as apply selects one.
|
|
369
|
+
export function takes(name, arity) {
|
|
370
|
+
return arity === 2 && Object.hasOwn(BINARY, name) || arity === 1 && Object.hasOwn(UNARY, name) ||
|
|
371
|
+
Object.hasOwn(FUNCTIONS, name) && accepts(name, arity);
|
|
372
|
+
}
|
|
373
|
+
|
|
368
374
|
function accepts(name, arity) {
|
|
369
375
|
const allowed = ARITIES[name];
|
|
370
376
|
if (allowed === undefined) return false;
|
package/src/le.js
CHANGED
|
@@ -8,6 +8,7 @@ import { write } from './writer.js';
|
|
|
8
8
|
import { compileOdrlLe, odrlLeReport, snapshotGoal } from './le-odrl.js';
|
|
9
9
|
import { dpvRules } from './dpv.js';
|
|
10
10
|
import { loadText } from './lang.js';
|
|
11
|
+
import { ARITHMETIC_NAMES, CONSTANTS, takes } from './arith.js';
|
|
11
12
|
|
|
12
13
|
const st = (name, ...args) => new Struct(name, args);
|
|
13
14
|
const VARIABLE = /^[A-Z][0-9]*$/;
|
|
@@ -19,6 +20,9 @@ const SENTENCE_WORDS = new Set(['every', 'for', 'if', 'find', 'there', 'it', 'co
|
|
|
19
20
|
const RESERVED = new Set([...PRIMITIVE_KEYS, ...CONTROL_KEYS, ...RESERVED_KEYS].map((key) => key.split('/')[0]));
|
|
20
21
|
for (const name of ['true', 'false', 'fail']) RESERVED.add(name);
|
|
21
22
|
const OPERATORS = { '+': ['add', 1], '-': ['sub', 1], '*': ['mul', 2], '/': ['div', 2] };
|
|
23
|
+
// LS arithmetic functions an expression can call, as exp(X) or gcd(A, B);
|
|
24
|
+
// and, or and not are LE words.
|
|
25
|
+
const CALLS = new Set([...ARITHMETIC_NAMES].filter((name) => !['and', 'or', 'not'].includes(name)));
|
|
22
26
|
const list = (items) => items.reduceRight((tail, head) => st('.', head, tail), EMPTY);
|
|
23
27
|
const cons = (head, tail) => st('.', head, tail);
|
|
24
28
|
const AGGREGATES = { number: 'le:count', sum: 'le:sum', maximum: 'le:max', minimum: 'le:min' };
|
|
@@ -229,9 +233,19 @@ class Parser {
|
|
|
229
233
|
|
|
230
234
|
expressionValue(min) {
|
|
231
235
|
let left;
|
|
236
|
+
const token = this.token, next = this.tokens[this.at + 1];
|
|
232
237
|
if (this.take('-')) left = st('neg', this.expression(3));
|
|
233
238
|
else if (this.take('(')) { left = this.expression(); this.need(')'); }
|
|
234
|
-
else {
|
|
239
|
+
else if (token.kind === 'word' && CALLS.has(token.value) && next?.value === '(') {
|
|
240
|
+
this.at += 2;
|
|
241
|
+
const args = [];
|
|
242
|
+
if (!this.take(')')) { do { args.push(this.expression()); } while (this.take(',')); this.need(')'); }
|
|
243
|
+
if (!takes(token.value, args.length)) this.error(`${token.value} does not take ${args.length} argument${args.length === 1 ? '' : 's'}`, token.line);
|
|
244
|
+
left = st(token.value, ...args);
|
|
245
|
+
} else if (token.kind === 'word' && Object.hasOwn(CONSTANTS, token.value)) {
|
|
246
|
+
this.at++;
|
|
247
|
+
left = token.value;
|
|
248
|
+
} else {
|
|
235
249
|
left = this.term();
|
|
236
250
|
if (!(left instanceof Var) && !['bigint', 'number'].includes(typeof left)) this.error('arithmetic operands must be numbers or declared variables');
|
|
237
251
|
}
|
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.8.
|
|
2
|
+
export const VERSION = '0.8.48';
|