eyeling 1.24.4 → 1.24.6
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/HANDBOOK.md +2 -101
- package/README.md +2 -2
- package/dist/browser/eyeling.browser.js +256 -4
- package/examples/annotation.n3 +3 -4
- package/{see/examples/n3/backward_recursion.n3 → examples/backward-recursion.n3} +0 -2
- package/examples/collection.n3 +1 -2
- package/examples/context-association.n3 +56 -30
- package/{see/examples/n3/dijkstra_risk_path.n3 → examples/dijkstra-risk-path.n3} +3 -18
- package/{see/examples/n3/eco_route_insight.n3 → examples/eco-route-insight.n3} +2 -47
- package/{see/examples/n3/genetic_knapsack_selection.n3 → examples/genetic-knapsack-selection.n3} +2 -24
- package/{see/examples → examples}/input/annotation.trig +3 -3
- package/{see/examples/input/backward_recursion.trig → examples/input/backward-recursion.trig} +2 -2
- package/{see/examples/input/builtin_coverage.trig → examples/input/builtin-coverage.trig} +2 -2
- package/{see/examples → examples}/input/collection.trig +3 -3
- package/{see/examples/input/dijkstra_risk_path.trig → examples/input/dijkstra-risk-path.trig} +4 -4
- package/{see/examples/input/eco_route_insight.trig → examples/input/eco-route-insight.trig} +4 -4
- package/{see/examples/input/genetic_knapsack_selection.trig → examples/input/genetic-knapsack-selection.trig} +4 -4
- package/{see/examples/input/rc_discharge_envelope.trig → examples/input/rc-discharge-envelope.trig} +4 -4
- package/{see/examples/input/rdf_dataset.trig → examples/input/rdf-dataset.trig} +4 -4
- package/{see/examples/input/rdf_message_flow.trig → examples/input/rdf-message-flow.trig} +3 -3
- package/{see/examples/input/rdf_messages.trig → examples/input/rdf-messages.trig} +4 -4
- package/{see/examples/input/school_placement_audit.trig → examples/input/school-placement-audit.trig} +4 -4
- package/{see/examples/input/smoke_arithmetic.trig → examples/input/smoke-arithmetic.trig} +3 -3
- package/{see/examples/input/triple_terms.trig → examples/input/triple-terms.trig} +3 -3
- package/examples/output/backward-recursion.n3 +4 -0
- package/examples/output/context-association.n3 +9 -0
- package/examples/output/dijkstra-risk-path.n3 +3 -0
- package/examples/output/eco-route-insight.n3 +3 -0
- package/examples/output/genetic-knapsack-selection.n3 +3 -0
- package/examples/output/rc-discharge-envelope.n3 +9 -0
- package/examples/output/rc-discharge-envelope.txt +9 -0
- package/examples/output/rdf-dataset.n3 +5 -0
- package/examples/output/rdf-message-flow.n3 +7 -0
- package/examples/output/rdf-messages.n3 +7 -0
- package/examples/output/school-placement-audit.n3 +3 -0
- package/examples/output/smoke-arithmetic.n3 +5 -0
- package/examples/output/smoke-arithmetic.txt +5 -0
- package/examples/output/triple-terms.n3 +5 -0
- package/{see/examples/n3/rc_discharge_envelope.n3 → examples/rc-discharge-envelope.n3} +2 -15
- package/{see/examples/n3/rdf_dataset.n3 → examples/rdf-dataset.n3} +2 -11
- package/{see/examples/n3/rdf_message_flow.n3 → examples/rdf-message-flow.n3} +9 -75
- package/{see/examples/n3/rdf_messages.n3 → examples/rdf-messages.n3} +6 -43
- package/{see/examples/n3/school_placement_audit.n3 → examples/school-placement-audit.n3} +2 -14
- package/{see/examples/n3/smoke_arithmetic.n3 → examples/smoke-arithmetic.n3} +3 -5
- package/{see/examples/n3/triple_terms.n3 → examples/triple-terms.n3} +1 -4
- package/eyeling.js +256 -4
- package/lib/builtins.js +6 -0
- package/lib/lexer.js +250 -4
- package/package.json +4 -7
- package/test/api.test.js +65 -8
- package/test/examples.test.js +22 -2
- package/test/package.test.js +16 -2
- package/examples/arcling/README.md +0 -11
- package/examples/input/annotation.ttl +0 -6
- package/examples/input/collection.ttl +0 -13
- package/examples/input/reifies.ttl +0 -10
- package/examples/input/triple-term.ttl +0 -8
- package/examples/output/triple-term.n3 +0 -0
- package/examples/reifies.n3 +0 -8
- package/examples/triple-term.n3 +0 -7
- package/see/README.md +0 -149
- package/see/examples/_see.js +0 -249
- package/see/examples/age.js +0 -1459
- package/see/examples/annotation.js +0 -1320
- package/see/examples/backward.js +0 -1405
- package/see/examples/backward_recursion.js +0 -1504
- package/see/examples/bayes_diagnosis.js +0 -2883
- package/see/examples/bayes_therapy.js +0 -4152
- package/see/examples/bmi.js +0 -3038
- package/see/examples/builtin_coverage.js +0 -2524
- package/see/examples/collection.js +0 -1320
- package/see/examples/complex.js +0 -3762
- package/see/examples/complex_matrix_stability.js +0 -2973
- package/see/examples/composition_of_injective_functions_is_injective.js +0 -2170
- package/see/examples/control_system.js +0 -1918
- package/see/examples/crypto_builtins_tests.js +0 -1489
- package/see/examples/delfour.js +0 -3174
- package/see/examples/digital_product_passport.js +0 -2856
- package/see/examples/dijkstra.js +0 -2070
- package/see/examples/dijkstra_risk_path.js +0 -1874
- package/see/examples/doc/age.md +0 -27
- package/see/examples/doc/annotation.md +0 -24
- package/see/examples/doc/backward.md +0 -26
- package/see/examples/doc/backward_recursion.md +0 -26
- package/see/examples/doc/bayes_diagnosis.md +0 -41
- package/see/examples/doc/bayes_therapy.md +0 -40
- package/see/examples/doc/bmi.md +0 -38
- package/see/examples/doc/builtin_coverage.md +0 -53
- package/see/examples/doc/collection.md +0 -24
- package/see/examples/doc/complex.md +0 -38
- package/see/examples/doc/complex_matrix_stability.md +0 -35
- package/see/examples/doc/composition_of_injective_functions_is_injective.md +0 -24
- package/see/examples/doc/control_system.md +0 -32
- package/see/examples/doc/crypto_builtins_tests.md +0 -27
- package/see/examples/doc/delfour.md +0 -37
- package/see/examples/doc/digital_product_passport.md +0 -36
- package/see/examples/doc/dijkstra.md +0 -28
- package/see/examples/doc/dijkstra_risk_path.md +0 -30
- package/see/examples/doc/dog.md +0 -28
- package/see/examples/doc/eco_route_insight.md +0 -33
- package/see/examples/doc/equals.md +0 -26
- package/see/examples/doc/equivalence_classes_overlap_implies_same_class.md +0 -24
- package/see/examples/doc/euler_identity.md +0 -39
- package/see/examples/doc/ev_roundtrip_planner.md +0 -32
- package/see/examples/doc/existential_rule.md +0 -24
- package/see/examples/doc/expression_eval.md +0 -26
- package/see/examples/doc/family_cousins.md +0 -24
- package/see/examples/doc/fastpow.md +0 -29
- package/see/examples/doc/fibonacci.md +0 -28
- package/see/examples/doc/french_cities.md +0 -28
- package/see/examples/doc/fundamental_theorem_arithmetic.md +0 -36
- package/see/examples/doc/genetic_knapsack_selection.md +0 -29
- package/see/examples/doc/goldbach_1000.md +0 -31
- package/see/examples/doc/good_cobbler.md +0 -27
- package/see/examples/doc/gps.md +0 -35
- package/see/examples/doc/gray_code_counter.md +0 -31
- package/see/examples/doc/greatest_lower_bound_uniqueness.md +0 -24
- package/see/examples/doc/group_inverse_uniqueness.md +0 -24
- package/see/examples/doc/hadamard_approx.md +0 -32
- package/see/examples/doc/hanoi.md +0 -26
- package/see/examples/doc/odrl_dpv_risk_ranked.md +0 -57
- package/see/examples/doc/path_discovery.md +0 -33
- package/see/examples/doc/rc_discharge_envelope.md +0 -33
- package/see/examples/doc/rdf_dataset.md +0 -26
- package/see/examples/doc/rdf_message_flow.md +0 -35
- package/see/examples/doc/rdf_messages.md +0 -37
- package/see/examples/doc/school_placement_audit.md +0 -31
- package/see/examples/doc/smoke_arithmetic.md +0 -31
- package/see/examples/doc/socrates.md +0 -24
- package/see/examples/doc/triple_terms.md +0 -26
- package/see/examples/doc/wind_turbine.md +0 -37
- package/see/examples/doc/witch.md +0 -28
- package/see/examples/dog.js +0 -1436
- package/see/examples/eco_route_insight.js +0 -2110
- package/see/examples/equals.js +0 -1363
- package/see/examples/equivalence_classes_overlap_implies_same_class.js +0 -1792
- package/see/examples/euler_identity.js +0 -2038
- package/see/examples/ev_roundtrip_planner.js +0 -2562
- package/see/examples/existential_rule.js +0 -1363
- package/see/examples/expression_eval.js +0 -1798
- package/see/examples/family_cousins.js +0 -1586
- package/see/examples/fastpow.js +0 -2207
- package/see/examples/fibonacci.js +0 -1594
- package/see/examples/french_cities.js +0 -1492
- package/see/examples/fundamental_theorem_arithmetic.js +0 -2106
- package/see/examples/genetic_knapsack_selection.js +0 -1743
- package/see/examples/goldbach_1000.js +0 -1798
- package/see/examples/good_cobbler.js +0 -1396
- package/see/examples/gps.js +0 -2813
- package/see/examples/gray_code_counter.js +0 -1641
- package/see/examples/greatest_lower_bound_uniqueness.js +0 -1918
- package/see/examples/group_inverse_uniqueness.js +0 -1897
- package/see/examples/hadamard_approx.js +0 -4417
- package/see/examples/hanoi.js +0 -1625
- package/see/examples/input/age.trig +0 -27
- package/see/examples/input/backward.trig +0 -25
- package/see/examples/input/bayes_diagnosis.trig +0 -111
- package/see/examples/input/bayes_therapy.trig +0 -130
- package/see/examples/input/bmi.trig +0 -28
- package/see/examples/input/complex.trig +0 -26
- package/see/examples/input/complex_matrix_stability.trig +0 -65
- package/see/examples/input/composition_of_injective_functions_is_injective.trig +0 -35
- package/see/examples/input/control_system.trig +0 -31
- package/see/examples/input/crypto_builtins_tests.trig +0 -25
- package/see/examples/input/delfour.trig +0 -90
- package/see/examples/input/digital_product_passport.trig +0 -116
- package/see/examples/input/dijkstra.trig +0 -34
- package/see/examples/input/dog.trig +0 -31
- package/see/examples/input/equals.trig +0 -25
- package/see/examples/input/equivalence_classes_overlap_implies_same_class.trig +0 -28
- package/see/examples/input/euler_identity.trig +0 -34
- package/see/examples/input/ev_roundtrip_planner.trig +0 -90
- package/see/examples/input/existential_rule.trig +0 -26
- package/see/examples/input/expression_eval.trig +0 -41
- package/see/examples/input/family_cousins.trig +0 -39
- package/see/examples/input/fastpow.trig +0 -25
- package/see/examples/input/fibonacci.trig +0 -51
- package/see/examples/input/french_cities.trig +0 -38
- package/see/examples/input/fundamental_theorem_arithmetic.trig +0 -42
- package/see/examples/input/goldbach_1000.trig +0 -53
- package/see/examples/input/good_cobbler.trig +0 -24
- package/see/examples/input/gps.trig +0 -35
- package/see/examples/input/gray_code_counter.trig +0 -33
- package/see/examples/input/greatest_lower_bound_uniqueness.trig +0 -29
- package/see/examples/input/group_inverse_uniqueness.trig +0 -29
- package/see/examples/input/hadamard_approx.trig +0 -32
- package/see/examples/input/hanoi.trig +0 -26
- package/see/examples/input/odrl_dpv_risk_ranked.trig +0 -107
- package/see/examples/input/path-discovery.trig +0 -96448
- package/see/examples/input/path_discovery.trig +0 -29
- package/see/examples/input/socrates.trig +0 -26
- package/see/examples/input/wind_turbine.trig +0 -48
- package/see/examples/input/witch.trig +0 -26
- package/see/examples/n3/age.n3 +0 -28
- package/see/examples/n3/annotation.n3 +0 -7
- package/see/examples/n3/backward.n3 +0 -22
- package/see/examples/n3/bayes_diagnosis.n3 +0 -122
- package/see/examples/n3/bayes_therapy.n3 +0 -149
- package/see/examples/n3/bmi.n3 +0 -145
- package/see/examples/n3/collection.n3 +0 -3
- package/see/examples/n3/complex.n3 +0 -140
- package/see/examples/n3/complex_matrix_stability.n3 +0 -113
- package/see/examples/n3/composition_of_injective_functions_is_injective.n3 +0 -27
- package/see/examples/n3/control_system.n3 +0 -59
- package/see/examples/n3/crypto_builtins_tests.n3 +0 -18
- package/see/examples/n3/delfour.n3 +0 -167
- package/see/examples/n3/digital_product_passport.n3 +0 -156
- package/see/examples/n3/dijkstra.n3 +0 -46
- package/see/examples/n3/dog.n3 +0 -20
- package/see/examples/n3/equals.n3 +0 -11
- package/see/examples/n3/equivalence_classes_overlap_implies_same_class.n3 +0 -19
- package/see/examples/n3/euler_identity.n3 +0 -41
- package/see/examples/n3/ev_roundtrip_planner.n3 +0 -82
- package/see/examples/n3/existential_rule.n3 +0 -10
- package/see/examples/n3/expression_eval.n3 +0 -21
- package/see/examples/n3/family_cousins.n3 +0 -62
- package/see/examples/n3/fastpow.n3 +0 -56
- package/see/examples/n3/fibonacci.n3 +0 -44
- package/see/examples/n3/french_cities.n3 +0 -28
- package/see/examples/n3/fundamental_theorem_arithmetic.n3 +0 -84
- package/see/examples/n3/goldbach_1000.n3 +0 -66
- package/see/examples/n3/good_cobbler.n3 +0 -10
- package/see/examples/n3/gps.n3 +0 -70
- package/see/examples/n3/gray_code_counter.n3 +0 -53
- package/see/examples/n3/greatest_lower_bound_uniqueness.n3 +0 -20
- package/see/examples/n3/group_inverse_uniqueness.n3 +0 -19
- package/see/examples/n3/hadamard_approx.n3 +0 -43
- package/see/examples/n3/hanoi.n3 +0 -16
- package/see/examples/n3/odrl_dpv_risk_ranked.n3 +0 -460
- package/see/examples/n3/path_discovery.n3 +0 -43
- package/see/examples/n3/socrates.n3 +0 -21
- package/see/examples/n3/wind_turbine.n3 +0 -85
- package/see/examples/n3/witch.n3 +0 -30
- package/see/examples/odrl_dpv_risk_ranked.js +0 -5128
- package/see/examples/output/age.md +0 -48
- package/see/examples/output/annotation.md +0 -43
- package/see/examples/output/backward.md +0 -50
- package/see/examples/output/backward_recursion.md +0 -54
- package/see/examples/output/bayes_diagnosis.md +0 -103
- package/see/examples/output/bayes_therapy.md +0 -84
- package/see/examples/output/bmi.md +0 -164
- package/see/examples/output/builtin_coverage.md +0 -99
- package/see/examples/output/collection.md +0 -44
- package/see/examples/output/complex.md +0 -61
- package/see/examples/output/complex_matrix_stability.md +0 -55
- package/see/examples/output/composition_of_injective_functions_is_injective.md +0 -62
- package/see/examples/output/control_system.md +0 -61
- package/see/examples/output/crypto_builtins_tests.md +0 -68
- package/see/examples/output/delfour.md +0 -100
- package/see/examples/output/digital_product_passport.md +0 -100
- package/see/examples/output/dijkstra.md +0 -74
- package/see/examples/output/dijkstra_risk_path.md +0 -76
- package/see/examples/output/dog.md +0 -50
- package/see/examples/output/eco_route_insight.md +0 -88
- package/see/examples/output/equals.md +0 -50
- package/see/examples/output/equivalence_classes_overlap_implies_same_class.md +0 -86
- package/see/examples/output/euler_identity.md +0 -73
- package/see/examples/output/ev_roundtrip_planner.md +0 -79
- package/see/examples/output/existential_rule.md +0 -54
- package/see/examples/output/expression_eval.md +0 -50
- package/see/examples/output/family_cousins.md +0 -187
- package/see/examples/output/fastpow.md +0 -36
- package/see/examples/output/fibonacci.md +0 -53
- package/see/examples/output/french_cities.md +0 -70
- package/see/examples/output/fundamental_theorem_arithmetic.md +0 -101
- package/see/examples/output/genetic_knapsack_selection.md +0 -66
- package/see/examples/output/goldbach_1000.md +0 -58
- package/see/examples/output/good_cobbler.md +0 -54
- package/see/examples/output/gps.md +0 -102
- package/see/examples/output/gray_code_counter.md +0 -68
- package/see/examples/output/greatest_lower_bound_uniqueness.md +0 -60
- package/see/examples/output/group_inverse_uniqueness.md +0 -60
- package/see/examples/output/hadamard_approx.md +0 -510
- package/see/examples/output/hanoi.md +0 -51
- package/see/examples/output/odrl_dpv_risk_ranked.md +0 -139
- package/see/examples/output/path_discovery.md +0 -65
- package/see/examples/output/rc_discharge_envelope.md +0 -102
- package/see/examples/output/rdf_dataset.md +0 -54
- package/see/examples/output/rdf_message_flow.md +0 -198
- package/see/examples/output/rdf_messages.md +0 -134
- package/see/examples/output/school_placement_audit.md +0 -99
- package/see/examples/output/smoke_arithmetic.md +0 -54
- package/see/examples/output/socrates.md +0 -55
- package/see/examples/output/triple_terms.md +0 -53
- package/see/examples/output/wind_turbine.md +0 -108
- package/see/examples/output/witch.md +0 -87
- package/see/examples/path_discovery.js +0 -1774
- package/see/examples/rc_discharge_envelope.js +0 -1993
- package/see/examples/rdf_dataset.js +0 -1512
- package/see/examples/rdf_message_flow.js +0 -2580
- package/see/examples/rdf_messages.js +0 -2176
- package/see/examples/school_placement_audit.js +0 -1867
- package/see/examples/smoke_arithmetic.js +0 -1483
- package/see/examples/socrates.js +0 -1420
- package/see/examples/triple_terms.js +0 -1442
- package/see/examples/wind_turbine.js +0 -2853
- package/see/examples/witch.js +0 -1519
- package/see/see.js +0 -2179
- package/test/see.test.js +0 -159
- /package/{see/examples/n3/builtin_coverage.n3 → examples/builtin-coverage.n3} +0 -0
- /package/examples/output/{reifies.n3 → builtin-coverage.n3} +0 -0
|
@@ -1,4417 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
'use strict';
|
|
3
|
-
const fs = require('fs');
|
|
4
|
-
const path = require('path');
|
|
5
|
-
const { fail, loadInput } = require('./_see');
|
|
6
|
-
|
|
7
|
-
const crypto = require('crypto');
|
|
8
|
-
|
|
9
|
-
function canonical(term) {
|
|
10
|
-
if (term.kind === 'list') return ['list', term.items.map(canonical)];
|
|
11
|
-
if (term.kind === 'triple') return ['triple', canonical(term.s), canonical(term.p), canonical(term.o)];
|
|
12
|
-
if (term.kind === 'formula') return ['formula', term.atoms.map((a) => [canonical(a.s), canonical(a.p), canonical(a.o)])];
|
|
13
|
-
return [term.kind, term.value];
|
|
14
|
-
}
|
|
15
|
-
function factKey(f) { return JSON.stringify([canonical(f.s), canonical(f.p), canonical(f.o)]); }
|
|
16
|
-
function termIndexKey(t) { return JSON.stringify(canonical(t)); }
|
|
17
|
-
function compoundIndexKey() { return Array.from(arguments).map(termIndexKey).join('\u001f'); }
|
|
18
|
-
function termIsConcrete(t) {
|
|
19
|
-
if (!t || t.kind === 'var') return false;
|
|
20
|
-
if (t.kind === 'list') return t.items.every(termIsConcrete);
|
|
21
|
-
if (t.kind === 'triple') return termIsConcrete(t.s) && termIsConcrete(t.p) && termIsConcrete(t.o);
|
|
22
|
-
if (t.kind === 'formula') return t.atoms.every((a) => termIsConcrete(a.s) && termIsConcrete(a.p) && termIsConcrete(a.o));
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
25
|
-
function isVar(t) { return t && t.kind === 'var'; }
|
|
26
|
-
function isIri(t, iri) { return t && t.kind === 'iri' && t.value === iri; }
|
|
27
|
-
function lit(value) { return { kind: 'lit', value }; }
|
|
28
|
-
function blank(value) { return { kind: 'blank', value }; }
|
|
29
|
-
function list(items) { return { kind: 'list', items }; }
|
|
30
|
-
function cloneTerm(t) { return JSON.parse(JSON.stringify(t)); }
|
|
31
|
-
function primitive(t) {
|
|
32
|
-
if (!t) return undefined;
|
|
33
|
-
if (t.kind === 'lit') return t.value;
|
|
34
|
-
if (t.kind === 'iri') return t.value.replace(/^:/, '');
|
|
35
|
-
if (t.kind === 'blank') return t.value;
|
|
36
|
-
if (t.kind === 'list') return t.items.map(primitive);
|
|
37
|
-
if (t.kind === 'triple') return termToN3(t);
|
|
38
|
-
if (t.kind === 'formula') return termToN3(t);
|
|
39
|
-
return undefined;
|
|
40
|
-
}
|
|
41
|
-
function literalToN3(value) {
|
|
42
|
-
if (typeof value === 'string') return JSON.stringify(value);
|
|
43
|
-
if (typeof value === 'number') {
|
|
44
|
-
if (Object.is(value, -0)) return '0';
|
|
45
|
-
if (Number.isInteger(value)) return String(value);
|
|
46
|
-
return Number(value.toPrecision(15)).toString();
|
|
47
|
-
}
|
|
48
|
-
if (typeof value === 'boolean') return value ? 'true' : 'false';
|
|
49
|
-
return JSON.stringify(value);
|
|
50
|
-
}
|
|
51
|
-
function termToN3(t) {
|
|
52
|
-
if (!t) return 'undefined';
|
|
53
|
-
if (t.kind === 'iri') return t.value;
|
|
54
|
-
if (t.kind === 'lit') return literalToN3(t.value);
|
|
55
|
-
if (t.kind === 'var') return '?' + t.value;
|
|
56
|
-
if (t.kind === 'blank') return t.value.startsWith('_:') ? t.value : '_:' + t.value.replace(/^_+/, '');
|
|
57
|
-
if (t.kind === 'list') return '(' + t.items.map(termToN3).join(' ') + ')';
|
|
58
|
-
if (t.kind === 'triple') return '<<( ' + termToN3(t.s) + ' ' + termToN3(t.p) + ' ' + termToN3(t.o) + ' )>>';
|
|
59
|
-
if (t.kind === 'formula') return '{ ' + t.atoms.map(atomToN3).join(' . ') + ' }';
|
|
60
|
-
return String(t.value ?? t);
|
|
61
|
-
}
|
|
62
|
-
function atomToN3(f) { return termToN3(f.s) + ' ' + termToN3(f.p) + ' ' + termToN3(f.o); }
|
|
63
|
-
function display(t) {
|
|
64
|
-
const value = primitive(t);
|
|
65
|
-
if (Array.isArray(value)) return value.map(String).join(' ');
|
|
66
|
-
return String(value);
|
|
67
|
-
}
|
|
68
|
-
function deepEqual(a, b) {
|
|
69
|
-
if (a?.kind === 'lit' && b?.kind === 'lit' && typeof a.value === 'number' && typeof b.value === 'number') {
|
|
70
|
-
return Math.abs(a.value - b.value) < 1e-12;
|
|
71
|
-
}
|
|
72
|
-
return JSON.stringify(canonical(a)) === JSON.stringify(canonical(b));
|
|
73
|
-
}
|
|
74
|
-
function resolve(term, env, seen = new Set()) {
|
|
75
|
-
if (term.kind === 'var' && Object.hasOwn(env, term.value)) {
|
|
76
|
-
if (seen.has(term.value)) return term;
|
|
77
|
-
seen.add(term.value);
|
|
78
|
-
return resolve(env[term.value], env, seen);
|
|
79
|
-
}
|
|
80
|
-
if (term.kind === 'list') return list(term.items.map((item) => resolve(item, env, seen)));
|
|
81
|
-
if (term.kind === 'triple') return { kind: 'triple', s: resolve(term.s, env), p: resolve(term.p, env), o: resolve(term.o, env) };
|
|
82
|
-
if (term.kind === 'formula') return { kind: 'formula', atoms: term.atoms.map((a) => ({ s: resolve(a.s, env), p: resolve(a.p, env), o: resolve(a.o, env) })) };
|
|
83
|
-
return term;
|
|
84
|
-
}
|
|
85
|
-
function unify(a, b, env) {
|
|
86
|
-
a = resolve(a, env);
|
|
87
|
-
b = resolve(b, env);
|
|
88
|
-
if (a.kind === 'var') return { ...env, [a.value]: b };
|
|
89
|
-
if (b.kind === 'var') return { ...env, [b.value]: a };
|
|
90
|
-
if (a.kind === 'list' || b.kind === 'list') {
|
|
91
|
-
if (a.kind !== 'list' || b.kind !== 'list' || a.items.length !== b.items.length) return null;
|
|
92
|
-
let out = env;
|
|
93
|
-
for (let i = 0; i < a.items.length; i += 1) {
|
|
94
|
-
out = unify(a.items[i], b.items[i], out);
|
|
95
|
-
if (!out) return null;
|
|
96
|
-
}
|
|
97
|
-
return out;
|
|
98
|
-
}
|
|
99
|
-
if (a.kind === 'triple' || b.kind === 'triple') {
|
|
100
|
-
if (a.kind !== 'triple' || b.kind !== 'triple') return null;
|
|
101
|
-
let out = unify(a.s, b.s, env);
|
|
102
|
-
if (!out) return null;
|
|
103
|
-
out = unify(a.p, b.p, out);
|
|
104
|
-
if (!out) return null;
|
|
105
|
-
return unify(a.o, b.o, out);
|
|
106
|
-
}
|
|
107
|
-
return deepEqual(a, b) ? env : null;
|
|
108
|
-
}
|
|
109
|
-
function bind(pattern, value, env) { return unify(pattern, value, env); }
|
|
110
|
-
function matchFact(atom, fact, env) {
|
|
111
|
-
let out = unify(atom.p, fact.p, env); if (!out) return null;
|
|
112
|
-
out = unify(atom.s, fact.s, out); if (!out) return null;
|
|
113
|
-
return unify(atom.o, fact.o, out);
|
|
114
|
-
}
|
|
115
|
-
function atomIsGround(atom, env) {
|
|
116
|
-
return termIsGround(atom.s, env) && termIsGround(atom.p, env) && termIsGround(atom.o, env);
|
|
117
|
-
}
|
|
118
|
-
function termIsGround(t, env) {
|
|
119
|
-
const r = resolve(t, env);
|
|
120
|
-
if (r.kind === 'var') return false;
|
|
121
|
-
if (r.kind === 'list') return r.items.every((item) => termIsGround(item, env));
|
|
122
|
-
if (r.kind === 'triple') return termIsGround(r.s, env) && termIsGround(r.p, env) && termIsGround(r.o, env);
|
|
123
|
-
if (r.kind === 'formula') return r.atoms.every((atom) => atomIsGround(atom, env));
|
|
124
|
-
return true;
|
|
125
|
-
}
|
|
126
|
-
function stringValue(t) {
|
|
127
|
-
const r = t;
|
|
128
|
-
if (!r) return null;
|
|
129
|
-
if (r.kind === 'lit') return String(r.value);
|
|
130
|
-
if (r.kind === 'iri') return r.value.replace(/[<>]/g, '');
|
|
131
|
-
if (r.kind === 'blank' || r.kind === 'var') return null;
|
|
132
|
-
return termToN3(r);
|
|
133
|
-
}
|
|
134
|
-
function xsdDurationSeconds(value) {
|
|
135
|
-
const m = String(value || '').match(/^(-)?P(?:(\d+(?:\.\d+)?)Y)?(?:(\d+(?:\.\d+)?)M)?(?:(\d+(?:\.\d+)?)W)?(?:(\d+(?:\.\d+)?)D)?(?:T(?:(\d+(?:\.\d+)?)H)?(?:(\d+(?:\.\d+)?)M)?(?:(\d+(?:\.\d+)?)S)?)?$/i);
|
|
136
|
-
if (!m) return null;
|
|
137
|
-
const sign = m[1] ? -1 : 1;
|
|
138
|
-
const years = Number(m[2] || 0);
|
|
139
|
-
const months = Number(m[3] || 0);
|
|
140
|
-
const weeks = Number(m[4] || 0);
|
|
141
|
-
const days = Number(m[5] || 0);
|
|
142
|
-
const hours = Number(m[6] || 0);
|
|
143
|
-
const minutes = Number(m[7] || 0);
|
|
144
|
-
const seconds = Number(m[8] || 0);
|
|
145
|
-
|
|
146
|
-
// xsd:duration years/months are calendar-relative. SEE uses Gregorian averages
|
|
147
|
-
// for standalone numeric comparisons such as "age above P80Y".
|
|
148
|
-
return sign * (
|
|
149
|
-
years * 365.2425 * 86400 +
|
|
150
|
-
months * (365.2425 / 12) * 86400 +
|
|
151
|
-
weeks * 7 * 86400 +
|
|
152
|
-
days * 86400 +
|
|
153
|
-
hours * 3600 +
|
|
154
|
-
minutes * 60 +
|
|
155
|
-
seconds
|
|
156
|
-
);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
function toNumberMaybe(t) {
|
|
160
|
-
const v = primitive(t);
|
|
161
|
-
if (typeof v === 'number') return Number.isFinite(v) || Number.isNaN(v) ? v : null;
|
|
162
|
-
if (typeof v === 'boolean') return v ? 1 : 0;
|
|
163
|
-
if (typeof v !== 'string') return null;
|
|
164
|
-
const dur = xsdDurationSeconds(v);
|
|
165
|
-
if (dur !== null) return dur;
|
|
166
|
-
const d = Date.parse(v);
|
|
167
|
-
if (/^\d{4}-\d{2}-\d{2}(?:T|$)/.test(v) && Number.isFinite(d)) return d / 1000;
|
|
168
|
-
const n = Number(v);
|
|
169
|
-
return Number.isNaN(n) ? null : n;
|
|
170
|
-
}
|
|
171
|
-
function toNumber(t) {
|
|
172
|
-
const n = toNumberMaybe(t);
|
|
173
|
-
if (n === null || !Number.isFinite(n)) throw new Error('Expected numeric value, got ' + JSON.stringify(primitive(t)));
|
|
174
|
-
return n;
|
|
175
|
-
}
|
|
176
|
-
function toIntegerMaybe(t) {
|
|
177
|
-
const n = toNumberMaybe(t);
|
|
178
|
-
if (n === null || !Number.isFinite(n) || !Number.isInteger(n)) return null;
|
|
179
|
-
return n;
|
|
180
|
-
}
|
|
181
|
-
function parseDate(t) {
|
|
182
|
-
const v = primitive(t);
|
|
183
|
-
if (typeof v !== 'string') return null;
|
|
184
|
-
const ms = Date.parse(v);
|
|
185
|
-
return Number.isFinite(ms) ? new Date(ms) : null;
|
|
186
|
-
}
|
|
187
|
-
function dateTimeLiteral(date) { return lit(date.toISOString().replace(/\.000Z$/, 'Z')); }
|
|
188
|
-
function durationLiteral(seconds) { return lit('PT' + Number(seconds.toPrecision(15)).toString() + 'S'); }
|
|
189
|
-
function termFrom(value) {
|
|
190
|
-
if (Array.isArray(value)) return list(value.map(termFrom));
|
|
191
|
-
if (value && typeof value === 'object' && value.kind) return value;
|
|
192
|
-
return lit(value);
|
|
193
|
-
}
|
|
194
|
-
function allBoundList(term, env) {
|
|
195
|
-
const r = resolve(term, env);
|
|
196
|
-
if (r.kind !== 'list') throw new Error('Expected N3 list');
|
|
197
|
-
if (r.items.some((item) => resolve(item, env).kind === 'var')) return null;
|
|
198
|
-
return r.items.map((item) => resolve(item, env));
|
|
199
|
-
}
|
|
200
|
-
function bindResult(pattern, value, env) {
|
|
201
|
-
return bind(pattern, termFrom(value), env);
|
|
202
|
-
}
|
|
203
|
-
function bindTermResult(pattern, term, env) {
|
|
204
|
-
const out = bind(pattern, term, env);
|
|
205
|
-
return out ? [out] : [];
|
|
206
|
-
}
|
|
207
|
-
function succeedIf(ok, env) { return ok ? [env] : []; }
|
|
208
|
-
function compareNumericTerms(a, b) {
|
|
209
|
-
const na = toNumberMaybe(a), nb = toNumberMaybe(b);
|
|
210
|
-
if (na === null || nb === null) return null;
|
|
211
|
-
if (Number.isNaN(na) || Number.isNaN(nb)) return NaN;
|
|
212
|
-
return na < nb ? -1 : na > nb ? 1 : 0;
|
|
213
|
-
}
|
|
214
|
-
function comparisonOperands(s, o, env) {
|
|
215
|
-
const left = resolve(s, env), right = resolve(o, env);
|
|
216
|
-
if (left.kind === 'list' && left.items.length === 2 && (right.kind === 'lit' ? right.value === true : right.kind === 'iri' && right.value === 'true')) {
|
|
217
|
-
return [resolve(left.items[0], env), resolve(left.items[1], env)];
|
|
218
|
-
}
|
|
219
|
-
return [left, right];
|
|
220
|
-
}
|
|
221
|
-
function bindNumericOutput(pattern, value, env) {
|
|
222
|
-
if (!Number.isFinite(value)) return [];
|
|
223
|
-
const normalized = Number.isInteger(value) ? value : Number(value.toPrecision(15));
|
|
224
|
-
return bindTermResult(pattern, lit(normalized), env);
|
|
225
|
-
}
|
|
226
|
-
function unaryMath(name, s, o, env, fwd, inv) {
|
|
227
|
-
const left = resolve(s, env), right = resolve(o, env);
|
|
228
|
-
if (left.kind !== 'var') return bindNumericOutput(o, fwd(toNumber(left)), env);
|
|
229
|
-
if (right.kind !== 'var' && inv) return bindNumericOutput(s, inv(toNumber(right)), env);
|
|
230
|
-
if (left.kind === 'var' && right.kind === 'var') return [env];
|
|
231
|
-
return [];
|
|
232
|
-
}
|
|
233
|
-
function builtinMath(name, s, o, env) {
|
|
234
|
-
const left = resolve(s, env);
|
|
235
|
-
const right = resolve(o, env);
|
|
236
|
-
const testCmp = (pred) => {
|
|
237
|
-
const [a, b] = comparisonOperands(s, o, env);
|
|
238
|
-
if (a.kind === 'var' || b.kind === 'var') return [];
|
|
239
|
-
const cmp = compareNumericTerms(a, b);
|
|
240
|
-
if (cmp === null || Number.isNaN(cmp)) return [];
|
|
241
|
-
return succeedIf(pred(cmp), env);
|
|
242
|
-
};
|
|
243
|
-
if (name === 'math:lessThan') return testCmp((c) => c < 0);
|
|
244
|
-
if (name === 'math:notLessThan') return testCmp((c) => c >= 0);
|
|
245
|
-
if (name === 'math:greaterThan') return testCmp((c) => c > 0);
|
|
246
|
-
if (name === 'math:notGreaterThan') return testCmp((c) => c <= 0);
|
|
247
|
-
if (name === 'math:equalTo') return testCmp((c) => c === 0);
|
|
248
|
-
if (name === 'math:notEqualTo') {
|
|
249
|
-
const [a, b] = comparisonOperands(s, o, env);
|
|
250
|
-
if (a.kind === 'var' || b.kind === 'var') return [];
|
|
251
|
-
const cmp = compareNumericTerms(a, b);
|
|
252
|
-
if (cmp !== null) return succeedIf(Number.isNaN(cmp) || cmp !== 0, env);
|
|
253
|
-
return succeedIf(!deepEqual(a, b), env);
|
|
254
|
-
}
|
|
255
|
-
if (name === 'math:negation') return unaryMath(name, s, o, env, (x) => -x, (x) => -x);
|
|
256
|
-
if (name === 'math:absoluteValue') {
|
|
257
|
-
if (left.kind === 'var' && right.kind === 'var') return [env];
|
|
258
|
-
if (left.kind !== 'var') return bindNumericOutput(o, Math.abs(toNumber(left)), env);
|
|
259
|
-
const n = toNumber(right);
|
|
260
|
-
const outs = [];
|
|
261
|
-
for (const v of n === 0 ? [0] : [n, -n]) {
|
|
262
|
-
const out = bind(s, lit(v), env); if (out) outs.push(out);
|
|
263
|
-
}
|
|
264
|
-
return outs;
|
|
265
|
-
}
|
|
266
|
-
if (name === 'math:degrees') return unaryMath(name, s, o, env, (x) => x * 180 / Math.PI, (x) => x * Math.PI / 180);
|
|
267
|
-
const unary = {
|
|
268
|
-
'math:sin': [Math.sin, Math.asin], 'math:cos': [Math.cos, Math.acos], 'math:tan': [Math.tan, Math.atan],
|
|
269
|
-
'math:asin': [Math.asin, Math.sin], 'math:acos': [Math.acos, Math.cos], 'math:atan': [Math.atan, Math.tan],
|
|
270
|
-
'math:sinh': [Math.sinh, Math.asinh], 'math:cosh': [Math.cosh, Math.acosh], 'math:tanh': [Math.tanh, Math.atanh],
|
|
271
|
-
'math:rounded': [Math.round, null], 'math:floor': [Math.floor, null]
|
|
272
|
-
};
|
|
273
|
-
if (Object.hasOwn(unary, name)) {
|
|
274
|
-
const [fwd, inv] = unary[name];
|
|
275
|
-
if (typeof fwd !== 'function') return [];
|
|
276
|
-
return unaryMath(name, s, o, env, fwd, typeof inv === 'function' ? inv : null);
|
|
277
|
-
}
|
|
278
|
-
if (name === 'math:exponentiation') {
|
|
279
|
-
const l = resolve(s, env);
|
|
280
|
-
if (l.kind !== 'list' || l.items.length !== 2) return [];
|
|
281
|
-
const base = resolve(l.items[0], env);
|
|
282
|
-
const exponent = resolve(l.items[1], env);
|
|
283
|
-
const result = resolve(o, env);
|
|
284
|
-
if (base.kind !== 'var' && exponent.kind !== 'var') return bindNumericOutput(o, Math.pow(toNumber(base), toNumber(exponent)), env);
|
|
285
|
-
if (base.kind !== 'var' && result.kind !== 'var') {
|
|
286
|
-
const b = toNumber(base), r = toNumber(result);
|
|
287
|
-
if (b > 0 && b !== 1 && r > 0) return bindNumericOutput(l.items[1], Math.log(r) / Math.log(b), env);
|
|
288
|
-
return [];
|
|
289
|
-
}
|
|
290
|
-
if (exponent.kind !== 'var' && result.kind !== 'var') {
|
|
291
|
-
const e = toNumber(exponent), r = toNumber(result);
|
|
292
|
-
if (e !== 0) return bindNumericOutput(l.items[0], Math.pow(r, 1 / e), env);
|
|
293
|
-
return [];
|
|
294
|
-
}
|
|
295
|
-
return [];
|
|
296
|
-
}
|
|
297
|
-
if (name === 'math:product' || name === 'math:sum') {
|
|
298
|
-
const vals = allBoundList(s, env); if (!vals) return [];
|
|
299
|
-
if (vals.length === 2) {
|
|
300
|
-
const [aT, bT] = vals;
|
|
301
|
-
const aD = parseDate(aT);
|
|
302
|
-
if (name === 'math:sum' && aD) {
|
|
303
|
-
const secs = toNumberMaybe(bT);
|
|
304
|
-
if (secs !== null && Number.isFinite(secs)) return bindTermResult(o, dateTimeLiteral(new Date(aD.getTime() + secs * 1000)), env);
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
const value = name === 'math:product' ? vals.reduce((a, x) => a * toNumber(x), 1) : vals.reduce((a, x) => a + toNumber(x), 0);
|
|
308
|
-
return bindNumericOutput(o, value, env);
|
|
309
|
-
}
|
|
310
|
-
if (name === 'math:difference' || name === 'math:quotient' || name === 'math:integerQuotient' || name === 'math:remainder') {
|
|
311
|
-
const vals = allBoundList(s, env); if (!vals || vals.length !== 2) return [];
|
|
312
|
-
const aD = parseDate(vals[0]), bD = parseDate(vals[1]);
|
|
313
|
-
if (name === 'math:difference' && aD && bD) return bindTermResult(o, durationLiteral((aD.getTime() - bD.getTime()) / 1000), env);
|
|
314
|
-
if (name === 'math:difference' && aD && !bD) {
|
|
315
|
-
const secs = toNumberMaybe(vals[1]);
|
|
316
|
-
if (secs !== null && Number.isFinite(secs)) return bindTermResult(o, dateTimeLiteral(new Date(aD.getTime() - secs * 1000)), env);
|
|
317
|
-
}
|
|
318
|
-
const a = toNumber(vals[0]), b = toNumber(vals[1]);
|
|
319
|
-
if ((name === 'math:quotient' || name === 'math:integerQuotient' || name === 'math:remainder') && b === 0) return [];
|
|
320
|
-
if (name === 'math:difference') return bindNumericOutput(o, a - b, env);
|
|
321
|
-
if (name === 'math:quotient') return bindNumericOutput(o, a / b, env);
|
|
322
|
-
if (!Number.isInteger(a) || !Number.isInteger(b)) return [];
|
|
323
|
-
if (name === 'math:integerQuotient') return bindNumericOutput(o, Math.trunc(a / b), env);
|
|
324
|
-
return bindNumericOutput(o, a % b, env);
|
|
325
|
-
}
|
|
326
|
-
return null;
|
|
327
|
-
}
|
|
328
|
-
function applyFormat(fmt, args) {
|
|
329
|
-
let i = 0;
|
|
330
|
-
return String(fmt).replace(/%([-0]?\d+)?(?:\.(\d+))?([%sdiufFeEgGc])/g, (m, width, precision, conv) => {
|
|
331
|
-
if (conv === '%') return '%';
|
|
332
|
-
const arg = args[i++];
|
|
333
|
-
if (conv === 's') return String(arg ?? '');
|
|
334
|
-
if (conv === 'c') return String.fromCodePoint(Number(arg));
|
|
335
|
-
if ('diu'.includes(conv)) return String(Math.trunc(Number(arg)));
|
|
336
|
-
const n = Number(arg);
|
|
337
|
-
if (conv === 'f' || conv === 'F') return n.toFixed(precision == null ? 6 : Number(precision));
|
|
338
|
-
if (conv === 'e' || conv === 'E') return n.toExponential(precision == null ? 6 : Number(precision));
|
|
339
|
-
if (conv === 'g' || conv === 'G') return n.toPrecision(precision == null ? 6 : Number(precision)).replace(/\.0+(e|$)/i, '$1');
|
|
340
|
-
return m;
|
|
341
|
-
});
|
|
342
|
-
}
|
|
343
|
-
function compileRegex(pattern, flags = '') {
|
|
344
|
-
try { return new RegExp(String(pattern), flags); }
|
|
345
|
-
catch { return null; }
|
|
346
|
-
}
|
|
347
|
-
function builtinString(name, s, o, env) {
|
|
348
|
-
const left = resolve(s, env), right = resolve(o, env);
|
|
349
|
-
function output(value) { return bindTermResult(o, lit(String(value)), env); }
|
|
350
|
-
const str = (term) => stringValue(resolve(term, env));
|
|
351
|
-
if (name === 'string:concatenation') {
|
|
352
|
-
const vals = allBoundList(s, env); if (!vals) return [];
|
|
353
|
-
return output(vals.map(stringValue).join(''));
|
|
354
|
-
}
|
|
355
|
-
if (name === 'string:format') {
|
|
356
|
-
const vals = allBoundList(s, env); if (!vals || vals.length === 0) return [];
|
|
357
|
-
return output(applyFormat(stringValue(vals[0]), vals.slice(1).map(stringValue)));
|
|
358
|
-
}
|
|
359
|
-
if (name === 'string:length') { const a = str(s); return a === null ? [] : bindTermResult(o, lit(a.length), env); }
|
|
360
|
-
if (name === 'string:charAt') {
|
|
361
|
-
const vals = allBoundList(s, env); if (!vals || vals.length !== 2) return [];
|
|
362
|
-
const a = stringValue(vals[0]); const idx = Math.trunc(toNumber(vals[1]));
|
|
363
|
-
return output(idx < 0 || idx >= a.length ? '' : a.charAt(idx));
|
|
364
|
-
}
|
|
365
|
-
if (name === 'string:setCharAt') {
|
|
366
|
-
const vals = allBoundList(s, env); if (!vals || vals.length !== 3) return [];
|
|
367
|
-
const a = stringValue(vals[0]); const idx = Math.trunc(toNumber(vals[1])); const ch = String(stringValue(vals[2]) || '').charAt(0);
|
|
368
|
-
if (idx < 0 || idx >= a.length) return output(a);
|
|
369
|
-
return output(a.slice(0, idx) + ch + a.slice(idx + 1));
|
|
370
|
-
}
|
|
371
|
-
const a = str(s), b = str(o);
|
|
372
|
-
if (name === 'string:contains') return a === null || b === null ? [] : succeedIf(a.includes(b), env);
|
|
373
|
-
if (name === 'string:containsIgnoringCase') return a === null || b === null ? [] : succeedIf(a.toLowerCase().includes(b.toLowerCase()), env);
|
|
374
|
-
if (name === 'string:startsWith') return a === null || b === null ? [] : succeedIf(a.startsWith(b), env);
|
|
375
|
-
if (name === 'string:endsWith') return a === null || b === null ? [] : succeedIf(a.endsWith(b), env);
|
|
376
|
-
if (name === 'string:equalIgnoringCase') return a === null || b === null ? [] : succeedIf(a.toLowerCase() === b.toLowerCase(), env);
|
|
377
|
-
if (name === 'string:notEqualIgnoringCase') return a === null || b === null ? [] : succeedIf(a.toLowerCase() !== b.toLowerCase(), env);
|
|
378
|
-
if (name === 'string:greaterThan') return a === null || b === null ? [] : succeedIf(a > b, env);
|
|
379
|
-
if (name === 'string:lessThan') return a === null || b === null ? [] : succeedIf(a < b, env);
|
|
380
|
-
if (name === 'string:notGreaterThan') return a === null || b === null ? [] : succeedIf(a <= b, env);
|
|
381
|
-
if (name === 'string:notLessThan') return a === null || b === null ? [] : succeedIf(a >= b, env);
|
|
382
|
-
if (name === 'string:matches' || name === 'string:notMatches') {
|
|
383
|
-
if (a === null || b === null) return [];
|
|
384
|
-
const re = compileRegex(b); if (!re) return [];
|
|
385
|
-
const ok = re.test(a);
|
|
386
|
-
return succeedIf(name === 'string:matches' ? ok : !ok, env);
|
|
387
|
-
}
|
|
388
|
-
if (name === 'string:replace') {
|
|
389
|
-
const vals = allBoundList(s, env); if (!vals || vals.length !== 3) return [];
|
|
390
|
-
const data = stringValue(vals[0]), pattern = stringValue(vals[1]), replacement = stringValue(vals[2]);
|
|
391
|
-
const re = compileRegex(pattern, 'g'); if (!re) return [];
|
|
392
|
-
return output(data.replace(re, replacement));
|
|
393
|
-
}
|
|
394
|
-
if (name === 'string:scrape') {
|
|
395
|
-
const vals = allBoundList(s, env); if (!vals || vals.length !== 2) return [];
|
|
396
|
-
const data = stringValue(vals[0]), pattern = stringValue(vals[1]);
|
|
397
|
-
const re = compileRegex(pattern); if (!re) return [];
|
|
398
|
-
const m = data.match(re); if (!m || m.length < 2) return [];
|
|
399
|
-
return output(m[1]);
|
|
400
|
-
}
|
|
401
|
-
return null;
|
|
402
|
-
}
|
|
403
|
-
function builtinCrypto(name, s, o, env) {
|
|
404
|
-
const algos = { 'crypto:sha': 'sha1', 'crypto:md5': 'md5', 'crypto:sha256': 'sha256', 'crypto:sha512': 'sha512' };
|
|
405
|
-
if (!Object.hasOwn(algos, name)) return null;
|
|
406
|
-
if (!termIsGround(s, env)) return [];
|
|
407
|
-
const digest = crypto.createHash(algos[name]).update(String(primitive(resolve(s, env))), 'utf8').digest('hex');
|
|
408
|
-
return bindTermResult(o, lit(digest), env);
|
|
409
|
-
}
|
|
410
|
-
function formulaContains(graph, patternAtoms, env, rules, depth) {
|
|
411
|
-
const localGraph = graph && graph.facts ? graph : makeGraph(graph?.atoms || graph?.facts || []);
|
|
412
|
-
return evalBody(patternAtoms, [env], localGraph, rules, depth + 1).length > 0;
|
|
413
|
-
}
|
|
414
|
-
function builtinLog(name, s, o, env, graph, rules, depth) {
|
|
415
|
-
if (name === 'log:equalTo') return bindTermResult(s, resolve(o, env), env);
|
|
416
|
-
if (name === 'log:notEqualTo') {
|
|
417
|
-
const out = unify(resolve(s, env), resolve(o, env), env);
|
|
418
|
-
return out ? [] : [env];
|
|
419
|
-
}
|
|
420
|
-
if (name === 'log:conjunction') {
|
|
421
|
-
const vals = allBoundList(s, env); if (!vals) return [];
|
|
422
|
-
const merged = [], seen = new Set();
|
|
423
|
-
for (const part of vals) {
|
|
424
|
-
if (part.kind === 'lit' && part.value === true) continue;
|
|
425
|
-
if (part.kind !== 'formula') return [];
|
|
426
|
-
for (const atom of part.atoms) { const k = factKey(atom); if (!seen.has(k)) { seen.add(k); merged.push(atom); } }
|
|
427
|
-
}
|
|
428
|
-
return bindTermResult(o, { kind: 'formula', atoms: merged }, env);
|
|
429
|
-
}
|
|
430
|
-
if (name === 'log:includes' || name === 'log:notIncludes') {
|
|
431
|
-
const scope = resolve(s, env), pattern = resolve(o, env);
|
|
432
|
-
if (pattern.kind !== 'formula') return [];
|
|
433
|
-
const local = scope.kind === 'formula' ? makeGraph(scope.atoms) : graph;
|
|
434
|
-
const ok = evalBody(pattern.atoms, [env], local, rules, depth + 1).length > 0;
|
|
435
|
-
return succeedIf(name === 'log:includes' ? ok : !ok, env);
|
|
436
|
-
}
|
|
437
|
-
if (name === 'log:rawType') {
|
|
438
|
-
const rt = resolve(s, env);
|
|
439
|
-
if (rt.kind === 'var') return [];
|
|
440
|
-
const ty = rt.kind === 'formula' ? 'log:Formula' : rt.kind === 'lit' ? 'log:Literal' : rt.kind === 'list' ? 'rdf:List' : 'log:Other';
|
|
441
|
-
return bindTermResult(o, { kind: 'iri', value: ty }, env);
|
|
442
|
-
}
|
|
443
|
-
if (name === 'log:dtlit') {
|
|
444
|
-
const l = resolve(s, env), obj = resolve(o, env);
|
|
445
|
-
if (l.kind === 'list' && l.items.length === 2) {
|
|
446
|
-
const lex = stringValue(resolve(l.items[0], env));
|
|
447
|
-
const dt = resolve(l.items[1], env);
|
|
448
|
-
if (lex === null || dt.kind !== 'iri') return [];
|
|
449
|
-
return bindTermResult(o, lit(lex), env);
|
|
450
|
-
}
|
|
451
|
-
if (obj.kind === 'var') return [];
|
|
452
|
-
return stringValue(obj) === null ? [] : [env];
|
|
453
|
-
}
|
|
454
|
-
if (name === 'log:outputString') return [env];
|
|
455
|
-
if (name === 'log:collectAllIn') {
|
|
456
|
-
const l = resolve(s, env); if (l.kind !== 'list' || l.items.length !== 3) return [];
|
|
457
|
-
const [valueTemplate, clause, outList] = l.items;
|
|
458
|
-
const scope = resolve(o, env);
|
|
459
|
-
const local = scope.kind === 'formula' ? makeGraph(scope.atoms) : graph;
|
|
460
|
-
if (clause.kind !== 'formula') return [];
|
|
461
|
-
const sols = evalBody(clause.atoms, [env], local, rules, depth + 1);
|
|
462
|
-
return bindTermResult(outList, list(sols.map((sol) => resolve(valueTemplate, sol))), env);
|
|
463
|
-
}
|
|
464
|
-
if (name === 'log:forAllIn') {
|
|
465
|
-
const l = resolve(s, env); if (l.kind !== 'list' || l.items.length !== 2) return [];
|
|
466
|
-
const [where, then] = l; if (where.kind !== 'formula' || then.kind !== 'formula') return [];
|
|
467
|
-
const scope = resolve(o, env);
|
|
468
|
-
const local = scope.kind === 'formula' ? makeGraph(scope.atoms) : graph;
|
|
469
|
-
const sols = evalBody(where.atoms, [{}], local, rules, depth + 1);
|
|
470
|
-
for (const sol of sols) if (!evalBody(then.atoms, [sol], local, rules, depth + 1).length) return [];
|
|
471
|
-
return [env];
|
|
472
|
-
}
|
|
473
|
-
if (['log:content', 'log:semantics', 'log:semanticsOrError', 'log:parsedAsN3'].includes(name)) {
|
|
474
|
-
throw new Error(name + ' requires dereferencing or parsing at runtime and is intentionally not available in offline specialized SEE output');
|
|
475
|
-
}
|
|
476
|
-
return null;
|
|
477
|
-
}
|
|
478
|
-
function splitList(items, parts, env, start = 0, idx = 0) {
|
|
479
|
-
if (idx === parts.length) return start === items.length ? [env] : [];
|
|
480
|
-
const outs = [];
|
|
481
|
-
const last = idx === parts.length - 1;
|
|
482
|
-
for (let end = start; end <= items.length; end += 1) {
|
|
483
|
-
if (last && end !== items.length) continue;
|
|
484
|
-
const out = bind(parts[idx], list(items.slice(start, end)), env);
|
|
485
|
-
if (out) outs.push(...splitList(items, parts, out, end, idx + 1));
|
|
486
|
-
}
|
|
487
|
-
return outs;
|
|
488
|
-
}
|
|
489
|
-
function termSortKey(t) {
|
|
490
|
-
if (t.kind === 'lit') { const n = Number(t.value); return Number.isNaN(n) ? '1:' + String(t.value) : '0:' + n.toString().padStart(20, '0'); }
|
|
491
|
-
if (t.kind === 'iri') return '2:' + t.value;
|
|
492
|
-
if (t.kind === 'list') return '3:' + t.items.map(termSortKey).join('|');
|
|
493
|
-
return '9:' + JSON.stringify(canonical(t));
|
|
494
|
-
}
|
|
495
|
-
function builtinList(name, s, o, env, graph, rules, depth) {
|
|
496
|
-
const predName = name === 'rdf:first' ? 'list:first' : name === 'rdf:rest' ? 'list:rest' : name;
|
|
497
|
-
const left = resolve(s, env);
|
|
498
|
-
const right = resolve(o, env);
|
|
499
|
-
const listItems = (term) => term.kind === 'list' ? term.items.map((x) => resolve(x, env)) : null;
|
|
500
|
-
if (predName === 'list:first') {
|
|
501
|
-
const xs = listItems(left); if (!xs || !xs.length) return [];
|
|
502
|
-
return bindTermResult(o, xs[0], env);
|
|
503
|
-
}
|
|
504
|
-
if (predName === 'list:rest') {
|
|
505
|
-
const xs = listItems(left); if (!xs || !xs.length) return [];
|
|
506
|
-
return bindTermResult(o, list(xs.slice(1)), env);
|
|
507
|
-
}
|
|
508
|
-
if (predName === 'list:firstRest') {
|
|
509
|
-
const outs = [];
|
|
510
|
-
if (left.kind === 'list' && left.items.length > 0 && !left.items.some((x) => resolve(x, env).kind === 'var')) {
|
|
511
|
-
const items = left.items.map((x) => resolve(x, env));
|
|
512
|
-
const out = bind(o, list([items[0], list(items.slice(1))]), env); if (out) outs.push(out);
|
|
513
|
-
}
|
|
514
|
-
if (right.kind === 'list' && right.items.length === 2) {
|
|
515
|
-
const rest = resolve(right.items[1], env);
|
|
516
|
-
const first = resolve(right.items[0], env);
|
|
517
|
-
if (rest.kind === 'list') { const out = bind(s, list([first, ...rest.items]), env); if (out) outs.push(out); }
|
|
518
|
-
}
|
|
519
|
-
return outs;
|
|
520
|
-
}
|
|
521
|
-
if (predName === 'list:append') {
|
|
522
|
-
if (left.kind !== 'list') return [];
|
|
523
|
-
if (right.kind === 'list') return splitList(right.items, left.items, env);
|
|
524
|
-
const outElems = [];
|
|
525
|
-
for (const part of left.items) { const p = resolve(part, env); if (p.kind !== 'list') return []; outElems.push(...p.items); }
|
|
526
|
-
return bindTermResult(o, list(outElems), env);
|
|
527
|
-
}
|
|
528
|
-
if (predName === 'list:iterate') {
|
|
529
|
-
const xs = listItems(left); if (!xs) return [];
|
|
530
|
-
const outs = [];
|
|
531
|
-
for (let i = 0; i < xs.length; i += 1) { const out = bind(o, list([lit(i), xs[i]]), env); if (out) outs.push(out); }
|
|
532
|
-
return outs;
|
|
533
|
-
}
|
|
534
|
-
if (predName === 'list:last') {
|
|
535
|
-
const xs = listItems(left); if (!xs || !xs.length) return [];
|
|
536
|
-
return bindTermResult(o, xs[xs.length - 1], env);
|
|
537
|
-
}
|
|
538
|
-
if (predName === 'list:memberAt') {
|
|
539
|
-
if (left.kind !== 'list' || left.items.length !== 2) return [];
|
|
540
|
-
const arr = resolve(left.items[0], env), idx = resolve(left.items[1], env);
|
|
541
|
-
if (arr.kind !== 'list') return [];
|
|
542
|
-
const outs = [];
|
|
543
|
-
for (let i = 0; i < arr.items.length; i += 1) {
|
|
544
|
-
let out = idx.kind === 'var' ? bind(left.items[1], lit(i), env) : (Number(idx.value) === i ? env : null);
|
|
545
|
-
if (out) out = bind(o, arr.items[i], out);
|
|
546
|
-
if (out) outs.push(out);
|
|
547
|
-
}
|
|
548
|
-
return outs;
|
|
549
|
-
}
|
|
550
|
-
if (predName === 'list:remove') {
|
|
551
|
-
if (left.kind !== 'list' || left.items.length !== 2) return [];
|
|
552
|
-
const arr = resolve(left.items[0], env), item = resolve(left.items[1], env);
|
|
553
|
-
if (arr.kind !== 'list' || item.kind === 'var') return [];
|
|
554
|
-
return bindTermResult(o, list(arr.items.filter((x) => !deepEqual(resolve(x, env), item))), env);
|
|
555
|
-
}
|
|
556
|
-
if (predName === 'list:member') {
|
|
557
|
-
const xs = listItems(left); if (!xs) return [];
|
|
558
|
-
return xs.map((x) => bind(o, x, env)).filter(Boolean);
|
|
559
|
-
}
|
|
560
|
-
if (predName === 'list:in') {
|
|
561
|
-
const xs = listItems(right); if (!xs) return [];
|
|
562
|
-
return xs.map((x) => bind(s, x, env)).filter(Boolean);
|
|
563
|
-
}
|
|
564
|
-
if (predName === 'list:length') {
|
|
565
|
-
const xs = listItems(left); if (!xs) return [];
|
|
566
|
-
return bindTermResult(o, lit(xs.length), env);
|
|
567
|
-
}
|
|
568
|
-
if (predName === 'list:notMember') {
|
|
569
|
-
const xs = listItems(left); if (!xs) return [];
|
|
570
|
-
return xs.some((x) => unify(o, x, env)) ? [] : [env];
|
|
571
|
-
}
|
|
572
|
-
if (predName === 'list:reverse') {
|
|
573
|
-
if (left.kind === 'list') return bindTermResult(o, list([...left.items].reverse()), env);
|
|
574
|
-
if (right.kind === 'list') return bindTermResult(s, list([...right.items].reverse()), env);
|
|
575
|
-
return [];
|
|
576
|
-
}
|
|
577
|
-
if (predName === 'list:sort') {
|
|
578
|
-
const source = left.kind === 'list' ? left : right.kind === 'list' ? right : null;
|
|
579
|
-
if (!source || source.items.some((x) => resolve(x, env).kind === 'var')) return [];
|
|
580
|
-
const sorted = [...source.items].sort((a, b) => termSortKey(a).localeCompare(termSortKey(b)));
|
|
581
|
-
return left.kind === 'list' ? bindTermResult(o, list(sorted), env) : bindTermResult(s, list(sorted), env);
|
|
582
|
-
}
|
|
583
|
-
if (predName === 'list:map') {
|
|
584
|
-
if (left.kind !== 'list' || left.items.length !== 2) return [];
|
|
585
|
-
const arr = resolve(left.items[0], env), pred = resolve(left.items[1], env);
|
|
586
|
-
if (arr.kind !== 'list' || pred.kind !== 'iri') return [];
|
|
587
|
-
const values = [];
|
|
588
|
-
for (let i = 0; i < arr.items.length; i += 1) {
|
|
589
|
-
const valueVar = { kind: 'var', value: '__map_' + depth + '_' + i };
|
|
590
|
-
const matches = evalAtom({ s: arr.items[i], p: pred, o: valueVar }, env, graph, rules, depth + 1);
|
|
591
|
-
for (const m of matches) { const v = resolve(valueVar, m); if (v.kind !== 'var') values.push(v); }
|
|
592
|
-
}
|
|
593
|
-
return bindTermResult(o, list(values), env);
|
|
594
|
-
}
|
|
595
|
-
return null;
|
|
596
|
-
}
|
|
597
|
-
function parseDateTimeParts(t) {
|
|
598
|
-
const v = primitive(t);
|
|
599
|
-
if (typeof v !== 'string') return null;
|
|
600
|
-
const m = v.match(/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d+)?)(Z|[+-]\d{2}:\d{2})?$/);
|
|
601
|
-
if (!m) return null;
|
|
602
|
-
return { year: Number(m[1]), month: Number(m[2]), day: Number(m[3]), hour: Number(m[4]), minute: Number(m[5]), second: Number(m[6]), timeZone: m[7] || '' };
|
|
603
|
-
}
|
|
604
|
-
function builtinTime(name, s, o, env) {
|
|
605
|
-
if (name === 'time:localTime') return bindTermResult(o, lit(new Date().toISOString().replace(/\.000Z$/, 'Z')), env);
|
|
606
|
-
const parts = parseDateTimeParts(resolve(s, env)); if (!parts) return [];
|
|
607
|
-
const key = name.slice('time:'.length);
|
|
608
|
-
if (['year','month','day','hour','minute','second'].includes(key)) return bindTermResult(o, lit(parts[key]), env);
|
|
609
|
-
if (key === 'timeZone') return bindTermResult(o, lit(parts.timeZone || 'Z'), env);
|
|
610
|
-
return null;
|
|
611
|
-
}
|
|
612
|
-
function evalBuiltin(atom, env, graph, rules, depth) {
|
|
613
|
-
const pred = resolve(atom.p, env);
|
|
614
|
-
if (pred.kind !== 'iri') return null;
|
|
615
|
-
const name = pred.value;
|
|
616
|
-
if (name.startsWith('math:')) return builtinMath(name, atom.s, atom.o, env);
|
|
617
|
-
if (name.startsWith('string:')) return builtinString(name, atom.s, atom.o, env);
|
|
618
|
-
if (name.startsWith('crypto:')) return builtinCrypto(name, atom.s, atom.o, env);
|
|
619
|
-
if (name.startsWith('list:') || name === 'rdf:first' || name === 'rdf:rest') return builtinList(name, atom.s, atom.o, env, graph, rules, depth);
|
|
620
|
-
if (name.startsWith('time:')) return builtinTime(name, atom.s, atom.o, env);
|
|
621
|
-
if (name.startsWith('log:')) return builtinLog(name, atom.s, atom.o, env, graph, rules, depth);
|
|
622
|
-
return null;
|
|
623
|
-
}
|
|
624
|
-
function renameTerm(term, suffix) {
|
|
625
|
-
if (term.kind === 'var') return { kind: 'var', value: term.value + suffix };
|
|
626
|
-
if (term.kind === 'list') return list(term.items.map((item) => renameTerm(item, suffix)));
|
|
627
|
-
if (term.kind === 'formula') return { kind: 'formula', atoms: term.atoms.map((a) => renameAtom(a, suffix)) };
|
|
628
|
-
return cloneTerm(term);
|
|
629
|
-
}
|
|
630
|
-
function renameAtom(atom, suffix) {
|
|
631
|
-
return { s: renameTerm(atom.s, suffix), p: renameTerm(atom.p, suffix), o: renameTerm(atom.o, suffix) };
|
|
632
|
-
}
|
|
633
|
-
let renameCounter = 0;
|
|
634
|
-
function evalBackward(atom, env, graph, rules, depth) {
|
|
635
|
-
if (depth > 200) throw new Error('Backward rule recursion limit exceeded');
|
|
636
|
-
const outs = [];
|
|
637
|
-
for (const rule of rules) {
|
|
638
|
-
if (rule.kind !== 'backward') continue;
|
|
639
|
-
for (const headAtom of rule.head) {
|
|
640
|
-
const suffix = '__rule' + rule.id + '_' + depth + '_' + (++renameCounter);
|
|
641
|
-
const renamedHead = renameAtom(headAtom, suffix);
|
|
642
|
-
let out = unify(atom.p, renamedHead.p, env); if (!out) continue;
|
|
643
|
-
out = unify(atom.s, renamedHead.s, out); if (!out) continue;
|
|
644
|
-
out = unify(atom.o, renamedHead.o, out); if (!out) continue;
|
|
645
|
-
const renamedBody = rule.body.map((bodyAtom) => renameAtom(bodyAtom, suffix));
|
|
646
|
-
outs.push(...evalBody(renamedBody, [out], graph, rules, depth + 1));
|
|
647
|
-
}
|
|
648
|
-
}
|
|
649
|
-
return outs;
|
|
650
|
-
}
|
|
651
|
-
function evalAtom(atom, env, graph, rules, depth = 0) {
|
|
652
|
-
const builtin = evalBuiltin(atom, env, graph, rules, depth);
|
|
653
|
-
if (builtin !== null) return builtin;
|
|
654
|
-
const outs = [];
|
|
655
|
-
for (const fact of candidateFactsForAtom(atom, env, graph)) {
|
|
656
|
-
const out = matchFact(atom, fact, env);
|
|
657
|
-
if (out) outs.push(out);
|
|
658
|
-
}
|
|
659
|
-
outs.push(...evalBackward(atom, env, graph, rules, depth + 1));
|
|
660
|
-
return outs;
|
|
661
|
-
}
|
|
662
|
-
function evalBody(atoms, envs, graph, rules, depth = 0) {
|
|
663
|
-
let out = envs;
|
|
664
|
-
for (const atom of atoms) {
|
|
665
|
-
const next = [];
|
|
666
|
-
for (const env of out) next.push(...evalAtom(atom, env, graph, rules, depth));
|
|
667
|
-
out = next;
|
|
668
|
-
if (!out.length) break;
|
|
669
|
-
}
|
|
670
|
-
return out;
|
|
671
|
-
}
|
|
672
|
-
function envSignature(env) {
|
|
673
|
-
return crypto.createHash('sha1').update(JSON.stringify(Object.keys(env).sort().map((k) => [k, canonical(env[k])]))).digest('hex').slice(0, 12);
|
|
674
|
-
}
|
|
675
|
-
function instantiate(term, env, ruleId) {
|
|
676
|
-
if (term.kind === 'var') {
|
|
677
|
-
if (!Object.hasOwn(env, term.value)) throw new Error('Unbound variable in rule head: ?' + term.value);
|
|
678
|
-
return cloneTerm(resolve(env[term.value], env));
|
|
679
|
-
}
|
|
680
|
-
if (term.kind === 'blank') return blank('_:r' + ruleId + '_' + envSignature(env) + '_' + term.value.replace(/^_/, ''));
|
|
681
|
-
if (term.kind === 'list') return list(term.items.map((item) => instantiate(item, env, ruleId)));
|
|
682
|
-
if (term.kind === 'triple') return { kind: 'triple', s: instantiate(term.s, env, ruleId), p: instantiate(term.p, env, ruleId), o: instantiate(term.o, env, ruleId) };
|
|
683
|
-
if (term.kind === 'formula') return { kind: 'formula', atoms: term.atoms.map((a) => ({ s: instantiate(a.s, env, ruleId), p: instantiate(a.p, env, ruleId), o: instantiate(a.o, env, ruleId) })) };
|
|
684
|
-
return cloneTerm(term);
|
|
685
|
-
}
|
|
686
|
-
function supportFactsForBody(body, env, graph) {
|
|
687
|
-
const seen = new Set();
|
|
688
|
-
const out = [];
|
|
689
|
-
for (const atom of body || []) {
|
|
690
|
-
const pred = resolve(atom.p, env);
|
|
691
|
-
if (pred.kind === 'iri') {
|
|
692
|
-
const builtin = pred.value.startsWith('math:') || pred.value.startsWith('string:') || pred.value.startsWith('crypto:') ||
|
|
693
|
-
pred.value.startsWith('list:') || pred.value.startsWith('time:') || pred.value.startsWith('log:') ||
|
|
694
|
-
pred.value === 'rdf:first' || pred.value === 'rdf:rest';
|
|
695
|
-
if (builtin) continue;
|
|
696
|
-
}
|
|
697
|
-
for (const fact of candidateFactsForAtom(atom, env, graph)) {
|
|
698
|
-
if (!matchFact(atom, fact, env)) continue;
|
|
699
|
-
const key = factKey(fact);
|
|
700
|
-
if (!seen.has(key)) { seen.add(key); out.push(fact); }
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
return out;
|
|
704
|
-
}
|
|
705
|
-
function makeIndex() { return { p: new Map(), spByP: new Map(), poByP: new Map(), s: null, o: null }; }
|
|
706
|
-
function pushIndex(map, key, fact) {
|
|
707
|
-
let bucket = map.get(key);
|
|
708
|
-
if (!bucket) { bucket = []; map.set(key, bucket); }
|
|
709
|
-
bucket.push(fact);
|
|
710
|
-
}
|
|
711
|
-
function makeGraph(facts) {
|
|
712
|
-
const graph = { facts: [], keys: new Set(), index: makeIndex() };
|
|
713
|
-
for (const fact of facts) addFact(graph, fact);
|
|
714
|
-
return graph;
|
|
715
|
-
}
|
|
716
|
-
function ensureFlatIndex(graph, kind, termSelector) {
|
|
717
|
-
if (!graph.index[kind]) {
|
|
718
|
-
const map = new Map();
|
|
719
|
-
for (const fact of graph.facts) pushIndex(map, termIndexKey(termSelector(fact)), fact);
|
|
720
|
-
graph.index[kind] = map;
|
|
721
|
-
}
|
|
722
|
-
return graph.index[kind];
|
|
723
|
-
}
|
|
724
|
-
function ensurePredicateTermIndex(graph, byPredicate, pKey, pFacts, termSelector) {
|
|
725
|
-
let map = graph.index[byPredicate].get(pKey);
|
|
726
|
-
if (!map) {
|
|
727
|
-
map = new Map();
|
|
728
|
-
for (const fact of pFacts) pushIndex(map, termIndexKey(termSelector(fact)), fact);
|
|
729
|
-
graph.index[byPredicate].set(pKey, map);
|
|
730
|
-
}
|
|
731
|
-
return map;
|
|
732
|
-
}
|
|
733
|
-
function addFact(graph, fact) {
|
|
734
|
-
const key = factKey(fact);
|
|
735
|
-
if (graph.keys.has(key)) return false;
|
|
736
|
-
graph.keys.add(key);
|
|
737
|
-
graph.facts.push(fact);
|
|
738
|
-
const pKey = termIndexKey(fact.p);
|
|
739
|
-
pushIndex(graph.index.p, pKey, fact);
|
|
740
|
-
if (graph.index.s) pushIndex(graph.index.s, termIndexKey(fact.s), fact);
|
|
741
|
-
if (graph.index.o) pushIndex(graph.index.o, termIndexKey(fact.o), fact);
|
|
742
|
-
const sp = graph.index.spByP.get(pKey);
|
|
743
|
-
if (sp) pushIndex(sp, termIndexKey(fact.s), fact);
|
|
744
|
-
const po = graph.index.poByP.get(pKey);
|
|
745
|
-
if (po) pushIndex(po, termIndexKey(fact.o), fact);
|
|
746
|
-
return true;
|
|
747
|
-
}
|
|
748
|
-
function candidateFactsForAtom(atom, env, graph) {
|
|
749
|
-
if (!graph || !graph.index) return graph && graph.facts ? graph.facts : [];
|
|
750
|
-
const s = resolve(atom.s, env), p = resolve(atom.p, env), o = resolve(atom.o, env);
|
|
751
|
-
const sg = termIsConcrete(s), pg = termIsConcrete(p), og = termIsConcrete(o);
|
|
752
|
-
if (pg) {
|
|
753
|
-
const pKey = termIndexKey(p);
|
|
754
|
-
const pFacts = graph.index.p.get(pKey) || [];
|
|
755
|
-
if (sg) return ensurePredicateTermIndex(graph, 'spByP', pKey, pFacts, (f) => f.s).get(termIndexKey(s)) || [];
|
|
756
|
-
if (og) return ensurePredicateTermIndex(graph, 'poByP', pKey, pFacts, (f) => f.o).get(termIndexKey(o)) || [];
|
|
757
|
-
return pFacts;
|
|
758
|
-
}
|
|
759
|
-
if (sg) return ensureFlatIndex(graph, 's', (f) => f.s).get(termIndexKey(s)) || [];
|
|
760
|
-
if (og) return ensureFlatIndex(graph, 'o', (f) => f.o).get(termIndexKey(o)) || [];
|
|
761
|
-
return graph.facts;
|
|
762
|
-
}
|
|
763
|
-
|
|
764
|
-
function isBuiltinPredicateValue(name) {
|
|
765
|
-
return typeof name === 'string' && (name.startsWith('math:') || name.startsWith('string:') || name.startsWith('crypto:') ||
|
|
766
|
-
name.startsWith('list:') || name.startsWith('time:') || name.startsWith('log:') || name === 'rdf:first' || name === 'rdf:rest');
|
|
767
|
-
}
|
|
768
|
-
function collectFormulaDependencyKeys(term, keys) {
|
|
769
|
-
if (!term) return true;
|
|
770
|
-
if (term.kind === 'formula') {
|
|
771
|
-
for (const atom of term.atoms || []) {
|
|
772
|
-
if (!collectAtomDependencyKeys(atom, keys)) return false;
|
|
773
|
-
}
|
|
774
|
-
return true;
|
|
775
|
-
}
|
|
776
|
-
if (term.kind === 'list') {
|
|
777
|
-
for (const item of term.items || []) if (!collectFormulaDependencyKeys(item, keys)) return false;
|
|
778
|
-
}
|
|
779
|
-
return true;
|
|
780
|
-
}
|
|
781
|
-
function collectAtomDependencyKeys(atom, keys) {
|
|
782
|
-
const pred = atom && atom.p;
|
|
783
|
-
if (!pred || pred.kind === 'var') return false;
|
|
784
|
-
if (pred.kind === 'iri') {
|
|
785
|
-
if (!isBuiltinPredicateValue(pred.value)) keys.add(termIndexKey(pred));
|
|
786
|
-
else if (pred.value.startsWith('log:')) {
|
|
787
|
-
if (!collectFormulaDependencyKeys(atom.s, keys)) return false;
|
|
788
|
-
if (!collectFormulaDependencyKeys(atom.o, keys)) return false;
|
|
789
|
-
}
|
|
790
|
-
}
|
|
791
|
-
return true;
|
|
792
|
-
}
|
|
793
|
-
function ruleDependencyPredicateKeys(rule) {
|
|
794
|
-
const keys = new Set();
|
|
795
|
-
for (const atom of rule.body || []) {
|
|
796
|
-
if (!collectAtomDependencyKeys(atom, keys)) return null;
|
|
797
|
-
}
|
|
798
|
-
return keys;
|
|
799
|
-
}
|
|
800
|
-
function producedFactsCanAffectRules(producedPredicates, ruleDependencies) {
|
|
801
|
-
if (!producedPredicates || !producedPredicates.size) return false;
|
|
802
|
-
for (const deps of ruleDependencies) {
|
|
803
|
-
if (deps === null) return true;
|
|
804
|
-
for (const key of producedPredicates) if (deps.has(key)) return true;
|
|
805
|
-
}
|
|
806
|
-
return false;
|
|
807
|
-
}
|
|
808
|
-
function saturate(initialFacts, rules) {
|
|
809
|
-
const graph = makeGraph(initialFacts);
|
|
810
|
-
const trace = [];
|
|
811
|
-
const maxIterations = 10000;
|
|
812
|
-
const activeRules = (rules || []).filter((rule) => rule.kind !== 'backward');
|
|
813
|
-
const ruleDependencies = activeRules.map(ruleDependencyPredicateKeys);
|
|
814
|
-
for (let iter = 0; iter < maxIterations; iter += 1) {
|
|
815
|
-
let changed = false;
|
|
816
|
-
const producedPredicates = new Set();
|
|
817
|
-
for (const rule of activeRules) {
|
|
818
|
-
const matches = evalBody(rule.body, [{}], graph, rules);
|
|
819
|
-
if (rule.kind === 'fuse') {
|
|
820
|
-
if (matches.length) throw new Error('N3 fuse failed in compiled rule #' + rule.id);
|
|
821
|
-
continue;
|
|
822
|
-
}
|
|
823
|
-
for (const env of matches) {
|
|
824
|
-
const supportFacts = supportFactsForBody(rule.body, env, graph);
|
|
825
|
-
const produced = [];
|
|
826
|
-
for (const atom of rule.head) {
|
|
827
|
-
const fact = { s: instantiate(atom.s, env, rule.id), p: instantiate(atom.p, env, rule.id), o: instantiate(atom.o, env, rule.id) };
|
|
828
|
-
if (addFact(graph, fact)) {
|
|
829
|
-
changed = true;
|
|
830
|
-
produced.push(fact);
|
|
831
|
-
producedPredicates.add(termIndexKey(fact.p));
|
|
832
|
-
}
|
|
833
|
-
}
|
|
834
|
-
if (produced.length) {
|
|
835
|
-
trace.push({
|
|
836
|
-
rule: rule.id,
|
|
837
|
-
produced: produced.length,
|
|
838
|
-
producedFacts: produced.map(codeFact).map((x) => x.replace(/ \.$/, '')),
|
|
839
|
-
supportFacts: supportFacts.map(codeFact).map((x) => x.replace(/ \.$/, ''))
|
|
840
|
-
});
|
|
841
|
-
}
|
|
842
|
-
}
|
|
843
|
-
}
|
|
844
|
-
if (!changed) break;
|
|
845
|
-
if (!producedFactsCanAffectRules(producedPredicates, ruleDependencies)) break;
|
|
846
|
-
if (iter === maxIterations - 1) throw new Error('Compiled derivation did not reach a fixpoint');
|
|
847
|
-
}
|
|
848
|
-
return { graph, trace };
|
|
849
|
-
}
|
|
850
|
-
function queryFacts(graph, queries, rules) {
|
|
851
|
-
const out = [];
|
|
852
|
-
const seen = new Set();
|
|
853
|
-
for (const query of queries || []) {
|
|
854
|
-
const matches = evalBody(query.premise || [], [{}], graph, rules);
|
|
855
|
-
for (const env of matches) {
|
|
856
|
-
for (const atom of query.conclusion || []) {
|
|
857
|
-
const fact = { s: instantiate(atom.s, env, 'q' + query.id), p: instantiate(atom.p, env, 'q' + query.id), o: instantiate(atom.o, env, 'q' + query.id) };
|
|
858
|
-
if (!atomIsGround(fact, {})) throw new Error('Unbound variable in log:query projection');
|
|
859
|
-
const key = factKey(fact);
|
|
860
|
-
if (!seen.has(key)) { seen.add(key); out.push(fact); }
|
|
861
|
-
}
|
|
862
|
-
}
|
|
863
|
-
}
|
|
864
|
-
return out;
|
|
865
|
-
}
|
|
866
|
-
function outputStrings(graph) {
|
|
867
|
-
return graph.facts
|
|
868
|
-
.filter((f) => isIri(f.p, 'log:outputString'))
|
|
869
|
-
.sort((a, b) => display(a.s).localeCompare(display(b.s)))
|
|
870
|
-
.map((f) => String(primitive(f.o)));
|
|
871
|
-
}
|
|
872
|
-
function initialKeys(initialFacts) {
|
|
873
|
-
if (!initialFacts) return new Set();
|
|
874
|
-
if (initialFacts.__seeKeySet) return initialFacts.__seeKeySet;
|
|
875
|
-
const keys = new Set((initialFacts || []).map(factKey));
|
|
876
|
-
try { Object.defineProperty(initialFacts, '__seeKeySet', { value: keys, enumerable: false }); } catch (_) {}
|
|
877
|
-
return keys;
|
|
878
|
-
}
|
|
879
|
-
function derivedFacts(graph, initialFacts) {
|
|
880
|
-
const base = initialKeys(initialFacts);
|
|
881
|
-
return graph.facts.filter((f) => !base.has(factKey(f)));
|
|
882
|
-
}
|
|
883
|
-
function codeFact(f) { return atomToN3(f) + ' .'; }
|
|
884
|
-
function unquoteLiteral(text) {
|
|
885
|
-
const m = String(text || '').match(/^\"([\s\S]*)\"$/);
|
|
886
|
-
if (!m) return String(text || '');
|
|
887
|
-
return m[1].replace(/\\"/g, '"').replace(/\\n/g, '\n').replace(/\\\\/g, '\\');
|
|
888
|
-
}
|
|
889
|
-
function readablePredicateName(term) {
|
|
890
|
-
return String(term || '')
|
|
891
|
-
.replace(/^[:<#]*/, '')
|
|
892
|
-
.replace(/[>#]*$/g, '')
|
|
893
|
-
.replace(/^./, (ch) => ch.toLowerCase());
|
|
894
|
-
}
|
|
895
|
-
function compactValidationValue(value) {
|
|
896
|
-
return String(value || '').replace(/^OK\s*-\s*/i, '').trim();
|
|
897
|
-
}
|
|
898
|
-
function compactSupportFactText(fact) {
|
|
899
|
-
const text = String(fact || '')
|
|
900
|
-
.replace(/===\s*Reason\s+Why\s*===/gi, '=== Explanation ===')
|
|
901
|
-
.replace(/===\s*Review\s*===/gi, '=== Explanation ===');
|
|
902
|
-
const report = text.match(/^(.*?\blog:outputString)\s+/);
|
|
903
|
-
if (report) return report[1] + ' "[authored report]"';
|
|
904
|
-
|
|
905
|
-
return text.replace(/\s{2,}/g, ' ').trim();
|
|
906
|
-
}
|
|
907
|
-
function compactRuleComment(comment) {
|
|
908
|
-
return compactSupportFactText(comment);
|
|
909
|
-
}
|
|
910
|
-
function shortTerm(t) { return termToN3(t); }
|
|
911
|
-
function factSentence(f) {
|
|
912
|
-
const s = shortTerm(f.s), p = shortTerm(f.p), o = shortTerm(f.o);
|
|
913
|
-
if (isIri(f.p, 'rdf:type')) return s + ' is a ' + o + '.';
|
|
914
|
-
if (isIri(f.p, 'rdfs:subClassOf')) return s + ' is a subclass of ' + o + '.';
|
|
915
|
-
if (isIri(f.p, ':is') || /(^|:)is$/.test(p)) return s + ' is ' + o + '.';
|
|
916
|
-
return s + ' ' + p + ' ' + o + '.';
|
|
917
|
-
}
|
|
918
|
-
function previewItems(items, limit = 2) {
|
|
919
|
-
const list = Array.isArray(items) ? items.filter(Boolean).map(compactRuleComment) : [];
|
|
920
|
-
const shown = list.slice(0, limit).join('; ');
|
|
921
|
-
const more = list.length > limit ? '; … +' + (list.length - limit) + ' more' : '';
|
|
922
|
-
return shown + more;
|
|
923
|
-
}
|
|
924
|
-
function describeRule(rule) {
|
|
925
|
-
if (!rule) return 'compiled rule';
|
|
926
|
-
const body = rule.bodyComment || [];
|
|
927
|
-
const head = rule.headComment || [];
|
|
928
|
-
if (rule.kind === 'fuse') {
|
|
929
|
-
const preview = previewItems(body, 2) || 'forbidden pattern';
|
|
930
|
-
return 'Fuse ' + rule.id + ' guards against ' + preview;
|
|
931
|
-
}
|
|
932
|
-
const bodyCount = body.length;
|
|
933
|
-
const headCount = head.length;
|
|
934
|
-
if (bodyCount <= 2 && headCount <= 2) {
|
|
935
|
-
return 'Rule ' + rule.id + ': ' + (previewItems(body, 2) || 'true') + ' => ' + (previewItems(head, 2) || 'false');
|
|
936
|
-
}
|
|
937
|
-
return 'Rule ' + rule.id + ' (' + bodyCount + ' premise pattern(s) => ' + headCount + ' conclusion pattern(s))';
|
|
938
|
-
}
|
|
939
|
-
function traceApplications(trace, rules, limit = 6) {
|
|
940
|
-
const byId = new Map((rules || []).map((r) => [r.id, r]));
|
|
941
|
-
const grouped = new Map();
|
|
942
|
-
for (const step of trace || []) {
|
|
943
|
-
const facts = Array.isArray(step.producedFacts) ? step.producedFacts : [];
|
|
944
|
-
if (!facts.length) continue;
|
|
945
|
-
const key = String(step.rule);
|
|
946
|
-
if (!grouped.has(key)) grouped.set(key, { rule: byId.get(step.rule), facts: [], supportFacts: [] });
|
|
947
|
-
const entry = grouped.get(key);
|
|
948
|
-
for (const fact of facts) if (!entry.facts.includes(fact)) entry.facts.push(fact);
|
|
949
|
-
for (const fact of Array.isArray(step.supportFacts) ? step.supportFacts : []) {
|
|
950
|
-
if (!entry.supportFacts.includes(fact)) entry.supportFacts.push(fact);
|
|
951
|
-
}
|
|
952
|
-
}
|
|
953
|
-
return Array.from(grouped.values()).slice(0, limit);
|
|
954
|
-
}
|
|
955
|
-
function supportIndex(trace) {
|
|
956
|
-
const index = new Map();
|
|
957
|
-
for (const step of trace || []) {
|
|
958
|
-
const facts = Array.isArray(step.producedFacts) ? step.producedFacts : [];
|
|
959
|
-
for (const fact of facts) {
|
|
960
|
-
if (!index.has(fact)) {
|
|
961
|
-
index.set(fact, { rule: step.rule, supportFacts: Array.isArray(step.supportFacts) ? step.supportFacts : [] });
|
|
962
|
-
}
|
|
963
|
-
}
|
|
964
|
-
}
|
|
965
|
-
return index;
|
|
966
|
-
}
|
|
967
|
-
function supportTreeLines(fact, supportMap, sourceKeys, ruleMap, opts = {}) {
|
|
968
|
-
const lines = [];
|
|
969
|
-
const maxDepth = opts.maxDepth ?? 4;
|
|
970
|
-
const maxChildren = opts.maxChildren ?? 4;
|
|
971
|
-
const maxLines = opts.maxLines ?? 40;
|
|
972
|
-
function walk(item, depth, seen) {
|
|
973
|
-
if (lines.length >= maxLines) return;
|
|
974
|
-
const indent = ' '.repeat(depth);
|
|
975
|
-
if (/\blog:outputString\b/.test(String(item || ''))) {
|
|
976
|
-
const support = supportMap.get(item);
|
|
977
|
-
const rule = support ? ruleMap.get(support.rule) : null;
|
|
978
|
-
const label = support ? (rule ? 'Rule ' + rule.id : 'compiled rule #' + support.rule) : 'no recorded rule support';
|
|
979
|
-
lines.push(indent + '- ' + compactSupportFactText(item) + ' . _(authored report, ' + label + ')_');
|
|
980
|
-
return;
|
|
981
|
-
}
|
|
982
|
-
if (sourceKeys.has(item)) {
|
|
983
|
-
lines.push(indent + '- ' + compactSupportFactText(item) + ' . _(source)_');
|
|
984
|
-
return;
|
|
985
|
-
}
|
|
986
|
-
const support = supportMap.get(item);
|
|
987
|
-
if (!support) {
|
|
988
|
-
lines.push(indent + '- ' + compactSupportFactText(item) + ' . _(no recorded rule support)_');
|
|
989
|
-
return;
|
|
990
|
-
}
|
|
991
|
-
const rule = ruleMap.get(support.rule);
|
|
992
|
-
const label = rule ? 'Rule ' + rule.id : 'compiled rule #' + support.rule;
|
|
993
|
-
lines.push(indent + '- ' + compactSupportFactText(item) + ' . _(derived by ' + label + ')_');
|
|
994
|
-
if (depth >= maxDepth) {
|
|
995
|
-
if (support.supportFacts && support.supportFacts.length) lines.push(indent + ' - support omitted beyond depth ' + maxDepth);
|
|
996
|
-
return;
|
|
997
|
-
}
|
|
998
|
-
const children = (support.supportFacts || []).slice(0, maxChildren);
|
|
999
|
-
const childIndent = indent + ' ';
|
|
1000
|
-
if (!children.length) {
|
|
1001
|
-
lines.push(childIndent + '- no graph premises; built-ins/constants satisfied the rule.');
|
|
1002
|
-
return;
|
|
1003
|
-
}
|
|
1004
|
-
for (const child of children) {
|
|
1005
|
-
if (seen.has(child)) {
|
|
1006
|
-
lines.push(childIndent + '- ' + compactSupportFactText(child) + ' . _(already shown)_');
|
|
1007
|
-
continue;
|
|
1008
|
-
}
|
|
1009
|
-
const nextSeen = new Set(seen);
|
|
1010
|
-
nextSeen.add(child);
|
|
1011
|
-
walk(child, depth + 1, nextSeen);
|
|
1012
|
-
if (lines.length >= maxLines) break;
|
|
1013
|
-
}
|
|
1014
|
-
if ((support.supportFacts || []).length > children.length) {
|
|
1015
|
-
lines.push(childIndent + '- ... ' + ((support.supportFacts || []).length - children.length) + ' more premise fact(s)');
|
|
1016
|
-
}
|
|
1017
|
-
}
|
|
1018
|
-
walk(fact, 0, new Set([fact]));
|
|
1019
|
-
if (lines.length >= maxLines) lines.push('- … support tree truncated after ' + maxLines + ' line(s)');
|
|
1020
|
-
return lines;
|
|
1021
|
-
}
|
|
1022
|
-
function conclusionSupportSection(selected, trace, rules, initialFacts, limit = 6) {
|
|
1023
|
-
const supportMap = supportIndex(trace);
|
|
1024
|
-
const sourceKeys = new Set((initialFacts || []).map((f) => codeFact(f).replace(/ \.$/, '')));
|
|
1025
|
-
const ruleMap = new Map((rules || []).map((r) => [r.id, r]));
|
|
1026
|
-
const facts = [];
|
|
1027
|
-
const seen = new Set();
|
|
1028
|
-
for (const f of selected || []) {
|
|
1029
|
-
const key = codeFact(f).replace(/ \.$/, '');
|
|
1030
|
-
if (!seen.has(key)) { seen.add(key); facts.push(key); }
|
|
1031
|
-
}
|
|
1032
|
-
const focus = facts.slice(-limit).reverse();
|
|
1033
|
-
if (!focus.length) return [];
|
|
1034
|
-
const lines = [];
|
|
1035
|
-
lines.push('Selected explanation support:');
|
|
1036
|
-
for (const fact of focus) {
|
|
1037
|
-
lines.push(...supportTreeLines(fact, supportMap, sourceKeys, ruleMap).map((line) => ' ' + line));
|
|
1038
|
-
}
|
|
1039
|
-
return lines;
|
|
1040
|
-
}
|
|
1041
|
-
function evidenceSummaryLine(mode) {
|
|
1042
|
-
if (mode === 'query') return 'The query-selected facts are serialized in the Formal TriG Output section.';
|
|
1043
|
-
if (mode === 'formula') return 'The formula-valued facts are serialized in the Formal TriG Output section.';
|
|
1044
|
-
return 'The selected facts are serialized in the Formal TriG Output section.';
|
|
1045
|
-
}
|
|
1046
|
-
function renderStructuredOutput({ title, graph, queries = [], rules = [], initialFacts = [], trace = [], mode = 'derived' }) {
|
|
1047
|
-
let selected = [];
|
|
1048
|
-
if (mode === 'query') selected = queryFacts(graph, queries, rules);
|
|
1049
|
-
else if (mode === 'formula') selected = graph.facts.filter((f) => f.o && f.o.kind === 'formula');
|
|
1050
|
-
else selected = derivedFacts(graph, initialFacts);
|
|
1051
|
-
if (!selected.length) selected = graph.facts.slice(0, 30);
|
|
1052
|
-
|
|
1053
|
-
const derived = derivedFacts(graph, initialFacts);
|
|
1054
|
-
const keyFact = selected[selected.length - 1];
|
|
1055
|
-
const lines = [];
|
|
1056
|
-
lines.push('# ' + title);
|
|
1057
|
-
lines.push('');
|
|
1058
|
-
lines.push('## Entailment');
|
|
1059
|
-
if (mode === 'query') {
|
|
1060
|
-
lines.push('The compiled query selected ' + selected.length + ' fact(s) after the rule closure was computed.');
|
|
1061
|
-
} else if (mode === 'formula') {
|
|
1062
|
-
lines.push('The derivation produced ' + selected.length + ' formula-valued entailment(s).');
|
|
1063
|
-
} else {
|
|
1064
|
-
lines.push('The derivation produced ' + derived.length + ' new fact(s) from ' + initialFacts.length + ' stated fact(s).');
|
|
1065
|
-
}
|
|
1066
|
-
if (keyFact) lines.push('Main entailment: **' + factSentence(keyFact) + '**');
|
|
1067
|
-
const bullets = selected.slice(-6).reverse();
|
|
1068
|
-
if (bullets.length) {
|
|
1069
|
-
lines.push('');
|
|
1070
|
-
lines.push('Selected entailments:');
|
|
1071
|
-
for (const fact of bullets) lines.push('- ' + codeFact(fact));
|
|
1072
|
-
}
|
|
1073
|
-
lines.push('');
|
|
1074
|
-
lines.push('## Explanation');
|
|
1075
|
-
const ordinaryRules = (rules || []).filter((r) => r.kind !== 'fuse').length;
|
|
1076
|
-
const fuses = (rules || []).filter((r) => r.kind === 'fuse').length;
|
|
1077
|
-
lines.push('Starts with ' + initialFacts.length + ' source fact(s), applies ' + ordinaryRules + ' rule(s), and reaches a fixpoint.');
|
|
1078
|
-
if (queries.length) lines.push('The log:query projection then keeps only the matching fact(s) shown above.');
|
|
1079
|
-
if (fuses) lines.push('The run also validates ' + fuses + ' fuse(s) for forbidden patterns.');
|
|
1080
|
-
const apps = traceApplications(trace, rules);
|
|
1081
|
-
if (apps.length) {
|
|
1082
|
-
lines.push('');
|
|
1083
|
-
lines.push('Derivation steps:');
|
|
1084
|
-
const sourceKeys = new Set((initialFacts || []).map((f) => codeFact(f).replace(/ \.$/, '')));
|
|
1085
|
-
for (const app of apps) {
|
|
1086
|
-
const produced = app.facts.slice(0, 4).map((f) => compactSupportFactText(f) + ' .').join(', ');
|
|
1087
|
-
const more = app.facts.length > 4 ? ', … +' + (app.facts.length - 4) + ' more' : '';
|
|
1088
|
-
lines.push('- ' + describeRule(app.rule) + ' derives ' + produced + more);
|
|
1089
|
-
if (app.supportFacts && app.supportFacts.length) {
|
|
1090
|
-
const used = app.supportFacts.slice(0, 4).map((fact) => compactSupportFactText(fact) + ' . ' + (sourceKeys.has(fact) ? '_(source)_' : '_(derived)_')).join('; ');
|
|
1091
|
-
const omitted = app.supportFacts.length > 4 ? '; … +' + (app.supportFacts.length - 4) + ' more premise fact(s)' : '';
|
|
1092
|
-
lines.push(' - Uses: ' + used + omitted);
|
|
1093
|
-
} else {
|
|
1094
|
-
lines.push(' - Uses: no graph premises; built-ins/constants satisfied the rule.');
|
|
1095
|
-
}
|
|
1096
|
-
}
|
|
1097
|
-
}
|
|
1098
|
-
const supportLines = conclusionSupportSection(selected, trace, rules, initialFacts);
|
|
1099
|
-
if (supportLines.length) {
|
|
1100
|
-
lines.push('');
|
|
1101
|
-
lines.push(...supportLines);
|
|
1102
|
-
}
|
|
1103
|
-
lines.push('');
|
|
1104
|
-
lines.push(evidenceSummaryLine(mode));
|
|
1105
|
-
return lines.join('\n') + '\n';
|
|
1106
|
-
}
|
|
1107
|
-
function renderRawOutput(graph, queries = [], rules = [], initialFacts = []) {
|
|
1108
|
-
const outs = outputStrings(graph);
|
|
1109
|
-
if (outs.length) return outs.join('');
|
|
1110
|
-
if (queries && queries.length) {
|
|
1111
|
-
const selected = queryFacts(graph, queries, rules);
|
|
1112
|
-
if (selected.length) return selected.map((f) => codeFact(f)).join('\n') + '\n';
|
|
1113
|
-
return '';
|
|
1114
|
-
}
|
|
1115
|
-
const formulaFacts = graph.facts.filter((f) => f.o && f.o.kind === 'formula');
|
|
1116
|
-
if (formulaFacts.length) return formulaFacts.map((f) => codeFact(f)).join('\n') + '\n';
|
|
1117
|
-
const derived = derivedFacts(graph, initialFacts);
|
|
1118
|
-
const selected = derived.length ? derived : graph.facts.slice(0, 30);
|
|
1119
|
-
return selected.map((f) => codeFact(f)).join('\n') + '\n';
|
|
1120
|
-
}
|
|
1121
|
-
function dedupeExplanationHeadings(text) {
|
|
1122
|
-
let seen = false;
|
|
1123
|
-
return String(text || '').replace(/^##\s+Explanation\s*$/gmi, () => {
|
|
1124
|
-
if (seen) return '';
|
|
1125
|
-
seen = true;
|
|
1126
|
-
return '## Explanation';
|
|
1127
|
-
});
|
|
1128
|
-
}
|
|
1129
|
-
function normalizePublicReport(markdown, title) {
|
|
1130
|
-
let text = String(markdown || '').trimEnd();
|
|
1131
|
-
if (!/^\s*#\s+/m.test(text)) text = '# ' + title + '\n\n' + text;
|
|
1132
|
-
if (!/^##\s+Entailment\s*$/mi.test(text)) {
|
|
1133
|
-
text = text.replace(/^(#\s+[^\n]+\n*)/, '$1\n## Entailment\n');
|
|
1134
|
-
}
|
|
1135
|
-
if (!/^##\s+Explanation\s*$/mi.test(text)) {
|
|
1136
|
-
text += '\n\n## Explanation\nNo additional explanation was provided by the generated output.';
|
|
1137
|
-
}
|
|
1138
|
-
text = text.replace(/^##\s+([^\n]+?)\s*$/gm, (line, heading) => {
|
|
1139
|
-
const normalized = heading.trim().toLowerCase();
|
|
1140
|
-
if (normalized === 'insight' || normalized === 'conclusion' || normalized === 'entailment' || normalized === 'explanation') return '## ' + (normalized === 'explanation' ? 'Explanation' : 'Entailment');
|
|
1141
|
-
return '**' + heading.trim() + '**';
|
|
1142
|
-
});
|
|
1143
|
-
text = dedupeExplanationHeadings(text);
|
|
1144
|
-
return text.trimEnd() + '\n';
|
|
1145
|
-
}
|
|
1146
|
-
function markdownize(raw, title) {
|
|
1147
|
-
let text = String(raw || '');
|
|
1148
|
-
text = text
|
|
1149
|
-
.replace(/===\s*Answer\s*===/g, '## Entailment')
|
|
1150
|
-
.replace(/===\s*Reason\s+Why\s*===/gi, '## Explanation')
|
|
1151
|
-
.replace(/===\s*Explanation\s*===/gi, '## Explanation')
|
|
1152
|
-
.replace(/===\s*([^=]+?)\s*===/g, (_, h) => '**' + h.trim() + '**');
|
|
1153
|
-
text = text.replace(/^C(\d+)\s+OK\s*-\s*/gm, 'C$1: ');
|
|
1154
|
-
text = dedupeExplanationHeadings(text);
|
|
1155
|
-
if (!text.trim()) text = '## Entailment\nNo log:outputString facts were derived.\n\n## Explanation\nThe compiled derivation did not produce authored report text.';
|
|
1156
|
-
return normalizePublicReport(text, title);
|
|
1157
|
-
}
|
|
1158
|
-
function authoredSupportAppendix(graph, queries, rules, initialFacts, trace) {
|
|
1159
|
-
const derived = derivedFacts(graph, initialFacts);
|
|
1160
|
-
let selected = [];
|
|
1161
|
-
if (queries && queries.length) selected = queryFacts(graph, queries, rules);
|
|
1162
|
-
else if (graph.facts.some((f) => f.o && f.o.kind === 'formula')) selected = graph.facts.filter((f) => f.o && f.o.kind === 'formula');
|
|
1163
|
-
else selected = derived;
|
|
1164
|
-
const lines = [];
|
|
1165
|
-
const ordinaryRules = (rules || []).filter((r) => r.kind !== 'fuse').length;
|
|
1166
|
-
const apps = traceApplications(trace, rules, 6);
|
|
1167
|
-
const supportLines = conclusionSupportSection(selected, trace, rules, initialFacts, 4);
|
|
1168
|
-
if (!apps.length && !supportLines.length) return '';
|
|
1169
|
-
lines.push('**Generated derivation support**');
|
|
1170
|
-
lines.push('');
|
|
1171
|
-
lines.push('Compiled support: ' + initialFacts.length + ' source fact(s), ' + ordinaryRules + ' rule(s), fixpoint reached before rendering.');
|
|
1172
|
-
if (apps.length) {
|
|
1173
|
-
lines.push('');
|
|
1174
|
-
lines.push('Derivation steps:');
|
|
1175
|
-
const sourceKeys = new Set((initialFacts || []).map((f) => codeFact(f).replace(/ \.$/, '')));
|
|
1176
|
-
for (const app of apps) {
|
|
1177
|
-
const produced = app.facts.slice(0, 4).map((f) => compactSupportFactText(f) + ' .').join(', ');
|
|
1178
|
-
const more = app.facts.length > 4 ? ', … +' + (app.facts.length - 4) + ' more' : '';
|
|
1179
|
-
lines.push('- ' + describeRule(app.rule) + ' derives ' + produced + more);
|
|
1180
|
-
if (app.supportFacts && app.supportFacts.length) {
|
|
1181
|
-
const used = app.supportFacts.slice(0, 4).map((fact) => compactSupportFactText(fact) + ' . ' + (sourceKeys.has(fact) ? '_(source)_' : '_(derived)_')).join('; ');
|
|
1182
|
-
const omitted = app.supportFacts.length > 4 ? '; … +' + (app.supportFacts.length - 4) + ' more premise fact(s)' : '';
|
|
1183
|
-
lines.push(' - Uses: ' + used + omitted);
|
|
1184
|
-
} else {
|
|
1185
|
-
lines.push(' - Uses: no graph premises; built-ins/constants satisfied the rule.');
|
|
1186
|
-
}
|
|
1187
|
-
}
|
|
1188
|
-
}
|
|
1189
|
-
if (supportLines.length) {
|
|
1190
|
-
lines.push('');
|
|
1191
|
-
lines.push(...supportLines);
|
|
1192
|
-
}
|
|
1193
|
-
return lines.join('\n');
|
|
1194
|
-
}
|
|
1195
|
-
function appendAuthoredExplanation(markdown, graph, queries, rules, initialFacts, trace) {
|
|
1196
|
-
const appendix = authoredSupportAppendix(graph, queries, rules, initialFacts, trace);
|
|
1197
|
-
if (!appendix) return markdown;
|
|
1198
|
-
return markdown.trimEnd() + '\n\n' + appendix + '\n';
|
|
1199
|
-
}
|
|
1200
|
-
function renderPresentation(graph, queries, rules, initialFacts, title, trace) {
|
|
1201
|
-
const outs = outputStrings(graph);
|
|
1202
|
-
if (outs.length) return appendAuthoredExplanation(markdownize(outs.join(''), title), graph, queries, rules, initialFacts, trace);
|
|
1203
|
-
if (queries && queries.length) return renderStructuredOutput({ title, graph, queries, rules, initialFacts, trace, mode: 'query' });
|
|
1204
|
-
if (graph.facts.some((f) => f.o && f.o.kind === 'formula')) return renderStructuredOutput({ title, graph, queries, rules, initialFacts, trace, mode: 'formula' });
|
|
1205
|
-
return renderStructuredOutput({ title, graph, queries, rules, initialFacts, trace, mode: 'derived' });
|
|
1206
|
-
}
|
|
1207
|
-
|
|
1208
|
-
const NAME = "hadamard_approx";
|
|
1209
|
-
const TITLE = "Hadamard gate approximation";
|
|
1210
|
-
const EXPECTED_INPUT_FACTS = 8;
|
|
1211
|
-
const RULES = [
|
|
1212
|
-
{
|
|
1213
|
-
"kind": "rule",
|
|
1214
|
-
"id": 1,
|
|
1215
|
-
"body": [
|
|
1216
|
-
{
|
|
1217
|
-
"s": {
|
|
1218
|
-
"kind": "iri",
|
|
1219
|
-
"value": ":sqrt2Proc"
|
|
1220
|
-
},
|
|
1221
|
-
"p": {
|
|
1222
|
-
"kind": "iri",
|
|
1223
|
-
"value": ":state"
|
|
1224
|
-
},
|
|
1225
|
-
"o": {
|
|
1226
|
-
"kind": "list",
|
|
1227
|
-
"items": [
|
|
1228
|
-
{
|
|
1229
|
-
"kind": "var",
|
|
1230
|
-
"value": "n"
|
|
1231
|
-
},
|
|
1232
|
-
{
|
|
1233
|
-
"kind": "var",
|
|
1234
|
-
"value": "l"
|
|
1235
|
-
},
|
|
1236
|
-
{
|
|
1237
|
-
"kind": "var",
|
|
1238
|
-
"value": "u"
|
|
1239
|
-
}
|
|
1240
|
-
]
|
|
1241
|
-
}
|
|
1242
|
-
},
|
|
1243
|
-
{
|
|
1244
|
-
"s": {
|
|
1245
|
-
"kind": "iri",
|
|
1246
|
-
"value": ":sqrt2Proc"
|
|
1247
|
-
},
|
|
1248
|
-
"p": {
|
|
1249
|
-
"kind": "iri",
|
|
1250
|
-
"value": ":maxN"
|
|
1251
|
-
},
|
|
1252
|
-
"o": {
|
|
1253
|
-
"kind": "var",
|
|
1254
|
-
"value": "maxN"
|
|
1255
|
-
}
|
|
1256
|
-
},
|
|
1257
|
-
{
|
|
1258
|
-
"s": {
|
|
1259
|
-
"kind": "var",
|
|
1260
|
-
"value": "n"
|
|
1261
|
-
},
|
|
1262
|
-
"p": {
|
|
1263
|
-
"kind": "iri",
|
|
1264
|
-
"value": "math:lessThan"
|
|
1265
|
-
},
|
|
1266
|
-
"o": {
|
|
1267
|
-
"kind": "var",
|
|
1268
|
-
"value": "maxN"
|
|
1269
|
-
}
|
|
1270
|
-
},
|
|
1271
|
-
{
|
|
1272
|
-
"s": {
|
|
1273
|
-
"kind": "list",
|
|
1274
|
-
"items": [
|
|
1275
|
-
{
|
|
1276
|
-
"kind": "var",
|
|
1277
|
-
"value": "n"
|
|
1278
|
-
},
|
|
1279
|
-
{
|
|
1280
|
-
"kind": "lit",
|
|
1281
|
-
"value": 1
|
|
1282
|
-
}
|
|
1283
|
-
]
|
|
1284
|
-
},
|
|
1285
|
-
"p": {
|
|
1286
|
-
"kind": "iri",
|
|
1287
|
-
"value": "math:sum"
|
|
1288
|
-
},
|
|
1289
|
-
"o": {
|
|
1290
|
-
"kind": "var",
|
|
1291
|
-
"value": "n1"
|
|
1292
|
-
}
|
|
1293
|
-
},
|
|
1294
|
-
{
|
|
1295
|
-
"s": {
|
|
1296
|
-
"kind": "list",
|
|
1297
|
-
"items": [
|
|
1298
|
-
{
|
|
1299
|
-
"kind": "var",
|
|
1300
|
-
"value": "l"
|
|
1301
|
-
},
|
|
1302
|
-
{
|
|
1303
|
-
"kind": "var",
|
|
1304
|
-
"value": "u"
|
|
1305
|
-
}
|
|
1306
|
-
]
|
|
1307
|
-
},
|
|
1308
|
-
"p": {
|
|
1309
|
-
"kind": "iri",
|
|
1310
|
-
"value": "math:sum"
|
|
1311
|
-
},
|
|
1312
|
-
"o": {
|
|
1313
|
-
"kind": "var",
|
|
1314
|
-
"value": "midNum"
|
|
1315
|
-
}
|
|
1316
|
-
},
|
|
1317
|
-
{
|
|
1318
|
-
"s": {
|
|
1319
|
-
"kind": "list",
|
|
1320
|
-
"items": [
|
|
1321
|
-
{
|
|
1322
|
-
"kind": "var",
|
|
1323
|
-
"value": "midNum"
|
|
1324
|
-
},
|
|
1325
|
-
{
|
|
1326
|
-
"kind": "var",
|
|
1327
|
-
"value": "midNum"
|
|
1328
|
-
}
|
|
1329
|
-
]
|
|
1330
|
-
},
|
|
1331
|
-
"p": {
|
|
1332
|
-
"kind": "iri",
|
|
1333
|
-
"value": "math:product"
|
|
1334
|
-
},
|
|
1335
|
-
"o": {
|
|
1336
|
-
"kind": "var",
|
|
1337
|
-
"value": "midSq"
|
|
1338
|
-
}
|
|
1339
|
-
},
|
|
1340
|
-
{
|
|
1341
|
-
"s": {
|
|
1342
|
-
"kind": "list",
|
|
1343
|
-
"items": [
|
|
1344
|
-
{
|
|
1345
|
-
"kind": "var",
|
|
1346
|
-
"value": "n"
|
|
1347
|
-
},
|
|
1348
|
-
{
|
|
1349
|
-
"kind": "lit",
|
|
1350
|
-
"value": 2
|
|
1351
|
-
}
|
|
1352
|
-
]
|
|
1353
|
-
},
|
|
1354
|
-
"p": {
|
|
1355
|
-
"kind": "iri",
|
|
1356
|
-
"value": "math:product"
|
|
1357
|
-
},
|
|
1358
|
-
"o": {
|
|
1359
|
-
"kind": "var",
|
|
1360
|
-
"value": "twoN"
|
|
1361
|
-
}
|
|
1362
|
-
},
|
|
1363
|
-
{
|
|
1364
|
-
"s": {
|
|
1365
|
-
"kind": "list",
|
|
1366
|
-
"items": [
|
|
1367
|
-
{
|
|
1368
|
-
"kind": "var",
|
|
1369
|
-
"value": "twoN"
|
|
1370
|
-
},
|
|
1371
|
-
{
|
|
1372
|
-
"kind": "lit",
|
|
1373
|
-
"value": 3
|
|
1374
|
-
}
|
|
1375
|
-
]
|
|
1376
|
-
},
|
|
1377
|
-
"p": {
|
|
1378
|
-
"kind": "iri",
|
|
1379
|
-
"value": "math:sum"
|
|
1380
|
-
},
|
|
1381
|
-
"o": {
|
|
1382
|
-
"kind": "var",
|
|
1383
|
-
"value": "exp"
|
|
1384
|
-
}
|
|
1385
|
-
},
|
|
1386
|
-
{
|
|
1387
|
-
"s": {
|
|
1388
|
-
"kind": "list",
|
|
1389
|
-
"items": [
|
|
1390
|
-
{
|
|
1391
|
-
"kind": "lit",
|
|
1392
|
-
"value": 2
|
|
1393
|
-
},
|
|
1394
|
-
{
|
|
1395
|
-
"kind": "var",
|
|
1396
|
-
"value": "exp"
|
|
1397
|
-
}
|
|
1398
|
-
]
|
|
1399
|
-
},
|
|
1400
|
-
"p": {
|
|
1401
|
-
"kind": "iri",
|
|
1402
|
-
"value": "math:exponentiation"
|
|
1403
|
-
},
|
|
1404
|
-
"o": {
|
|
1405
|
-
"kind": "var",
|
|
1406
|
-
"value": "pow"
|
|
1407
|
-
}
|
|
1408
|
-
},
|
|
1409
|
-
{
|
|
1410
|
-
"s": {
|
|
1411
|
-
"kind": "var",
|
|
1412
|
-
"value": "midSq"
|
|
1413
|
-
},
|
|
1414
|
-
"p": {
|
|
1415
|
-
"kind": "iri",
|
|
1416
|
-
"value": "math:lessThan"
|
|
1417
|
-
},
|
|
1418
|
-
"o": {
|
|
1419
|
-
"kind": "var",
|
|
1420
|
-
"value": "pow"
|
|
1421
|
-
}
|
|
1422
|
-
},
|
|
1423
|
-
{
|
|
1424
|
-
"s": {
|
|
1425
|
-
"kind": "list",
|
|
1426
|
-
"items": [
|
|
1427
|
-
{
|
|
1428
|
-
"kind": "lit",
|
|
1429
|
-
"value": 2
|
|
1430
|
-
},
|
|
1431
|
-
{
|
|
1432
|
-
"kind": "var",
|
|
1433
|
-
"value": "u"
|
|
1434
|
-
}
|
|
1435
|
-
]
|
|
1436
|
-
},
|
|
1437
|
-
"p": {
|
|
1438
|
-
"kind": "iri",
|
|
1439
|
-
"value": "math:product"
|
|
1440
|
-
},
|
|
1441
|
-
"o": {
|
|
1442
|
-
"kind": "var",
|
|
1443
|
-
"value": "uScaled"
|
|
1444
|
-
}
|
|
1445
|
-
}
|
|
1446
|
-
],
|
|
1447
|
-
"head": [
|
|
1448
|
-
{
|
|
1449
|
-
"s": {
|
|
1450
|
-
"kind": "iri",
|
|
1451
|
-
"value": ":sqrt2Proc"
|
|
1452
|
-
},
|
|
1453
|
-
"p": {
|
|
1454
|
-
"kind": "iri",
|
|
1455
|
-
"value": ":state"
|
|
1456
|
-
},
|
|
1457
|
-
"o": {
|
|
1458
|
-
"kind": "list",
|
|
1459
|
-
"items": [
|
|
1460
|
-
{
|
|
1461
|
-
"kind": "var",
|
|
1462
|
-
"value": "n1"
|
|
1463
|
-
},
|
|
1464
|
-
{
|
|
1465
|
-
"kind": "var",
|
|
1466
|
-
"value": "midNum"
|
|
1467
|
-
},
|
|
1468
|
-
{
|
|
1469
|
-
"kind": "var",
|
|
1470
|
-
"value": "uScaled"
|
|
1471
|
-
}
|
|
1472
|
-
]
|
|
1473
|
-
}
|
|
1474
|
-
}
|
|
1475
|
-
],
|
|
1476
|
-
"bodyComment": [
|
|
1477
|
-
":sqrt2Proc :state (?n ?l ?u)",
|
|
1478
|
-
":sqrt2Proc :maxN ?maxN",
|
|
1479
|
-
"?n math:lessThan ?maxN",
|
|
1480
|
-
"(?n 1) math:sum ?n1",
|
|
1481
|
-
"(?l ?u) math:sum ?midNum",
|
|
1482
|
-
"(?midNum ?midNum) math:product ?midSq",
|
|
1483
|
-
"(?n 2) math:product ?twoN",
|
|
1484
|
-
"(?twoN 3) math:sum ?exp",
|
|
1485
|
-
"(2 ?exp) math:exponentiation ?pow",
|
|
1486
|
-
"?midSq math:lessThan ?pow",
|
|
1487
|
-
"(2 ?u) math:product ?uScaled"
|
|
1488
|
-
],
|
|
1489
|
-
"headComment": [
|
|
1490
|
-
":sqrt2Proc :state (?n1 ?midNum ?uScaled)"
|
|
1491
|
-
]
|
|
1492
|
-
},
|
|
1493
|
-
{
|
|
1494
|
-
"kind": "rule",
|
|
1495
|
-
"id": 2,
|
|
1496
|
-
"body": [
|
|
1497
|
-
{
|
|
1498
|
-
"s": {
|
|
1499
|
-
"kind": "iri",
|
|
1500
|
-
"value": ":sqrt2Proc"
|
|
1501
|
-
},
|
|
1502
|
-
"p": {
|
|
1503
|
-
"kind": "iri",
|
|
1504
|
-
"value": ":state"
|
|
1505
|
-
},
|
|
1506
|
-
"o": {
|
|
1507
|
-
"kind": "list",
|
|
1508
|
-
"items": [
|
|
1509
|
-
{
|
|
1510
|
-
"kind": "var",
|
|
1511
|
-
"value": "n"
|
|
1512
|
-
},
|
|
1513
|
-
{
|
|
1514
|
-
"kind": "var",
|
|
1515
|
-
"value": "l"
|
|
1516
|
-
},
|
|
1517
|
-
{
|
|
1518
|
-
"kind": "var",
|
|
1519
|
-
"value": "u"
|
|
1520
|
-
}
|
|
1521
|
-
]
|
|
1522
|
-
}
|
|
1523
|
-
},
|
|
1524
|
-
{
|
|
1525
|
-
"s": {
|
|
1526
|
-
"kind": "iri",
|
|
1527
|
-
"value": ":sqrt2Proc"
|
|
1528
|
-
},
|
|
1529
|
-
"p": {
|
|
1530
|
-
"kind": "iri",
|
|
1531
|
-
"value": ":maxN"
|
|
1532
|
-
},
|
|
1533
|
-
"o": {
|
|
1534
|
-
"kind": "var",
|
|
1535
|
-
"value": "maxN"
|
|
1536
|
-
}
|
|
1537
|
-
},
|
|
1538
|
-
{
|
|
1539
|
-
"s": {
|
|
1540
|
-
"kind": "var",
|
|
1541
|
-
"value": "n"
|
|
1542
|
-
},
|
|
1543
|
-
"p": {
|
|
1544
|
-
"kind": "iri",
|
|
1545
|
-
"value": "math:lessThan"
|
|
1546
|
-
},
|
|
1547
|
-
"o": {
|
|
1548
|
-
"kind": "var",
|
|
1549
|
-
"value": "maxN"
|
|
1550
|
-
}
|
|
1551
|
-
},
|
|
1552
|
-
{
|
|
1553
|
-
"s": {
|
|
1554
|
-
"kind": "list",
|
|
1555
|
-
"items": [
|
|
1556
|
-
{
|
|
1557
|
-
"kind": "var",
|
|
1558
|
-
"value": "n"
|
|
1559
|
-
},
|
|
1560
|
-
{
|
|
1561
|
-
"kind": "lit",
|
|
1562
|
-
"value": 1
|
|
1563
|
-
}
|
|
1564
|
-
]
|
|
1565
|
-
},
|
|
1566
|
-
"p": {
|
|
1567
|
-
"kind": "iri",
|
|
1568
|
-
"value": "math:sum"
|
|
1569
|
-
},
|
|
1570
|
-
"o": {
|
|
1571
|
-
"kind": "var",
|
|
1572
|
-
"value": "n1"
|
|
1573
|
-
}
|
|
1574
|
-
},
|
|
1575
|
-
{
|
|
1576
|
-
"s": {
|
|
1577
|
-
"kind": "list",
|
|
1578
|
-
"items": [
|
|
1579
|
-
{
|
|
1580
|
-
"kind": "var",
|
|
1581
|
-
"value": "l"
|
|
1582
|
-
},
|
|
1583
|
-
{
|
|
1584
|
-
"kind": "var",
|
|
1585
|
-
"value": "u"
|
|
1586
|
-
}
|
|
1587
|
-
]
|
|
1588
|
-
},
|
|
1589
|
-
"p": {
|
|
1590
|
-
"kind": "iri",
|
|
1591
|
-
"value": "math:sum"
|
|
1592
|
-
},
|
|
1593
|
-
"o": {
|
|
1594
|
-
"kind": "var",
|
|
1595
|
-
"value": "midNum"
|
|
1596
|
-
}
|
|
1597
|
-
},
|
|
1598
|
-
{
|
|
1599
|
-
"s": {
|
|
1600
|
-
"kind": "list",
|
|
1601
|
-
"items": [
|
|
1602
|
-
{
|
|
1603
|
-
"kind": "var",
|
|
1604
|
-
"value": "midNum"
|
|
1605
|
-
},
|
|
1606
|
-
{
|
|
1607
|
-
"kind": "var",
|
|
1608
|
-
"value": "midNum"
|
|
1609
|
-
}
|
|
1610
|
-
]
|
|
1611
|
-
},
|
|
1612
|
-
"p": {
|
|
1613
|
-
"kind": "iri",
|
|
1614
|
-
"value": "math:product"
|
|
1615
|
-
},
|
|
1616
|
-
"o": {
|
|
1617
|
-
"kind": "var",
|
|
1618
|
-
"value": "midSq"
|
|
1619
|
-
}
|
|
1620
|
-
},
|
|
1621
|
-
{
|
|
1622
|
-
"s": {
|
|
1623
|
-
"kind": "list",
|
|
1624
|
-
"items": [
|
|
1625
|
-
{
|
|
1626
|
-
"kind": "var",
|
|
1627
|
-
"value": "n"
|
|
1628
|
-
},
|
|
1629
|
-
{
|
|
1630
|
-
"kind": "lit",
|
|
1631
|
-
"value": 2
|
|
1632
|
-
}
|
|
1633
|
-
]
|
|
1634
|
-
},
|
|
1635
|
-
"p": {
|
|
1636
|
-
"kind": "iri",
|
|
1637
|
-
"value": "math:product"
|
|
1638
|
-
},
|
|
1639
|
-
"o": {
|
|
1640
|
-
"kind": "var",
|
|
1641
|
-
"value": "twoN"
|
|
1642
|
-
}
|
|
1643
|
-
},
|
|
1644
|
-
{
|
|
1645
|
-
"s": {
|
|
1646
|
-
"kind": "list",
|
|
1647
|
-
"items": [
|
|
1648
|
-
{
|
|
1649
|
-
"kind": "var",
|
|
1650
|
-
"value": "twoN"
|
|
1651
|
-
},
|
|
1652
|
-
{
|
|
1653
|
-
"kind": "lit",
|
|
1654
|
-
"value": 3
|
|
1655
|
-
}
|
|
1656
|
-
]
|
|
1657
|
-
},
|
|
1658
|
-
"p": {
|
|
1659
|
-
"kind": "iri",
|
|
1660
|
-
"value": "math:sum"
|
|
1661
|
-
},
|
|
1662
|
-
"o": {
|
|
1663
|
-
"kind": "var",
|
|
1664
|
-
"value": "exp"
|
|
1665
|
-
}
|
|
1666
|
-
},
|
|
1667
|
-
{
|
|
1668
|
-
"s": {
|
|
1669
|
-
"kind": "list",
|
|
1670
|
-
"items": [
|
|
1671
|
-
{
|
|
1672
|
-
"kind": "lit",
|
|
1673
|
-
"value": 2
|
|
1674
|
-
},
|
|
1675
|
-
{
|
|
1676
|
-
"kind": "var",
|
|
1677
|
-
"value": "exp"
|
|
1678
|
-
}
|
|
1679
|
-
]
|
|
1680
|
-
},
|
|
1681
|
-
"p": {
|
|
1682
|
-
"kind": "iri",
|
|
1683
|
-
"value": "math:exponentiation"
|
|
1684
|
-
},
|
|
1685
|
-
"o": {
|
|
1686
|
-
"kind": "var",
|
|
1687
|
-
"value": "pow"
|
|
1688
|
-
}
|
|
1689
|
-
},
|
|
1690
|
-
{
|
|
1691
|
-
"s": {
|
|
1692
|
-
"kind": "var",
|
|
1693
|
-
"value": "midSq"
|
|
1694
|
-
},
|
|
1695
|
-
"p": {
|
|
1696
|
-
"kind": "iri",
|
|
1697
|
-
"value": "math:notLessThan"
|
|
1698
|
-
},
|
|
1699
|
-
"o": {
|
|
1700
|
-
"kind": "var",
|
|
1701
|
-
"value": "pow"
|
|
1702
|
-
}
|
|
1703
|
-
},
|
|
1704
|
-
{
|
|
1705
|
-
"s": {
|
|
1706
|
-
"kind": "list",
|
|
1707
|
-
"items": [
|
|
1708
|
-
{
|
|
1709
|
-
"kind": "lit",
|
|
1710
|
-
"value": 2
|
|
1711
|
-
},
|
|
1712
|
-
{
|
|
1713
|
-
"kind": "var",
|
|
1714
|
-
"value": "l"
|
|
1715
|
-
}
|
|
1716
|
-
]
|
|
1717
|
-
},
|
|
1718
|
-
"p": {
|
|
1719
|
-
"kind": "iri",
|
|
1720
|
-
"value": "math:product"
|
|
1721
|
-
},
|
|
1722
|
-
"o": {
|
|
1723
|
-
"kind": "var",
|
|
1724
|
-
"value": "lScaled"
|
|
1725
|
-
}
|
|
1726
|
-
}
|
|
1727
|
-
],
|
|
1728
|
-
"head": [
|
|
1729
|
-
{
|
|
1730
|
-
"s": {
|
|
1731
|
-
"kind": "iri",
|
|
1732
|
-
"value": ":sqrt2Proc"
|
|
1733
|
-
},
|
|
1734
|
-
"p": {
|
|
1735
|
-
"kind": "iri",
|
|
1736
|
-
"value": ":state"
|
|
1737
|
-
},
|
|
1738
|
-
"o": {
|
|
1739
|
-
"kind": "list",
|
|
1740
|
-
"items": [
|
|
1741
|
-
{
|
|
1742
|
-
"kind": "var",
|
|
1743
|
-
"value": "n1"
|
|
1744
|
-
},
|
|
1745
|
-
{
|
|
1746
|
-
"kind": "var",
|
|
1747
|
-
"value": "lScaled"
|
|
1748
|
-
},
|
|
1749
|
-
{
|
|
1750
|
-
"kind": "var",
|
|
1751
|
-
"value": "midNum"
|
|
1752
|
-
}
|
|
1753
|
-
]
|
|
1754
|
-
}
|
|
1755
|
-
}
|
|
1756
|
-
],
|
|
1757
|
-
"bodyComment": [
|
|
1758
|
-
":sqrt2Proc :state (?n ?l ?u)",
|
|
1759
|
-
":sqrt2Proc :maxN ?maxN",
|
|
1760
|
-
"?n math:lessThan ?maxN",
|
|
1761
|
-
"(?n 1) math:sum ?n1",
|
|
1762
|
-
"(?l ?u) math:sum ?midNum",
|
|
1763
|
-
"(?midNum ?midNum) math:product ?midSq",
|
|
1764
|
-
"(?n 2) math:product ?twoN",
|
|
1765
|
-
"(?twoN 3) math:sum ?exp",
|
|
1766
|
-
"(2 ?exp) math:exponentiation ?pow",
|
|
1767
|
-
"?midSq math:notLessThan ?pow",
|
|
1768
|
-
"(2 ?l) math:product ?lScaled"
|
|
1769
|
-
],
|
|
1770
|
-
"headComment": [
|
|
1771
|
-
":sqrt2Proc :state (?n1 ?lScaled ?midNum)"
|
|
1772
|
-
]
|
|
1773
|
-
},
|
|
1774
|
-
{
|
|
1775
|
-
"kind": "rule",
|
|
1776
|
-
"id": 3,
|
|
1777
|
-
"body": [
|
|
1778
|
-
{
|
|
1779
|
-
"s": {
|
|
1780
|
-
"kind": "iri",
|
|
1781
|
-
"value": ":sqrt2Proc"
|
|
1782
|
-
},
|
|
1783
|
-
"p": {
|
|
1784
|
-
"kind": "iri",
|
|
1785
|
-
"value": ":state"
|
|
1786
|
-
},
|
|
1787
|
-
"o": {
|
|
1788
|
-
"kind": "list",
|
|
1789
|
-
"items": [
|
|
1790
|
-
{
|
|
1791
|
-
"kind": "var",
|
|
1792
|
-
"value": "n"
|
|
1793
|
-
},
|
|
1794
|
-
{
|
|
1795
|
-
"kind": "var",
|
|
1796
|
-
"value": "l"
|
|
1797
|
-
},
|
|
1798
|
-
{
|
|
1799
|
-
"kind": "var",
|
|
1800
|
-
"value": "u"
|
|
1801
|
-
}
|
|
1802
|
-
]
|
|
1803
|
-
}
|
|
1804
|
-
},
|
|
1805
|
-
{
|
|
1806
|
-
"s": {
|
|
1807
|
-
"kind": "list",
|
|
1808
|
-
"items": [
|
|
1809
|
-
{
|
|
1810
|
-
"kind": "lit",
|
|
1811
|
-
"value": 2
|
|
1812
|
-
},
|
|
1813
|
-
{
|
|
1814
|
-
"kind": "var",
|
|
1815
|
-
"value": "n"
|
|
1816
|
-
}
|
|
1817
|
-
]
|
|
1818
|
-
},
|
|
1819
|
-
"p": {
|
|
1820
|
-
"kind": "iri",
|
|
1821
|
-
"value": "math:exponentiation"
|
|
1822
|
-
},
|
|
1823
|
-
"o": {
|
|
1824
|
-
"kind": "var",
|
|
1825
|
-
"value": "denom"
|
|
1826
|
-
}
|
|
1827
|
-
},
|
|
1828
|
-
{
|
|
1829
|
-
"s": {
|
|
1830
|
-
"kind": "list",
|
|
1831
|
-
"items": [
|
|
1832
|
-
{
|
|
1833
|
-
"kind": "var",
|
|
1834
|
-
"value": "l"
|
|
1835
|
-
},
|
|
1836
|
-
{
|
|
1837
|
-
"kind": "var",
|
|
1838
|
-
"value": "denom"
|
|
1839
|
-
}
|
|
1840
|
-
]
|
|
1841
|
-
},
|
|
1842
|
-
"p": {
|
|
1843
|
-
"kind": "iri",
|
|
1844
|
-
"value": "math:quotient"
|
|
1845
|
-
},
|
|
1846
|
-
"o": {
|
|
1847
|
-
"kind": "var",
|
|
1848
|
-
"value": "L"
|
|
1849
|
-
}
|
|
1850
|
-
},
|
|
1851
|
-
{
|
|
1852
|
-
"s": {
|
|
1853
|
-
"kind": "list",
|
|
1854
|
-
"items": [
|
|
1855
|
-
{
|
|
1856
|
-
"kind": "var",
|
|
1857
|
-
"value": "u"
|
|
1858
|
-
},
|
|
1859
|
-
{
|
|
1860
|
-
"kind": "var",
|
|
1861
|
-
"value": "denom"
|
|
1862
|
-
}
|
|
1863
|
-
]
|
|
1864
|
-
},
|
|
1865
|
-
"p": {
|
|
1866
|
-
"kind": "iri",
|
|
1867
|
-
"value": "math:quotient"
|
|
1868
|
-
},
|
|
1869
|
-
"o": {
|
|
1870
|
-
"kind": "var",
|
|
1871
|
-
"value": "U"
|
|
1872
|
-
}
|
|
1873
|
-
}
|
|
1874
|
-
],
|
|
1875
|
-
"head": [
|
|
1876
|
-
{
|
|
1877
|
-
"s": {
|
|
1878
|
-
"kind": "iri",
|
|
1879
|
-
"value": ":sqrt2Proc"
|
|
1880
|
-
},
|
|
1881
|
-
"p": {
|
|
1882
|
-
"kind": "iri",
|
|
1883
|
-
"value": ":dyadic"
|
|
1884
|
-
},
|
|
1885
|
-
"o": {
|
|
1886
|
-
"kind": "list",
|
|
1887
|
-
"items": [
|
|
1888
|
-
{
|
|
1889
|
-
"kind": "var",
|
|
1890
|
-
"value": "n"
|
|
1891
|
-
},
|
|
1892
|
-
{
|
|
1893
|
-
"kind": "var",
|
|
1894
|
-
"value": "l"
|
|
1895
|
-
},
|
|
1896
|
-
{
|
|
1897
|
-
"kind": "var",
|
|
1898
|
-
"value": "u"
|
|
1899
|
-
},
|
|
1900
|
-
{
|
|
1901
|
-
"kind": "var",
|
|
1902
|
-
"value": "denom"
|
|
1903
|
-
}
|
|
1904
|
-
]
|
|
1905
|
-
}
|
|
1906
|
-
},
|
|
1907
|
-
{
|
|
1908
|
-
"s": {
|
|
1909
|
-
"kind": "iri",
|
|
1910
|
-
"value": ":sqrt2Proc"
|
|
1911
|
-
},
|
|
1912
|
-
"p": {
|
|
1913
|
-
"kind": "iri",
|
|
1914
|
-
"value": ":bounds"
|
|
1915
|
-
},
|
|
1916
|
-
"o": {
|
|
1917
|
-
"kind": "list",
|
|
1918
|
-
"items": [
|
|
1919
|
-
{
|
|
1920
|
-
"kind": "var",
|
|
1921
|
-
"value": "n"
|
|
1922
|
-
},
|
|
1923
|
-
{
|
|
1924
|
-
"kind": "var",
|
|
1925
|
-
"value": "L"
|
|
1926
|
-
},
|
|
1927
|
-
{
|
|
1928
|
-
"kind": "var",
|
|
1929
|
-
"value": "U"
|
|
1930
|
-
}
|
|
1931
|
-
]
|
|
1932
|
-
}
|
|
1933
|
-
}
|
|
1934
|
-
],
|
|
1935
|
-
"bodyComment": [
|
|
1936
|
-
":sqrt2Proc :state (?n ?l ?u)",
|
|
1937
|
-
"(2 ?n) math:exponentiation ?denom",
|
|
1938
|
-
"(?l ?denom) math:quotient ?L",
|
|
1939
|
-
"(?u ?denom) math:quotient ?U"
|
|
1940
|
-
],
|
|
1941
|
-
"headComment": [
|
|
1942
|
-
":sqrt2Proc :dyadic (?n ?l ?u ?denom)",
|
|
1943
|
-
":sqrt2Proc :bounds (?n ?L ?U)"
|
|
1944
|
-
]
|
|
1945
|
-
},
|
|
1946
|
-
{
|
|
1947
|
-
"kind": "rule",
|
|
1948
|
-
"id": 4,
|
|
1949
|
-
"body": [
|
|
1950
|
-
{
|
|
1951
|
-
"s": {
|
|
1952
|
-
"kind": "iri",
|
|
1953
|
-
"value": ":sqrt2Proc"
|
|
1954
|
-
},
|
|
1955
|
-
"p": {
|
|
1956
|
-
"kind": "iri",
|
|
1957
|
-
"value": ":dyadic"
|
|
1958
|
-
},
|
|
1959
|
-
"o": {
|
|
1960
|
-
"kind": "list",
|
|
1961
|
-
"items": [
|
|
1962
|
-
{
|
|
1963
|
-
"kind": "var",
|
|
1964
|
-
"value": "n"
|
|
1965
|
-
},
|
|
1966
|
-
{
|
|
1967
|
-
"kind": "var",
|
|
1968
|
-
"value": "l"
|
|
1969
|
-
},
|
|
1970
|
-
{
|
|
1971
|
-
"kind": "var",
|
|
1972
|
-
"value": "u"
|
|
1973
|
-
},
|
|
1974
|
-
{
|
|
1975
|
-
"kind": "var",
|
|
1976
|
-
"value": "denom"
|
|
1977
|
-
}
|
|
1978
|
-
]
|
|
1979
|
-
}
|
|
1980
|
-
},
|
|
1981
|
-
{
|
|
1982
|
-
"s": {
|
|
1983
|
-
"kind": "list",
|
|
1984
|
-
"items": [
|
|
1985
|
-
{
|
|
1986
|
-
"kind": "var",
|
|
1987
|
-
"value": "denom"
|
|
1988
|
-
},
|
|
1989
|
-
{
|
|
1990
|
-
"kind": "var",
|
|
1991
|
-
"value": "u"
|
|
1992
|
-
}
|
|
1993
|
-
]
|
|
1994
|
-
},
|
|
1995
|
-
"p": {
|
|
1996
|
-
"kind": "iri",
|
|
1997
|
-
"value": "math:quotient"
|
|
1998
|
-
},
|
|
1999
|
-
"o": {
|
|
2000
|
-
"kind": "var",
|
|
2001
|
-
"value": "sL"
|
|
2002
|
-
}
|
|
2003
|
-
},
|
|
2004
|
-
{
|
|
2005
|
-
"s": {
|
|
2006
|
-
"kind": "list",
|
|
2007
|
-
"items": [
|
|
2008
|
-
{
|
|
2009
|
-
"kind": "var",
|
|
2010
|
-
"value": "denom"
|
|
2011
|
-
},
|
|
2012
|
-
{
|
|
2013
|
-
"kind": "var",
|
|
2014
|
-
"value": "l"
|
|
2015
|
-
}
|
|
2016
|
-
]
|
|
2017
|
-
},
|
|
2018
|
-
"p": {
|
|
2019
|
-
"kind": "iri",
|
|
2020
|
-
"value": "math:quotient"
|
|
2021
|
-
},
|
|
2022
|
-
"o": {
|
|
2023
|
-
"kind": "var",
|
|
2024
|
-
"value": "sU"
|
|
2025
|
-
}
|
|
2026
|
-
}
|
|
2027
|
-
],
|
|
2028
|
-
"head": [
|
|
2029
|
-
{
|
|
2030
|
-
"s": {
|
|
2031
|
-
"kind": "iri",
|
|
2032
|
-
"value": ":invSqrt2"
|
|
2033
|
-
},
|
|
2034
|
-
"p": {
|
|
2035
|
-
"kind": "iri",
|
|
2036
|
-
"value": ":bounds"
|
|
2037
|
-
},
|
|
2038
|
-
"o": {
|
|
2039
|
-
"kind": "list",
|
|
2040
|
-
"items": [
|
|
2041
|
-
{
|
|
2042
|
-
"kind": "var",
|
|
2043
|
-
"value": "n"
|
|
2044
|
-
},
|
|
2045
|
-
{
|
|
2046
|
-
"kind": "var",
|
|
2047
|
-
"value": "sL"
|
|
2048
|
-
},
|
|
2049
|
-
{
|
|
2050
|
-
"kind": "var",
|
|
2051
|
-
"value": "sU"
|
|
2052
|
-
}
|
|
2053
|
-
]
|
|
2054
|
-
}
|
|
2055
|
-
}
|
|
2056
|
-
],
|
|
2057
|
-
"bodyComment": [
|
|
2058
|
-
":sqrt2Proc :dyadic (?n ?l ?u ?denom)",
|
|
2059
|
-
"(?denom ?u) math:quotient ?sL",
|
|
2060
|
-
"(?denom ?l) math:quotient ?sU"
|
|
2061
|
-
],
|
|
2062
|
-
"headComment": [
|
|
2063
|
-
":invSqrt2 :bounds (?n ?sL ?sU)"
|
|
2064
|
-
]
|
|
2065
|
-
},
|
|
2066
|
-
{
|
|
2067
|
-
"kind": "rule",
|
|
2068
|
-
"id": 5,
|
|
2069
|
-
"body": [
|
|
2070
|
-
{
|
|
2071
|
-
"s": {
|
|
2072
|
-
"kind": "iri",
|
|
2073
|
-
"value": ":invSqrt2"
|
|
2074
|
-
},
|
|
2075
|
-
"p": {
|
|
2076
|
-
"kind": "iri",
|
|
2077
|
-
"value": ":bounds"
|
|
2078
|
-
},
|
|
2079
|
-
"o": {
|
|
2080
|
-
"kind": "list",
|
|
2081
|
-
"items": [
|
|
2082
|
-
{
|
|
2083
|
-
"kind": "var",
|
|
2084
|
-
"value": "n"
|
|
2085
|
-
},
|
|
2086
|
-
{
|
|
2087
|
-
"kind": "var",
|
|
2088
|
-
"value": "sL"
|
|
2089
|
-
},
|
|
2090
|
-
{
|
|
2091
|
-
"kind": "var",
|
|
2092
|
-
"value": "sU"
|
|
2093
|
-
}
|
|
2094
|
-
]
|
|
2095
|
-
}
|
|
2096
|
-
},
|
|
2097
|
-
{
|
|
2098
|
-
"s": {
|
|
2099
|
-
"kind": "list",
|
|
2100
|
-
"items": [
|
|
2101
|
-
{
|
|
2102
|
-
"kind": "var",
|
|
2103
|
-
"value": "sU"
|
|
2104
|
-
},
|
|
2105
|
-
{
|
|
2106
|
-
"kind": "var",
|
|
2107
|
-
"value": "sL"
|
|
2108
|
-
}
|
|
2109
|
-
]
|
|
2110
|
-
},
|
|
2111
|
-
"p": {
|
|
2112
|
-
"kind": "iri",
|
|
2113
|
-
"value": "math:difference"
|
|
2114
|
-
},
|
|
2115
|
-
"o": {
|
|
2116
|
-
"kind": "var",
|
|
2117
|
-
"value": "sW"
|
|
2118
|
-
}
|
|
2119
|
-
},
|
|
2120
|
-
{
|
|
2121
|
-
"s": {
|
|
2122
|
-
"kind": "list",
|
|
2123
|
-
"items": [
|
|
2124
|
-
{
|
|
2125
|
-
"kind": "var",
|
|
2126
|
-
"value": "sW"
|
|
2127
|
-
},
|
|
2128
|
-
{
|
|
2129
|
-
"kind": "lit",
|
|
2130
|
-
"value": 2
|
|
2131
|
-
}
|
|
2132
|
-
]
|
|
2133
|
-
},
|
|
2134
|
-
"p": {
|
|
2135
|
-
"kind": "iri",
|
|
2136
|
-
"value": "math:quotient"
|
|
2137
|
-
},
|
|
2138
|
-
"o": {
|
|
2139
|
-
"kind": "var",
|
|
2140
|
-
"value": "compErr"
|
|
2141
|
-
}
|
|
2142
|
-
},
|
|
2143
|
-
{
|
|
2144
|
-
"s": {
|
|
2145
|
-
"kind": "list",
|
|
2146
|
-
"items": [
|
|
2147
|
-
{
|
|
2148
|
-
"kind": "var",
|
|
2149
|
-
"value": "sL"
|
|
2150
|
-
},
|
|
2151
|
-
{
|
|
2152
|
-
"kind": "var",
|
|
2153
|
-
"value": "sU"
|
|
2154
|
-
}
|
|
2155
|
-
]
|
|
2156
|
-
},
|
|
2157
|
-
"p": {
|
|
2158
|
-
"kind": "iri",
|
|
2159
|
-
"value": "math:sum"
|
|
2160
|
-
},
|
|
2161
|
-
"o": {
|
|
2162
|
-
"kind": "var",
|
|
2163
|
-
"value": "sSum"
|
|
2164
|
-
}
|
|
2165
|
-
},
|
|
2166
|
-
{
|
|
2167
|
-
"s": {
|
|
2168
|
-
"kind": "list",
|
|
2169
|
-
"items": [
|
|
2170
|
-
{
|
|
2171
|
-
"kind": "var",
|
|
2172
|
-
"value": "sSum"
|
|
2173
|
-
},
|
|
2174
|
-
{
|
|
2175
|
-
"kind": "lit",
|
|
2176
|
-
"value": 2
|
|
2177
|
-
}
|
|
2178
|
-
]
|
|
2179
|
-
},
|
|
2180
|
-
"p": {
|
|
2181
|
-
"kind": "iri",
|
|
2182
|
-
"value": "math:quotient"
|
|
2183
|
-
},
|
|
2184
|
-
"o": {
|
|
2185
|
-
"kind": "var",
|
|
2186
|
-
"value": "m"
|
|
2187
|
-
}
|
|
2188
|
-
},
|
|
2189
|
-
{
|
|
2190
|
-
"s": {
|
|
2191
|
-
"kind": "list",
|
|
2192
|
-
"items": [
|
|
2193
|
-
{
|
|
2194
|
-
"kind": "lit",
|
|
2195
|
-
"value": 0
|
|
2196
|
-
},
|
|
2197
|
-
{
|
|
2198
|
-
"kind": "var",
|
|
2199
|
-
"value": "sU"
|
|
2200
|
-
}
|
|
2201
|
-
]
|
|
2202
|
-
},
|
|
2203
|
-
"p": {
|
|
2204
|
-
"kind": "iri",
|
|
2205
|
-
"value": "math:difference"
|
|
2206
|
-
},
|
|
2207
|
-
"o": {
|
|
2208
|
-
"kind": "var",
|
|
2209
|
-
"value": "negL"
|
|
2210
|
-
}
|
|
2211
|
-
},
|
|
2212
|
-
{
|
|
2213
|
-
"s": {
|
|
2214
|
-
"kind": "list",
|
|
2215
|
-
"items": [
|
|
2216
|
-
{
|
|
2217
|
-
"kind": "lit",
|
|
2218
|
-
"value": 0
|
|
2219
|
-
},
|
|
2220
|
-
{
|
|
2221
|
-
"kind": "var",
|
|
2222
|
-
"value": "sL"
|
|
2223
|
-
}
|
|
2224
|
-
]
|
|
2225
|
-
},
|
|
2226
|
-
"p": {
|
|
2227
|
-
"kind": "iri",
|
|
2228
|
-
"value": "math:difference"
|
|
2229
|
-
},
|
|
2230
|
-
"o": {
|
|
2231
|
-
"kind": "var",
|
|
2232
|
-
"value": "negU"
|
|
2233
|
-
}
|
|
2234
|
-
},
|
|
2235
|
-
{
|
|
2236
|
-
"s": {
|
|
2237
|
-
"kind": "list",
|
|
2238
|
-
"items": [
|
|
2239
|
-
{
|
|
2240
|
-
"kind": "lit",
|
|
2241
|
-
"value": 0
|
|
2242
|
-
},
|
|
2243
|
-
{
|
|
2244
|
-
"kind": "var",
|
|
2245
|
-
"value": "m"
|
|
2246
|
-
}
|
|
2247
|
-
]
|
|
2248
|
-
},
|
|
2249
|
-
"p": {
|
|
2250
|
-
"kind": "iri",
|
|
2251
|
-
"value": "math:difference"
|
|
2252
|
-
},
|
|
2253
|
-
"o": {
|
|
2254
|
-
"kind": "var",
|
|
2255
|
-
"value": "negM"
|
|
2256
|
-
}
|
|
2257
|
-
}
|
|
2258
|
-
],
|
|
2259
|
-
"head": [
|
|
2260
|
-
{
|
|
2261
|
-
"s": {
|
|
2262
|
-
"kind": "iri",
|
|
2263
|
-
"value": ":invSqrt2"
|
|
2264
|
-
},
|
|
2265
|
-
"p": {
|
|
2266
|
-
"kind": "iri",
|
|
2267
|
-
"value": ":width"
|
|
2268
|
-
},
|
|
2269
|
-
"o": {
|
|
2270
|
-
"kind": "list",
|
|
2271
|
-
"items": [
|
|
2272
|
-
{
|
|
2273
|
-
"kind": "var",
|
|
2274
|
-
"value": "n"
|
|
2275
|
-
},
|
|
2276
|
-
{
|
|
2277
|
-
"kind": "var",
|
|
2278
|
-
"value": "sW"
|
|
2279
|
-
}
|
|
2280
|
-
]
|
|
2281
|
-
}
|
|
2282
|
-
},
|
|
2283
|
-
{
|
|
2284
|
-
"s": {
|
|
2285
|
-
"kind": "iri",
|
|
2286
|
-
"value": ":invSqrt2"
|
|
2287
|
-
},
|
|
2288
|
-
"p": {
|
|
2289
|
-
"kind": "iri",
|
|
2290
|
-
"value": ":componentErrBound"
|
|
2291
|
-
},
|
|
2292
|
-
"o": {
|
|
2293
|
-
"kind": "list",
|
|
2294
|
-
"items": [
|
|
2295
|
-
{
|
|
2296
|
-
"kind": "var",
|
|
2297
|
-
"value": "n"
|
|
2298
|
-
},
|
|
2299
|
-
{
|
|
2300
|
-
"kind": "var",
|
|
2301
|
-
"value": "compErr"
|
|
2302
|
-
}
|
|
2303
|
-
]
|
|
2304
|
-
}
|
|
2305
|
-
},
|
|
2306
|
-
{
|
|
2307
|
-
"s": {
|
|
2308
|
-
"kind": "iri",
|
|
2309
|
-
"value": ":invSqrt2"
|
|
2310
|
-
},
|
|
2311
|
-
"p": {
|
|
2312
|
-
"kind": "iri",
|
|
2313
|
-
"value": ":midpoint"
|
|
2314
|
-
},
|
|
2315
|
-
"o": {
|
|
2316
|
-
"kind": "list",
|
|
2317
|
-
"items": [
|
|
2318
|
-
{
|
|
2319
|
-
"kind": "var",
|
|
2320
|
-
"value": "n"
|
|
2321
|
-
},
|
|
2322
|
-
{
|
|
2323
|
-
"kind": "var",
|
|
2324
|
-
"value": "m"
|
|
2325
|
-
}
|
|
2326
|
-
]
|
|
2327
|
-
}
|
|
2328
|
-
},
|
|
2329
|
-
{
|
|
2330
|
-
"s": {
|
|
2331
|
-
"kind": "iri",
|
|
2332
|
-
"value": ":invSqrt2"
|
|
2333
|
-
},
|
|
2334
|
-
"p": {
|
|
2335
|
-
"kind": "iri",
|
|
2336
|
-
"value": ":negBounds"
|
|
2337
|
-
},
|
|
2338
|
-
"o": {
|
|
2339
|
-
"kind": "list",
|
|
2340
|
-
"items": [
|
|
2341
|
-
{
|
|
2342
|
-
"kind": "var",
|
|
2343
|
-
"value": "n"
|
|
2344
|
-
},
|
|
2345
|
-
{
|
|
2346
|
-
"kind": "var",
|
|
2347
|
-
"value": "negL"
|
|
2348
|
-
},
|
|
2349
|
-
{
|
|
2350
|
-
"kind": "var",
|
|
2351
|
-
"value": "negU"
|
|
2352
|
-
}
|
|
2353
|
-
]
|
|
2354
|
-
}
|
|
2355
|
-
},
|
|
2356
|
-
{
|
|
2357
|
-
"s": {
|
|
2358
|
-
"kind": "iri",
|
|
2359
|
-
"value": ":invSqrt2"
|
|
2360
|
-
},
|
|
2361
|
-
"p": {
|
|
2362
|
-
"kind": "iri",
|
|
2363
|
-
"value": ":negMidpoint"
|
|
2364
|
-
},
|
|
2365
|
-
"o": {
|
|
2366
|
-
"kind": "list",
|
|
2367
|
-
"items": [
|
|
2368
|
-
{
|
|
2369
|
-
"kind": "var",
|
|
2370
|
-
"value": "n"
|
|
2371
|
-
},
|
|
2372
|
-
{
|
|
2373
|
-
"kind": "var",
|
|
2374
|
-
"value": "negM"
|
|
2375
|
-
}
|
|
2376
|
-
]
|
|
2377
|
-
}
|
|
2378
|
-
}
|
|
2379
|
-
],
|
|
2380
|
-
"bodyComment": [
|
|
2381
|
-
":invSqrt2 :bounds (?n ?sL ?sU)",
|
|
2382
|
-
"(?sU ?sL) math:difference ?sW",
|
|
2383
|
-
"(?sW 2) math:quotient ?compErr",
|
|
2384
|
-
"(?sL ?sU) math:sum ?sSum",
|
|
2385
|
-
"(?sSum 2) math:quotient ?m",
|
|
2386
|
-
"(0 ?sU) math:difference ?negL",
|
|
2387
|
-
"(0 ?sL) math:difference ?negU",
|
|
2388
|
-
"(0 ?m) math:difference ?negM"
|
|
2389
|
-
],
|
|
2390
|
-
"headComment": [
|
|
2391
|
-
":invSqrt2 :width (?n ?sW)",
|
|
2392
|
-
":invSqrt2 :componentErrBound (?n ?compErr)",
|
|
2393
|
-
":invSqrt2 :midpoint (?n ?m)",
|
|
2394
|
-
":invSqrt2 :negBounds (?n ?negL ?negU)",
|
|
2395
|
-
":invSqrt2 :negMidpoint (?n ?negM)"
|
|
2396
|
-
]
|
|
2397
|
-
},
|
|
2398
|
-
{
|
|
2399
|
-
"kind": "rule",
|
|
2400
|
-
"id": 6,
|
|
2401
|
-
"body": [
|
|
2402
|
-
{
|
|
2403
|
-
"s": {
|
|
2404
|
-
"kind": "iri",
|
|
2405
|
-
"value": ":invSqrt2"
|
|
2406
|
-
},
|
|
2407
|
-
"p": {
|
|
2408
|
-
"kind": "iri",
|
|
2409
|
-
"value": ":bounds"
|
|
2410
|
-
},
|
|
2411
|
-
"o": {
|
|
2412
|
-
"kind": "list",
|
|
2413
|
-
"items": [
|
|
2414
|
-
{
|
|
2415
|
-
"kind": "var",
|
|
2416
|
-
"value": "n"
|
|
2417
|
-
},
|
|
2418
|
-
{
|
|
2419
|
-
"kind": "var",
|
|
2420
|
-
"value": "sL"
|
|
2421
|
-
},
|
|
2422
|
-
{
|
|
2423
|
-
"kind": "var",
|
|
2424
|
-
"value": "sU"
|
|
2425
|
-
}
|
|
2426
|
-
]
|
|
2427
|
-
}
|
|
2428
|
-
},
|
|
2429
|
-
{
|
|
2430
|
-
"s": {
|
|
2431
|
-
"kind": "iri",
|
|
2432
|
-
"value": ":invSqrt2"
|
|
2433
|
-
},
|
|
2434
|
-
"p": {
|
|
2435
|
-
"kind": "iri",
|
|
2436
|
-
"value": ":negBounds"
|
|
2437
|
-
},
|
|
2438
|
-
"o": {
|
|
2439
|
-
"kind": "list",
|
|
2440
|
-
"items": [
|
|
2441
|
-
{
|
|
2442
|
-
"kind": "var",
|
|
2443
|
-
"value": "n"
|
|
2444
|
-
},
|
|
2445
|
-
{
|
|
2446
|
-
"kind": "var",
|
|
2447
|
-
"value": "negL"
|
|
2448
|
-
},
|
|
2449
|
-
{
|
|
2450
|
-
"kind": "var",
|
|
2451
|
-
"value": "negU"
|
|
2452
|
-
}
|
|
2453
|
-
]
|
|
2454
|
-
}
|
|
2455
|
-
}
|
|
2456
|
-
],
|
|
2457
|
-
"head": [
|
|
2458
|
-
{
|
|
2459
|
-
"s": {
|
|
2460
|
-
"kind": "iri",
|
|
2461
|
-
"value": ":HGate"
|
|
2462
|
-
},
|
|
2463
|
-
"p": {
|
|
2464
|
-
"kind": "iri",
|
|
2465
|
-
"value": ":entry"
|
|
2466
|
-
},
|
|
2467
|
-
"o": {
|
|
2468
|
-
"kind": "list",
|
|
2469
|
-
"items": [
|
|
2470
|
-
{
|
|
2471
|
-
"kind": "var",
|
|
2472
|
-
"value": "n"
|
|
2473
|
-
},
|
|
2474
|
-
{
|
|
2475
|
-
"kind": "lit",
|
|
2476
|
-
"value": 0
|
|
2477
|
-
},
|
|
2478
|
-
{
|
|
2479
|
-
"kind": "lit",
|
|
2480
|
-
"value": 0
|
|
2481
|
-
},
|
|
2482
|
-
{
|
|
2483
|
-
"kind": "var",
|
|
2484
|
-
"value": "sL"
|
|
2485
|
-
},
|
|
2486
|
-
{
|
|
2487
|
-
"kind": "var",
|
|
2488
|
-
"value": "sU"
|
|
2489
|
-
},
|
|
2490
|
-
{
|
|
2491
|
-
"kind": "lit",
|
|
2492
|
-
"value": 0
|
|
2493
|
-
},
|
|
2494
|
-
{
|
|
2495
|
-
"kind": "lit",
|
|
2496
|
-
"value": 0
|
|
2497
|
-
}
|
|
2498
|
-
]
|
|
2499
|
-
}
|
|
2500
|
-
},
|
|
2501
|
-
{
|
|
2502
|
-
"s": {
|
|
2503
|
-
"kind": "iri",
|
|
2504
|
-
"value": ":HGate"
|
|
2505
|
-
},
|
|
2506
|
-
"p": {
|
|
2507
|
-
"kind": "iri",
|
|
2508
|
-
"value": ":entry"
|
|
2509
|
-
},
|
|
2510
|
-
"o": {
|
|
2511
|
-
"kind": "list",
|
|
2512
|
-
"items": [
|
|
2513
|
-
{
|
|
2514
|
-
"kind": "var",
|
|
2515
|
-
"value": "n"
|
|
2516
|
-
},
|
|
2517
|
-
{
|
|
2518
|
-
"kind": "lit",
|
|
2519
|
-
"value": 0
|
|
2520
|
-
},
|
|
2521
|
-
{
|
|
2522
|
-
"kind": "lit",
|
|
2523
|
-
"value": 1
|
|
2524
|
-
},
|
|
2525
|
-
{
|
|
2526
|
-
"kind": "var",
|
|
2527
|
-
"value": "sL"
|
|
2528
|
-
},
|
|
2529
|
-
{
|
|
2530
|
-
"kind": "var",
|
|
2531
|
-
"value": "sU"
|
|
2532
|
-
},
|
|
2533
|
-
{
|
|
2534
|
-
"kind": "lit",
|
|
2535
|
-
"value": 0
|
|
2536
|
-
},
|
|
2537
|
-
{
|
|
2538
|
-
"kind": "lit",
|
|
2539
|
-
"value": 0
|
|
2540
|
-
}
|
|
2541
|
-
]
|
|
2542
|
-
}
|
|
2543
|
-
},
|
|
2544
|
-
{
|
|
2545
|
-
"s": {
|
|
2546
|
-
"kind": "iri",
|
|
2547
|
-
"value": ":HGate"
|
|
2548
|
-
},
|
|
2549
|
-
"p": {
|
|
2550
|
-
"kind": "iri",
|
|
2551
|
-
"value": ":entry"
|
|
2552
|
-
},
|
|
2553
|
-
"o": {
|
|
2554
|
-
"kind": "list",
|
|
2555
|
-
"items": [
|
|
2556
|
-
{
|
|
2557
|
-
"kind": "var",
|
|
2558
|
-
"value": "n"
|
|
2559
|
-
},
|
|
2560
|
-
{
|
|
2561
|
-
"kind": "lit",
|
|
2562
|
-
"value": 1
|
|
2563
|
-
},
|
|
2564
|
-
{
|
|
2565
|
-
"kind": "lit",
|
|
2566
|
-
"value": 0
|
|
2567
|
-
},
|
|
2568
|
-
{
|
|
2569
|
-
"kind": "var",
|
|
2570
|
-
"value": "sL"
|
|
2571
|
-
},
|
|
2572
|
-
{
|
|
2573
|
-
"kind": "var",
|
|
2574
|
-
"value": "sU"
|
|
2575
|
-
},
|
|
2576
|
-
{
|
|
2577
|
-
"kind": "lit",
|
|
2578
|
-
"value": 0
|
|
2579
|
-
},
|
|
2580
|
-
{
|
|
2581
|
-
"kind": "lit",
|
|
2582
|
-
"value": 0
|
|
2583
|
-
}
|
|
2584
|
-
]
|
|
2585
|
-
}
|
|
2586
|
-
},
|
|
2587
|
-
{
|
|
2588
|
-
"s": {
|
|
2589
|
-
"kind": "iri",
|
|
2590
|
-
"value": ":HGate"
|
|
2591
|
-
},
|
|
2592
|
-
"p": {
|
|
2593
|
-
"kind": "iri",
|
|
2594
|
-
"value": ":entry"
|
|
2595
|
-
},
|
|
2596
|
-
"o": {
|
|
2597
|
-
"kind": "list",
|
|
2598
|
-
"items": [
|
|
2599
|
-
{
|
|
2600
|
-
"kind": "var",
|
|
2601
|
-
"value": "n"
|
|
2602
|
-
},
|
|
2603
|
-
{
|
|
2604
|
-
"kind": "lit",
|
|
2605
|
-
"value": 1
|
|
2606
|
-
},
|
|
2607
|
-
{
|
|
2608
|
-
"kind": "lit",
|
|
2609
|
-
"value": 1
|
|
2610
|
-
},
|
|
2611
|
-
{
|
|
2612
|
-
"kind": "var",
|
|
2613
|
-
"value": "negL"
|
|
2614
|
-
},
|
|
2615
|
-
{
|
|
2616
|
-
"kind": "var",
|
|
2617
|
-
"value": "negU"
|
|
2618
|
-
},
|
|
2619
|
-
{
|
|
2620
|
-
"kind": "lit",
|
|
2621
|
-
"value": 0
|
|
2622
|
-
},
|
|
2623
|
-
{
|
|
2624
|
-
"kind": "lit",
|
|
2625
|
-
"value": 0
|
|
2626
|
-
}
|
|
2627
|
-
]
|
|
2628
|
-
}
|
|
2629
|
-
}
|
|
2630
|
-
],
|
|
2631
|
-
"bodyComment": [
|
|
2632
|
-
":invSqrt2 :bounds (?n ?sL ?sU)",
|
|
2633
|
-
":invSqrt2 :negBounds (?n ?negL ?negU)"
|
|
2634
|
-
],
|
|
2635
|
-
"headComment": [
|
|
2636
|
-
":HGate :entry (?n 0 0 ?sL ?sU 0 0)",
|
|
2637
|
-
":HGate :entry (?n 0 1 ?sL ?sU 0 0)",
|
|
2638
|
-
":HGate :entry (?n 1 0 ?sL ?sU 0 0)",
|
|
2639
|
-
":HGate :entry (?n 1 1 ?negL ?negU 0 0)"
|
|
2640
|
-
]
|
|
2641
|
-
},
|
|
2642
|
-
{
|
|
2643
|
-
"kind": "rule",
|
|
2644
|
-
"id": 7,
|
|
2645
|
-
"body": [
|
|
2646
|
-
{
|
|
2647
|
-
"s": {
|
|
2648
|
-
"kind": "iri",
|
|
2649
|
-
"value": ":invSqrt2"
|
|
2650
|
-
},
|
|
2651
|
-
"p": {
|
|
2652
|
-
"kind": "iri",
|
|
2653
|
-
"value": ":midpoint"
|
|
2654
|
-
},
|
|
2655
|
-
"o": {
|
|
2656
|
-
"kind": "list",
|
|
2657
|
-
"items": [
|
|
2658
|
-
{
|
|
2659
|
-
"kind": "var",
|
|
2660
|
-
"value": "n"
|
|
2661
|
-
},
|
|
2662
|
-
{
|
|
2663
|
-
"kind": "var",
|
|
2664
|
-
"value": "m"
|
|
2665
|
-
}
|
|
2666
|
-
]
|
|
2667
|
-
}
|
|
2668
|
-
},
|
|
2669
|
-
{
|
|
2670
|
-
"s": {
|
|
2671
|
-
"kind": "iri",
|
|
2672
|
-
"value": ":invSqrt2"
|
|
2673
|
-
},
|
|
2674
|
-
"p": {
|
|
2675
|
-
"kind": "iri",
|
|
2676
|
-
"value": ":negMidpoint"
|
|
2677
|
-
},
|
|
2678
|
-
"o": {
|
|
2679
|
-
"kind": "list",
|
|
2680
|
-
"items": [
|
|
2681
|
-
{
|
|
2682
|
-
"kind": "var",
|
|
2683
|
-
"value": "n"
|
|
2684
|
-
},
|
|
2685
|
-
{
|
|
2686
|
-
"kind": "var",
|
|
2687
|
-
"value": "negM"
|
|
2688
|
-
}
|
|
2689
|
-
]
|
|
2690
|
-
}
|
|
2691
|
-
}
|
|
2692
|
-
],
|
|
2693
|
-
"head": [
|
|
2694
|
-
{
|
|
2695
|
-
"s": {
|
|
2696
|
-
"kind": "iri",
|
|
2697
|
-
"value": ":HGate"
|
|
2698
|
-
},
|
|
2699
|
-
"p": {
|
|
2700
|
-
"kind": "iri",
|
|
2701
|
-
"value": ":midpointEntry"
|
|
2702
|
-
},
|
|
2703
|
-
"o": {
|
|
2704
|
-
"kind": "list",
|
|
2705
|
-
"items": [
|
|
2706
|
-
{
|
|
2707
|
-
"kind": "var",
|
|
2708
|
-
"value": "n"
|
|
2709
|
-
},
|
|
2710
|
-
{
|
|
2711
|
-
"kind": "lit",
|
|
2712
|
-
"value": 0
|
|
2713
|
-
},
|
|
2714
|
-
{
|
|
2715
|
-
"kind": "lit",
|
|
2716
|
-
"value": 0
|
|
2717
|
-
},
|
|
2718
|
-
{
|
|
2719
|
-
"kind": "var",
|
|
2720
|
-
"value": "m"
|
|
2721
|
-
},
|
|
2722
|
-
{
|
|
2723
|
-
"kind": "lit",
|
|
2724
|
-
"value": 0
|
|
2725
|
-
}
|
|
2726
|
-
]
|
|
2727
|
-
}
|
|
2728
|
-
},
|
|
2729
|
-
{
|
|
2730
|
-
"s": {
|
|
2731
|
-
"kind": "iri",
|
|
2732
|
-
"value": ":HGate"
|
|
2733
|
-
},
|
|
2734
|
-
"p": {
|
|
2735
|
-
"kind": "iri",
|
|
2736
|
-
"value": ":midpointEntry"
|
|
2737
|
-
},
|
|
2738
|
-
"o": {
|
|
2739
|
-
"kind": "list",
|
|
2740
|
-
"items": [
|
|
2741
|
-
{
|
|
2742
|
-
"kind": "var",
|
|
2743
|
-
"value": "n"
|
|
2744
|
-
},
|
|
2745
|
-
{
|
|
2746
|
-
"kind": "lit",
|
|
2747
|
-
"value": 0
|
|
2748
|
-
},
|
|
2749
|
-
{
|
|
2750
|
-
"kind": "lit",
|
|
2751
|
-
"value": 1
|
|
2752
|
-
},
|
|
2753
|
-
{
|
|
2754
|
-
"kind": "var",
|
|
2755
|
-
"value": "m"
|
|
2756
|
-
},
|
|
2757
|
-
{
|
|
2758
|
-
"kind": "lit",
|
|
2759
|
-
"value": 0
|
|
2760
|
-
}
|
|
2761
|
-
]
|
|
2762
|
-
}
|
|
2763
|
-
},
|
|
2764
|
-
{
|
|
2765
|
-
"s": {
|
|
2766
|
-
"kind": "iri",
|
|
2767
|
-
"value": ":HGate"
|
|
2768
|
-
},
|
|
2769
|
-
"p": {
|
|
2770
|
-
"kind": "iri",
|
|
2771
|
-
"value": ":midpointEntry"
|
|
2772
|
-
},
|
|
2773
|
-
"o": {
|
|
2774
|
-
"kind": "list",
|
|
2775
|
-
"items": [
|
|
2776
|
-
{
|
|
2777
|
-
"kind": "var",
|
|
2778
|
-
"value": "n"
|
|
2779
|
-
},
|
|
2780
|
-
{
|
|
2781
|
-
"kind": "lit",
|
|
2782
|
-
"value": 1
|
|
2783
|
-
},
|
|
2784
|
-
{
|
|
2785
|
-
"kind": "lit",
|
|
2786
|
-
"value": 0
|
|
2787
|
-
},
|
|
2788
|
-
{
|
|
2789
|
-
"kind": "var",
|
|
2790
|
-
"value": "m"
|
|
2791
|
-
},
|
|
2792
|
-
{
|
|
2793
|
-
"kind": "lit",
|
|
2794
|
-
"value": 0
|
|
2795
|
-
}
|
|
2796
|
-
]
|
|
2797
|
-
}
|
|
2798
|
-
},
|
|
2799
|
-
{
|
|
2800
|
-
"s": {
|
|
2801
|
-
"kind": "iri",
|
|
2802
|
-
"value": ":HGate"
|
|
2803
|
-
},
|
|
2804
|
-
"p": {
|
|
2805
|
-
"kind": "iri",
|
|
2806
|
-
"value": ":midpointEntry"
|
|
2807
|
-
},
|
|
2808
|
-
"o": {
|
|
2809
|
-
"kind": "list",
|
|
2810
|
-
"items": [
|
|
2811
|
-
{
|
|
2812
|
-
"kind": "var",
|
|
2813
|
-
"value": "n"
|
|
2814
|
-
},
|
|
2815
|
-
{
|
|
2816
|
-
"kind": "lit",
|
|
2817
|
-
"value": 1
|
|
2818
|
-
},
|
|
2819
|
-
{
|
|
2820
|
-
"kind": "lit",
|
|
2821
|
-
"value": 1
|
|
2822
|
-
},
|
|
2823
|
-
{
|
|
2824
|
-
"kind": "var",
|
|
2825
|
-
"value": "negM"
|
|
2826
|
-
},
|
|
2827
|
-
{
|
|
2828
|
-
"kind": "lit",
|
|
2829
|
-
"value": 0
|
|
2830
|
-
}
|
|
2831
|
-
]
|
|
2832
|
-
}
|
|
2833
|
-
}
|
|
2834
|
-
],
|
|
2835
|
-
"bodyComment": [
|
|
2836
|
-
":invSqrt2 :midpoint (?n ?m)",
|
|
2837
|
-
":invSqrt2 :negMidpoint (?n ?negM)"
|
|
2838
|
-
],
|
|
2839
|
-
"headComment": [
|
|
2840
|
-
":HGate :midpointEntry (?n 0 0 ?m 0)",
|
|
2841
|
-
":HGate :midpointEntry (?n 0 1 ?m 0)",
|
|
2842
|
-
":HGate :midpointEntry (?n 1 0 ?m 0)",
|
|
2843
|
-
":HGate :midpointEntry (?n 1 1 ?negM 0)"
|
|
2844
|
-
]
|
|
2845
|
-
},
|
|
2846
|
-
{
|
|
2847
|
-
"kind": "rule",
|
|
2848
|
-
"id": 8,
|
|
2849
|
-
"body": [
|
|
2850
|
-
{
|
|
2851
|
-
"s": {
|
|
2852
|
-
"kind": "iri",
|
|
2853
|
-
"value": ":sqrt2Proc"
|
|
2854
|
-
},
|
|
2855
|
-
"p": {
|
|
2856
|
-
"kind": "iri",
|
|
2857
|
-
"value": ":dyadic"
|
|
2858
|
-
},
|
|
2859
|
-
"o": {
|
|
2860
|
-
"kind": "list",
|
|
2861
|
-
"items": [
|
|
2862
|
-
{
|
|
2863
|
-
"kind": "var",
|
|
2864
|
-
"value": "n"
|
|
2865
|
-
},
|
|
2866
|
-
{
|
|
2867
|
-
"kind": "var",
|
|
2868
|
-
"value": "l"
|
|
2869
|
-
},
|
|
2870
|
-
{
|
|
2871
|
-
"kind": "var",
|
|
2872
|
-
"value": "u"
|
|
2873
|
-
},
|
|
2874
|
-
{
|
|
2875
|
-
"kind": "var",
|
|
2876
|
-
"value": "denom"
|
|
2877
|
-
}
|
|
2878
|
-
]
|
|
2879
|
-
}
|
|
2880
|
-
},
|
|
2881
|
-
{
|
|
2882
|
-
"s": {
|
|
2883
|
-
"kind": "list",
|
|
2884
|
-
"items": [
|
|
2885
|
-
{
|
|
2886
|
-
"kind": "var",
|
|
2887
|
-
"value": "denom"
|
|
2888
|
-
},
|
|
2889
|
-
{
|
|
2890
|
-
"kind": "var",
|
|
2891
|
-
"value": "denom"
|
|
2892
|
-
}
|
|
2893
|
-
]
|
|
2894
|
-
},
|
|
2895
|
-
"p": {
|
|
2896
|
-
"kind": "iri",
|
|
2897
|
-
"value": "math:product"
|
|
2898
|
-
},
|
|
2899
|
-
"o": {
|
|
2900
|
-
"kind": "var",
|
|
2901
|
-
"value": "denom2"
|
|
2902
|
-
}
|
|
2903
|
-
},
|
|
2904
|
-
{
|
|
2905
|
-
"s": {
|
|
2906
|
-
"kind": "list",
|
|
2907
|
-
"items": [
|
|
2908
|
-
{
|
|
2909
|
-
"kind": "lit",
|
|
2910
|
-
"value": 2
|
|
2911
|
-
},
|
|
2912
|
-
{
|
|
2913
|
-
"kind": "var",
|
|
2914
|
-
"value": "denom2"
|
|
2915
|
-
}
|
|
2916
|
-
]
|
|
2917
|
-
},
|
|
2918
|
-
"p": {
|
|
2919
|
-
"kind": "iri",
|
|
2920
|
-
"value": "math:product"
|
|
2921
|
-
},
|
|
2922
|
-
"o": {
|
|
2923
|
-
"kind": "var",
|
|
2924
|
-
"value": "normNum"
|
|
2925
|
-
}
|
|
2926
|
-
},
|
|
2927
|
-
{
|
|
2928
|
-
"s": {
|
|
2929
|
-
"kind": "list",
|
|
2930
|
-
"items": [
|
|
2931
|
-
{
|
|
2932
|
-
"kind": "var",
|
|
2933
|
-
"value": "l"
|
|
2934
|
-
},
|
|
2935
|
-
{
|
|
2936
|
-
"kind": "var",
|
|
2937
|
-
"value": "l"
|
|
2938
|
-
}
|
|
2939
|
-
]
|
|
2940
|
-
},
|
|
2941
|
-
"p": {
|
|
2942
|
-
"kind": "iri",
|
|
2943
|
-
"value": "math:product"
|
|
2944
|
-
},
|
|
2945
|
-
"o": {
|
|
2946
|
-
"kind": "var",
|
|
2947
|
-
"value": "l2"
|
|
2948
|
-
}
|
|
2949
|
-
},
|
|
2950
|
-
{
|
|
2951
|
-
"s": {
|
|
2952
|
-
"kind": "list",
|
|
2953
|
-
"items": [
|
|
2954
|
-
{
|
|
2955
|
-
"kind": "var",
|
|
2956
|
-
"value": "u"
|
|
2957
|
-
},
|
|
2958
|
-
{
|
|
2959
|
-
"kind": "var",
|
|
2960
|
-
"value": "u"
|
|
2961
|
-
}
|
|
2962
|
-
]
|
|
2963
|
-
},
|
|
2964
|
-
"p": {
|
|
2965
|
-
"kind": "iri",
|
|
2966
|
-
"value": "math:product"
|
|
2967
|
-
},
|
|
2968
|
-
"o": {
|
|
2969
|
-
"kind": "var",
|
|
2970
|
-
"value": "u2"
|
|
2971
|
-
}
|
|
2972
|
-
},
|
|
2973
|
-
{
|
|
2974
|
-
"s": {
|
|
2975
|
-
"kind": "var",
|
|
2976
|
-
"value": "normNum"
|
|
2977
|
-
},
|
|
2978
|
-
"p": {
|
|
2979
|
-
"kind": "iri",
|
|
2980
|
-
"value": "math:notGreaterThan"
|
|
2981
|
-
},
|
|
2982
|
-
"o": {
|
|
2983
|
-
"kind": "var",
|
|
2984
|
-
"value": "u2"
|
|
2985
|
-
}
|
|
2986
|
-
},
|
|
2987
|
-
{
|
|
2988
|
-
"s": {
|
|
2989
|
-
"kind": "var",
|
|
2990
|
-
"value": "normNum"
|
|
2991
|
-
},
|
|
2992
|
-
"p": {
|
|
2993
|
-
"kind": "iri",
|
|
2994
|
-
"value": "math:notLessThan"
|
|
2995
|
-
},
|
|
2996
|
-
"o": {
|
|
2997
|
-
"kind": "var",
|
|
2998
|
-
"value": "l2"
|
|
2999
|
-
}
|
|
3000
|
-
},
|
|
3001
|
-
{
|
|
3002
|
-
"s": {
|
|
3003
|
-
"kind": "list",
|
|
3004
|
-
"items": [
|
|
3005
|
-
{
|
|
3006
|
-
"kind": "var",
|
|
3007
|
-
"value": "normNum"
|
|
3008
|
-
},
|
|
3009
|
-
{
|
|
3010
|
-
"kind": "var",
|
|
3011
|
-
"value": "u2"
|
|
3012
|
-
}
|
|
3013
|
-
]
|
|
3014
|
-
},
|
|
3015
|
-
"p": {
|
|
3016
|
-
"kind": "iri",
|
|
3017
|
-
"value": "math:quotient"
|
|
3018
|
-
},
|
|
3019
|
-
"o": {
|
|
3020
|
-
"kind": "var",
|
|
3021
|
-
"value": "normL"
|
|
3022
|
-
}
|
|
3023
|
-
},
|
|
3024
|
-
{
|
|
3025
|
-
"s": {
|
|
3026
|
-
"kind": "list",
|
|
3027
|
-
"items": [
|
|
3028
|
-
{
|
|
3029
|
-
"kind": "var",
|
|
3030
|
-
"value": "normNum"
|
|
3031
|
-
},
|
|
3032
|
-
{
|
|
3033
|
-
"kind": "var",
|
|
3034
|
-
"value": "l2"
|
|
3035
|
-
}
|
|
3036
|
-
]
|
|
3037
|
-
},
|
|
3038
|
-
"p": {
|
|
3039
|
-
"kind": "iri",
|
|
3040
|
-
"value": "math:quotient"
|
|
3041
|
-
},
|
|
3042
|
-
"o": {
|
|
3043
|
-
"kind": "var",
|
|
3044
|
-
"value": "normU"
|
|
3045
|
-
}
|
|
3046
|
-
},
|
|
3047
|
-
{
|
|
3048
|
-
"s": {
|
|
3049
|
-
"kind": "list",
|
|
3050
|
-
"items": [
|
|
3051
|
-
{
|
|
3052
|
-
"kind": "var",
|
|
3053
|
-
"value": "normU"
|
|
3054
|
-
},
|
|
3055
|
-
{
|
|
3056
|
-
"kind": "var",
|
|
3057
|
-
"value": "normL"
|
|
3058
|
-
}
|
|
3059
|
-
]
|
|
3060
|
-
},
|
|
3061
|
-
"p": {
|
|
3062
|
-
"kind": "iri",
|
|
3063
|
-
"value": "math:difference"
|
|
3064
|
-
},
|
|
3065
|
-
"o": {
|
|
3066
|
-
"kind": "var",
|
|
3067
|
-
"value": "normW"
|
|
3068
|
-
}
|
|
3069
|
-
}
|
|
3070
|
-
],
|
|
3071
|
-
"head": [
|
|
3072
|
-
{
|
|
3073
|
-
"s": {
|
|
3074
|
-
"kind": "iri",
|
|
3075
|
-
"value": ":HGate"
|
|
3076
|
-
},
|
|
3077
|
-
"p": {
|
|
3078
|
-
"kind": "iri",
|
|
3079
|
-
"value": ":rowNormSqBounds"
|
|
3080
|
-
},
|
|
3081
|
-
"o": {
|
|
3082
|
-
"kind": "list",
|
|
3083
|
-
"items": [
|
|
3084
|
-
{
|
|
3085
|
-
"kind": "var",
|
|
3086
|
-
"value": "n"
|
|
3087
|
-
},
|
|
3088
|
-
{
|
|
3089
|
-
"kind": "lit",
|
|
3090
|
-
"value": 0
|
|
3091
|
-
},
|
|
3092
|
-
{
|
|
3093
|
-
"kind": "var",
|
|
3094
|
-
"value": "normL"
|
|
3095
|
-
},
|
|
3096
|
-
{
|
|
3097
|
-
"kind": "var",
|
|
3098
|
-
"value": "normU"
|
|
3099
|
-
}
|
|
3100
|
-
]
|
|
3101
|
-
}
|
|
3102
|
-
},
|
|
3103
|
-
{
|
|
3104
|
-
"s": {
|
|
3105
|
-
"kind": "iri",
|
|
3106
|
-
"value": ":HGate"
|
|
3107
|
-
},
|
|
3108
|
-
"p": {
|
|
3109
|
-
"kind": "iri",
|
|
3110
|
-
"value": ":rowNormSqBounds"
|
|
3111
|
-
},
|
|
3112
|
-
"o": {
|
|
3113
|
-
"kind": "list",
|
|
3114
|
-
"items": [
|
|
3115
|
-
{
|
|
3116
|
-
"kind": "var",
|
|
3117
|
-
"value": "n"
|
|
3118
|
-
},
|
|
3119
|
-
{
|
|
3120
|
-
"kind": "lit",
|
|
3121
|
-
"value": 1
|
|
3122
|
-
},
|
|
3123
|
-
{
|
|
3124
|
-
"kind": "var",
|
|
3125
|
-
"value": "normL"
|
|
3126
|
-
},
|
|
3127
|
-
{
|
|
3128
|
-
"kind": "var",
|
|
3129
|
-
"value": "normU"
|
|
3130
|
-
}
|
|
3131
|
-
]
|
|
3132
|
-
}
|
|
3133
|
-
},
|
|
3134
|
-
{
|
|
3135
|
-
"s": {
|
|
3136
|
-
"kind": "iri",
|
|
3137
|
-
"value": ":HGate"
|
|
3138
|
-
},
|
|
3139
|
-
"p": {
|
|
3140
|
-
"kind": "iri",
|
|
3141
|
-
"value": ":rowNormSqWidth"
|
|
3142
|
-
},
|
|
3143
|
-
"o": {
|
|
3144
|
-
"kind": "list",
|
|
3145
|
-
"items": [
|
|
3146
|
-
{
|
|
3147
|
-
"kind": "var",
|
|
3148
|
-
"value": "n"
|
|
3149
|
-
},
|
|
3150
|
-
{
|
|
3151
|
-
"kind": "var",
|
|
3152
|
-
"value": "normW"
|
|
3153
|
-
}
|
|
3154
|
-
]
|
|
3155
|
-
}
|
|
3156
|
-
},
|
|
3157
|
-
{
|
|
3158
|
-
"s": {
|
|
3159
|
-
"kind": "iri",
|
|
3160
|
-
"value": ":HGate"
|
|
3161
|
-
},
|
|
3162
|
-
"p": {
|
|
3163
|
-
"kind": "iri",
|
|
3164
|
-
"value": ":rowNormSqContains1"
|
|
3165
|
-
},
|
|
3166
|
-
"o": {
|
|
3167
|
-
"kind": "list",
|
|
3168
|
-
"items": [
|
|
3169
|
-
{
|
|
3170
|
-
"kind": "var",
|
|
3171
|
-
"value": "n"
|
|
3172
|
-
},
|
|
3173
|
-
{
|
|
3174
|
-
"kind": "lit",
|
|
3175
|
-
"value": true
|
|
3176
|
-
}
|
|
3177
|
-
]
|
|
3178
|
-
}
|
|
3179
|
-
}
|
|
3180
|
-
],
|
|
3181
|
-
"bodyComment": [
|
|
3182
|
-
":sqrt2Proc :dyadic (?n ?l ?u ?denom)",
|
|
3183
|
-
"(?denom ?denom) math:product ?denom2",
|
|
3184
|
-
"(2 ?denom2) math:product ?normNum",
|
|
3185
|
-
"(?l ?l) math:product ?l2",
|
|
3186
|
-
"(?u ?u) math:product ?u2",
|
|
3187
|
-
"?normNum math:notGreaterThan ?u2",
|
|
3188
|
-
"?normNum math:notLessThan ?l2",
|
|
3189
|
-
"(?normNum ?u2) math:quotient ?normL",
|
|
3190
|
-
"(?normNum ?l2) math:quotient ?normU",
|
|
3191
|
-
"(?normU ?normL) math:difference ?normW"
|
|
3192
|
-
],
|
|
3193
|
-
"headComment": [
|
|
3194
|
-
":HGate :rowNormSqBounds (?n 0 ?normL ?normU)",
|
|
3195
|
-
":HGate :rowNormSqBounds (?n 1 ?normL ?normU)",
|
|
3196
|
-
":HGate :rowNormSqWidth (?n ?normW)",
|
|
3197
|
-
":HGate :rowNormSqContains1 (?n true)"
|
|
3198
|
-
]
|
|
3199
|
-
},
|
|
3200
|
-
{
|
|
3201
|
-
"kind": "rule",
|
|
3202
|
-
"id": 9,
|
|
3203
|
-
"body": [
|
|
3204
|
-
{
|
|
3205
|
-
"s": {
|
|
3206
|
-
"kind": "iri",
|
|
3207
|
-
"value": ":invSqrt2"
|
|
3208
|
-
},
|
|
3209
|
-
"p": {
|
|
3210
|
-
"kind": "iri",
|
|
3211
|
-
"value": ":midpoint"
|
|
3212
|
-
},
|
|
3213
|
-
"o": {
|
|
3214
|
-
"kind": "list",
|
|
3215
|
-
"items": [
|
|
3216
|
-
{
|
|
3217
|
-
"kind": "var",
|
|
3218
|
-
"value": "n"
|
|
3219
|
-
},
|
|
3220
|
-
{
|
|
3221
|
-
"kind": "var",
|
|
3222
|
-
"value": "m"
|
|
3223
|
-
}
|
|
3224
|
-
]
|
|
3225
|
-
}
|
|
3226
|
-
},
|
|
3227
|
-
{
|
|
3228
|
-
"s": {
|
|
3229
|
-
"kind": "iri",
|
|
3230
|
-
"value": ":invSqrt2"
|
|
3231
|
-
},
|
|
3232
|
-
"p": {
|
|
3233
|
-
"kind": "iri",
|
|
3234
|
-
"value": ":negMidpoint"
|
|
3235
|
-
},
|
|
3236
|
-
"o": {
|
|
3237
|
-
"kind": "list",
|
|
3238
|
-
"items": [
|
|
3239
|
-
{
|
|
3240
|
-
"kind": "var",
|
|
3241
|
-
"value": "n"
|
|
3242
|
-
},
|
|
3243
|
-
{
|
|
3244
|
-
"kind": "var",
|
|
3245
|
-
"value": "negM"
|
|
3246
|
-
}
|
|
3247
|
-
]
|
|
3248
|
-
}
|
|
3249
|
-
},
|
|
3250
|
-
{
|
|
3251
|
-
"s": {
|
|
3252
|
-
"kind": "list",
|
|
3253
|
-
"items": [
|
|
3254
|
-
{
|
|
3255
|
-
"kind": "var",
|
|
3256
|
-
"value": "m"
|
|
3257
|
-
},
|
|
3258
|
-
{
|
|
3259
|
-
"kind": "var",
|
|
3260
|
-
"value": "m"
|
|
3261
|
-
}
|
|
3262
|
-
]
|
|
3263
|
-
},
|
|
3264
|
-
"p": {
|
|
3265
|
-
"kind": "iri",
|
|
3266
|
-
"value": "math:product"
|
|
3267
|
-
},
|
|
3268
|
-
"o": {
|
|
3269
|
-
"kind": "var",
|
|
3270
|
-
"value": "m2"
|
|
3271
|
-
}
|
|
3272
|
-
},
|
|
3273
|
-
{
|
|
3274
|
-
"s": {
|
|
3275
|
-
"kind": "list",
|
|
3276
|
-
"items": [
|
|
3277
|
-
{
|
|
3278
|
-
"kind": "var",
|
|
3279
|
-
"value": "m"
|
|
3280
|
-
},
|
|
3281
|
-
{
|
|
3282
|
-
"kind": "var",
|
|
3283
|
-
"value": "negM"
|
|
3284
|
-
}
|
|
3285
|
-
]
|
|
3286
|
-
},
|
|
3287
|
-
"p": {
|
|
3288
|
-
"kind": "iri",
|
|
3289
|
-
"value": "math:product"
|
|
3290
|
-
},
|
|
3291
|
-
"o": {
|
|
3292
|
-
"kind": "var",
|
|
3293
|
-
"value": "mn"
|
|
3294
|
-
}
|
|
3295
|
-
},
|
|
3296
|
-
{
|
|
3297
|
-
"s": {
|
|
3298
|
-
"kind": "list",
|
|
3299
|
-
"items": [
|
|
3300
|
-
{
|
|
3301
|
-
"kind": "var",
|
|
3302
|
-
"value": "m2"
|
|
3303
|
-
},
|
|
3304
|
-
{
|
|
3305
|
-
"kind": "var",
|
|
3306
|
-
"value": "mn"
|
|
3307
|
-
}
|
|
3308
|
-
]
|
|
3309
|
-
},
|
|
3310
|
-
"p": {
|
|
3311
|
-
"kind": "iri",
|
|
3312
|
-
"value": "math:sum"
|
|
3313
|
-
},
|
|
3314
|
-
"o": {
|
|
3315
|
-
"kind": "var",
|
|
3316
|
-
"value": "dot"
|
|
3317
|
-
}
|
|
3318
|
-
},
|
|
3319
|
-
{
|
|
3320
|
-
"s": {
|
|
3321
|
-
"kind": "var",
|
|
3322
|
-
"value": "dot"
|
|
3323
|
-
},
|
|
3324
|
-
"p": {
|
|
3325
|
-
"kind": "iri",
|
|
3326
|
-
"value": "math:equalTo"
|
|
3327
|
-
},
|
|
3328
|
-
"o": {
|
|
3329
|
-
"kind": "lit",
|
|
3330
|
-
"value": 0
|
|
3331
|
-
}
|
|
3332
|
-
}
|
|
3333
|
-
],
|
|
3334
|
-
"head": [
|
|
3335
|
-
{
|
|
3336
|
-
"s": {
|
|
3337
|
-
"kind": "iri",
|
|
3338
|
-
"value": ":HGate"
|
|
3339
|
-
},
|
|
3340
|
-
"p": {
|
|
3341
|
-
"kind": "iri",
|
|
3342
|
-
"value": ":midpointRowsOrthogonal"
|
|
3343
|
-
},
|
|
3344
|
-
"o": {
|
|
3345
|
-
"kind": "list",
|
|
3346
|
-
"items": [
|
|
3347
|
-
{
|
|
3348
|
-
"kind": "var",
|
|
3349
|
-
"value": "n"
|
|
3350
|
-
},
|
|
3351
|
-
{
|
|
3352
|
-
"kind": "lit",
|
|
3353
|
-
"value": true
|
|
3354
|
-
}
|
|
3355
|
-
]
|
|
3356
|
-
}
|
|
3357
|
-
}
|
|
3358
|
-
],
|
|
3359
|
-
"bodyComment": [
|
|
3360
|
-
":invSqrt2 :midpoint (?n ?m)",
|
|
3361
|
-
":invSqrt2 :negMidpoint (?n ?negM)",
|
|
3362
|
-
"(?m ?m) math:product ?m2",
|
|
3363
|
-
"(?m ?negM) math:product ?mn",
|
|
3364
|
-
"(?m2 ?mn) math:sum ?dot",
|
|
3365
|
-
"?dot math:equalTo 0"
|
|
3366
|
-
],
|
|
3367
|
-
"headComment": [
|
|
3368
|
-
":HGate :midpointRowsOrthogonal (?n true)"
|
|
3369
|
-
]
|
|
3370
|
-
},
|
|
3371
|
-
{
|
|
3372
|
-
"kind": "rule",
|
|
3373
|
-
"id": 10,
|
|
3374
|
-
"body": [
|
|
3375
|
-
{
|
|
3376
|
-
"s": {
|
|
3377
|
-
"kind": "iri",
|
|
3378
|
-
"value": ":invSqrt2"
|
|
3379
|
-
},
|
|
3380
|
-
"p": {
|
|
3381
|
-
"kind": "iri",
|
|
3382
|
-
"value": ":componentErrBound"
|
|
3383
|
-
},
|
|
3384
|
-
"o": {
|
|
3385
|
-
"kind": "list",
|
|
3386
|
-
"items": [
|
|
3387
|
-
{
|
|
3388
|
-
"kind": "var",
|
|
3389
|
-
"value": "n"
|
|
3390
|
-
},
|
|
3391
|
-
{
|
|
3392
|
-
"kind": "var",
|
|
3393
|
-
"value": "compErr"
|
|
3394
|
-
}
|
|
3395
|
-
]
|
|
3396
|
-
}
|
|
3397
|
-
},
|
|
3398
|
-
{
|
|
3399
|
-
"s": {
|
|
3400
|
-
"kind": "list",
|
|
3401
|
-
"items": [
|
|
3402
|
-
{
|
|
3403
|
-
"kind": "lit",
|
|
3404
|
-
"value": 2
|
|
3405
|
-
},
|
|
3406
|
-
{
|
|
3407
|
-
"kind": "var",
|
|
3408
|
-
"value": "compErr"
|
|
3409
|
-
}
|
|
3410
|
-
]
|
|
3411
|
-
},
|
|
3412
|
-
"p": {
|
|
3413
|
-
"kind": "iri",
|
|
3414
|
-
"value": "math:product"
|
|
3415
|
-
},
|
|
3416
|
-
"o": {
|
|
3417
|
-
"kind": "var",
|
|
3418
|
-
"value": "rowErr"
|
|
3419
|
-
}
|
|
3420
|
-
}
|
|
3421
|
-
],
|
|
3422
|
-
"head": [
|
|
3423
|
-
{
|
|
3424
|
-
"s": {
|
|
3425
|
-
"kind": "iri",
|
|
3426
|
-
"value": ":HGate"
|
|
3427
|
-
},
|
|
3428
|
-
"p": {
|
|
3429
|
-
"kind": "iri",
|
|
3430
|
-
"value": ":entryAbsErrBoundMidpoint"
|
|
3431
|
-
},
|
|
3432
|
-
"o": {
|
|
3433
|
-
"kind": "list",
|
|
3434
|
-
"items": [
|
|
3435
|
-
{
|
|
3436
|
-
"kind": "var",
|
|
3437
|
-
"value": "n"
|
|
3438
|
-
},
|
|
3439
|
-
{
|
|
3440
|
-
"kind": "var",
|
|
3441
|
-
"value": "compErr"
|
|
3442
|
-
}
|
|
3443
|
-
]
|
|
3444
|
-
}
|
|
3445
|
-
},
|
|
3446
|
-
{
|
|
3447
|
-
"s": {
|
|
3448
|
-
"kind": "iri",
|
|
3449
|
-
"value": ":HGate"
|
|
3450
|
-
},
|
|
3451
|
-
"p": {
|
|
3452
|
-
"kind": "iri",
|
|
3453
|
-
"value": ":rowAbsErrBoundMidpoint"
|
|
3454
|
-
},
|
|
3455
|
-
"o": {
|
|
3456
|
-
"kind": "list",
|
|
3457
|
-
"items": [
|
|
3458
|
-
{
|
|
3459
|
-
"kind": "var",
|
|
3460
|
-
"value": "n"
|
|
3461
|
-
},
|
|
3462
|
-
{
|
|
3463
|
-
"kind": "var",
|
|
3464
|
-
"value": "rowErr"
|
|
3465
|
-
}
|
|
3466
|
-
]
|
|
3467
|
-
}
|
|
3468
|
-
}
|
|
3469
|
-
],
|
|
3470
|
-
"bodyComment": [
|
|
3471
|
-
":invSqrt2 :componentErrBound (?n ?compErr)",
|
|
3472
|
-
"(2 ?compErr) math:product ?rowErr"
|
|
3473
|
-
],
|
|
3474
|
-
"headComment": [
|
|
3475
|
-
":HGate :entryAbsErrBoundMidpoint (?n ?compErr)",
|
|
3476
|
-
":HGate :rowAbsErrBoundMidpoint (?n ?rowErr)"
|
|
3477
|
-
]
|
|
3478
|
-
}
|
|
3479
|
-
];
|
|
3480
|
-
const QUERIES = [
|
|
3481
|
-
{
|
|
3482
|
-
"id": 1,
|
|
3483
|
-
"premise": [
|
|
3484
|
-
{
|
|
3485
|
-
"s": {
|
|
3486
|
-
"kind": "iri",
|
|
3487
|
-
"value": ":sqrt2Proc"
|
|
3488
|
-
},
|
|
3489
|
-
"p": {
|
|
3490
|
-
"kind": "iri",
|
|
3491
|
-
"value": ":dyadic"
|
|
3492
|
-
},
|
|
3493
|
-
"o": {
|
|
3494
|
-
"kind": "list",
|
|
3495
|
-
"items": [
|
|
3496
|
-
{
|
|
3497
|
-
"kind": "var",
|
|
3498
|
-
"value": "n"
|
|
3499
|
-
},
|
|
3500
|
-
{
|
|
3501
|
-
"kind": "var",
|
|
3502
|
-
"value": "l"
|
|
3503
|
-
},
|
|
3504
|
-
{
|
|
3505
|
-
"kind": "var",
|
|
3506
|
-
"value": "u"
|
|
3507
|
-
},
|
|
3508
|
-
{
|
|
3509
|
-
"kind": "var",
|
|
3510
|
-
"value": "denom"
|
|
3511
|
-
}
|
|
3512
|
-
]
|
|
3513
|
-
}
|
|
3514
|
-
},
|
|
3515
|
-
{
|
|
3516
|
-
"s": {
|
|
3517
|
-
"kind": "iri",
|
|
3518
|
-
"value": ":sqrt2Proc"
|
|
3519
|
-
},
|
|
3520
|
-
"p": {
|
|
3521
|
-
"kind": "iri",
|
|
3522
|
-
"value": ":bounds"
|
|
3523
|
-
},
|
|
3524
|
-
"o": {
|
|
3525
|
-
"kind": "list",
|
|
3526
|
-
"items": [
|
|
3527
|
-
{
|
|
3528
|
-
"kind": "var",
|
|
3529
|
-
"value": "n"
|
|
3530
|
-
},
|
|
3531
|
-
{
|
|
3532
|
-
"kind": "var",
|
|
3533
|
-
"value": "L"
|
|
3534
|
-
},
|
|
3535
|
-
{
|
|
3536
|
-
"kind": "var",
|
|
3537
|
-
"value": "U"
|
|
3538
|
-
}
|
|
3539
|
-
]
|
|
3540
|
-
}
|
|
3541
|
-
},
|
|
3542
|
-
{
|
|
3543
|
-
"s": {
|
|
3544
|
-
"kind": "iri",
|
|
3545
|
-
"value": ":invSqrt2"
|
|
3546
|
-
},
|
|
3547
|
-
"p": {
|
|
3548
|
-
"kind": "iri",
|
|
3549
|
-
"value": ":bounds"
|
|
3550
|
-
},
|
|
3551
|
-
"o": {
|
|
3552
|
-
"kind": "list",
|
|
3553
|
-
"items": [
|
|
3554
|
-
{
|
|
3555
|
-
"kind": "var",
|
|
3556
|
-
"value": "n"
|
|
3557
|
-
},
|
|
3558
|
-
{
|
|
3559
|
-
"kind": "var",
|
|
3560
|
-
"value": "sL"
|
|
3561
|
-
},
|
|
3562
|
-
{
|
|
3563
|
-
"kind": "var",
|
|
3564
|
-
"value": "sU"
|
|
3565
|
-
}
|
|
3566
|
-
]
|
|
3567
|
-
}
|
|
3568
|
-
},
|
|
3569
|
-
{
|
|
3570
|
-
"s": {
|
|
3571
|
-
"kind": "iri",
|
|
3572
|
-
"value": ":invSqrt2"
|
|
3573
|
-
},
|
|
3574
|
-
"p": {
|
|
3575
|
-
"kind": "iri",
|
|
3576
|
-
"value": ":width"
|
|
3577
|
-
},
|
|
3578
|
-
"o": {
|
|
3579
|
-
"kind": "list",
|
|
3580
|
-
"items": [
|
|
3581
|
-
{
|
|
3582
|
-
"kind": "var",
|
|
3583
|
-
"value": "n"
|
|
3584
|
-
},
|
|
3585
|
-
{
|
|
3586
|
-
"kind": "var",
|
|
3587
|
-
"value": "sW"
|
|
3588
|
-
}
|
|
3589
|
-
]
|
|
3590
|
-
}
|
|
3591
|
-
},
|
|
3592
|
-
{
|
|
3593
|
-
"s": {
|
|
3594
|
-
"kind": "iri",
|
|
3595
|
-
"value": ":invSqrt2"
|
|
3596
|
-
},
|
|
3597
|
-
"p": {
|
|
3598
|
-
"kind": "iri",
|
|
3599
|
-
"value": ":midpoint"
|
|
3600
|
-
},
|
|
3601
|
-
"o": {
|
|
3602
|
-
"kind": "list",
|
|
3603
|
-
"items": [
|
|
3604
|
-
{
|
|
3605
|
-
"kind": "var",
|
|
3606
|
-
"value": "n"
|
|
3607
|
-
},
|
|
3608
|
-
{
|
|
3609
|
-
"kind": "var",
|
|
3610
|
-
"value": "m"
|
|
3611
|
-
}
|
|
3612
|
-
]
|
|
3613
|
-
}
|
|
3614
|
-
},
|
|
3615
|
-
{
|
|
3616
|
-
"s": {
|
|
3617
|
-
"kind": "iri",
|
|
3618
|
-
"value": ":invSqrt2"
|
|
3619
|
-
},
|
|
3620
|
-
"p": {
|
|
3621
|
-
"kind": "iri",
|
|
3622
|
-
"value": ":negMidpoint"
|
|
3623
|
-
},
|
|
3624
|
-
"o": {
|
|
3625
|
-
"kind": "list",
|
|
3626
|
-
"items": [
|
|
3627
|
-
{
|
|
3628
|
-
"kind": "var",
|
|
3629
|
-
"value": "n"
|
|
3630
|
-
},
|
|
3631
|
-
{
|
|
3632
|
-
"kind": "var",
|
|
3633
|
-
"value": "negM"
|
|
3634
|
-
}
|
|
3635
|
-
]
|
|
3636
|
-
}
|
|
3637
|
-
},
|
|
3638
|
-
{
|
|
3639
|
-
"s": {
|
|
3640
|
-
"kind": "iri",
|
|
3641
|
-
"value": ":HGate"
|
|
3642
|
-
},
|
|
3643
|
-
"p": {
|
|
3644
|
-
"kind": "iri",
|
|
3645
|
-
"value": ":entryAbsErrBoundMidpoint"
|
|
3646
|
-
},
|
|
3647
|
-
"o": {
|
|
3648
|
-
"kind": "list",
|
|
3649
|
-
"items": [
|
|
3650
|
-
{
|
|
3651
|
-
"kind": "var",
|
|
3652
|
-
"value": "n"
|
|
3653
|
-
},
|
|
3654
|
-
{
|
|
3655
|
-
"kind": "var",
|
|
3656
|
-
"value": "cE"
|
|
3657
|
-
}
|
|
3658
|
-
]
|
|
3659
|
-
}
|
|
3660
|
-
},
|
|
3661
|
-
{
|
|
3662
|
-
"s": {
|
|
3663
|
-
"kind": "iri",
|
|
3664
|
-
"value": ":HGate"
|
|
3665
|
-
},
|
|
3666
|
-
"p": {
|
|
3667
|
-
"kind": "iri",
|
|
3668
|
-
"value": ":rowAbsErrBoundMidpoint"
|
|
3669
|
-
},
|
|
3670
|
-
"o": {
|
|
3671
|
-
"kind": "list",
|
|
3672
|
-
"items": [
|
|
3673
|
-
{
|
|
3674
|
-
"kind": "var",
|
|
3675
|
-
"value": "n"
|
|
3676
|
-
},
|
|
3677
|
-
{
|
|
3678
|
-
"kind": "var",
|
|
3679
|
-
"value": "rE"
|
|
3680
|
-
}
|
|
3681
|
-
]
|
|
3682
|
-
}
|
|
3683
|
-
},
|
|
3684
|
-
{
|
|
3685
|
-
"s": {
|
|
3686
|
-
"kind": "iri",
|
|
3687
|
-
"value": ":HGate"
|
|
3688
|
-
},
|
|
3689
|
-
"p": {
|
|
3690
|
-
"kind": "iri",
|
|
3691
|
-
"value": ":rowNormSqBounds"
|
|
3692
|
-
},
|
|
3693
|
-
"o": {
|
|
3694
|
-
"kind": "list",
|
|
3695
|
-
"items": [
|
|
3696
|
-
{
|
|
3697
|
-
"kind": "var",
|
|
3698
|
-
"value": "n"
|
|
3699
|
-
},
|
|
3700
|
-
{
|
|
3701
|
-
"kind": "lit",
|
|
3702
|
-
"value": 0
|
|
3703
|
-
},
|
|
3704
|
-
{
|
|
3705
|
-
"kind": "var",
|
|
3706
|
-
"value": "rnL"
|
|
3707
|
-
},
|
|
3708
|
-
{
|
|
3709
|
-
"kind": "var",
|
|
3710
|
-
"value": "rnU"
|
|
3711
|
-
}
|
|
3712
|
-
]
|
|
3713
|
-
}
|
|
3714
|
-
},
|
|
3715
|
-
{
|
|
3716
|
-
"s": {
|
|
3717
|
-
"kind": "iri",
|
|
3718
|
-
"value": ":HGate"
|
|
3719
|
-
},
|
|
3720
|
-
"p": {
|
|
3721
|
-
"kind": "iri",
|
|
3722
|
-
"value": ":rowNormSqWidth"
|
|
3723
|
-
},
|
|
3724
|
-
"o": {
|
|
3725
|
-
"kind": "list",
|
|
3726
|
-
"items": [
|
|
3727
|
-
{
|
|
3728
|
-
"kind": "var",
|
|
3729
|
-
"value": "n"
|
|
3730
|
-
},
|
|
3731
|
-
{
|
|
3732
|
-
"kind": "var",
|
|
3733
|
-
"value": "rnW"
|
|
3734
|
-
}
|
|
3735
|
-
]
|
|
3736
|
-
}
|
|
3737
|
-
},
|
|
3738
|
-
{
|
|
3739
|
-
"s": {
|
|
3740
|
-
"kind": "iri",
|
|
3741
|
-
"value": ":HGate"
|
|
3742
|
-
},
|
|
3743
|
-
"p": {
|
|
3744
|
-
"kind": "iri",
|
|
3745
|
-
"value": ":rowNormSqContains1"
|
|
3746
|
-
},
|
|
3747
|
-
"o": {
|
|
3748
|
-
"kind": "list",
|
|
3749
|
-
"items": [
|
|
3750
|
-
{
|
|
3751
|
-
"kind": "var",
|
|
3752
|
-
"value": "n"
|
|
3753
|
-
},
|
|
3754
|
-
{
|
|
3755
|
-
"kind": "var",
|
|
3756
|
-
"value": "okNorm"
|
|
3757
|
-
}
|
|
3758
|
-
]
|
|
3759
|
-
}
|
|
3760
|
-
},
|
|
3761
|
-
{
|
|
3762
|
-
"s": {
|
|
3763
|
-
"kind": "iri",
|
|
3764
|
-
"value": ":HGate"
|
|
3765
|
-
},
|
|
3766
|
-
"p": {
|
|
3767
|
-
"kind": "iri",
|
|
3768
|
-
"value": ":midpointRowsOrthogonal"
|
|
3769
|
-
},
|
|
3770
|
-
"o": {
|
|
3771
|
-
"kind": "list",
|
|
3772
|
-
"items": [
|
|
3773
|
-
{
|
|
3774
|
-
"kind": "var",
|
|
3775
|
-
"value": "n"
|
|
3776
|
-
},
|
|
3777
|
-
{
|
|
3778
|
-
"kind": "var",
|
|
3779
|
-
"value": "okDot"
|
|
3780
|
-
}
|
|
3781
|
-
]
|
|
3782
|
-
}
|
|
3783
|
-
}
|
|
3784
|
-
],
|
|
3785
|
-
"conclusion": [
|
|
3786
|
-
{
|
|
3787
|
-
"s": {
|
|
3788
|
-
"kind": "iri",
|
|
3789
|
-
"value": ":result"
|
|
3790
|
-
},
|
|
3791
|
-
"p": {
|
|
3792
|
-
"kind": "iri",
|
|
3793
|
-
"value": ":n"
|
|
3794
|
-
},
|
|
3795
|
-
"o": {
|
|
3796
|
-
"kind": "var",
|
|
3797
|
-
"value": "n"
|
|
3798
|
-
}
|
|
3799
|
-
},
|
|
3800
|
-
{
|
|
3801
|
-
"s": {
|
|
3802
|
-
"kind": "iri",
|
|
3803
|
-
"value": ":result"
|
|
3804
|
-
},
|
|
3805
|
-
"p": {
|
|
3806
|
-
"kind": "iri",
|
|
3807
|
-
"value": ":sqrt2Dyadic"
|
|
3808
|
-
},
|
|
3809
|
-
"o": {
|
|
3810
|
-
"kind": "list",
|
|
3811
|
-
"items": [
|
|
3812
|
-
{
|
|
3813
|
-
"kind": "var",
|
|
3814
|
-
"value": "n"
|
|
3815
|
-
},
|
|
3816
|
-
{
|
|
3817
|
-
"kind": "var",
|
|
3818
|
-
"value": "l"
|
|
3819
|
-
},
|
|
3820
|
-
{
|
|
3821
|
-
"kind": "var",
|
|
3822
|
-
"value": "u"
|
|
3823
|
-
},
|
|
3824
|
-
{
|
|
3825
|
-
"kind": "var",
|
|
3826
|
-
"value": "denom"
|
|
3827
|
-
}
|
|
3828
|
-
]
|
|
3829
|
-
}
|
|
3830
|
-
},
|
|
3831
|
-
{
|
|
3832
|
-
"s": {
|
|
3833
|
-
"kind": "iri",
|
|
3834
|
-
"value": ":result"
|
|
3835
|
-
},
|
|
3836
|
-
"p": {
|
|
3837
|
-
"kind": "iri",
|
|
3838
|
-
"value": ":sqrt2Bounds"
|
|
3839
|
-
},
|
|
3840
|
-
"o": {
|
|
3841
|
-
"kind": "list",
|
|
3842
|
-
"items": [
|
|
3843
|
-
{
|
|
3844
|
-
"kind": "var",
|
|
3845
|
-
"value": "n"
|
|
3846
|
-
},
|
|
3847
|
-
{
|
|
3848
|
-
"kind": "var",
|
|
3849
|
-
"value": "L"
|
|
3850
|
-
},
|
|
3851
|
-
{
|
|
3852
|
-
"kind": "var",
|
|
3853
|
-
"value": "U"
|
|
3854
|
-
}
|
|
3855
|
-
]
|
|
3856
|
-
}
|
|
3857
|
-
},
|
|
3858
|
-
{
|
|
3859
|
-
"s": {
|
|
3860
|
-
"kind": "iri",
|
|
3861
|
-
"value": ":result"
|
|
3862
|
-
},
|
|
3863
|
-
"p": {
|
|
3864
|
-
"kind": "iri",
|
|
3865
|
-
"value": ":invSqrt2Bounds"
|
|
3866
|
-
},
|
|
3867
|
-
"o": {
|
|
3868
|
-
"kind": "list",
|
|
3869
|
-
"items": [
|
|
3870
|
-
{
|
|
3871
|
-
"kind": "var",
|
|
3872
|
-
"value": "n"
|
|
3873
|
-
},
|
|
3874
|
-
{
|
|
3875
|
-
"kind": "var",
|
|
3876
|
-
"value": "sL"
|
|
3877
|
-
},
|
|
3878
|
-
{
|
|
3879
|
-
"kind": "var",
|
|
3880
|
-
"value": "sU"
|
|
3881
|
-
}
|
|
3882
|
-
]
|
|
3883
|
-
}
|
|
3884
|
-
},
|
|
3885
|
-
{
|
|
3886
|
-
"s": {
|
|
3887
|
-
"kind": "iri",
|
|
3888
|
-
"value": ":result"
|
|
3889
|
-
},
|
|
3890
|
-
"p": {
|
|
3891
|
-
"kind": "iri",
|
|
3892
|
-
"value": ":invSqrt2Width"
|
|
3893
|
-
},
|
|
3894
|
-
"o": {
|
|
3895
|
-
"kind": "list",
|
|
3896
|
-
"items": [
|
|
3897
|
-
{
|
|
3898
|
-
"kind": "var",
|
|
3899
|
-
"value": "n"
|
|
3900
|
-
},
|
|
3901
|
-
{
|
|
3902
|
-
"kind": "var",
|
|
3903
|
-
"value": "sW"
|
|
3904
|
-
}
|
|
3905
|
-
]
|
|
3906
|
-
}
|
|
3907
|
-
},
|
|
3908
|
-
{
|
|
3909
|
-
"s": {
|
|
3910
|
-
"kind": "iri",
|
|
3911
|
-
"value": ":result"
|
|
3912
|
-
},
|
|
3913
|
-
"p": {
|
|
3914
|
-
"kind": "iri",
|
|
3915
|
-
"value": ":midpointScale"
|
|
3916
|
-
},
|
|
3917
|
-
"o": {
|
|
3918
|
-
"kind": "list",
|
|
3919
|
-
"items": [
|
|
3920
|
-
{
|
|
3921
|
-
"kind": "var",
|
|
3922
|
-
"value": "n"
|
|
3923
|
-
},
|
|
3924
|
-
{
|
|
3925
|
-
"kind": "var",
|
|
3926
|
-
"value": "m"
|
|
3927
|
-
}
|
|
3928
|
-
]
|
|
3929
|
-
}
|
|
3930
|
-
},
|
|
3931
|
-
{
|
|
3932
|
-
"s": {
|
|
3933
|
-
"kind": "iri",
|
|
3934
|
-
"value": ":result"
|
|
3935
|
-
},
|
|
3936
|
-
"p": {
|
|
3937
|
-
"kind": "iri",
|
|
3938
|
-
"value": ":midpointNegScale"
|
|
3939
|
-
},
|
|
3940
|
-
"o": {
|
|
3941
|
-
"kind": "list",
|
|
3942
|
-
"items": [
|
|
3943
|
-
{
|
|
3944
|
-
"kind": "var",
|
|
3945
|
-
"value": "n"
|
|
3946
|
-
},
|
|
3947
|
-
{
|
|
3948
|
-
"kind": "var",
|
|
3949
|
-
"value": "negM"
|
|
3950
|
-
}
|
|
3951
|
-
]
|
|
3952
|
-
}
|
|
3953
|
-
},
|
|
3954
|
-
{
|
|
3955
|
-
"s": {
|
|
3956
|
-
"kind": "iri",
|
|
3957
|
-
"value": ":result"
|
|
3958
|
-
},
|
|
3959
|
-
"p": {
|
|
3960
|
-
"kind": "iri",
|
|
3961
|
-
"value": ":entryAbsErrBoundMidpoint"
|
|
3962
|
-
},
|
|
3963
|
-
"o": {
|
|
3964
|
-
"kind": "list",
|
|
3965
|
-
"items": [
|
|
3966
|
-
{
|
|
3967
|
-
"kind": "var",
|
|
3968
|
-
"value": "n"
|
|
3969
|
-
},
|
|
3970
|
-
{
|
|
3971
|
-
"kind": "var",
|
|
3972
|
-
"value": "cE"
|
|
3973
|
-
}
|
|
3974
|
-
]
|
|
3975
|
-
}
|
|
3976
|
-
},
|
|
3977
|
-
{
|
|
3978
|
-
"s": {
|
|
3979
|
-
"kind": "iri",
|
|
3980
|
-
"value": ":result"
|
|
3981
|
-
},
|
|
3982
|
-
"p": {
|
|
3983
|
-
"kind": "iri",
|
|
3984
|
-
"value": ":rowAbsErrBoundMidpoint"
|
|
3985
|
-
},
|
|
3986
|
-
"o": {
|
|
3987
|
-
"kind": "list",
|
|
3988
|
-
"items": [
|
|
3989
|
-
{
|
|
3990
|
-
"kind": "var",
|
|
3991
|
-
"value": "n"
|
|
3992
|
-
},
|
|
3993
|
-
{
|
|
3994
|
-
"kind": "var",
|
|
3995
|
-
"value": "rE"
|
|
3996
|
-
}
|
|
3997
|
-
]
|
|
3998
|
-
}
|
|
3999
|
-
},
|
|
4000
|
-
{
|
|
4001
|
-
"s": {
|
|
4002
|
-
"kind": "iri",
|
|
4003
|
-
"value": ":result"
|
|
4004
|
-
},
|
|
4005
|
-
"p": {
|
|
4006
|
-
"kind": "iri",
|
|
4007
|
-
"value": ":rowNormSqBounds"
|
|
4008
|
-
},
|
|
4009
|
-
"o": {
|
|
4010
|
-
"kind": "list",
|
|
4011
|
-
"items": [
|
|
4012
|
-
{
|
|
4013
|
-
"kind": "var",
|
|
4014
|
-
"value": "n"
|
|
4015
|
-
},
|
|
4016
|
-
{
|
|
4017
|
-
"kind": "var",
|
|
4018
|
-
"value": "rnL"
|
|
4019
|
-
},
|
|
4020
|
-
{
|
|
4021
|
-
"kind": "var",
|
|
4022
|
-
"value": "rnU"
|
|
4023
|
-
}
|
|
4024
|
-
]
|
|
4025
|
-
}
|
|
4026
|
-
},
|
|
4027
|
-
{
|
|
4028
|
-
"s": {
|
|
4029
|
-
"kind": "iri",
|
|
4030
|
-
"value": ":result"
|
|
4031
|
-
},
|
|
4032
|
-
"p": {
|
|
4033
|
-
"kind": "iri",
|
|
4034
|
-
"value": ":rowNormSqWidth"
|
|
4035
|
-
},
|
|
4036
|
-
"o": {
|
|
4037
|
-
"kind": "list",
|
|
4038
|
-
"items": [
|
|
4039
|
-
{
|
|
4040
|
-
"kind": "var",
|
|
4041
|
-
"value": "n"
|
|
4042
|
-
},
|
|
4043
|
-
{
|
|
4044
|
-
"kind": "var",
|
|
4045
|
-
"value": "rnW"
|
|
4046
|
-
}
|
|
4047
|
-
]
|
|
4048
|
-
}
|
|
4049
|
-
},
|
|
4050
|
-
{
|
|
4051
|
-
"s": {
|
|
4052
|
-
"kind": "iri",
|
|
4053
|
-
"value": ":result"
|
|
4054
|
-
},
|
|
4055
|
-
"p": {
|
|
4056
|
-
"kind": "iri",
|
|
4057
|
-
"value": ":rowNormSqContains1"
|
|
4058
|
-
},
|
|
4059
|
-
"o": {
|
|
4060
|
-
"kind": "list",
|
|
4061
|
-
"items": [
|
|
4062
|
-
{
|
|
4063
|
-
"kind": "var",
|
|
4064
|
-
"value": "n"
|
|
4065
|
-
},
|
|
4066
|
-
{
|
|
4067
|
-
"kind": "var",
|
|
4068
|
-
"value": "okNorm"
|
|
4069
|
-
}
|
|
4070
|
-
]
|
|
4071
|
-
}
|
|
4072
|
-
},
|
|
4073
|
-
{
|
|
4074
|
-
"s": {
|
|
4075
|
-
"kind": "iri",
|
|
4076
|
-
"value": ":result"
|
|
4077
|
-
},
|
|
4078
|
-
"p": {
|
|
4079
|
-
"kind": "iri",
|
|
4080
|
-
"value": ":midpointRowsOrthogonal"
|
|
4081
|
-
},
|
|
4082
|
-
"o": {
|
|
4083
|
-
"kind": "list",
|
|
4084
|
-
"items": [
|
|
4085
|
-
{
|
|
4086
|
-
"kind": "var",
|
|
4087
|
-
"value": "n"
|
|
4088
|
-
},
|
|
4089
|
-
{
|
|
4090
|
-
"kind": "var",
|
|
4091
|
-
"value": "okDot"
|
|
4092
|
-
}
|
|
4093
|
-
]
|
|
4094
|
-
}
|
|
4095
|
-
}
|
|
4096
|
-
],
|
|
4097
|
-
"premiseComment": [
|
|
4098
|
-
":sqrt2Proc :dyadic (?n ?l ?u ?denom)",
|
|
4099
|
-
":sqrt2Proc :bounds (?n ?L ?U)",
|
|
4100
|
-
":invSqrt2 :bounds (?n ?sL ?sU)",
|
|
4101
|
-
":invSqrt2 :width (?n ?sW)",
|
|
4102
|
-
":invSqrt2 :midpoint (?n ?m)",
|
|
4103
|
-
":invSqrt2 :negMidpoint (?n ?negM)",
|
|
4104
|
-
":HGate :entryAbsErrBoundMidpoint (?n ?cE)",
|
|
4105
|
-
":HGate :rowAbsErrBoundMidpoint (?n ?rE)",
|
|
4106
|
-
":HGate :rowNormSqBounds (?n 0 ?rnL ?rnU)",
|
|
4107
|
-
":HGate :rowNormSqWidth (?n ?rnW)",
|
|
4108
|
-
":HGate :rowNormSqContains1 (?n ?okNorm)",
|
|
4109
|
-
":HGate :midpointRowsOrthogonal (?n ?okDot)"
|
|
4110
|
-
],
|
|
4111
|
-
"conclusionComment": [
|
|
4112
|
-
":result :n ?n",
|
|
4113
|
-
":result :sqrt2Dyadic (?n ?l ?u ?denom)",
|
|
4114
|
-
":result :sqrt2Bounds (?n ?L ?U)",
|
|
4115
|
-
":result :invSqrt2Bounds (?n ?sL ?sU)",
|
|
4116
|
-
":result :invSqrt2Width (?n ?sW)",
|
|
4117
|
-
":result :midpointScale (?n ?m)",
|
|
4118
|
-
":result :midpointNegScale (?n ?negM)",
|
|
4119
|
-
":result :entryAbsErrBoundMidpoint (?n ?cE)",
|
|
4120
|
-
":result :rowAbsErrBoundMidpoint (?n ?rE)",
|
|
4121
|
-
":result :rowNormSqBounds (?n ?rnL ?rnU)",
|
|
4122
|
-
":result :rowNormSqWidth (?n ?rnW)",
|
|
4123
|
-
":result :rowNormSqContains1 (?n ?okNorm)",
|
|
4124
|
-
":result :midpointRowsOrthogonal (?n ?okDot)"
|
|
4125
|
-
]
|
|
4126
|
-
},
|
|
4127
|
-
{
|
|
4128
|
-
"id": 2,
|
|
4129
|
-
"premise": [
|
|
4130
|
-
{
|
|
4131
|
-
"s": {
|
|
4132
|
-
"kind": "iri",
|
|
4133
|
-
"value": ":HGate"
|
|
4134
|
-
},
|
|
4135
|
-
"p": {
|
|
4136
|
-
"kind": "iri",
|
|
4137
|
-
"value": ":entry"
|
|
4138
|
-
},
|
|
4139
|
-
"o": {
|
|
4140
|
-
"kind": "list",
|
|
4141
|
-
"items": [
|
|
4142
|
-
{
|
|
4143
|
-
"kind": "var",
|
|
4144
|
-
"value": "n"
|
|
4145
|
-
},
|
|
4146
|
-
{
|
|
4147
|
-
"kind": "var",
|
|
4148
|
-
"value": "r"
|
|
4149
|
-
},
|
|
4150
|
-
{
|
|
4151
|
-
"kind": "var",
|
|
4152
|
-
"value": "c"
|
|
4153
|
-
},
|
|
4154
|
-
{
|
|
4155
|
-
"kind": "var",
|
|
4156
|
-
"value": "reL"
|
|
4157
|
-
},
|
|
4158
|
-
{
|
|
4159
|
-
"kind": "var",
|
|
4160
|
-
"value": "reU"
|
|
4161
|
-
},
|
|
4162
|
-
{
|
|
4163
|
-
"kind": "var",
|
|
4164
|
-
"value": "imL"
|
|
4165
|
-
},
|
|
4166
|
-
{
|
|
4167
|
-
"kind": "var",
|
|
4168
|
-
"value": "imU"
|
|
4169
|
-
}
|
|
4170
|
-
]
|
|
4171
|
-
}
|
|
4172
|
-
}
|
|
4173
|
-
],
|
|
4174
|
-
"conclusion": [
|
|
4175
|
-
{
|
|
4176
|
-
"s": {
|
|
4177
|
-
"kind": "iri",
|
|
4178
|
-
"value": ":result"
|
|
4179
|
-
},
|
|
4180
|
-
"p": {
|
|
4181
|
-
"kind": "iri",
|
|
4182
|
-
"value": ":HEntry"
|
|
4183
|
-
},
|
|
4184
|
-
"o": {
|
|
4185
|
-
"kind": "list",
|
|
4186
|
-
"items": [
|
|
4187
|
-
{
|
|
4188
|
-
"kind": "var",
|
|
4189
|
-
"value": "n"
|
|
4190
|
-
},
|
|
4191
|
-
{
|
|
4192
|
-
"kind": "var",
|
|
4193
|
-
"value": "r"
|
|
4194
|
-
},
|
|
4195
|
-
{
|
|
4196
|
-
"kind": "var",
|
|
4197
|
-
"value": "c"
|
|
4198
|
-
},
|
|
4199
|
-
{
|
|
4200
|
-
"kind": "var",
|
|
4201
|
-
"value": "reL"
|
|
4202
|
-
},
|
|
4203
|
-
{
|
|
4204
|
-
"kind": "var",
|
|
4205
|
-
"value": "reU"
|
|
4206
|
-
},
|
|
4207
|
-
{
|
|
4208
|
-
"kind": "var",
|
|
4209
|
-
"value": "imL"
|
|
4210
|
-
},
|
|
4211
|
-
{
|
|
4212
|
-
"kind": "var",
|
|
4213
|
-
"value": "imU"
|
|
4214
|
-
}
|
|
4215
|
-
]
|
|
4216
|
-
}
|
|
4217
|
-
}
|
|
4218
|
-
],
|
|
4219
|
-
"premiseComment": [
|
|
4220
|
-
":HGate :entry (?n ?r ?c ?reL ?reU ?imL ?imU)"
|
|
4221
|
-
],
|
|
4222
|
-
"conclusionComment": [
|
|
4223
|
-
":result :HEntry (?n ?r ?c ?reL ?reU ?imL ?imU)"
|
|
4224
|
-
]
|
|
4225
|
-
},
|
|
4226
|
-
{
|
|
4227
|
-
"id": 3,
|
|
4228
|
-
"premise": [
|
|
4229
|
-
{
|
|
4230
|
-
"s": {
|
|
4231
|
-
"kind": "iri",
|
|
4232
|
-
"value": ":HGate"
|
|
4233
|
-
},
|
|
4234
|
-
"p": {
|
|
4235
|
-
"kind": "iri",
|
|
4236
|
-
"value": ":midpointEntry"
|
|
4237
|
-
},
|
|
4238
|
-
"o": {
|
|
4239
|
-
"kind": "list",
|
|
4240
|
-
"items": [
|
|
4241
|
-
{
|
|
4242
|
-
"kind": "var",
|
|
4243
|
-
"value": "n"
|
|
4244
|
-
},
|
|
4245
|
-
{
|
|
4246
|
-
"kind": "var",
|
|
4247
|
-
"value": "r"
|
|
4248
|
-
},
|
|
4249
|
-
{
|
|
4250
|
-
"kind": "var",
|
|
4251
|
-
"value": "c"
|
|
4252
|
-
},
|
|
4253
|
-
{
|
|
4254
|
-
"kind": "var",
|
|
4255
|
-
"value": "re"
|
|
4256
|
-
},
|
|
4257
|
-
{
|
|
4258
|
-
"kind": "var",
|
|
4259
|
-
"value": "im"
|
|
4260
|
-
}
|
|
4261
|
-
]
|
|
4262
|
-
}
|
|
4263
|
-
}
|
|
4264
|
-
],
|
|
4265
|
-
"conclusion": [
|
|
4266
|
-
{
|
|
4267
|
-
"s": {
|
|
4268
|
-
"kind": "iri",
|
|
4269
|
-
"value": ":result"
|
|
4270
|
-
},
|
|
4271
|
-
"p": {
|
|
4272
|
-
"kind": "iri",
|
|
4273
|
-
"value": ":HMidpointEntry"
|
|
4274
|
-
},
|
|
4275
|
-
"o": {
|
|
4276
|
-
"kind": "list",
|
|
4277
|
-
"items": [
|
|
4278
|
-
{
|
|
4279
|
-
"kind": "var",
|
|
4280
|
-
"value": "n"
|
|
4281
|
-
},
|
|
4282
|
-
{
|
|
4283
|
-
"kind": "var",
|
|
4284
|
-
"value": "r"
|
|
4285
|
-
},
|
|
4286
|
-
{
|
|
4287
|
-
"kind": "var",
|
|
4288
|
-
"value": "c"
|
|
4289
|
-
},
|
|
4290
|
-
{
|
|
4291
|
-
"kind": "var",
|
|
4292
|
-
"value": "re"
|
|
4293
|
-
},
|
|
4294
|
-
{
|
|
4295
|
-
"kind": "var",
|
|
4296
|
-
"value": "im"
|
|
4297
|
-
}
|
|
4298
|
-
]
|
|
4299
|
-
}
|
|
4300
|
-
}
|
|
4301
|
-
],
|
|
4302
|
-
"premiseComment": [
|
|
4303
|
-
":HGate :midpointEntry (?n ?r ?c ?re ?im)"
|
|
4304
|
-
],
|
|
4305
|
-
"conclusionComment": [
|
|
4306
|
-
":result :HMidpointEntry (?n ?r ?c ?re ?im)"
|
|
4307
|
-
]
|
|
4308
|
-
}
|
|
4309
|
-
];
|
|
4310
|
-
const DOC_MARKDOWN = "# Hadamard gate approximation\n\nGenerated by `see.js` from a Notation3 source file.\n\n## Compilation summary\n\n- Example name: `hadamard_approx`\n- Input facts emitted: 8\n- Forward rules compiled: 10\n- Backward predicate rules compiled: 0\n- Fuses compiled: 0\n- Predicate count: 39\n\n## Built-ins used\n\n- `math:difference`\n- `math:equalTo`\n- `math:exponentiation`\n- `math:lessThan`\n- `math:notGreaterThan`\n- `math:notLessThan`\n- `math:product`\n- `math:quotient`\n- `math:sum`\n\n## Runtime model\n\nThe generated `examples/hadamard_approx.js` is a specialized JavaScript derivation program. For ordinary sources, `see.js` emits the source facts as `examples/input/hadamard_approx.trig`. For rules-only sources, generation can reuse an existing external evidence file such as `examples/input/hadamard-approx.trig` or `examples/input/hadamard_approx.trig`. The runner reads that TriG evidence directly and performs a local fixpoint derivation; it does not parse the program source or call an external reasoner.\n\n## Output model\n\nRunning `node examples/hadamard_approx.js` produces a SEE-style Markdown report with an **Entailment** section, an **Explanation** section, and a **Formal TriG Output** section containing the selected derived/query facts.\n";
|
|
4311
|
-
function seeMetadata(data) { return (data && data.__see) || {}; }
|
|
4312
|
-
function trustedDerivation(data) { const meta = seeMetadata(data); const facts = data && Array.isArray(data.facts) ? data.facts : []; const expectedFacts = EXPECTED_INPUT_FACTS || Number(meta.InputFacts || 0); if (meta.SourceSHA256 && meta.SourceSHA256 !== "e8ecabf81463a98ebcb7a1970dfe31792d96011b5e060ad2ed6f5f02ee46a6d2") throw new Error('input evidence does not match the N3 source compiled into this example'); const result = saturate(facts, RULES); const rawOutput = renderRawOutput(result.graph, QUERIES, RULES, facts); fail('Compiled N3 derivation failed', { 'input evidence metadata is present and matches compiled source': meta.SourceSHA256 === "e8ecabf81463a98ebcb7a1970dfe31792d96011b5e060ad2ed6f5f02ee46a6d2", 'input evidence facts were loaded': expectedFacts > 0 ? facts.length === expectedFacts : facts.length >= 0, 'compiled rules were loaded': RULES.length === 10, 'compiled query directives were loaded': QUERIES.length === 3, 'a derivation fixpoint was reached': result.graph.facts.length >= facts.length, 'query or output facts were produced': rawOutput.length > 0 }); return { ...result, rawOutput, inputFacts: facts }; }
|
|
4313
|
-
function snapshotMarkdown(markdown) { return markdown.split(/\n/).map((line) => line ? line + ' \n' : '\n').join(''); }
|
|
4314
|
-
function prefixLinesFromTrig(trig) {
|
|
4315
|
-
const out = [];
|
|
4316
|
-
const seen = new Set();
|
|
4317
|
-
for (const rawLine of String(trig || '').split(String.fromCharCode(10))) {
|
|
4318
|
-
const trimmed = rawLine.replace(String.fromCharCode(13), '').trim();
|
|
4319
|
-
if (!trimmed.toLowerCase().startsWith('@prefix ')) continue;
|
|
4320
|
-
if (!seen.has(trimmed)) { seen.add(trimmed); out.push(trimmed); }
|
|
4321
|
-
}
|
|
4322
|
-
if (!out.some((line) => line.toLowerCase().startsWith('@prefix rdf:'))) out.push('@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .');
|
|
4323
|
-
return out;
|
|
4324
|
-
}
|
|
4325
|
-
function formalOutputFacts(graph, queries, rules, initialFacts) {
|
|
4326
|
-
const base = initialKeys(initialFacts);
|
|
4327
|
-
const out = [];
|
|
4328
|
-
const seen = new Set();
|
|
4329
|
-
const add = (fact) => {
|
|
4330
|
-
if (!fact) return;
|
|
4331
|
-
const key = factKey(fact);
|
|
4332
|
-
if (!seen.has(key)) { seen.add(key); out.push(fact); }
|
|
4333
|
-
};
|
|
4334
|
-
if (queries && queries.length) {
|
|
4335
|
-
for (const fact of queryFacts(graph, queries, rules)) add(fact);
|
|
4336
|
-
return out;
|
|
4337
|
-
}
|
|
4338
|
-
for (const fact of derivedFacts(graph, initialFacts)) add(fact);
|
|
4339
|
-
if (!out.length) {
|
|
4340
|
-
for (const fact of graph.facts) if (fact.o && fact.o.kind === 'formula' && !base.has(factKey(fact))) add(fact);
|
|
4341
|
-
}
|
|
4342
|
-
return out;
|
|
4343
|
-
}
|
|
4344
|
-
function termHasTripleTerm(term) {
|
|
4345
|
-
if (!term) return false;
|
|
4346
|
-
if (term.kind === 'triple') return true;
|
|
4347
|
-
if (term.kind === 'list') return term.items.some(termHasTripleTerm);
|
|
4348
|
-
if (term.kind === 'formula') return term.atoms.some(atomHasTripleTerm);
|
|
4349
|
-
return false;
|
|
4350
|
-
}
|
|
4351
|
-
function atomHasTripleTerm(atom) { return termHasTripleTerm(atom.s) || termHasTripleTerm(atom.p) || termHasTripleTerm(atom.o); }
|
|
4352
|
-
function factsHaveTripleTerms(facts) { return (facts || []).some(atomHasTripleTerm); }
|
|
4353
|
-
function trigHasVersion12(trig) { return /^s*(?:@version|VERSION)s+["']1.2["']/mi.test(String(trig || '')); }
|
|
4354
|
-
function trigGraphBlock(label, atoms) {
|
|
4355
|
-
const lines = [label + ' {'];
|
|
4356
|
-
for (const atom of atoms || []) lines.push(' ' + atomToN3(atom) + ' .');
|
|
4357
|
-
lines.push('}');
|
|
4358
|
-
return lines;
|
|
4359
|
-
}
|
|
4360
|
-
function formalFactToTrigLines(fact, state) {
|
|
4361
|
-
if (fact.o && fact.o.kind === 'formula') {
|
|
4362
|
-
if (isIri(fact.p, 'log:nameOf')) return trigGraphBlock(termToN3(fact.s), fact.o.atoms);
|
|
4363
|
-
state.formulaCounter += 1;
|
|
4364
|
-
state.needOutPrefix = true;
|
|
4365
|
-
const label = 'out:formula' + state.formulaCounter;
|
|
4366
|
-
return [termToN3(fact.s) + ' ' + termToN3(fact.p) + ' ' + label + ' .', '', ...trigGraphBlock(label, fact.o.atoms)];
|
|
4367
|
-
}
|
|
4368
|
-
return [codeFact(fact)];
|
|
4369
|
-
}
|
|
4370
|
-
function trigMetadataBlock(trig) {
|
|
4371
|
-
const lines = String(trig || '').split(String.fromCharCode(10));
|
|
4372
|
-
const out = [];
|
|
4373
|
-
let depth = 0;
|
|
4374
|
-
let active = false;
|
|
4375
|
-
for (const line of lines) {
|
|
4376
|
-
const trimmed = line.trim();
|
|
4377
|
-
if (!active && !trimmed.startsWith('in:metadata')) continue;
|
|
4378
|
-
active = true;
|
|
4379
|
-
out.push(line.replace(String.fromCharCode(13), ''));
|
|
4380
|
-
depth += (line.match(/{/g) || []).length;
|
|
4381
|
-
depth -= (line.match(/}/g) || []).length;
|
|
4382
|
-
if (active && depth <= 0) break;
|
|
4383
|
-
}
|
|
4384
|
-
return out.length ? out.join(String.fromCharCode(10)).trimEnd() : '';
|
|
4385
|
-
}
|
|
4386
|
-
function formalOutputToTrig(facts, trig) {
|
|
4387
|
-
const state = { formulaCounter: 0, needOutPrefix: false };
|
|
4388
|
-
const body = [];
|
|
4389
|
-
for (const fact of facts || []) {
|
|
4390
|
-
body.push(...formalFactToTrigLines(fact, state));
|
|
4391
|
-
}
|
|
4392
|
-
const metadata = trigMetadataBlock(trig);
|
|
4393
|
-
if (metadata) {
|
|
4394
|
-
if (body.length) body.push('');
|
|
4395
|
-
body.push(metadata);
|
|
4396
|
-
}
|
|
4397
|
-
if (!body.length) return '';
|
|
4398
|
-
const prefixes = prefixLinesFromTrig(trig);
|
|
4399
|
-
if (state.needOutPrefix && !prefixes.some((line) => line.toLowerCase().startsWith('@prefix out:'))) prefixes.push('@prefix out: <https://example.org/see/output#> .');
|
|
4400
|
-
const nl = String.fromCharCode(10);
|
|
4401
|
-
const version = factsHaveTripleTerms(facts) ? 'VERSION "1.2"' + nl + nl : '';
|
|
4402
|
-
return version + prefixes.join(nl) + nl + nl + body.join(nl);
|
|
4403
|
-
}
|
|
4404
|
-
function appendFormalTrigOutput(markdown, graph, queries, rules, initialFacts, data) {
|
|
4405
|
-
const trig = formalOutputToTrig(formalOutputFacts(graph, queries, rules, initialFacts), data && data.trig);
|
|
4406
|
-
if (!trig) return markdown;
|
|
4407
|
-
const nl = String.fromCharCode(10);
|
|
4408
|
-
const fence = String.fromCharCode(96).repeat(3);
|
|
4409
|
-
const fenced = trig.trimEnd().replace(new RegExp(fence, 'g'), '` ` `');
|
|
4410
|
-
return markdown.trimEnd() + nl + nl + '## Formal TriG Output' + nl + nl + fence + 'trig' + nl + fenced + nl + fence + nl;
|
|
4411
|
-
}
|
|
4412
|
-
function outputMarkdown() { const data = loadInput(NAME); const result = trustedDerivation(data); const markdown = renderPresentation(result.graph, QUERIES, RULES, result.inputFacts, TITLE, result.trace); return snapshotMarkdown(appendFormalTrigOutput(markdown, result.graph, QUERIES, RULES, result.inputFacts, data)); }
|
|
4413
|
-
function documentationMarkdown() { return DOC_MARKDOWN; }
|
|
4414
|
-
function writeArtefacts() { const outputDir = path.join(__dirname, 'output'); const docDir = path.join(__dirname, 'doc'); fs.mkdirSync(outputDir, { recursive: true }); fs.mkdirSync(docDir, { recursive: true }); fs.writeFileSync(path.join(outputDir, NAME + '.md'), outputMarkdown(), 'utf8'); fs.writeFileSync(path.join(docDir, NAME + '.md'), documentationMarkdown(), 'utf8'); }
|
|
4415
|
-
function main(argv = process.argv.slice(2)) { if (argv.includes('--write') || argv.includes('--write-files') || argv.includes('--snapshot')) { writeArtefacts(); return; } if (argv.includes('--doc')) { process.stdout.write(documentationMarkdown()); return; } process.stdout.write(outputMarkdown()); }
|
|
4416
|
-
if (require.main === module) main();
|
|
4417
|
-
module.exports = { trustedDerivation, outputMarkdown, documentationMarkdown, writeArtefacts };
|