brdnum = 9 ## the number of strands in the braids lmt = 10000 ## the number of braids we will build rmin = 18 ## minimum length of the braid word rmax = 60 ## maximum length of the braid word retries = 50 ## number of crossing decision iterations to make for each braid built ## The next parameters allow you to change the likelihood that a crossing is an undercrossing, ## to 'unbalance' the crossing types. zset = 4 ## A random integer between 0 and zset-1 will return 0 uset = 8 ## A random integer between zset and uset-1 will return 1 dat = '170518a' ## This will be prepended to every filename, to prevent overwriting old files num = '1' ## This will be appended to every filename execfile('initialdata170515.txt') lowrec=open(dat+'newlow'+num+'.txt','w') highrec=open(dat+'newhigh'+num+'.txt','w') lowhold=open(dat+'low'+num+'.txt','w') highhold=open(dat+'high'+num+'.txt','w') rec=open(dat+'rec'+num+'.txt','w') linked=open(dat+'linked'+num+'.txt','w') source=open(dat+'src'+num+'.txt','w') errors=open(dat+'error'+num+'.txt','w') lowrec.write(' \n') highrec.write(' \n') lowhold.write(' \n') highhold.write(' \n') rec.write(' \n') linked.write(' \n') source.write(' \n') errors.write(' \n') lowrec.close() highrec.close() lowhold.close() highhold.close() linked.close() errors.close() from sys import setrecursionlimit setrecursionlimit(10000) import random if brdnum==4: C,Id=RationalTangle(1),IdentityBraid(1) a1=C|Id|Id b1=-C|Id|Id a2=Id|C|Id b2=Id|-C|Id a3=Id|Id|C b3=Id|Id|-C Brd=[[a1,a2,a3],[b1,b2,b3]] if brdnum==5: C,Id=RationalTangle(1),IdentityBraid(1) a1=C|Id|Id|Id b1=-C|Id|Id|Id a2=Id|C|Id|Id b2=Id|-C|Id|Id a3=Id|Id|C|Id b3=Id|Id|-C|Id a4=Id|Id|Id|C b4=Id|Id|Id|-C Brd=[[a1,a2,a3,a4],[b1,b2,b3,b4]] if brdnum==6: C,Id=RationalTangle(1),IdentityBraid(1) a1=C|Id|Id|Id|Id b1=-C|Id|Id|Id|Id a2=Id|C|Id|Id|Id b2=Id|-C|Id|Id|Id a3=Id|Id|C|Id|Id b3=Id|Id|-C|Id|Id a4=Id|Id|Id|C|Id b4=Id|Id|Id|-C|Id a5=Id|Id|Id|Id|C b5=Id|Id|Id|Id|-C Brd=[[a1,a2,a3,a4,a5],[b1,b2,b3,b4,b5]] if brdnum==7: C,Id=RationalTangle(1),IdentityBraid(1) a1=C|Id|Id|Id|Id|Id b1=-C|Id|Id|Id|Id|Id a2=Id|C|Id|Id|Id|Id b2=Id|-C|Id|Id|Id|Id a3=Id|Id|C|Id|Id|Id b3=Id|Id|-C|Id|Id|Id a4=Id|Id|Id|C|Id|Id b4=Id|Id|Id|-C|Id|Id a5=Id|Id|Id|Id|C|Id b5=Id|Id|Id|Id|-C|Id a6=Id|Id|Id|Id|Id|C b6=Id|Id|Id|Id|Id|-C Brd=[[a1,a2,a3,a4,a5,a6],[b1,b2,b3,b4,b5,b6]] if brdnum==8: C,Id=RationalTangle(1),IdentityBraid(1) a1=C|Id|Id|Id|Id|Id|Id b1=-C|Id|Id|Id|Id|Id|Id a2=Id|C|Id|Id|Id|Id|Id b2=Id|-C|Id|Id|Id|Id|Id a3=Id|Id|C|Id|Id|Id|Id b3=Id|Id|-C|Id|Id|Id|Id a4=Id|Id|Id|C|Id|Id|Id b4=Id|Id|Id|-C|Id|Id|Id a5=Id|Id|Id|Id|C|Id|Id b5=Id|Id|Id|Id|-C|Id|Id a6=Id|Id|Id|Id|Id|C|Id b6=Id|Id|Id|Id|Id|-C|Id a7=Id|Id|Id|Id|Id|Id|C b7=Id|Id|Id|Id|Id|Id|-C Brd=[[a1,a2,a3,a4,a5,a6,a7],[b1,b2,b3,b4,b5,b6,b7]] if brdnum==9: C,Id=RationalTangle(1),IdentityBraid(1) a1=C|Id|Id|Id|Id|Id|Id|Id b1=-C|Id|Id|Id|Id|Id|Id|Id a2=Id|C|Id|Id|Id|Id|Id|Id b2=Id|-C|Id|Id|Id|Id|Id|Id a3=Id|Id|C|Id|Id|Id|Id|Id b3=Id|Id|-C|Id|Id|Id|Id|Id a4=Id|Id|Id|C|Id|Id|Id|Id b4=Id|Id|Id|-C|Id|Id|Id|Id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|Id|Id|Id|Id|Id|C|Id|Id|Id|Id b7=Id|Id|Id|Id|Id|Id|-C|Id|Id|Id|Id a8=Id|Id|Id|Id|Id|Id|Id|C|Id|Id|Id b8=Id|Id|Id|Id|Id|Id|Id|-C|Id|Id|Id a9=Id|Id|Id|Id|Id|Id|Id|Id|C|Id|Id b9=Id|Id|Id|Id|Id|Id|Id|Id|-C|Id|Id a10=Id|Id|Id|Id|Id|Id|Id|Id|Id|C|Id b10=Id|Id|Id|Id|Id|Id|Id|Id|Id|-C|Id a11=Id|Id|Id|Id|Id|Id|Id|Id|Id|Id|C b11=Id|Id|Id|Id|Id|Id|Id|Id|Id|Id|-C Brd=[[a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11],[b1,b2,b3,b4,b5,b6,b7,b8,a9,b10,b11]] ## The code then creates a series of random braids, tests if they are knots, ## and then (if SnapPy can identify it) determines which bucket they belong in, ## and changes each crossing to make comparisons. for qq in range(0,lmt): A = random.sample(range(rmin,rmax),1) ## Choose a braid length at random ## Should build in a simple test here to check if the braid word ## will have the right parity to give a (qq-1)-cycle? ## This chooses the length of the braid word: we "want" it to be A[0], but it needs to ## be of a parity to have a chance of yielding a brdnum-cycle, so we adjust it... a = 2*(A[0]-(A[0]/2))+1-(brdnum-2*(brdnum/2)) ## the first part "makes" A[0] even, the last adds one if brdnum is even bard = [] sgnu = [] for s in range(0,a): ## build a random braid pattern hh = random.sample(range(0,brdnum-1),1) bard = bard+hh perm = [0]*brdnum ## this tests to see if the braid built for er in range(0,brdnum): ## induces a (brdnum)-cycle on the ends perm[er] = er ## of the strands (and so will build a knot) for re in range(0,len(bard)): ld = [perm[bard[re]+1]][:] perm[bard[re]+1]=perm[bard[re]] perm[bard[re]]=ld[0] coll = [perm[0]] po=perm[0] for ri in range(1,brdnum): coll = coll + [perm[po]] pu=[perm[po]][:] po=pu[0] truy = 0 for rt in range(0,brdnum): if rt not in coll: truy = 1 if truy==0: ## the braid pattern gives a knot print qq,' ',bard for uvw in range(0,retries): ## build a random choice of crossings to populate the braid pattern sgnu = [] for s in range(0,a): sse = random.sample(range(0,uset),1) ## this provides a (probabilistic) bias for one if sse[0] in range(0,zset): ## crossing type over another ss = [0] if sse[0] in range(zset,uset): ss = [1] sgnu = sgnu+ss xx=Brd[sgnu[0]][bard[0]] for i in range(1,len(bard)): xx=xx*Brd[sgnu[i]][bard[i]] L=(xx).denominator_closure() rec.write(str(qq)+' '+str(bard)+str(sgnu)+'\n') try: ## SnapPy's routines will sometimes fail on non-hyperbolic E=L.exterior() ## knots; this is designed to keep the loop from crashing G=E.fundamental_group() ## tests if we have started with the unknot QQ=G.relators() if QQ == []: source.write('unknot '+'['+str(bard)+','+str(sgnu)+']\n') rec.write(str(bard)+str(sgnu)+' unknot'+'\n') print 'unknot ',sgnu for j in range(0,len(sgnu)): sgnu2 = sgnu[:] sgnu2[j] = 1-sgnu[j] xxx=Brd[sgnu2[0]][bard[0]] for k in range(1,len(bard)): xxx=xxx*Brd[sgnu2[k]][bard[k]] Lx=(xxx).denominator_closure() try: Ex = Lx.exterior() IDx = Ex.identify() if not(IDx == []): ### print 'test0 ',qq,',',uvw,',',j,' : ',IDx source.write(str(IDx)+'['+str(bard)+','+str(sgnu2)+']\n') SSix = [] for t in range(0,len(IDx)): SSix = SSix + [IDx[t].name()] for ttt in SSix: for c in range(2,7): if ttt in UNHI[c]: print '\n\n Breaking BJ Conjecture! ',ttt,' has u(K)=1\n\n' highhold=open(dat+'high'+num+'.txt','a') highrec=open(dat+'newhigh'+num+'.txt','a') highrec.write('success: '+str(ttt)+' has u(K)=1 \n') highrec.write(str(bard) + ':' + str(sgnu) + ',' + str(sgnu2)+'\n') highhold.write(str(ttt)+' from Kun'+str(c)+'hi to Kun1hi \n') highrec.close() highhold.close() except SnapPeaFatalError: print sgnu,':',sgnu2,' SnapPeaFatalError' errors=open(dat+'error'+num+'.txt','a') errors.write(str(bard)+str(sgnu2)+'SnapPeaFatalError\n') errors.close() except ValueError: print sgnu,':',sgnu2,' ValueError' errors=open(dat+'error'+num+'.txt','a') errors.write(str(bard)+str(sgnu2)+'ValueError\n') errors.close() except IndexError: print sgnu,':',sgnu2,' IndexError' errors=open(dat+'error'+num+'.txt','a') errors.write(str(bard)+str(sgnu2)+'IndexError\n') errors.close() except RuntimeError: print sgnu,':',sgnu2,' RuntimeError' errors=open(dat+'error'+num+'.txt','a') errors.write(str(bard)+str(sgnu2)+'RuntimeError\n') errors.close() except IOError: print sgnu,':',sgnu2,' IOError' errors=open(dat+'error'+num+'.txt','a') errors.write(str(bard)+str(sgnu2)+'IOError\n') errors.close() except KeyError: print sgnu,':',sgnu2,' KeyError' errors=open(dat+'error'+num+'.txt','a') errors.write(str(bard)+str(sgnu2)+'KeyError\n') errors.close() SS = E.identify() rec.write(str(SS)+str(bard)+str(sgnu)+'\n') if not(SS == []): print 'new: ',qq,',',uvw,' : ',SS SSX = [] for t in range(0,len(SS)): SSX = SSX + [SS[t].name()] for nnn in SSX: chk = 0 low = 0 high = 99 for q in range(1,7): if nnn in UNLO[q]: low = q chk = 1 if nnn in UNHI[q]: high = q chk = 1 source.write(str(nnn) + ' : ' + str(low) + ',' + str(high)) if chk == 1: print 'K ',nnn,' : ',low,high for j in range(0,len(sgnu)): sgnu2 = sgnu[:] sgnu2[j] = 1-sgnu[j] xxx=Brd[sgnu2[0]][bard[0]] for k in range(1,len(bard)): xxx=xxx*Brd[sgnu2[k]][bard[k]] Lx=(xxx).denominator_closure() try: Ex = Lx.exterior() IDx = Ex.identify() if not(IDx == []): ### print 'test1: ',qq,',',uvw,',',j,' : ',IDx source.write(str(IDx)+'['+str(bard)+','+str(sgnu2)+']\n') SSix = [] for t in range(0,len(IDx)): SSix = SSix + [IDx[t].name()] for ttt in SSix: tlow = 0 thigh = 99 tchk = 0 for q in range(1,7): if ttt in UNLO[q]: tchk = 1 tlow = q if ttt in UNHI[q]: tchk = 1 thigh = q if tchk == 1: print 'T ',ttt,' : ',tlow,thigh fix1 = low - tlow if fix1 > 1: ## nnn lifts ttt's low estimate rr = low-1 print 'New Low. ',ttt,' in Kun',rr,'lo \n' lowrec=open(dat+'newlow'+num+'.txt','a') lowhold=open(dat+'low'+num+'.txt','a') lowrec.write('success: '+str(ttt)+' in Kun'+str(rr)+'lo, by '+str(nnn)+' \n') lowrec.write(str(bard) + ':' + str(sgnu) + ',' + str(sgnu2)+'.'+str(nnn)+';'+str(ttt)+'\n') lowhold.write(str(ttt)+' from Kun'+str(tlow)+'lo to Kun'+str(rr)+'lo \n') if rr == thigh: print 'computed: ',ttt,' has u(K)=',rr,'\n' lowrec.write('computed: '+str(ttt)+' has u(k)='+str(rr)+'\n') lowrec.close() lowhold.close() fix2 = tlow - low if fix2 > 1: ## ttt lifts nnn's low estimate rr = tlow-1 print 'New Low. ',nnn,' in Kun',rr,'lo \n' lowrec=open(dat+'newlow'+num+'.txt','a') lowhold=open(dat+'low'+num+'.txt','a') lowrec.write('success: '+str(nnn)+' in Kun'+str(rr)+'lo, by '+str(ttt)+' \n') lowrec.write(str(bard) + ':' + str(sgnu) + ',' + str(sgnu2)+'.'+str(nnn)+';'+str(ttt)+'\n') lowhold.write(str(nnn)+' from Kun'+str(low)+'lo to Kun'+str(rr)+'lo \n') if rr == high: print 'computed: ',nnn,' has u(K)=',rr,'\n' lowrec.write('computed: '+str(nnn)+' has u(k)='+str(rr)+'\n') lowrec.close() lowhold.close() fix3 = high - thigh if fix3 > 1: ## ttt lowers nnn's high estimate rr = thigh+1 print '\n\n New High! ',nnn,' in Kun',rr,'hi \n\n' highhold=open(dat+'high'+num+'.txt','a') highrec=open(dat+'newhigh'+num+'.txt','a') highrec.write('success: '+str(nnn)+' in Kun'+str(rr)+'hi, by '+str(ttt)+' \n') highrec.write(str(bard) + ':' + str(sgnu) + ',' + str(sgnu2)+'.'+str(nnn)+';'+str(ttt)+'\n') highhold.write(str(nnn)+' from Kun'+str(high)+'hi to Kun'+str(rr)+'hi \n') if rr == low: print 'computed: ',nnn,' has u(K)=',rr,'\n' highrec.write('computed: '+str(nnn)+' has u(k)='+str(rr)+'\n') highrec.close() highhold.close() fix4 = thigh - high if fix4 > 1: ## nnn lowers ttt's high estimate rr = high+1 print '\n\n New High! ',ttt,' in Kun',rr,'hi, by '+str(nnn)+' \n\n' highhold=open(dat+'high'+num+'.txt','a') highrec=open(dat+'newhigh'+num+'.txt','a') highrec.write('success: '+str(nnn)+' in Kun'+str(rr)+'hi \n') highrec.write('success: '+str(ttt)+' in Kun'+str(rr)+'hi \n') highrec.write(str(bard) + ':' + str(sgnu) + ',' + str(sgnu2)+'.'+str(nnn)+';'+str(ttt)+'\n') highhold.write(str(ttt)+' from Kun'+str(thigh)+'hi to Kun'+str(rr)+'hi \n') if rr == tlow: print 'computed: ',ttt,' has u(K)=',rr,'\n' highrec.write('computed: '+str(ttt)+' has u(k)='+str(rr)+'\n') highrec.close() highhold.close() fix5 = thigh - high #### START test for linked knots if fix5 == 1: fix6 = tlow - low if fix6 == 1: linked=open(dat+'linked'+num+'.txt','a') linked.write(str(nnn)+' is ['+str(low)+','+str(high)+'], '+str(ttt)+' is ['+str(tlow)+','+str(thigh)+']\n') linked.write(str(bard)+' '+str(sgnu)+' '+str(sgnu2)+'\n') linked.close() fix7 = high - thigh if fix7 == 1: fix8 = low - tlow if fix8 == 1: linked=open(dat+'linked'+num+'.txt','a') linked.write(str(ttt)+' is ['+str(tlow)+','+str(thigh)+'], '+str(nnn)+' is ['+str(low)+','+str(high)+']\n') linked.write(str(bard)+' '+str(sgnu2)+' '+str(sgnu)+'\n') linked.close() #### FINISH test for linked knots except SnapPeaFatalError: print sgnu,':',sgnu2,' SnapPeaFatalError' errors=open(dat+'error'+num+'.txt','a') errors.write(str(bard)+str(sgnu2)+'SnapPeaFatalError\n') errors.close() except ValueError: print sgnu,':',sgnu2,' ValueError' errors=open(dat+'error'+num+'.txt','a') errors.write(str(bard)+str(sgnu2)+'ValueError\n') errors.close() except IndexError: print sgnu,':',sgnu2,' IndexError' errors=open(dat+'error'+num+'.txt','a') errors.write(str(bard)+str(sgnu2)+'IndexError\n') errors.close() except RuntimeError: print sgnu,':',sgnu2,' RuntimeError' errors=open(dat+'error'+num+'.txt','a') errors.write(str(bard)+str(sgnu2)+'RuntimeError\n') errors.close() except IOError: print sgnu,':',sgnu2,' IOError' errors=open(dat+'error'+num+'.txt','a') errors.write(str(bard)+str(sgnu2)+'IOError\n') errors.close() except KeyError: print sgnu,':',sgnu2,' KeyError' errors=open(dat+'error'+num+'.txt','a') errors.write(str(bard)+str(sgnu2)+'KeyError\n') errors.close() except SnapPeaFatalError: print sgnu,': SnapPeaFatalError' errors=open(dat+'error'+num+'.txt','a') errors.write(str(bard)+str(sgnu)+'SnapPeaFatalError\n') errors.close() except ValueError: print sgnu,': ValueError' errors=open(dat+'error'+num+'.txt','a') errors.write(str(bard)+str(sgnu)+'ValueError\n') errors.close() except IndexError: print sgnu,': IndexError' errors=open(dat+'error'+num+'.txt','a') errors.write(str(bard)+str(sgnu)+'IndexError\n') errors.close() except RuntimeError: print sgnu,': RuntimeError' errors=open(dat+'error'+num+'.txt','a') errors.write(str(bard)+str(sgnu)+'RuntimeError\n') errors.close() except IOError: print sgnu,': IOError' errors=open(dat+'error'+num+'.txt','a') errors.write(str(bard)+str(sgnu)+'IOError\n') errors.close() except KeyError: print sgnu,': KeyError' errors=open(dat+'error'+num+'.txt','a') errors.write(str(bard)+str(sgnu)+'KeyError\n') errors.close() rec.close() source.close()