Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jaa/is nilpotent #1974

Merged
merged 37 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
77e4926
Improved is_nilpotent(::ResElem)
JohnAAbbott Dec 13, 2024
07d5861
Merge branch 'Nemocas:master' into JAA/is_nilpotent
JohnAAbbott Dec 13, 2024
f1abed2
New tests for is_nilpotent
JohnAAbbott Dec 13, 2024
0b80802
Merge branch 'JAA/is_nilpotent' of github.com:JohnAAbbott/Nemo.jl int…
JohnAAbbott Dec 13, 2024
7173aa9
Removed spaces which triggered syntax error
JohnAAbbott Dec 13, 2024
7b2fea9
Fixed typo (from careless copy-paste)
JohnAAbbott Dec 13, 2024
db38bc5
Inserted missing defn of is_domain_type
JohnAAbbott Dec 13, 2024
7928bd5
Inserted missing defn of is_domain_type
JohnAAbbott Dec 13, 2024
dd78f50
Inserted missing defn of is_domain_type
JohnAAbbott Dec 13, 2024
6c5912f
Inserted missing defn of is_domain_type
JohnAAbbott Dec 13, 2024
9cb13a3
Add defns of is_nilpotent for ZZRingElem & QQFieldElem
JohnAAbbott Dec 13, 2024
1061b42
Bugfix: use data instead of lift, use mod! to avoid overflow
JohnAAbbott Dec 16, 2024
d5739b3
Minor impl change to is_nilpotent
JohnAAbbott Dec 16, 2024
80afb22
Removed unnecessary is_domain_type defn
JohnAAbbott Dec 16, 2024
e714f6c
Removed unnecessary is_domain_type defn
JohnAAbbott Dec 16, 2024
4254da6
Removed unnecessary is_domain_type defn
JohnAAbbott Dec 16, 2024
013b53c
Removed unnecessary is_domain_type defn
JohnAAbbott Dec 16, 2024
9d2354e
Added overflow test
JohnAAbbott Dec 16, 2024
a755c62
Fixed typo
JohnAAbbott Dec 16, 2024
96616b1
Commented out buggy old impl of is_unit
JohnAAbbott Dec 17, 2024
0773b26
Merge branch 'Nemocas:master' into JAA/is_nilpotent
JohnAAbbott Dec 18, 2024
80e1c02
is_unit subsumed by impl in AbstractAlgebra/src/generic/Residue.jl
JohnAAbbott Dec 20, 2024
61e9fc1
is_nilpotent subsumed by impl in AbstractAlgebra/src/Residue.jl
JohnAAbbott Dec 20, 2024
2de0918
Minor: inserted underscore dummy arg
JohnAAbbott Dec 20, 2024
3829e3a
Merge branch 'master' into JAA/is_nilpotent
fingolfin Dec 21, 2024
e3004f4
Require AA 0.44.2
fingolfin Dec 21, 2024
c09c7df
Apply suggestions from code review
fingolfin Dec 22, 2024
fe4c891
Remove more redundant methods
fingolfin Dec 22, 2024
08f690d
Remove more redundant stuff
fingolfin Dec 22, 2024
baa6317
Remove more redundant methods
fingolfin Dec 22, 2024
31125c8
Removed blank line
JohnAAbbott Jan 8, 2025
77dbc49
Removed blank line
JohnAAbbott Jan 8, 2025
b319a28
Moved test on residue_ring(ZZ,720) to nmod; replaced length(filter(..…
JohnAAbbott Jan 8, 2025
959bc11
Moved test from fmpz_mod-test to here: is_nilpotent in ZZmod720
JohnAAbbott Jan 8, 2025
cebd9c6
Inserted a space
JohnAAbbott Jan 8, 2025
522970d
Merge branch 'Nemocas:master' into JAA/is_nilpotent
JohnAAbbott Jan 8, 2025
956abae
Merge branch 'JAA/is_nilpotent' of github.com:JohnAAbbott/Nemo.jl int…
JohnAAbbott Jan 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce"
TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76"

[compat]
AbstractAlgebra = "0.44.1"
AbstractAlgebra = "0.44.2"
FLINT_jll = "^300.100.100"
Libdl = "1.6"
LinearAlgebra = "1.6"
Expand Down
1 change: 0 additions & 1 deletion src/Exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,6 @@ export is_less_real
export is_less_root_order
export is_lower_triangular
export is_negative
export is_nilpotent
export is_nonnegative
export is_nonpositive
export is_nonzero
Expand Down
32 changes: 0 additions & 32 deletions src/HeckeMoreStuff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -346,38 +346,6 @@ function gcdx(a::ResElem{T}, b::ResElem{T}) where {T<:IntegerUnion}
return R(G), R(U) * R(u), R(U) * R(v)
end

@doc raw"""
is_unit(f::Union{ZZModPolyRingElem,zzModPolyRingElem}) -> Bool

Tests if $f$ is a unit in the polynomial ring, i.e. if
$f = u + n$ where $u$ is a unit in the coeff. ring
and $n$ is nilpotent.
"""
function is_unit(f::T) where {T<:Union{ZZModPolyRingElem,zzModPolyRingElem}}
if !is_unit(constant_coefficient(f))
return false
end
for i = 1:degree(f)
if !is_nilpotent(coeff(f, i))
return false
end
end
return true
end

@doc raw"""
is_nilpotent(a::ResElem{ZZRingElem}) -> Bool
is_nilpotent(a::ResElem{Integer}) -> Bool

Tests if $a$ is nilpotent.
"""
function is_nilpotent(a::ResElem{T}) where {T<:IntegerUnion}
#a is nilpontent if it is divisible by all primes divising the modulus
# the largest exponent a prime can divide is nbits(m)
l = nbits(modulus(a))
return iszero(a^l)
end

function inv(f::T) where {T<:Union{ZZModPolyRingElem,zzModPolyRingElem}}
if !is_unit(f)
error("impossible inverse")
Expand Down
8 changes: 0 additions & 8 deletions src/antic/nf_elem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,6 @@ function iszero(a::AbsSimpleNumFieldElem)
return @ccall libflint.nf_elem_is_zero(a::Ref{AbsSimpleNumFieldElem}, a.parent::Ref{AbsSimpleNumField})::Bool
end

@doc raw"""
is_unit(a::AbsSimpleNumFieldElem)

Return `true` if the given number field element is invertible, i.e. nonzero,
otherwise return `false`. Note, this does not take the maximal order into account.
"""
is_unit(a::AbsSimpleNumFieldElem) = !iszero(a)

@doc raw"""
isinteger(a::AbsSimpleNumFieldElem)

Expand Down
4 changes: 0 additions & 4 deletions src/arb/Complex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -447,10 +447,6 @@ end
#
################################################################################

function is_unit(x::ComplexFieldElem)
!iszero(x)
end

@doc raw"""
iszero(x::ComplexFieldElem)

Expand Down
4 changes: 0 additions & 4 deletions src/arb/acb.jl
Original file line number Diff line number Diff line change
Expand Up @@ -458,10 +458,6 @@ end
#
################################################################################

function is_unit(x::AcbFieldElem)
!iszero(x)
end

@doc raw"""
iszero(x::AcbFieldElem)

Expand Down
4 changes: 0 additions & 4 deletions src/arb/arb.jl
Original file line number Diff line number Diff line change
Expand Up @@ -450,10 +450,6 @@ end
#
################################################################################

function is_unit(x::ArbFieldElem)
!iszero(x)
end

@doc raw"""
iszero(x::ArbFieldElem)

Expand Down
2 changes: 0 additions & 2 deletions src/flint/fmpq.jl
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ is_one(a::QQFieldElemOrPtr) = isinteger(a) && is_one(_num_ptr(a))

is_zero(a::QQFieldElemOrPtr) = is_zero(_num_ptr(a))

is_unit(a::QQFieldElem) = !iszero(a)

isinteger(a::QQFieldElemOrPtr) = is_one(_den_ptr(a))

isfinite(::QQFieldElem) = true
Expand Down
4 changes: 0 additions & 4 deletions src/flint/fmpq_mpoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,6 @@ function is_term(a::QQMPolyRingElem)
return length(a) == 1
end

function is_unit(a::QQMPolyRingElem)
return length(a) == 1 && total_degree(a) == 0 && is_unit(coeff(a, 1))
end

function is_constant(a::QQMPolyRingElem)
b = @ccall libflint.fmpq_mpoly_is_fmpq(a::Ref{QQMPolyRingElem}, parent(a)::Ref{QQMPolyRing})::Cint
return Bool(b)
Expand Down
4 changes: 0 additions & 4 deletions src/flint/fmpz_mod_mpoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,6 @@ for (etype, rtype, ftype, ctype) in (
return length(a) == 1
end

function is_unit(a::($etype))
return length(a) == 1 && total_degree(a) == 0 && is_unit(coeff(a, 1))
end

function is_constant(a::($etype))
return Bool(@ccall libflint.fmpz_mod_mpoly_is_fmpz(a::Ref{($etype)}, parent(a)::Ref{($rtype)})::Cint)
end
Expand Down
4 changes: 0 additions & 4 deletions src/flint/fmpz_mpoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,6 @@ function is_term(a::ZZMPolyRingElem)
return length(a) == 1
end

function is_unit(a::ZZMPolyRingElem)
return length(a) == 1 && total_degree(a) == 0 && is_unit(coeff(a, 1))
end

function is_constant(a::ZZMPolyRingElem)
b = @ccall libflint.fmpz_mpoly_is_fmpz(a::Ref{ZZMPolyRingElem}, parent(a)::Ref{ZZMPolyRing})::Cint
return Bool(b)
Expand Down
2 changes: 0 additions & 2 deletions src/flint/fq.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ finite field, otherwise return `false`.
"""
is_gen(a::FqPolyRepFieldElem) = a == gen(parent(a))

is_unit(a::FqPolyRepFieldElem) = !is_zero(a)

function characteristic(a::FqPolyRepField)
d = ZZRingElem()
@ccall libflint.__fq_ctx_prime(d::Ref{ZZRingElem}, a::Ref{FqPolyRepField})::Nothing
Expand Down
2 changes: 0 additions & 2 deletions src/flint/fq_default.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ isone(a::FqFieldElem) = @ccall libflint.fq_default_is_one(a::Ref{FqFieldElem}, a

_is_gen(a::FqFieldElem) = a == _gen(parent(a))

is_unit(a::FqFieldElem) = !iszero(a)

function characteristic(a::FqField)
d = ZZRingElem()
@ccall libflint.fq_default_ctx_prime(d::Ref{ZZRingElem}, a::Ref{FqField})::Nothing
Expand Down
2 changes: 0 additions & 2 deletions src/flint/fq_nmod.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ isone(a::fqPolyRepFieldElem) = @ccall libflint.fq_nmod_is_one(a::Ref{fqPolyRepFi

is_gen(a::fqPolyRepFieldElem) = a == gen(parent(a)) # there is no is_gen in flint

is_unit(a::fqPolyRepFieldElem) = @ccall libflint.fq_nmod_is_invertible(a::Ref{fqPolyRepFieldElem}, a.parent::Ref{fqPolyRepField})::Bool

function characteristic(a::fqPolyRepField)
return ZZ(a.n)
end
Expand Down
4 changes: 0 additions & 4 deletions src/flint/fq_nmod_mpoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,6 @@ function is_term(a::fqPolyRepMPolyRingElem)
return length(a) == 1
end

function is_unit(a::fqPolyRepMPolyRingElem)
return is_constant(a)
end

function is_constant(a::fqPolyRepMPolyRingElem)
b = @ccall libflint.fq_nmod_mpoly_is_fq_nmod(a::Ref{fqPolyRepMPolyRingElem}, parent(a)::Ref{fqPolyRepMPolyRing})::Cint
return Bool(b)
Expand Down
2 changes: 0 additions & 2 deletions src/flint/gfp_elem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ iszero(a::fpFieldElem) = a.data == 0

isone(a::fpFieldElem) = a.data == 1

is_unit(a::fpFieldElem) = a.data != 0

modulus(R::fpField) = R.n

function deepcopy_internal(a::fpFieldElem, dict::IdDict)
Expand Down
2 changes: 0 additions & 2 deletions src/flint/gfp_fmpz_elem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ function one(R::FpField)
end
end

is_unit(a::FpFieldElem) = a.data != 0

modulus(R::FpField) = R.n

characteristic(F::FpField) = modulus(F)
Expand Down
4 changes: 1 addition & 3 deletions src/flint/nmod.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ end

iszero(a::zzModRingElem) = a.data == 0

isone(a::zzModRingElem) = a.parent.n == 1 ? a.data == 0 : a.data == 1

is_unit(a::zzModRingElem) = a.parent.n == 1 ? a.data == 0 : gcd(a.data, a.parent.n) == 1
isone(a::zzModRingElem) = (a.parent.n == 1) || (a.data == 1)

modulus(R::zzModRing) = R.n

Expand Down
4 changes: 0 additions & 4 deletions src/flint/nmod_mpoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,6 @@ for (etype, rtype, ftype, ctype, utype) in (
return length(a) == 1
end

function is_unit(a::($etype))
return length(a) == 1 && total_degree(a) == 0 && is_unit(coeff(a, 1))
end

function is_constant(a::($etype))
return Bool(@ccall libflint.nmod_mpoly_is_ui(a::Ref{($etype)}, parent(a)::Ref{($rtype)})::Cint)
end
Expand Down
2 changes: 0 additions & 2 deletions src/flint/padic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,6 @@ iszero(a::PadicFieldElem) = Bool(@ccall libflint.padic_is_zero(a::Ref{PadicField

isone(a::PadicFieldElem) = Bool(@ccall libflint.padic_is_one(a::Ref{PadicFieldElem})::Cint)

is_unit(a::PadicFieldElem) = !iszero(a)

characteristic(R::PadicField) = 0

###############################################################################
Expand Down
2 changes: 0 additions & 2 deletions src/flint/qadic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,6 @@ iszero(a::QadicFieldElem) = Bool(@ccall libflint.qadic_is_zero(a::Ref{QadicField

isone(a::QadicFieldElem) = Bool(@ccall libflint.qadic_is_one(a::Ref{QadicFieldElem})::Cint)

is_unit(a::QadicFieldElem) = !iszero(a)

characteristic(R::QadicField) = 0

function shift_right(a::QadicFieldElem, n::Int)
Expand Down
4 changes: 0 additions & 4 deletions src/gaussiannumbers/QQi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -384,10 +384,6 @@ end
#
###############################################################################

function is_unit(a::QQiFieldElem)
return !iszero(a)
end

function inv!(z::QQiFieldElem, a::QQiFieldElem)
d = abs2(a.num)
mul!(z.num.x, a.num.x, a.den)
Expand Down
7 changes: 7 additions & 0 deletions test/flint/fmpz_mod-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ end

@test !is_unit(R())
@test is_unit(R(3))
@test is_nilpotent(R())
@test !is_nilpotent(R(3))

@test deepcopy(R(3)) == R(3)

Expand All @@ -103,6 +105,7 @@ end
@test modulus(S) == UInt(1)

@test is_unit(S())
@test is_nilpotent(S())

@test characteristic(R) == 13

Expand All @@ -128,6 +131,10 @@ end
@test_throws Exception R6(R22(1))
@test_throws Exception R2(R3(1))
@test_throws Exception R3(R2(1))

ZZmodZZ720,_ = residue_ring(ZZ,ZZ(720))
@test is_nilpotent(ZZmodZZ720(30))
@test count(is_nilpotent, ZZmodZZ720) == 24 # 720/(2*3*5)
end

@testset "ZZModRingElem.unary_ops" begin
Expand Down
10 changes: 10 additions & 0 deletions test/flint/nmod-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ end
@test_throws Exception R6(R2(1))
@test_throws Exception R2(R3(1))
@test_throws Exception R3(R2(1))

ZZmod720,_ = residue_ring(ZZ, 720)
@test is_nilpotent(ZZmod720(30))
@test count(is_nilpotent, ZZmod720) == 24 # 720/(2*3*5)

# 64-bit overflow test: **ASSUMES** Int is 64 bits
rr = 4*3^20
mm = 3*rr
R_overflow,_ = residue_ring(ZZ, mm)
@test is_nilpotent(R_overflow(rr))
end

@testset "zzModRingElem.unary_ops" begin
Expand Down
Loading