Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagelib
Path: blob/master/sage/homology/examples.py
4077 views
1
# -*- coding: utf-8 -*-
2
"""
3
Examples of simplicial complexes
4
5
AUTHORS:
6
7
- John H. Palmieri (2009-04)
8
9
This file constructs some examples of simplicial complexes. There are
10
two main types: manifolds and examples related to graph theory.
11
12
For manifolds, there are functions defining the `n`-sphere for any
13
`n`, the torus, `n`-dimensional real projective space for any `n`, the
14
complex projective plane, surfaces of arbitrary genus, and some other
15
manifolds, all as simplicial complexes.
16
17
Aside from surfaces, this file also provides some functions for
18
constructing some other simplicial complexes: the simplicial complex
19
of not-`i`-connected graphs on `n` vertices, the matching complex on n
20
vertices, and the chessboard complex for an `n` by `i` chessboard.
21
These provide examples of large simplicial complexes; for example,
22
``simplicial_complexes.NotIConnectedGraphs(7,2)`` has over a million
23
simplices.
24
25
All of these examples are accessible by typing
26
"simplicial_complexes.NAME", where "NAME" is the name of the example.
27
You can get a list by typing "simplicial_complexes." and hitting the
28
TAB key::
29
30
simplicial_complexes.ChessboardComplex
31
simplicial_complexes.ComplexProjectivePlane
32
simplicial_complexes.K3Surface
33
simplicial_complexes.KleinBottle
34
simplicial_complexes.MatchingComplex
35
simplicial_complexes.MooreSpace
36
simplicial_complexes.NotIConnectedGraphs
37
simplicial_complexes.PoincareHomologyThreeSphere
38
simplicial_complexes.RandomComplex
39
simplicial_complexes.RealProjectivePlane
40
simplicial_complexes.RealProjectiveSpace
41
simplicial_complexes.Simplex
42
simplicial_complexes.Sphere
43
simplicial_complexes.SurfaceOfGenus
44
simplicial_complexes.Torus
45
46
See the documentation for ``simplicial_complexes`` and for each
47
particular type of example for full details.
48
"""
49
50
from sage.homology.simplicial_complex import SimplicialComplex, Simplex
51
from sage.sets.set import Set
52
from sage.misc.functional import is_even
53
from sage.combinat.subset import Subsets
54
import sage.misc.prandom as random
55
56
def matching(A, B):
57
"""
58
List of maximal matchings between the sets A and B: a matching
59
is a set of pairs (a,b) in A x B where each a, b appears in at
60
most one pair. A maximal matching is one which is maximal
61
with respect to inclusion of subsets of A x B.
62
63
INPUT:
64
65
- ``A``, ``B`` - list, tuple, or indeed anything which can be
66
converted to a set.
67
68
EXAMPLES::
69
70
sage: from sage.homology.examples import matching
71
sage: matching([1,2], [3,4])
72
[set([(1, 3), (2, 4)]), set([(2, 3), (1, 4)])]
73
sage: matching([0,2], [0])
74
[set([(0, 0)]), set([(2, 0)])]
75
"""
76
answer = []
77
if len(A) == 0 or len(B) == 0:
78
return [set([])]
79
for v in A:
80
for w in B:
81
for M in matching(set(A).difference([v]), set(B).difference([w])):
82
new = M.union([(v,w)])
83
if new not in answer:
84
answer.append(new)
85
return answer
86
87
# for backwards compatibility:
88
SimplicialSurface = SimplicialComplex
89
90
class SimplicialComplexExamples():
91
"""
92
Some examples of simplicial complexes.
93
94
Here are the available examples; you can also type
95
"simplicial_complexes." and hit tab to get a list::
96
97
ChessboardComplex
98
ComplexProjectivePlane
99
K3Surface
100
KleinBottle
101
MatchingComplex
102
MooreSpace
103
NotIConnectedGraphs
104
PoincareHomologyThreeSphere
105
RandomComplex
106
RealProjectivePlane
107
RealProjectiveSpace
108
Simplex
109
Sphere
110
SurfaceOfGenus
111
Torus
112
113
EXAMPLES::
114
115
sage: S = simplicial_complexes.Sphere(2) # the 2-sphere
116
sage: S.homology()
117
{0: 0, 1: 0, 2: Z}
118
sage: simplicial_complexes.SurfaceOfGenus(3)
119
Simplicial complex with 15 vertices and 38 facets
120
sage: M4 = simplicial_complexes.MooreSpace(4)
121
sage: M4.homology()
122
{0: 0, 1: C4, 2: 0}
123
sage: simplicial_complexes.MatchingComplex(6).homology()
124
{0: 0, 1: Z^16, 2: 0}
125
"""
126
127
def Sphere(self,n):
128
"""
129
A minimal triangulation of the n-dimensional sphere.
130
131
INPUT:
132
133
- ``n`` - positive integer
134
135
EXAMPLES::
136
137
sage: simplicial_complexes.Sphere(2)
138
Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 2, 3), (0, 1, 2), (1, 2, 3), (0, 1, 3)}
139
sage: simplicial_complexes.Sphere(5).homology()
140
{0: 0, 1: 0, 2: 0, 3: 0, 4: 0, 5: Z}
141
sage: [simplicial_complexes.Sphere(n).euler_characteristic() for n in range(6)]
142
[2, 0, 2, 0, 2, 0]
143
sage: [simplicial_complexes.Sphere(n).f_vector() for n in range(6)]
144
[[1, 2],
145
[1, 3, 3],
146
[1, 4, 6, 4],
147
[1, 5, 10, 10, 5],
148
[1, 6, 15, 20, 15, 6],
149
[1, 7, 21, 35, 35, 21, 7]]
150
"""
151
S = Simplex(n+1)
152
facets = S.faces()
153
S = SimplicialComplex(n+1, facets)
154
return S
155
156
def Simplex(self, n):
157
"""
158
An `n`-dimensional simplex, as a simplicial complex.
159
160
INPUT:
161
162
- ``n`` - a non-negative integer
163
164
OUTPUT: the simplicial complex consisting of the `n`-simplex
165
on vertices `(0, 1, ..., n)` and all of its faces.
166
167
EXAMPLES::
168
169
sage: simplicial_complexes.Simplex(3)
170
Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 1, 2, 3)}
171
sage: simplicial_complexes.Simplex(5).euler_characteristic()
172
1
173
"""
174
S = Simplex(n)
175
return SimplicialComplex(n, list(S))
176
177
178
def Torus(self):
179
"""
180
A minimal triangulation of the torus.
181
182
EXAMPLES::
183
184
sage: simplicial_complexes.Torus().homology(1)
185
Z x Z
186
"""
187
return SimplicialComplex(6, [[0,1,2], [1,2,4], [1,3,4], [1,3,6],
188
[0,1,5], [1,5,6], [2,3,5], [2,4,5],
189
[2,3,6], [0,2,6], [0,3,4], [0,3,5],
190
[4,5,6], [0,4,6]])
191
192
def RealProjectivePlane(self):
193
"""
194
A minimal triangulation of the real projective plane.
195
196
EXAMPLES::
197
198
sage: P = simplicial_complexes.RealProjectivePlane()
199
sage: Q = simplicial_complexes.ProjectivePlane()
200
sage: P == Q
201
True
202
sage: P.cohomology(1)
203
0
204
sage: P.cohomology(2)
205
C2
206
sage: P.cohomology(1, base_ring=GF(2))
207
Vector space of dimension 1 over Finite Field of size 2
208
sage: P.cohomology(2, base_ring=GF(2))
209
Vector space of dimension 1 over Finite Field of size 2
210
"""
211
return SimplicialComplex(5, [[0,1,2], [0,2,3], [0,1,5], [0,4,5],
212
[0,3,4], [1,2,4], [1,3,4], [1,3,5],
213
[2,3,5], [2,4,5]])
214
215
ProjectivePlane = RealProjectivePlane
216
217
def KleinBottle(self):
218
"""
219
A triangulation of the Klein bottle, formed by taking the
220
connected sum of a real projective plane with itself. (This is not
221
a minimal triangulation.)
222
223
EXAMPLES::
224
225
sage: simplicial_complexes.KleinBottle()
226
Simplicial complex with 9 vertices and 18 facets
227
"""
228
P = simplicial_complexes.RealProjectivePlane()
229
return P.connected_sum(P)
230
231
def SurfaceOfGenus(self, g, orientable=True):
232
"""
233
A surface of genus g.
234
235
INPUT:
236
237
- ``g`` - a non-negative integer. The desired genus
238
239
- ``orientable`` - boolean (optional, default True). If True,
240
return an orientable surface, and if False, return a
241
non-orientable surface.
242
243
In the orientable case, return a sphere if `g` is zero, and
244
otherwise return a `g`-fold connected sum of a torus with
245
itself.
246
247
In the non-orientable case, raise an error if `g` is zero. If
248
`g` is positive, return a `g`-fold connected sum of a
249
real projective plane with itself.
250
251
EXAMPLES::
252
253
sage: simplicial_complexes.SurfaceOfGenus(2)
254
Simplicial complex with 11 vertices and 26 facets
255
sage: simplicial_complexes.SurfaceOfGenus(1, orientable=False)
256
Simplicial complex with vertex set (0, 1, 2, 3, 4, 5) and 10 facets
257
"""
258
if g == 0:
259
if not orientable:
260
raise ValueError, "No non-orientable surface of genus zero."
261
else:
262
return simplicial_complexes.Sphere(2)
263
if orientable:
264
T = simplicial_complexes.Torus()
265
else:
266
T = simplicial_complexes.RealProjectivePlane()
267
S = T
268
for i in range(g-1):
269
S = S.connected_sum(T)
270
return S
271
272
def MooreSpace(self, q):
273
"""
274
Triangulation of the mod q Moore space.
275
276
INPUT:
277
278
- ``q`` - integer, at least 2
279
280
This is a simplicial complex with simplices of dimension 0, 1,
281
and 2, such that its reduced homology is isomorphic to
282
`\\ZZ/q\\ZZ` in dimension 1, zero otherwise.
283
284
If `q=2`, this is the real projective plane. If `q>2`, then
285
construct it as follows: start with a triangle with vertices
286
1, 2, 3. We take a `3q`-gon forming a `q`-fold cover of the
287
triangle, and we form the resulting complex as an
288
identification space of the `3q`-gon. To triangulate this
289
identification space, put `q` vertices `A_0`, ..., `A_{q-1}`,
290
in the interior, each of which is connected to 1, 2, 3 (two
291
facets each: `[1, 2, A_i]`, `[2, 3, A_i]`). Put `q` more
292
vertices in the interior: `B_0`, ..., `B_{q-1}`, with facets
293
`[3, 1, B_i]`, `[3, B_i, A_i]`, `[1, B_i, A_{i+1}]`, `[B_i,
294
A_i, A_{i+1}]`. Then triangulate the interior polygon with
295
vertices `A_0`, `A_1`, ..., `A_{q-1}`.
296
297
EXAMPLES::
298
299
sage: simplicial_complexes.MooreSpace(3).homology()[1]
300
C3
301
sage: simplicial_complexes.MooreSpace(4).suspension().homology()[2]
302
C4
303
sage: simplicial_complexes.MooreSpace(8)
304
Simplicial complex with 19 vertices and 54 facets
305
"""
306
if q <= 1:
307
raise ValueError, "The mod q Moore space is only defined if q is at least 2"
308
if q == 2:
309
return simplicial_complexes.RealProjectivePlane()
310
vertices = [1, 2, 3]
311
facets = []
312
for i in range(q):
313
Ai = "A" + str(i)
314
Aiplus = "A" + str((i+1)%q)
315
Bi = "B" + str(i)
316
vertices.append(Ai)
317
vertices.append(Bi)
318
facets.append([1, 2, Ai])
319
facets.append([2, 3, Ai])
320
facets.append([3, 1, Bi])
321
facets.append([3, Bi, Ai])
322
facets.append([1, Bi, Aiplus])
323
facets.append([Bi, Ai, Aiplus])
324
for i in range(1, q-1):
325
Ai = "A" + str(i)
326
Aiplus = "A" + str((i+1)%q)
327
facets.append(["A0", Ai, Aiplus])
328
return SimplicialComplex(vertices, facets)
329
330
def ComplexProjectivePlane(self):
331
"""
332
A minimal triangulation of the complex projective plane.
333
334
This was constructed by Kühnel and Banchoff.
335
336
REFERENCES:
337
338
- W. Kühnel and T. F. Banchoff, "The 9-vertex complex
339
projective plane", Math. Intelligencer 5 (1983), no. 3,
340
11-22.
341
342
EXAMPLES::
343
344
sage: C = simplicial_complexes.ComplexProjectivePlane()
345
sage: C.f_vector()
346
[1, 9, 36, 84, 90, 36]
347
sage: C.homology(2)
348
Z
349
sage: C.homology(4)
350
Z
351
"""
352
return SimplicialComplex(
353
[[1, 2, 4, 5, 6], [2, 3, 5, 6, 4], [3, 1, 6, 4, 5],
354
[1, 2, 4, 5, 9], [2, 3, 5, 6, 7], [3, 1, 6, 4, 8],
355
[2, 3, 6, 4, 9], [3, 1, 4, 5, 7], [1, 2, 5, 6, 8],
356
[3, 1, 5, 6, 9], [1, 2, 6, 4, 7], [2, 3, 4, 5, 8],
357
[4, 5, 7, 8, 9], [5, 6, 8, 9, 7], [6, 4, 9, 7, 8],
358
[4, 5, 7, 8, 3], [5, 6, 8, 9, 1], [6, 4, 9, 7, 2],
359
[5, 6, 9, 7, 3], [6, 4, 7, 8, 1], [4, 5, 8, 9, 2],
360
[6, 4, 8, 9, 3], [4, 5, 9, 7, 1], [5, 6, 7, 8, 2],
361
[7, 8, 1, 2, 3], [8, 9, 2, 3, 1], [9, 7, 3, 1, 2],
362
[7, 8, 1, 2, 6], [8, 9, 2, 3, 4], [9, 7, 3, 1, 5],
363
[8, 9, 3, 1, 6], [9, 7, 1, 2, 4], [7, 8, 2, 3, 5],
364
[9, 7, 2, 3, 6], [7, 8, 3, 1, 4], [8, 9, 1, 2, 5]])
365
366
def PoincareHomologyThreeSphere(self):
367
"""
368
A triangulation of the Poincare homology 3-sphere.
369
370
This is a manifold whose integral homology is identical to the
371
ordinary 3-sphere, but it is not simply connected. The
372
triangulation given here has 16 vertices and is due to Björner
373
and Lutz.
374
375
REFERENCES:
376
377
- Anders Björner and Frank H. Lutz, "Simplicial manifolds,
378
bistellar flips and a 16-vertex triangulation of the
379
Poincaré homology 3-sphere", Experiment. Math. 9 (2000),
380
no. 2, 275-289.
381
382
EXAMPLES::
383
384
sage: S3 = simplicial_complexes.Sphere(3)
385
sage: Sigma3 = simplicial_complexes.PoincareHomologyThreeSphere()
386
sage: S3.homology() == Sigma3.homology()
387
True
388
"""
389
return SimplicialComplex(
390
[[1, 2, 4, 9], [1, 2, 4, 15], [1, 2, 6, 14], [1, 2, 6, 15],
391
[1, 2, 9, 14], [1, 3, 4, 12], [1, 3, 4, 15], [1, 3, 7, 10],
392
[1, 3, 7, 12], [1, 3, 10, 15], [1, 4, 9, 12], [1, 5, 6, 13],
393
[1, 5, 6, 14], [1, 5, 8, 11], [1, 5, 8, 13], [1, 5, 11, 14],
394
[1, 6, 13, 15], [1, 7, 8, 10], [1, 7, 8, 11], [1, 7, 11, 12],
395
[1, 8, 10, 13], [1, 9, 11, 12], [1, 9, 11, 14], [1, 10, 13, 15],
396
[2, 3, 5, 10], [2, 3, 5, 11], [2, 3, 7, 10], [2, 3, 7, 13],
397
[2, 3, 11, 13], [2, 4, 9, 13], [2, 4, 11, 13], [2, 4, 11, 15],
398
[2, 5, 8, 11], [2, 5, 8, 12], [2, 5, 10, 12], [2, 6, 10, 12],
399
[2, 6, 10, 14], [2, 6, 12, 15], [2, 7, 9, 13], [2, 7, 9, 14],
400
[2, 7, 10, 14], [2, 8, 11, 15], [2, 8, 12, 15], [3, 4, 5, 14],
401
[3, 4, 5, 15], [3, 4, 12, 14], [3, 5, 10, 15], [3, 5, 11, 14],
402
[3, 7, 12, 13], [3, 11, 13, 14], [3, 12, 13, 14], [4, 5, 6, 7],
403
[4, 5, 6, 14], [4, 5, 7, 15], [4, 6, 7, 11], [4, 6, 10, 11],
404
[4, 6, 10, 14], [4, 7, 11, 15], [4, 8, 9, 12], [4, 8, 9, 13],
405
[4, 8, 10, 13], [4, 8, 10, 14], [4, 8, 12, 14], [4, 10, 11, 13],
406
[5, 6, 7, 13], [5, 7, 9, 13], [5, 7, 9, 15], [5, 8, 9, 12],
407
[5, 8, 9, 13], [5, 9, 10, 12], [5, 9, 10, 15], [6, 7, 11, 12],
408
[6, 7, 12, 13], [6, 10, 11, 12], [6, 12, 13, 15], [7, 8, 10, 14],
409
[7, 8, 11, 15], [7, 8, 14, 15], [7, 9, 14, 15], [8, 12, 14, 15],
410
[9, 10, 11, 12], [9, 10, 11, 16], [9, 10, 15, 16], [9, 11, 14, 16],
411
[9, 14, 15, 16], [10, 11, 13, 16], [10, 13, 15, 16],
412
[11, 13, 14, 16], [12, 13, 14, 15], [13, 14, 15, 16]])
413
414
def RealProjectiveSpace(self, n):
415
r"""
416
A triangulation of `\Bold{R}P^n` for any `n \geq 0`.
417
418
INPUT:
419
420
- ``n`` - integer, the dimension of the real projective space
421
to construct
422
423
The first few cases are pretty trivial:
424
425
- `\Bold{R}P^0` is a point.
426
427
- `\Bold{R}P^1` is a circle, triangulated as the boundary of a
428
single 2-simplex.
429
430
- `\Bold{R}P^2` is the real projective plane, here given its
431
minimal triangulation with 6 vertices, 15 edges, and 10
432
triangles.
433
434
- `\Bold{R}P^3`: any triangulation has at least 11 vertices by
435
a result of Walkup; this function returns a
436
triangulation with 11 vertices, as given by Lutz.
437
438
- `\Bold{R}P^4`: any triangulation has at least 16 vertices by
439
a result of Walkup; this function returns a triangulation
440
with 16 vertices as given by Lutz; see also Datta, Example
441
3.12.
442
443
- `\Bold{R}P^n`: Lutz has found a triangulation of
444
`\Bold{R}P^5` with 24 vertices, but it does not seem to have
445
been published. Kühnel has described a triangulation of
446
`\Bold{R}P^n`, in general, with `2^{n+1}-1` vertices; see
447
also Datta, Example 3.21. This triangulation is presumably
448
not minimal, but it seems to be the best in the published
449
literature as of this writing. So this function returns it
450
when `n > 4`.
451
452
ALGORITHM: For `n < 4`, these are constructed explicitly by
453
listing the facets. For `n = 4`, this is constructed by
454
specifying 16 vertices, two facets, and a certain subgroup `G`
455
of the symmetric group `S_{16}`. Then the set of all facets
456
is the `G`-orbit of the two given facets.
457
458
For `n > 4`, the construction is as follows: let `S` denote
459
the simplicial complex structure on the `n`-sphere given by
460
the first barycentric subdivision of the boundary of an
461
`(n+1)`-simplex. This has a simplicial antipodal action: if
462
`V` denotes the vertices in the boundary of the simplex, then
463
the vertices in its barycentric subdivision `S` correspond to
464
nonempty proper subsets `U` of `V`, and the antipodal action
465
sends any subset `U` to its complement. One can show that
466
modding out by this action results in a triangulation for
467
`\Bold{R}P^n`. To find the facets in this triangulation, find
468
the facets in `S`. These are indentified in pairs to form
469
`\Bold{R}P^n`, so choose a representative from each pair: for
470
each facet in `S`, replace any vertex in `S` containing 0 with
471
its complement.
472
473
Of course these complexes increase in size pretty quickly as
474
`n` increases.
475
476
REFERENCES:
477
478
- Basudeb Datta, "Minimal triangulations of manifolds",
479
J. Indian Inst. Sci. 87 (2007), no. 4, 429-449.
480
481
- W. Kühnel, "Minimal triangulations of Kummer varieties",
482
Abh. Math. Sem. Univ. Hamburg 57 (1987), 7-20.
483
484
- Frank H. Lutz, "Triangulated Manifolds with Few Vertices:
485
Combinatorial Manifolds", preprint (2005),
486
arXiv:math/0506372.
487
488
- David W. Walkup, "The lower bound conjecture for 3- and
489
4-manifolds", Acta Math. 125 (1970), 75-107.
490
491
EXAMPLES::
492
493
sage: P3 = simplicial_complexes.RealProjectiveSpace(3)
494
sage: P3.f_vector()
495
[1, 11, 51, 80, 40]
496
sage: P3.homology()
497
{0: 0, 1: C2, 2: 0, 3: Z}
498
sage: P4 = simplicial_complexes.RealProjectiveSpace(4) # long time (2s on sage.math, 2011)
499
sage: P4.f_vector() # long time
500
[1, 16, 120, 330, 375, 150]
501
sage: P4.homology() # long time
502
{0: 0, 1: C2, 2: 0, 3: C2, 4: 0}
503
sage: P5 = simplicial_complexes.RealProjectiveSpace(5) # long time (40s on sage.math, 2011)
504
sage: P5.f_vector() # long time
505
[1, 63, 903, 4200, 8400, 7560, 2520]
506
507
The following computation can take a long time -- over half an
508
hour -- with Sage's default computation of homology groups,
509
but if you have CHomP installed, Sage will use that and the
510
computation should only take a second or two. (You can
511
download CHomP from http://chomp.rutgers.edu/, or you can
512
install it as a Sage package using "sage -i chomp"). ::
513
514
sage: P5.homology() # long time # optional - CHomP
515
{0: 0, 1: C2, 2: 0, 3: C2, 4: 0, 5: Z}
516
sage: simplicial_complexes.RealProjectiveSpace(2).dimension()
517
2
518
sage: P3.dimension()
519
3
520
sage: P4.dimension() # long time
521
4
522
sage: P5.dimension() # long time
523
5
524
"""
525
if n == 0:
526
return self.Simplex(0)
527
if n == 1:
528
return self.Sphere(1)
529
if n == 2:
530
return self.RealProjectivePlane()
531
if n == 3:
532
# Minimal triangulation found by Walkup and given
533
# explicitly by Lutz
534
return SimplicialComplex(
535
[[1, 2, 3, 7], [1, 4, 7, 9], [2, 3, 4, 8], [2, 5, 8, 10],
536
[3, 6, 7, 10], [1, 2, 3, 11], [1, 4, 7, 10], [2, 3, 4, 11],
537
[2, 5, 9, 10], [3, 6, 8, 9], [1, 2, 6, 9], [1, 4, 8, 9],
538
[2, 3, 7, 8], [2, 6, 9, 10], [3, 6, 9, 10], [1, 2, 6, 11],
539
[1, 4, 8, 10], [2, 4, 6, 10], [3, 4, 5, 9], [4, 5, 6, 7],
540
[1, 2, 7, 9], [1, 5, 6, 8], [2, 4, 6, 11], [3, 4, 5, 11],
541
[4, 5, 6, 11], [1, 3, 5, 10], [1, 5, 6, 11], [2, 4, 8, 10],
542
[3, 4, 8, 9], [4, 5, 7, 9], [1, 3, 5, 11], [1, 5, 8, 10],
543
[2, 5, 7, 8], [3, 5, 9, 10], [4, 6, 7, 10], [1, 3, 7, 10],
544
[1, 6, 8, 9], [2, 5, 7, 9], [3, 6, 7, 8], [5, 6, 7, 8]])
545
if n == 4:
546
# The facets in RP^4 are constructed by specifying two
547
# simplices on 16 vertices, and then finding their orbit
548
# under a certain subgroup of the permutation group on 16
549
# letters. See the description in Example 3.12 in Datta.
550
#
551
# Define the group:
552
from sage.groups.perm_gps.permgroup import PermutationGroup
553
g1 = '(2,7)(4,10)(5,6)(11,12)'
554
g2 = '(1, 2, 3, 4, 5, 10)(6, 8, 9)(11, 12, 13, 14, 15, 16)'
555
G = PermutationGroup([g1, g2])
556
# Define the two simplices:
557
t1 = (1, 2, 4, 5, 11)
558
t2 = (1, 2, 4, 11, 13)
559
# Apply the group elements to the simplices:
560
facets = []
561
for g in G:
562
d = g.dict()
563
for t in [t1, t2]:
564
new = tuple([d[j] for j in t])
565
if new not in facets:
566
facets.append(new)
567
return SimplicialComplex(facets)
568
if n >= 5:
569
# Use the construction given by Datta in Example 3.21.
570
V = set(range(0, n+2))
571
S = simplicial_complexes.Sphere(n).barycentric_subdivision()
572
X = S.facets()
573
facets = set([])
574
for f in X:
575
new = []
576
for v in f:
577
if 0 in v:
578
new.append(tuple(V.difference(v)))
579
else:
580
new.append(v)
581
facets.add(tuple(new))
582
return SimplicialComplex(list(facets))
583
584
def K3Surface(self):
585
"""
586
Returns a minimal triangulation of the K3 surface. This is
587
a pure simplicial complex of dimension 4 with 16 vertices
588
and 288 facets. It was constructed by Casella and Kühnel
589
in [CK2001]_. The construction here uses the labeling from
590
Spreer and Kühnel [SK2011]_.
591
592
REFERENCES:
593
594
.. [CK2001] M. Casella and W. Kühnel, "A triangulated K3 surface
595
with the minimum number of vertices", Topology 40 (2001),
596
753–772.
597
598
.. [SK2011] J. Spreer and W. Kühnel, "Combinatorial properties
599
of the K3 surface: Simplicial blowups and slicings", Experimental
600
Mathematics, Volume 20, Issue 2, 2011.
601
602
EXAMPLES::
603
604
sage: K3=simplicial_complexes.K3Surface() ; K3
605
Simplicial complex with 16 vertices and 288 facets
606
sage: K3.f_vector()
607
[1, 16, 120, 560, 720, 288]
608
"""
609
from sage.groups.perm_gps.permgroup import PermutationGroup
610
G = PermutationGroup([[(1,3,8,4,9,16,15,2,14,12,6,7,13,5,10)],[(1,11,16),(2,10,14),(3,12,13),(4,9,15),(5,7,8)]])
611
return SimplicialComplex([tuple([g(i) for i in (1,2,3,8,12)]) for g in G]+[tuple([g(i) for i in (1,2,5,8,14)]) for g in G])
612
613
###############################################################
614
# examples from graph theory:
615
616
def NotIConnectedGraphs(self, n, i):
617
"""
618
The simplicial complex of all graphs on n vertices which are
619
not i-connected.
620
621
Fix an integer `n>0` and consider the set of graphs on `n`
622
vertices. View each graph as its set of edges, so it is a
623
subset of a set of size `n` choose 2. A graph is
624
`i`-connected if, for any `j<i`, if any `j` vertices are
625
removed along with the edges emanating from them, then the
626
graph remains connected. Now fix `i`: it is clear that if `G`
627
is not `i`-connected, then the same is true for any graph
628
obtained from `G` by deleting edges. Thus the set of all
629
graphs which are not `i`-connected, viewed as a set of subsets
630
of the `n` choose 2 possible edges, is closed under taking
631
subsets, and thus forms a simplicial complex. This function
632
produces that simplicial complex.
633
634
INPUT:
635
636
- ``n``, ``i`` - non-negative integers with `i` at most `n`
637
638
See Dumas et al. for information on computing its homology by
639
computer, and see Babson et al. for theory. For example,
640
Babson et al. show that when `i=2`, the reduced homology of
641
this complex is nonzero only in dimension `2n-5`, where it is
642
free abelian of rank `(n-2)!`.
643
644
EXAMPLES::
645
646
sage: simplicial_complexes.NotIConnectedGraphs(5,2).f_vector()
647
[1, 10, 45, 120, 210, 240, 140, 20]
648
sage: simplicial_complexes.NotIConnectedGraphs(5,2).homology(5).ngens()
649
6
650
651
REFERENCES:
652
653
- Babson, Bjorner, Linusson, Shareshian, and Welker,
654
"Complexes of not i-connected graphs," Topology 38 (1999),
655
271-299
656
657
- Dumas, Heckenbach, Saunders, Welker, "Computing simplicial
658
homology based on efficient Smith normal form algorithms,"
659
in "Algebra, geometry, and software systems" (2003),
660
177-206.
661
"""
662
G_list = range(1,n+1)
663
G_vertices = Set(G_list)
664
E_list = []
665
for w in G_list:
666
for v in range(1,w):
667
E_list.append((v,w))
668
E = Set(E_list)
669
facets = []
670
i_minus_one_sets = list(G_vertices.subsets(size=i-1))
671
for A in i_minus_one_sets:
672
G_minus_A = G_vertices.difference(A)
673
for B in G_minus_A.subsets():
674
if len(B) > 0 and len(B) < len(G_minus_A):
675
C = G_minus_A.difference(B)
676
facet = E
677
for v in B:
678
for w in C:
679
bad_edge = (min(v,w), max(v,w))
680
facet = facet.difference(Set([bad_edge]))
681
facets.append(facet)
682
return SimplicialComplex(E_list, facets)
683
684
def MatchingComplex(self, n):
685
"""
686
The matching complex of graphs on n vertices.
687
688
Fix an integer `n>0` and consider a set `V` of `n` vertices.
689
A 'partial matching' on `V` is a graph formed by edges so that
690
each vertex is in at most one edge. If `G` is a partial
691
matching, then so is any graph obtained by deleting edges from
692
`G`. Thus the set of all partial matchings on `n` vertices,
693
viewed as a set of subsets of the `n` choose 2 possible edges,
694
is closed under taking subsets, and thus forms a simplicial
695
complex called the 'matching complex'. This function produces
696
that simplicial complex.
697
698
INPUT:
699
700
- ``n`` - positive integer.
701
702
See Dumas et al. for information on computing its homology by
703
computer, and see Wachs for an expository article about the
704
theory. For example, the homology of these complexes seems to
705
have only mod 3 torsion, and this has been proved for the
706
bottom non-vanishing homology group for the matching complex
707
`M_n`.
708
709
EXAMPLES::
710
711
sage: M = simplicial_complexes.MatchingComplex(7)
712
sage: H = M.homology()
713
sage: H
714
{0: 0, 1: C3, 2: Z^20}
715
sage: H[2].ngens()
716
20
717
sage: simplicial_complexes.MatchingComplex(8).homology(2) # long time (a few seconds)
718
Z^132
719
720
REFERENCES:
721
722
- Dumas, Heckenbach, Saunders, Welker, "Computing simplicial
723
homology based on efficient Smith normal form algorithms,"
724
in "Algebra, geometry, and software systems" (2003),
725
177-206.
726
727
- Wachs, "Topology of Matching, Chessboard and General Bounded
728
Degree Graph Complexes" (Algebra Universalis Special Issue
729
in Memory of Gian-Carlo Rota, Algebra Universalis, 49 (2003)
730
345-385)
731
"""
732
G_vertices = Set(range(1,n+1))
733
E_list = []
734
for w in G_vertices:
735
for v in range(1,w):
736
E_list.append((v,w))
737
facets = []
738
if is_even(n):
739
half = int(n/2)
740
half_n_sets = list(G_vertices.subsets(size=half))
741
else:
742
half = int((n-1)/2)
743
half_n_sets = list(G_vertices.subsets(size=half))
744
for X in half_n_sets:
745
Xcomp = G_vertices.difference(X)
746
if is_even(n):
747
if 1 in X:
748
A = X
749
B = Xcomp
750
else:
751
A = Xcomp
752
B = X
753
for M in matching(A, B):
754
facet = []
755
for pair in M:
756
facet.append(tuple(sorted(pair)))
757
facets.append(facet)
758
else:
759
for w in Xcomp:
760
if 1 in X or (w == 1 and 2 in X):
761
A = X
762
B = Xcomp.difference([w])
763
else:
764
B = X
765
A = Xcomp.difference([w])
766
for M in matching(A, B):
767
facet = []
768
for pair in M:
769
facet.append(tuple(sorted(pair)))
770
facets.append(facet)
771
return SimplicialComplex(E_list, facets)
772
773
def ChessboardComplex(self, n, i):
774
r"""
775
The chessboard complex for an n by i chessboard.
776
777
Fix integers `n, i > 0` and consider sets `V` of `n` vertices
778
and `W` of `i` vertices. A 'partial matching' between `V` and
779
`W` is a graph formed by edges `(v,w)` with `v \in V` and `w
780
\in W` so that each vertex is in at most one edge. If `G` is
781
a partial matching, then so is any graph obtained by deleting
782
edges from `G`. Thus the set of all partial matchings on `V`
783
and `W`, viewed as a set of subsets of the `n+i` choose 2
784
possible edges, is closed under taking subsets, and thus forms
785
a simplicial complex called the 'chessboard complex'. This
786
function produces that simplicial complex. (It is called the
787
chessboard complex because such graphs also correspond to ways
788
of placing rooks on an `n` by `i` chessboard so that none of
789
them are attacking each other.)
790
791
INPUT:
792
793
- ``n, i`` - positive integers.
794
795
See Dumas et al. for information on computing its homology by
796
computer, and see Wachs for an expository article about the
797
theory.
798
799
EXAMPLES::
800
801
sage: C = simplicial_complexes.ChessboardComplex(5,5)
802
sage: C.f_vector()
803
[1, 25, 200, 600, 600, 120]
804
sage: simplicial_complexes.ChessboardComplex(3,3).homology()
805
{0: 0, 1: Z x Z x Z x Z, 2: 0}
806
807
REFERENCES:
808
809
- Dumas, Heckenbach, Saunders, Welker, "Computing simplicial
810
homology based on efficient Smith normal form algorithms,"
811
in "Algebra, geometry, and software systems" (2003),
812
177-206.
813
814
- Wachs, "Topology of Matching, Chessboard and General Bounded
815
Degree Graph Complexes" (Algebra Universalis Special Issue
816
in Memory of Gian-Carlo Rota, Algebra Universalis, 49 (2003)
817
345-385)
818
"""
819
A = range(n)
820
B = range(i)
821
E_dict = {}
822
index = 0
823
for v in A:
824
for w in B:
825
E_dict[(v,w)] = index
826
index += 1
827
E = range(n*i)
828
facets = []
829
for M in matching(A, B):
830
facet = []
831
for pair in M:
832
facet.append(E_dict[pair])
833
facets.append(facet)
834
return SimplicialComplex(E, facets)
835
836
def RandomComplex(self, n, d, p=0.5):
837
"""
838
A random ``d``-dimensional simplicial complex on ``n``
839
vertices.
840
841
INPUT:
842
843
- ``n`` - number of vertices
844
- ``d`` - dimension of the complex
845
- ``p`` - floating point number between 0 and 1
846
(optional, default 0.5)
847
848
A random `d`-dimensional simplicial complex on `n` vertices,
849
as defined for example by Meshulam and Wallach, is constructed
850
as follows: take `n` vertices and include all of the simplices
851
of dimension strictly less than `d`, and then for each
852
possible simplex of dimension `d`, include it with probability
853
`p`.
854
855
EXAMPLES::
856
857
sage: simplicial_complexes.RandomComplex(6, 2)
858
Simplicial complex with vertex set (0, 1, 2, 3, 4, 5, 6) and 15 facets
859
860
If `d` is too large (if `d > n+1`, so that there are no
861
`d`-dimensional simplices), then return the simplicial complex
862
with a single `(n+1)`-dimensional simplex::
863
864
sage: simplicial_complexes.RandomComplex(6,12)
865
Simplicial complex with vertex set (0, 1, 2, 3, 4, 5, 6, 7) and facets {(0, 1, 2, 3, 4, 5, 6, 7)}
866
867
REFERENCES:
868
869
- Meshulam and Wallach, "Homological connectivity of random
870
`k`-dimensional complexes", preprint, math.CO/0609773.
871
"""
872
if d > n+1:
873
return simplicial_complexes.Simplex(n+1)
874
else:
875
vertices = range(n+1)
876
facets = Subsets(vertices, d).list()
877
maybe = Subsets(vertices, d+1)
878
facets.extend([f for f in maybe if random.random() <= p])
879
return SimplicialComplex(n, facets)
880
881
simplicial_complexes = SimplicialComplexExamples()
882
883