Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions deps/build.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,32 @@ oldwdir = pwd()
@show YASM_VERSION = "1.3.0"
@show MPIR_VERSION = "3.0.0"
@show MPFR_VERSION = "4.0.0"
@show ANTIC_VERSION = "7905f41b7ae661eef30c301f58dca4cd5dcf92cb"
@show ANTIC_VERSION = "96b37f6242526f95f68f1f15c925db5a4a19a21c"
@show FLINT_VERSION = "adf1583c6bd92a454f3f92a18adf9063d14637a0"
@show ARB_VERSION = "232135f35eeebb74afcea5dd7be436142bee9227"
@show ARB_VERSION = "e0c823ab52c7a909acb692597864e748d73cdebe"

pkgdir = dirname(dirname(@__FILE__))
wdir = joinpath(pkgdir, "deps")
vdir = joinpath(pkgdir, "local")

if "NEMO_MAKE_CLEAN" in keys(ENV) && ENV["NEMO_MAKE_CLEAN"] == "1"
print("
===============================================================================
=
= NEMO_MAKE_CLEAN = 1
= Removing old sources and builds
=
================================================================================\n")

rm(joinpath(wdir, "flint2"), force = true, recursive = true)
rm(joinpath(wdir, "arb"), force = true, recursive = true)
rm(joinpath(wdir, "antic"), force = true, recursive = true)
rm(joinpath(wdir, "mpfr-4.0.0"), force = true, recursive = true)
rm(joinpath(wdir, "mpir-3.0.0"), force = true, recursive = true)
rm(joinpath(wdir, "yasm-1.3.0"), force = true, recursive = true)
rm(vdir, force = true, recursive = true)
end

if is_apple() && !("CC" in keys(ENV))
ENV["CC"] = "clang"
ENV["CXX"] = "clang++"
Expand Down
6 changes: 3 additions & 3 deletions src/Nemo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Base: Array, abs, acos, acosh, asin, asinh, atan, atan2, atanh, base,
cospi, cot, coth, dec, deepcopy, deepcopy_internal, deserialize,
det, div, divrem, expm1, exp, eye, floor, gamma, gcd, gcdx, getindex,
hash, hcat, hex, hypot, intersect, inv, invmod, isequal,
isfinite, isless, isqrt, isreal, iszero, lcm, ldexp, length,
isfinite, isinteger, isless, isqrt, isreal, iszero, lcm, ldexp, length,
lgamma, log, log1p, lufact, lufact!, mod, ndigits, nextpow2, norm,
nullspace, numerator, oct, one, parent, parse, precision,
prevpow2, rand, rank, Rational, rem, reverse, serialize,
Expand Down Expand Up @@ -228,7 +228,7 @@ function __init__()
(Ptr{Void},), cfunction(flint_abort, Void, ()))

println("")
println("Welcome to Nemo version 0.8.3")
println("Welcome to Nemo version 0.8.4")
println("")
println("Nemo comes with absolutely no warranty whatsoever")
println("")
Expand All @@ -249,7 +249,7 @@ end
################################################################################

function versioninfo()
print("Nemo version 0.8.3\n")
print("Nemo version 0.8.4\n")
nemorepo = dirname(dirname(@__FILE__))

print("Nemo: ")
Expand Down
76 changes: 67 additions & 9 deletions src/antic/nf_elem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

export AnticNumberField, nf_elem, norm, representation_matrix,
representation_matrix_q, trace, CyclotomicField, MaximalRealSubfield,
add!, sub!, mul!, signature, sqr_classical
add!, sub!, mul!, signature, sqr_classical, isrational, isinteger

###############################################################################
#
Expand Down Expand Up @@ -173,7 +173,29 @@ doc"""
> Return `true` if the given number field element is invertible, i.e. nonzero,
> otherwise return `false`.
"""
isunit(a::nf_elem) = a != 0
isunit(a::nf_elem) = !iszero(a)

