Skip to content

Commit

Permalink
Add two missing helper functions (#1574)
Browse files Browse the repository at this point in the history
- Add lift for fq_default_poly -> ZZPolyRingElem
- Generalize set_coeff! for qadic
  • Loading branch information
thofma authored Nov 2, 2023
1 parent 1fcc3b5 commit 1acb178
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Nemo"
uuid = "2edaba10-b0f1-5616-af89-8c11ac63239a"
version = "0.37.2"
version = "0.37.3"

[deps]
AbstractAlgebra = "c3fe647b-3220-5bb0-a1ea-a7954cac585d"
Expand Down
4 changes: 4 additions & 0 deletions src/HeckeMoreStuff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1272,6 +1272,10 @@ function setcoeff!(x::qadic, i::Int, y::padic)
end

function setcoeff!(x::qadic, i::Int, y::UInt)
return setcoeff!(x, i, ZZRingElem(y))
end

function setcoeff!(x::qadic, i::Int, y::ZZRingElem)
R = FlintPadicField(prime(parent(x)), parent(x).prec_max)
Y = R(ZZRingElem(y))
ccall((:padic_poly_set_coeff_padic, libflint), Nothing,
Expand Down
24 changes: 24 additions & 0 deletions src/flint/fq_default_poly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -892,3 +892,27 @@ function (R::FqPolyRing)(x::FqPolyRingElem)
parent(x) != R && error("Unable to coerce to polynomial")
return x
end

################################################################################
#
# Lift
#
################################################################################

function lift(R::ZZPolyRing, f::FqPolyRingElem)
F = coefficient_ring(f)
absolute_degree(F) != 1 && error("Must be a prime field.")
if _fq_default_ctx_type(F) == _FQ_DEFAULT_NMOD
z = R()
ccall((:fmpz_poly_set_nmod_poly_unsigned, libflint), Nothing,
(Ref{ZZPolyRingElem}, Ref{FqPolyRingElem}), z, f)
return z
else
@assert _fq_default_ctx_type(F) == _FQ_DEFAULT_FMPZ_NMOD
z = R()
ccall((:fmpz_mod_poly_get_fmpz_poly, libflint), Nothing,
(Ref{ZZPolyRingElem}, Ref{FqPolyRingElem}, Ptr{Nothing}),
z, f, pointer_from_objref(F) + 2 * sizeof(Cint))
return z
end
end
25 changes: 25 additions & 0 deletions test/flint/fq_default_poly-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -563,3 +563,28 @@ end

@test !v
end

@testset "FqPolyRingElem.lift" begin
R, x = NGFiniteField(23, 1, "x")
S, y = R["y"]
ZZy, z = ZZ["z"]
f = lift(ZZy, y^2 + 1)
@test parent(f) === ZZy
@test map_coefficients(R, f, parent = S) == y^2 + 1

R, x = NGFiniteField(next_prime(ZZ(2)^100), 1, "x")
S, y = R["y"]
ZZy, z = ZZ["z"]
f = lift(ZZy, y^2 + 1)
@test parent(f) === ZZy
@test map_coefficients(R, f, parent = S) == y^2 + 1

R, x = NGFiniteField(23, 2, "x")
S, y = R["y"]
ZZy, z = ZZ["z"]
@test_throws ErrorException lift(ZZy, y^2 + 1)
R, x = NGFiniteField(next_prime(ZZ(2)^100), 2, "x")
S, y = R["y"]
ZZy, z = ZZ["z"]
@test_throws ErrorException lift(ZZy, y^2 + 1)
end
8 changes: 8 additions & 0 deletions test/flint/qadic-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -306,3 +306,11 @@ end

@test 6 * log(R(2)) == log(R(2)^6)
end

@testset "qadic.setcoeff!" begin
R, _ = QadicField(7, 1, 30)
a = 1 + 7 + 2*7^2 + O(R, 7^3)
setcoeff!(a, 0, ZZ(2))
@test a == 2
end

2 comments on commit 1acb178

@thofma
Copy link
Member Author

@thofma thofma commented on 1acb178 Nov 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/94678

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.37.3 -m "<description of version>" 1acb1784acbda27915a96991531c55f6315a6327
git push origin v0.37.3

Please sign in to comment.