Skip to content

Commit

Permalink
Misc changes (#1878)
Browse files Browse the repository at this point in the history
* Remove redundant gcdinv methods.
  The default method in AA delegates to gcdx
* Enhance fpPolyRingElem constructor to accept more Integer types
  e.g. Bool -- this is needed to pass the conformance tests
* Fix missing return values in two unsafe ops
  • Loading branch information
fingolfin authored Oct 7, 2024
1 parent 414585c commit ef20920
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 55 deletions.
2 changes: 2 additions & 0 deletions src/HeckeMoreStuff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,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)
Expand Down Expand Up @@ -1045,6 +1046,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)
Expand Down
9 changes: 2 additions & 7 deletions src/flint/FlintTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
9 changes: 0 additions & 9 deletions src/flint/fmpz.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
11 changes: 0 additions & 11 deletions src/flint/fq_default_poly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)()
Expand Down
12 changes: 0 additions & 12 deletions src/flint/fq_nmod_poly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)()
Expand Down
11 changes: 0 additions & 11 deletions src/flint/fq_poly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)()
Expand Down
5 changes: 0 additions & 5 deletions src/gaussiannumbers/ZZi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down

0 comments on commit ef20920

Please sign in to comment.