diff --git a/src/GrpAb/GrpAbFinGen.jl b/src/GrpAb/GrpAbFinGen.jl index 3d5b350770..eb66476f9c 100644 --- a/src/GrpAb/GrpAbFinGen.jl +++ b/src/GrpAb/GrpAbFinGen.jl @@ -606,6 +606,14 @@ function is_isomorphic(G::FinGenAbGroup, H::FinGenAbGroup) return elementary_divisors(G) == elementary_divisors(H) end +function isomorphism(G::FinGenAbGroup, H::FinGenAbGroup) + SG, SGtoG = snf(G) + SH, SHtoH = snf(H) + @req SG.snf == SH.snf "Groups are not isomorphic" + h = hom(SG, SH, gens(SH)) + return inv(SGtoG) * h * SHtoH +end + ################################################################################ # # Direct products/direct sums/biproducts diff --git a/test/GrpAb/GrpAbFinGen.jl b/test/GrpAb/GrpAbFinGen.jl index 3e93fefd96..61dd2baf85 100644 --- a/test/GrpAb/GrpAbFinGen.jl +++ b/test/GrpAb/GrpAbFinGen.jl @@ -176,10 +176,18 @@ @testset "Isomorphism" begin b = @inferred is_isomorphic(abelian_group(Int[]), abelian_group(Int[])) @test b + h = isomorphism(abelian_group(Int[]), abelian_group(Int[])) + @test is_bijective(h) G = abelian_group([2, 3, 5]) H = abelian_group([30]) @test @inferred is_isomorphic(G, H) + + h = isomorphism(G, H) + @test is_bijective(h) + + K = abelian_group([2, 3]) + @test_throws ArgumentError isomorphism(G, K) end @testset "Direct product" begin