1
0
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:
kalmarek 2019-01-02 16:13:41 +01:00
parent 69419d9294
commit 4be3bbf5e8
2 changed files with 17 additions and 8 deletions

View File

@ -224,15 +224,24 @@ end
function show(io::IO, X::GroupRingElem) function show(io::IO, X::GroupRingElem)
RG = parent(X) RG = parent(X)
if X.coeffs == zero(X.coeffs)
T = eltype(X.coeffs) T = eltype(X.coeffs)
if X.coeffs == zero(X.coeffs)
print(io, "$(zero(T))*$((RG.group)())") print(io, "$(zero(T))*$((RG.group)())")
elseif isdefined(RG, :basis) elseif isdefined(RG, :basis)
non_zeros = ((X.coeffs[i], RG.basis[i]) for i in findall(!iszero, X.coeffs)) 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) elts = String[]
str = join(elts, "")[2:end] 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 if sign(first(non_zeros)[1]) > 0
str = str[3:end] str = str[4:end]
end end
print(io, str) print(io, str)
else else

View File

@ -98,8 +98,8 @@ using SparseArrays
@test a[5] == 1 @test a[5] == 1
@test a[p] == 1 @test a[p] == 1
@test string(a) == "1*(1,2,3)" @test string(a) == "(1,2,3)"
@test string(-a) == "- 1*(1,2,3)" @test string(-a) == " - 1(1,2,3)"
@test RG([0,0,0,0,1,0]) == a @test RG([0,0,0,0,1,0]) == a
@ -111,8 +111,8 @@ using SparseArrays
@test a[1] == 2 @test a[1] == 2
@test a[s] == 2 @test a[s] == 2
@test string(a) == "2*() + 1*(1,2,3)" @test string(a) == "2() + (1,2,3)"
@test string(-a) == "- 2*() - 1*(1,2,3)" @test string(-a) == " - 2() - 1(1,2,3)"
@test length(a) == 2 @test length(a) == 2
end end