Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix (change) printing of complexes #1181

Merged
merged 2 commits into from
Aug 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 85 additions & 31 deletions src/GrpAb/ChainComplex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,6 @@
set_attribute!(C, :show=>nothing)
end


function shift(C::ComplexOfMorphisms{T}, n::Int) where T
if iseven(n)
ComplexOfMorphisms(T, copy(C.maps), seed = C.seed+n, typ = C.typ)
Expand All @@ -329,7 +328,19 @@

Hecke.base_ring(::GrpAbFinGen) = ZZ

function free_show(io::IO, C::ComplexOfMorphisms)
function get_name(M, na::String)
name = get_attribute(M, :name)
if name !== nothing
return name

Check warning on line 334 in src/GrpAb/ChainComplex.jl

View check run for this annotation

Codecov / codecov/patch

src/GrpAb/ChainComplex.jl#L331-L334

Added lines #L331 - L334 were not covered by tests
end
name = AbstractAlgebra.find_name(M)
if name !== nothing
return String(name)

Check warning on line 338 in src/GrpAb/ChainComplex.jl

View check run for this annotation

Codecov / codecov/patch

src/GrpAb/ChainComplex.jl#L336-L338

Added lines #L336 - L338 were not covered by tests
end
return na

Check warning on line 340 in src/GrpAb/ChainComplex.jl

View check run for this annotation

Codecov / codecov/patch

src/GrpAb/ChainComplex.jl#L340

Added line #L340 was not covered by tests
end

function pres_show(io::IO, C::ComplexOfMorphisms)

Check warning on line 343 in src/GrpAb/ChainComplex.jl

View check run for this annotation

Codecov / codecov/patch

src/GrpAb/ChainComplex.jl#L343

Added line #L343 was not covered by tests
Cn = get_attribute(C, :name)
if Cn === nothing
Cn = "F"
Expand All @@ -339,19 +350,75 @@
rank_mod = Int[]

rng = range(C)
if C.typ == :chain
arr = ("--", "-->")
else
arr = ("<--", "--")
arr = ("<--", "--")

Check warning on line 353 in src/GrpAb/ChainComplex.jl

View check run for this annotation

Codecov / codecov/patch

src/GrpAb/ChainComplex.jl#L353

Added line #L353 was not covered by tests

R = Nemo.base_ring(C[first(rng)])
R_name = get_name(R, "$R")

Check warning on line 356 in src/GrpAb/ChainComplex.jl

View check run for this annotation

Codecov / codecov/patch

src/GrpAb/ChainComplex.jl#L355-L356

Added lines #L355 - L356 were not covered by tests

for i=reverse(rng)
M = C[i]
if i == -1 #the object that is presented
push!(name_mod, get_name(M, "M"))
push!(rank_mod, 0)

Check warning on line 362 in src/GrpAb/ChainComplex.jl

View check run for this annotation

Codecov / codecov/patch

src/GrpAb/ChainComplex.jl#L358-L362

Added lines #L358 - L362 were not covered by tests
else
push!(name_mod, get_name(M, "$R_name^$(rank(M))"))
push!(rank_mod, rank(M))

Check warning on line 365 in src/GrpAb/ChainComplex.jl

View check run for this annotation

Codecov / codecov/patch

src/GrpAb/ChainComplex.jl#L364-L365

Added lines #L364 - L365 were not covered by tests
end
end

io = IOContext(io, :compact => true)

Check warning on line 369 in src/GrpAb/ChainComplex.jl

View check run for this annotation

Codecov / codecov/patch

src/GrpAb/ChainComplex.jl#L369

Added line #L369 was not covered by tests
# print(io, "Presentation")
# N = get_attribute(C, :free_res)
# if N !== nothing
# print(io, " of ", N)
# end
# print(io, "\n")

pos = 0
pos_mod = Int[]

Check warning on line 378 in src/GrpAb/ChainComplex.jl

View check run for this annotation

Codecov / codecov/patch

src/GrpAb/ChainComplex.jl#L377-L378

Added lines #L377 - L378 were not covered by tests

for i=1:length(name_mod)
print(io, name_mod[i])
push!(pos_mod, pos)
pos += length(name_mod[i])
if i < length(name_mod)
print(io, " ", arr[1], arr[2], " ")
pos += length(arr[1]) + length(arr[2]) + 2

Check warning on line 386 in src/GrpAb/ChainComplex.jl

View check run for this annotation

Codecov / codecov/patch

src/GrpAb/ChainComplex.jl#L380-L386

Added lines #L380 - L386 were not covered by tests
end
end

Check warning on line 388 in src/GrpAb/ChainComplex.jl

View check run for this annotation

Codecov / codecov/patch

src/GrpAb/ChainComplex.jl#L388

