eyeling 1.11.22 → 1.11.23
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.
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# ==========================================================
|
|
2
|
+
# Matiyasevich (1985): π from Fibonacci numbers
|
|
3
|
+
#
|
|
4
|
+
# Illustrates the identity:
|
|
5
|
+
# π = 4 * Σ_{n≥1} atan( 1 / F_{2n+1} )
|
|
6
|
+
# where F_k is the k-th Fibonacci number.
|
|
7
|
+
#
|
|
8
|
+
# This N3 program computes a finite partial sum using the list
|
|
9
|
+
# of n values in :run :ns, and compares it with π = 4*atan(1).
|
|
10
|
+
#
|
|
11
|
+
# Notes:
|
|
12
|
+
# - To keep reasoners terminating, Fibonacci computation is gated:
|
|
13
|
+
# only indices reachable from the required {2n+1} set are derived.
|
|
14
|
+
# ==========================================================
|
|
15
|
+
|
|
16
|
+
@prefix : <http://example.org/matiyasevich#>.
|
|
17
|
+
@prefix math: <http://www.w3.org/2000/10/swap/math#>.
|
|
18
|
+
@prefix list: <http://www.w3.org/2000/10/swap/list#>.
|
|
19
|
+
@prefix log: <http://www.w3.org/2000/10/swap/log#>.
|
|
20
|
+
|
|
21
|
+
:run :ns (1 2 3 4 5 6 7 8 9 10 11 12 13 14 15).
|
|
22
|
+
|
|
23
|
+
# --- Determine which Fibonacci indices are needed: k = 2n+1 ----------
|
|
24
|
+
{
|
|
25
|
+
:run :ns ?Ns0.
|
|
26
|
+
?Ns0 list:iterate (?i0 ?n0).
|
|
27
|
+
|
|
28
|
+
(2 ?n0) math:product ?twoN0.
|
|
29
|
+
(?twoN0 1) math:sum ?k0.
|
|
30
|
+
}
|
|
31
|
+
=>
|
|
32
|
+
{
|
|
33
|
+
:need :fibIndex ?k0.
|
|
34
|
+
}.
|
|
35
|
+
|
|
36
|
+
# --- Close the needed set downward: if we need n, we also need n-1 and n-2 ----
|
|
37
|
+
{
|
|
38
|
+
:need :fibIndex ?nN.
|
|
39
|
+
?nN math:greaterThan 1.
|
|
40
|
+
|
|
41
|
+
(?nN 1) math:difference ?n1N.
|
|
42
|
+
(?nN 2) math:difference ?n2N.
|
|
43
|
+
}
|
|
44
|
+
=>
|
|
45
|
+
{
|
|
46
|
+
:need :fibIndex ?n1N.
|
|
47
|
+
:need :fibIndex ?n2N.
|
|
48
|
+
}.
|
|
49
|
+
|
|
50
|
+
# --- Fibonacci facts, computed only for indices requested via :need :fibIndex ----
|
|
51
|
+
{
|
|
52
|
+
:need :fibIndex 0.
|
|
53
|
+
}
|
|
54
|
+
=>
|
|
55
|
+
{
|
|
56
|
+
0 :fib 0.
|
|
57
|
+
}.
|
|
58
|
+
|
|
59
|
+
{
|
|
60
|
+
:need :fibIndex 1.
|
|
61
|
+
}
|
|
62
|
+
=>
|
|
63
|
+
{
|
|
64
|
+
1 :fib 1.
|
|
65
|
+
}.
|
|
66
|
+
|
|
67
|
+
{
|
|
68
|
+
:need :fibIndex ?nF.
|
|
69
|
+
?nF math:greaterThan 1.
|
|
70
|
+
|
|
71
|
+
(?nF 1) math:difference ?n1F.
|
|
72
|
+
(?nF 2) math:difference ?n2F.
|
|
73
|
+
|
|
74
|
+
?n1F :fib ?f1F.
|
|
75
|
+
?n2F :fib ?f2F.
|
|
76
|
+
(?f1F ?f2F) math:sum ?fnF.
|
|
77
|
+
}
|
|
78
|
+
=>
|
|
79
|
+
{
|
|
80
|
+
?nF :fib ?fnF.
|
|
81
|
+
}.
|
|
82
|
+
|
|
83
|
+
# --- Final: collect terms, sum angles, approximate pi, and compute error ----
|
|
84
|
+
{
|
|
85
|
+
:run :ns ?Ns.
|
|
86
|
+
|
|
87
|
+
# Rows: (n k F_k theta_n) with theta_n = atan(1/F_k)
|
|
88
|
+
( (?n ?k ?F ?theta)
|
|
89
|
+
{
|
|
90
|
+
:run :ns ?Ns.
|
|
91
|
+
?Ns list:iterate (?i ?n).
|
|
92
|
+
|
|
93
|
+
(2 ?n) math:product ?twoN.
|
|
94
|
+
(?twoN 1) math:sum ?k.
|
|
95
|
+
|
|
96
|
+
?k :fib ?F.
|
|
97
|
+
(1 ?F) math:quotient ?inv.
|
|
98
|
+
?inv math:atan ?theta.
|
|
99
|
+
}
|
|
100
|
+
?rows
|
|
101
|
+
) log:collectAllIn _:rowsScope.
|
|
102
|
+
|
|
103
|
+
# Angles only, to sum
|
|
104
|
+
( ?theta2
|
|
105
|
+
{
|
|
106
|
+
:run :ns ?Ns.
|
|
107
|
+
?Ns list:iterate (?i2 ?n2).
|
|
108
|
+
|
|
109
|
+
(2 ?n2) math:product ?twoN2.
|
|
110
|
+
(?twoN2 1) math:sum ?k2.
|
|
111
|
+
|
|
112
|
+
?k2 :fib ?F2.
|
|
113
|
+
(1 ?F2) math:quotient ?inv2.
|
|
114
|
+
?inv2 math:atan ?theta2.
|
|
115
|
+
}
|
|
116
|
+
?thetas
|
|
117
|
+
) log:collectAllIn _:thetaScope.
|
|
118
|
+
|
|
119
|
+
# A small “grounding” guard: list:length requires the list input be present.
|
|
120
|
+
?thetas list:length ?len.
|
|
121
|
+
|
|
122
|
+
?thetas math:sum ?sumAngles.
|
|
123
|
+
(4 ?sumAngles) math:product ?piFromFibs.
|
|
124
|
+
|
|
125
|
+
# Reference value: atan(1) = pi/4 => pi = 4*atan(1)
|
|
126
|
+
1 math:atan ?atan1.
|
|
127
|
+
(4 ?atan1) math:product ?piRef.
|
|
128
|
+
|
|
129
|
+
(?piFromFibs ?piRef) math:difference ?delta.
|
|
130
|
+
?delta math:absoluteValue ?absError.
|
|
131
|
+
}
|
|
132
|
+
=>
|
|
133
|
+
{
|
|
134
|
+
:result
|
|
135
|
+
:rows ?rows;
|
|
136
|
+
:piFromFibs ?piFromFibs;
|
|
137
|
+
:piRef ?piRef;
|
|
138
|
+
:absError ?absError.
|
|
139
|
+
}.
|
|
140
|
+
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
@prefix : <http://example.org/matiyasevich#> .
|
|
2
|
+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
|
|
3
|
+
|
|
4
|
+
:need :fibIndex 3 .
|
|
5
|
+
:need :fibIndex 5 .
|
|
6
|
+
:need :fibIndex 7 .
|
|
7
|
+
:need :fibIndex 9 .
|
|
8
|
+
:need :fibIndex 11 .
|
|
9
|
+
:need :fibIndex 13 .
|
|
10
|
+
:need :fibIndex 15 .
|
|
11
|
+
:need :fibIndex 17 .
|
|
12
|
+
:need :fibIndex 19 .
|
|
13
|
+
:need :fibIndex 21 .
|
|
14
|
+
:need :fibIndex 23 .
|
|
15
|
+
:need :fibIndex 25 .
|
|
16
|
+
:need :fibIndex 27 .
|
|
17
|
+
:need :fibIndex 29 .
|
|
18
|
+
:need :fibIndex 31 .
|
|
19
|
+
:need :fibIndex 2 .
|
|
20
|
+
:need :fibIndex 1 .
|
|
21
|
+
:need :fibIndex 4 .
|
|
22
|
+
:need :fibIndex 6 .
|
|
23
|
+
:need :fibIndex 8 .
|
|
24
|
+
:need :fibIndex 10 .
|
|
25
|
+
:need :fibIndex 12 .
|
|
26
|
+
:need :fibIndex 14 .
|
|
27
|
+
:need :fibIndex 16 .
|
|
28
|
+
:need :fibIndex 18 .
|
|
29
|
+
:need :fibIndex 20 .
|
|
30
|
+
:need :fibIndex 22 .
|
|
31
|
+
:need :fibIndex 24 .
|
|
32
|
+
:need :fibIndex 26 .
|
|
33
|
+
:need :fibIndex 28 .
|
|
34
|
+
:need :fibIndex 30 .
|
|
35
|
+
1 :fib 1 .
|
|
36
|
+
:need :fibIndex 0 .
|
|
37
|
+
0 :fib 0 .
|
|
38
|
+
2 :fib 1 .
|
|
39
|
+
3 :fib 2 .
|
|
40
|
+
4 :fib 3 .
|
|
41
|
+
5 :fib 5 .
|
|
42
|
+
6 :fib 8 .
|
|
43
|
+
7 :fib 13 .
|
|
44
|
+
8 :fib 21 .
|
|
45
|
+
9 :fib 34 .
|
|
46
|
+
10 :fib 55 .
|
|
47
|
+
11 :fib 89 .
|
|
48
|
+
12 :fib 144 .
|
|
49
|
+
13 :fib 233 .
|
|
50
|
+
14 :fib 377 .
|
|
51
|
+
15 :fib 610 .
|
|
52
|
+
16 :fib 987 .
|
|
53
|
+
17 :fib 1597 .
|
|
54
|
+
18 :fib 2584 .
|
|
55
|
+
19 :fib 4181 .
|
|
56
|
+
20 :fib 6765 .
|
|
57
|
+
21 :fib 10946 .
|
|
58
|
+
22 :fib 17711 .
|
|
59
|
+
23 :fib 28657 .
|
|
60
|
+
24 :fib 46368 .
|
|
61
|
+
25 :fib 75025 .
|
|
62
|
+
26 :fib 121393 .
|
|
63
|
+
27 :fib 196418 .
|
|
64
|
+
28 :fib 317811 .
|
|
65
|
+
29 :fib 514229 .
|
|
66
|
+
30 :fib 832040 .
|
|
67
|
+
31 :fib 1346269 .
|
|
68
|
+
:result :rows ((1 3 2 "0.4636476090008061"^^xsd:decimal) (2 5 5 "0.19739555984988078"^^xsd:decimal) (3 7 13 "0.07677189126977804"^^xsd:decimal) (4 9 34 "0.029403288204005115"^^xsd:decimal) (5 11 89 "0.011235482257962729"^^xsd:decimal) (6 13 233 "0.004291819142011206"^^xsd:decimal) (7 15 610 "0.0016393427937457503"^^xsd:decimal) (8 17 1597 "0.0006261739945535625"^^xsd:decimal) (9 19 4181 "0.00023917722576690222"^^xsd:decimal) (10 21 10946 "0.00009135757328868366"^^xsd:decimal) (11 23 28657 "0.000034895487999235846"^^xsd:decimal) (12 25 75025 "0.000013328890369087375"^^xsd:decimal) (13 27 196418 "0.0000050911830890822634"^^xsd:decimal) (14 29 514229 "0.000001944658897103702"^^xsd:decimal) (15 31 1346269 "7.427936021700092e-7"^^xsd:decimal)) .
|
|
69
|
+
:result :piFromFibs "3.1415908173030225"^^xsd:decimal .
|
|
70
|
+
:result :piRef "3.141592653589793"^^xsd:decimal .
|
|
71
|
+
:result :absError "0.000001836286770640072"^^xsd:decimal .
|
package/package.json
CHANGED
package/test/manifest.test.js
CHANGED
|
@@ -109,15 +109,7 @@ function rmrf(p) {
|
|
|
109
109
|
}
|
|
110
110
|
ok(`npm ci ${C.dim}(${r.ms} ms)${C.n}`);
|
|
111
111
|
|
|
112
|
-
// 3)
|
|
113
|
-
r = run('npm', ['run', 'build'], { cwd: ROOT });
|
|
114
|
-
if (r.status !== 0) {
|
|
115
|
-
fail(`npm run build failed (exit ${r.status})`);
|
|
116
|
-
rmrf(workDir);
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
ok(`built eyeling ${C.dim}(${r.ms} ms)${C.n}`);
|
|
120
|
-
|
|
112
|
+
// 3) Pack local Eyeling
|
|
121
113
|
const pack = runCapture('npm', ['pack', '--silent'], {
|
|
122
114
|
cwd: ROOT,
|
|
123
115
|
stdio: ['ignore', 'pipe', 'pipe'],
|