File: Intsect.gi

package info (click to toggle)
gap-fga 1.5.0-1
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 764 kB
  • sloc: xml: 523; javascript: 155; makefile: 106
file content (194 lines) | stat: -rw-r--r-- 5,891 bytes parent folder | download | duplicates (2)
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
#############################################################################
##  
#W Intsect.gi                  FGA package                  Christian Sievers
##
## Installations for the computation of intersections of free groups
##
#Y 2003 - 2012
##


#############################################################################
##
#F  FGA_StateTable( <table>, <i>, <j> )
##
InstallGlobalFunction( FGA_StateTable,
    function( t, i, j )
    if not IsBound( t[i] ) then
        t[i] := [];
    fi;
    if not IsBound( t[i][j] ) then
        t[i][j] := FGA_newstate();
    fi;
    return t[i][j];
    end );

#############################################################################
##
#M  Intersection2( <G1>, <G2> )
##
InstallMethod( Intersection2,
    "for subgroups of free groups",
    IsIdenticalObj,
    [ CanComputeWithInverseAutomaton, CanComputeWithInverseAutomaton ],
    function( G1, G2 )
    local A, t, sl1, sl2, i, nr1, nr2, Q, pair, g, q, q1, q2, bpd, bpdi;

    # let the gap lib handle this case:
    if IsSubgroupOfWholeGroupByQuotientRep( G1 ) and
       IsSubgroupOfWholeGroupByQuotientRep( G2 ) then
        TryNextMethod();
    fi;

    t := [];
    i := FGA_StateTable( t, 1, 1 );
    sl1 := FGA_States( FreeGroupAutomaton( G1 ) );
    sl2 := FGA_States( FreeGroupAutomaton( G2 ) );
    Q := [ [1,1] ];
    for pair in Q do
        q1 := sl1[ pair[1] ];
        q2 := sl2[ pair[2] ];
        q  := FGA_StateTable( t, pair[1], pair[2] );
        for g in Difference(
                   Intersection( BoundPositions( q1.delta ),
                                 BoundPositions( q2.delta ) ),
                   BoundPositions( q.delta ) ) do
            nr1 := q1.delta[g].nr;
            nr2 := q2.delta[g].nr;
            FGA_connectpos( q, FGA_StateTable( t, nr1, nr2 ), g );
            Add( Q, [ nr1, nr2 ] );
        od;

        for g in Difference(
                   Intersection( BoundPositions( q1.deltainv ),
                                 BoundPositions( q2.deltainv ) ),
                   BoundPositions( q.deltainv ) ) do
            nr1 := q1.deltainv[g].nr;
            nr2 := q2.deltainv[g].nr;
            FGA_connectpos( FGA_StateTable( t, nr1, nr2 ), q, g );
            Add( Q, [ nr1, nr2 ] );
        od;

        bpd  := BoundPositions( q.delta );
        bpdi := BoundPositions( q.deltainv );
        while Size( bpd ) + Size( bpdi ) = 1  and
              IsNotIdenticalObj( q, i ) do
            if Size( bpd ) = 1 then
                g := bpd[ 1 ];
                q := q.delta[ g ];
                Unbind( q.deltainv[ g ] );
            else
                g := bpdi[ 1 ];
                q := q.deltainv[ g ];
                Unbind( q.delta[ g ] );
            fi;
            bpd  := BoundPositions( q.delta );
            bpdi := BoundPositions( q.deltainv );
        od;
    od;
    A := Objectify( NewType( FamilyObj( G1 ), IsSimpleInvAutomatonRep ),
                    rec( initial:=i, terminal:=i, 
                         group := TrivialSubgroup( G1 ) ) );
    return AsGroup( A );
    end );


#############################################################################
##
#F  FGA_TrySetRepTable( <t>, <i>, <j>, <r>, <g> )
##
InstallGlobalFunction( FGA_TrySetRepTable,
    function( t, i, j, r, g )    
    local rx;
    if not IsBound( t[i] ) then
        t[i] := [];
    fi;
    if not IsBound( t[i][j] ) then
        rx := ShallowCopy( r );
        Add( rx, g );
        t[i][j] := rx;
        return rx;
    else
        return fail;
    fi;
    end );


#############################################################################
##
#F  FGA_GetNr ( <state>, <statelist> )
##
InstallGlobalFunction( FGA_GetNr,
    function( q, sl )
    if not IsBound( q.nr ) then
        Add( sl, q );
        q.nr := Size( sl );
    elif not IsBound( sl[ q.nr ] ) then
        sl[ q.nr ] := q;
    fi;
    return q.nr;
    end );

#############################################################################
##
#F  FGA_FindRepInIntersection ( <A1>, <t1>, <A2>, <t2> )
##
InstallGlobalFunction( FGA_FindRepInIntersection,
    function( A1, t1, A2, t2 )
    local tab, sl1, sl2, Q, pair, g, q1, nr1, q2, nr2, r, rx;
    sl1 := [];
    sl2 := [];
    q1 := A1!.initial;
    q2 := A2!.initial;
    if IsIdenticalObj( q1, t1) and
       IsIdenticalObj( q2, t2) then
        return [];
    fi;
    nr1 := FGA_GetNr( q1, sl1 );
    nr2 := FGA_GetNr( q2, sl2 );
    tab := [];
    tab [ nr1 ] := [];
    tab [ nr1 ][ nr2 ] := []; # empty word at initial state
    Q := [ [ nr1, nr2 ] ];
    for pair in Q do
        q1 := sl1[ pair[1] ];
        q2 := sl2[ pair[2] ];
        r  := tab [ pair[1] ] [ pair[2] ];
        for g in Intersection( BoundPositions( q1.delta ),
                               BoundPositions( q2.delta ) ) do
            nr1 := FGA_GetNr(q1.delta[g], sl1);
            nr2 := FGA_GetNr(q2.delta[g], sl2);
            rx := FGA_TrySetRepTable( tab, nr1, nr2, r, g );
            if rx <> fail then
                if IsIdenticalObj(sl1[ nr1 ], t1) and
                   IsIdenticalObj(sl2[ nr2 ], t2) then
                    return rx;
                fi;
                Add( Q, [ nr1, nr2 ] );
            fi;
        od;

        for g in Intersection( BoundPositions( q1.deltainv ),
                               BoundPositions( q2.deltainv ) ) do
            nr1 := FGA_GetNr(q1.deltainv[g], sl1);
            nr2 := FGA_GetNr(q2.deltainv[g], sl2);
            rx := FGA_TrySetRepTable( tab, nr1, nr2, r, -g );
            if rx <> fail then
                if IsIdenticalObj(sl1[ nr1 ], t1) and
                   IsIdenticalObj(sl2[ nr2 ], t2) then
                    return rx;
                fi;
                Add( Q, [ nr1, nr2 ] );
            fi;
        od;
    od;

    return fail;

    end );



#############################################################################
##
#E