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

Move obvious type piracy from Hecke to Nemo #1501

Merged
merged 18 commits into from
Jul 6, 2023

Conversation

lgoettgens
Copy link
Collaborator

@lgoettgens lgoettgens commented Jun 28, 2023

Resolves parts of thofma/Hecke.jl#1126.

I will have a look through the Hecke files that contain many cases of reported type piracy, and move those functions to Nemo, that are either trivial in their implementation, or if it is clear that they only use functionality already in Nemo (like calls to flint).

Functions, where I do not directly see a good place to put them, will be in some files named after the Hecke file they originate from for the time being. Moving them around in Nemo is easy to do later in a separate PR. Or if you have any recommendations, let me know and I will move them in this PR.

The then duplicate functions will be removed from Hecke at thofma/Hecke.jl#1143.

return c < 0
end

function mulmod(a::UInt, b::UInt, n::UInt, ni::UInt)
Copy link
Member

Choose a reason for hiding this comment

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

There are probably better places for this and other functions. What's the plan here? Move the first into this file and merge it; and then when we are done, we can take our time to move things to a nicer place?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Functions, where I do not directly see a good place to put them, will be in some files named after the Hecke file they originate from for the time being. Moving them around in Nemo is easy to do later in a separate PR. Or if you have any recommendations, let me know and I will move them in this PR.

Copy link
Member

Choose a reason for hiding this comment

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

src/flint/fmpz.jl?

@fingolfin
Copy link
Member

Maybe it would be best to organize a meeting (real or virtual) involving at least @lgoettgens @thofma and @fieker (I am also happy to join) to closely coordinate these changes and do them in 1-2 days, instead of having all these disruptive changes spaced out over multiple weeks and PRs and so on....

@lgoettgens
Copy link
Collaborator Author

Maybe it would be best to organize a meeting (real or virtual) involving at least @lgoettgens @thofma and @fieker (I am also happy to join) to closely coordinate these changes and do them in 1-2 days, instead of having all these disruptive changes spaced out over multiple weeks and PRs and so on....

That sounds like a good idea. I am available to travel to Kaiserslautern or Siegen for a few days. Or meet online. Let's further plan this on slack.

Copy link
Member

@fingolfin fingolfin left a comment

Choose a reason for hiding this comment

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

A couple more semi-random suggestions. I'd like to stress that these are just meant as food for thought. I don't mind merging the PR w/o them (of course there are other blockers for merging, like tests need to pass and syncing with our other packages be sorted out).

Comment on lines 31 to 61
function remove(z::T, p::T) where {T<:Integer}
z == 0 && return (0, z)
v = 0
@assert p > 1
while mod(z, p) == 0
z = Base.div(z, p)
v += 1
end
return (v, z)
end

function remove(z::Rational{T}, p::T) where {T<:Integer}
z == 0 && return (0, z)
v, d = remove(denominator(z), p)
w, n = remove(numerator(z), p)
return w - v, n // d
end

function valuation(z::T, p::T) where {T<:Integer}
z == 0 && return 0
v = 0
@assert p > 1
while mod(z, p) == 0
z = Base.div(z, p)
v += 1
end
return v
end

function valuation(z::Rational{T}, p::T) where {T<:Integer}
z == 0 && error("Not yet implemented")
v = valuation(denominator(z), p)
w = valuation(numerator(z), p)
return w - 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.

These could even go into AbstractAlgebra, no?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I do not know if it is easier to manage large PRs over three repos right now or first move stuff from Hecke to Nemo and then later, in a separate PR, tackle the Nemo <-> AbstractAlgebra side. For the moment, I am doing the later.

Copy link
Collaborator Author

@lgoettgens lgoettgens Jul 3, 2023

Choose a reason for hiding this comment

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

Changed my plan. There now is Nemocas/AbstractAlgebra.jl#1392 containing the parts of this PR that belong to AA.

src/HeckeMiscInteger.jl Outdated Show resolved Hide resolved
Comment on lines 72 to 76
function remove!(a::QQFieldElem, b::ZZRingElem)
nr = ccall((:fmpq_numerator_ptr, libflint), Ptr{ZZRingElem}, (Ref{QQFieldElem},), a)
vn = ccall((:fmpz_remove, libflint), Clong, (Ptr{ZZRingElem}, Ptr{ZZRingElem}, Ref{ZZRingElem}), nr, nr, b)
#QQFieldElem's are simplified: either num OR den will be non-trivial
if vn != 0
return vn, a
end
nr = ccall((:fmpq_denominator_ptr, libflint), Ptr{ZZRingElem}, (Ref{QQFieldElem},), a)
vn = ccall((:fmpz_remove, libflint), Clong, (Ptr{ZZRingElem}, Ptr{ZZRingElem}, Ref{ZZRingElem}), nr, nr, b)
return -vn, a
end

