File: group.cpp

package info (click to toggle)
regina-normal 7.4.1-1.1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 154,244 kB
  • sloc: cpp: 295,026; xml: 9,992; sh: 1,344; python: 1,225; perl: 616; ansic: 138; makefile: 26
file content (229 lines) | stat: -rw-r--r-- 9,857 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

/**************************************************************************
 *                                                                        *
 *  Regina - A Normal Surface Theory Calculator                           *
 *  Computational Engine                                                  *
 *                                                                        *
 *  Copyright (c) 1999-2025, Ben Burton                                   *
 *  For further details contact Ben Burton (bab@debian.org).              *
 *                                                                        *
 *  This program is free software; you can redistribute it and/or         *
 *  modify it under the terms of the GNU General Public License as        *
 *  published by the Free Software Foundation; either version 2 of the    *
 *  License, or (at your option) any later version.                       *
 *                                                                        *
 *  As an exception, when this program is distributed through (i) the     *
 *  App Store by Apple Inc.; (ii) the Mac App Store by Apple Inc.; or     *
 *  (iii) Google Play by Google Inc., then that store may impose any      *
 *  digital rights management, device limits and/or redistribution        *
 *  restrictions that are required by its terms of service.               *
 *                                                                        *
 *  This program is distributed in the hope that it will be useful, but   *
 *  WITHOUT ANY WARRANTY; without even the implied warranty of            *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
 *  General Public License for more details.                              *
 *                                                                        *
 *  You should have received a copy of the GNU General Public License     *
 *  along with this program. If not, see <https://www.gnu.org/licenses/>. *
 *                                                                        *
 **************************************************************************/

#include "link.h"

