@stevenvo780/st-lang 4.11.0 → 4.12.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 (209) hide show
  1. package/dist/proof-systems/fol-prover-advanced/index.d.ts +7 -0
  2. package/dist/proof-systems/fol-prover-advanced/index.d.ts.map +1 -0
  3. package/dist/proof-systems/fol-prover-advanced/index.js +34 -0
  4. package/dist/proof-systems/fol-prover-advanced/index.js.map +1 -0
  5. package/dist/proof-systems/fol-prover-advanced/ordering.d.ts +34 -0
  6. package/dist/proof-systems/fol-prover-advanced/ordering.d.ts.map +1 -0
  7. package/dist/proof-systems/fol-prover-advanced/ordering.js +197 -0
  8. package/dist/proof-systems/fol-prover-advanced/ordering.js.map +1 -0
  9. package/dist/proof-systems/fol-prover-advanced/prover.d.ts +22 -0
  10. package/dist/proof-systems/fol-prover-advanced/prover.d.ts.map +1 -0
  11. package/dist/proof-systems/fol-prover-advanced/prover.js +219 -0
  12. package/dist/proof-systems/fol-prover-advanced/prover.js.map +1 -0
  13. package/dist/proof-systems/fol-prover-advanced/resolve.d.ts +43 -0
  14. package/dist/proof-systems/fol-prover-advanced/resolve.d.ts.map +1 -0
  15. package/dist/proof-systems/fol-prover-advanced/resolve.js +297 -0
  16. package/dist/proof-systems/fol-prover-advanced/resolve.js.map +1 -0
  17. package/dist/proof-systems/fol-prover-advanced/subsumption.d.ts +28 -0
  18. package/dist/proof-systems/fol-prover-advanced/subsumption.d.ts.map +1 -0
  19. package/dist/proof-systems/fol-prover-advanced/subsumption.js +172 -0
  20. package/dist/proof-systems/fol-prover-advanced/subsumption.js.map +1 -0
  21. package/dist/proof-systems/fol-prover-advanced/types.d.ts +68 -0
  22. package/dist/proof-systems/fol-prover-advanced/types.d.ts.map +1 -0
  23. package/dist/proof-systems/fol-prover-advanced/types.js +12 -0
  24. package/dist/proof-systems/fol-prover-advanced/types.js.map +1 -0
  25. package/dist/proof-systems/fol-prover-advanced/unify.d.ts +15 -0
  26. package/dist/proof-systems/fol-prover-advanced/unify.d.ts.map +1 -0
  27. package/dist/proof-systems/fol-prover-advanced/unify.js +144 -0
  28. package/dist/proof-systems/fol-prover-advanced/unify.js.map +1 -0
  29. package/dist/reasoning/combinatorics/basic-counts.d.ts +6 -0
  30. package/dist/reasoning/combinatorics/basic-counts.d.ts.map +1 -0
  31. package/dist/reasoning/combinatorics/basic-counts.js +82 -0
  32. package/dist/reasoning/combinatorics/basic-counts.js.map +1 -0
  33. package/dist/reasoning/combinatorics/bigint-helpers.d.ts +5 -0
  34. package/dist/reasoning/combinatorics/bigint-helpers.d.ts.map +1 -0
  35. package/dist/reasoning/combinatorics/bigint-helpers.js +8 -0
  36. package/dist/reasoning/combinatorics/bigint-helpers.js.map +1 -0
  37. package/dist/reasoning/combinatorics/burnside.d.ts +15 -0
  38. package/dist/reasoning/combinatorics/burnside.d.ts.map +1 -0
  39. package/dist/reasoning/combinatorics/burnside.js +91 -0
  40. package/dist/reasoning/combinatorics/burnside.js.map +1 -0
  41. package/dist/reasoning/combinatorics/generating-functions.d.ts +12 -0
  42. package/dist/reasoning/combinatorics/generating-functions.d.ts.map +1 -0
  43. package/dist/reasoning/combinatorics/generating-functions.js +67 -0
  44. package/dist/reasoning/combinatorics/generating-functions.js.map +1 -0
  45. package/dist/reasoning/combinatorics/generators.d.ts +5 -0
  46. package/dist/reasoning/combinatorics/generators.d.ts.map +1 -0
  47. package/dist/reasoning/combinatorics/generators.js +111 -0
  48. package/dist/reasoning/combinatorics/generators.js.map +1 -0
  49. package/dist/reasoning/combinatorics/inclusion-exclusion.d.ts +8 -0
  50. package/dist/reasoning/combinatorics/inclusion-exclusion.d.ts.map +1 -0
  51. package/dist/reasoning/combinatorics/inclusion-exclusion.js +45 -0
  52. package/dist/reasoning/combinatorics/inclusion-exclusion.js.map +1 -0
  53. package/dist/reasoning/combinatorics/index.d.ts +10 -0
  54. package/dist/reasoning/combinatorics/index.d.ts.map +1 -0
  55. package/dist/reasoning/combinatorics/index.js +44 -0
  56. package/dist/reasoning/combinatorics/index.js.map +1 -0
  57. package/dist/reasoning/combinatorics/partitions.d.ts +4 -0
  58. package/dist/reasoning/combinatorics/partitions.d.ts.map +1 -0
  59. package/dist/reasoning/combinatorics/partitions.js +90 -0
  60. package/dist/reasoning/combinatorics/partitions.js.map +1 -0
  61. package/dist/reasoning/combinatorics/permutations.d.ts +6 -0
  62. package/dist/reasoning/combinatorics/permutations.d.ts.map +1 -0
  63. package/dist/reasoning/combinatorics/permutations.js +124 -0
  64. package/dist/reasoning/combinatorics/permutations.js.map +1 -0
  65. package/dist/reasoning/combinatorics/set-partitions.d.ts +3 -0
  66. package/dist/reasoning/combinatorics/set-partitions.d.ts.map +1 -0
  67. package/dist/reasoning/combinatorics/set-partitions.js +46 -0
  68. package/dist/reasoning/combinatorics/set-partitions.js.map +1 -0
  69. package/dist/reasoning/combinatorics/special-numbers.d.ts +7 -0
  70. package/dist/reasoning/combinatorics/special-numbers.d.ts.map +1 -0
  71. package/dist/reasoning/combinatorics/special-numbers.js +128 -0
  72. package/dist/reasoning/combinatorics/special-numbers.js.map +1 -0
  73. package/dist/reasoning/constructive-analysis/cauchy.d.ts +51 -0
  74. package/dist/reasoning/constructive-analysis/cauchy.d.ts.map +1 -0
  75. package/dist/reasoning/constructive-analysis/cauchy.js +77 -0
  76. package/dist/reasoning/constructive-analysis/cauchy.js.map +1 -0
  77. package/dist/reasoning/constructive-analysis/compact.d.ts +35 -0
  78. package/dist/reasoning/constructive-analysis/compact.d.ts.map +1 -0
  79. package/dist/reasoning/constructive-analysis/compact.js +61 -0
  80. package/dist/reasoning/constructive-analysis/compact.js.map +1 -0
  81. package/dist/reasoning/constructive-analysis/continuity.d.ts +62 -0
  82. package/dist/reasoning/constructive-analysis/continuity.d.ts.map +1 -0
  83. package/dist/reasoning/constructive-analysis/continuity.js +112 -0
  84. package/dist/reasoning/constructive-analysis/continuity.js.map +1 -0
  85. package/dist/reasoning/constructive-analysis/index.d.ts +24 -0
  86. package/dist/reasoning/constructive-analysis/index.d.ts.map +1 -0
  87. package/dist/reasoning/constructive-analysis/index.js +36 -0
  88. package/dist/reasoning/constructive-analysis/index.js.map +1 -0
  89. package/dist/reasoning/constructive-analysis/integral.d.ts +31 -0
  90. package/dist/reasoning/constructive-analysis/integral.d.ts.map +1 -0
  91. package/dist/reasoning/constructive-analysis/integral.js +59 -0
  92. package/dist/reasoning/constructive-analysis/integral.js.map +1 -0
  93. package/dist/reasoning/constructive-analysis/ivt.d.ts +41 -0
  94. package/dist/reasoning/constructive-analysis/ivt.d.ts.map +1 -0
  95. package/dist/reasoning/constructive-analysis/ivt.js +115 -0
  96. package/dist/reasoning/constructive-analysis/ivt.js.map +1 -0
  97. package/dist/reasoning/constructive-reals/index.d.ts +23 -0
  98. package/dist/reasoning/constructive-reals/index.d.ts.map +1 -1
  99. package/dist/reasoning/constructive-reals/index.js +52 -1
  100. package/dist/reasoning/constructive-reals/index.js.map +1 -1
  101. package/dist/reasoning/linear-algebra/index.d.ts +69 -0
  102. package/dist/reasoning/linear-algebra/index.d.ts.map +1 -0
  103. package/dist/reasoning/linear-algebra/index.js +859 -0
  104. package/dist/reasoning/linear-algebra/index.js.map +1 -0
  105. package/dist/reasoning/set-theory/hf-functions.d.ts +35 -0
  106. package/dist/reasoning/set-theory/hf-functions.d.ts.map +1 -0
  107. package/dist/reasoning/set-theory/hf-functions.js +147 -0
  108. package/dist/reasoning/set-theory/hf-functions.js.map +1 -0
  109. package/dist/reasoning/set-theory/hf-sets.d.ts +79 -0
  110. package/dist/reasoning/set-theory/hf-sets.d.ts.map +1 -0
  111. package/dist/reasoning/set-theory/hf-sets.js +338 -0
  112. package/dist/reasoning/set-theory/hf-sets.js.map +1 -0
  113. package/dist/reasoning/set-theory/index.d.ts +7 -0
  114. package/dist/reasoning/set-theory/index.d.ts.map +1 -0
  115. package/dist/reasoning/set-theory/index.js +44 -0
  116. package/dist/reasoning/set-theory/index.js.map +1 -0
  117. package/dist/reasoning/set-theory/zfc-axioms.d.ts +59 -0
  118. package/dist/reasoning/set-theory/zfc-axioms.d.ts.map +1 -0
  119. package/dist/reasoning/set-theory/zfc-axioms.js +245 -0
  120. package/dist/reasoning/set-theory/zfc-axioms.js.map +1 -0
  121. package/dist/tests/proof-systems/fol-prover-advanced/prover.test.d.ts +2 -0
  122. package/dist/tests/proof-systems/fol-prover-advanced/prover.test.d.ts.map +1 -0
  123. package/dist/tests/proof-systems/fol-prover-advanced/prover.test.js +253 -0
  124. package/dist/tests/proof-systems/fol-prover-advanced/prover.test.js.map +1 -0
  125. package/dist/tests/reasoning/combinatorics/combinatorics.test.d.ts +2 -0
  126. package/dist/tests/reasoning/combinatorics/combinatorics.test.d.ts.map +1 -0
  127. package/dist/tests/reasoning/combinatorics/combinatorics.test.js +256 -0
  128. package/dist/tests/reasoning/combinatorics/combinatorics.test.js.map +1 -0
  129. package/dist/tests/reasoning/constructive-analysis/constructive-analysis.test.d.ts +2 -0
  130. package/dist/tests/reasoning/constructive-analysis/constructive-analysis.test.d.ts.map +1 -0
  131. package/dist/tests/reasoning/constructive-analysis/constructive-analysis.test.js +174 -0
  132. package/dist/tests/reasoning/constructive-analysis/constructive-analysis.test.js.map +1 -0
  133. package/dist/tests/reasoning/linear-algebra/linear-algebra.test.d.ts +2 -0
  134. package/dist/tests/reasoning/linear-algebra/linear-algebra.test.d.ts.map +1 -0
  135. package/dist/tests/reasoning/linear-algebra/linear-algebra.test.js +369 -0
  136. package/dist/tests/reasoning/linear-algebra/linear-algebra.test.js.map +1 -0
  137. package/dist/tests/reasoning/set-theory/hf-functions.test.d.ts +2 -0
  138. package/dist/tests/reasoning/set-theory/hf-functions.test.d.ts.map +1 -0
  139. package/dist/tests/reasoning/set-theory/hf-functions.test.js +122 -0
  140. package/dist/tests/reasoning/set-theory/hf-functions.test.js.map +1 -0
  141. package/dist/tests/reasoning/set-theory/hf-sets.test.d.ts +2 -0
  142. package/dist/tests/reasoning/set-theory/hf-sets.test.d.ts.map +1 -0
  143. package/dist/tests/reasoning/set-theory/hf-sets.test.js +177 -0
  144. package/dist/tests/reasoning/set-theory/hf-sets.test.js.map +1 -0
  145. package/dist/tests/reasoning/set-theory/zfc-axioms.test.d.ts +2 -0
  146. package/dist/tests/reasoning/set-theory/zfc-axioms.test.d.ts.map +1 -0
  147. package/dist/tests/reasoning/set-theory/zfc-axioms.test.js +56 -0
  148. package/dist/tests/reasoning/set-theory/zfc-axioms.test.js.map +1 -0
  149. package/dist/tests/tooling/doc-gen/doc-gen.test.d.ts +2 -0
  150. package/dist/tests/tooling/doc-gen/doc-gen.test.d.ts.map +1 -0
  151. package/dist/tests/tooling/doc-gen/doc-gen.test.js +350 -0
  152. package/dist/tests/tooling/doc-gen/doc-gen.test.js.map +1 -0
  153. package/dist/tests/tooling/test-harness/test-harness.test.d.ts +2 -0
  154. package/dist/tests/tooling/test-harness/test-harness.test.d.ts.map +1 -0
  155. package/dist/tests/tooling/test-harness/test-harness.test.js +208 -0
  156. package/dist/tests/tooling/test-harness/test-harness.test.js.map +1 -0
  157. package/dist/tooling/doc-gen/extract.d.ts +13 -0
  158. package/dist/tooling/doc-gen/extract.d.ts.map +1 -0
  159. package/dist/tooling/doc-gen/extract.js +379 -0
  160. package/dist/tooling/doc-gen/extract.js.map +1 -0
  161. package/dist/tooling/doc-gen/generate.d.ts +9 -0
  162. package/dist/tooling/doc-gen/generate.d.ts.map +1 -0
  163. package/dist/tooling/doc-gen/generate.js +116 -0
  164. package/dist/tooling/doc-gen/generate.js.map +1 -0
  165. package/dist/tooling/doc-gen/index.d.ts +7 -0
  166. package/dist/tooling/doc-gen/index.d.ts.map +1 -0
  167. package/dist/tooling/doc-gen/index.js +39 -0
  168. package/dist/tooling/doc-gen/index.js.map +1 -0
  169. package/dist/tooling/doc-gen/jsdoc.d.ts +31 -0
  170. package/dist/tooling/doc-gen/jsdoc.d.ts.map +1 -0
  171. package/dist/tooling/doc-gen/jsdoc.js +140 -0
  172. package/dist/tooling/doc-gen/jsdoc.js.map +1 -0
  173. package/dist/tooling/doc-gen/render.d.ts +29 -0
  174. package/dist/tooling/doc-gen/render.d.ts.map +1 -0
  175. package/dist/tooling/doc-gen/render.js +206 -0
  176. package/dist/tooling/doc-gen/render.js.map +1 -0
  177. package/dist/tooling/doc-gen/types.d.ts +51 -0
  178. package/dist/tooling/doc-gen/types.d.ts.map +1 -0
  179. package/dist/tooling/doc-gen/types.js +10 -0
  180. package/dist/tooling/doc-gen/types.js.map +1 -0
  181. package/dist/tooling/test-harness/combinators.d.ts +14 -0
  182. package/dist/tooling/test-harness/combinators.d.ts.map +1 -0
  183. package/dist/tooling/test-harness/combinators.js +122 -0
  184. package/dist/tooling/test-harness/combinators.js.map +1 -0
  185. package/dist/tooling/test-harness/coverage.d.ts +3 -0
  186. package/dist/tooling/test-harness/coverage.d.ts.map +1 -0
  187. package/dist/tooling/test-harness/coverage.js +32 -0
  188. package/dist/tooling/test-harness/coverage.js.map +1 -0
  189. package/dist/tooling/test-harness/generators.d.ts +6 -0
  190. package/dist/tooling/test-harness/generators.d.ts.map +1 -0
  191. package/dist/tooling/test-harness/generators.js +66 -0
  192. package/dist/tooling/test-harness/generators.js.map +1 -0
  193. package/dist/tooling/test-harness/index.d.ts +7 -0
  194. package/dist/tooling/test-harness/index.d.ts.map +1 -0
  195. package/dist/tooling/test-harness/index.js +27 -0
  196. package/dist/tooling/test-harness/index.js.map +1 -0
  197. package/dist/tooling/test-harness/mutation.d.ts +4 -0
  198. package/dist/tooling/test-harness/mutation.d.ts.map +1 -0
  199. package/dist/tooling/test-harness/mutation.js +28 -0
  200. package/dist/tooling/test-harness/mutation.js.map +1 -0
  201. package/dist/tooling/test-harness/snapshot.d.ts +5 -0
  202. package/dist/tooling/test-harness/snapshot.d.ts.map +1 -0
  203. package/dist/tooling/test-harness/snapshot.js +86 -0
  204. package/dist/tooling/test-harness/snapshot.js.map +1 -0
  205. package/dist/tooling/test-harness/types.d.ts +32 -0
  206. package/dist/tooling/test-harness/types.d.ts.map +1 -0
  207. package/dist/tooling/test-harness/types.js +3 -0
  208. package/dist/tooling/test-harness/types.js.map +1 -0
  209. package/package.json +1 -1
