Advertisement
Guest User

Totient

a guest
Oct 22nd, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.04 KB | None | 0 0
  1. import numpy
  2. import math
  3.  
  4. phiList = []
  5. AB_list = []
  6. BC_list = []
  7. CD_list = []
  8. DE_list = []
  9. EA_list = []
  10. B_vert = []
  11. C_vert = []
  12. D_vert = []
  13. BC_Verts = []
  14. BCD_Verts = []
  15.  
  16. '''
  17. This program seeks to find a set of x,y coordinates for 5 points that are exactly
  18. the same angle apart from one another as those 5 dots found throughout the
  19. Liber Primus.
  20. '''
  21.  
  22. def gcd(a, b):
  23.  
  24.     if a == 0:
  25.         return b
  26.     return gcd(b % a, a)
  27.  
  28. def phi(n):
  29.  
  30.     '''
  31.    This is some copy and pasted code on how to find the totient of the argument.
  32.    '''
  33.  
  34.     result = 1
  35.     for i in range(2, n):
  36.  
  37.         if gcd(i, n) == 1:
  38.             result += 1
  39.     return result
  40.  
  41. for n in range(0, 100):
  42.    
  43.     '''
  44.    This loop will create a list of tuples of the x and y coordinates of the graph of the totient fucntion. I add 1 to n here since the range starts at zero. I know
  45.    there are easy fixes to this, but it works and is still pretty apparent what is happening.
  46.    '''
  47.  
  48.     phiList.append((n + 1, phi(n + 1)))
  49.    
  50. for i in range(len(phiList)):
  51.  
  52.     '''
  53.    This is where things get a little bit trickier, but are still pretty simple.
  54.    I create a loop that iterates through each point, and then nest a second loop
  55.    that compares every point to each other. It then uses some numpy/math functions
  56.    to find the slope of each set of points in relation to the origin and from there
  57.    measure their angles.
  58.  
  59.    I used photoshop to figure out the angles of each of the Liber Primus points,
  60.    which means that there was some margin of error that I tried to account for.
  61.    That is why the 'deg' variable is compared between some angle measures. This
  62.    might cause some issues.
  63.  
  64.    This loop will then organize all of the lines that we compared based on their
  65.    angle measure. I denoted each of the points from the Liber Primus from left to
  66.    right, as A, B, C, D, and E, and the lines between them as AB, BC, CD, DE, and EA.
  67.    '''
  68.  
  69.     for x in range(len(phiList)):
  70.        
  71.         tempTup = tuple(numpy.subtract(phiList[i], phiList[x]))
  72.         deg = math.degrees(math.atan2(tempTup[1], tempTup[0]))
  73.        
  74.         if deg > float(-76) and deg < float(-73):
  75.             AB_list.append(list(phiList[i]))
  76.             AB_list.append(list(phiList[x]))
  77.         elif deg > float(53) and deg < float(56):
  78.             BC_list.append(list(phiList[i]))
  79.             BC_list.append(list(phiList[x]))
  80.  
  81.         elif deg > float(-46) and deg < float(-43):
  82.             CD_list.append(list(phiList[i]))
  83.             CD_list.append(list(phiList[x]))
  84.  
  85.         elif deg > float(15) and deg <  float(19):
  86.             DE_list.append(list(phiList[i]))
  87.             DE_list.append(list(phiList[x]))
  88.  
  89.         elif deg > float(-14) and deg < float(-12):
  90.             EA_list.append(list(phiList[x]))
  91.             EA_list.append(list(phiList[i]))
  92.            
  93. for i in range(len(AB_list)):
  94.    
  95.     '''
  96.    After we have all of the lines of the totient function organized,
  97.    this loop will find all lines that have a vertex B that connects a line from
  98.    AB and BC.
  99.  
  100.    Because we are looking for the B vertex, it only looks at every even element from
  101.    the AB_list(since it is organized in such a way that every odd entry is the
  102.    x,y coordinates for an A point, and the even entries are all B points.
  103.  
  104.    For every vertext found, it will add The A, B, and C points of said vertex into
  105.    a new list to build upon later.
  106.    '''
  107.  
  108.     if i%2 == 0:
  109.         if AB_list[i] in BC_list[1::2]:
  110.             B_vert.append([AB_list[i - 1], AB_list[i], BC_list[BC_list.index(AB_list[i]) + 1]])
  111. print('B_vert Complete')
  112.  
  113. for i in range(len(BC_list)):
  114.  
  115.     '''
  116.    Same shit as above but for a C-vertext between lines BC and CD
  117.    '''
  118.  
  119.     if i%2 == 0:
  120.         if BC_list[i] in CD_list[1::2]:
  121.             C_vert.append([BC_list[i - 1], BC_list[i], CD_list[CD_list.index(BC_list[i]) + 1]])
  122. print('C_vert complete')
  123.  
  124. for i in range(len(CD_list)):
  125.  
  126.     '''
  127.    ^
  128.    '''
  129.     if i%2 == 0:
  130.         if CD_list[i] in DE_list[1::2]:
  131.             D_vert.append([CD_list[i - 1], CD_list[i], DE_list[DE_list.index(CD_list[i]) + 1]])
  132. print('D_vert complete')
  133.  
  134. for i in range(len(B_vert)):
  135.    
  136.     '''
  137.    This does a pretty similar thing to the loops above.
  138.    It iterates through the list of B-vertices and looks at their BC line portion,
  139.    and then compares them to the C-vertices BC lines. If they share that BC line,
  140.    then we smash them together to make a BC vertex, which should hopefully
  141.    look like the first foour points of the image in the Liber Primus.
  142.  
  143.    Threw in some print statements because this program does take a really long time,
  144.    and it is nice to see where you're at while it is running.
  145.    '''
  146.  
  147.     for x in range(len(C_vert)):
  148.        
  149.         if B_vert[i][1:2] == C_vert[x][0:1]:
  150.             BC_Verts.append([B_vert[i][0], B_vert[i][1], B_vert[i][2], C_vert[x][2]])
  151.  
  152. print('BC_Verts complete')
  153. print('length of BC_Verts: ' + str(len(BC_Verts)))
  154.  
  155. for i in range(len(BC_Verts)):
  156.  
  157.     '''
  158.    This will do the same as above, but this time comparing the CD line from each
  159.    entry in BC_Verts to the CD line of each D-vertex. If successful, it will
  160.    give us every set of points in the totient function that have the same angle
  161.    measures from point to point.
  162.  
  163.    This isn't perfect, and will require a human to go through and verify that the angle
  164.    measures create the same shape(since just having same angle measures does not mean it will
  165.    be the same shape, e.g. squares and rectangles), but it will hopefully reduce
  166.    the amount of human work required here. It could also get coded out by comparing the
  167.    length of lines to one another(but since we don't know how long each line would be,
  168.    the comparisons would have to be something like 'line AB is 1.3x longer than line BC'
  169.    '''
  170.     for x in range(len(D_vert)):
  171.        
  172.         if BC_Verts[i][2:3] == D_vert[x][0:1]:
  173.             BCD_Verts.append([BC_Verts[i][0], BC_Verts[i][1], BC_Verts[i][2], BC_Verts[i][3], D_vert[x][2]])
  174.  
  175. print(BCD_Verts)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement