MCPcopy Create free account
hub / github.com/cortex-js/compute-engine / det

Function det

test/compute-engine/diophantine.test.ts:101–113  ·  view source on GitHub ↗

Determinant of a square bigint matrix via cofactor expansion (n ≤ 4 here).

(m: bigint[][])

Source from the content-addressed store, hash-verified

99
100/** Determinant of a square bigint matrix via cofactor expansion (n ≤ 4 here). */
101function det(m: bigint[][]): bigint {
102 const n = m.length;
103 if (n === 0) return 1n;
104 if (n === 1) return m[0][0];
105 if (n === 2) return m[0][0] * m[1][1] - m[0][1] * m[1][0];
106 let sum = 0n;
107 for (let j = 0; j < n; j++) {
108 const minor = m.slice(1).map((row) => row.filter((_, ci) => ci !== j));
109 const sign = j % 2 === 0 ? 1n : -1n;
110 sum += sign * m[0][j] * det(minor);
111 }
112 return sum;
113}
114
115function* combinations<T>(pool: T[], k: number): Generator<T[]> {
116 if (k === 0) {

Callers 1

invertParamsFunction · 0.85

Calls 2

mapMethod · 0.65
sliceMethod · 0.65

Tested by

no test coverage detected