mirror of
https://github.com/kalmarek/GroupRings.jl.git
synced 2024-11-19 06:30:27 +01:00
better printing
This commit is contained in:
parent
69419d9294
commit
4be3bbf5e8
@ -224,15 +224,24 @@ end
|
||||
|
||||
function show(io::IO, X::GroupRingElem)
|
||||
RG = parent(X)
|
||||
if X.coeffs == zero(X.coeffs)
|
||||
T = eltype(X.coeffs)
|
||||
if X.coeffs == zero(X.coeffs)
|
||||
print(io, "$(zero(T))*$((RG.group)())")
|
||||
elseif isdefined(RG, :basis)
|
||||
non_zeros = ((X.coeffs[i], RG.basis[i]) for i in findall(!iszero, X.coeffs))
|
||||
elts = ("$(sign(c)> 0 ? " + " : " - ")$(abs(c))*$g" for (c,g) in non_zeros)
|
||||
str = join(elts, "")[2:end]
|
||||
elts = String[]
|
||||
for (c,g) in non_zeros
|
||||
sgn = (sign(c)>=0 ? " + " : " - ")
|
||||
if c == T(1)
|
||||
coeff = ""
|
||||
else
|
||||
coeff = "$(abs(c))"
|
||||
end
|
||||
push!(elts, sgn*coeff*"$(g)")
|
||||
end
|
||||
str = join(elts, "")
|
||||
if sign(first(non_zeros)[1]) > 0
|
||||
str = str[3:end]
|
||||
str = str[4:end]
|
||||
end
|
||||
print(io, str)
|
||||
else
|
||||
|
@ -98,8 +98,8 @@ using SparseArrays
|
||||
@test a[5] == 1
|
||||
@test a[p] == 1
|
||||
|
||||
@test string(a) == "1*(1,2,3)"
|
||||
@test string(-a) == "- 1*(1,2,3)"
|
||||
@test string(a) == "(1,2,3)"
|
||||
@test string(-a) == " - 1(1,2,3)"
|
||||
|
||||
@test RG([0,0,0,0,1,0]) == a
|
||||
|
||||
@ -111,8 +111,8 @@ using SparseArrays
|
||||
@test a[1] == 2
|
||||
@test a[s] == 2
|
||||
|
||||
@test string(a) == "2*() + 1*(1,2,3)"
|
||||
@test string(-a) == "- 2*() - 1*(1,2,3)"
|
||||
@test string(a) == "2() + (1,2,3)"
|
||||
@test string(-a) == " - 2() - 1(1,2,3)"
|
||||
|
||||
@test length(a) == 2
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user