File: kernels.gi

package info (click to toggle)
gap-polycyclic 2.17-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 2,796 kB
  • sloc: xml: 3,018; javascript: 155; makefile: 124
file content (352 lines) | stat: -rw-r--r-- 10,447 bytes parent folder | download
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
#############################################################################
##
#W  kernels.gi                   Polycyc                         Bettina Eick
##

#############################################################################
##
#F  InducedByPcp( pcpG, pcpU, actG )
##
BindGlobal( "InducedByPcp", function( pcpG, pcpU, actG )
    if IsMultiplicativeElement( pcpU ) then
        return MappedVector( ExponentsByPcp( pcpG, pcpU ), actG );
    fi;
    if AsList(pcpU) = AsList(pcpG) then
        return actG;
    else
        return List(pcpU, x-> MappedVector(ExponentsByPcp(pcpG,x),actG));
    fi;
end );

#############################################################################
##
#W KernelOfFiniteMatrixAction( G, mats, f )
##
BindGlobal( "KernelOfFiniteMatrixAction", function( G, mats, f )
    local d, I, U, i, actU, stab;

    if Length( mats ) = 0 then return G; fi;
    d := Length( mats[1] );
    I := IdentityMat( d, f );

    # loop over basis and stabilize each point
    U := G;
    for i in [1..d] do
        actU := InducedByPcp( Pcp(G), Pcp(U), mats );
        stab := PcpOrbitStabilizer( I[i], Pcp(U), actU, OnRight );
        U := SubgroupByIgs( G, stab.stab );
    od;

    # that's it
    return U;
end );

#############################################################################
##
#W KernelOfFiniteAction( G, pcp )
##
## If pcp defines an elementary abelian layer, then we compute the kernel
## of the action of G. If pcp is free abelian, then we compute the kernel
## of the action mod 3.
##
BindGlobal( "KernelOfFiniteAction", function( G, pcp )
    local rels, p, f, pcpG, actG;

    # get the char and the field
    rels := RelativeOrdersOfPcp( pcp );
    p := rels[1];
    if p = 0 then p := 3; fi;
    f := GF(p);

    # get the action of G on pcp
    pcpG := Pcp(G);
    actG := LinearActionOnPcp( pcpG, pcp );
    actG := InducedByField( actG, f );

    # centralize
    return KernelOfFiniteMatrixAction( G, actG, f );
end );

#############################################################################
##
#F RelationLatticeMod( gens, f )
##
BindGlobal( "RelationLatticeMod", function( gens, f )
    local mats, l, pcgs, free, r, defn, g, e, null, base, i;

    # induce to f
    mats := InducedByField( gens, f );
    l := Length( mats );

    # compute independent gens
    pcgs := BasePcgsByPcFFEMatrices( mats );
    free := FreeGensByBasePcgs( pcgs );
    r := Length( free.gens );
    if r = 0 then return IdentityMat(l); fi;

    # set up relation system
    defn := [];
    for g in mats do
        e := ExponentsByBasePcgs( pcgs, g );
        Add( defn, e * free.prei );
    od;

    # solve it mod relative orders
    null := NullspaceMatMod( defn, free.rels );

    # determine lattice basis
    base := NormalFormIntMat( null, 2 ).normal;
    base := Filtered( base, x -> PositionNonZero(x) <= l );

    ## do a temporary check
    #for i in [1..Length(base)] do
    #    if not MappedVector( base[i], mats ) = mats[1]^0 then
    #        Error("found non-relation");
    #    fi;
    #od;

    return base;
end );

#############################################################################
##
#F IsRelation( mats, rel ) . . . . . . . .check if rel is a relation for mats
##
BindGlobal( "IsRelation", function( mats, rel )
    local   M1,  M2,  i;
    M1 := mats[1]^0;
    M2 := mats[1]^0;
    for i in [1..Length(mats)] do
        if rel[i] > 0 then
            M1 := M1*mats[i]^rel[i];
        elif rel[i] < 0 then
            M2 := M2*mats[i]^-rel[i];
        fi;
    od;
    return M1 = M2;
end );

#############################################################################
##
#F ApproxRelationLattice( mats, k, p ). .  . . . . . . . k step approximation
##
BindGlobal( "ApproxRelationLattice", function( mats, k, p )
    local lat, i, new, ind, len;

    # set up
    lat := IdentityMat( Length(mats) );

    # compute new lattices and intersect
    for i in [1..k] do
        p := NextPrimeInt(p);
        new := RelationLatticeMod( mats, GF(p) );
        lat := LatticeIntersection( lat, new );
    od;

    # find short vectors
    lat := LLLReducedBasis( lat ).basis;

    # did we find any relations?
    for i in [1..Length(lat)] do
        if not IsRelation( mats, lat[i] ) then lat[i] := false; fi;
    od;
    return rec( rels := Filtered( lat, x -> not IsBool(x) ), prime := p );
end );

#############################################################################
##
#F VerifyIndependence( mats )
##
BindGlobal( "VerifyIndependence", function( mats )
    local base, prim, dixn, done, L, p, i, N, w, d;

    if Length( mats ) = 1 and mats[1] <> mats[1]^0 then return true; fi;

    Print("   verifying linear independence \n");
    base := AlgebraBase( mats );
    d := Length( base );
    Print("     got ", Length( mats ), " generators and dimension ", d,"\n");

    if Length( mats ) >= d then return false; fi;
    prim := PrimitiveAlgebraElement( mats, base );
    Print("     computing dixon bound \n");
    dixn := Length(mats[1]) * LogDixonBound( mats, prim )^2;
    Print("     found ", dixn, "\n");
    done := false;

    # set up
    L := IdentityMat( Length(mats) );
    p := 1;

    while not done do
        Print("     next step verification \n");

        # compute new lattices and intersect
        for i in [1..d] do
            p := NextPrimeInt(p);
            N := RelationLatticeMod( mats, GF(p) );
            L := LatticeIntersection( L, N );
        od;

        # find short vectors
        L := LLLReducedBasis( L ).basis;
        w := Minimum( List( L, x -> x * x ) );
        Print("     got shortest vector ", w, "\n");

        # check dixon bound
        if w > dixn then return true; fi;

        # check rels
        for i in [1..Length(L)] do
            if IsRelation( mats, L[i] ) then return false; fi;
        od;
    od;
end );

