Skip to content

Commit

Permalink
ENHANCE: RandomUnimodularMat allows for option of entry range
Browse files Browse the repository at this point in the history
as Random(Integers) only selects from [-10..10].
  • Loading branch information
hulpke committed Jan 21, 2020
1 parent d35e37f commit b896eb2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 2 additions & 0 deletions lib/matrix.gd
Original file line number Diff line number Diff line change
Expand Up @@ -1734,6 +1734,8 @@ DeclareGlobalFunction( "RandomMat" );
## returns a new random mutable <A>m</A><M>\times</M><A>m</A> matrix with integer
## entries that is invertible over the integers.
## Optionally, a random source <A>rs</A> can be supplied.
## If the option <A>domain</A> is given, random seection is made from <A>domain</A>, otherwise
## from <A>Integers</A>
## <Example><![CDATA[
## gap> m := RandomUnimodularMat(3);
## [ [ -5, 1, 0 ], [ 12, -2, -1 ], [ -14, 3, 0 ] ]
Expand Down
15 changes: 10 additions & 5 deletions lib/matrix.gi
Original file line number Diff line number Diff line change
Expand Up @@ -3593,8 +3593,13 @@ end );
#F RandomUnimodularMat( [rs ,] <m> ) . . . . . . . random unimodular matrix
##
InstallGlobalFunction( RandomUnimodularMat, function ( arg )
local rs, m, mat, c, i, j, k, l, a, b, v, w, gcd;
local rs, m, mat, c, i, j, k, l, a, b, v, w, gcd,dom;

dom:=ValueOption("domain");
if dom=fail or dom=false then
dom:=Integers;
fi;

if Length(arg) >= 1 and IsRandomSource(arg[1]) then
rs := Remove(arg, 1);
else
Expand Down Expand Up @@ -3626,8 +3631,8 @@ InstallGlobalFunction( RandomUnimodularMat, function ( arg )
j := Random(rs, 1, m);
until j <> i;
repeat
a := Random( rs, Integers );
b := Random( rs, Integers );
a := Random( rs, dom );
b := Random( rs, dom );
gcd := Gcdex( a, b );
until gcd.gcd = 1;
v := mat[i]; w := mat[j];
Expand All @@ -3640,8 +3645,8 @@ InstallGlobalFunction( RandomUnimodularMat, function ( arg )
l := Random(rs, 1, m);
until l <> k;
repeat
a := Random( rs, Integers );
b := Random( rs, Integers );
a := Random( rs, dom );
b := Random( rs, dom );
gcd := Gcdex( a, b );
until gcd.gcd = 1;
for i in [1..m] do
Expand Down

0 comments on commit b896eb2

Please sign in to comment.