From 455182cadbffc53468eb793874bea4cd83827055 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albin=20Ahlb=C3=A4ck?= Date: Wed, 2 Apr 2025 14:40:58 +0200 Subject: [PATCH 1/8] Add codecov.yml --- .github/codecov.yml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .github/codecov.yml diff --git a/.github/codecov.yml b/.github/codecov.yml new file mode 100644 index 0000000000..9cbefe8a55 --- /dev/null +++ b/.github/codecov.yml @@ -0,0 +1,4 @@ +coverage: + precision: 2 + round: down + range: 85...95 # FIXME: We should set this one to about 90...95 From a577e5286ed2ef0605c22373075c5af456322d98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albin=20Ahlb=C3=A4ck?= Date: Wed, 2 Apr 2025 14:50:34 +0200 Subject: [PATCH 2/8] Remove _is_known_via_attributes --- src/KnownProperties.jl | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/KnownProperties.jl b/src/KnownProperties.jl index 4312b922ec..38d0f06284 100644 --- a/src/KnownProperties.jl +++ b/src/KnownProperties.jl @@ -42,11 +42,3 @@ ERROR: MethodError: no method matching is_known(::typeof(dim), ::AbstractAlgebra ``` """ function is_known end - -# A generic implementation to look up attributes. This can be used to implement -# `is_known` for a specific type of arguments of unary functions. -function _is_known_via_attributes(f::Function, x::Any) - @req _is_attribute_storing_type(typeof(x)) "objects of type $(typeof(x)) do not support attribute storage" - return has_attribute(x, nameof(f)) -end - From 6efe5135d91ba2629764553cfcbb51f08a703c45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albin=20Ahlb=C3=A4ck?= Date: Wed, 2 Apr 2025 16:06:51 +0200 Subject: [PATCH 3/8] Gather show for univariate polynomials --- src/NCPoly.jl | 11 ++++++++--- src/Poly.jl | 12 ------------ 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/src/NCPoly.jl b/src/NCPoly.jl index 34557e3de9..bf4b4a1832 100644 --- a/src/NCPoly.jl +++ b/src/NCPoly.jl @@ -145,11 +145,16 @@ number_of_generators(R::NCPolyRing) = 1 # ############################################################################### -function show(io::IO, p::NCPolyRing) +function show(io::IO, p::Union{NCPolyRing, PolyRing}) @show_name(io, p) @show_special(io, p) - print(io, "Univariate polynomial ring in ", var(p), " over ") - print(terse(pretty(io)), Lowercase(), base_ring(p)) + if is_terse(io) + print(io, "Univariate polynomial ring") + else + io = pretty(io) + print(io, "Univariate polynomial ring in ", var(p), " over ") + print(terse(io), Lowercase(), base_ring(p)) + end end ############################################################################### diff --git a/src/Poly.jl b/src/Poly.jl index 5e371ffc18..20b1f9a368 100644 --- a/src/Poly.jl +++ b/src/Poly.jl @@ -471,18 +471,6 @@ end @enable_all_show_via_expressify Union{PolynomialElem, NCPolyRingElem} -function show(io::IO, p::PolyRing) - @show_name(io, p) - @show_special(io, p) - if is_terse(io) - print(io, "Univariate polynomial ring") - else - io = pretty(io) - print(io, "Univariate polynomial ring in ", var(p), " over ") - print(terse(io), Lowercase(), base_ring(p)) - end -end - ############################################################################### # # Unary operations From 6a174e4f44dee3ed08eab8a3a935bfdd81c4c8c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albin=20Ahlb=C3=A4ck?= Date: Thu, 3 Apr 2025 09:52:59 +0200 Subject: [PATCH 4/8] Fix is_power(::PolyRingElem, ::Int) --- src/generic/Misc/Poly.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/generic/Misc/Poly.jl b/src/generic/Misc/Poly.jl index 0846e020d3..9915e459a9 100644 --- a/src/generic/Misc/Poly.jl +++ b/src/generic/Misc/Poly.jl @@ -13,7 +13,7 @@ function is_power(a::PolyRingElem, n::Int) fl || return false, a f = factor(a) all(i -> i % n == 0, values(f.fac)) || return false, a - return true, x*prod(p^div(k, n) for (p, k) = f.fac) + return true, f.unit * prod(p^div(k, n) for (p, k) = f.fac) end ################################################################################ From 12a5cf5d463416c6207973a5abb6f62f1fba88ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albin=20Ahlb=C3=A4ck?= Date: Thu, 3 Apr 2025 09:53:41 +0200 Subject: [PATCH 5/8] Test is_power(::PolyRingElem, ::Int) --- test/generic/Poly-test.jl | 63 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/test/generic/Poly-test.jl b/test/generic/Poly-test.jl index f5e4c351b7..8a596d76da 100644 --- a/test/generic/Poly-test.jl +++ b/test/generic/Poly-test.jl @@ -3053,3 +3053,66 @@ end @test is_separable(x) @test !is_separable(x^2) end + +@testset "Generic.Poly.Misc" begin + # factor function is required for is_power. Implement naive ones here. + function AbstractAlgebra.factor(a::Integer) + R = parent(a) + f = Fac{typeof(a)}() + f.unit = sign(a) + a = abs(a) + for ix in [R(2), R(3), R(5), R(7), R(11)] + if is_zero(a % ix) + a /= ix + f.fac[ix] = 1 + end + while is_zero(a % ix) + a /= ix + f.fac[ix] += 1 + end + end + if !is_one(a) + error() + end + return f + end + function AbstractAlgebra.factor(p::PolyRingElem) + P = parent(p) + x = gen(P) + f = Fac{typeof(p)}() + ct = content(p) + cf = factor(ct) + ut = sign(leading_coefficient(p)) + for (t, k) in cf + f.fac[P(t)] = k + end + f.unit = P(ut) + p /= ut * ct + for y in [x + c for c in -2:2] + if is_zero(p % y) + p /= y + f.fac[y] = 1 + end + while is_zero(p % y) + p /= y + f.fac[y] += 1 + end + end + if !is_one(p) + error() + end + return f + end + ZZx, x = ZZ[:x] + @test is_power(x, 2) == (false, x) + @test is_power(x, 3) == (false, x) + @test is_power(x^2, 2) == (true, x) + @test is_power(3 * x^2, 2) == (false, 3 * x^2) + @test is_power(2^2 * x^2, 2) == (true, 2 * x) + @test is_power(2^3 * x^3, 3) == (true, 2 * x) + @test is_power(3^4 * x^4, 2) == (true, 9 * x^2) + @test is_power(-3^4 * x^4, 2) == (false, -81 * x^4) + @test is_power(-3^3 * x^3, 3) == (true, -3 * x) + @test is_power(3^2 * (x + 1)^2 * x^2, 2) == (true, 3 * (x + 1) * x) + @test is_power(-3^2 * (x + 1)^2 * x^2, 2) == (false, -3^2 * (x + 1)^2 * x^2) +end From 34097240cbee1551316869168293292475e24387 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albin=20Ahlb=C3=A4ck?= Date: Thu, 3 Apr 2025 11:33:44 +0200 Subject: [PATCH 6/8] Add test for julia/Matrix.jl --- test/Rings-test.jl | 1 + test/julia/Matrix-test.jl | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 test/julia/Matrix-test.jl diff --git a/test/Rings-test.jl b/test/Rings-test.jl index 1a5f76bb2c..1e058bbe56 100644 --- a/test/Rings-test.jl +++ b/test/Rings-test.jl @@ -1,4 +1,5 @@ include("julia/Integers-test.jl") +include("julia/Matrix-test.jl") include("broadcasting-test.jl") # artificially low cutoffs for testing purposes diff --git a/test/julia/Matrix-test.jl b/test/julia/Matrix-test.jl new file mode 100644 index 0000000000..b9d48e8f08 --- /dev/null +++ b/test/julia/Matrix-test.jl @@ -0,0 +1,36 @@ +@testset "Julia.Matrix.manipulation" begin + r, c = 1, 2 + A = zero_matrix(Int, r, c) + A[1, :] = [10, -2] + B = Int[10 -2] + + @test A == B + @test number_of_rows(A) == r + @test number_of_columns(A) == c +end + +@testset "Julia.Matrix.array_creation" begin + M = matrix_ring(ZZ, 2) + m1 = M(ZZ[1 2; 3 4]) + m2 = M(ZZ[1 0; 0 1]) + arr = Array(M, 2) + arr[1] = deepcopy(m1) + arr[2] = deepcopy(m2) + @test arr[1] == m1 + @test arr[2] == m2 +end + +@testset "Julia.Matrix.permutations" begin + M = matrix_ring(ZZ, 2) + m0 = M([1 2; 3 4]) + m1 = M([2 3; 4 5]) + m2 = M([3 4; 5 6]) + m3 = M([4 5; 6 7]) + m = elem_type(M)[m0 m1; m2 m3] + Rm = elem_type(M)[m2 m3; m0 m1] + Cm = elem_type(M)[m1 m0; m3 m2] + rm = swap_rows(m, 2, 1) + cm = swap_cols(m, 1, 2) + @test rm == Rm + @test cm == Cm +end From 74d277d8e1999a16a2e93336765356d04ed20fbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albin=20Ahlb=C3=A4ck?= Date: Thu, 3 Apr 2025 13:07:55 +0200 Subject: [PATCH 7/8] Test sqrt for rings --- test/Rings-test.jl | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/Rings-test.jl b/test/Rings-test.jl index 1e058bbe56..d430e67491 100644 --- a/test/Rings-test.jl +++ b/test/Rings-test.jl @@ -63,6 +63,16 @@ end end end +@testset "sqrt" begin + Base.sqrt(a::EuclideanRingResidueRingElem{BigInt}) = parent(a)(BigInt(sqrt(a.data))) + R = residue_ring(ZZ, 101)[1] + + @test sqrt(R(81), check=true) == R(9) + @test_throws ErrorException sqrt(R(82), check=true) + @test is_square_with_sqrt(R(16)) == (true, R(4)) + @test is_square_with_sqrt(R(15))[1] == false +end + @testset "properties" begin @test is_perfect(QQ) @test is_perfect(GF(2)) From d9344cc946143602f27ec1907ad62b8bd4135020 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albin=20Ahlb=C3=A4ck?= Date: Fri, 4 Apr 2025 14:43:48 +0200 Subject: [PATCH 8/8] Fix swap_cols! for Matrix{T} --- src/julia/Matrix.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/julia/Matrix.jl b/src/julia/Matrix.jl index f636af1d1d..a28183bb59 100644 --- a/src/julia/Matrix.jl +++ b/src/julia/Matrix.jl @@ -112,7 +112,7 @@ end function swap_cols!(a::Matrix{T}, i::Int, j::Int) where T <: NCRingElement if i != j for k = 1:nrows(a) - a[k, i], a[k, j] = a[k, i], a[k, j] + a[k, i], a[k, j] = a[k, j], a[k, i] end end return a