#############################################################################
##
#W KernelOfCongruenceMatrixActionGAP( G, mats )  . . G acts as ss cong subgrp
##
## Warning: G must be integral!
##
BindGlobal( "KernelOfCongruenceMatrixActionGAP", function( G, mats )
    local p, U, pcp, K, gens, acts, rell, tmps;

    # set up
    p := 1;
    U := DerivedSubgroup(G);
    pcp := Pcp( G );

    # now loop
    repeat
        K := U;
        gens := Pcp( G, K );
        acts := InducedByPcp( pcp, gens, mats );
        rell := ApproxRelationLattice( acts, Length(acts[1]), p );
        tmps := List( rell.rels, x -> MappedVector( x, gens ) );
        tmps := AddToIgs( DenominatorOfPcp( gens ), tmps );
        U := SubgroupByIgs( G, tmps );
        p := rell.prime;
    until Index( G, U ) = 1 or Index( U, K ) = 1;

    # verify if desired
    if Index( G, U ) > 1 and VERIFY@ then
        gens := Pcp( G, U );
        acts := InducedByPcp( pcp, gens, mats );
        if not VerifyIndependence( acts ) then
            Error("  generators are not linearly independent");
        fi;
    fi;

    # that's it
    return U;
end );

#############################################################################
##
#F KernelOfCongruenceMatrixActionALNUTH( G, mats ) . G acts as ss cong subgrp
##
BindGlobal( "KernelOfCongruenceMatrixActionALNUTH", function( G, mats )
    local H, base, prim, fact, full, f, s, h, imats, F, rels, gens;

    # the trivial case
    if ForAll( mats, x -> x^0 = x ) then return G; fi;

    # split into irreducibles
    base := AlgebraBase( mats );
    prim := PrimitiveAlgebraElement( base, List( base, Flat ) );
    fact := Factors( prim.poly );

    # catch the trivial case first - for increased efficiency
    if Length(fact) = 1 then
        F := FieldByMatricesNC( mats );
        SetPrimitiveElement( F, prim.elem );
        SetDefiningPolynomial( F, prim.poly );
        rels := RelationLatticeOfTFUnits( F, mats );
        return Subgroup( G, List( rels, x -> MappedVector( x, Pcp(G) ) ) );
    fi;

    # loop over subspaces
    full := mats[1]^0;
    gens := AsList( Pcp(G) );
    H := G;
    for f in fact do

        # induce matrices if necessary
        if Index( G, H ) > 1 then
            mats := List( rels, x -> MappedVector( x, mats ) );
            G := H;
        fi;

        # get subspace
        s := NullspaceRatMat( Value( f, prim.elem ) );
        h := NaturalHomomorphismBySemiEchelonBases( full, s );

        # induce to factor
        imats := List( mats, x -> InducedActionSubspaceByNHSEB( x, h ) );
        if ForAny( imats, x -> x <> x^0 ) then
            F := FieldByMatricesNC( mats );
            SetPrimitiveElement( F, prim.elem );
            SetDefiningPolynomial( F, prim.poly );

            # compute kernel
            rels := RelationLatticeOfTFUnits( F, imats );

            # set up for iteration
            gens := List( rels, x -> MappedVector( x, gens ) );
            H := Subgroup( G, gens );
        fi;
    od;

    # that's it
    return H;
end );

#############################################################################
##
#F KernelOfCongruenceMatrixAction( G, mats )  . . . . . . . . header function
##
BindGlobal( "KernelOfCongruenceMatrixAction", function( G, mats )
    if ForAll( mats, x -> x = x^0 ) then return G; fi;
    if USE_ALNUTH@ then
        return KernelOfCongruenceMatrixActionALNUTH( G, mats );
    else
        return KernelOfCongruenceMatrixActionGAP( G, mats );
    fi;
end );

#############################################################################
##
#F KernelOfCongruenceAction( G, pcp ) . . . . . . . .G acts as ss cong subgrp
##
BindGlobal( "KernelOfCongruenceAction", function( G, pcp )
    local mats;
    mats := LinearActionOnPcp( Pcp(G), pcp );
    return KernelOfCongruenceMatrixAction( G, mats );
end );

#############################################################################
##
#F MemberByCongruenceMatrixAction( G, mats, m ) . . G acts as irr cong subgrp
##
## So far, this works only if G is an integral group.
##
BindGlobal( "MemberByCongruenceMatrixAction", function( G, mats, m )
    local F, r, e;

    # get field
    F := FieldByMatricesNC( mats );

    # check whether m is a unit in F
    if not IsUnitOfNumberField( F, m ) then return false; fi;

    # check if m is in G
    r := RelationLatticeOfUnits( F, Concatenation( [m], mats ) )[1];
    if PositionNonZero( r ) > 1 or AbsInt( r[1] ) <> 1 then return false; fi;

    # now translate to G
    e := -r{[2..Length(r)]} * r[1];
    return MappedVector( e, Pcp(G) );
end );