Added line #L388 was not covered by tests
# print(io, "\n")
# len = 0
# for i=1:length(name_mod)
# if i>1
# print(io, " "^(pos_mod[i] - pos_mod[i-1]-len +1))
# end
# print(io, rng[i])
# len += length("$(rng[i])")
# end
# print(io, "\n")
end


function free_show(io::IO, C::ComplexOfMorphisms)
Cn = get_attribute(C, :name)
if Cn === nothing
Cn = "F"

Check warning on line 405 in src/GrpAb/ChainComplex.jl

View check run for this annotation

Codecov / codecov/patch

src/GrpAb/ChainComplex.jl#L402-L405

Added lines #L402 - L405 were not covered by tests
end

name_mod = String[]
rank_mod = Int[]

Check warning on line 409 in src/GrpAb/ChainComplex.jl

View check run for this annotation

Codecov / codecov/patch

src/GrpAb/ChainComplex.jl#L408-L409

Added lines #L408 - L409 were not covered by tests

rng = range(C)
rng = first(rng)-1:-1:0
arr = ("<--", "--")

Check warning on line 413 in src/GrpAb/ChainComplex.jl

View check run for this annotation

Codecov / codecov/patch

src/GrpAb/ChainComplex.jl#L411-L413

Added lines #L411 - L413 were not covered by tests

R = Nemo.base_ring(C[first(rng)])
R_name = get_attribute(R, :name)
if R_name === nothing
R_name = "$R"
end

for i=rng
for i=reverse(rng)

Check warning on line 421 in src/GrpAb/ChainComplex.jl

View check run for this annotation

Codecov / codecov/patch

src/GrpAb/ChainComplex.jl#L421

Added line #L421 was not covered by tests
M = C[i]
if get_attribute(M, :name) !== nothing
push!(name_mod, get_attribute(M, :name))
Expand All @@ -371,25 +438,27 @@

pos = 0
pos_mod = Int[]

for i=1:length(name_mod)
print(io, name_mod[i])
push!(pos_mod, pos)
pos += length(name_mod[i])
if i < length(name_mod)
print(io, arr[1], arr[2], " ")
pos += length(arr[1]) + length(arr[2]) + 1
print(io, " ", arr[1], arr[2], " ")
pos += length(arr[1]) + length(arr[2]) + 2

Check warning on line 448 in src/GrpAb/ChainComplex.jl

View check run for this annotation

Codecov / codecov/patch

src/GrpAb/ChainComplex.jl#L447-L448

Added lines #L447 - L448 were not covered by tests
end
end

print(io, "\n")
len = 0
for i=1:length(name_mod)
if i>1
print(io, " "^(pos_mod[i] - pos_mod[i-1]-len))
end
print(io, rank_mod[i])
len += length("$(rank_mod[i])")
print(io, reverse(rng)[i])
len = length("$(reverse(rng)[i])")

Check warning on line 459 in src/GrpAb/ChainComplex.jl

View check run for this annotation

Codecov / codecov/patch

src/GrpAb/ChainComplex.jl#L458-L459

Added lines #L458 - L459 were not covered by tests
end
print(io, "\n")
# print(io, "\n")
end

function show(io::IO, C::ComplexOfMorphisms)
Expand All @@ -406,37 +475,25 @@
mis_mod = Tuple{Int, <:Any}[]

rng = range(C)
arr = ("<--", "--")

Check warning on line 478 in src/GrpAb/ChainComplex.jl

View check run for this annotation

Codecov / codecov/patch

src/GrpAb/ChainComplex.jl#L478

Added line #L478 was not covered by tests
if is_chain_complex(C)
arr = ("--", "-->")
dir = 1
else
arr = ("<--", "--")
arr = ("--", "-->")
dir = 0
end

for i=rng
M = obj(C, i)
# if get_attribute(M, :name) !== nothing
# name_mod[i] = get_attribute(M, :name)
# else
if is_chain_complex(C)
name_mod[i] = "$(Cn)_$i"
else
name_mod[i] = "$(Cn)^$i"
end
# AbstractAlgebra.set_name!(M)
# if get_attribute(M, :name) !== nothing
# name_mod[i] = get_attribute(M, :name)
# else
# push!(mis_mod, (i, M))
# end
# end
end

io = IOContext(io, :compact => true)
for i=rng
if i == first(rng)
for i=reverse(rng)
if i == last(rng)

Check warning on line 496 in src/GrpAb/ChainComplex.jl

View check run for this annotation

Codecov / codecov/patch

src/GrpAb/ChainComplex.jl#L495-L496

Added lines #L495 - L496 were not covered by tests
print(io, name_mod[i])
continue
end
Expand All @@ -447,9 +504,6 @@
for (i, M) = mis_mod
print(io, "\t$(name_mod[i]) = ", M, "\n")
end
# for (i, phi) = mis_map
# print(io, "\tphi_$i = ", phi, "\n")
# end
end
end

Expand Down
Loading