Skip to content

Commit

Permalink
Add support for random sources for padic extensions families and pure…
Browse files Browse the repository at this point in the history
… padic families
  • Loading branch information
ChrisJefferson committed Jan 13, 2017
1 parent 08d7b1e commit c2c478d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
20 changes: 10 additions & 10 deletions lib/padics.gi
Original file line number Diff line number Diff line change
Expand Up @@ -480,17 +480,17 @@ end );
## may get two pure p-adic numbers that have no "digit" in common, so by
## adding them, one of the two vanishes.
##
InstallOtherMethod( Random,
InstallOtherMethodWithRandomSource( Random, "for a random source and a pure p-adic family",
true,
[ IsPurePadicNumberFamily ],
[ IsRandomSource, IsPurePadicNumberFamily ],
0,

function ( fam )
function ( rg, fam )
local c;

c := [];
c[1] := Random( -fam!.precision, fam!.precision );
c[2] := Random( 0, fam!.modulus-1 );
c[1] := Random( rg, -fam!.precision, fam!.precision );
c[2] := Random( rg, 0, fam!.modulus-1 );
while c[2] mod fam!.prime = 0 do
c[1] := c[1] + 1;
c[2] := c[2] / fam!.prime;
Expand Down Expand Up @@ -903,19 +903,19 @@ end );
## Again this is just something that returns an extended p-adic number. The
## p-part is not totally covered (just ranges from -precision to precision).
##
InstallOtherMethod( Random,
InstallOtherMethodWithRandomSource( Random, "for a random source and p-adic extension family",
true,
[ IsPadicExtensionNumberFamily ],
[ IsRandomSource, IsPadicExtensionNumberFamily ],
0,

function ( fam )
function ( rg, fam )
local c, l;

c := [];
c[1] := Random( -fam!.precision, fam!.precision );
c[1] := Random( rg, -fam!.precision, fam!.precision );
c[2] := [];
for l in [ 1 .. fam!.n ] do
c[2][l] := Random( 0, fam!.modulus-1 );
c[2][l] := Random( rg, 0, fam!.modulus-1 );
od;
while ForAll( c[2], x-> x mod fam!.prime = 0 ) do
c[1] := c[1] + 1;
Expand Down
2 changes: 2 additions & 0 deletions tst/testinstall/random.tst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ gap> Read( Filename( DirectoriesLibrary( "tst" ), "testrandom.g" ) );
gap> randomTest(Integers, Random);
gap> randomTest([1..10], Random);
gap> randomTest([1,-6,"cheese", Group(())], Random);
gap> randomTest(PadicExtensionNumberFamily(3, 5, [1,1,1], [1,1]), Random, function(x,y) return IsPadicExtensionNumber(x); end);
gap> randomTest(PurePadicNumberFamily(2,20), Random, function(x,y) return IsPurePadicNumber(x); end);
gap> STOP_TEST("random.tst", 1);

0 comments on commit c2c478d

Please sign in to comment.