-
Notifications
You must be signed in to change notification settings - Fork 0
/
bips.py
80 lines (67 loc) · 2.07 KB
/
bips.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
# Gregory Kehne
# These methods are for manipulating sequences of crossing-centered bipyramids.
# The bipSeq and unfoldBipSeq methods supplement the methods in bounds.py.
# The maxXing, concave, and sumdiff methods are just for exploring.
import math
# returns sequence of crossing centered bipyramid sizes given a permutation.
# 0th bipyramid is the top one.
def bipSeq(scramble):
seq = [0 for x in range(len(scramble))]
a = min(scramble[0], scramble[-1])
b = max(scramble[0], scramble[-1])
for i in range(a, b):
seq[i] = seq[i] + 2
for i in range(len(scramble) - 1):
a = min(scramble[i], scramble[i + 1])
b = max(scramble[i], scramble[i + 1])
for i in range(a, b):
seq[i] = seq[i] + 2
return seq
# returns a list of x-ing centered bipyramid sizes from unfolding a petal
# knot p at index k. Unfolding happens just 'above' the k^th strand
# (strands indexed starting at 0), k=1 is prepetal.
def unfoldBipSeq(p, k):
q1 = []
q2 = []
for i in range(len(p)):
if p[i] < k:
q1.append(p[i])
else:
q2.append(p[i] - k)
return bipSeq(q1) + bipSeq(q2)
# checks if xing bips are maximally sized for the perm size
# dev is # of allowed deviations from max size.
def maxXing(p, dev):
b = bipSeq(p)
for i in range(len(b) / 2 - 1):
if b[i] >= b[i + 1]:
if dev > 0:
dev = dev - 1
else:
return False
for i in range(len(b) / 2, len(b) - 2):
if b[i] <= b[i + 1]:
if dev > 0:
dev = dev - 1
else:
return False
return True
# checks whether the xing bipyramid sequence for a knot is concave
def concave(p):
b = bipSeq(p)
for i in range(1, len(b) - 1):
if b[i] < b[i - 1]:
for j in range(-1, len(b) - 1):
if b[j] > b[i]:
return True
return False
# given a list of integers, calculates the pairwise abs val sum.
# this is equal to the number of tetrahedra in face-centered bipyramids
# (less the outside face) for random permutations and large N, these seem
# to approach a normal distribution.
def sumdiff(a):
summ = math.fabs(a[len(a) - 1] - a[0])
for i in range(len(a) - 1):
N = math.fabs(a[i] - a[i + 1])
summ = summ + N
return summ