Skip to content

Commit

Permalink
allow == for two groups/group elements in fewer cases
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ThomasBreuer committed Oct 11, 2024
1 parent 5c9a47e commit 7a20ddf
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/Groups/GAPGroups.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions test/Groups/conformance.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ include(joinpath(dirname(pathof(AbstractAlgebra)), "..", "test", "Groups-conform
@test g>h || g==h || g<h
@test isequal(g,h) || isless(g,h) || isless(h,g)
end

F = free_group(1)
@test_throws ArgumentError F == G
@test_throws ArgumentError gen(F, 1) == g
end

@testset "Group operations" begin
Expand Down

0 comments on commit 7a20ddf

Please sign in to comment.