"#function that returns the new curvature for the nth generator, just for checking whether we should go deeper into the word tree or start going down \n",
"def transval(n,root):\n",
" return 2*sum(root)-3*root[n-1]\n",
"\n",
"#function for when the word would have given a curvature that is too big \n",
"def down(word): \n",
" #if not word:\n",
" #return word #this is older stuff you can probably ignore\n",
"\n",
" if word[-1] == 4: #if the word ends in the last generator, drop that and repeat this whole function with that new word\n",
" word.pop()\n",
" word = down(word)\n",
" elif len(word)>1 and word[-1]+1==word[-2]: #if the word has length 2 and the last two generators are n+1, n\n",
" if word[-1]==3: #if the word ended in \"43\", then drop those two (since that is as far as we could go in this part of the tree), and if it is nonempty, then call this whole function again \n",
" word.pop()\n",
" word.pop()\n",
" if word: \n",
" word = down(word)\n",
" else: #if it ended in somehting like \"21\", then that becomes \"23\", like it skips over \"22,\" since that wouldn't be reduced.\n",
" word[-1]=word[-1]+2\n",
" else: #if it wasn't one of the weird above cases then just change the last generator to the one after that \n",
" word[-1]=word[-1]+1\n",
" return word\n",
"\n",
"#function for when the word gives a curvature that's still under the bound\n",
"#just adds a 1 or 2 at the end of the word, which is basically like the left-most branch above the word in the tree\n",
"root = [-6, 11, 14, 23] #some base tuple, it will change as we go through the words since we are kinda only paying attention to the end of the word\n",
"circlelist = list(root) #list of the curvatures, it starts with the root stuff and we will add to it \n",
"word = [1] #word that we are currently considering, it will change as we go through these, the first word we start with is just the word that consists of the first generator\n",
"recentroot = [] #this will be an array of arrays. the recentroot[i] is the most recent tuple that wasn't too big for word of length i so that when we go back down we know which tuple to operate on\n",
"recentroot.append(root) #the root thing will be our 0th element of this array\n",
"while word: #this runs until you get back to the empty word\n",
" #print(\"root : \" + str(root))\n",
" #print(\"word : \" + str(word))\n",
" n = word[-1] #we only really pay attention to the last generator in our word\n",
" l = len(word) #so we know which tuple to pull from recentroot\n",
" #print(recentroot)\n",
" root = list(recentroot[l-1]) #you have to cast it as a list or else it is just referencing an element of recentroot and will change when that changes, which we don't want\n",
" if transval(n,root)>bound: #if the new curvature was bigger than our bound, change the word according to the down function \n",
" word = down(word)\n",
" else: #if it was not bigger than our bound, replace/append the corresponding element of recentroot, add that curvature to the circlelist, \n",
" #and change the word according to the over function, since we may go deeper into that part of the tree before we hit the bound\n",