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

Refactor some Map printing code #2877

Merged
merged 1 commit into from
Oct 3, 2023

Conversation

fingolfin
Copy link
Member

@fingolfin fingolfin commented Oct 2, 2023

Reduce some code duplication and prepare for a further reduction in the future.

The primary goal here is to remove gratuitous differences in the code, which in turn makes it trivial to detect possibly unwanted differences and other problematic behavior. I'll add some inline comments to point out specific changes.

See also Nemocas/AbstractAlgebra.jl#1450 for related changes in AbstractAlgebra.

CC @StevellM

Reduce some code duplication and prepare for a further reduction in the future
@@ -71,7 +71,7 @@ end

function Base.show(io::IO, ::MIME"text/plain", h::LieAlgebraHom)
io = pretty(io)
println(io, LowercaseOff(), "Lie algebra morphism")
println(IOContext(io, :supercompact => true), h)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ensures that this detailed printing method is identical to that for LieAlgebraModuleHom or GAPGroupHomomorphism

@@ -122,7 +122,9 @@ function Base.show(io::IOContext, Phi::MorphismFromRationalFunctions)
if get(io, :supercompact, false)
print("Morphism from rational functions")
else
print("Hom: ", X, " -> ", Y)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes a bug, X and Y are not defined in this function

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This also means there is no test for this printing variant, so ideally we should add one)

@@ -122,7 +122,9 @@ function Base.show(io::IOContext, Phi::MorphismFromRationalFunctions)
if get(io, :supercompact, false)
print("Morphism from rational functions")
else
print("Hom: ", X, " -> ", Y)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This also means there is no test for this printing variant, so ideally we should add one)

print("Hom: ", X, " -> ", Y)
io = pretty(io)
print(io, "Hom: ")
print(io, Lowercase(), domain(Phi), " -> ", Lowercase(), codomain(Phi))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In other functions we print this in "supercompact" mode. But not here and not in some others. One can argue either way, for now I wanted to keep this change "simple" while also aligning it as much as possible with other show methods for maps here and in other repos.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not understand, which part is printed in "supercompact" in other functions ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is "one line" printing mode, and the recommendation (though not a requirement) is that any delegation it performs uses "supercompact" mode, to help ensure the "one line" promise is kept. So for other kinds of maps we do

print(IOContext(io, :supercompact => true), Lowercase(), domain(x), " -> ", Lowercase(), codomain(x))

@@ -19,7 +17,7 @@ function Base.show(io::IO, X::AbsProjectiveVariety{<:Field,<:MPolyQuoRing})
elseif get_attribute(X, :is_empty, false)
print(io, "Empty projective variety")
else
print(io, "V(")
print(io, LowercaseOff(), "V(")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ensures the V always is in uppercase, so technically this is a bug fix, albeit a very minor one

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to have this function, I was not aware of this one, thanks !

psi = restricted_map(phi)
to = is_unicode_allowed() ? " ↦ " : " -> "
for i in 1:ngens(R)-1
println(io, R[i], to, psi(R[i]))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is just about minimizing code duplication and simplification... though it also fixes a bug (in the unicode variant, there was a final println instead of a final print)

print(io, "Hom: ")
if typeof(X) <: Union{PrincipalOpenSubset, AffineVariety{ <:Field, <: MPolyAnyRing}, <:Spec{<:Field, <:MPolyAnyRing}} # Take care of the case where the domain is not given as a V(bla)
print(io, Lowercase())
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This case was checking for specific types of X to decide whether or not to issue Lowercase() -- that's a bad code smell, don't do that! Here, the proper fix is to ensure that the sub-object issues LowercaseOff if necessary (I've done on such change elsewhere in this PR).

@StevellM There is more printing code for Schemes which performs similar checks that should be changed. I'll write to you about this separately on Slack.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good, as mentioned in another comment, I was not aware this was an option. I will add it to the list of things to be changed among others for the schemes' printings.

Copy link
Member

@lgoettgens lgoettgens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes to Lie algebra stuff look fine. Didn't check the rest.

@codecov
Copy link

codecov bot commented Oct 2, 2023

Codecov Report

Merging #2877 (037dcbf) into master (141adbf) will increase coverage by 0.00%.
Report is 1 commits behind head on master.
The diff coverage is 87.50%.

@@           Coverage Diff           @@
##           master    #2877   +/-   ##
=======================================
  Coverage   80.50%   80.51%           
=======================================
  Files         456      456           
  Lines       65214    65194   -20     
=======================================
- Hits        52502    52491   -11     
+ Misses      12712    12703    -9     
Files Coverage Δ
experimental/LieAlgebras/src/LieAlgebraHom.jl 90.90% <100.00%> (+4.54%) ⬆️
...xperimental/LieAlgebras/src/LieAlgebraModuleHom.jl 85.53% <100.00%> (+2.51%) ⬆️
...eometry/Schemes/AffineSchemes/Morphisms/Methods.jl 91.22% <100.00%> (-0.58%) ⬇️
.../Schemes/ProjectiveAlgebraicSet/Objects/Methods.jl 82.35% <100.00%> (ø)
...try/Schemes/ProjectiveSchemes/Morphisms/Methods.jl 78.57% <100.00%> (-1.65%) ⬇️
...Geometry/ToricVarieties/ToricSchemes/attributes.jl 68.65% <ø> (ø)
src/Groups/homomorphisms.jl 93.33% <100.00%> (ø)
src/Rings/MPolyMap/MPolyAnyMap.jl 94.00% <100.00%> (+1.07%) ⬆️
src/Rings/mpoly-graded.jl 91.20% <100.00%> (+0.10%) ⬆️
src/Rings/mpolyquo-localizations.jl 74.22% <100.00%> (+0.63%) ⬆️
... and 3 more

... and 8 files with indirect coverage changes

@fingolfin fingolfin merged commit 1bd5727 into oscar-system:master Oct 3, 2023
@fingolfin fingolfin deleted the mh/map-printing branch October 3, 2023 20:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants