Skip to content

Commit 7ccc360

Browse files
committed
Improved README; ready for 1st release
1 parent 3873258 commit 7ccc360

File tree

3 files changed

+124
-5
lines changed

3 files changed

+124
-5
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "LinearAlgebraX"
22
uuid = "9b3f67b0-2d00-526e-9884-9e4938f8fb88"
3-
version = "0.0.0"
3+
version = "0.0.1"
44

55
[deps]
66
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

README.md

Lines changed: 112 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,60 @@ These functions in this module end with the letter `x`
2222
and have the same definitions as their counterparts that do not have an `x`.
2323
For exact types (such as `Int`s) these functions give exact results.
2424

25-
* `detx` -- exact determinant
25+
* `detx` -- exact determinant (via row reduced echelon form)
26+
* `cofactor_det`-- slower exact determinant (via cofactor expansion)
2627
* `nullspacex` -- exact nullspace
2728
* `rankx` -- exact rankx
2829
* `invx` -- exact inverse
30+
* `rrefx` -- row reduced echelon form
31+
* `eye` -- lovingly restored
2932

30-
#### Example
33+
## Examples
34+
35+
#### Determinant
36+
```
37+
julia> A = ones(Int,10,10)+eye(Int,10);
38+
39+
julia> det(A)
40+
11.000000000000004
41+
42+
julia> detx(A)
43+
11
44+
45+
julia> A = rand(Int,20,20) .% 20;
46+
47+
julia> det(A)
48+
3.3905496651565455e29
49+
50+
julia> detx(A)
51+
339054966515654744413389494504
52+
```
53+
54+
#### Nullspace
55+
56+
```
57+
julia> A = reshape(collect(1:12),3,4)
58+
3×4 Array{Int64,2}:
59+
1 4 7 10
60+
2 5 8 11
61+
3 6 9 12
62+
63+
julia> nullspacex(A)
64+
4×2 Array{Rational{BigInt},2}:
65+
1//1 2//1
66+
-2//1 -3//1
67+
1//1 0//1
68+
0//1 1//1
69+
70+
julia> nullspace(A)
71+
4×2 Array{Float64,2}:
72+
-0.475185 -0.272395
73+
0.430549 0.717376
74+
0.564458 -0.617566
75+
-0.519821 0.172585
76+
```
77+
78+
#### Rank
3179

3280
Consider the 12-by-12 Hibert matrix, `H`.
3381
```
@@ -54,3 +102,65 @@ julia> rank(H)
54102
julia> rankx(H)
55103
12
56104
```
105+
106+
#### Inverse
107+
108+
```
109+
julia> using Mods
110+
111+
julia> A = rand(Mod{11},5,5)
112+
5×5 Array{Mod{11},2}:
113+
Mod{11}(2) Mod{11}(4) Mod{11}(4) Mod{11}(0) Mod{11}(2)
114+
Mod{11}(9) Mod{11}(4) Mod{11}(5) Mod{11}(1) Mod{11}(10)
115+
Mod{11}(3) Mod{11}(4) Mod{11}(5) Mod{11}(6) Mod{11}(0)
116+
Mod{11}(5) Mod{11}(10) Mod{11}(4) Mod{11}(5) Mod{11}(4)
117+
Mod{11}(9) Mod{11}(10) Mod{11}(7) Mod{11}(8) Mod{11}(9)
118+
119+
julia> B = invx(A)
120+
5×5 Array{Mod{11},2}:
121+
Mod{11}(4) Mod{11}(5) Mod{11}(0) Mod{11}(6) Mod{11}(8)
122+
Mod{11}(7) Mod{11}(4) Mod{11}(9) Mod{11}(10) Mod{11}(3)
123+
Mod{11}(6) Mod{11}(0) Mod{11}(2) Mod{11}(5) Mod{11}(5)
124+
Mod{11}(3) Mod{11}(4) Mod{11}(9) Mod{11}(10) Mod{11}(10)
125+
Mod{11}(9) Mod{11}(9) Mod{11}(0) Mod{11}(8) Mod{11}(9)
126+
127+
julia> A*B
128+
5×5 Array{Mod{11},2}:
129+
Mod{11}(1) Mod{11}(0) Mod{11}(0) Mod{11}(0) Mod{11}(0)
130+
Mod{11}(0) Mod{11}(1) Mod{11}(0) Mod{11}(0) Mod{11}(0)
131+
Mod{11}(0) Mod{11}(0) Mod{11}(1) Mod{11}(0) Mod{11}(0)
132+
Mod{11}(0) Mod{11}(0) Mod{11}(0) Mod{11}(1) Mod{11}(0)
133+
Mod{11}(0) Mod{11}(0) Mod{11}(0) Mod{11}(0) Mod{11}(1)
134+
```
135+
136+
#### Row reduced echelon form
137+
138+
```
139+
julia> A = rand(Int,4,6) .% 10
140+
4×6 Array{Int64,2}:
141+
6 8 0 -6 -5 4
142+
0 -5 2 0 -3 -4
143+
0 -4 2 -8 7 -8
144+
1 -3 7 2 -6 2
145+
146+
julia> c = A[:,1] + A[:,2] - A[:,3]
147+
4-element Array{Int64,1}:
148+
14
149+
-7
150+
-6
151+
-9
152+
153+
julia> A = [c A]
154+
4×7 Array{Int64,2}:
155+
14 6 8 0 -6 -5 4
156+
-7 0 -5 2 0 -3 -4
157+
-6 0 -4 2 -8 7 -8
158+
-9 1 -3 7 2 -6 2
159+
160+
julia> rrefx(A)
161+
4×7 Array{Rational{Int64},2}:
162+
1//1 0//1 0//1 -1//1 0//1 -23//130 -36//65
163+
0//1 1//1 0//1 1//1 0//1 -883//325 158//325
164+
0//1 0//1 1//1 1//1 0//1 551//650 512//325
165+
0//1 0//1 0//1 0//1 1//1 -379//325 204//325
166+
```

src/detx.jl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,21 @@ I hope to expand this to `Polynomial`s.
88
"""
99
function detx(A::AbstractArray{T,2}) where T<:IntegerX
1010
# @info "Using IntegerX detx{$T}"
11-
return T(det(A//1))
11+
try
12+
return T(det(A//1))
13+
catch
14+
A = big.(A)
15+
return detx(A)
16+
end
1217
end
1318

1419
function detx(A::AbstractArray{T,2}) where T<:RationalX
1520
# @info "Using RationalX detx{$T}"
16-
return det(A)
21+
try
22+
return det(A)
23+
catch
24+
return det(big.(A))
25+
end
1726
end
1827

1928
function detx(A::AbstractArray{T,2}) where T

0 commit comments

Comments
 (0)