@descix/egpt-math-sdk 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +224 -0
- package/dist/egpt-math-sdk.browser.js +5 -0
- package/dist/index.d.ts +100 -0
- package/dist/index.js +985 -0
- package/dist/notebooks/arithmetic-basics.html +166 -0
- package/dist/notebooks/complex-twiddle.html +148 -0
- package/dist/notebooks/double-slit-rosetta-qft.html +154 -0
- package/dist/notebooks/egpt-fft-test.html +202 -0
- package/dist/notebooks/egpt-matrix-test.html +241 -0
- package/dist/notebooks/egpt-polynomial-test.html +703 -0
- package/dist/notebooks/egpt-prime-composite-test.html +561 -0
- package/dist/notebooks/egpt-test-suite.html +1387 -0
- package/dist/notebooks/egpt-topology-test.html +410 -0
- package/dist/notebooks/factorization-basics.html +131 -0
- package/dist/notebooks/fft.html +155 -0
- package/dist/notebooks/frqtl-qft-benchmark.html +207 -0
- package/dist/notebooks/gallery-atomic-model.html +51 -0
- package/dist/notebooks/gallery-big-bang.html +62 -0
- package/dist/notebooks/gallery-blackbody.html +52 -0
- package/dist/notebooks/gallery-circuit-sat.html +104 -0
- package/dist/notebooks/gallery-collision-matrix-3d.html +51 -0
- package/dist/notebooks/gallery-double-slit.html +53 -0
- package/dist/notebooks/gallery-gun-chamber.html +62 -0
- package/dist/notebooks/gallery-particle-walk-3d.html +53 -0
- package/dist/notebooks/gallery-wave-interference.html +52 -0
- package/dist/notebooks/getting-started-hello-frqtl.html +53 -0
- package/dist/notebooks/iso-canonical-chain.html +203 -0
- package/dist/notebooks/iso-entropy-log.html +127 -0
- package/dist/notebooks/iso-fft-polynomial.html +136 -0
- package/dist/notebooks/iso-matrix-four-views.html +131 -0
- package/dist/notebooks/iso-number-theory-four-views.html +99 -0
- package/dist/notebooks/iso-pi-log-fraction-loop.html +140 -0
- package/dist/notebooks/matrix.html +202 -0
- package/dist/notebooks/notebooks.json +240 -0
- package/dist/notebooks/polynomials.html +201 -0
- package/dist/notebooks/prime-composite.html +268 -0
- package/dist/notebooks/rational-core.html +179 -0
- package/dist/notebooks/reference-egpt-fft-test.html +187 -0
- package/dist/notebooks/reference-order-finder-test.html +196 -0
- package/dist/notebooks/reference-prime-atom-polynomial-test.html +542 -0
- package/dist/notebooks/reference-solve-polynomial-system-test.html +471 -0
- package/dist/notebooks/scaled-vectors.html +112 -0
- package/dist/notebooks/stats.html +206 -0
- package/dist/notebooks/transcendentals.html +195 -0
- package/dist/notebooks/view-vendored-d3.html +78 -0
- package/dist/vendor/d3-array/src/array.js +4 -0
- package/dist/vendor/d3-array/src/ascending.js +3 -0
- package/dist/vendor/d3-array/src/bin.js +125 -0
- package/dist/vendor/d3-array/src/bisect.js +9 -0
- package/dist/vendor/d3-array/src/bisector.js +56 -0
- package/dist/vendor/d3-array/src/blur.js +115 -0
- package/dist/vendor/d3-array/src/constant.js +3 -0
- package/dist/vendor/d3-array/src/count.js +18 -0
- package/dist/vendor/d3-array/src/cross.js +33 -0
- package/dist/vendor/d3-array/src/cumsum.js +6 -0
- package/dist/vendor/d3-array/src/descending.js +7 -0
- package/dist/vendor/d3-array/src/deviation.js +6 -0
- package/dist/vendor/d3-array/src/difference.js +11 -0
- package/dist/vendor/d3-array/src/disjoint.js +15 -0
- package/dist/vendor/d3-array/src/every.js +10 -0
- package/dist/vendor/d3-array/src/extent.js +29 -0
- package/dist/vendor/d3-array/src/filter.js +11 -0
- package/dist/vendor/d3-array/src/fsum.js +69 -0
- package/dist/vendor/d3-array/src/greatest.js +29 -0
- package/dist/vendor/d3-array/src/greatestIndex.js +19 -0
- package/dist/vendor/d3-array/src/group.js +65 -0
- package/dist/vendor/d3-array/src/groupSort.js +10 -0
- package/dist/vendor/d3-array/src/identity.js +3 -0
- package/dist/vendor/d3-array/src/index.js +57 -0
- package/dist/vendor/d3-array/src/intersection.js +19 -0
- package/dist/vendor/d3-array/src/least.js +29 -0
- package/dist/vendor/d3-array/src/leastIndex.js +19 -0
- package/dist/vendor/d3-array/src/map.js +5 -0
- package/dist/vendor/d3-array/src/max.js +20 -0
- package/dist/vendor/d3-array/src/maxIndex.js +22 -0
- package/dist/vendor/d3-array/src/mean.js +19 -0
- package/dist/vendor/d3-array/src/median.js +9 -0
- package/dist/vendor/d3-array/src/merge.js +9 -0
- package/dist/vendor/d3-array/src/min.js +20 -0
- package/dist/vendor/d3-array/src/minIndex.js +22 -0
- package/dist/vendor/d3-array/src/mode.js +28 -0
- package/dist/vendor/d3-array/src/nice.js +18 -0
- package/dist/vendor/d3-array/src/number.js +20 -0
- package/dist/vendor/d3-array/src/pairs.js +15 -0
- package/dist/vendor/d3-array/src/permute.js +3 -0
- package/dist/vendor/d3-array/src/quantile.js +47 -0
- package/dist/vendor/d3-array/src/quickselect.js +53 -0
- package/dist/vendor/d3-array/src/range.js +13 -0
- package/dist/vendor/d3-array/src/rank.js +24 -0
- package/dist/vendor/d3-array/src/reduce.js +14 -0
- package/dist/vendor/d3-array/src/reverse.js +4 -0
- package/dist/vendor/d3-array/src/scan.js +6 -0
- package/dist/vendor/d3-array/src/shuffle.js +13 -0
- package/dist/vendor/d3-array/src/some.js +10 -0
- package/dist/vendor/d3-array/src/sort.js +39 -0
- package/dist/vendor/d3-array/src/subset.js +5 -0
- package/dist/vendor/d3-array/src/sum.js +18 -0
- package/dist/vendor/d3-array/src/superset.js +19 -0
- package/dist/vendor/d3-array/src/threshold/freedmanDiaconis.js +7 -0
- package/dist/vendor/d3-array/src/threshold/scott.js +7 -0
- package/dist/vendor/d3-array/src/threshold/sturges.js +5 -0
- package/dist/vendor/d3-array/src/ticks.js +55 -0
- package/dist/vendor/d3-array/src/transpose.js +15 -0
- package/dist/vendor/d3-array/src/union.js +11 -0
- package/dist/vendor/d3-array/src/variance.js +25 -0
- package/dist/vendor/d3-array/src/zip.js +5 -0
- package/dist/vendor/internmap/src/index.js +61 -0
- package/dist/vendor/manifest.json +11 -0
- package/dist/wasm/egpt_math_sdk_wasm.d.ts +214 -0
- package/dist/wasm/egpt_math_sdk_wasm.js +1120 -0
- package/dist/wasm/egpt_math_sdk_wasm_bg.wasm +0 -0
- package/dist/wasm/egpt_math_sdk_wasm_bg.wasm.d.ts +66 -0
- package/dist/wasm/manifest.json +5 -0
- package/package.json +53 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
<frqtl-notebook version="1" title="Matrix Multiplication via the Polynomial Bijective Chain — EGPTMatrix GEMM">
|
|
2
|
+
|
|
3
|
+
<cell type="markdown">
|
|
4
|
+
# Matrix Multiplication via the Polynomial Bijective Chain
|
|
5
|
+
|
|
6
|
+
Classical matrix multiplication multiplies two *n × n* matrices in O(n³) operations, touching every element three times. EGPT takes a different route: each matrix row **is** a polynomial in coefficient form, so the dot product of two vectors becomes the (n−1)-th coefficient of a polynomial product. The entire GEMM operation routes through `EGPTPolynomial.multiply` — no Vandermonde, no Toeplitz table, no twiddle precomputation.
|
|
7
|
+
|
|
8
|
+
This is not notation — it is the implementation. The bijective chain is Lean-formalized in `Translation5.lean` (`(Matrix × Matrix) ≃ ℕ × ℕ`) with closure `{propext, Quot.sound}`. Results are exact rational arithmetic end-to-end; `toMathString()` at the output boundary reads the canonical rational form.
|
|
9
|
+
|
|
10
|
+
Every cell in this notebook reaches its compute through the single injected `math` builtin. No URL imports, no hardcoded backend labels.
|
|
11
|
+
</cell>
|
|
12
|
+
|
|
13
|
+
<cell type="js" lane="math" id="backend">
|
|
14
|
+
// Derive the active math backend — never hardcode.
|
|
15
|
+
const { math, display } = caps;
|
|
16
|
+
const backend = math.activeMathBackend;
|
|
17
|
+
display(`Active math backend (derived): ${backend}`);
|
|
18
|
+
</cell>
|
|
19
|
+
|
|
20
|
+
<cell type="markdown">
|
|
21
|
+
## 1. Constructing matrices with `EGPTMatrix.from`
|
|
22
|
+
|
|
23
|
+
`EGPTMatrix.from` accepts a rectangular array of JS values and converts each entry to an `EGPTReal`. BigInt literals (`1n`, `2n`, …) are the most explicit form for integer entries — they map directly to `EGPTReal.fromBigInt` with no numeric-precision ambiguity.
|
|
24
|
+
|
|
25
|
+
The result is a plain 2-D array of `EGPTReal` instances — a representation that is simultaneously a matrix and a polynomial system (each row is a polynomial's coefficient list).
|
|
26
|
+
</cell>
|
|
27
|
+
|
|
28
|
+
<cell type="js" lane="math" id="construct-matrices" out="A, B">
|
|
29
|
+
const { math, display } = caps;
|
|
30
|
+
const { EGPTMatrix } = math;
|
|
31
|
+
|
|
32
|
+
// A and B are the two 2×2 matrices from the original demo.
|
|
33
|
+
const A = EGPTMatrix.from([
|
|
34
|
+
[1n, 2n],
|
|
35
|
+
[3n, 4n]
|
|
36
|
+
]);
|
|
37
|
+
|
|
38
|
+
const B = EGPTMatrix.from([
|
|
39
|
+
[5n, 6n],
|
|
40
|
+
[7n, 8n]
|
|
41
|
+
]);
|
|
42
|
+
|
|
43
|
+
display('A =');
|
|
44
|
+
display(EGPTMatrix.format(A, 'A'));
|
|
45
|
+
display('B =');
|
|
46
|
+
display(EGPTMatrix.format(B, 'B'));
|
|
47
|
+
|
|
48
|
+
return { A, B };
|
|
49
|
+
</cell>
|
|
50
|
+
|
|
51
|
+
<cell type="markdown">
|
|
52
|
+
## 2. How the dot product becomes polynomial multiplication
|
|
53
|
+
|
|
54
|
+
The key identity: for two vectors **a** = [a₀, a₁, …, aₙ₋₁] and **b** = [b₀, b₁, …, bₙ₋₁], the dot product Σᵢ aᵢ·bᵢ equals the (n−1)-th coefficient of `P_a(x) · P_b_reversed(x)`, where `P_b_reversed` places the entries of **b** in reverse order as polynomial coefficients.
|
|
55
|
+
|
|
56
|
+
Convolution at index n−1 picks up exactly Σ_{i+j=n−1} aᵢ · b_{n−1−j} = Σᵢ aᵢ · bᵢ.
|
|
57
|
+
|
|
58
|
+
`EGPTMatrix.dotViaPolynomial` implements this directly; `EGPTMatrix.gemm` calls it for every (row, column) pair. No scalar multiply-and-accumulate loop, no force equation — just a coefficient extraction from a polynomial product.
|
|
59
|
+
</cell>
|
|
60
|
+
|
|
61
|
+
<cell type="js" lane="math" id="dot-product-demo" in="A, B">
|
|
62
|
+
const { math, display } = caps;
|
|
63
|
+
const { EGPTMatrix } = math;
|
|
64
|
+
const { A, B } = inputs;
|
|
65
|
+
|
|
66
|
+
// Demonstrate the dot-product identity directly on row 0 of A and col 0 of B.
|
|
67
|
+
// Row 0 of A = [1, 2]
|
|
68
|
+
// Col 0 of B = [5, 7]
|
|
69
|
+
// Expected dot = 1·5 + 2·7 = 19
|
|
70
|
+
const rowA0 = A[0]; // [EGPTReal(1), EGPTReal(2)]
|
|
71
|
+
const colB0 = [B[0][0], B[1][0]]; // [EGPTReal(5), EGPTReal(7)]
|
|
72
|
+
|
|
73
|
+
const dot = EGPTMatrix.dotViaPolynomial(rowA0, colB0);
|
|
74
|
+
display(`dot(A[0], B[:,0]) via polynomial = ${dot.toMathString()} (expected 19)`);
|
|
75
|
+
</cell>
|
|
76
|
+
|
|
77
|
+
<cell type="markdown">
|
|
78
|
+
## 3. GEMM — full matrix-matrix product
|
|
79
|
+
|
|
80
|
+
`EGPTMatrix.gemm(A, B)` computes C = A · B by applying the polynomial dot-product identity to every (row of A, column of B) pair. The result entries are exact `EGPTReal` rationals read out by `toMathString()`.
|
|
81
|
+
|
|
82
|
+
Expected result for these inputs:
|
|
83
|
+
|
|
84
|
+
```
|
|
85
|
+
A · B = [ [1·5+2·7, 1·6+2·8], = [ [19, 22],
|
|
86
|
+
[3·5+4·7, 3·6+4·8] ] [43, 50] ]
|
|
87
|
+
```
|
|
88
|
+
</cell>
|
|
89
|
+
|
|
90
|
+
<cell type="js" lane="math" id="gemm" in="A, B" out="C">
|
|
91
|
+
const { math, display } = caps;
|
|
92
|
+
const { EGPTMatrix } = math;
|
|
93
|
+
const { A, B } = inputs;
|
|
94
|
+
|
|
95
|
+
const C = EGPTMatrix.gemm(A, B);
|
|
96
|
+
|
|
97
|
+
// Render as string grid for readability.
|
|
98
|
+
const Cstr = C.map(row => row.map(v => v.toMathString()));
|
|
99
|
+
display('C = A · B (via EGPTPolynomial.multiply):');
|
|
100
|
+
display(EGPTMatrix.format(C, 'C = A·B'));
|
|
101
|
+
|
|
102
|
+
return { C };
|
|
103
|
+
</cell>
|
|
104
|
+
|
|
105
|
+
<cell type="markdown">
|
|
106
|
+
## 4. Verification — exact rational comparison
|
|
107
|
+
|
|
108
|
+
EGPT arithmetic is exact. Comparing matrix entries with `toMathString()` (or `EGPTMatrix.equals`) gives a bit-identical answer — no floating-point rounding, no tolerance band. The check below asserts the four entries of C against the expected values and throws on any mismatch (matching the original demo's error semantics).
|
|
109
|
+
</cell>
|
|
110
|
+
|
|
111
|
+
<cell type="js" lane="math" id="verify" in="C">
|
|
112
|
+
const { math, display } = caps;
|
|
113
|
+
const { C } = inputs;
|
|
114
|
+
|
|
115
|
+
const expected = [["19","22"],["43","50"]];
|
|
116
|
+
let passed = true;
|
|
117
|
+
const failures = [];
|
|
118
|
+
|
|
119
|
+
for (let i = 0; i < 2; i++) {
|
|
120
|
+
for (let j = 0; j < 2; j++) {
|
|
121
|
+
const got = C[i][j].toMathString();
|
|
122
|
+
const want = expected[i][j];
|
|
123
|
+
if (got !== want) {
|
|
124
|
+
passed = false;
|
|
125
|
+
failures.push(`C[${i}][${j}]: got ${got}, expected ${want}`);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (!passed) {
|
|
131
|
+
throw new Error("Matrix multiplication verification failed: " + failures.join("; "));
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
display(`All 4 entries verified exact: C[0][0]=19, C[0][1]=22, C[1][0]=43, C[1][1]=50`);
|
|
135
|
+
display(`Verification: PASS`);
|
|
136
|
+
</cell>
|
|
137
|
+
|
|
138
|
+
<cell type="markdown">
|
|
139
|
+
## 5. Value-representation form — the spectral surface
|
|
140
|
+
|
|
141
|
+
Every matrix has a dual: **coefficient form** (what `EGPTMatrix.from` produces) and **value-representation form** (samples at integer powers of 2). `EGPTMatrix.toValueReps` converts each row to its sample list via `EGPTPolynomial.toValueRepresentation`; `EGPTMatrix.fromValueReps` inverts via Newton divided differences.
|
|
142
|
+
|
|
143
|
+
The pair `(toValueReps, fromValueReps)` is an invertible bijection — the same entry C that GEMM produced in coefficient form round-trips through spectral form exactly.
|
|
144
|
+
</cell>
|
|
145
|
+
|
|
146
|
+
<cell type="js" lane="math" id="value-rep-roundtrip" in="A">
|
|
147
|
+
const { math, display } = caps;
|
|
148
|
+
const { EGPTMatrix } = math;
|
|
149
|
+
const { A } = inputs;
|
|
150
|
+
|
|
151
|
+
// Convert A to value-rep (spectral) form, then back to coefficient form.
|
|
152
|
+
const A_vr = EGPTMatrix.toValueReps(A);
|
|
153
|
+
const A_rt = EGPTMatrix.fromValueReps(A_vr);
|
|
154
|
+
|
|
155
|
+
display('A (original coefficient form):');
|
|
156
|
+
display(EGPTMatrix.format(A, 'A'));
|
|
157
|
+
display('A → toValueReps (sample form):');
|
|
158
|
+
display(EGPTMatrix.format(A_vr, 'A_vr'));
|
|
159
|
+
display('A_vr → fromValueReps (recovered coefficient form):');
|
|
160
|
+
display(EGPTMatrix.format(A_rt, 'A_rt'));
|
|
161
|
+
|
|
162
|
+
const roundTrips = EGPTMatrix.equals(A, A_rt);
|
|
163
|
+
display(`Round-trip exact equality (EGPTMatrix.equals): ${roundTrips ? 'PASS' : 'FAIL'}`);
|
|
164
|
+
if (!roundTrips) throw new Error('Value-rep round-trip failed — EGPTMatrix.equals returned false.');
|
|
165
|
+
</cell>
|
|
166
|
+
|
|
167
|
+
<cell type="markdown">
|
|
168
|
+
## 6. Transpose
|
|
169
|
+
|
|
170
|
+
`EGPTMatrix.transpose` swaps rows and columns. For a 2×2 matrix this is straightforward, but the implementation handles arbitrary rectangular shapes. The result is a new matrix; entries are the same `EGPTReal` objects (no copies).
|
|
171
|
+
</cell>
|
|
172
|
+
|
|
173
|
+
<cell type="js" lane="math" id="transpose" in="B">
|
|
174
|
+
const { math, display } = caps;
|
|
175
|
+
const { EGPTMatrix } = math;
|
|
176
|
+
const { B } = inputs;
|
|
177
|
+
|
|
178
|
+
const Bt = EGPTMatrix.transpose(B);
|
|
179
|
+
|
|
180
|
+
display('B:');
|
|
181
|
+
display(EGPTMatrix.format(B, 'B'));
|
|
182
|
+
display('B transposed:');
|
|
183
|
+
display(EGPTMatrix.format(Bt, 'Bᵀ'));
|
|
184
|
+
</cell>
|
|
185
|
+
|
|
186
|
+
<cell type="markdown">
|
|
187
|
+
## Summary
|
|
188
|
+
|
|
189
|
+
`EGPTMatrix.gemm` computes the matrix product by routing every dot product through `EGPTPolynomial.multiply` — extracting the (n−1)-th coefficient of the convolution. This is the operational realization of Translation5 (`(Matrix × Matrix) ≃ ℕ × ℕ`): matrix arithmetic **is** polynomial arithmetic in coefficient form, and polynomial arithmetic **is** integer arithmetic via the EGPT bijective chain.
|
|
190
|
+
|
|
191
|
+
Key methods demonstrated:
|
|
192
|
+
- `EGPTMatrix.from(rows)` — construct from BigInt / integer / EGPTReal entries
|
|
193
|
+
- `EGPTMatrix.gemm(A, B)` — polynomial-routed matrix product (exact rational)
|
|
194
|
+
- `EGPTMatrix.dotViaPolynomial(a, b)` — dot product as polynomial coefficient extraction
|
|
195
|
+
- `EGPTMatrix.toValueReps(M)` / `fromValueReps(VR)` — bijection between coefficient and spectral form
|
|
196
|
+
- `EGPTMatrix.transpose(M)` — row ↔ column swap
|
|
197
|
+
- `EGPTMatrix.equals(A, B)` — exact element-wise comparison
|
|
198
|
+
- `EGPTMatrix.format(M, label)` — render as right-aligned string grid
|
|
199
|
+
- `.toMathString()` on `EGPTReal` entries — exact canonical rational output at the output boundary
|
|
200
|
+
</cell>
|
|
201
|
+
|
|
202
|
+
</frqtl-notebook>
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 1,
|
|
3
|
+
"description": "Curated FRQTL native-notebook index. The BROWSER's list/group index ONLY \u2014 the build copies every lib/notebooks/*.html by directory enumeration (this file never decides what ships). id is the file stem (no .html); ?notebook=<id> round-trips through the presets.js sanitizer charset [a-zA-Z0-9._-].",
|
|
4
|
+
"notebooks": [
|
|
5
|
+
{
|
|
6
|
+
"id": "view-vendored-d3",
|
|
7
|
+
"file": "view-vendored-d3.html",
|
|
8
|
+
"title": "View Cell — Vendored d3-array",
|
|
9
|
+
"group": "Notebook Features"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"id": "gallery-wave-interference",
|
|
13
|
+
"file": "gallery-wave-interference.html",
|
|
14
|
+
"title": "Wave Interference",
|
|
15
|
+
"group": "Gallery"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"id": "gallery-double-slit",
|
|
19
|
+
"file": "gallery-double-slit.html",
|
|
20
|
+
"title": "Double Slit",
|
|
21
|
+
"group": "Gallery"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"id": "gallery-atomic-model",
|
|
25
|
+
"file": "gallery-atomic-model.html",
|
|
26
|
+
"title": "Atomic Model",
|
|
27
|
+
"group": "Gallery"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"id": "gallery-blackbody",
|
|
31
|
+
"file": "gallery-blackbody.html",
|
|
32
|
+
"title": "Blackbody",
|
|
33
|
+
"group": "Gallery"
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"id": "gallery-big-bang",
|
|
37
|
+
"file": "gallery-big-bang.html",
|
|
38
|
+
"title": "Big Bang",
|
|
39
|
+
"group": "Gallery"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"id": "gallery-circuit-sat",
|
|
43
|
+
"file": "gallery-circuit-sat.html",
|
|
44
|
+
"title": "Circuit SAT",
|
|
45
|
+
"group": "Gallery"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"id": "gallery-particle-walk-3d",
|
|
49
|
+
"file": "gallery-particle-walk-3d.html",
|
|
50
|
+
"title": "Particle Walk 3D",
|
|
51
|
+
"group": "Gallery"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"id": "gallery-collision-matrix-3d",
|
|
55
|
+
"file": "gallery-collision-matrix-3d.html",
|
|
56
|
+
"title": "Collision Matrix 3D",
|
|
57
|
+
"group": "Gallery"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"id": "gallery-gun-chamber",
|
|
61
|
+
"file": "gallery-gun-chamber.html",
|
|
62
|
+
"title": "Gun Chamber",
|
|
63
|
+
"group": "Gallery"
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"id": "iso-entropy-log",
|
|
67
|
+
"file": "iso-entropy-log.html",
|
|
68
|
+
"title": "E \u2014 Entropy-Log Bijection",
|
|
69
|
+
"group": "Isomorphisms"
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
"id": "iso-fft-polynomial",
|
|
73
|
+
"file": "iso-fft-polynomial.html",
|
|
74
|
+
"title": "F \u2014 FFT-Polynomial Isomorphism",
|
|
75
|
+
"group": "Isomorphisms"
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"id": "iso-matrix-four-views",
|
|
79
|
+
"file": "iso-matrix-four-views.html",
|
|
80
|
+
"title": "M \u2014 Matrix Four Views",
|
|
81
|
+
"group": "Isomorphisms"
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"id": "iso-number-theory-four-views",
|
|
85
|
+
"file": "iso-number-theory-four-views.html",
|
|
86
|
+
"title": "N \u2014 Number Theory Four Views",
|
|
87
|
+
"group": "Isomorphisms"
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
"id": "iso-canonical-chain",
|
|
91
|
+
"file": "iso-canonical-chain.html",
|
|
92
|
+
"title": "U \u2014 Canonical Chain Unified",
|
|
93
|
+
"group": "Isomorphisms"
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
"id": "iso-pi-log-fraction-loop",
|
|
97
|
+
"file": "iso-pi-log-fraction-loop.html",
|
|
98
|
+
"title": "\u03c0 \u2014 Log-Fraction Unit Loop",
|
|
99
|
+
"group": "Isomorphisms"
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
"id": "frqtl-qft-benchmark",
|
|
103
|
+
"file": "frqtl-qft-benchmark.html",
|
|
104
|
+
"title": "FRQTL QFT Benchmark (vs. supercomputer)",
|
|
105
|
+
"group": "Showcase"
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
"id": "double-slit-rosetta-qft",
|
|
109
|
+
"file": "double-slit-rosetta-qft.html",
|
|
110
|
+
"title": "Double Slit \u2192 Rosetta \u2192 QFT",
|
|
111
|
+
"group": "Showcase"
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
"id": "arithmetic-basics",
|
|
115
|
+
"file": "arithmetic-basics.html",
|
|
116
|
+
"title": "Arithmetic Basics",
|
|
117
|
+
"group": "Core Math"
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
"id": "factorization-basics",
|
|
121
|
+
"file": "factorization-basics.html",
|
|
122
|
+
"title": "Factorization Basics",
|
|
123
|
+
"group": "Core Math"
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
"id": "rational-core",
|
|
127
|
+
"file": "rational-core.html",
|
|
128
|
+
"title": "Rational Core",
|
|
129
|
+
"group": "Core Math"
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
"id": "scaled-vectors",
|
|
133
|
+
"file": "scaled-vectors.html",
|
|
134
|
+
"title": "Scaled Vectors",
|
|
135
|
+
"group": "Algebra & Vectors"
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
"id": "complex-twiddle",
|
|
139
|
+
"file": "complex-twiddle.html",
|
|
140
|
+
"title": "Complex & Twiddle",
|
|
141
|
+
"group": "Algebra & Vectors"
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
"id": "stats",
|
|
145
|
+
"file": "stats.html",
|
|
146
|
+
"title": "Statistics",
|
|
147
|
+
"group": "Statistics"
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
"id": "transcendentals",
|
|
151
|
+
"file": "transcendentals.html",
|
|
152
|
+
"title": "Transcendentals",
|
|
153
|
+
"group": "Advanced Math"
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
"id": "polynomials",
|
|
157
|
+
"file": "polynomials.html",
|
|
158
|
+
"title": "Polynomials",
|
|
159
|
+
"group": "Advanced Math"
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
"id": "fft",
|
|
163
|
+
"file": "fft.html",
|
|
164
|
+
"title": "FFT",
|
|
165
|
+
"group": "Advanced Math"
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
"id": "matrix",
|
|
169
|
+
"file": "matrix.html",
|
|
170
|
+
"title": "Matrix GEMM",
|
|
171
|
+
"group": "Advanced Math"
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
"id": "prime-composite",
|
|
175
|
+
"file": "prime-composite.html",
|
|
176
|
+
"title": "Prime Composite",
|
|
177
|
+
"group": "Advanced Math"
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
"id": "reference-egpt-fft-test",
|
|
181
|
+
"file": "reference-egpt-fft-test.html",
|
|
182
|
+
"title": "Reference: FFT Test",
|
|
183
|
+
"group": "Reference Examples"
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
"id": "reference-order-finder-test",
|
|
187
|
+
"file": "reference-order-finder-test.html",
|
|
188
|
+
"title": "Reference: Order Finder",
|
|
189
|
+
"group": "Reference Examples"
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
"id": "reference-prime-atom-polynomial-test",
|
|
193
|
+
"file": "reference-prime-atom-polynomial-test.html",
|
|
194
|
+
"title": "Reference: Prime-Atom Polynomial",
|
|
195
|
+
"group": "Reference Examples"
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
"id": "reference-solve-polynomial-system-test",
|
|
199
|
+
"file": "reference-solve-polynomial-system-test.html",
|
|
200
|
+
"title": "Reference: Solve Polynomial System",
|
|
201
|
+
"group": "Reference Examples"
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
"id": "egpt-test-suite",
|
|
205
|
+
"file": "egpt-test-suite.html",
|
|
206
|
+
"title": "EGPT Test Suite",
|
|
207
|
+
"group": "Original Test Suites"
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
"id": "egpt-polynomial-test",
|
|
211
|
+
"file": "egpt-polynomial-test.html",
|
|
212
|
+
"title": "Polynomial Test Suite",
|
|
213
|
+
"group": "Original Test Suites"
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
"id": "egpt-fft-test",
|
|
217
|
+
"file": "egpt-fft-test.html",
|
|
218
|
+
"title": "FFT Test Suite",
|
|
219
|
+
"group": "Original Test Suites"
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
"id": "egpt-matrix-test",
|
|
223
|
+
"file": "egpt-matrix-test.html",
|
|
224
|
+
"title": "Matrix Test Suite",
|
|
225
|
+
"group": "Original Test Suites"
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
"id": "egpt-prime-composite-test",
|
|
229
|
+
"file": "egpt-prime-composite-test.html",
|
|
230
|
+
"title": "Prime Composite Test Suite",
|
|
231
|
+
"group": "Original Test Suites"
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
"id": "egpt-topology-test",
|
|
235
|
+
"file": "egpt-topology-test.html",
|
|
236
|
+
"title": "Topology Test Suite",
|
|
237
|
+
"group": "Original Test Suites"
|
|
238
|
+
}
|
|
239
|
+
]
|
|
240
|
+
}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
<frqtl-notebook version="1" title="Polynomial Arithmetic in EGPT Canonical Space">
|
|
2
|
+
|
|
3
|
+
<cell type="markdown">
|
|
4
|
+
# Polynomial Arithmetic in EGPT Canonical Space
|
|
5
|
+
|
|
6
|
+
A polynomial over the EGPT number system is just a list of `EGPTReal` coefficients — `[a₀, a₁, a₂, …]` represents `a₀ + a₁x + a₂x²+ …`. All arithmetic stays in exact rational space: no floats, no decimal approximations, no rounding. Coefficients are compared with `.equals()`, never with `==` or `.toString()`.
|
|
7
|
+
|
|
8
|
+
`EGPTPolynomial` is the static class that provides these operations. Every cell below reaches it through the injected `math` builtin — no imports, no URLs.
|
|
9
|
+
|
|
10
|
+
The three fundamental operations demonstrated here are:
|
|
11
|
+
|
|
12
|
+
1. **Addition** — coefficient-wise, extended to match the longer polynomial's degree.
|
|
13
|
+
2. **Multiplication** — convolution (each pair of coefficients multiplied and accumulated at the sum-of-degree position).
|
|
14
|
+
3. **Division** — long division returning an exact `{ quotient, remainder }` pair that satisfies `dividend = divisor × quotient + remainder`.
|
|
15
|
+
</cell>
|
|
16
|
+
|
|
17
|
+
<cell type="markdown">
|
|
18
|
+
## Setup — construct the two base polynomials
|
|
19
|
+
|
|
20
|
+
We work with two simple linear polynomials:
|
|
21
|
+
|
|
22
|
+
- **poly1** = `1 + 2x`
|
|
23
|
+
- **poly2** = `3 + 4x`
|
|
24
|
+
|
|
25
|
+
Each coefficient is created from an integer via `EGPTReal.fromBigInt(n)`. This places the value in exact rational form (`numerator/denominator` internally) where the denominator is 1.
|
|
26
|
+
</cell>
|
|
27
|
+
|
|
28
|
+
<cell type="js" lane="math" id="setup" out="poly1, poly2">
|
|
29
|
+
const { math, display } = caps;
|
|
30
|
+
const { EGPTReal } = math;
|
|
31
|
+
|
|
32
|
+
// poly1 = 1 + 2x → coefficients [1, 2] (index = power of x)
|
|
33
|
+
const poly1 = [EGPTReal.fromBigInt(1n), EGPTReal.fromBigInt(2n)];
|
|
34
|
+
|
|
35
|
+
// poly2 = 3 + 4x → coefficients [3, 4]
|
|
36
|
+
const poly2 = [EGPTReal.fromBigInt(3n), EGPTReal.fromBigInt(4n)];
|
|
37
|
+
|
|
38
|
+
display(`poly1 = ${poly1.map(c => c.toMathString()).join(' + ') /* [1, 2] */}`);
|
|
39
|
+
display(`poly2 = ${poly2.map(c => c.toMathString()).join(' + ') /* [3, 4] */}`);
|
|
40
|
+
display('Coefficients are EGPTReal — exact rationals, no floating-point.');
|
|
41
|
+
|
|
42
|
+
return { poly1, poly2 };
|
|
43
|
+
</cell>
|
|
44
|
+
|
|
45
|
+
<cell type="markdown">
|
|
46
|
+
## Addition — `EGPTPolynomial.add(p1, p2)`
|
|
47
|
+
|
|
48
|
+
Adding two polynomials sums their coefficients position by position. For positions where one polynomial is shorter, the missing coefficient is treated as zero.
|
|
49
|
+
|
|
50
|
+
Expected result: `(1 + 2x) + (3 + 4x) = 4 + 6x` → coefficients `[4, 6]`.
|
|
51
|
+
</cell>
|
|
52
|
+
|
|
53
|
+
<cell type="js" lane="math" id="addition" in="poly1, poly2" out="sum">
|
|
54
|
+
const { math, display } = caps;
|
|
55
|
+
const { EGPTPolynomial } = math;
|
|
56
|
+
const { poly1, poly2 } = inputs;
|
|
57
|
+
|
|
58
|
+
const sum = EGPTPolynomial.add(poly1, poly2);
|
|
59
|
+
|
|
60
|
+
// Verify: coefficient 0 must be "4", coefficient 1 must be "6"
|
|
61
|
+
if (sum[0].toMathString() !== '4' || sum[1].toMathString() !== '6') {
|
|
62
|
+
throw new Error('Polynomial addition failed: got ' + sum.map(c => c.toMathString()));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
display('poly1 + poly2 = [' + sum.map(c => c.toMathString()).join(', ') + ']');
|
|
66
|
+
display(' = ' + sum[0].toMathString() + ' + ' + sum[1].toMathString() + 'x ✓');
|
|
67
|
+
|
|
68
|
+
return { sum };
|
|
69
|
+
</cell>
|
|
70
|
+
|
|
71
|
+
<cell type="markdown">
|
|
72
|
+
## Multiplication — `EGPTPolynomial.multiply(p1, p2)`
|
|
73
|
+
|
|
74
|
+
Polynomial multiplication is convolution: the coefficient at degree `k` in the product is the sum of all `a[i] × b[j]` where `i + j = k`.
|
|
75
|
+
|
|
76
|
+
For `(1 + 2x)(3 + 4x)`:
|
|
77
|
+
|
|
78
|
+
```
|
|
79
|
+
degree 0: 1 × 3 = 3
|
|
80
|
+
degree 1: 1 × 4 + 2 × 3 = 4 + 6 = 10
|
|
81
|
+
degree 2: 2 × 4 = 8
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Expected result: `3 + 10x + 8x²` → coefficients `[3, 10, 8]`.
|
|
85
|
+
</cell>
|
|
86
|
+
|
|
87
|
+
<cell type="js" lane="math" id="multiplication" in="poly1, poly2" out="product">
|
|
88
|
+
const { math, display } = caps;
|
|
89
|
+
const { EGPTPolynomial } = math;
|
|
90
|
+
const { poly1, poly2 } = inputs;
|
|
91
|
+
|
|
92
|
+
const product = EGPTPolynomial.multiply(poly1, poly2);
|
|
93
|
+
|
|
94
|
+
// Verify: [3, 10, 8]
|
|
95
|
+
if (
|
|
96
|
+
product[0].toMathString() !== '3' ||
|
|
97
|
+
product[1].toMathString() !== '10' ||
|
|
98
|
+
product[2].toMathString() !== '8'
|
|
99
|
+
) {
|
|
100
|
+
throw new Error('Polynomial multiplication failed: got ' + product.map(c => c.toMathString()));
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
display('poly1 × poly2 = [' + product.map(c => c.toMathString()).join(', ') + ']');
|
|
104
|
+
display(' = ' + product[0].toMathString()
|
|
105
|
+
+ ' + ' + product[1].toMathString() + 'x'
|
|
106
|
+
+ ' + ' + product[2].toMathString() + 'x² ✓');
|
|
107
|
+
|
|
108
|
+
return { product };
|
|
109
|
+
</cell>
|
|
110
|
+
|
|
111
|
+
<cell type="markdown">
|
|
112
|
+
## Division — `EGPTPolynomial.divide(dividend, divisor)`
|
|
113
|
+
|
|
114
|
+
Polynomial long division works exactly as integer long division, but at each step we divide the leading coefficient of the current remainder by the leading coefficient of the divisor. The result is always an exact rational, so no approximation ever occurs.
|
|
115
|
+
|
|
116
|
+
`divide()` returns `{ quotient, remainder }` satisfying `dividend = divisor × quotient + remainder`.
|
|
117
|
+
|
|
118
|
+
We divide the product `3 + 10x + 8x²` back by `poly1 = 1 + 2x`. Since `poly1` is one of the original factors, the quotient should recover `poly2 = 3 + 4x` exactly, with zero remainder.
|
|
119
|
+
</cell>
|
|
120
|
+
|
|
121
|
+
<cell type="js" lane="math" id="division" in="product, poly1" out="quotient, remainder">
|
|
122
|
+
const { math, display } = caps;
|
|
123
|
+
const { EGPTReal, EGPTPolynomial } = math;
|
|
124
|
+
const { product, poly1 } = inputs;
|
|
125
|
+
|
|
126
|
+
// dividend = 3 + 10x + 8x² (the product from the previous cell)
|
|
127
|
+
// divisor = 1 + 2x (poly1)
|
|
128
|
+
const dividend = product;
|
|
129
|
+
const divisor = poly1;
|
|
130
|
+
|
|
131
|
+
const { quotient, remainder } = EGPTPolynomial.divide(dividend, divisor);
|
|
132
|
+
|
|
133
|
+
// Verify quotient = [3, 4]
|
|
134
|
+
if (quotient[0].toMathString() !== '3' || quotient[1].toMathString() !== '4') {
|
|
135
|
+
throw new Error('Polynomial division quotient failed: got ' + quotient.map(c => c.toMathString()));
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const zero = EGPTReal.fromBigInt(0n);
|
|
139
|
+
const remIsZero = remainder.every(c => c.equals(zero));
|
|
140
|
+
|
|
141
|
+
display('dividend ÷ divisor:');
|
|
142
|
+
display(' quotient = [' + quotient.map(c => c.toMathString()).join(', ') + '] → '
|
|
143
|
+
+ quotient[0].toMathString() + ' + ' + quotient[1].toMathString() + 'x');
|
|
144
|
+
display(' remainder = [' + remainder.map(c => c.toMathString()).join(', ') + '] → '
|
|
145
|
+
+ (remIsZero ? 'zero (exact division) ✓' : 'non-zero'));
|
|
146
|
+
display('');
|
|
147
|
+
display('The quotient recovers poly2 exactly — division is the inverse of multiplication in EGPT canonical space.');
|
|
148
|
+
|
|
149
|
+
return { quotient, remainder };
|
|
150
|
+
</cell>
|
|
151
|
+
|
|
152
|
+
<cell type="markdown">
|
|
153
|
+
## Summary — all four results
|
|
154
|
+
|
|
155
|
+
The final cell collects the results and confirms they match the expected values from the source example.
|
|
156
|
+
|
|
157
|
+
| Operation | Expression | Result (coefficients) |
|
|
158
|
+
|---|---|---|
|
|
159
|
+
| Addition | `(1+2x) + (3+4x)` | `[4, 6]` = `4 + 6x` |
|
|
160
|
+
| Multiplication | `(1+2x) × (3+4x)` | `[3, 10, 8]` = `3 + 10x + 8x²` |
|
|
161
|
+
| Division (quotient) | `(3+10x+8x²) ÷ (1+2x)` | `[3, 4]` = `3 + 4x` |
|
|
162
|
+
| Division (remainder) | — | `[0]` (exact) |
|
|
163
|
+
</cell>
|
|
164
|
+
|
|
165
|
+
<cell type="js" lane="math" id="summary" in="sum, product, quotient, remainder">
|
|
166
|
+
const { math, display } = caps;
|
|
167
|
+
const { EGPTReal } = math;
|
|
168
|
+
const { sum, product, quotient, remainder } = inputs;
|
|
169
|
+
|
|
170
|
+
const zero = EGPTReal.fromBigInt(0n);
|
|
171
|
+
const remIsZero = remainder.every(c => c.equals(zero));
|
|
172
|
+
|
|
173
|
+
const result = {
|
|
174
|
+
category: 'polynomials',
|
|
175
|
+
sum: sum.map(c => c.toMathString()),
|
|
176
|
+
product: product.map(c => c.toMathString()),
|
|
177
|
+
quotient: quotient.map(c => c.toMathString()),
|
|
178
|
+
remainder: remainder.map(c => c.toMathString())
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
const allPass =
|
|
182
|
+
result.sum[0] === '4' && result.sum[1] === '6' &&
|
|
183
|
+
result.product[0] === '3' && result.product[1] === '10' && result.product[2] === '8' &&
|
|
184
|
+
result.quotient[0]=== '3' && result.quotient[1]=== '4' &&
|
|
185
|
+
remIsZero;
|
|
186
|
+
|
|
187
|
+
display(result);
|
|
188
|
+
|
|
189
|
+
const el = document.createElement('div');
|
|
190
|
+
el.style.cssText =
|
|
191
|
+
'font:600 0.95rem/1.5 system-ui,sans-serif;padding:10px 14px;border-radius:6px;margin:4px 0;' +
|
|
192
|
+
(allPass
|
|
193
|
+
? 'background:#0f2417;border:1px solid #1f5a36;color:#7ee2a8;'
|
|
194
|
+
: 'background:#2a0c0c;border:1px solid #5a1f1f;color:#ff8a8a;');
|
|
195
|
+
el.textContent = allPass
|
|
196
|
+
? 'ALL CHECKS PASS — polynomial add / multiply / divide verified in exact rational space.'
|
|
197
|
+
: 'ONE OR MORE CHECKS FAILED — see individual cells for details.';
|
|
198
|
+
display(el);
|
|
199
|
+
</cell>
|
|
200
|
+
|
|
201
|
+
</frqtl-notebook>
|