doc"""
isinteger(a::nf_elem)
> Return `true` if the given number field element is an integer, otherwise
> return `false`.
"""
function isinteger(a::nf_elem)
b = ccall((:nf_elem_is_integer, :libantic), Cint,
(Ref{nf_elem}, Ref{AnticNumberField}), a, a.parent)
return Bool(b)
end

doc"""
isrational(a::nf_elem)
> Return `true` if the given number field element is a rational number,
> otherwise `false`.
"""
function isrational(a::nf_elem)
b = ccall((:nf_elem_is_rational, :libantic), Cint,
(Ref{nf_elem}, Ref{AnticNumberField}), a, a.parent)
return Bool(b)
end

doc"""
denominator(a::nf_elem)
Expand Down Expand Up @@ -426,7 +448,9 @@ function *(a::Rational, b::nf_elem)
return fmpq(a) * b
end

*(a::nf_elem, b::Rational) = b*a
*(a::nf_elem, b::Rational) = b * a

*(a::nf_elem, b::Integer) = a * fmpz(b)

*(a::Integer, b::nf_elem) = b * a

Expand Down Expand Up @@ -487,17 +511,49 @@ end
#
###############################################################################

==(a::nf_elem, b::Integer) = a == parent(a)(b)
function ==(a::nf_elem, b::fmpz)
b = ccall((:nf_elem_equal_fmpz, :libantic), Cint,
(Ref{nf_elem}, Ref{fmpz}, Ref{AnticNumberField}),
a, b, a.parent)
return Bool(b)
end

function ==(a::nf_elem, b::fmpq)
b = ccall((:nf_elem_equal_fmpq, :libantic), Cint,
(Ref{nf_elem}, Ref{fmpq}, Ref{AnticNumberField}),
a, b, a.parent)
return Bool(b)
end

function ==(a::nf_elem, b::Int)
b = ccall((:nf_elem_equal_si, :libantic), Cint,
(Ref{nf_elem}, Int, Ref{AnticNumberField}),
a, b, a.parent)
return Bool(b)
end

function ==(a::nf_elem, b::UInt)
b = ccall((:nf_elem_equal_ui, :libantic), Cint,
(Ref{nf_elem}, UInt, Ref{AnticNumberField}),
a, b, a.parent)
return Bool(b)
end

==(a::nf_elem, b::Integer) = a == fmpz(b)

==(a::nf_elem, b::Rational) = a == fmpq(b)

==(a::nf_elem, b::fmpz) = a == parent(a)(b)
==(a::fmpz, b::nf_elem) = b == a

==(a::nf_elem, b::fmpq) = a == parent(a)(b)
==(a::fmpq, b::nf_elem) = b == a

==(a::Integer, b::nf_elem) = parent(b)(a) == b
==(a::Int, b::nf_elem) = b == a

==(a::fmpz, b::nf_elem) = parent(b)(a) == b
==(a::UInt, b::nf_elem) = b == a

==(a::fmpq, b::nf_elem) = parent(b)(a) == b
==(a::Integer, b::nf_elem) = b == a

==(a::Rational, b::nf_elem) = b == a

###############################################################################
#
Expand Down Expand Up @@ -993,6 +1049,8 @@ function (a::AnticNumberField)(c::fmpq)
return z
end

(a::AnticNumberField)(c::Rational) = a(fmpq(c))

function (a::AnticNumberField)(b::nf_elem)
parent(b) != a && error("Cannot coerce number field element")
return b
Expand Down
14 changes: 13 additions & 1 deletion src/arb/arb.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export ball, radius, midpoint, contains, contains_zero,
isnonzero, isexact, isint, ispositive, isfinite,
isnonnegative, isnegative, isnonpositive, add!, mul!,
sub!, div!, strongequal, prec, overlaps, unique_integer,
accuracy_bits, trim, ldexp, setunion,
accuracy_bits, trim, ldexp, setunion, setintersection,
const_pi, const_e, const_log2, const_log10, const_euler,
const_catalan, const_khinchin, const_glaisher,
floor, ceil, hypot, rsqrt, sqrt1pm1, root,
Expand Down Expand Up @@ -907,6 +907,18 @@ function setunion(x::arb, y::arb)
return z
end

doc"""
setintersection(x::arb, y::arb)
> Return an `arb` containing the intersection of the intervals represented by
> $x$ and $y$.
"""
function setintersection(x::arb, y::arb)
z = parent(x)()
ccall((:arb_intersection, :libarb), Void,
(Ref{arb}, Ref{arb}, Ref{arb}, Int), z, x, y, parent(x).prec)
return z
end

################################################################################
#
# Constants
Expand Down
2 changes: 1 addition & 1 deletion src/flint/fmpq_mpoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function isgen(a::fmpq_mpoly)
return false
end

function deepcopy(a::fmpq_mpoly)
function deepcopy_internal(a::fmpq_mpoly, dict::ObjectIdDict)
z = parent(a)()
ccall((:fmpq_mpoly_set, :libflint), Void,
(Ref{fmpq_mpoly}, Ref{fmpq_mpoly}, Ref{FmpqMPolyRing}),
Expand Down
10 changes: 6 additions & 4 deletions src/flint/nmod.jl
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ function divexact(x::nmod, y::nmod)
check_parent(x, y)
fl, q = divides(x, y)
if !fl
error("Impossible inverse in ", R)
error("Impossible inverse in ", parent(x))
end
return q
end
Expand All @@ -294,9 +294,11 @@ function divides(a::nmod, b::nmod)
if r != 0
return false, b
end
ub = div(B, gb)
_, x = ppio(m, ub)
r = R(q)*inv(R(ub))
ub = divexact(B, gb)
# The Julia invmod function does not give the correct result for me
b1 = ccall((:n_invmod, :libflint), UInt, (UInt, UInt),
ub, divexact(m, gb))
r = R(q)*b1
return true, r
end

Expand Down
23 changes: 20 additions & 3 deletions test/antic/nf_elem-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ function test_nf_elem_constructors()

@test isa(f, nf_elem)

h = K(1//2)

@test isa(h, nf_elem)

g = K(x^2 + 2x - 7)

@test isa(g, nf_elem)
Expand Down Expand Up @@ -153,6 +157,13 @@ function test_nf_elem_manipulation()

@test signature(K) == (1, 1)

@test !isinteger(d)
@test !isrational(d)
@test isinteger(K(2))
@test isrational(K(2))
@test !isinteger(K(1//2))
@test isrational(K(1//2))

println("PASS")
end

Expand Down Expand Up @@ -245,10 +256,16 @@ function test_nf_elem_adhoc_comparison()
K, a = NumberField(x^3 + 3x + 1, "a")

c = 3a^2 - a + 1
b = K(5)

for T in [Int, UInt, BigInt, fmpz, fmpq,
Rational{Int}, Rational{BigInt}]
@test c != T(5)
@test T(5) != c
@test b == T(5)
@test T(5) == b
end

@test c != 5
@test K(5) == 5
@test K(5) == fmpz(5)
@test K(fmpq(2, 3)) == fmpq(2, 3)
@test 5 == K(5)
@test fmpz(5) == K(5)
Expand Down
12 changes: 10 additions & 2 deletions test/flint/nmod-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,12 @@ function test_nmod_exact_division()
for iter = 1:100
a1 = rand(R)
a2 = rand(R)
a2 += Int(a2 == 0) # still works mod 1
p = a1*a2

@test !isunit(a2) || divexact(a1, a2)*a2 == a1
q = divexact(p, a2)

@test q*a2 == p
end
end

Expand All @@ -392,8 +396,12 @@ function test_nmod_exact_division()
for iter = 1:100
a1 = rand(R)
a2 = rand(R)
a2 += Int(a2 == 0) # still works mod 1
p = a1*a2

q = divexact(p, a2)

@test !isunit(a2) || divexact(a1, a2)*a2 == a1
@test q*a2 == p
end
end

Expand Down