diff --git a/deps/build.jl b/deps/build.jl index 46ff6ac26..cbdf90e36 100644 --- a/deps/build.jl +++ b/deps/build.jl @@ -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++" diff --git a/src/Nemo.jl b/src/Nemo.jl index e73f77286..6a2a5ff1d 100644 --- a/src/Nemo.jl +++ b/src/Nemo.jl @@ -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, @@ -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("") @@ -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: ") diff --git a/src/antic/nf_elem.jl b/src/antic/nf_elem.jl index 1f839dd23..a7c78691b 100644 --- a/src/antic/nf_elem.jl +++ b/src/antic/nf_elem.jl @@ -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 ############################################################################### # @@ -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) @@ -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 @@ -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 ############################################################################### # @@ -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 diff --git a/src/arb/arb.jl b/src/arb/arb.jl index 906bcf0e3..a419229fe 100644 --- a/src/arb/arb.jl +++ b/src/arb/arb.jl @@ -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, @@ -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 diff --git a/src/flint/fmpq_mpoly.jl b/src/flint/fmpq_mpoly.jl index dd9add1b5..7ac1b338c 100644 --- a/src/flint/fmpq_mpoly.jl +++ b/src/flint/fmpq_mpoly.jl @@ -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}), diff --git a/src/flint/nmod.jl b/src/flint/nmod.jl index 73bd142ce..490effbed 100644 --- a/src/flint/nmod.jl +++ b/src/flint/nmod.jl @@ -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 @@ -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 diff --git a/test/antic/nf_elem-test.jl b/test/antic/nf_elem-test.jl index 3cd571390..376601246 100644 --- a/test/antic/nf_elem-test.jl +++ b/test/antic/nf_elem-test.jl @@ -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) @@ -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 @@ -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) diff --git a/test/flint/nmod-test.jl b/test/flint/nmod-test.jl index e312e00d1..4e8f7e06a 100644 --- a/test/flint/nmod-test.jl +++ b/test/flint/nmod-test.jl @@ -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 @@ -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