function valuation!(a::QQFieldElem, b::ZZRingElem)
nr = ccall((:fmpq_numerator_ptr, libflint), Ptr{ZZRingElem}, (Ref{QQFieldElem},), a)
vn = ccall((:fmpz_remove, libflint), Clong, (Ptr{ZZRingElem}, Ptr{ZZRingElem}, Ref{ZZRingElem}), nr, nr, b)
#QQFieldElem's are simplified: either num OR den will be non-trivial
if vn != 0
return vn
end
nr = ccall((:fmpq_denominator_ptr, libflint), Ptr{ZZRingElem}, (Ref{QQFieldElem},), a)
vn = ccall((:fmpz_remove, libflint), Clong, (Ptr{ZZRingElem}, Ptr{ZZRingElem}, Ref{ZZRingElem}), nr, nr, b)
return -vn
end

function BigFloat(a::QQFieldElem)
r = BigFloat(0)
ccall((:fmpq_get_mpfr, libflint), Nothing, (Ref{BigFloat}, Ref{QQFieldElem}, Int32), r, a, __get_rounding_mode())
return r
end

function isless(a::Float64, b::QQFieldElem)
return a < b * 1.0
end
function isless(a::QQFieldElem, b::Float64)
return a * 1.0 < b
end
Copy link
Member

Choose a reason for hiding this comment

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

belongs to src/flint/fmpq.jl...

Though I guess we could also move all the methods involving BigFloat inputs into a file of their own... a matter of taste, I am open to either or a third alternative.

src/HeckeMiscInteger.jl Outdated Show resolved Hide resolved
src/HeckeMiscInteger.jl Outdated Show resolved Hide resolved
return c < 0
end

function mulmod(a::UInt, b::UInt, n::UInt, ni::UInt)
Copy link
Member

Choose a reason for hiding this comment

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

src/flint/fmpz.jl?

src/HeckeMiscInteger.jl Outdated Show resolved Hide resolved
src/HeckeMiscInteger.jl Outdated Show resolved Hide resolved
src/HeckeMiscInteger.jl Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Jun 29, 2023

Codecov Report

Merging #1501 (2819441) into master (2942627) will decrease coverage by 6.02%.
The diff coverage is 10.50%.

@@            Coverage Diff             @@
##           master    #1501      +/-   ##
==========================================
- Coverage   88.78%   82.76%   -6.02%     
==========================================
  Files          89       95       +6     
  Lines       34346    37181    +2835     
==========================================
+ Hits        30494    30773     +279     
- Misses       3852     6408    +2556     
Impacted Files Coverage Δ
src/Nemo.jl 29.41% <ø> (ø)
src/arb/acb.jl 87.42% <0.00%> (-0.44%) ⬇️
src/arb/arb.jl 87.72% <0.00%> (-1.00%) ⬇️
src/flint/fmpq.jl 85.60% <0.00%> (-9.18%) ⬇️
src/HeckeMoreStuff.jl 3.20% <3.20%> (ø)
src/HeckeMiscPoly.jl 7.05% <7.05%> (ø)
src/HeckeMiscMatrix.jl 13.59% <13.59%> (ø)
src/flint/fmpz.jl 91.03% <15.38%> (-2.74%) ⬇️
src/HeckeMiscInteger.jl 16.10% <16.10%> (ø)
src/HeckeMiscFiniteField.jl 38.59% <38.59%> (ø)
... and 1 more

... and 10 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@lgoettgens lgoettgens force-pushed the lg/hecke-piracy branch 3 times, most recently from 9020a7d to ebf791e Compare June 29, 2023 15:42
@lgoettgens
Copy link
Collaborator Author

The number of reported piracy cases already went down from 721 to 425!

@lgoettgens lgoettgens force-pushed the lg/hecke-piracy branch 3 times, most recently from 2a83a9e to 93fba0a Compare July 1, 2023 17:09
src/HeckeMiscMatrix.jl Outdated Show resolved Hide resolved
@lgoettgens
Copy link
Collaborator Author

lgoettgens commented Jul 3, 2023

The OscarCI-release failures are expected as this is a breaking change.
The OscarCI-matching-1.8 failures will be fixed by oscar-system/Oscar.jl#2442.
As the OscarCI-matching-1.6 succeeded, I think this is good to go.

@lgoettgens lgoettgens marked this pull request as ready for review July 3, 2023 08:49
@lgoettgens
Copy link
Collaborator Author

lgoettgens commented Jul 3, 2023

The now relevant CI for everything working is the OscarCI-matching in Nemocas/AbstractAlgebra.jl#1392.

@lgoettgens
Copy link
Collaborator Author

lgoettgens commented Jul 3, 2023

The move of some stuff to AbstractAlgebra seemed too involved for me to fix it in the next days. Thus I would revert back to the original plan to just move a lot of stuff from Hecke to Nemo in this PR, and look to Nemo and AA sometime in the future.
I guess we will already have enough fun with the other breaking changes in AA for the next release.

@thofma thofma merged commit 513e097 into Nemocas:master Jul 6, 2023
@lgoettgens lgoettgens deleted the lg/hecke-piracy branch July 6, 2023 10:02
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