@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.
Files changed (114) hide show
  1. package/README.md +224 -0
  2. package/dist/egpt-math-sdk.browser.js +5 -0
  3. package/dist/index.d.ts +100 -0
  4. package/dist/index.js +985 -0
  5. package/dist/notebooks/arithmetic-basics.html +166 -0
  6. package/dist/notebooks/complex-twiddle.html +148 -0
  7. package/dist/notebooks/double-slit-rosetta-qft.html +154 -0
  8. package/dist/notebooks/egpt-fft-test.html +202 -0
  9. package/dist/notebooks/egpt-matrix-test.html +241 -0
  10. package/dist/notebooks/egpt-polynomial-test.html +703 -0
  11. package/dist/notebooks/egpt-prime-composite-test.html +561 -0
  12. package/dist/notebooks/egpt-test-suite.html +1387 -0
  13. package/dist/notebooks/egpt-topology-test.html +410 -0
  14. package/dist/notebooks/factorization-basics.html +131 -0
  15. package/dist/notebooks/fft.html +155 -0
  16. package/dist/notebooks/frqtl-qft-benchmark.html +207 -0
  17. package/dist/notebooks/gallery-atomic-model.html +51 -0
  18. package/dist/notebooks/gallery-big-bang.html +62 -0
  19. package/dist/notebooks/gallery-blackbody.html +52 -0
  20. package/dist/notebooks/gallery-circuit-sat.html +104 -0
  21. package/dist/notebooks/gallery-collision-matrix-3d.html +51 -0
  22. package/dist/notebooks/gallery-double-slit.html +53 -0
  23. package/dist/notebooks/gallery-gun-chamber.html +62 -0
  24. package/dist/notebooks/gallery-particle-walk-3d.html +53 -0
  25. package/dist/notebooks/gallery-wave-interference.html +52 -0
  26. package/dist/notebooks/getting-started-hello-frqtl.html +53 -0
  27. package/dist/notebooks/iso-canonical-chain.html +203 -0
  28. package/dist/notebooks/iso-entropy-log.html +127 -0
  29. package/dist/notebooks/iso-fft-polynomial.html +136 -0
  30. package/dist/notebooks/iso-matrix-four-views.html +131 -0
  31. package/dist/notebooks/iso-number-theory-four-views.html +99 -0
  32. package/dist/notebooks/iso-pi-log-fraction-loop.html +140 -0
  33. package/dist/notebooks/matrix.html +202 -0
  34. package/dist/notebooks/notebooks.json +240 -0
  35. package/dist/notebooks/polynomials.html +201 -0
  36. package/dist/notebooks/prime-composite.html +268 -0
  37. package/dist/notebooks/rational-core.html +179 -0
  38. package/dist/notebooks/reference-egpt-fft-test.html +187 -0
  39. package/dist/notebooks/reference-order-finder-test.html +196 -0
  40. package/dist/notebooks/reference-prime-atom-polynomial-test.html +542 -0
  41. package/dist/notebooks/reference-solve-polynomial-system-test.html +471 -0
  42. package/dist/notebooks/scaled-vectors.html +112 -0
  43. package/dist/notebooks/stats.html +206 -0
  44. package/dist/notebooks/transcendentals.html +195 -0
  45. package/dist/notebooks/view-vendored-d3.html +78 -0
  46. package/dist/vendor/d3-array/src/array.js +4 -0
  47. package/dist/vendor/d3-array/src/ascending.js +3 -0
  48. package/dist/vendor/d3-array/src/bin.js +125 -0
  49. package/dist/vendor/d3-array/src/bisect.js +9 -0
  50. package/dist/vendor/d3-array/src/bisector.js +56 -0
  51. package/dist/vendor/d3-array/src/blur.js +115 -0
  52. package/dist/vendor/d3-array/src/constant.js +3 -0
  53. package/dist/vendor/d3-array/src/count.js +18 -0
  54. package/dist/vendor/d3-array/src/cross.js +33 -0
  55. package/dist/vendor/d3-array/src/cumsum.js +6 -0
  56. package/dist/vendor/d3-array/src/descending.js +7 -0
  57. package/dist/vendor/d3-array/src/deviation.js +6 -0
  58. package/dist/vendor/d3-array/src/difference.js +11 -0
  59. package/dist/vendor/d3-array/src/disjoint.js +15 -0
  60. package/dist/vendor/d3-array/src/every.js +10 -0
  61. package/dist/vendor/d3-array/src/extent.js +29 -0
  62. package/dist/vendor/d3-array/src/filter.js +11 -0
  63. package/dist/vendor/d3-array/src/fsum.js +69 -0
  64. package/dist/vendor/d3-array/src/greatest.js +29 -0
  65. package/dist/vendor/d3-array/src/greatestIndex.js +19 -0
  66. package/dist/vendor/d3-array/src/group.js +65 -0
  67. package/dist/vendor/d3-array/src/groupSort.js +10 -0
  68. package/dist/vendor/d3-array/src/identity.js +3 -0
  69. package/dist/vendor/d3-array/src/index.js +57 -0
  70. package/dist/vendor/d3-array/src/intersection.js +19 -0
  71. package/dist/vendor/d3-array/src/least.js +29 -0
  72. package/dist/vendor/d3-array/src/leastIndex.js +19 -0
  73. package/dist/vendor/d3-array/src/map.js +5 -0
  74. package/dist/vendor/d3-array/src/max.js +20 -0
  75. package/dist/vendor/d3-array/src/maxIndex.js +22 -0
  76. package/dist/vendor/d3-array/src/mean.js +19 -0
  77. package/dist/vendor/d3-array/src/median.js +9 -0
  78. package/dist/vendor/d3-array/src/merge.js +9 -0
  79. package/dist/vendor/d3-array/src/min.js +20 -0
  80. package/dist/vendor/d3-array/src/minIndex.js +22 -0
  81. package/dist/vendor/d3-array/src/mode.js +28 -0
  82. package/dist/vendor/d3-array/src/nice.js +18 -0
  83. package/dist/vendor/d3-array/src/number.js +20 -0
  84. package/dist/vendor/d3-array/src/pairs.js +15 -0
  85. package/dist/vendor/d3-array/src/permute.js +3 -0
  86. package/dist/vendor/d3-array/src/quantile.js +47 -0
  87. package/dist/vendor/d3-array/src/quickselect.js +53 -0
  88. package/dist/vendor/d3-array/src/range.js +13 -0
  89. package/dist/vendor/d3-array/src/rank.js +24 -0
  90. package/dist/vendor/d3-array/src/reduce.js +14 -0
  91. package/dist/vendor/d3-array/src/reverse.js +4 -0
  92. package/dist/vendor/d3-array/src/scan.js +6 -0
  93. package/dist/vendor/d3-array/src/shuffle.js +13 -0
  94. package/dist/vendor/d3-array/src/some.js +10 -0
  95. package/dist/vendor/d3-array/src/sort.js +39 -0
  96. package/dist/vendor/d3-array/src/subset.js +5 -0
  97. package/dist/vendor/d3-array/src/sum.js +18 -0
  98. package/dist/vendor/d3-array/src/superset.js +19 -0
  99. package/dist/vendor/d3-array/src/threshold/freedmanDiaconis.js +7 -0
  100. package/dist/vendor/d3-array/src/threshold/scott.js +7 -0
  101. package/dist/vendor/d3-array/src/threshold/sturges.js +5 -0
  102. package/dist/vendor/d3-array/src/ticks.js +55 -0
  103. package/dist/vendor/d3-array/src/transpose.js +15 -0
  104. package/dist/vendor/d3-array/src/union.js +11 -0
  105. package/dist/vendor/d3-array/src/variance.js +25 -0
  106. package/dist/vendor/d3-array/src/zip.js +5 -0
  107. package/dist/vendor/internmap/src/index.js +61 -0
  108. package/dist/vendor/manifest.json +11 -0
  109. package/dist/wasm/egpt_math_sdk_wasm.d.ts +214 -0
  110. package/dist/wasm/egpt_math_sdk_wasm.js +1120 -0
  111. package/dist/wasm/egpt_math_sdk_wasm_bg.wasm +0 -0
  112. package/dist/wasm/egpt_math_sdk_wasm_bg.wasm.d.ts +66 -0
  113. package/dist/wasm/manifest.json +5 -0
  114. package/package.json +53 -0
