File: random.gi

package info (click to toggle)
gap-sonata 2.9.1%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 16,076 kB
  • sloc: makefile: 25; sh: 24
file content (81 lines) | stat: -rw-r--r-- 2,031 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#############################################################################
##
#F  RandomClosure( <G>, <fam>, <e> )
##
##	<G>: group the nearring is acting on as a transformation nearring
##	<fam>: the family of the elements of the nearring
##	<e>: a record with the components
##		p : the result has probability 1/p to be incorrect
##		size : if the size of the nearring is known it can
##			be given to the function which produces a
##			correct result in this case
##
##	Note: only one of p and size has to be set via the function
##		SetErrorProbability

RandomClosure := function ( group, fam, e )
local i, m, badp, p, size, addGens;

  if IsBound( e.size ) then
	size := e.size;
	p := 10^100;
  else
	size := Size(fam!.group)^Size(fam!.group);
	p := e.p;
  fi;

  Info( InfoNearRing, 2, "actual size: ",Size(group) );

  addGens := GeneratorsOfGroup( group );
  i := 0; 
  badp := Length(addGens)/(Length(addGens)-1);
  while badp^i < p  and Size(group) < size do
#    Print("->",QuotientRemainder(NumeratorRat(badp^i),DenominatorRat(badp^i))[1],"\n");
    i := i + 1;
    Info( InfoNearRing, 2, "pass: ", i );
    m := GroupElementRepOfNearRingElement(
	NearRingElementByGroupRep( fam, Random(group) ) *
	NearRingElementByGroupRep( fam, Random( GeneratorsOfGroup(group) ) )
    );
    if not m in group then
	return RandomClosure( ClosureGroup( group, m ), fam, e );
    fi;
  od;

  return group;
end;

#############################################################################
##
#M  GroupReduct( <TfmNR> )		random method
##

InstallMethod(
	GroupReduct,
	"random",
	true,
	[IsNearRing and IsTransformationNearRing and HasErrorProbability],
	0,
  function ( nr )
  local addGroup, id;

  if ErrorProbability( nr ) = 0 then
	TryNextMethod();
  fi;

  id := GroupElementRepOfNearRingElement( GeneratorsOfNearRing(nr)[1] )^0;
  addGroup := Group( List( GeneratorsOfNearRing(nr), GroupElementRepOfNearRingElement ), id );

  return RandomClosure( addGroup, nr!.elementsInfo, ErrorProbability( nr ) );
  end );