From 7e8619a1004627b9040736bf141c6eb1b5d92113 Mon Sep 17 00:00:00 2001 From: John Abbott Date: Thu, 16 Oct 2025 14:42:25 +0200 Subject: [PATCH 1/5] Make equality of factorizations give error (instead of false) --- src/Factor.jl | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Factor.jl b/src/Factor.jl index 241b648ec4..475e8142a1 100644 --- a/src/Factor.jl +++ b/src/Factor.jl @@ -56,6 +56,18 @@ _is_legal(a::Fac) = xor(isdefined(a, :fac), isdefined(a, :arr)) _is_dic(a::Fac) = _is_legal(a) && isdefined(a, :fac) +function Base.:(==)(F1::Fac{T}, F2::Fac{T}) where {T <: RingElement} + (F1 === F2) && return true + if unit(F1) isa RingElem && parent(unit(F1)) != parent(unit(F2)) + error("Equality testing of factorizations over different rings is forbidden"); + end + error("Equality testing of factorizations is not supported"); +end + +function Base.:(==)(F1::Fac{T1}, F2::Fac{T2}) where {T1 <: RingElement, T2 <: RingElement} + error("Equality testing of factorizations of different types is forbidden"); +end + @doc raw""" unit(a::Fac{T}) -> T From 4f00952b593c7675753cd2c099c323b48c367435 Mon Sep 17 00:00:00 2001 From: John Abbott Date: Mon, 20 Oct 2025 14:35:09 +0200 Subject: [PATCH 2/5] Added basic test --- test/Factor-test.jl | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/Factor-test.jl b/test/Factor-test.jl index a2582744b5..c90cd7e96c 100644 --- a/test/Factor-test.jl +++ b/test/Factor-test.jl @@ -29,3 +29,14 @@ end @test string(f) == "x * (x + y) * (x*y)" || string(f) == "x * (x*y) * (x + y)" end + +@testset "Fac.equality" begin + # 2025-10-20 equality test on factorizations always gives error (except if the args are ===) + f = Fac(-1, Dict{Int, Int}(2 => 3, 3 => 1)) + ff = Fac(-1, [2 => 3, 3 => 1]) + fzz = Fac(ZZ(-1), Dict{ZZRingElem, Int}(ZZ(2) => 3, ZZ(3) => 1)) + + @test f == f + @test_throws MethodError (f == ff) + @test_throws MethodError (f == fzz) +end From 4b8fa6772505fd45e320a0f158bcea06452b01a1 Mon Sep 17 00:00:00 2001 From: John Abbott Date: Mon, 20 Oct 2025 14:53:33 +0200 Subject: [PATCH 3/5] Equality test of factorizations ALWAYS gives error; updated tests --- src/Factor.jl | 17 +++++++++-------- test/Factor-test.jl | 8 ++++---- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/Factor.jl b/src/Factor.jl index 475e8142a1..e9f8fd5455 100644 --- a/src/Factor.jl +++ b/src/Factor.jl @@ -56,16 +56,17 @@ _is_legal(a::Fac) = xor(isdefined(a, :fac), isdefined(a, :arr)) _is_dic(a::Fac) = _is_legal(a) && isdefined(a, :fac) -function Base.:(==)(F1::Fac{T}, F2::Fac{T}) where {T <: RingElement} - (F1 === F2) && return true - if unit(F1) isa RingElem && parent(unit(F1)) != parent(unit(F2)) - error("Equality testing of factorizations over different rings is forbidden"); - end - error("Equality testing of factorizations is not supported"); -end +# function Base.:(==)(F1::Fac{T}, F2::Fac{T}) where {T <: RingElement} +# (F1 === F2) && return true +# if unit(F1) isa RingElem && parent(unit(F1)) != parent(unit(F2)) +# error("Equality testing of factorizations over different rings is forbidden"); +# end +# error("Equality testing of factorizations is not supported"); +# end function Base.:(==)(F1::Fac{T1}, F2::Fac{T2}) where {T1 <: RingElement, T2 <: RingElement} - error("Equality testing of factorizations of different types is forbidden"); + error("Equality testing of factorizations is not supported"); + #error("Equality testing of factorizations of different types is forbidden"); end @doc raw""" diff --git a/test/Factor-test.jl b/test/Factor-test.jl index c90cd7e96c..e01fa67b2a 100644 --- a/test/Factor-test.jl +++ b/test/Factor-test.jl @@ -31,12 +31,12 @@ end end @testset "Fac.equality" begin - # 2025-10-20 equality test on factorizations always gives error (except if the args are ===) + # 2025-10-20 equality test on factorizations always gives error (even if the args are ===) f = Fac(-1, Dict{Int, Int}(2 => 3, 3 => 1)) ff = Fac(-1, [2 => 3, 3 => 1]) fzz = Fac(ZZ(-1), Dict{ZZRingElem, Int}(ZZ(2) => 3, ZZ(3) => 1)) - @test f == f - @test_throws MethodError (f == ff) - @test_throws MethodError (f == fzz) + @test_throws ErrorException f == f + @test_throws ErrorException (f == ff) + @test_throws ErrorException (f == fzz) end From 7f40048f2a68ff22f47bb3239f2bc2d3cf83c3c7 Mon Sep 17 00:00:00 2001 From: John Abbott Date: Mon, 20 Oct 2025 16:57:39 +0200 Subject: [PATCH 4/5] Removed cruft --- src/Factor.jl | 9 --------- test/Factor-test.jl | 2 -- 2 files changed, 11 deletions(-) diff --git a/src/Factor.jl b/src/Factor.jl index e9f8fd5455..6ab7713e12 100644 --- a/src/Factor.jl +++ b/src/Factor.jl @@ -56,17 +56,8 @@ _is_legal(a::Fac) = xor(isdefined(a, :fac), isdefined(a, :arr)) _is_dic(a::Fac) = _is_legal(a) && isdefined(a, :fac) -# function Base.:(==)(F1::Fac{T}, F2::Fac{T}) where {T <: RingElement} -# (F1 === F2) && return true -# if unit(F1) isa RingElem && parent(unit(F1)) != parent(unit(F2)) -# error("Equality testing of factorizations over different rings is forbidden"); -# end -# error("Equality testing of factorizations is not supported"); -# end - function Base.:(==)(F1::Fac{T1}, F2::Fac{T2}) where {T1 <: RingElement, T2 <: RingElement} error("Equality testing of factorizations is not supported"); - #error("Equality testing of factorizations of different types is forbidden"); end @doc raw""" diff --git a/test/Factor-test.jl b/test/Factor-test.jl index e01fa67b2a..d154dbffcd 100644 --- a/test/Factor-test.jl +++ b/test/Factor-test.jl @@ -34,9 +34,7 @@ end # 2025-10-20 equality test on factorizations always gives error (even if the args are ===) f = Fac(-1, Dict{Int, Int}(2 => 3, 3 => 1)) ff = Fac(-1, [2 => 3, 3 => 1]) - fzz = Fac(ZZ(-1), Dict{ZZRingElem, Int}(ZZ(2) => 3, ZZ(3) => 1)) @test_throws ErrorException f == f @test_throws ErrorException (f == ff) - @test_throws ErrorException (f == fzz) end From 9d850210e35f5a9a7eb87f9719953bab38975a98 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Wed, 22 Oct 2025 11:51:11 +0200 Subject: [PATCH 5/5] Apply suggestions from code review --- src/Factor.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Factor.jl b/src/Factor.jl index 6ab7713e12..7d7ec7be74 100644 --- a/src/Factor.jl +++ b/src/Factor.jl @@ -56,8 +56,8 @@ _is_legal(a::Fac) = xor(isdefined(a, :fac), isdefined(a, :arr)) _is_dic(a::Fac) = _is_legal(a) && isdefined(a, :fac) -function Base.:(==)(F1::Fac{T1}, F2::Fac{T2}) where {T1 <: RingElement, T2 <: RingElement} - error("Equality testing of factorizations is not supported"); +function Base.:(==)(F1::Fac, F2::Fac) + error("Equality testing of factorizations is not supported") end @doc raw"""