Skip to content

Commit cc58444

Browse files
committed
When printing matrices, replace zeros by dots
This makes it easier to read many matrices, especially those which are relatively sparse. Before: julia> matrix(QQ, [42 0 0; 0 42 0; 0 0 42]) [42//1 0//1 0//1] [ 0//1 42//1 0//1] [ 0//1 0//1 42//1] After: julia> matrix(QQ, [42 0 0; 0 42 0; 0 0 42]) [42//1 . .] [ . 42//1 .] [ . . 42//1]
1 parent 5170909 commit cc58444

File tree

8 files changed

+137
-136
lines changed

8 files changed

+137
-136
lines changed

docs/src/matrix.md

Lines changed: 72 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,19 @@ Matrix space of 3 rows and 3 columns
8787
over univariate polynomial ring in t over rationals
8888
8989
julia> A = S()
90-
[0 0 0]
91-
[0 0 0]
92-
[0 0 0]
90+
[. . .]
91+
[. . .]
92+
[. . .]
9393
9494
julia> B = S(12)
95-
[12 0 0]
96-
[ 0 12 0]
97-
[ 0 0 12]
95+
[12 . .]
96+
[ . 12 .]
97+
[ . . 12]
9898
9999
julia> C = S(R(11))
100-
[11 0 0]
101-
[ 0 11 0]
102-
[ 0 0 11]
100+
[11 . .]
101+
[ . 11 .]
102+
[ . . 11]
103103
104104
```
105105

@@ -155,23 +155,23 @@ Matrix ring of degree 2
155155
156156
julia> M1 = S(Rational{BigInt}[2 3 1; 1 0 4])
157157
[2//1 3//1 1//1]
158-
[1//1 0//1 4//1]
158+
[1//1 . 4//1]
159159
160160
julia> M2 = S(BigInt[2 3 1; 1 0 4])
161161
[2//1 3//1 1//1]
162-
[1//1 0//1 4//1]
162+
[1//1 . 4//1]
163163
164164
julia> M3 = S(BigInt[2, 3, 1, 1, 0, 4])
165165
[2//1 3//1 1//1]
166-
[1//1 0//1 4//1]
166+
[1//1 . 4//1]
167167
168168
julia> N1 = T(Rational{BigInt}[2 3; 1 0])
169169
[2//1 3//1]
170-
[1//1 0//1]
170+
[1//1 .]
171171
172172
julia> N2 = T(BigInt[2 3; 1 0])
173173
[2//1 3//1]
174-
[1//1 0//1]
174+
[1//1 .]
175175
176176
julia> N3 = T(BigInt[2, 3, 1, 1])
177177
[2//1 3//1]
@@ -186,7 +186,7 @@ Matrix space of 3 rows and 3 columns
186186
187187
julia> M = R[t + 1 1; t^2 0]
188188
[t + 1 1]
189-
[ t^2 0]
189+
[ t^2 .]
190190
191191
julia> N = R[t + 1 2 t] # create a row vector
192192
[t + 1 2 t]
@@ -228,25 +228,25 @@ Construct the $r\times c$ AbstractAlgebra.jl zero matrix over the ring `R`.
228228
```jldoctest
229229
julia> M = matrix(ZZ, BigInt[3 1 2; 2 0 1])
230230
[3 1 2]
231-
[2 0 1]
231+
[2 . 1]
232232
233233
julia> N = matrix(ZZ, 3, 2, BigInt[3, 1, 2, 2, 0, 1])
234234
[3 1]
235235
[2 2]
236-
[0 1]
236+
[. 1]
237237
238238
julia> P = zero_matrix(ZZ, 3, 2)
239-
[0 0]
240-
[0 0]
241-
[0 0]
239+
[. .]
240+
[. .]
241+
[. .]
242242
243243
julia> R = matrix_ring(ZZ, 2)
244244
Matrix ring of degree 2
245245
over integers
246246
247247
julia> M = R()
248-
[0 0]
249-
[0 0]
248+
[. .]
249+
[. .]
250250
```
251251

252252
## Block diagonal matrix constructors
@@ -267,10 +267,10 @@ block_diagonal_matrix(::Ring, ::Vector{<:Matrix{T}}) where T <: RingElement
267267

268268
```jldoctest
269269
julia> block_diagonal_matrix(ZZ, [[1 2; 3 4], [4 5 6; 7 8 9]])
270-
[1 2 0 0 0]
271-
[3 4 0 0 0]
272-
[0 0 4 5 6]
273-
[0 0 7 8 9]
270+
[1 2 . . .]
271+
[3 4 . . .]
272+
[. . 4 5 6]
273+
[. . 7 8 9]
274274
275275
julia> M = matrix(ZZ, [1 2; 3 4])
276276
[1 2]
@@ -281,10 +281,10 @@ julia> N = matrix(ZZ, [4 5 6; 7 8 9])
281281
[7 8 9]
282282
283283
julia> block_diagonal_matrix([M, N])
284-
[1 2 0 0 0]
285-
[3 4 0 0 0]
286-
[0 0 4 5 6]
287-
[0 0 7 8 9]
284+
[1 2 . . .]
285+
[3 4 . . .]
286+
[. . 4 5 6]
287+
[. . 7 8 9]
288288
```
289289

290290
## Conversion to Julia matrices, iteration and broacasting
@@ -554,7 +554,7 @@ julia> Z = divexact(2*A, 2)
554554
[ -2 t + 2 t^2 + t + 1]
555555
556556
julia> M = matrix(ZZ, BigInt[2 3 0; 1 1 1])
557-
[2 3 0]
557+
[2 3 .]
558558
[1 1 1]
559559
560560
julia> M[1, 2] = BigInt(4)
@@ -685,22 +685,22 @@ julia> M = matrix(ZZ, BigInt[1 2 3; 2 3 4; 3 4 5])
685685
[3 4 5]
686686
687687
julia> N = matrix(ZZ, BigInt[1 0 1; 0 1 0; 1 0 1])
688-
[1 0 1]
689-
[0 1 0]
690-
[1 0 1]
688+
[1 . 1]
689+
[. 1 .]
690+
[1 . 1]
691691
692692
julia> P = hcat(M, N)
693-
[1 2 3 1 0 1]
694-
[2 3 4 0 1 0]
695-
[3 4 5 1 0 1]
693+
[1 2 3 1 . 1]
694+
[2 3 4 . 1 .]
695+
[3 4 5 1 . 1]
696696
697697
julia> Q = vcat(M, N)
698698
[1 2 3]
699699
[2 3 4]
700700
[3 4 5]
701-
[1 0 1]
702-
[0 1 0]
703-
[1 0 1]
701+
[1 . 1]
702+
[. 1 .]
703+
[1 . 1]
704704
705705
```
706706

@@ -740,7 +740,7 @@ Test whether the given matrix has a value associated with indices `i` and `j`.
740740
```jldoctest
741741
julia> M = matrix(ZZ, BigInt[3 1 2; 2 0 1])
742742
[3 1 2]
743-
[2 0 1]
743+
[2 . 1]
744744
745745
julia> isassigned(M, 1, 2)
746746
true
@@ -756,8 +756,8 @@ julia> isassigned(A, 1, 2)
756756
false
757757
758758
julia> B = zero(M)
759-
[0 0 0]
760-
[0 0 0]
759+
[. . .]
760+
[. . .]
761761
762762
julia> C = similar(M, 4, 5)
763763
[#undef #undef #undef #undef #undef]
@@ -769,8 +769,8 @@ julia> base_ring(B)
769769
Integers
770770
771771
julia> D = zero(M, QQ, 2, 2)
772-
[0//1 0//1]
773-
[0//1 0//1]
772+
[. .]
773+
[. .]
774774
775775
julia> base_ring(D)
776776
Rationals
@@ -839,7 +839,7 @@ Matrix space of 3 rows and 3 columns
839839
over residue field of univariate polynomial ring modulo x^3 + 3*x + 1
840840
841841
julia> A = S([K(0) 2a + 3 a^2 + 1; a^2 - 2 a - 1 2a; a^2 - 2 a - 1 2a])
842-
[ 0 2*x + 3 x^2 + 1]
842+
[ . 2*x + 3 x^2 + 1]
843843
[x^2 - 2 x - 1 2*x]
844844
[x^2 - 2 x - 1 2*x]
845845
@@ -876,7 +876,7 @@ Matrix space of 3 rows and 3 columns
876876
over residue field of univariate polynomial ring modulo x^3 + 3*x + 1
877877
878878
julia> M = S([K(0) 2a + 3 a^2 + 1; a^2 - 2 a - 1 2a; a^2 + 3a + 1 2a K(1)])
879-
[ 0 2*x + 3 x^2 + 1]
879+
[ . 2*x + 3 x^2 + 1]
880880
[ x^2 - 2 x - 1 2*x]
881881
[x^2 + 3*x + 1 2*x 1]
882882
@@ -894,7 +894,7 @@ Matrix space of 3 rows and 3 columns
894894
over univariate polynomial ring in x over integers
895895
896896
julia> M = S([R(0) 2x + 3 x^2 + 1; x^2 - 2 x - 1 2x; x^2 + 3x + 1 2x R(1)])
897-
[ 0 2*x + 3 x^2 + 1]
897+
[ . 2*x + 3 x^2 + 1]
898898
[ x^2 - 2 x - 1 2*x]
899899
[x^2 + 3*x + 1 2*x 1]
900900
@@ -949,10 +949,10 @@ julia> R, x = polynomial_ring(QQ, ["x$i" for i in 1:6])
949949
(Multivariate polynomial ring in 6 variables over rationals, AbstractAlgebra.Generic.MPoly{Rational{BigInt}}[x1, x2, x3, x4, x5, x6])
950950
951951
julia> M = R[0 x[1] x[2] x[3]; -x[1] 0 x[4] x[5]; -x[2] -x[4] 0 x[6]; -x[3] -x[5] -x[6] 0]
952-
[ 0 x1 x2 x3]
953-
[-x1 0 x4 x5]
954-
[-x2 -x4 0 x6]
955-
[-x3 -x5 -x6 0]
952+
[ . x1 x2 x3]
953+
[-x1 . x4 x5]
954+
[-x2 -x4 . x6]
955+
[-x3 -x5 -x6 .]
956956
957957
julia> pfaffian(M)
958958
x1*x6 - x2*x5 + x3*x4
@@ -999,7 +999,7 @@ Matrix space of 3 rows and 3 columns
999999
over residue field of univariate polynomial ring modulo x^3 + 3*x + 1
10001000
10011001
julia> A = S([K(0) 2a + 3 a^2 + 1; a^2 - 2 a - 1 2a; a^2 + 3a + 1 2a K(1)])
1002-
[ 0 2*x + 3 x^2 + 1]
1002+
[ . 2*x + 3 x^2 + 1]
10031003
[ x^2 - 2 x - 1 2*x]
10041004
[x^2 + 3*x + 1 2*x 1]
10051005
@@ -1022,7 +1022,7 @@ Matrix space of 3 rows and 3 columns
10221022
over univariate polynomial ring in x over integers
10231023
10241024
julia> A = S([R(0) 2x + 3 x^2 + 1; x^2 - 2 x - 1 2x; x^2 + 3x + 1 2x R(1)])
1025-
[ 0 2*x + 3 x^2 + 1]
1025+
[ . 2*x + 3 x^2 + 1]
10261026
[ x^2 - 2 x - 1 2*x]
10271027
[x^2 + 3*x + 1 2*x 1]
10281028
@@ -1059,15 +1059,15 @@ Matrix space of 4 rows and 4 columns
10591059
julia> M = S([R(1) R(2) R(4) R(3); R(2) R(5) R(1) R(0);
10601060
R(6) R(1) R(3) R(2); R(1) R(1) R(3) R(5)])
10611061
[1 2 4 3]
1062-
[2 5 1 0]
1062+
[2 5 1 .]
10631063
[6 1 3 2]
10641064
[1 1 3 5]
10651065
10661066
julia> A = hessenberg(M)
10671067
[1 5 5 3]
1068-
[2 1 1 0]
1069-
[0 1 3 2]
1070-
[0 0 2 2]
1068+
[2 1 1 .]
1069+
[. 1 3 2]
1070+
[. . 2 2]
10711071
10721072
julia> is_hessenberg(A)
10731073
true
@@ -1112,9 +1112,9 @@ julia> A = matrix(ZZ, [2 3 -1; 3 5 7; 11 1 12])
11121112
[11 1 12]
11131113
11141114
julia> H = hnf(A)
1115-
[1 0 255]
1116-
[0 1 17]
1117-
[0 0 281]
1115+
[1 . 255]
1116+
[. 1 17]
1117+
[. . 281]
11181118
11191119
julia> is_hnf(H)
11201120
true
@@ -1123,9 +1123,9 @@ julia> H, U = hnf_with_transform(A)
11231123
([1 0 255; 0 1 17; 0 0 281], [-47 28 1; -3 2 0; -52 31 1])
11241124
11251125
julia> U*A
1126-
[1 0 255]
1127-
[0 1 17]
1128-
[0 0 281]
1126+
[1 . 255]
1127+
[. 1 17]
1128+
[. . 281]
11291129
```
11301130

11311131
### Smith normal form
@@ -1148,17 +1148,17 @@ julia> A = matrix(ZZ, [2 3 -1; 3 5 7; 11 1 12])
11481148
[11 1 12]
11491149
11501150
julia> S = snf(A)
1151-
[1 0 0]
1152-
[0 1 0]
1153-
[0 0 281]
1151+
[1 . .]
1152+
[. 1 .]
1153+
[. . 281]
11541154
11551155
julia> S, T, U = snf_with_transform(A)
11561156
([1 0 0; 0 1 0; 0 0 281], [1 0 0; 7 1 0; 229 31 1], [0 -3 26; 0 2 -17; -1 0 1])
11571157
11581158
julia> T*A*U
1159-
[1 0 0]
1160-
[0 1 0]
1161-
[0 0 281]
1159+
[1 . .]
1160+
[. 1 .]
1161+
[. . 281]
11621162
```
11631163

11641164
### (Weak) Popov form
@@ -1189,14 +1189,14 @@ julia> A = matrix(R, map(R, Any[1 2 3 x; x 2*x 3*x x^2; x x^2+1 x^3+x^2 x^4+x^2+
11891189
11901190
julia> P = weak_popov(A)
11911191
[ 1 2 3 x]
1192-
[ 0 0 0 0]
1192+
[ . . . .]
11931193
[-x^3 -2*x^3 + x^2 - 2*x + 1 -2*x^3 + x^2 - 3*x 1]
11941194
11951195
julia> P, U = weak_popov_with_transform(A)
11961196
([1 2 3 x; 0 0 0 0; -x^3 -2*x^3+x^2-2*x+1 -2*x^3+x^2-3*x 1], [1 0 0; -x 1 0; -x^3-x 0 1])
11971197
11981198
julia> U*A
11991199
[ 1 2 3 x]
1200-
[ 0 0 0 0]
1200+
[ . . . .]
12011201
[-x^3 -2*x^3 + x^2 - 2*x + 1 -2*x^3 + x^2 - 3*x 1]
12021202
```

docs/src/matrix_algebras.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,19 @@ Matrix ring of degree 3
8080
over univariate polynomial ring in t over rationals
8181
8282
julia> A = S()
83-
[0 0 0]
84-
[0 0 0]
85-
[0 0 0]
83+
[. . .]
84+
[. . .]
85+
[. . .]
8686
8787
julia> B = S(12)
88-
[12 0 0]
89-
[ 0 12 0]
90-
[ 0 0 12]
88+
[12 . .]
89+
[ . 12 .]
90+
[ . . 12]
9191
9292
julia> C = S(R(11))
93-
[11 0 0]
94-
[ 0 11 0]
95-
[ 0 0 11]
93+
[11 . .]
94+
[ . 11 .]
95+
[ . . 11]
9696
9797
```
9898

docs/src/polynomial.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -898,8 +898,8 @@ julia> g = 6(x + 1)*y + (x^3 + 2x + 2)
898898
899899
julia> S = sylvester_matrix(f, g)
900900
[ 3*x x + 1 3]
901-
[6*x + 6 x^3 + 2*x + 2 0]
902-
[ 0 6*x + 6 x^3 + 2*x + 2]
901+
[6*x + 6 x^3 + 2*x + 2 .]
902+
[ . 6*x + 6 x^3 + 2*x + 2]
903903
904904
julia> h = resultant(f, g)
905905
3*x^7 + 6*x^5 - 6*x^3 + 96*x^2 + 192*x + 96

src/FreeAssociativeAlgebra.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,8 @@ julia> m1 = S([1 2; 3 4])
178178
[3 4]
179179
180180
julia> m2 = S([0 1; 1 0])
181-
[0 1]
182-
[1 0]
181+
[. 1]
182+
[1 .]
183183
184184
julia> evaluate(f, [m1, m2])
185185
[-1 -3]

0 commit comments

Comments
 (0)