From 77e4926f2051837f726f3eb3d185e26ba7755990 Mon Sep 17 00:00:00 2001 From: John Abbott Date: Fri, 13 Dec 2024 11:32:05 +0100 Subject: [PATCH 01/31] Improved is_nilpotent(::ResElem) --- src/HeckeMoreStuff.jl | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/HeckeMoreStuff.jl b/src/HeckeMoreStuff.jl index 58c42d1774..a2b6d18ef9 100644 --- a/src/HeckeMoreStuff.jl +++ b/src/HeckeMoreStuff.jl @@ -391,11 +391,19 @@ end 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) +function is_nilpotent(res::ResElem{T}) where {T<:IntegerUnion} + # Code below is faster than + # m=modulus(res); + # return powermod(lift(res),nbits(m),m)==0 + m = modulus(res) + r = lift(res) + while true + g = gcd(r, m) + (g == m) && return true + (g == 1) && return false + m /= g + r = g^2 + end end function inv(f::T) where {T<:Union{ZZModPolyRingElem,zzModPolyRingElem}} From f1abed26062714280d0663eb51c9c377fb0b21c1 Mon Sep 17 00:00:00 2001 From: John Abbott Date: Fri, 13 Dec 2024 11:58:47 +0100 Subject: [PATCH 02/31] New tests for is_nilpotent --- test/flint/fmpz_mod-test.jl | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/flint/fmpz_mod-test.jl b/test/flint/fmpz_mod-test.jl index ff4bea8359..809ad8d2f6 100644 --- a/test/flint/fmpz_mod-test.jl +++ b/test/flint/fmpz_mod-test.jl @@ -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) @@ -103,6 +105,7 @@ end @test modulus(S) == UInt(1) @test is_unit(S()) + @test is_nilpotent(S()) @test characteristic(R) == 13 @@ -128,6 +131,16 @@ end @test_throws Exception R6(R22(1)) @test_throws Exception R2(R3(1)) @test_throws Exception R3(R2(1)) + + ZZmod720,_ = residue_ring (ZZ,720) + ZZmodZZ720,_ = residue_ring (ZZ,ZZ(720)) + @test is_nilpotent(ZZmod720(30)) + @test is_nilpotent(ZZmodZZ720(30)) + nilp720 = filter((r -> is_nilpotent(ZZmod720(r))), 0:719); + @test length(nilp) == 24 # 720/(2*3*5) + nilp = filter((r -> is_nilpotent(ZZmodZZ720(r))), 0:719); + @test length(nilp) == 24 # 720/(2*3*5) + end @testset "ZZModRingElem.unary_ops" begin From 7173aa9e250997fe1796cdc689b03d0bbca0ec9a Mon Sep 17 00:00:00 2001 From: John Abbott Date: Fri, 13 Dec 2024 14:22:25 +0100 Subject: [PATCH 03/31] Removed spaces which triggered syntax error --- test/flint/fmpz_mod-test.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/flint/fmpz_mod-test.jl b/test/flint/fmpz_mod-test.jl index 809ad8d2f6..52b010086e 100644 --- a/test/flint/fmpz_mod-test.jl +++ b/test/flint/fmpz_mod-test.jl @@ -132,8 +132,8 @@ end @test_throws Exception R2(R3(1)) @test_throws Exception R3(R2(1)) - ZZmod720,_ = residue_ring (ZZ,720) - ZZmodZZ720,_ = residue_ring (ZZ,ZZ(720)) + ZZmod720,_ = residue_ring(ZZ,720) + ZZmodZZ720,_ = residue_ring(ZZ,ZZ(720)) @test is_nilpotent(ZZmod720(30)) @test is_nilpotent(ZZmodZZ720(30)) nilp720 = filter((r -> is_nilpotent(ZZmod720(r))), 0:719); From 7b2fea9a307a38e7a8c73d34d1ae0426466cf24c Mon Sep 17 00:00:00 2001 From: John Abbott Date: Fri, 13 Dec 2024 14:54:39 +0100 Subject: [PATCH 04/31] Fixed typo (from careless copy-paste) --- test/flint/fmpz_mod-test.jl | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test/flint/fmpz_mod-test.jl b/test/flint/fmpz_mod-test.jl index 52b010086e..741b546ca3 100644 --- a/test/flint/fmpz_mod-test.jl +++ b/test/flint/fmpz_mod-test.jl @@ -137,10 +137,9 @@ end @test is_nilpotent(ZZmod720(30)) @test is_nilpotent(ZZmodZZ720(30)) nilp720 = filter((r -> is_nilpotent(ZZmod720(r))), 0:719); - @test length(nilp) == 24 # 720/(2*3*5) - nilp = filter((r -> is_nilpotent(ZZmodZZ720(r))), 0:719); - @test length(nilp) == 24 # 720/(2*3*5) - + @test length(nilp720) == 24 # 720/(2*3*5) + nilp720 = filter((r -> is_nilpotent(ZZmodZZ720(r))), 0:719); + @test length(nilp720) == 24 # 720/(2*3*5) end @testset "ZZModRingElem.unary_ops" begin From db38bc565e304d47ac625b23f7354bfaf6eca023 Mon Sep 17 00:00:00 2001 From: John Abbott Date: Fri, 13 Dec 2024 15:01:43 +0100 Subject: [PATCH 05/31] Inserted missing defn of is_domain_type --- src/flint/fmpz_mod.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/flint/fmpz_mod.jl b/src/flint/fmpz_mod.jl index 596037b968..3c1764eebf 100644 --- a/src/flint/fmpz_mod.jl +++ b/src/flint/fmpz_mod.jl @@ -20,6 +20,8 @@ base_ring(a::ZZModRing) = ZZ parent(a::ZZModRingElem) = a.parent +is_domain_type(::Type{ZZModRingElem}) = false + ############################################################################### # # Basic manipulation From 7928bd58ab95d979e64be0c6b4166af28386a884 Mon Sep 17 00:00:00 2001 From: John Abbott Date: Fri, 13 Dec 2024 15:02:31 +0100 Subject: [PATCH 06/31] Inserted missing defn of is_domain_type --- src/flint/fmpz_mod_poly.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/flint/fmpz_mod_poly.jl b/src/flint/fmpz_mod_poly.jl index 0658b758ad..20bebb6c40 100644 --- a/src/flint/fmpz_mod_poly.jl +++ b/src/flint/fmpz_mod_poly.jl @@ -18,6 +18,8 @@ elem_type(::Type{ZZModPolyRing}) = ZZModPolyRingElem parent_type(::Type{ZZModPolyRingElem}) = ZZModPolyRing +is_domain_type(::Type{ZZModPolyRingElem}) = false + dense_poly_type(::Type{ZZModRingElem}) = ZZModPolyRingElem function _is_one_or_throw(f, y) From dd78f5017fe89f2f0020f7b504f1730e7c8acccc Mon Sep 17 00:00:00 2001 From: John Abbott Date: Fri, 13 Dec 2024 15:03:36 +0100 Subject: [PATCH 07/31] Inserted missing defn of is_domain_type --- src/flint/nmod.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/flint/nmod.jl b/src/flint/nmod.jl index b04266f62e..8099e8b424 100644 --- a/src/flint/nmod.jl +++ b/src/flint/nmod.jl @@ -20,6 +20,8 @@ base_ring(a::zzModRing) = ZZ parent(a::zzModRingElem) = a.parent +is_domain_type(::Type{zzModRingElem}) = false + ############################################################################### # # Basic manipulation From 6c5912f892c9adaeacbc6b127eb15db647fcec31 Mon Sep 17 00:00:00 2001 From: John Abbott Date: Fri, 13 Dec 2024 15:04:00 +0100 Subject: [PATCH 08/31] Inserted missing defn of is_domain_type --- src/flint/nmod_poly.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/flint/nmod_poly.jl b/src/flint/nmod_poly.jl index bd4bab902d..45576ab78a 100644 --- a/src/flint/nmod_poly.jl +++ b/src/flint/nmod_poly.jl @@ -20,6 +20,8 @@ elem_type(::Type{zzModPolyRing}) = zzModPolyRingElem dense_poly_type(::Type{zzModRingElem}) = zzModPolyRingElem +is_domain_type(::Type{zzModPolyRingElem}) = false + ################################################################################ # # Basic helper From 9cb13a34a5285b504e8cff29427d61b00bbc39f8 Mon Sep 17 00:00:00 2001 From: John Abbott Date: Fri, 13 Dec 2024 16:37:52 +0100 Subject: [PATCH 09/31] Add defns of is_nilpotent for ZZRingElem & QQFieldElem --- src/flint/fmpq.jl | 2 ++ src/flint/fmpz.jl | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/flint/fmpq.jl b/src/flint/fmpq.jl index 39bca1ca01..b814b11c6a 100644 --- a/src/flint/fmpq.jl +++ b/src/flint/fmpq.jl @@ -115,6 +115,8 @@ is_zero(a::QQFieldElemOrPtr) = is_zero(_num_ptr(a)) is_unit(a::QQFieldElem) = !iszero(a) +is_nilpotent(a::QQFieldElem) = iszero(a) + isinteger(a::QQFieldElemOrPtr) = is_one(_den_ptr(a)) isfinite(::QQFieldElem) = true diff --git a/src/flint/fmpz.jl b/src/flint/fmpz.jl index 7c811794f6..2e991f9203 100644 --- a/src/flint/fmpz.jl +++ b/src/flint/fmpz.jl @@ -254,6 +254,8 @@ size(a::ZZRingElem) = _fmpz_is_small(a) ? 1 : abs(_fmpz_size(a)) is_unit(a::ZZRingElemOrPtr) = data(a) == 1 || data(a) == -1 +is_nilpotent(a::ZZRingElemOrPtr) = iszero(data(a)) + is_zero(a::ZZRingElemOrPtr) = data(a) == 0 is_one(a::ZZRingElemOrPtr) = data(a) == 1 From 1061b42f04b3b742e1fb70e8bad181e9592a251d Mon Sep 17 00:00:00 2001 From: John Abbott Date: Mon, 16 Dec 2024 16:34:37 +0100 Subject: [PATCH 10/31] Bugfix: use data instead of lift, use mod! to avoid overflow --- src/HeckeMoreStuff.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/HeckeMoreStuff.jl b/src/HeckeMoreStuff.jl index a2b6d18ef9..f1c8b82210 100644 --- a/src/HeckeMoreStuff.jl +++ b/src/HeckeMoreStuff.jl @@ -396,13 +396,13 @@ function is_nilpotent(res::ResElem{T}) where {T<:IntegerUnion} # m=modulus(res); # return powermod(lift(res),nbits(m),m)==0 m = modulus(res) - r = lift(res) + r = data(res) # the least non-negative class representative as a value of type "unsigned" T; !!note that "lift" casts the value to BigInt!! while true g = gcd(r, m) (g == m) && return true (g == 1) && return false - m /= g - r = g^2 + m = divexact(m, g) # equiv to: m /= g + mod!(g, m); r = g^2 # g^2 cannot overflow thanks to mod! end end From d5739b3b5dc6b4afff9f8f80b7037ead498b94a0 Mon Sep 17 00:00:00 2001 From: John Abbott Date: Mon, 16 Dec 2024 16:35:41 +0100 Subject: [PATCH 11/31] Minor impl change to is_nilpotent --- src/flint/fmpz.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/flint/fmpz.jl b/src/flint/fmpz.jl index 2e991f9203..c7819cfafd 100644 --- a/src/flint/fmpz.jl +++ b/src/flint/fmpz.jl @@ -254,7 +254,7 @@ size(a::ZZRingElem) = _fmpz_is_small(a) ? 1 : abs(_fmpz_size(a)) is_unit(a::ZZRingElemOrPtr) = data(a) == 1 || data(a) == -1 -is_nilpotent(a::ZZRingElemOrPtr) = iszero(data(a)) +is_nilpotent(a::ZZRingElemOrPtr) = (data(a) == 0) is_zero(a::ZZRingElemOrPtr) = data(a) == 0 From 80afb2273734fc26ebdf2579cefdadb96ceb1bf6 Mon Sep 17 00:00:00 2001 From: John Abbott Date: Mon, 16 Dec 2024 16:36:42 +0100 Subject: [PATCH 12/31] Removed unnecessary is_domain_type defn --- src/flint/fmpz_mod.jl | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/flint/fmpz_mod.jl b/src/flint/fmpz_mod.jl index 3c1764eebf..596037b968 100644 --- a/src/flint/fmpz_mod.jl +++ b/src/flint/fmpz_mod.jl @@ -20,8 +20,6 @@ base_ring(a::ZZModRing) = ZZ parent(a::ZZModRingElem) = a.parent -is_domain_type(::Type{ZZModRingElem}) = false - ############################################################################### # # Basic manipulation From e714f6c027c05d47c83724c5a563b678362602dd Mon Sep 17 00:00:00 2001 From: John Abbott Date: Mon, 16 Dec 2024 16:37:19 +0100 Subject: [PATCH 13/31] Removed unnecessary is_domain_type defn --- src/flint/fmpz_mod_poly.jl | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/flint/fmpz_mod_poly.jl b/src/flint/fmpz_mod_poly.jl index 20bebb6c40..0658b758ad 100644 --- a/src/flint/fmpz_mod_poly.jl +++ b/src/flint/fmpz_mod_poly.jl @@ -18,8 +18,6 @@ elem_type(::Type{ZZModPolyRing}) = ZZModPolyRingElem parent_type(::Type{ZZModPolyRingElem}) = ZZModPolyRing -is_domain_type(::Type{ZZModPolyRingElem}) = false - dense_poly_type(::Type{ZZModRingElem}) = ZZModPolyRingElem function _is_one_or_throw(f, y) From 4254da6d3db8c99bced01b8b15f940bfa7c816ae Mon Sep 17 00:00:00 2001 From: John Abbott Date: Mon, 16 Dec 2024 16:37:45 +0100 Subject: [PATCH 14/31] Removed unnecessary is_domain_type defn --- src/flint/nmod.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/flint/nmod.jl b/src/flint/nmod.jl index 8099e8b424..406aeebe95 100644 --- a/src/flint/nmod.jl +++ b/src/flint/nmod.jl @@ -20,7 +20,6 @@ base_ring(a::zzModRing) = ZZ parent(a::zzModRingElem) = a.parent -is_domain_type(::Type{zzModRingElem}) = false ############################################################################### # From 013b53c760c2169afca952470af5f4bd918cd638 Mon Sep 17 00:00:00 2001 From: John Abbott Date: Mon, 16 Dec 2024 16:38:05 +0100 Subject: [PATCH 15/31] Removed unnecessary is_domain_type defn --- src/flint/nmod_poly.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/flint/nmod_poly.jl b/src/flint/nmod_poly.jl index 45576ab78a..4beead4040 100644 --- a/src/flint/nmod_poly.jl +++ b/src/flint/nmod_poly.jl @@ -20,7 +20,6 @@ elem_type(::Type{zzModPolyRing}) = zzModPolyRingElem dense_poly_type(::Type{zzModRingElem}) = zzModPolyRingElem -is_domain_type(::Type{zzModPolyRingElem}) = false ################################################################################ # From 9d2354ebe3e70a2d1acc3c85ca74be8e9611c97d Mon Sep 17 00:00:00 2001 From: John Abbott Date: Mon, 16 Dec 2024 16:38:54 +0100 Subject: [PATCH 16/31] Added overflow test --- test/flint/fmpz_mod-test.jl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/flint/fmpz_mod-test.jl b/test/flint/fmpz_mod-test.jl index 741b546ca3..6d18966d7a 100644 --- a/test/flint/fmpz_mod-test.jl +++ b/test/flint/fmpz_mod-test.jl @@ -140,6 +140,12 @@ end @test length(nilp720) == 24 # 720/(2*3*5) nilp720 = filter((r -> is_nilpotent(ZZmodZZ720(r))), 0:719); @test length(nilp720) == 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(rr)) end @testset "ZZModRingElem.unary_ops" begin From a755c62eb35c9d2b676bf774e69d9a5d1e4d4c5f Mon Sep 17 00:00:00 2001 From: John Abbott Date: Mon, 16 Dec 2024 18:02:25 +0100 Subject: [PATCH 17/31] Fixed typo --- test/flint/fmpz_mod-test.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/flint/fmpz_mod-test.jl b/test/flint/fmpz_mod-test.jl index 6d18966d7a..b71ab48f32 100644 --- a/test/flint/fmpz_mod-test.jl +++ b/test/flint/fmpz_mod-test.jl @@ -145,7 +145,7 @@ end rr = 4*3^20 mm = 3*rr R_overflow, = residue_ring(ZZ, mm) - @test is_nilpotent(R(rr)) + @test is_nilpotent(R_overflow(rr)) end @testset "ZZModRingElem.unary_ops" begin From 96616b173dac3f525c9c0c2c0dbe6f95450a6e51 Mon Sep 17 00:00:00 2001 From: John Abbott Date: Tue, 17 Dec 2024 17:30:01 +0100 Subject: [PATCH 18/31] Commented out buggy old impl of is_unit --- src/flint/nmod_mpoly.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/flint/nmod_mpoly.jl b/src/flint/nmod_mpoly.jl index b434177acd..5bfd3d507d 100644 --- a/src/flint/nmod_mpoly.jl +++ b/src/flint/nmod_mpoly.jl @@ -100,9 +100,9 @@ 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_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) From 80e1c02f5022bd7ef1aa6574652cf735d1b0f255 Mon Sep 17 00:00:00 2001 From: John Abbott Date: Fri, 20 Dec 2024 15:34:54 +0100 Subject: [PATCH 19/31] is_unit subsumed by impl in AbstractAlgebra/src/generic/Residue.jl --- src/flint/nmod.jl | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/flint/nmod.jl b/src/flint/nmod.jl index 406aeebe95..d77f25708a 100644 --- a/src/flint/nmod.jl +++ b/src/flint/nmod.jl @@ -51,9 +51,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 From 61e9fc1e69ffa67b627844efb5c96096e219b8c9 Mon Sep 17 00:00:00 2001 From: John Abbott Date: Fri, 20 Dec 2024 15:37:01 +0100 Subject: [PATCH 20/31] is_nilpotent subsumed by impl in AbstractAlgebra/src/Residue.jl --- src/HeckeMoreStuff.jl | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/src/HeckeMoreStuff.jl b/src/HeckeMoreStuff.jl index f1c8b82210..bf5ccad52c 100644 --- a/src/HeckeMoreStuff.jl +++ b/src/HeckeMoreStuff.jl @@ -385,26 +385,6 @@ function is_unit(f::T) where {T<:Union{ZZModPolyRingElem,zzModPolyRingElem}} 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(res::ResElem{T}) where {T<:IntegerUnion} - # Code below is faster than - # m=modulus(res); - # return powermod(lift(res),nbits(m),m)==0 - m = modulus(res) - r = data(res) # the least non-negative class representative as a value of type "unsigned" T; !!note that "lift" casts the value to BigInt!! - while true - g = gcd(r, m) - (g == m) && return true - (g == 1) && return false - m = divexact(m, g) # equiv to: m /= g - mod!(g, m); r = g^2 # g^2 cannot overflow thanks to mod! - end -end function inv(f::T) where {T<:Union{ZZModPolyRingElem,zzModPolyRingElem}} if !is_unit(f) From 2de0918d8d701466449bc91978372637a1389790 Mon Sep 17 00:00:00 2001 From: John Abbott Date: Fri, 20 Dec 2024 15:38:14 +0100 Subject: [PATCH 21/31] Minor: inserted underscore dummy arg --- test/flint/fmpz_mod-test.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/flint/fmpz_mod-test.jl b/test/flint/fmpz_mod-test.jl index b71ab48f32..abc5407f52 100644 --- a/test/flint/fmpz_mod-test.jl +++ b/test/flint/fmpz_mod-test.jl @@ -144,7 +144,7 @@ end # 64-bit overflow test: **ASSUMES** Int is 64 bits rr = 4*3^20 mm = 3*rr - R_overflow, = residue_ring(ZZ, mm) + R_overflow,_ = residue_ring(ZZ, mm) @test is_nilpotent(R_overflow(rr)) end From e3004f451527fb607b8b78d010e18eb6116e960a Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sun, 22 Dec 2024 00:42:56 +0100 Subject: [PATCH 22/31] Require AA 0.44.2 --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 23c03e103c..2c63e04f09 100644 --- a/Project.toml +++ b/Project.toml @@ -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" From c09c7df5bab31837b4e9170c09de3b4c226b43b6 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sun, 22 Dec 2024 14:09:18 +0100 Subject: [PATCH 23/31] Apply suggestions from code review --- src/flint/fmpq.jl | 4 ---- src/flint/fmpz.jl | 2 -- src/flint/nmod.jl | 1 - src/flint/nmod_mpoly.jl | 4 ---- src/flint/nmod_poly.jl | 1 - 5 files changed, 12 deletions(-) diff --git a/src/flint/fmpq.jl b/src/flint/fmpq.jl index b814b11c6a..ae22e4d284 100644 --- a/src/flint/fmpq.jl +++ b/src/flint/fmpq.jl @@ -113,10 +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) - -is_nilpotent(a::QQFieldElem) = iszero(a) - isinteger(a::QQFieldElemOrPtr) = is_one(_den_ptr(a)) isfinite(::QQFieldElem) = true diff --git a/src/flint/fmpz.jl b/src/flint/fmpz.jl index 32566968f1..84dc6fddc4 100644 --- a/src/flint/fmpz.jl +++ b/src/flint/fmpz.jl @@ -254,8 +254,6 @@ size(a::ZZRingElem) = _fmpz_is_small(a) ? 1 : abs(_fmpz_size(a)) is_unit(a::ZZRingElemOrPtr) = data(a) == 1 || data(a) == -1 -is_nilpotent(a::ZZRingElemOrPtr) = (data(a) == 0) - is_zero(a::ZZRingElemOrPtr) = data(a) == 0 is_one(a::ZZRingElemOrPtr) = data(a) == 1 diff --git a/src/flint/nmod.jl b/src/flint/nmod.jl index d77f25708a..f8c7442fa2 100644 --- a/src/flint/nmod.jl +++ b/src/flint/nmod.jl @@ -20,7 +20,6 @@ base_ring(a::zzModRing) = ZZ parent(a::zzModRingElem) = a.parent - ############################################################################### # # Basic manipulation diff --git a/src/flint/nmod_mpoly.jl b/src/flint/nmod_mpoly.jl index 5bfd3d507d..ceed984e65 100644 --- a/src/flint/nmod_mpoly.jl +++ b/src/flint/nmod_mpoly.jl @@ -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 diff --git a/src/flint/nmod_poly.jl b/src/flint/nmod_poly.jl index 4beead4040..bd4bab902d 100644 --- a/src/flint/nmod_poly.jl +++ b/src/flint/nmod_poly.jl @@ -20,7 +20,6 @@ elem_type(::Type{zzModPolyRing}) = zzModPolyRingElem dense_poly_type(::Type{zzModRingElem}) = zzModPolyRingElem - ################################################################################ # # Basic helper From fe4c8910c8713f50cd33b94c7104fca8eb08392e Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sun, 22 Dec 2024 14:14:33 +0100 Subject: [PATCH 24/31] Remove more redundant methods --- src/HeckeMoreStuff.jl | 20 -------------------- src/antic/nf_elem.jl | 8 -------- src/arb/Complex.jl | 4 ---- src/arb/acb.jl | 4 ---- src/arb/arb.jl | 4 ---- src/flint/fmpq_mpoly.jl | 4 ---- src/flint/gfp_elem.jl | 2 -- src/flint/gfp_fmpz_elem.jl | 2 -- src/flint/padic.jl | 2 -- src/flint/qadic.jl | 2 -- 10 files changed, 52 deletions(-) diff --git a/src/HeckeMoreStuff.jl b/src/HeckeMoreStuff.jl index e01f47f433..63bc84faa4 100644 --- a/src/HeckeMoreStuff.jl +++ b/src/HeckeMoreStuff.jl @@ -346,26 +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 - - function inv(f::T) where {T<:Union{ZZModPolyRingElem,zzModPolyRingElem}} if !is_unit(f) error("impossible inverse") diff --git a/src/antic/nf_elem.jl b/src/antic/nf_elem.jl index 312f88efff..71be6296f1 100644 --- a/src/antic/nf_elem.jl +++ b/src/antic/nf_elem.jl @@ -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) diff --git a/src/arb/Complex.jl b/src/arb/Complex.jl index 0e36d14904..e32895f99c 100644 --- a/src/arb/Complex.jl +++ b/src/arb/Complex.jl @@ -447,10 +447,6 @@ end # ################################################################################ -function is_unit(x::ComplexFieldElem) - !iszero(x) -end - @doc raw""" iszero(x::ComplexFieldElem) diff --git a/src/arb/acb.jl b/src/arb/acb.jl index bf7031d7a3..95b3fbc313 100644 --- a/src/arb/acb.jl +++ b/src/arb/acb.jl @@ -458,10 +458,6 @@ end # ################################################################################ -function is_unit(x::AcbFieldElem) - !iszero(x) -end - @doc raw""" iszero(x::AcbFieldElem) diff --git a/src/arb/arb.jl b/src/arb/arb.jl index f7abff284b..4a5a0c5c58 100644 --- a/src/arb/arb.jl +++ b/src/arb/arb.jl @@ -450,10 +450,6 @@ end # ################################################################################ -function is_unit(x::ArbFieldElem) - !iszero(x) -end - @doc raw""" iszero(x::ArbFieldElem) diff --git a/src/flint/fmpq_mpoly.jl b/src/flint/fmpq_mpoly.jl index f4e9398ce9..cab8b11af7 100644 --- a/src/flint/fmpq_mpoly.jl +++ b/src/flint/fmpq_mpoly.jl @@ -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) diff --git a/src/flint/gfp_elem.jl b/src/flint/gfp_elem.jl index 8a44ab0103..1dab8ecbaa 100644 --- a/src/flint/gfp_elem.jl +++ b/src/flint/gfp_elem.jl @@ -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) diff --git a/src/flint/gfp_fmpz_elem.jl b/src/flint/gfp_fmpz_elem.jl index d4fa418d72..7d6f828ac4 100644 --- a/src/flint/gfp_fmpz_elem.jl +++ b/src/flint/gfp_fmpz_elem.jl @@ -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) diff --git a/src/flint/padic.jl b/src/flint/padic.jl index 0b64f029f9..681d2d2f71 100644 --- a/src/flint/padic.jl +++ b/src/flint/padic.jl @@ -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 ############################################################################### diff --git a/src/flint/qadic.jl b/src/flint/qadic.jl index 3d29e60f02..acf11e4002 100644 --- a/src/flint/qadic.jl +++ b/src/flint/qadic.jl @@ -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) From 08f690df133eb7c98f87db0ec8b806b100bec5a5 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sun, 22 Dec 2024 14:21:20 +0100 Subject: [PATCH 25/31] Remove more redundant stuff is_unit(a::fqPolyRepMPolyRingElem) even was wrong (it return true for zero) --- src/Exports.jl | 1 - src/flint/fq.jl | 2 -- src/flint/fq_default.jl | 2 -- src/flint/fq_nmod.jl | 2 -- src/flint/fq_nmod_mpoly.jl | 4 ---- src/gaussiannumbers/QQi.jl | 4 ---- 6 files changed, 15 deletions(-) diff --git a/src/Exports.jl b/src/Exports.jl index cb77d506d3..ee29b244b5 100644 --- a/src/Exports.jl +++ b/src/Exports.jl @@ -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 diff --git a/src/flint/fq.jl b/src/flint/fq.jl index ab363b9b96..ae4d2093ef 100644 --- a/src/flint/fq.jl +++ b/src/flint/fq.jl @@ -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 diff --git a/src/flint/fq_default.jl b/src/flint/fq_default.jl index 15fa7165f2..0cf3b78bcb 100644 --- a/src/flint/fq_default.jl +++ b/src/flint/fq_default.jl @@ -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 diff --git a/src/flint/fq_nmod.jl b/src/flint/fq_nmod.jl index f10daf4a0a..1b53fbcd74 100644 --- a/src/flint/fq_nmod.jl +++ b/src/flint/fq_nmod.jl @@ -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 diff --git a/src/flint/fq_nmod_mpoly.jl b/src/flint/fq_nmod_mpoly.jl index 6557697a2f..d29346995a 100644 --- a/src/flint/fq_nmod_mpoly.jl +++ b/src/flint/fq_nmod_mpoly.jl @@ -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) diff --git a/src/gaussiannumbers/QQi.jl b/src/gaussiannumbers/QQi.jl index 46e3b6543a..07ca8c1fb1 100644 --- a/src/gaussiannumbers/QQi.jl +++ b/src/gaussiannumbers/QQi.jl @@ -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) From baa6317f32778477ccce194ff894b96bd4c7a776 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sun, 22 Dec 2024 14:38:57 +0100 Subject: [PATCH 26/31] Remove more redundant methods The generic code is actually faster than those --- src/flint/fmpz_mod_mpoly.jl | 4 ---- src/flint/fmpz_mpoly.jl | 4 ---- 2 files changed, 8 deletions(-) diff --git a/src/flint/fmpz_mod_mpoly.jl b/src/flint/fmpz_mod_mpoly.jl index 2254152c3d..e7d44cd2e7 100644 --- a/src/flint/fmpz_mod_mpoly.jl +++ b/src/flint/fmpz_mod_mpoly.jl @@ -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 diff --git a/src/flint/fmpz_mpoly.jl b/src/flint/fmpz_mpoly.jl index f83fb2be72..73bb15c4d1 100644 --- a/src/flint/fmpz_mpoly.jl +++ b/src/flint/fmpz_mpoly.jl @@ -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) From 31125c8fe31f8c89d4e5f50a8ff0e6c93d016fbb Mon Sep 17 00:00:00 2001 From: John Abbott Date: Wed, 8 Jan 2025 16:13:37 +0100 Subject: [PATCH 27/31] Removed blank line --- src/flint/nmod.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/flint/nmod.jl b/src/flint/nmod.jl index d77f25708a..f8c7442fa2 100644 --- a/src/flint/nmod.jl +++ b/src/flint/nmod.jl @@ -20,7 +20,6 @@ base_ring(a::zzModRing) = ZZ parent(a::zzModRingElem) = a.parent - ############################################################################### # # Basic manipulation From 77dbc490946747b14d5d48679ede03f7ac3ccd79 Mon Sep 17 00:00:00 2001 From: John Abbott Date: Wed, 8 Jan 2025 16:14:04 +0100 Subject: [PATCH 28/31] Removed blank line --- src/flint/nmod_poly.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/flint/nmod_poly.jl b/src/flint/nmod_poly.jl index 4beead4040..bd4bab902d 100644 --- a/src/flint/nmod_poly.jl +++ b/src/flint/nmod_poly.jl @@ -20,7 +20,6 @@ elem_type(::Type{zzModPolyRing}) = zzModPolyRingElem dense_poly_type(::Type{zzModRingElem}) = zzModPolyRingElem - ################################################################################ # # Basic helper From b319a28a8d3569917bae3fbf6ff7e8ee23e316ba Mon Sep 17 00:00:00 2001 From: John Abbott Date: Wed, 8 Jan 2025 16:16:03 +0100 Subject: [PATCH 29/31] Moved test on residue_ring(ZZ,720) to nmod; replaced length(filter(...)) by count(...) --- test/flint/fmpz_mod-test.jl | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/test/flint/fmpz_mod-test.jl b/test/flint/fmpz_mod-test.jl index abc5407f52..e1c81c8df3 100644 --- a/test/flint/fmpz_mod-test.jl +++ b/test/flint/fmpz_mod-test.jl @@ -132,20 +132,9 @@ end @test_throws Exception R2(R3(1)) @test_throws Exception R3(R2(1)) - ZZmod720,_ = residue_ring(ZZ,720) ZZmodZZ720,_ = residue_ring(ZZ,ZZ(720)) - @test is_nilpotent(ZZmod720(30)) @test is_nilpotent(ZZmodZZ720(30)) - nilp720 = filter((r -> is_nilpotent(ZZmod720(r))), 0:719); - @test length(nilp720) == 24 # 720/(2*3*5) - nilp720 = filter((r -> is_nilpotent(ZZmodZZ720(r))), 0:719); - @test length(nilp720) == 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)) + @test count(is_nilpotent, ZZmodZZ720) == 24 # 720/(2*3*5) end @testset "ZZModRingElem.unary_ops" begin From 959bc112b5c02bc19c27c5b4d560172323f8f153 Mon Sep 17 00:00:00 2001 From: John Abbott Date: Wed, 8 Jan 2025 16:17:27 +0100 Subject: [PATCH 30/31] Moved test from fmpz_mod-test to here: is_nilpotent in ZZmod720 --- test/flint/nmod-test.jl | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/flint/nmod-test.jl b/test/flint/nmod-test.jl index c92702ba10..9ca2850cd3 100644 --- a/test/flint/nmod-test.jl +++ b/test/flint/nmod-test.jl @@ -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 From cebd9c6e2c686812babe139adbb8f01f22fc3aa3 Mon Sep 17 00:00:00 2001 From: John Abbott Date: Wed, 8 Jan 2025 16:19:23 +0100 Subject: [PATCH 31/31] Inserted a space --- test/flint/nmod-test.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/flint/nmod-test.jl b/test/flint/nmod-test.jl index 9ca2850cd3..1759a5d266 100644 --- a/test/flint/nmod-test.jl +++ b/test/flint/nmod-test.jl @@ -130,7 +130,7 @@ end @test_throws Exception R2(R3(1)) @test_throws Exception R3(R2(1)) - ZZmod720,_ = residue_ring(ZZ,720) + ZZmod720,_ = residue_ring(ZZ, 720) @test is_nilpotent(ZZmod720(30)) @test count(is_nilpotent, ZZmod720) == 24 # 720/(2*3*5)