@@ -0,0 +1,859 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mat = mat;
4
+ exports.zeros = zeros;
5
+ exports.ones = ones;
6
+ exports.identity = identity;
7
+ exports.diagonal = diagonal;
8
+ exports.clone = clone;
9
+ exports.transpose = transpose;
10
+ exports.add = add;
11
+ exports.sub = sub;
12
+ exports.scalarMul = scalarMul;
13
+ exports.multiply = multiply;
14
+ exports.matVec = matVec;
15
+ exports.dot = dot;
16
+ exports.norm = norm;
17
+ exports.normalize = normalize;
18
+ exports.cross = cross;
19
+ exports.rref = rref;
20
+ exports.rank = rank;
21
+ exports.determinant = determinant;
22
+ exports.inverse = inverse;
23
+ exports.solve = solve;
24
+ exports.leastSquares = leastSquares;
25
+ exports.decomposeLU = decomposeLU;
26
+ exports.permutationMatrix = permutationMatrix;
27
+ exports.decomposeQR = decomposeQR;
28
+ exports.decomposeSVD = decomposeSVD;
29
+ exports.powerIteration = powerIteration;
30
+ exports.eigenvalues = eigenvalues;
31
+ exports.eigenvectors = eigenvectors;
32
+ exports.nullSpace = nullSpace;
33
+ exports.columnSpace = columnSpace;
34
+ exports.gramSchmidt = gramSchmidt;
35
+ exports.isLinearlyIndependent = isLinearlyIndependent;
36
+ const DEFAULT_EPS = 1e-10;
37
+ function ensureRect(M, label = 'matrix') {
38
+ const rows = M.length;
39
+ if (rows === 0) {
40
+ return { rows: 0, cols: 0 };
41
+ }
42
+ const first = M[0];
43
+ if (!first) {
44
+ throw new Error(`${label}: empty row`);
45
+ }
46
+ const cols = first.length;
47
+ for (let i = 0; i < rows; i++) {
48
+ const row = M[i];
49
+ if (!row || row.length !== cols) {
50
+ throw new Error(`${label}: row ${i} has inconsistent length`);
51
+ }
52
+ }
53
+ return { rows, cols };
54
+ }
55
+ function getCell(M, r, c) {
56
+ const row = M[r];
57
+ if (!row) {
58
+ throw new Error(`out of bounds: row ${r}`);
59
+ }
60
+ const v = row[c];
61
+ if (v === undefined) {
62
+ throw new Error(`out of bounds: col ${c}`);
63
+ }
64
+ return v;
65
+ }
66
+ function setCell(M, r, c, v) {
67
+ const row = M[r];
68
+ if (!row) {
69
+ throw new Error(`out of bounds: row ${r}`);
70
+ }
71
+ row[c] = v;
72
+ }
73
+ function getRow(M, r) {
74
+ const row = M[r];
75
+ if (!row) {
76
+ throw new Error(`out of bounds: row ${r}`);
77
+ }
78
+ return row;
79
+ }
80
+ function getVec(v, i) {
81
+ const x = v[i];
82
+ if (x === undefined) {
83
+ throw new Error(`vector out of bounds: ${i}`);
84
+ }
85
+ return x;
86
+ }
87
+ function mat(rows, cols, fill = 0) {
88
+ if (rows < 0 || cols < 0 || !Number.isInteger(rows) || !Number.isInteger(cols)) {
89
+ throw new Error('mat: rows and cols must be non-negative integers');
90
+ }
91
+ const M = new Array(rows);
92
+ for (let i = 0; i < rows; i++) {
93
+ M[i] = new Array(cols).fill(fill);
94
+ }
95
+ return M;
96
+ }
97
+ function zeros(rows, cols) {
98
+ return mat(rows, cols, 0);
99
+ }
100
+ function ones(rows, cols) {
101
+ return mat(rows, cols, 1);
102
+ }
103
+ function identity(n) {
104
+ const I = zeros(n, n);
105
+ for (let i = 0; i < n; i++) {
106
+ setCell(I, i, i, 1);
107
+ }
108
+ return I;
109
+ }
110
+ function diagonal(entries) {
111
+ const n = entries.length;
112
+ const D = zeros(n, n);
113
+ for (let i = 0; i < n; i++) {
114
+ setCell(D, i, i, getVec(entries, i));
115
+ }
116
+ return D;
117
+ }
118
+ function clone(M) {
119
+ const { rows, cols } = ensureRect(M, 'clone');
120
+ const out = zeros(rows, cols);
121
+ for (let i = 0; i < rows; i++) {
122
+ for (let j = 0; j < cols; j++) {
123
+ setCell(out, i, j, getCell(M, i, j));
124
+ }
125
+ }
126
+ return out;
127
+ }
128
+ function transpose(M) {
129
+ const { rows, cols } = ensureRect(M, 'transpose');
130
+ const T = zeros(cols, rows);
131
+ for (let i = 0; i < rows; i++) {
132
+ for (let j = 0; j < cols; j++) {
133
+ setCell(T, j, i, getCell(M, i, j));
134
+ }
135
+ }
136
+ return T;
137
+ }
138
+ function sameShape(a, b, label) {
139
+ const A = ensureRect(a, `${label}/a`);
140
+ const B = ensureRect(b, `${label}/b`);
141
+ if (A.rows !== B.rows || A.cols !== B.cols) {
142
+ throw new Error(`${label}: shape mismatch (${A.rows}x${A.cols}) vs (${B.rows}x${B.cols})`);
143
+ }
144
+ return A;
145
+ }
146
+ function add(a, b) {
147
+ const { rows, cols } = sameShape(a, b, 'add');
148
+ const out = zeros(rows, cols);
149
+ for (let i = 0; i < rows; i++) {
150
+ for (let j = 0; j < cols; j++) {
151
+ setCell(out, i, j, getCell(a, i, j) + getCell(b, i, j));
152
+ }
153
+ }
154
+ return out;
155
+ }
156
+ function sub(a, b) {
157
+ const { rows, cols } = sameShape(a, b, 'sub');
158
+ const out = zeros(rows, cols);
159
+ for (let i = 0; i < rows; i++) {
160
+ for (let j = 0; j < cols; j++) {
161
+ setCell(out, i, j, getCell(a, i, j) - getCell(b, i, j));
162
+ }
163
+ }
164
+ return out;
165
+ }
166
+ function scalarMul(c, M) {
167
+ const { rows, cols } = ensureRect(M, 'scalarMul');
168
+ const out = zeros(rows, cols);
169
+ for (let i = 0; i < rows; i++) {
170
+ for (let j = 0; j < cols; j++) {
171
+ setCell(out, i, j, c * getCell(M, i, j));
172
+ }
173
+ }
174
+ return out;
175
+ }
176
+ function multiply(a, b) {
177
+ const A = ensureRect(a, 'multiply/a');
178
+ const B = ensureRect(b, 'multiply/b');
179
+ if (A.cols !== B.rows) {
180
+ throw new Error(`multiply: dimension mismatch (${A.rows}x${A.cols}) * (${B.rows}x${B.cols})`);
181
+ }
182
+ const out = zeros(A.rows, B.cols);
183
+ for (let i = 0; i < A.rows; i++) {
184
+ for (let k = 0; k < A.cols; k++) {
185
+ const aik = getCell(a, i, k);
186
+ if (aik === 0) {
187
+ continue;
188
+ }
189
+ for (let j = 0; j < B.cols; j++) {
190
+ setCell(out, i, j, getCell(out, i, j) + aik * getCell(b, k, j));
191
+ }
192
+ }
193
+ }
194
+ return out;
195
+ }
196
+ function matVec(M, v) {
197
+ const { rows, cols } = ensureRect(M, 'matVec');
198
+ if (cols !== v.length) {
199
+ throw new Error(`matVec: dimension mismatch (${rows}x${cols}) * (${v.length})`);
200
+ }
201
+ const out = new Array(rows).fill(0);
202
+ for (let i = 0; i < rows; i++) {
203
+ let s = 0;
204
+ for (let j = 0; j < cols; j++) {
205
+ s += getCell(M, i, j) * getVec(v, j);
206
+ }
207
+ out[i] = s;
208
+ }
209
+ return out;
210
+ }
211
+ function dot(a, b) {
212
+ if (a.length !== b.length) {
213
+ throw new Error(`dot: length mismatch (${a.length} vs ${b.length})`);
214
+ }
215
+ let s = 0;
216
+ for (let i = 0; i < a.length; i++) {
217
+ s += getVec(a, i) * getVec(b, i);
218
+ }
219
+ return s;
220
+ }
221
+ function norm(v) {
222
+ let s = 0;
223
+ for (let i = 0; i < v.length; i++) {
224
+ const x = getVec(v, i);
225
+ s += x * x;
226
+ }
227
+ return Math.sqrt(s);
228
+ }
229
+ function normalize(v) {
230
+ const n = norm(v);
231
+ if (n < DEFAULT_EPS) {
232
+ throw new Error('normalize: zero vector');
233
+ }
234
+ const out = new Array(v.length);
235
+ for (let i = 0; i < v.length; i++) {
236
+ out[i] = getVec(v, i) / n;
237
+ }
238
+ return out;
239
+ }
240
+ function cross(a, b) {
241
+ if (a.length !== 3 || b.length !== 3) {
242
+ throw new Error('cross: only defined for R^3 vectors');
243
+ }
244
+ const a0 = getVec(a, 0);
245
+ const a1 = getVec(a, 1);
246
+ const a2 = getVec(a, 2);
247
+ const b0 = getVec(b, 0);
248
+ const b1 = getVec(b, 1);
249
+ const b2 = getVec(b, 2);
250
+ return [
251
+ a1 * b2 - a2 * b1,
252
+ a2 * b0 - a0 * b2,
253
+ a0 * b1 - a1 * b0
254
+ ];
255
+ }
256
+ function rref(M) {
257
+ const { rows, cols } = ensureRect(M, 'rref');
258
+ const R = clone(M);
259
+ const pivotCols = [];
260
+ let lead = 0;
261
+ for (let r = 0; r < rows; r++) {
262
+ if (lead >= cols) {
263
+ break;
264
+ }
265
+ let i = r;
266
+ while (i < rows && Math.abs(getCell(R, i, lead)) < DEFAULT_EPS) {
267
+ i++;
268
+ }
269
+ if (i === rows) {
270
+ r--;
271
+ lead++;
272
+ continue;
273
+ }
274
+ if (i !== r) {
275
+ const tmp = getRow(R, i);
276
+ R[i] = getRow(R, r);
277
+ R[r] = tmp;
278
+ }
279
+ const pivot = getCell(R, r, lead);
280
+ for (let j = 0; j < cols; j++) {
281
+ setCell(R, r, j, getCell(R, r, j) / pivot);
282
+ }
283
+ for (let k = 0; k < rows; k++) {
284
+ if (k === r) {
285
+ continue;
286
+ }
287
+ const factor = getCell(R, k, lead);
288
+ if (Math.abs(factor) < DEFAULT_EPS) {
289
+ continue;
290
+ }
291
+ for (let j = 0; j < cols; j++) {
292
+ setCell(R, k, j, getCell(R, k, j) - factor * getCell(R, r, j));
293
+ }
294
+ }
295
+ pivotCols.push(lead);
296
+ lead++;
297
+ }
298
+ for (let i = 0; i < rows; i++) {
299
+ for (let j = 0; j < cols; j++) {
300
+ if (Math.abs(getCell(R, i, j)) < DEFAULT_EPS) {
301
+ setCell(R, i, j, 0);
302
+ }
303
+ }
304
+ }
305
+ return { reduced: R, rank: pivotCols.length, pivotCols };
306
+ }
307
+ function rank(M) {
308
+ return rref(M).rank;
309
+ }
310
+ function determinant(M) {
311
+ const { rows, cols } = ensureRect(M, 'determinant');
312
+ if (rows !== cols) {
313
+ throw new Error('determinant: matrix must be square');
314
+ }
315
+ const n = rows;
316
+ if (n === 0) {
317
+ return 1;
318
+ }
319
+ const A = clone(M);
320
+ let det = 1;
321
+ for (let i = 0; i < n; i++) {
322
+ let pivotRow = i;
323
+ let pivotAbs = Math.abs(getCell(A, i, i));
324
+ for (let k = i + 1; k < n; k++) {
325
+ const v = Math.abs(getCell(A, k, i));
326
+ if (v > pivotAbs) {
327
+ pivotAbs = v;
328
+ pivotRow = k;
329
+ }
330
+ }
331
+ if (pivotAbs < DEFAULT_EPS) {
332
+ return 0;
333
+ }
334
+ if (pivotRow !== i) {
335
+ const tmp = getRow(A, pivotRow);
336
+ A[pivotRow] = getRow(A, i);
337
+ A[i] = tmp;
338
+ det = -det;
339
+ }
340
+ const pivot = getCell(A, i, i);
341
+ det *= pivot;
342
+ for (let k = i + 1; k < n; k++) {
343
+ const factor = getCell(A, k, i) / pivot;
344
+ if (factor === 0) {
345
+ continue;
346
+ }
347
+ for (let j = i; j < n; j++) {
348
+ setCell(A, k, j, getCell(A, k, j) - factor * getCell(A, i, j));
349
+ }
350
+ }
351
+ }
352
+ return det;
353
+ }
354
+ function inverse(M) {
355
+ const { rows, cols } = ensureRect(M, 'inverse');
356
+ if (rows !== cols) {
357
+ throw new Error('inverse: matrix must be square');
358
+ }
359
+ const n = rows;
360
+ const aug = zeros(n, 2 * n);
361
+ for (let i = 0; i < n; i++) {
362
+ for (let j = 0; j < n; j++) {
363
+ setCell(aug, i, j, getCell(M, i, j));
364
+ }
365
+ setCell(aug, i, n + i, 1);
366
+ }
367
+ const { reduced } = rref(aug);
368
+ for (let i = 0; i < n; i++) {
369
+ for (let j = 0; j < n; j++) {
370
+ const want = i === j ? 1 : 0;
371
+ if (Math.abs(getCell(reduced, i, j) - want) > 1e-8) {
372
+ return null;
373
+ }
374
+ }
375
+ }
376
+ const inv = zeros(n, n);
377
+ for (let i = 0; i < n; i++) {
378
+ for (let j = 0; j < n; j++) {
379
+ setCell(inv, i, j, getCell(reduced, i, n + j));
380
+ }
381
+ }
382
+ return inv;
383
+ }
384
+ function solve(A, b) {
385
+ const { rows, cols } = ensureRect(A, 'solve');
386
+ if (rows !== b.length) {
387
+ throw new Error('solve: b length must match A rows');
388
+ }
389
+ const aug = zeros(rows, cols + 1);
390
+ for (let i = 0; i < rows; i++) {
391
+ for (let j = 0; j < cols; j++) {
392
+ setCell(aug, i, j, getCell(A, i, j));
393
+ }
394
+ setCell(aug, i, cols, getVec(b, i));
395
+ }
396
+ const { reduced, pivotCols } = rref(aug);
397
+ for (const p of pivotCols) {
398
+ if (p === cols) {
399
+ return null;
400
+ }
401
+ }
402
+ if (pivotCols.length < cols) {
403
+ return null;
404
+ }
405
+ const x = new Array(cols).fill(0);
406
+ for (let i = 0; i < pivotCols.length; i++) {
407
+ const col = getVec(pivotCols, i);
408
+ x[col] = getCell(reduced, i, cols);
409
+ }
410
+ return x;
411
+ }
412
+ function leastSquares(A, b) {
413
+ const { rows, cols } = ensureRect(A, 'leastSquares');
414
+ if (rows !== b.length) {
415
+ throw new Error('leastSquares: b length must match A rows');
416
+ }
417
+ const At = transpose(A);
418
+ const AtA = multiply(At, A);
419
+ const Atb = matVec(At, b);
420
+ const x = solve(AtA, Atb);
421
+ if (!x) {
422
+ throw new Error('leastSquares: AtA is singular (rank-deficient A)');
423
+ }
424
+ if (x.length !== cols) {
425
+ throw new Error('leastSquares: internal dimension error');
426
+ }
427
+ return x;
428
+ }
429
+ function decomposeLU(M) {
430
+ const { rows, cols } = ensureRect(M, 'decomposeLU');
431
+ if (rows !== cols) {
432
+ throw new Error('decomposeLU: matrix must be square');
433
+ }
434
+ const n = rows;
435
+ const U = clone(M);
436
+ const L = identity(n);
437
+ const P = new Array(n);
438
+ for (let i = 0; i < n; i++) {
439
+ P[i] = i;
440
+ }
441
+ for (let i = 0; i < n; i++) {
442
+ let pivotRow = i;
443
+ let pivotAbs = Math.abs(getCell(U, i, i));
444
+ for (let k = i + 1; k < n; k++) {
445
+ const v = Math.abs(getCell(U, k, i));
446
+ if (v > pivotAbs) {
447
+ pivotAbs = v;
448
+ pivotRow = k;
449
+ }
450
+ }
451
+ if (pivotAbs < DEFAULT_EPS) {
452
+ return null;
453
+ }
454
+ if (pivotRow !== i) {
455
+ const tmpU = getRow(U, pivotRow);
456
+ U[pivotRow] = getRow(U, i);
457
+ U[i] = tmpU;
458
+ const tmpP = getVec(P, pivotRow);
459
+ P[pivotRow] = getVec(P, i);
460
+ P[i] = tmpP;
461
+ for (let j = 0; j < i; j++) {
462
+ const tmpL = getCell(L, i, j);
463
+ setCell(L, i, j, getCell(L, pivotRow, j));
464
+ setCell(L, pivotRow, j, tmpL);
465
+ }
466
+ }
467
+ const pivot = getCell(U, i, i);
468
+ for (let k = i + 1; k < n; k++) {
469
+ const factor = getCell(U, k, i) / pivot;
470
+ setCell(L, k, i, factor);
471
+ for (let j = i; j < n; j++) {
472
+ setCell(U, k, j, getCell(U, k, j) - factor * getCell(U, i, j));
473
+ }
474
+ }
475
+ }
476
+ return { L, U, P };
477
+ }
478
+ function permutationMatrix(P) {
479
+ const n = P.length;
480
+ const M = zeros(n, n);
481
+ for (let i = 0; i < n; i++) {
482
+ setCell(M, i, getVec(P, i), 1);
483
+ }
484
+ return M;
485
+ }
486
+ function decomposeQR(M) {
487
+ const { rows, cols } = ensureRect(M, 'decomposeQR');
488
+ if (rows < cols) {
489
+ throw new Error('decomposeQR: rows must be >= cols');
490
+ }
491
+ const Q = zeros(rows, cols);
492
+ const R = zeros(cols, cols);
493
+ for (let j = 0; j < cols; j++) {
494
+ const v = new Array(rows);
495
+ for (let i = 0; i < rows; i++) {
496
+ v[i] = getCell(M, i, j);
497
+ }
498
+ for (let k = 0; k < j; k++) {
499
+ let r = 0;
500
+ for (let i = 0; i < rows; i++) {
501
+ r += getCell(Q, i, k) * getVec(v, i);
502
+ }
503
+ setCell(R, k, j, r);
504
+ for (let i = 0; i < rows; i++) {
505
+ v[i] = getVec(v, i) - r * getCell(Q, i, k);
506
+ }
507
+ }
508
+ const nrm = norm(v);
509
+ if (nrm < DEFAULT_EPS) {
510
+ setCell(R, j, j, 0);
511
+ for (let i = 0; i < rows; i++) {
512
+ setCell(Q, i, j, 0);
513
+ }
514
+ }
515
+ else {
516
+ setCell(R, j, j, nrm);
517
+ for (let i = 0; i < rows; i++) {
518
+ setCell(Q, i, j, getVec(v, i) / nrm);
519
+ }
520
+ }
521
+ }
522
+ return { Q, R };
523
+ }
524
+ function symmetricEigen(S, maxIter, eps) {
525
+ const { rows, cols } = ensureRect(S, 'symmetricEigen');
526
+ if (rows !== cols) {
527
+ throw new Error('symmetricEigen: matrix must be square');
528
+ }
529
+ const n = rows;
530
+ const A = clone(S);
531
+ const V = identity(n);
532
+ for (let iter = 0; iter < maxIter; iter++) {
533
+ let p = 0;
534
+ let q = 1;
535
+ let maxOff = 0;
536
+ for (let i = 0; i < n; i++) {
537
+ for (let j = i + 1; j < n; j++) {
538
+ const v = Math.abs(getCell(A, i, j));
539
+ if (v > maxOff) {
540
+ maxOff = v;
541
+ p = i;
542
+ q = j;
543
+ }
544
+ }
545
+ }
546
+ if (maxOff < eps) {
547
+ break;
548
+ }
549
+ const app = getCell(A, p, p);
550
+ const aqq = getCell(A, q, q);
551
+ const apq = getCell(A, p, q);
552
+ const theta = (aqq - app) / (2 * apq);
553
+ let t;
554
+ if (Math.abs(theta) > 1e15) {
555
+ t = 1 / (2 * theta);
556
+ }
557
+ else {
558
+ const sign = theta >= 0 ? 1 : -1;
559
+ t = sign / (Math.abs(theta) + Math.sqrt(theta * theta + 1));
560
+ }
561
+ const c = 1 / Math.sqrt(t * t + 1);
562
+ const s = t * c;
563
+ for (let i = 0; i < n; i++) {
564
+ const aip = getCell(A, i, p);
565
+ const aiq = getCell(A, i, q);
566
+ setCell(A, i, p, c * aip - s * aiq);
567
+ setCell(A, i, q, s * aip + c * aiq);
568
+ }
569
+ for (let j = 0; j < n; j++) {
570
+ const apj = getCell(A, p, j);
571
+ const aqj = getCell(A, q, j);
572
+ setCell(A, p, j, c * apj - s * aqj);
573
+ setCell(A, q, j, s * apj + c * aqj);
574
+ }
575
+ for (let i = 0; i < n; i++) {
576
+ const vip = getCell(V, i, p);
577
+ const viq = getCell(V, i, q);
578
+ setCell(V, i, p, c * vip - s * viq);
579
+ setCell(V, i, q, s * vip + c * viq);
580
+ }
581
+ }
582
+ const values = new Array(n);
583
+ for (let i = 0; i < n; i++) {
584
+ values[i] = getCell(A, i, i);
585
+ }
586
+ return { values, vectors: V };
587
+ }
588
+ function decomposeSVD(M, maxIter = 200) {
589
+ const { rows, cols } = ensureRect(M, 'decomposeSVD');
590
+ const At = transpose(M);
591
+ const AtA = multiply(At, M);
592
+ const { values, vectors: V } = symmetricEigen(AtA, maxIter, 1e-12);
593
+ const order = [];
594
+ for (let i = 0; i < values.length; i++) {
595
+ order.push(i);
596
+ }
597
+ order.sort((a, b) => Math.abs(getVec(values, b)) - Math.abs(getVec(values, a)));
598
+ const Vsorted = zeros(cols, cols);
599
+ const sigma = new Array(cols).fill(0);
600
+ for (let j = 0; j < cols; j++) {
601
+ const src = getVec(order, j);
602
+ const val = getVec(values, src);
603
+ sigma[j] = Math.sqrt(Math.max(val, 0));
604
+ for (let i = 0; i < cols; i++) {
605
+ setCell(Vsorted, i, j, getCell(V, i, src));
606
+ }
607
+ }
608
+ const U = zeros(rows, cols);
609
+ for (let j = 0; j < cols; j++) {
610
+ const vj = new Array(cols);
611
+ for (let i = 0; i < cols; i++) {
612
+ vj[i] = getCell(Vsorted, i, j);
613
+ }
614
+ const Av = matVec(M, vj);
615
+ const s = getVec(sigma, j);
616
+ if (s > 1e-10) {
617
+ for (let i = 0; i < rows; i++) {
618
+ setCell(U, i, j, getVec(Av, i) / s);
619
+ }
620
+ }
621
+ else {
622
+ for (let i = 0; i < rows; i++) {
623
+ setCell(U, i, j, 0);
624
+ }
625
+ }
626
+ }
627
+ return { U, S: sigma, V: Vsorted };
628
+ }
629
+ function powerIteration(M, opts = {}) {
630
+ const { rows, cols } = ensureRect(M, 'powerIteration');
631
+ if (rows !== cols) {
632
+ throw new Error('powerIteration: matrix must be square');
633
+ }
634
+ const n = rows;
635
+ const maxIter = opts.maxIter ?? 1000;
636
+ const eps = opts.eps ?? 1e-10;
637
+ let v = new Array(n);
638
+ for (let i = 0; i < n; i++) {
639
+ v[i] = Math.sin(i + 1);
640
+ }
641
+ let nrm = norm(v);
642
+ if (nrm < DEFAULT_EPS) {
643
+ v[0] = 1;
644
+ nrm = 1;
645
+ }
646
+ for (let i = 0; i < n; i++) {
647
+ v[i] = getVec(v, i) / nrm;
648
+ }
649
+ let lambda = 0;
650
+ for (let iter = 0; iter < maxIter; iter++) {
651
+ const w = matVec(M, v);
652
+ const wn = norm(w);
653
+ if (wn < DEFAULT_EPS) {
654
+ return { eigenvalue: 0, eigenvector: v };
655
+ }
656
+ const next = new Array(n);
657
+ for (let i = 0; i < n; i++) {
658
+ next[i] = getVec(w, i) / wn;
659
+ }
660
+ const newLambda = dot(next, matVec(M, next));
661
+ if (Math.abs(newLambda - lambda) < eps) {
662
+ lambda = newLambda;
663
+ v = next;
664
+ break;
665
+ }
666
+ lambda = newLambda;
667
+ v = next;
668
+ }
669
+ return { eigenvalue: lambda, eigenvector: v };
670
+ }
671
+ function isSymmetric(M, eps = 1e-9) {
672
+ const { rows, cols } = ensureRect(M, 'isSymmetric');
673
+ if (rows !== cols) {
674
+ return false;
675
+ }
676
+ for (let i = 0; i < rows; i++) {
677
+ for (let j = i + 1; j < cols; j++) {
678
+ if (Math.abs(getCell(M, i, j) - getCell(M, j, i)) > eps) {
679
+ return false;
680
+ }
681
+ }
682
+ }
683
+ return true;
684
+ }
685
+ function eigenvalues(M, opts = {}) {
686
+ const { rows, cols } = ensureRect(M, 'eigenvalues');
687
+ if (rows !== cols) {
688
+ throw new Error('eigenvalues: matrix must be square');
689
+ }
690
+ const n = rows;
691
+ const maxIter = opts.maxIter ?? 500;
692
+ const eps = opts.eps ?? 1e-10;
693
+ if (n === 0) {
694
+ return [];
695
+ }
696
+ if (n === 1) {
697
+ return [getCell(M, 0, 0)];
698
+ }
699
+ if (n === 2) {
700
+ const a = getCell(M, 0, 0);
701
+ const b = getCell(M, 0, 1);
702
+ const c = getCell(M, 1, 0);
703
+ const d = getCell(M, 1, 1);
704
+ const tr = a + d;
705
+ const det = a * d - b * c;
706
+ const disc = tr * tr - 4 * det;
707
+ if (disc < -eps) {
708
+ return [];
709
+ }
710
+ const sq = Math.sqrt(Math.max(disc, 0));
711
+ return [(tr + sq) / 2, (tr - sq) / 2];
712
+ }
713
+ if (isSymmetric(M, 1e-9)) {
714
+ const { values } = symmetricEigen(M, maxIter, eps);
715
+ return values.slice().sort((a, b) => b - a);
716
+ }
717
+ let A = clone(M);
718
+ for (let iter = 0; iter < maxIter; iter++) {
719
+ const { Q, R } = decomposeQR(A);
720
+ A = multiply(R, Q);
721
+ let off = 0;
722
+ for (let i = 1; i < n; i++) {
723
+ off += Math.abs(getCell(A, i, i - 1));
724
+ }
725
+ if (off < eps) {
726
+ break;
727
+ }
728
+ }
729
+ const out = new Array(n);
730
+ for (let i = 0; i < n; i++) {
731
+ out[i] = getCell(A, i, i);
732
+ }
733
+ return out.sort((a, b) => b - a);
734
+ }
735
+ function eigenvectors(M, opts = {}) {
736
+ const { rows, cols } = ensureRect(M, 'eigenvectors');
737
+ if (rows !== cols) {
738
+ throw new Error('eigenvectors: matrix must be square');
739
+ }
740
+ const maxIter = opts.maxIter ?? 500;
741
+ const eps = opts.eps ?? 1e-12;
742
+ if (!isSymmetric(M, 1e-9)) {
743
+ throw new Error('eigenvectors: only supported for symmetric matrices');
744
+ }
745
+ const { values, vectors } = symmetricEigen(M, maxIter, eps);
746
+ const n = values.length;
747
+ const order = [];
748
+ for (let i = 0; i < n; i++) {
749
+ order.push(i);
750
+ }
751
+ order.sort((a, b) => getVec(values, b) - getVec(values, a));
752
+ const sortedVals = new Array(n);
753
+ const sortedVecs = zeros(n, n);
754
+ for (let j = 0; j < n; j++) {
755
+ const src = getVec(order, j);
756
+ sortedVals[j] = getVec(values, src);
757
+ for (let i = 0; i < n; i++) {
758
+ setCell(sortedVecs, i, j, getCell(vectors, i, src));
759
+ }
760
+ }
761
+ return { values: sortedVals, vectors: sortedVecs };
762
+ }
763
+ function nullSpace(M) {
764
+ const { cols } = ensureRect(M, 'nullSpace');
765
+ const { reduced, pivotCols } = rref(M);
766
+ const reducedRect = ensureRect(reduced, 'nullSpace/reduced');
767
+ const pivotSet = new Set(pivotCols);
768
+ const freeCols = [];
769
+ for (let j = 0; j < cols; j++) {
770
+ if (!pivotSet.has(j)) {
771
+ freeCols.push(j);
772
+ }
773
+ }
774
+ const basis = [];
775
+ for (const free of freeCols) {
776
+ const v = new Array(cols).fill(0);
777
+ v[free] = 1;
778
+ for (let i = 0; i < pivotCols.length; i++) {
779
+ const pc = getVec(pivotCols, i);
780
+ if (i >= reducedRect.rows) {
781
+ break;
782
+ }
783
+ v[pc] = -getCell(reduced, i, free);
784
+ }
785
+ basis.push(v);
786
+ }
787
+ return basis;
788
+ }
789
+ function columnSpace(M) {
790
+ const { rows } = ensureRect(M, 'columnSpace');
791
+ const { pivotCols } = rref(M);
792
+ const basis = [];
793
+ for (const c of pivotCols) {
794
+ const col = new Array(rows);
795
+ for (let i = 0; i < rows; i++) {
796
+ col[i] = getCell(M, i, c);
797
+ }
798
+ basis.push(col);
799
+ }
800
+ return basis;
801
+ }
802
+ function gramSchmidt(vectors) {
803
+ if (vectors.length === 0) {
804
+ return [];
805
+ }
806
+ const first = vectors[0];
807
+ if (!first) {
808
+ return [];
809
+ }
810
+ const dim = first.length;
811
+ const out = [];
812
+ for (const raw of vectors) {
813
+ if (raw.length !== dim) {
814
+ throw new Error('gramSchmidt: vectors must share dimension');
815
+ }
816
+ const v = raw.slice();
817
+ for (const u of out) {
818
+ const c = dot(v, u);
819
+ for (let i = 0; i < dim; i++) {
820
+ v[i] = getVec(v, i) - c * getVec(u, i);
821
+ }
822
+ }
823
+ const nrm = norm(v);
824
+ if (nrm < DEFAULT_EPS) {
825
+ continue;
826
+ }
827
+ const unit = new Array(dim);
828
+ for (let i = 0; i < dim; i++) {
829
+ unit[i] = getVec(v, i) / nrm;
830
+ }
831
+ out.push(unit);
832
+ }
833
+ return out;
834
+ }
835
+ function isLinearlyIndependent(vectors) {
836
+ if (vectors.length === 0) {
837
+ return true;
838
+ }
839
+ const first = vectors[0];
840
+ if (!first) {
841
+ return true;
842
+ }
843
+ const dim = first.length;
844
+ if (vectors.length > dim) {
845
+ return false;
846
+ }
847
+ const M = zeros(dim, vectors.length);
848
+ for (let j = 0; j < vectors.length; j++) {
849
+ const v = vectors[j];
850
+ if (!v || v.length !== dim) {
851
+ throw new Error('isLinearlyIndependent: vectors must share dimension');
852
+ }
853
+ for (let i = 0; i < dim; i++) {
854
+ setCell(M, i, j, getVec(v, i));
855
+ }
856
+ }
857
+ return rank(M) === vectors.length;
858
+ }
859
+ //# sourceMappingURL=index.js.map