-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathResChoice.mag
171 lines (153 loc) · 5.61 KB
/
ResChoice.mag
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
declare type PGGAlg_ResChoice: PGGAlg;
declare type PGGAlg_ResChoice_Tranche: PGGAlg_ResChoice;
declare attributes PGGAlg_ResChoice_Tranche: tranche_alg, priority;
declare type PGGAlg_ResChoice_Stream: PGGAlg_ResChoice;
declare attributes PGGAlg_ResChoice_Stream: stream_alg, limit;
declare type PGGAlgState_ResChoice: PGGAlgState;
declare attributes PGGAlgState_ResChoice: parent;
declare type PGGAlgState_ResChoice_Tranche: PGGAlgState_ResChoice;
declare attributes PGGAlgState_ResChoice_Tranche: tranche_state, overgroup;
declare type PGGAlgState_ResChoice_Stream: PGGAlgState_ResChoice;
declare attributes PGGAlgState_ResChoice_Stream: stream_state, overgroup;
intrinsic PGGAlg_ResChoice_Tranche_Make(:Tranche:=false, Priority:=false) -> PGGAlg_ResChoice_Tranche
{The "Tranche" subgroups choice.}
alg := New(PGGAlg_ResChoice_Tranche);
alg`tranche_alg := Tranche cmpne false select Tranche else PGGAlg_Tranche_Index_Make();
alg`priority := Priority cmpne false select Priority else PGGAlg_ResPriority_Null_Make();
return alg;
end intrinsic;
intrinsic PGGAlg_ResChoice_Stream_Make(Stream :: PGGAlg_Stream : Limit:=false) -> PGGAlg_ResChoice_Stream
{The "Stream" subgroups choice.}
alg := New(PGGAlg_ResChoice_Stream);
alg`stream_alg := Stream;
alg`limit := Limit;
return alg;
end intrinsic;
intrinsic Print(alg :: PGGAlg_ResChoice_Tranche)
{Print.}
printf "tranche -> "; Print(alg`tranche_alg);
if Type(alg`priority) ne PGGAlg_ResPriority_Null then
print "";
IndentPush();
printf "priority = "; Print(alg`priority);
IndentPop();
end if;
end intrinsic;
intrinsic Print(alg :: PGGAlg_ResChoice_Stream)
{"}
printf "stream";
if alg`limit cmpne false then
printf " %o", alg`limit;
end if;
printf " -> ";
Print(alg`stream_alg);
end intrinsic;
intrinsic Start(alg :: PGGAlg_ResChoice_Tranche, parent :: PGGAlgState_ResGroups) -> PGGAlgState_ResChoice_Tranche
{Starts alg.}
s := New(PGGAlgState_ResChoice_Tranche);
s`algorithm := alg;
s`parent := parent;
s`overgroup := Group(parent`resolvent_overgroup);
s`tranche_state := Start(alg`tranche_alg, parent`resolvent_overgroup);
return s;
end intrinsic;
intrinsic Start(alg :: PGGAlg_ResChoice_Stream, parent :: PGGAlgState_ResGroups) -> PGGAlg_ResChoice_Stream
{"}
s := New(PGGAlgState_ResChoice_Stream);
s`algorithm := alg;
s`parent := parent;
s`overgroup := Group(parent`resolvent_overgroup);
s`stream_state := Start(alg`stream_alg, parent`resolvent_overgroup);
return s;
end intrinsic;
intrinsic Reset(s :: PGGAlgState_ResChoice_Tranche)
{Starts the choice from the beginning again.}
Reset(s`tranche_state);
end intrinsic;
intrinsic Reset(s :: PGGAlgState_ResChoice_Stream)
{"}
Reset(s`stream_state);
end intrinsic;
intrinsic Restart(alg :: PGGAlg_ResChoice, s :: PGGAlgState_ResChoice) -> PGGAlgState_ResChoice
{Like ``Start(alg, s`parent)`` but tries to preserve information.}
vprint PGG_GaloisGroup: "*** starting ResChoice algorithm from scratch:", alg;
return Start(alg, s`parent);
end intrinsic;
intrinsic Restart(alg :: PGGAlg_ResChoice_Tranche, s :: PGGAlgState_ResChoice_Tranche) -> PGGAlgState_ResChoice_Tranche
{"}
s`algorithm := alg;
s`tranche_state := Restart(alg`tranche_alg, s`tranche_state);
return s;
end intrinsic;
intrinsic Restart(alg :: PGGAlg_ResChoice_Stream, s :: PGGAlgState_ResChoice_Stream) -> PGGAlgState_ResChoice_Stream
{"}
s`algorithm := alg;
s`stream_state := Restart(alg`stream_alg, s`stream_state);
return s;
end intrinsic;
intrinsic HasSubgroup(s :: PGGAlgState_ResChoice_Tranche : NoForget:=false) -> BoolElt, GrpPerm
{Selects a subgroup.}
while true do
PGG_GlobalTimer_Push("tranche");
ok, tranche := HasTranche(s`tranche_state);
if not ok then
PGG_GlobalTimer_Pop();
return false, _;
end if;
assert #tranche gt 0;
vprint PGG_GaloisGroup: "#tranche =", #tranche;
PGG_GlobalTimer_Swap("prioritize");
tranche2 := Prioritize(PGG_ToIter(tranche), s`algorithm`priority, s`parent);
ok, i, j := FilterHasNext(tranche2, func<i | IsUseful(s`parent, i)>);
PGG_GlobalTimer_Pop();
if ok then
vprint PGG_GaloisGroup: "using tranche item", j;
if not NoForget then
Forget(i);
end if;
return true, Group(i);
end if;
end while;
end intrinsic;
intrinsic HasSubgroup(s :: PGGAlgState_ResChoice_Stream) -> BoolElt, GrpPerm
{"}
maxtries := s`algorithm`limit cmpeq false select Infinity() else s`algorithm`limit;
ntries := 0;
while true do
if ntries lt maxtries then
// get a group
PGG_GlobalTimer_Push("next group");
ok, group := HasNextGroup(s`stream_state);
PGG_GlobalTimer_Pop();
else
ok := false;
end if;
if ok then
ntries +:= 1;
// if useful, we are done
PGG_GlobalTimer_Push("useful");
ok := IsUseful(s`parent, group);
PGG_GlobalTimer_Pop();
if ok then
vprint PGG_GaloisGroup: "using item #", ntries;
return true, group;
end if;
else
ntries := 0;
// move on to the next stream
if not HasNextStream(s`stream_state) then
return false, _;
end if;
end if;
end while;
end intrinsic;
intrinsic Subgroup(s :: PGGAlgState_ResChoice) -> GrpPerm
{The next subgroup.}
ok, G := HasSubgroup(s);
error if not ok, "ran out of subgroups";
return G;
end intrinsic;
intrinsic MarkSpecial(s :: PGGAlgState_ResChoice_Tranche)
{Marks the current state of s as "special".}
MarkSpecialTranche(s`tranche_state);
end intrinsic;