diff --git a/hpcgap/lib/zmodnz.gi b/hpcgap/lib/zmodnz.gi index 3005c6ad62..59dd3b0337 100644 --- a/hpcgap/lib/zmodnz.gi +++ b/hpcgap/lib/zmodnz.gi @@ -655,6 +655,39 @@ InstallMethod(ZOp, end); +############################################################################# +## +#M StandardAssociate( ) +## +InstallMethod( StandardAssociate, + "for full ring Z/nZ and an element in Z/nZ", + IsCollsElms, + [ IsZmodnZObjNonprimeCollection and IsWholeFamily and IsRing, IsZmodnZObj and IsModulusRep ], + function ( R, r ) + local m, n; + m := ModulusOfZmodnZObj( r ); + n := GcdInt( r![1], m ); + return ZmodnZObj( FamilyObj( r ), n ); + end ); + +############################################################################# +## +#M StandardAssociateUnit( ) +## +InstallMethod( StandardAssociateUnit, + "for full ring Z/nZ and an element in Z/nZ", + IsCollsElms, + [ IsZmodnZObjNonprimeCollection and IsWholeFamily and IsRing, IsZmodnZObj and IsModulusRep ], + function ( R, r ) + local m, n; + m := ModulusOfZmodnZObj( r ); + if r![1] = 0 then + n := 1; + else + n := QuotientMod(GcdInt( r![1], m ), r![1], m); + fi; + return ZmodnZObj( FamilyObj( r ), n ); + end ); ############################################################################# diff --git a/lib/zmodnz.gi b/lib/zmodnz.gi index 68b2114fec..3c29ed1ea8 100644 --- a/lib/zmodnz.gi +++ b/lib/zmodnz.gi @@ -655,6 +655,39 @@ InstallMethod(ZOp, end); +############################################################################# +## +#M StandardAssociate( ) +## +InstallMethod( StandardAssociate, + "for full ring Z/nZ and an element in Z/nZ", + IsCollsElms, + [ IsZmodnZObjNonprimeCollection and IsWholeFamily and IsRing, IsZmodnZObj and IsModulusRep ], + function ( R, r ) + local m, n; + m := ModulusOfZmodnZObj( r ); + n := GcdInt( r![1], m ); + return ZmodnZObj( FamilyObj( r ), n ); + end ); + +############################################################################# +## +#M StandardAssociateUnit( ) +## +InstallMethod( StandardAssociateUnit, + "for full ring Z/nZ and an element in Z/nZ", + IsCollsElms, + [ IsZmodnZObjNonprimeCollection and IsWholeFamily and IsRing, IsZmodnZObj and IsModulusRep ], + function ( R, r ) + local m, n; + m := ModulusOfZmodnZObj( r ); + if r![1] = 0 then + n := 1; + else + n := QuotientMod(GcdInt( r![1], m ), r![1], m); + fi; + return ZmodnZObj( FamilyObj( r ), n ); + end ); ############################################################################# diff --git a/tst/testinstall/zmodnz.tst b/tst/testinstall/zmodnz.tst index 711a178acf..06a0650e57 100644 --- a/tst/testinstall/zmodnz.tst +++ b/tst/testinstall/zmodnz.tst @@ -467,6 +467,47 @@ ZmodnZObj( 0, 10 ) gap> 3/y; fail +# test StandardAssociate +gap> checkCompatible := R -> ForAll(R, r -> StandardAssociateUnit(R,r) * r = StandardAssociate(R,r));; + +# +gap> R := Integers mod 4;; +gap> List(Elements(R), x -> Int(StandardAssociate(R, x))); +[ 0, 1, 2, 1 ] +gap> List(Elements(R), x -> Int(StandardAssociateUnit(R, x))); +[ 1, 1, 1, 3 ] + +# +gap> R := Integers mod 5;; +gap> List(Elements(R), x -> Int(StandardAssociate(R, x))); +[ 0, 1, 1, 1, 1 ] +gap> List(Elements(R), x -> Int(StandardAssociateUnit(R, x))); +[ 1, 1, 3, 4, 2 ] +gap> ForAll(R, r -> StandardAssociateUnit(R,r) * r = StandardAssociate(R,r)); +true + +# +gap> R := Integers mod 6;; +gap> List(Elements(R), x -> Int(StandardAssociate(R, x))); +[ 0, 1, 2, 3, 2, 1 ] +gap> List(Elements(R), x -> Int(StandardAssociateUnit(R, x))); +[ 1, 1, 1, 1, 2, 5 ] +gap> ForAll(R, r -> StandardAssociateUnit(R,r) * r = StandardAssociate(R,r)); +true + +# +gap> R := Integers mod 9;; +gap> List(Elements(R), x -> Int(StandardAssociate(R, x))); +[ 0, 1, 1, 3, 1, 1, 3, 1, 1 ] +gap> List(Elements(R), x -> Int(StandardAssociateUnit(R, x))); +[ 1, 1, 5, 1, 7, 2, 2, 4, 8 ] +gap> ForAll(R, r -> StandardAssociateUnit(R,r) * r = StandardAssociate(R,r)); +true + +# +gap> ForAll([1..100], m -> checkCompatible(Integers mod m)); +true + # gap> STOP_TEST( "zmodnz.tst", 1);