forked from xieyuheng/cell-complex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathint-module.js
82 lines (67 loc) · 1.14 KB
/
int-module.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
let assert = require ("assert") .strict
let ut = require ("../lib/util")
let int = require ("../lib/int")
{
/**
* generic `row_canonical_form`
* i.e. `hermite_normal_form` for integers
*/
let A = int.matrix ([
[2, 3, 6, 2],
[5, 6, 1, 6],
[8, 3, 1, 1],
])
let B = int.matrix ([
[1, 0, -11, 2],
[0, 3, 28, -2],
[0, 0, 61, -13],
])
assert (
A.row_canonical_form () .eq (B)
)
}
{
/**
* generic `diag_canonical_form`
* i.e. `smith_normal_form` for integers
*/
let A = int.matrix ([
[2, 4, 4],
[-6, 6, 12],
[10, -4, -16],
])
let S = int.matrix ([
[2, 0, 0],
[0, 6, 0],
[0, 0, -12],
])
assert (
A.diag_canonical_form () .eq (S)
)
}
{
/**
* solve linear diophantine equations
*/
let A = int.matrix ([
[1, 2, 3, 4, 5, 6, 7],
[1, 0, 1, 0, 1, 0, 1],
[2, 4, 5, 6, 1, 1, 1],
[1, 4, 2, 5, 2, 0, 0],
[0, 0, 1, 1, 2, 2, 3],
])
let b = int.vector ([
28,
4,
20,
14,
9,
])
let solution = A.solve (b)
if (solution !== null) {
solution.print ()
assert (
A.act (solution) .eq (b)
)
}
}