Skip to content

Commit

Permalink
Implement StandardAssociate(Unit) for ZmodnZ
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin authored and alex-konovalov committed Dec 18, 2017
1 parent a29ee9c commit f0b86fe
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 0 deletions.
33 changes: 33 additions & 0 deletions hpcgap/lib/zmodnz.gi
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,39 @@ InstallMethod(ZOp,
end);


#############################################################################
##
#M StandardAssociate( <r> )
##
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( <r> )
##
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 );


#############################################################################
Expand Down
33 changes: 33 additions & 0 deletions lib/zmodnz.gi
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,39 @@ InstallMethod(ZOp,
end);


#############################################################################
##
#M StandardAssociate( <r> )
##
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( <r> )
##
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 );


#############################################################################
Expand Down
41 changes: 41 additions & 0 deletions tst/testinstall/zmodnz.tst
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit f0b86fe

Please sign in to comment.