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 committed Dec 5, 2017
1 parent 4589cd2 commit c8d4de9
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
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 := r![1] / GcdInt( r![1], m );
fi;
return ZmodnZObj( FamilyObj( r ), n );
end );


#############################################################################
Expand Down
12 changes: 12 additions & 0 deletions tst/testinstall/zmodnz.tst
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,18 @@ ZmodnZObj( 4, 10 )
gap> Random(GlobalRandomSource, R);
ZmodnZObj( 9, 10 )
# test StandardAssociate
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> STOP_TEST( "zmodnz.tst", 1);
Expand Down

0 comments on commit c8d4de9

Please sign in to comment.