Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix RandomUnimodularMat (revised) #1511

Merged
merged 4 commits into from
Jul 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/matrix.gi
Original file line number Diff line number Diff line change
Expand Up @@ -3577,10 +3577,18 @@ end );
##
InstallGlobalFunction( RandomUnimodularMat, function ( m )
local mat, c, i, j, k, l, a, b, v, w, gcd;

if not IsPosInt( m ) then
Error("<m> must be a positive integer");
fi;

# start with the identity matrix
mat := IdentityMat( m );

if m = 1 then
return Random( [ 1, -1 ] ) * mat;
fi;

for c in [1..m] do

# multiply two random rows with a random? unimodular 2x2 matrix
Expand Down Expand Up @@ -3609,7 +3617,6 @@ InstallGlobalFunction( RandomUnimodularMat, function ( m )
v := mat[i][k]; w := mat[i][l];
mat[i][k] := gcd.coeff1 * v + gcd.coeff2 * w;
mat[i][l] := gcd.coeff3 * v + gcd.coeff4 * w;
ConvertToVectorRepNC( mat[i] );
od;

od;
Expand Down
6 changes: 6 additions & 0 deletions tst/testinstall/opers/EmptyPlist.tst
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
gap> START_TEST("EmptyPlist.tst");

#
gap> EmptyPlist(-1);
Error, <len> must be a non-negative small integer
gap> EmptyPlist(-(2^100));
Expand All @@ -20,3 +23,6 @@ gap> l;
gap> l[12] := 2;;
gap> l;
[ ,,,, 5,,,,,,, 2 ]

#
gap> STOP_TEST("EmptyPlist.tst", 1);
6 changes: 6 additions & 0 deletions tst/testinstall/opers/ListBlist.tst
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
gap> START_TEST("ListBlist.tst");

#
gap> ListBlist([],[false,true]);
Error, ListBlist: <blist> must have the same length as <list> (0)
gap> ListBlist([],[1,2]);
Expand All @@ -12,3 +15,6 @@ gap> ListBlist([1..5],[false,true,false,true,false]);
[ 2, 4 ]
gap> ListBlist([1..5],[true,false,true,false,true]);
[ 1, 3, 5 ]

#
gap> STOP_TEST("ListBlist.tst", 1);
30 changes: 30 additions & 0 deletions tst/testinstall/opers/RandomUnimodularMat.tst
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
gap> START_TEST("RandomUnimodularMat.tst");

#
gap> for n in [1..10] do
> Print("Testing n = ", n, "\n");
> for i in [1..10] do
> M := RandomUnimodularMat( n );
> Assert(0, Length(M) = n);
> Assert(0, ForAll(M, row -> Length(row) = n));
> Assert(0, ForAll(M, row -> ForAll(row, x -> IsInt(x))));
> Assert(0, Determinant(M) in [1,-1]);
> od;
> od;
Testing n = 1
Testing n = 2
Testing n = 3
Testing n = 4
Testing n = 5
Testing n = 6
Testing n = 7
Testing n = 8
Testing n = 9
Testing n = 10

#
gap> RandomUnimodularMat(0);
Error, <m> must be a positive integer

#
gap> STOP_TEST("RandomUnimodularMat.tst", 1);