-
Notifications
You must be signed in to change notification settings - Fork 15
/
Contents.swift
69 lines (53 loc) · 981 Bytes
/
Contents.swift
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
import SwmCore
// MARK: Fixed size square matrix
do {
typealias M = Matrix3x3<𝐙> // 3x3 integer matrix
let a: M = [
1,2,3,
4,5,6,
7,8,9
]
let b: M = [
1,0,1,
0,1,0,
4,0,5
]
a + b
a - b
a * b
a.trace
a.determinant
a.inverse // nil
b.trace
b.determinant
b.inverse
b * b.inverse! == .identity
}
// MARK: Fixed size rectangular matrix
do {
typealias M = Matrix<𝐙, _3, _2> // 3x2 integer matrix
let a: M = [
1,2,
3,4,
5,6
]
let b: M = [
1,0,
0,1,
4,0,
]
a + b
a - b
// Below are prohibited in compile-time:
// a * b
// a.trace
// a.determinant
// a.inverse
typealias N = Matrix<𝐙, _2, _3>
let c: N = [
1, 2, 3,
4, 5, 6
]
a * c
(a * c).determinant // This is OK, because it is a 2x2 matrix.
}