diff --git a/src/GrpAb/SubgroupEnum.jl b/src/GrpAb/SubgroupEnum.jl index a3d93c100d..d3d8726449 100644 --- a/src/GrpAb/SubgroupEnum.jl +++ b/src/GrpAb/SubgroupEnum.jl @@ -875,6 +875,13 @@ end # Same as above but now allow a function to be applied to the output function _subgroups(G::FinGenAbGroup; subtype = [-1], quotype = [-1], order = -1, index = -1, fun = sub) + if !is_divisible_by(Hecke.order(G), order) || # the -1 default is ok + !is_divisible_by(Hecke.order(G), index) || + (subtype != [-1] && !has_quotient(G, subtype)) || + (quotype != [-1] && !has_quotient(G, quotype)) + return () + end + return ( fun(G, convert(Vector{FinGenAbGroupElem}, z)) for z in _subgroups_gens(G, subtype, quotype, order, index)) end @@ -919,14 +926,6 @@ function subgroups(G::FinGenAbGroup; subtype = :all, options = Int16[ subtype != :all, quotype != :all, order != -1, index != -1] - if mod(Hecke.order(G), index) != 0 - error("Index must divide the group order") - end - - if mod(Hecke.order(G), order) != 0 - error("Index must divide the group order") - end - if sum(options) > 1 error("Currently only one non-default parameter is supported.") end diff --git a/test/GrpAb/SubgroupEnum.jl b/test/GrpAb/SubgroupEnum.jl index 7fbee0d149..e3b3738021 100644 --- a/test/GrpAb/SubgroupEnum.jl +++ b/test/GrpAb/SubgroupEnum.jl @@ -220,4 +220,12 @@ @test all([order(t[1]) == 7*3 for t in T]) end end + + # test for no subgroups + + G = abelian_group([9, 3, 3]) + @test length(collect(subgroups(G; index = 2))) == 0 + @test length(collect(subgroups(G; order = 10001323))) == 0 + @test length(collect(subgroups(G; subtype = [6, 6, 6]))) == 0 + @test length(collect(subgroups(G; quotype = [6, 6, 6]))) == 0 end