From b22d98ef843fd42dfc5af4a381ac1bde4798e3f1 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sat, 5 Oct 2024 01:22:24 +0200 Subject: [PATCH 1/4] Remove redundant gcdinv methods The default method in AA delegates to gcdx --- src/flint/fmpz.jl | 9 --------- src/flint/fq_default_poly.jl | 11 ----------- src/flint/fq_nmod_poly.jl | 12 ------------ src/flint/fq_poly.jl | 11 ----------- src/gaussiannumbers/ZZi.jl | 5 ----- 5 files changed, 48 deletions(-) diff --git a/src/flint/fmpz.jl b/src/flint/fmpz.jl index 886a4e621..1cf787ad5 100644 --- a/src/flint/fmpz.jl +++ b/src/flint/fmpz.jl @@ -1425,15 +1425,6 @@ function gcdx(a::ZZRingElem, b::ZZRingElem) return d, x, y end -@doc raw""" - gcdinv(a::ZZRingElem, b::ZZRingElem) - -Return a tuple $g, s$ where $g$ is the greatest common divisor of $a$ and -$b$ and where $s$ is the inverse of $a$ modulo $b$ if $g = 1$. This function -can be used to detect impossible inverses, i.e. where $a$ and $b$ are not -coprime, and to yield the common factor of $a$ and $b$ if they are not -coprime. We require $b \geq a \geq 0$. -""" function gcdinv(a::ZZRingElem, b::ZZRingElem) a < 0 && throw(DomainError(a, "First argument must be non-negative")) b < a && throw(DomainError((a, b), "First argument must be smaller than second argument")) diff --git a/src/flint/fq_default_poly.jl b/src/flint/fq_default_poly.jl index 3ea91c36f..ccdc81554 100644 --- a/src/flint/fq_default_poly.jl +++ b/src/flint/fq_default_poly.jl @@ -509,17 +509,6 @@ function gcd(x::FqPolyRingElem, y::FqPolyRingElem) return z end -function gcdinv(x::FqPolyRingElem, y::FqPolyRingElem) - check_parent(x,y) - z = parent(x)() - s = parent(x)() - t = parent(x)() - ccall((:fq_default_poly_xgcd, libflint), Nothing, - (Ref{FqPolyRingElem}, Ref{FqPolyRingElem}, Ref{FqPolyRingElem}, Ref{FqPolyRingElem}, Ref{FqPolyRingElem}, - Ref{FqField}), z, s, t, x, y, base_ring(parent(x))) - return z, s -end - function gcdx(x::FqPolyRingElem, y::FqPolyRingElem) check_parent(x,y) z = parent(x)() diff --git a/src/flint/fq_nmod_poly.jl b/src/flint/fq_nmod_poly.jl index 195b0745a..d9809dbc7 100644 --- a/src/flint/fq_nmod_poly.jl +++ b/src/flint/fq_nmod_poly.jl @@ -515,18 +515,6 @@ function gcd(x::fqPolyRepPolyRingElem, y::fqPolyRepPolyRingElem) return z end -function gcdinv(x::fqPolyRepPolyRingElem, y::fqPolyRepPolyRingElem) - check_parent(x,y) - z = parent(x)() - s = parent(x)() - t = parent(x)() - ccall((:fq_nmod_poly_xgcd, libflint), Nothing, - (Ref{fqPolyRepPolyRingElem}, Ref{fqPolyRepPolyRingElem}, Ref{fqPolyRepPolyRingElem}, - Ref{fqPolyRepPolyRingElem}, Ref{fqPolyRepPolyRingElem}, - Ref{fqPolyRepField}), z, s, t, x, y, base_ring(parent(x))) - return z, s -end - function gcdx(x::fqPolyRepPolyRingElem, y::fqPolyRepPolyRingElem) check_parent(x,y) z = parent(x)() diff --git a/src/flint/fq_poly.jl b/src/flint/fq_poly.jl index 5217d7e60..713908645 100644 --- a/src/flint/fq_poly.jl +++ b/src/flint/fq_poly.jl @@ -515,17 +515,6 @@ function gcd(x::FqPolyRepPolyRingElem, y::FqPolyRepPolyRingElem) return z end -function gcdinv(x::FqPolyRepPolyRingElem, y::FqPolyRepPolyRingElem) - check_parent(x,y) - z = parent(x)() - s = parent(x)() - t = parent(x)() - ccall((:fq_poly_xgcd, libflint), Nothing, - (Ref{FqPolyRepPolyRingElem}, Ref{FqPolyRepPolyRingElem}, Ref{FqPolyRepPolyRingElem}, Ref{FqPolyRepPolyRingElem}, Ref{FqPolyRepPolyRingElem}, - Ref{FqPolyRepField}), z, s, t, x, y, base_ring(parent(x))) - return z, s -end - function gcdx(x::FqPolyRepPolyRingElem, y::FqPolyRepPolyRingElem) check_parent(x,y) z = parent(x)() diff --git a/src/gaussiannumbers/ZZi.jl b/src/gaussiannumbers/ZZi.jl index 3c43dff16..e3a707efc 100644 --- a/src/gaussiannumbers/ZZi.jl +++ b/src/gaussiannumbers/ZZi.jl @@ -627,11 +627,6 @@ function invmod(a::ZZiRingElem, b::ZZiRingElem) return x end -function gcdinv(a::ZZiRingElem, b::ZZiRingElem) - g, x, y = gcdx(a, b) - return (g, x) -end - function remove(a::ZZiRingElem, b::ZZiRingElem) if (iszero(b) || is_unit(b)) throw(ArgumentError("Second argument must be a non-zero non-unit")) From 51a39fa0216ea8c980effd42cd34feb994564575 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sat, 5 Oct 2024 01:23:23 +0200 Subject: [PATCH 2/4] Add isapprox methods for ZZRingElem & QQFieldElem ... to allow testing relative and absolute series --- src/flint/fmpq.jl | 10 ++++++++++ src/flint/fmpz.jl | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/flint/fmpq.jl b/src/flint/fmpq.jl index b40536f2e..bb5403415 100644 --- a/src/flint/fmpq.jl +++ b/src/flint/fmpq.jl @@ -369,6 +369,16 @@ function isless(a::QQFieldElem, b::QQFieldElem) return cmp(a, b) < 0 end +function Base.isapprox(x::QQFieldElem, y::QQFieldElem; + atol::Real=0, rtol::Real=0, + nans::Bool=false, norm::Function=abs) + if norm === abs && atol < 1 && rtol == 0 + return x == y + else + return norm(x - y) <= max(atol, rtol*max(norm(x), norm(y))) + end +end + ############################################################################### # # Ad hoc comparison diff --git a/src/flint/fmpz.jl b/src/flint/fmpz.jl index 1cf787ad5..d8d8f8bd6 100644 --- a/src/flint/fmpz.jl +++ b/src/flint/fmpz.jl @@ -860,6 +860,16 @@ isless(x::ZZRingElem, y::Integer) = x < ZZRingElem(y) isless(x::Integer, y::ZZRingElem) = ZZRingElem(x) < y +function Base.isapprox(x::ZZRingElem, y::ZZRingElem; + atol::Real=0, rtol::Real=0, + nans::Bool=false, norm::Function=abs) + if norm === abs && atol < 1 && rtol == 0 + return x == y + else + return norm(x - y) <= max(atol, rtol*max(norm(x), norm(y))) + end +end + ############################################################################### # # Ad hoc comparison From 4d6bf09371cac108b38c1dd4c53ff7792d56ad6b Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sat, 5 Oct 2024 01:24:06 +0200 Subject: [PATCH 3/4] Enhance fpPolyRingElem constructor to accept more Integer types ... e.g. Bool -- this is needed to pass the conformance tests --- src/flint/FlintTypes.jl | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/flint/FlintTypes.jl b/src/flint/FlintTypes.jl index 65611449d..dfed74ad5 100644 --- a/src/flint/FlintTypes.jl +++ b/src/flint/FlintTypes.jl @@ -754,13 +754,8 @@ mutable struct fpPolyRingElem <: PolyRingElem{fpFieldElem} return z end - function fpPolyRingElem(n::UInt, a::Int) - z = new() - ccall((:nmod_poly_init, libflint), Nothing, (Ref{fpPolyRingElem}, UInt), z, n) - ccall((:nmod_poly_set_coeff_ui, libflint), Nothing, - (Ref{fpPolyRingElem}, Int, UInt), z, 0, mod(a, n)) - finalizer(_gfp_poly_clear_fn, z) - return z + function fpPolyRingElem(n::UInt, a::Integer) + return fpPolyRingElem(n, mod(a, n) % UInt) end function fpPolyRingElem(n::UInt, arr::Vector{ZZRingElem}) From b7eb26a5dd510b501d369a8a435799bf38074940 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sat, 5 Oct 2024 01:37:20 +0200 Subject: [PATCH 4/4] Fix missing return values in two unsafe ops --- src/HeckeMoreStuff.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/HeckeMoreStuff.jl b/src/HeckeMoreStuff.jl index 8d79d1aa4..00d7d2c1c 100644 --- a/src/HeckeMoreStuff.jl +++ b/src/HeckeMoreStuff.jl @@ -351,6 +351,7 @@ function sub!(a::AbsSimpleNumFieldElem, b::AbsSimpleNumFieldElem, c::AbsSimpleNu ccall((:nf_elem_sub, libflint), Nothing, (Ref{AbsSimpleNumFieldElem}, Ref{AbsSimpleNumFieldElem}, Ref{AbsSimpleNumFieldElem}, Ref{AbsSimpleNumField}), a, b, c, a.parent) + return a end function lift(R::ZZAbsPowerSeriesRing, f::ZZModAbsPowerSeriesRingElem) @@ -1053,6 +1054,7 @@ function mod_sym!(f::ZZPolyRingElem, p::ZZRingElem) for i = 0:degree(f) setcoeff!(f, i, mod_sym(coeff(f, i), p)) end + return f end function mod_sym(a::AbsSimpleNumFieldElem, b::ZZRingElem, b2::ZZRingElem)