File: SnapPeaScripting.html

package info (click to toggle)
snappea 3.0d3-20
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 5,896 kB
  • ctags: 3,582
  • sloc: ansic: 33,469; sh: 8,293; python: 7,623; makefile: 240
file content (320 lines) | stat: -rw-r--r-- 7,482 bytes parent folder | download | duplicates (8)
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
<html>

<head>
<title>SnapPea 3.0 Scripting</title>
</head>

<body bgcolor="#80FFC0" text="#000000">

<table width="100%">
	<tr align=center>
		<td width="20%">
				<img src="SnapPea.gif" width=64 height=64 border=0><br>
		</td>
		<td width="60%">
				<b>SnapPea 3.0</b><br>
				<font size=+4><b>Scripting</b></font>
		</td>
		<td width="20%">
				<img src="SnapPea.gif" width=64 height=64 border=0><br>
		</td>
</table>

<p>SnapPea 3.0 is organized as a set of Python classes,
which sit on top of the SnapPea kernel.
For simple scripts you might be able to modify the
samples below to suit your purposes.
For more extensive work, you may obtain good Python
documentation online from the
<a href="http://www.python.org">Python web site</a>,
or in printed form from <a href="http://www.amazon.com">
amazon.com</a>.</p>

<p>As you read the following examples, you may want
to follow along on your own computer.  To start Python
on a unix machine, simply type <i>python</i> at the shell
prompt:</p>

<pre>
jeff$ python
Python 1.5.1 (#1, Mar 21 1999, 22:49:36)
[GCC egcs-2.91.66 19990314/Li on linux-i386
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>>
</pre>

<p>The <i>&gt;&gt;&gt;</i> is Python's own prompt.
You type Python commands at the prompt, each followed
by a return.
When you are done, type <i>Control-D</i> to quit.
Python does not understand <i>quit</i> or <i>exit</i>.</p>

<p>At its most basic level, Python is a calculator:</p>

<pre>
>>> 2 + 2
4
</pre>

<p>You may extend Python's modest built-in capabilities
by <b>importing</b> the functions from the math library:</p>

<pre>
>>> from math import *
>>> pi
3.14159265359
>>> cos(pi/4)
0.707106781187
</pre>

<p>Python lets you use variables in the obvious way:</p>

<pre>
>>> a = 7
>>> b = 10
>>> a + b
17
</pre>

<p>Variables are not typed.  They may be integers,
floating point numbers, strings, lists (illustrated here),
and even Triangulations or AbelianGroups
(illustrated later in this document).
Note that list elements are accessed with square brackets.</p>

<pre>
>>> a = [1, 'two', 3.0]
>>> a[0]
1
>>> a[1]
'two'
>>> a[2]
3.0
</pre>

<p><table border=1 align=center width="80%" cellpadding=16><tr align=center><td>
	To use SnapPea within Python, always begin with
	<center>
		<font face=courier18>from SnapPea import *</font>
	</center>
</td></tr></table></p>

<pre>
>>> from SnapPea import *
>>> t = Triangulation('MyFile')
>>> t

name:      MyFile
volume:    2.029883
homology:  Z
Dehn fillings:
  0      complete
</pre>

<p>The preceding example reads a Triangulation
from <i>MyFile</i> and assigns it to
the variable <i>t</i>.  Printing <i>t</i> reveals
some basic information about the Triangulation.
We may ask for additional information about <i>t</i>
by calling its <b>methods</b> (functions).</p>

<pre>
>>> t.fundamental_group()
generators:  a,b,c
relations:
aCAbc
aBcb
</pre>

<p>
The data returned by a method may, of course, be
assigned to a variable of its own, and queried further.
</p>

<pre>
>>> h = t.homology()
>>> h
Z
>>> h.Betti_number()
1
</pre>

<p>The Cusped Census manifolds are available as shown below,
specifying the number of tetrahedra
(5, 6, or 7) and the orientability ('o' for orientable
or 'n' for nonorientable).  If no orientability is
given, the default is 'o'.  If no number of tetrahedra
is given, the default is 5.  In the following example,
<i>a</i> is the nonorientable 6-tetrahedron census,
<i>b</i> and <i>c</i> are both the orientable 6-tetrahedron
census, and <i>d</i> is the 5-tetrahedron census.</p>

<pre>
>>> a = CuspedCensus(6, 'n')
>>> b = CuspedCensus(6, 'o')
>>> c = CuspedCensus(6)
>>> d = CuspedCensus()
</pre>

<p>(As in SnapPea 2.x, the 5-tetrahedron census is exceptional
in two ways:  it contains all cusped hyperbolic 3-manifolds,
<i>orientable and nonorientable</i>,
obtainable from 5 <i>or fewer</i> tetrahedra.
Its orientability parameter -- the <i>'n'</i>
in CuspedCensus(5, <i>'n'</i>) -- is ignored.)</p>

<p>Once we have a CuspedCensus, we may read manifolds
from it.  For example, the 0<sup>th</sup> manifold in the
5-tetrahedron census is the Gieseking, and the 4<sup>th</sup>
manifold is the figure eight knot complement.</p>

<pre>
>>> d = CuspedCensus()
>>> s = d[0]
>>> s

name:      m000
volume:    1.014942
homology:  Z
Dehn fillings:
  0      complete

>>> t = d[4]
>>> t

name:      m004
volume:    2.029883
homology:  Z
Dehn fillings:
  0      complete
</pre>

<p>Python offers control structures similar to those of C.
Note that
<ol>
	<li>the indentation determines the block structure (no curly brackets!), and</li>
	<li>the use of the colon.</li>
</ol>
</p>

<pre>
>>> a = [3, 5, 7, 9]
>>> for n in a:
...     m = n*n
...     print n, m
...
3 9
5 25
7 49
9 81
</pre>

<p>The same syntax works with Triangulations:</p>

<pre>
>>> for t in CuspedCensus(5):
...     t.volume()
...
1.01494160641
1.83193118835
2.02988321282
2.02988321282
2.02988321282
2.40690959305
etc.
</pre>

<p>If were interested only in the manifolds
with first Betti number at least 2, it would be
easy to select them out:</p>

<pre>
>>> for t in CuspedCensus(5):
...     if t.homology().Betti_number() > 1:
...         print t.get_name(), t.volume(), t.homology()
...
m124 3.66386237671 Z/2 + Z + Z
m125 3.66386237671 Z + Z
m128 3.66386237671 Z + Z
etc.
</pre>

<p>Typing scripts at the python prompt is frustrating,
because if you make
even the smallest mistake you need to retype the whole thing.
A better approach is to type the script into a file
(using a text editor, not python), such as the following:</p>

<b>links.py</b>
<pre>
#   links.py

#   Search for link complements in the 5-tetrahedron census.

#   Note:  The pound sign (#) introduces comments.

from SnapPea import *

#   Examine each Triangulation in the 5-tetrahedron census.

for t in CuspedCensus():

    #   For each cusp, do a Dehn filling on the shortest
    #   curve, which, by SnapPea's convention, is the
    #   meridional filling (1,0).
    for i in range(t.get_num_cusps()):
        t.set_cusp(i, 1, 0)
        
    #   We now have a closed manifold.
    #   Look at its fundamental group, and if the
    #   number of generators is zero (meaning the
    #   group is trivial), print the name of
    #   the original Triangulation, which we have shown
    #   to be a link complement in a homotopy sphere.
    if t.fundamental_group().num_generators() == 0:
        print t.get_name()
</pre>

<p>To run the script (under Unix) you may either pass it
to Python at the shell prompt...</p>

<pre>
jeff$ python links.py
m004
m015
m016
etc.
</pre>

<p>...or import it within the Python interpreter (without
the <i>.py</i> suffix).</p>

<pre>
jeff$ python
Python 1.5.1 (#1, Mar 21 1999, 22:49:36)  [GCC egcs-2.91.66 19990314/Li on linux-i386
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import links
m004
m015
m016
etc.
</pre>

<p><table border=1 align=center width="80%" cellpadding=16><tr align=center><td>
	I will eventually provide systematic documentation
	of SnapPea 3.0's objects and their methods.
	In the meantime, you may glean this information
	from the file <i>SnapPea.py</i>.
</td></tr></table></p>

<p>And speaking of documentation, I'm eager to have your
<a href="mailto:weeks@northnet.org">feedback</a>
on how this documentation should be developed.
Please let me know what you would find useful.</p>

<p>For interactive work, use SnapPea 3.0's
<a href="SnapPeaGUI.html">graphical user interface</a>.</p>

</body>

</html>