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

Add Vinberg's algorithm #4023

Open
wants to merge 19 commits into
base: master
Choose a base branch
from

Conversation

ElMerkel
Copy link

I added an implementation of Vinberg's algorithm for computing fundamental roots of Lorentzian lattices.

@simonbrandhorst
@StevellM

Copy link

codecov bot commented Aug 19, 2024

Codecov Report

Attention: Patch coverage is 95.10490% with 7 lines in your changes missing coverage. Please review.

Project coverage is 84.66%. Comparing base (56eaf4a) to head (5e6acd6).
Report is 11 commits behind head on master.

Files with missing lines Patch % Lines
src/NumberTheory/vinberg.jl 95.03% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4023      +/-   ##
==========================================
+ Coverage   84.10%   84.66%   +0.55%     
==========================================
  Files         612      613       +1     
  Lines       83067    83393     +326     
==========================================
+ Hits        69865    70606     +741     
+ Misses      13202    12787     -415     
Files with missing lines Coverage Δ
src/Oscar.jl 69.13% <100.00%> (+0.78%) ⬆️
src/NumberTheory/vinberg.jl 95.03% <95.03%> (ø)

... and 57 files with indirect coverage changes

docs/doc.main Outdated Show resolved Hide resolved
docs/oscar_references.bib Outdated Show resolved Hide resolved
series = {Tata Inst. Fundam. Res. Stud. Math.},
volume = {No. 7},
pages = {323--348},
publisher = {Published for the Tata Institute of Fundamental Research, Bombay by Oxford University Press, Bombay},
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, did you run bibtool as described here?

Copy link
Member

Choose a reason for hiding this comment

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

Also, if there is a DOI available, please add it as well.

author = {Turkalj, I.},
title = {Reflective Lorentzian lattices of signature (5, 1)},
year = {2017},
school = {TU Dortmund}
Copy link
Member

Choose a reason for hiding this comment

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

There is also a paper, could that be cited instead? See https://doi.org/10.1016/j.jalgebra.2018.06.013

If not, a URL or better a DOI to the thesis would be great

docs/src/LinearAlgebra/vinberg.md Outdated Show resolved Hide resolved
docs/src/LinearAlgebra/vinberg.md Outdated Show resolved Hide resolved
docs/src/LinearAlgebra/vinberg.md Outdated Show resolved Hide resolved
end

@doc raw"""
vinberg_algorithm(Q::ZZMatrix, upper_bound::ZZRingElem; v0::ZZMatrix, root_lengths::Vector{ZZRingElem}, direction_vector::ZZMatrix) -> Vector{ZZMatrix}
Copy link
Member

Choose a reason for hiding this comment

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

Q is a matrix, not a lattice, though the text below refers to it as "a lattice". This always opens up ambiguities as to how to interpret that matrix. I thought we had types specifically to represent lattices, such as ZZLat, why not use that?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Indeed, I agree with fingolfin please prepare a dispatch via ZZLat.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@ElMerkel You marked this as resolved, but I cannot find the method with ZZLat as argument. Did you upload your changes?

Copy link
Author

Choose a reason for hiding this comment

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

Oh I did not know that you can see when I mark a conversation as resolved. I thought that I can use this for having a better overall view of the feedback. I am sorry, I can imagine that this led to confusion. The code should be uploaded now.

src/NumberTheory/vinberg.jl Outdated Show resolved Hide resolved
src/NumberTheory/vinberg.jl Outdated Show resolved Hide resolved
src/NumberTheory/vinberg.jl Outdated Show resolved Hide resolved
@fieker
Copy link
Contributor

fieker commented Aug 28, 2024

Needs sorting and possibly moved to experimental? @simonbrandhorst any idea? It's your baby....(indirectly)

@lgoettgens lgoettgens removed the triage label Aug 28, 2024
@simonbrandhorst
Copy link
Collaborator

@fieker Yes, I commissioned this and will take care of this PR.
@ElMerkel Thanks for the very nice work! More comments will follow later on.

docs/src/LinearAlgebra/vinberg.md Outdated Show resolved Hide resolved
docs/src/LinearAlgebra/vinberg.md Outdated Show resolved Hide resolved
docs/src/LinearAlgebra/vinberg.md Outdated Show resolved Hide resolved
docs/src/LinearAlgebra/vinberg.md Outdated Show resolved Hide resolved
docs/src/LinearAlgebra/vinberg.md Outdated Show resolved Hide resolved
src/NumberTheory/vinberg.jl Outdated Show resolved Hide resolved
src/NumberTheory/vinberg.jl Outdated Show resolved Hide resolved
src/NumberTheory/vinberg.jl Show resolved Hide resolved
Comment on lines +284 to +285
if _crystallographic_condition(Q, v)
if _check_coorientation(Q, roots, v, v0)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is the hot loop. So these two function will be called many times. Can you make them non-allocating?

src/NumberTheory/vinberg.jl Outdated Show resolved Hide resolved
@simonbrandhorst
Copy link
Collaborator

The math looks good to me.

Comment on lines +104 to +109
gcd = reduce(gcd, v)
if isone(gcd)
return v
else
return (1 // gcd * v)
end
Copy link
Member

Choose a reason for hiding this comment

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

Minor comment: I would recommend not re-using a name like gcd for a local variable, perhaps call it g.

More importantlu, though, I don't think the else part works, or at least it doesn't when I tried it locally:

julia> v = matrix(ZZ, 6 * [1 2 ; 3 4])
[ 6   12]
[18   24]

julia> g = reduce(gcd, v)
6

julia> (1 // g * v)
ERROR: Cannot promote to common type

Even if it works, I would expect this to return a QQMatrix, which is probably not what you want. However, this works:

julia> v / g
[1   2]
[3   4]

So overall perhaps use this?

Suggested change
gcd = reduce(gcd, v)
if isone(gcd)
return v
else
return (1 // gcd * v)
end
g = reduce(gcd, v)
if isone(g)
return v
else
return v / g
end

or even

Suggested change
gcd = reduce(gcd, v)
if isone(gcd)
return v
else
return (1 // gcd * v)
end
g = reduce(gcd, v)
return isone(g) ? v : v / g

negative_eigenvalue = x
break
end
stopping_condition =+
Copy link
Member

Choose a reason for hiding this comment

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

Looks as if something is wrong here? Perhaps this was meant?

Suggested change
stopping_condition =+
stopping_condition += 1

Comment on lines +12 to +22
Eigenvalues = eigenvalues(QQ, Q)
stopping_condition = 0
negative_eigenvalue = 0
for x in Eigenvalues
if x < 0
negative_eigenvalue = x
break
end
stopping_condition =+
end
@req stopping_condition < length(Eigenvalues) "Q is not of signature (1, n)"
Copy link
Member

Choose a reason for hiding this comment

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

Actually, if I understand this code right, perhaps you could write it like this?

Suggested change
Eigenvalues = eigenvalues(QQ, Q)
stopping_condition = 0
negative_eigenvalue = 0
for x in Eigenvalues
if x < 0
negative_eigenvalue = x
break
end
stopping_condition =+
end
@req stopping_condition < length(Eigenvalues) "Q is not of signature (1, n)"
ev = eigenvalues(QQ, Q)
pos = findfirst(is_negative, ev)
@req pos === nothing "Q is not of signature (1, n)"
x = ev[pos]

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.

5 participants