@@ -0,0 +1,196 @@
1
+ <frqtl-notebook version="1" title="OrderFinder — Deterministic Period Detection Test Suite">
2
+
3
+ <cell type="markdown">
4
+ # OrderFinder — Deterministic Period Detection
5
+
6
+ `OrderFinder` finds the multiplicative order of `a` in ℤ_N* — the smallest positive integer `r` such that:
7
+
8
+ > a^r ≡ 1 (mod N)
9
+
10
+ This is the **order-finding** step at the heart of Shor's algorithm and factorization via period detection. The EGPT implementation is fully deterministic: it uses the Lean-verified LFTA (Fundamental Theorem of Arithmetic via Information) path rather than quantum sampling or probabilistic peak detection.
11
+
12
+ ## The algorithm in four steps
13
+
14
+ 1. **Factor N** via `PrimeAtomPolynomial.factorize` — the LFTA polynomial samples
15
+ 2. **Compute φ(N)** (Euler's totient) via `PrimeAtomPolynomial.totient` — a closed-form LFTA identity
16
+ 3. **Enumerate divisors** of φ(N) in increasing order (Lagrange guarantees every order divides φ(N))
17
+ 4. **Return the smallest r** with a^r ≡ 1 (mod N)
18
+
19
+ No peak detection, no tolerance threshold, no backtracking. Every step is an identity on the LFTA polynomial that Lean proves sorry-free.
20
+
21
+ ## API surface
22
+
23
+ ```
24
+ OrderFinder.findOrder(a, N) → number | null
25
+ OrderFinder.verifyOrder(a, N, r) → boolean
26
+ OrderFinder.calculateSampleSize(N) → number (legacy, retained for compatibility)
27
+ ```
28
+
29
+ This notebook ports the canonical 10-case suite from `examples/reference/OrderFinderTest.js`, verifying both the returned order value and the independent round-trip check `a^r ≡ 1 (mod N)`.
30
+ </cell>
31
+
32
+ <cell type="markdown">
33
+ ## Setup — test harness
34
+
35
+ A minimal `test` / `assert` / `expectOrder` harness. Each phase cell receives `suite` from this setup cell and appends its results.
36
+ </cell>
37
+
38
+ <cell type="js" lane="math" id="of-setup" out="suite">
39
+ const { OrderFinder } = caps.math;
40
+
41
+ const results = [];
42
+
43
+ function assert(cond, msg) {
44
+ if (!cond) throw new Error(msg || 'assertion failed');
45
+ }
46
+
47
+ function test(name, fn, bucket) {
48
+ try {
49
+ fn();
50
+ bucket.push({ name, ok: true });
51
+ } catch (err) {
52
+ bucket.push({ name, ok: false, error: err.message });
53
+ }
54
+ }
55
+
56
+ function expectOrder(a, N, expected, bucket) {
57
+ test(`order(${a} mod ${N}) = ${expected}`, () => {
58
+ const r = OrderFinder.findOrder(a, N);
59
+ assert(r === expected, `expected ${expected}, got ${r}`);
60
+ assert(OrderFinder.verifyOrder(a, N, r),
61
+ `verify failed: ${a}^${r} !≡ 1 (mod ${N})`);
62
+ }, bucket);
63
+ }
64
+
65
+ return { suite: { results, assert, test, expectOrder } };
66
+ </cell>
67
+
68
+ <cell type="markdown">
69
+ ## Phase 1 — The 10 canonical PPF order-finding cases
70
+
71
+ These are the exact 10 cases ported from `PPF_Order_Finding_Proof.js`. Each assertion checks:
72
+
73
+ - The returned order equals the known expected value
74
+ - Independent round-trip verification: `a^r ≡ 1 (mod N)` holds
75
+
76
+ | Test | a | N | Expected order r |
77
+ |------|---|---|-----------------|
78
+ | 1 | 3 | 8 | 2 |
79
+ | 2 | 7 | 15 | 4 |
80
+ | 3 | 2 | 7 | 3 |
81
+ | 4 | 3 | 10 | 4 (since 3⁴ = 81 ≡ 1 mod 10) |
82
+ | 5 | 2 | 15 | 4 |
83
+ | 6 | 4 | 15 | 2 |
84
+ | 7 | 2 | 21 | 6 |
85
+ | 8 | 5 | 21 | 6 |
86
+ | 9 | 3 | 35 | 12 |
87
+ | 10 | 6 | 35 | 2 |
88
+ </cell>
89
+
90
+ <cell type="js" lane="math" id="of-phase1" in="suite" out="phase1">
91
+ const { display } = caps;
92
+ const { results, expectOrder } = inputs.suite;
93
+
94
+ const bucket = [];
95
+
96
+ expectOrder(3n, 8n, 2, bucket);
97
+ expectOrder(7n, 15n, 4, bucket);
98
+ expectOrder(2n, 7n, 3, bucket);
99
+ expectOrder(3n, 10n, 4, bucket);
100
+ expectOrder(2n, 15n, 4, bucket);
101
+ expectOrder(4n, 15n, 2, bucket);
102
+ expectOrder(2n, 21n, 6, bucket);
103
+ expectOrder(5n, 21n, 6, bucket);
104
+ expectOrder(3n, 35n, 12, bucket);
105
+ expectOrder(6n, 35n, 2, bucket);
106
+
107
+ for (const r of bucket) {
108
+ display((r.ok ? ' ok — ' : ' FAIL — ') + r.name + (r.ok ? '' : '\n ' + r.error));
109
+ results.push(r);
110
+ }
111
+
112
+ const p = bucket.filter(r => r.ok).length;
113
+ const f = bucket.filter(r => !r.ok).length;
114
+ display(`\nPhase 1: ${p}/${bucket.length} passed` + (f > 0 ? ` (${f} FAILED)` : ''));
115
+
116
+ return { phase1: bucket };
117
+ </cell>
118
+
119
+ <cell type="markdown">
120
+ ## Phase 2 — Structural checks
121
+
122
+ Three properties of the `OrderFinder` API beyond the core 10 cases:
123
+
124
+ 1. **`calculateSampleSize`** — legacy helper returns a power-of-2 value ≥ 16 (retained for compatibility with the transform era; the LFTA path does not consume a sample window)
125
+ 2. **Coprimality guard** — `findOrder(4, 8)` must throw because gcd(4, 8) = 4 ≠ 1 (4 is not in ℤ_8*)
126
+ 3. **`verifyOrder` correctly rejects** a wrong candidate order — `r = 1` is not the order of 3 mod 8, but `r = 2` is
127
+ </cell>
128
+
129
+ <cell type="js" lane="math" id="of-phase2" in="suite" out="phase2">
130
+ const { display } = caps;
131
+ const { results, assert, test } = inputs.suite;
132
+ const { OrderFinder } = caps.math;
133
+
134
+ const bucket = [];
135
+
136
+ test('calculateSampleSize(N=8) is a power of 2, >= 16', () => {
137
+ const s = OrderFinder.calculateSampleSize(8n);
138
+ assert(s >= 16 && (s & (s - 1)) === 0,
139
+ `sampleSize ${s} should be >= 16 and a power of 2`);
140
+ }, bucket);
141
+
142
+ test('coprimality check: findOrder(4, 8) throws', () => {
143
+ let threw = false;
144
+ try { OrderFinder.findOrder(4n, 8n); } catch { threw = true; }
145
+ assert(threw, 'expected non-coprime input to throw');
146
+ }, bucket);
147
+
148
+ test('verifyOrder rejects wrong r=1, accepts correct r=2 for order(3 mod 8)', () => {
149
+ assert(!OrderFinder.verifyOrder(3n, 8n, 1),
150
+ 'verify should reject r=1 for order(3, 8)=2');
151
+ assert(OrderFinder.verifyOrder(3n, 8n, 2),
152
+ 'verify should accept r=2 for order(3, 8)=2');
153
+ }, bucket);
154
+
155
+ for (const r of bucket) {
156
+ display((r.ok ? ' ok — ' : ' FAIL — ') + r.name + (r.ok ? '' : '\n ' + r.error));
157
+ results.push(r);
158
+ }
159
+
160
+ const p = bucket.filter(r => r.ok).length;
161
+ const f = bucket.filter(r => !r.ok).length;
162
+ display(`\nPhase 2: ${p}/${bucket.length} passed` + (f > 0 ? ` (${f} FAILED)` : ''));
163
+
164
+ return { phase2: bucket };
165
+ </cell>
166
+
167
+ <cell type="markdown">
168
+ ## Summary
169
+
170
+ Aggregated results across both phases. A non-zero failure count throws so the IDE surfaces the run as failed.
171
+ </cell>
172
+
173
+ <cell type="js" lane="math" id="of-summary" in="suite, phase1, phase2">
174
+ const { display } = caps;
175
+ const { results } = inputs.suite;
176
+
177
+ const total = results.length;
178
+ const passed = results.filter(r => r.ok).length;
179
+ const failed = results.filter(r => !r.ok).length;
180
+
181
+ display('='.repeat(60));
182
+ display(`TOTAL: ${passed}/${total} passed`);
183
+ if (failed > 0) {
184
+ display(`FAILED (${failed}):`);
185
+ for (const r of results.filter(r => !r.ok)) {
186
+ display(` - ${r.name}: ${r.error}`);
187
+ }
188
+ }
189
+ display('='.repeat(60));
190
+
191
+ if (failed > 0) {
192
+ throw new Error(`[OrderFinderTest] ${failed} test(s) failed`);
193
+ }
194
+ </cell>
195
+
196
+ </frqtl-notebook>