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 Aug 31, 2018
1 parent f2262d2 commit a88f230
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
10 changes: 8 additions & 2 deletions lib/matrix.gd
Original file line number Diff line number Diff line change
Expand Up @@ -1671,17 +1671,23 @@ DeclareGlobalFunction( "RandomMat" );
##
## <#GAPDoc Label="RandomUnimodularMat">
## <ManSection>
## <Func Name="RandomUnimodularMat" Arg='[rs ,] m'/>
## <Func Name="RandomUnimodularMat" Arg='[rs ,] m [:random:=d]'/>
##
## <Description>
## 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.
## Optionally, a random source <A>rs</A> can be supplied. If the
## option <C>random</C> is given, selection of random numbers is made from
## <A>d</A> (allowing for larger coefficients), otherwise from
## <Ref Var="Integers"/> (for which random selection is bounded).
## <Example><![CDATA[
## gap> m := RandomUnimodularMat(3);
## [ [ -5, 1, 0 ], [ 12, -2, -1 ], [ -14, 3, 0 ] ]
## gap> m^-1;
## [ [ -3, 0, 1 ], [ -14, 0, 5 ], [ -8, -1, 2 ] ]
## gap> m := RandomUnimodularMat(3:random:=[-100..100]);
## [ [ -2795335, 8733, 6466434 ], [ -19667053, 61444, 45495692 ],
## [ 37158478, -116088, -85958515 ] ]
## ]]></Example>
## </Description>
## </ManSection>
Expand Down
15 changes: 10 additions & 5 deletions lib/matrix.gi
Original file line number Diff line number Diff line change
Expand Up @@ -3651,8 +3651,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("random");
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 @@ -3684,8 +3689,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 @@ -3698,8 +3703,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 a88f230

Please sign in to comment.