Skip to content

Commit

Permalink
New Nemo/AA version (#339)
Browse files Browse the repository at this point in the history
* Fix promote rules

* Bump version

* Remove next_prime (now in Nemo)
  • Loading branch information
thofma authored Jul 10, 2021
1 parent f7b64f3 commit f2547b3
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 79 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/Misc/FiniteField.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

################################################################################
#
Expand Down
3 changes: 3 additions & 0 deletions src/Misc/Localization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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}

72 changes: 4 additions & 68 deletions src/Misc/Primes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

################################################################################
Expand Down
3 changes: 3 additions & 0 deletions src/Misc/Residue.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/NfOrd/Hensel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/QuadForm/Quad/NormalForm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
8 changes: 2 additions & 6 deletions test/Misc/Primes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f2547b3

Please sign in to comment.