namespace regina {

GroupPresentation Link::internalGroup(bool flip, bool simplify) const {
    if (crossings_.empty()) {
        // This is a zero-crossing unlink.
        return { components_.size() };
    }

    // We have a non-zero number of crossings.
    // Build the Wirtinger presentation.
    //
    // We start with just the generators corresponding to sections of
    // the diagram that include crossings; we will pick up any additional
    // generators for zero-crossing unknot components when we traverse the
    // link shortly.
    GroupPresentation g(crossings_.size());

    // We will need to number the "segments" - contiguous sections of the link
    // that consist entirely of over-crossings (if flip is false), or entirely
    // of under-crossings (if flip is true).
    // Construct a map from arc IDs to segment IDs, by traversing each
    // component one at a time.
    FixedArray<size_t> strandToSegment(2 * crossings_.size());
    size_t currSegment = 0;

    // The kind of strand at which we start a new segment as we traverse.
    int breakAt = (flip ? 1 : 0);

    for (StrandRef comp : components_) {
        if (! comp) {
            // This is a zero-crossing unknot component.
            g.addGenerator();
            continue;
        }

        // Start our traversal of each component at the beginning of a segment.
        StrandRef start = comp;
        if (start.strand() != breakAt) {
            if (components_.size() == 1) {
                // Just jump immediately to the other strand at this crossing.
                start.jump();
            } else {
                // There is no guarantee that the other strand is part of the
                // same component.  Instead, walk along the component until we
                // find a viable starting point.
                StrandRef s = start;
                do {
                    ++s;
                } while (s.strand() != breakAt && s != start);

                start = s;

                // It is possible that we never found a good starting point.
                // This happens when the entire component is an knot with
                // no self-crossings that is overlaid above the diagram
                // (if flip is false) or under the diagram (if flip is true).
                //
                // How this affects us now is that the total number of
                // segments (i.e., the number of generators in our
                // group presentation) goes up by one.
                //
                // We will adjust this later.
            }
        }

        StrandRef s = start;
        do {
            strandToSegment[s.id()] = currSegment;
            ++s;
            if (s.strand() == breakAt) {
                // We just passed through a crossing that ended a segment.
                ++currSegment;
            }
        } while (s != start);

        if (start.strand() != breakAt) {
            // This is the scenario noted above where some component
            // consists entirely of a closed segment that never gets broken.
            // We need to make two adjustments:
            //
            // - increment currSegment, since we are about to move to a new
            //   component but we did not increment it at the end of the
            //   loop just now; and
            //
            // - increment the total number of group generators, since we
            //   based our original count on the number of crossings, which
            //   only counts those segments with start and end points.

            ++currSegment;
            g.addGenerator();
        }
    }

    // Now build the presentation.
    for (Crossing* c : crossings_) {
        GroupExpression exp;
        if (flip) {
            if (c->sign() < 0) {
                exp.addTermLast(strandToSegment[c->lower().id()], 1);
                exp.addTermLast(strandToSegment[c->upper().id()], 1);
                exp.addTermLast(strandToSegment[c->lower().id()], -1);
                exp.addTermLast(strandToSegment[c->upper().prev().id()], -1);
            } else {
                exp.addTermLast(strandToSegment[c->lower().id()], 1);
                exp.addTermLast(strandToSegment[c->upper().prev().id()], 1);
                exp.addTermLast(strandToSegment[c->lower().id()], -1);
                exp.addTermLast(strandToSegment[c->upper().id()], -1);
            }
        } else {
            if (c->sign() > 0) {
                exp.addTermLast(strandToSegment[c->upper().id()], 1);
                exp.addTermLast(strandToSegment[c->lower().id()], 1);
                exp.addTermLast(strandToSegment[c->upper().id()], -1);
                exp.addTermLast(strandToSegment[c->lower().prev().id()], -1);
            } else {
                exp.addTermLast(strandToSegment[c->upper().id()], 1);
                exp.addTermLast(strandToSegment[c->lower().prev().id()], 1);
                exp.addTermLast(strandToSegment[c->upper().id()], -1);
                exp.addTermLast(strandToSegment[c->lower().id()], -1);
            }
        }
        g.addRelation(std::move(exp));
    }

    if (simplify)
        g.simplify();
    return g;
}

GroupPresentation Link::internalExtendedGroup(bool flip, bool simplify) const {
    if (crossings_.empty()) {
        // This is a zero-crossing unlink.
        return { components_.size() + 1 };
    }

    // We have a non-zero number of crossings.
    // Build the Wirtinger-like presentation as given by Silver and Williams.
    //
    // For strand s, we use generator number s.id() + 1.
    // For the special generator x, we use generator number 0.
    // For zero-crossing unknot components, we use additional generators
    // beyond these indices (which will never appear in any relations).
    GroupPresentation g(2 * crossings_.size() + 1 + countTrivialComponents());

    for (Crossing* c : crossings_) {
        // The first relation is the same regardless of whether we flip.
        GroupExpression r1;
        if (c->sign() > 0) {
            r1.addTermLast(c->upper().id() + 1, 1);
            r1.addTermLast(c->lower().id() + 1, 1);
            r1.addTermLast(c->upper().prev().id() + 1, -1);
            r1.addTermLast(c->lower().prev().id() + 1, -1);
        } else {
            r1.addTermLast(c->upper().prev().id() + 1, 1);
            r1.addTermLast(c->lower().prev().id() + 1, 1);
            r1.addTermLast(c->upper().id() + 1, -1);
            r1.addTermLast(c->lower().id() + 1, -1);
        }
        g.addRelation(std::move(r1));

        // The second relation changes.
        GroupExpression r2;
        if (flip) {
            if (c->sign() > 0) {
                r2.addTermLast(c->lower().id() + 1, 1);
                r2.addTermLast(0, 1);
                r2.addTermLast(c->lower().prev().id() + 1, -1);
                r2.addTermLast(0, -1);
            } else {
                r2.addTermLast(c->lower().prev().id() + 1, 1);
                r2.addTermLast(0, 1);
                r2.addTermLast(c->lower().id() + 1, -1);
                r2.addTermLast(0, -1);
            }
        } else {
            if (c->sign() > 0) {
                r2.addTermLast(c->upper().prev().id() + 1, 1);
                r2.addTermLast(0, 1);
                r2.addTermLast(c->upper().id() + 1, -1);
                r2.addTermLast(0, -1);
            } else {
                r2.addTermLast(c->upper().id() + 1, 1);
                r2.addTermLast(0, 1);
                r2.addTermLast(c->upper().prev().id() + 1, -1);
                r2.addTermLast(0, -1);
            }
        }
        g.addRelation(std::move(r2));
    }

    if (simplify)
        g.simplify();
    return g;
}

} // namespace regina