From 7a20ddf299c54ed94f8ec1591f9d3cc758f2c1f0 Mon Sep 17 00:00:00 2001 From: ThomasBreuer Date: Fri, 11 Oct 2024 16:02:56 +0200 Subject: [PATCH 1/2] allow `==` for two groups/group elements in fewer cases If `_check_compatible` for the two groups in question returns `false` then throw an exception. Note that the result is not based only on the types of the arguments but also on the groups. --- src/Groups/GAPGroups.jl | 21 +++++++++++++++++++-- test/Groups/conformance.jl | 4 ++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/Groups/GAPGroups.jl b/src/Groups/GAPGroups.jl index b71cbaf8509a..2475d290d111 100644 --- a/src/Groups/GAPGroups.jl +++ b/src/Groups/GAPGroups.jl @@ -372,9 +372,26 @@ end Base.:*(x::GAPGroupElem, y::GAPGroupElem) = _prod(x, y) -==(x::GAPGroup, y::GAPGroup) = GapObj(x) == GapObj(y) +function ==(x::GAPGroup, y::GAPGroup) + _check_compatible(x, y; error = false) || throw(ArgumentError("x and y are not compatible")) + return GapObj(x) == GapObj(y) +end + +# For two `BasicGAPGroupElem`s, +# we allow the question for equality if their parents fit together +# in the sense of `_check_compatible`, +# and compare the `GapObj`s if this is the case. +function ==(x::BasicGAPGroupElem, y::BasicGAPGroupElem) + _check_compatible(parent(x), parent(y); error = false) || throw(ArgumentError("parents of x and y are not compatible")) + return GapObj(x) == GapObj(y) +end -==(x::BasicGAPGroupElem, y::BasicGAPGroupElem ) = GapObj(x) == GapObj(y) +# For two `GAPGroupElem`s, +# if no specialized method is applicable then no `==` comparison is allowed. +function ==(x::GAPGroupElem, y::GAPGroupElem) + _check_compatible(parent(x), parent(y); error = false) || throw(ArgumentError("parents of x and y are not compatible")) + throw(ArgumentError("== is not implemented for the given types")) +end """ one(G::GAPGroup) -> elem_type(G) diff --git a/test/Groups/conformance.jl b/test/Groups/conformance.jl index e92c09bf2530..dbbc4ceed9f9 100644 --- a/test/Groups/conformance.jl +++ b/test/Groups/conformance.jl @@ -60,6 +60,10 @@ include(joinpath(dirname(pathof(AbstractAlgebra)), "..", "test", "Groups-conform @test g>h || g==h || g Date: Fri, 11 Oct 2024 17:19:40 +0200 Subject: [PATCH 2/2] address a comment --- src/Groups/GAPGroups.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Groups/GAPGroups.jl b/src/Groups/GAPGroups.jl index 2475d290d111..68152aa1ddf6 100644 --- a/src/Groups/GAPGroups.jl +++ b/src/Groups/GAPGroups.jl @@ -373,7 +373,7 @@ end Base.:*(x::GAPGroupElem, y::GAPGroupElem) = _prod(x, y) function ==(x::GAPGroup, y::GAPGroup) - _check_compatible(x, y; error = false) || throw(ArgumentError("x and y are not compatible")) + _check_compatible(x, y) return GapObj(x) == GapObj(y) end @@ -382,7 +382,7 @@ end # in the sense of `_check_compatible`, # and compare the `GapObj`s if this is the case. function ==(x::BasicGAPGroupElem, y::BasicGAPGroupElem) - _check_compatible(parent(x), parent(y); error = false) || throw(ArgumentError("parents of x and y are not compatible")) + _check_compatible(parent(x), parent(y)) return GapObj(x) == GapObj(y) end