Skip to content

Instantly share code, notes, and snippets.

@mango314
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mango314/0fd296f89532b227f0d5 to your computer and use it in GitHub Desktop.
Save mango314/0fd296f89532b227f0d5 to your computer and use it in GitHub Desktop.
gauss reduction algorithm and cycles
def S((a,b,c), k=1):
return (a, -2*a*k+b, a*k**2-b*k+c)
def T((a,b,c)):
return (c,b,a)
x = (1,33,-21)
x = (7, 33, -8)
x = (13,13,-22)
# never changes in this process. eveluate it once
D = x[1]**2 - 4*x[0]*x[2]
O = [x]
x = (x[2], -1*x[1], x[0])
c = 0
while True:
while x[1] < 0 or 2*abs(x[2]) < np.sqrt(D) - x[1] or 2*abs(x[2]) > np.sqrt(D) + x[1]:
x = S(x, -1*x[0]/abs(x[0]))
if x == O[0]:
break
else:
O += [x]
x = (x[2], -1*x[1], x[0])
O
[(13, 13, -22),
(-22, 31, 4),
(4, 33, -14),
(-14, 23, 14),
(14, 33, -4),
(-4, 31, 22),
(22, 13, -13),
(-13, 13, 22),
(22, 31, -4),
(-4, 33, 14),
(14, 23, -14),
(-14, 33, 4),
(4, 31, -22),
(-22, 13, 13)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment