-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbdry_run.py
103 lines (92 loc) · 3.82 KB
/
bdry_run.py
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
# This program computes the boundary slopes of a Montesinos
# or two-bridge knot.
#
# You will need a Python interperator (version 1.5 or newer) to run
# these programs. These are free and availible for virtually every
# platform from the Python home page <http://www.python.org>. If you're
# using UNIX, you can see if your system has python installed by
# typing which python. To run do
#
# UNIX: While in the directory where you put all the files, type: python bdry_run.py
#
# MacOS: Run the Python program BuildApplet on bdry_run.py to
# create an executable. (Old versions of MacPython: Drag the file
# bdry_run.py and drop it onto the main Python icon.)
#
# Windoze: Double click the file bdry_run.py. If this doesn't
# work, try the instructions for MacOS.
#
# Version 1.0 Dec 4, 1998.
# Version 1.1 Jan 29, 1999. Added more graceful handling of improper input.
# Version 1.1.1 Oct 16, 2000. Changed MacOS instructions.
# Version 1.3 Nov 14, 2020. Made work with Python 3.*
#
# Written by Nathan Dunfield <nathand@math.harvard.edu>
import os, re, sys
import two_bridge, montesinos, gcd_tools
out = print
get_input = sys.stdin.readline
# ask user Question and get back a one character response which must be from Answers
def ask_question(Question, Answers):
while 1:
out(Question)
inp = get_input()[0]
if re.search(inp, Answers):
break
out("Sorry, input not understood.\n")
return inp
# begin main program
out("This program computes the boundary slopes of a Montesinos knot.\n")
out("Written by Nathan Dunfield <nathan@dunfield.info>\n\n")
while 1:
inp = ask_question("Do you want to do a t)wo-bridge knot or a m)ontesinos knot?: ", "tm")
if inp == 't':
while 1:
out("Enter a fraction describing the two-bridge knot, e.g. 5/7: ")
inp = get_input()[:-1]
try:
f = gcd_tools.string_to_frac(inp)
except:
out("Sorry, input not understood.\n")
continue
if f <= 0:
out("Sorry, need fraction to be > 0.\n")
continue
break
surfaces = two_bridge.branched_surfaces(f.t, f.b)
out("K(%s) %s\n" % (f, two_bridge.slopes(surfaces)))
inp = ask_question("Do you want more information? (y/n): ", "yn")
if inp == 'y':
out("\nContinued fraction expansion corresponding to each branched surface\n")
out("followed by the slope.\n")
two_bridge.print_surfaces(surfaces)
else: #montesinos knot
while 1:
out("Enter fractions describing a montesinos knot, e.g. 1/3 1/3 -1/3 : ")
tangles = []
inp = get_input()[:-1]
try:
for item in re.split(r"\s+", inp):
tangles.append(gcd_tools.string_to_frac(item))
except:
out("Sorry, input not understood.\n")
continue
if not montesinos.defines_knot(tangles):
out("Tangles give a link, not a knot.\n")
continue
if not montesinos.no_integer_tangles(tangles):
out("No integer tangles allowed.\n")
continue
break
surfaces = montesinos.compute_surfaces(tangles)
out("K%s\t%s\n" % (tuple(tangles), montesinos.compute_boundary_slopes(surfaces) ))
out("More info: (slope, number of sheets, euler char)\n")
out(repr(montesinos.essential_info(surfaces)) + "\n")
inp = ask_question("Do you want more information? (y/n): ", "yn")
if inp == 'y':
out("\n")
for surface in surfaces:
if surface.carries_incompressible:
out(repr(surface) + "\n")
if ask_question("Another knot? (y/n): ", "yn") == "n":
break