From 0fc9f8e21c6a602bbb603e2ae3a8751bb3577349 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Wed, 9 Oct 2024 01:55:40 +0200 Subject: [PATCH] Some fixes and a minor tweak - Better conversion to CalciumField / zzModPolyRing - Fix neg! for FpFieldElem - Fix neg! for ZZModRingElem - Fix one! for ZZModRingElem --- src/calcium/ca.jl | 4 ++++ src/flint/FlintTypes.jl | 9 ++------- src/flint/fmpz_mod.jl | 16 +++++++++++----- src/flint/gfp_fmpz_elem.jl | 7 ++++++- 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/calcium/ca.jl b/src/calcium/ca.jl index bc0d9d52f..9b6b4af33 100644 --- a/src/calcium/ca.jl +++ b/src/calcium/ca.jl @@ -1470,6 +1470,10 @@ function (C::CalciumField)(v::QQBarFieldElem) return z end +function (C::CalciumField)(v::RationalUnion) + return C(flintify(v)) +end + # todo: optimize function (C::CalciumField)(v::Complex{Int}) return C(QQBarFieldElem(v)) diff --git a/src/flint/FlintTypes.jl b/src/flint/FlintTypes.jl index 92c7e8faa..25b28318e 100644 --- a/src/flint/FlintTypes.jl +++ b/src/flint/FlintTypes.jl @@ -615,13 +615,8 @@ mutable struct zzModPolyRingElem <: PolyRingElem{zzModRingElem} return z end - function zzModPolyRingElem(n::UInt, a::Int) - z = new() - ccall((:nmod_poly_init, libflint), Nothing, (Ref{zzModPolyRingElem}, UInt), z, n) - ccall((:nmod_poly_set_coeff_ui, libflint), Nothing, - (Ref{zzModPolyRingElem}, Int, UInt), z, 0, mod(a, n)) - finalizer(_nmod_poly_clear_fn, z) - return z + function zzModPolyRingElem(n::UInt, a::Integer) + return zzModPolyRingElem(n, mod(a, n) % UInt) end function zzModPolyRingElem(n::UInt, arr::Vector{ZZRingElem}) diff --git a/src/flint/fmpz_mod.jl b/src/flint/fmpz_mod.jl index a0cfde48e..936b36747 100644 --- a/src/flint/fmpz_mod.jl +++ b/src/flint/fmpz_mod.jl @@ -343,15 +343,21 @@ function zero!(z::ZZModRingElem) end function one!(z::ZZModRingElem) - one!(z.data) + R = parent(z) + if R.n == 1 + zero!(z.data) + else + one!(z.data) + end return z end -function neg!(z::ZZModRingElem, a::ZZModRingElem) - if iszero(a.data) - z.data = zero!(z.data) +function neg!(z::ZZModRingElem, x::ZZModRingElem) + R = parent(z) + if is_zero(x.data) + zero!(z.data) else - z.data = sub!(z.data, R.n, a.data) + sub!(z.data, R.n, x.data) end return z end diff --git a/src/flint/gfp_fmpz_elem.jl b/src/flint/gfp_fmpz_elem.jl index ccc77c4da..dd01fffa7 100644 --- a/src/flint/gfp_fmpz_elem.jl +++ b/src/flint/gfp_fmpz_elem.jl @@ -360,7 +360,12 @@ function one!(z::FpFieldElem) end function neg!(z::FpFieldElem, x::FpFieldElem) - z.data = R.n - x.data + R = parent(z) + if is_zero(x.data) + zero!(z.data) + else + sub!(z.data, R.n, x.data) + end return z end