From f2547b30c4dd8617f215a8bccb5196e74284cc2c Mon Sep 17 00:00:00 2001 From: Tommy Hofmann Date: Sat, 10 Jul 2021 12:07:54 +0200 Subject: [PATCH] New Nemo/AA version (#339) * Fix promote rules * Bump version * Remove next_prime (now in Nemo) --- Project.toml | 4 +- src/Misc/FiniteField.jl | 2 +- src/Misc/Localization.jl | 3 ++ src/Misc/Primes.jl | 72 ++------------------------------- src/Misc/Residue.jl | 3 ++ src/NfOrd/Hensel.jl | 2 +- src/QuadForm/Quad/NormalForm.jl | 2 +- test/Misc/Primes.jl | 8 +--- 8 files changed, 17 insertions(+), 79 deletions(-) diff --git a/Project.toml b/Project.toml index f1c460acc4..5a0c2c7458 100644 --- a/Project.toml +++ b/Project.toml @@ -25,8 +25,8 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" [compat] -AbstractAlgebra = "^0.18.0" -Nemo = "^0.24.0" +AbstractAlgebra = "^0.19.0" +Nemo = "^0.25.0" RandomExtensions = "0.4.3" Requires = "^0.5.2, 1.0" julia = "1" diff --git a/src/Misc/FiniteField.jl b/src/Misc/FiniteField.jl index 6378038fc1..9d50e9fdb6 100644 --- a/src/Misc/FiniteField.jl +++ b/src/Misc/FiniteField.jl @@ -226,7 +226,7 @@ end Nemo.promote_rule(::Type{fq_nmod}, ::Type{gfp_elem}) = fq_nmod -Nemo.promote_rule(::Type{fq}, ::Type{Generic.ResF{fmpz}}) = fq +Nemo.promote_rule(::Type{fq}, ::Type{gfp_fmpz_elem}) = fq ################################################################################ # diff --git a/src/Misc/Localization.jl b/src/Misc/Localization.jl index 96593b0ea5..9556b237fe 100644 --- a/src/Misc/Localization.jl +++ b/src/Misc/Localization.jl @@ -15,3 +15,6 @@ function rand(L::Loc{T}, num_scale = (1:1000), den_scale=(1:1000)) where {T <: f end return L(num//den) end + +Nemo.promote_rule(::Type{LocElem{T}}, ::Type{T}) where {T} = LocElem{T} + diff --git a/src/Misc/Primes.jl b/src/Misc/Primes.jl index e6cd305309..34f923b08c 100644 --- a/src/Misc/Primes.jl +++ b/src/Misc/Primes.jl @@ -11,76 +11,12 @@ function isprime(x::Integer) return isprime(fmpz(x)) end -################################################################################ -# -# Missing next_prime functionality -# -################################################################################ - -function next_prime(x::UInt, proof::Bool) - z = ccall((:n_nextprime, libflint), UInt, (UInt, Cint), x, Cint(proof)) - return z -end - -function next_prime(x::Int, proof::Bool) - x < 0 && error("Argument must be positive") - z = next_prime(UInt(x), proof) - z > typemax(Int) && error("Next prime of input does not fit into an Int") - return Int(z) +function next_prime(x::BigInt, proved::Bool = true) + return BigInt(next_prime(fmpz(x), proved)) end -function next_prime(x::Int) - x < 0 && error("Argument must be positive") - z = next_prime(x, false) - return z -end - -function next_prime(z::T) where T <: Integer - z < 0 && error("Argument must be positive") - - Tone = one(z) - Tzero = zero(z) - Ttwo = T(2) - - if iszero(z) || isone(z) - return Ttwo - end - - if iseven(z) - z += Tone - else - z += Ttwo - end - - while !isprime(z) - z += Ttwo - end - - return z -end - -function next_prime(z::fmpz) - z < 0 && error("Argument must be positive") - - Tone = one(z) - Tzero = zero(z) - Ttwo = fmpz(2) - - if isone(z) || iszero(z) - return Ttwo - end - - if iseven(z) - z += Tone - else - z += Ttwo - end - - while !isprime(z) - Nemo.addeq!(z, Ttwo) - end - - return z +function next_prime(x::T, proved::Bool = true) where {T <: Integer} + return T(next_prime(BigInt(x), proved)) end ################################################################################ diff --git a/src/Misc/Residue.jl b/src/Misc/Residue.jl index a1e8e6772a..3c338403d7 100644 --- a/src/Misc/Residue.jl +++ b/src/Misc/Residue.jl @@ -1,3 +1,6 @@ +function divexact(a::fmpz_mod, y::fmpz) + return divexact(a, parent(a)(y)) +end function lift(a::Generic.Res) return a.data diff --git a/src/NfOrd/Hensel.jl b/src/NfOrd/Hensel.jl index 8dadd0dd7a..9cbe41d64d 100644 --- a/src/NfOrd/Hensel.jl +++ b/src/NfOrd/Hensel.jl @@ -643,7 +643,7 @@ function _hensel(f::Generic.Poly{nf_elem}, #double lift: #IRT = invmod(fp'(rt), p^k) # using x -> x(2-xy) to compute the inverse of y - IRT[j] = lift(ZX, Qt(IRT[j])*(Qt(2-IRT[j]*eval_fs) % pgg) %pgg) + IRT[j] = lift(ZX, Qt(IRT[j])*(Qt(2-Qt(IRT[j])*eval_fs) % pgg) %pgg) #RT = rt mod p^k normal Newton # using x -> x-fp(x)//fp'(x) = x-fp(x) * IRT RT[j] = lift(ZX, Qt(pow[2] - eval_f*Qt(IRT[j])) % pgg) diff --git a/src/QuadForm/Quad/NormalForm.jl b/src/QuadForm/Quad/NormalForm.jl index 3bbfe9d142..9526845069 100644 --- a/src/QuadForm/Quad/NormalForm.jl +++ b/src/QuadForm/Quad/NormalForm.jl @@ -1066,7 +1066,7 @@ function _normalize_twobytwo(G, p) error("Not a valid 2 x 2 block.") end scale = p^(_val(G[1, 2], p)) - D = matrix(R, 2, 2, [divexact(d, scale) for d in G]) # G is symmetric + D = matrix(R, 2, 2, [divexact(d, R(scale)) for d in G]) # G is symmetric # now D is of the form # [2a b ] # [b 2c] diff --git a/test/Misc/Primes.jl b/test/Misc/Primes.jl index 3a47356663..120d6e41d0 100644 --- a/test/Misc/Primes.jl +++ b/test/Misc/Primes.jl @@ -6,14 +6,10 @@ @test @inferred next_prime(T(3)) == T(5) end - for T in [Int32, Int64, Int128, BigInt, fmpz] - @test_throws ErrorException next_prime(T(-1)) - end - if Int == Int64 - @test_throws ErrorException next_prime(Int(9223372036854775783)) + @test_throws InexactError next_prime(Int(9223372036854775783)) elseif Int == Int32 - @test_throws ErrorException next_prime(Int32(2147483647)) + @test_throws InexactError next_prime(Int32(2147483647)) end for B in 1:100