eyemind 0.2.2 → 0.2.3
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/README.md +1 -1
- package/SPEC.md +13 -2
- package/package.json +1 -1
- package/src/proof.js +47 -1
- package/src/version.js +1 -1
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ JavaScript library, and a browser application, with no dependencies.
|
|
|
18
18
|
- **[Examples](https://eyereasoner.github.io/eyemind/examples/)**:
|
|
19
19
|
94 runnable programs, each with a card deck and saved conclusions, proofs
|
|
20
20
|
and check reports.
|
|
21
|
-
- **[Conformance suite](conformance/)**:
|
|
21
|
+
- **[Conformance suite](conformance/)**: 556 cases that test any
|
|
22
22
|
implementation of the specification through its command line.
|
|
23
23
|
Run the suite [in your browser](https://eyereasoner.github.io/eyemind/playground/conformance).
|
|
24
24
|
|
package/SPEC.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
```text
|
|
4
4
|
Title: The eyemind Rule Language and Proof Format
|
|
5
|
-
Version: eyemind 0.2.
|
|
5
|
+
Version: eyemind 0.2.3
|
|
6
6
|
```
|
|
7
7
|
|
|
8
8
|
This document specifies the syntax and meaning of eyemind programs and data
|
|
@@ -1172,6 +1172,16 @@ and its uses MUST be identical, in order, to the conjuncts of the argument of
|
|
|
1172
1172
|
`call` or `once`, or of one side of a disjunction. When trusted boundaries are
|
|
1173
1173
|
forbidden ("strict"), each `'absent'` or `'collected'` step fails C5.
|
|
1174
1174
|
|
|
1175
|
+
Host math is the one exception to identical re-decision. A `'builtin'` step
|
|
1176
|
+
`is(V, E)`, where `V` is a float and `E` applies `exp`, `log`, `log2`,
|
|
1177
|
+
`log10`, a trigonometric or hyperbolic function, or `pow`, also passes C5
|
|
1178
|
+
when `E` evaluates to a float at most 4 units in the last place from `V`,
|
|
1179
|
+
that is, with at most 3 floats between them. Such results may differ between
|
|
1180
|
+
conforming implementations (Section 14), so a proof made by one still checks
|
|
1181
|
+
with another. Every other recomputed result MUST be identical; a difference
|
|
1182
|
+
that grows beyond this bound, for example through cancellation, MAY make a
|
|
1183
|
+
proof fail on an implementation other than the one that made it.
|
|
1184
|
+
|
|
1175
1185
|
### 11.7 C6 Boundary consistency
|
|
1176
1186
|
|
|
1177
1187
|
A trusted boundary cannot be proved, but the evidence at hand can refute it.
|
|
@@ -1393,7 +1403,8 @@ Canonical term spelling, conclusion order, proof contents and report counts
|
|
|
1393
1403
|
are required as specified. Comment wording and failure `Detail` text are
|
|
1394
1404
|
informative. Fresh variable names are unspecified where Section 2.4 says
|
|
1395
1405
|
so. Float results of `exp`, logarithms, trigonometric and hyperbolic
|
|
1396
|
-
functions, and `pow` with floats MAY differ in the last
|
|
1406
|
+
functions, and `pow` with floats MAY differ by one unit in the last place,
|
|
1407
|
+
and C5 accepts a result of such a function within 4 units (Section 11.6).
|
|
1397
1408
|
|
|
1398
1409
|
The conformance cases and saved example documents exercise these
|
|
1399
1410
|
requirements. They do not replace the definitions in this specification.
|
package/package.json
CHANGED
package/src/proof.js
CHANGED
|
@@ -16,7 +16,7 @@ import { CONTROL_KEYS, Program } from './program.js';
|
|
|
16
16
|
import { readTerms } from './reader.js';
|
|
17
17
|
import {
|
|
18
18
|
Env, EyemindError, Struct, Var, conjunction, copyResolved, deref, flattenConjunction, freshTerm,
|
|
19
|
-
isCallable, isGround, isTerm, key, listFromItems, properListItems, unify, variables,
|
|
19
|
+
isCallable, isFloat, isGround, isTerm, key, listFromItems, properListItems, unify, variables,
|
|
20
20
|
} from './terms.js';
|
|
21
21
|
import { Lettering, letterName, quote, write, writeNotingVariables } from './writer.js';
|
|
22
22
|
|
|
@@ -52,6 +52,51 @@ function sameValue(a, b) {
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
// Whether term, read through env, is exactly target, variables included.
|
|
55
|
+
// The functions whose float results may differ between hosts' math libraries
|
|
56
|
+
// (SPEC Section 14), and how far apart, in units in the last place, a claimed
|
|
57
|
+
// result of one of them may be from the recomputed one (Section 11.6).
|
|
58
|
+
const HOST_MATH = new Set(['exp', 'log', 'log2', 'log10', 'sin', 'cos', 'tan', 'asin', 'acos', 'atan', 'atan2',
|
|
59
|
+
'sinh', 'cosh', 'tanh', 'pow']);
|
|
60
|
+
const HOST_MATH_ULPS = 4n;
|
|
61
|
+
|
|
62
|
+
function usesHostMath(expression) {
|
|
63
|
+
const pending = [expression];
|
|
64
|
+
while (pending.length) {
|
|
65
|
+
const term = pending.pop();
|
|
66
|
+
if (!(term instanceof Struct)) continue;
|
|
67
|
+
if (HOST_MATH.has(term.name)) return true;
|
|
68
|
+
pending.push(...term.args);
|
|
69
|
+
}
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// A float's position among all floats, so that adjacent floats differ by one.
|
|
74
|
+
const BITS = new DataView(new ArrayBuffer(8));
|
|
75
|
+
function floatPosition(value) {
|
|
76
|
+
BITS.setFloat64(0, value);
|
|
77
|
+
const bits = BITS.getBigInt64(0);
|
|
78
|
+
return bits < 0n ? -(bits & 0x7fffffffffffffffn) : bits;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// is(Claimed, Expression) with a float claimed for an expression that uses
|
|
82
|
+
// host math agrees when the recomputed float lies within HOST_MATH_ULPS of it.
|
|
83
|
+
function nearHostMath(goal) {
|
|
84
|
+
if (!isTerm(goal, 'is', 2) || !isFloat(goal.args[0]) || !usesHostMath(goal.args[1])) return false;
|
|
85
|
+
const result = new Var('Result');
|
|
86
|
+
const env = new Env();
|
|
87
|
+
try {
|
|
88
|
+
for (const solution of primitive(new Struct('is', [result, goal.args[1]]), env)) {
|
|
89
|
+
const value = deref(result, solution);
|
|
90
|
+
if (!isFloat(value)) return false;
|
|
91
|
+
const distance = floatPosition(value) - floatPosition(goal.args[0]);
|
|
92
|
+
return (distance < 0n ? -distance : distance) <= HOST_MATH_ULPS;
|
|
93
|
+
}
|
|
94
|
+
} catch (error) {
|
|
95
|
+
if (!(error instanceof EyemindError)) throw error;
|
|
96
|
+
}
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
|
|
55
100
|
function resolvesTo(term, env, target) {
|
|
56
101
|
const pending = [term, target];
|
|
57
102
|
while (pending.length) {
|
|
@@ -366,6 +411,7 @@ function checkSteps(program, steps, allowTrusted, fail, spellings, name) {
|
|
|
366
411
|
// A primitive that cannot be recomputed does not pass C5.
|
|
367
412
|
if (!(error instanceof EyemindError)) throw error;
|
|
368
413
|
}
|
|
414
|
+
if (!agrees) agrees = nearHostMath(goal);
|
|
369
415
|
if (!agrees) fail.add('C5', `primitive disagrees: ${text(goal)}`, goal);
|
|
370
416
|
else tally.redecided++;
|
|
371
417
|
} else if (by === CONTROL_BY) {
|
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.2.
|
|
2
|
+
export const VERSION = '0.2.3';
|