Skip to content

Instantly share code, notes, and snippets.

@Th0rgal
Created November 21, 2022 09:27
Show Gist options
  • Save Th0rgal/cc86167023788f9f2cce5061fde3dddd to your computer and use it in GitHub Desktop.
Save Th0rgal/cc86167023788f9f2cce5061fde3dddd to your computer and use it in GitHub Desktop.
# [input trace:]
# p.x
# p.y
# p.infinity
# q.x
# q.y
# q.infinity
# [appended trace:]
# coef -> coef * (trace[ap - 3] - trace[ap - 6]) - (trace[ap - 2] - trace[ap - 5]) = 0
# x -> x - ( (coef**2 - trace[ap - 7] - trace[ap - 4]) * (1-p.infinity) * (1-q.infinity) + p.infinity*q.x + q.infinity*p.x ) = 0
# y -> similar idea
def trace_add(self, trace):
ap = len(trace)
trace.append((trace[ap - 2] - trace[ap - 5]) / (trace[ap - 3] - trace[ap - 6]))
ap += 1
coef = trace[ap - 1]
# if p = O, q.x, if q = O, return p.x
trace.append(
(coef**2 - trace[ap - 7] - trace[ap - 4])
* (1 - trace[ap - 5])
* (1 - trace[ap - 2])
+ (trace[ap - 5] * trace[ap - 4])
+ (trace[ap - 2] * trace[ap - 7])
)
ap += 1
x = trace[ap - 1]
# if p = O, q.x, if q = O, return p.x
trace.append(
(coef * (trace[ap - 8] - x) - trace[ap - 7])
* (1 - trace[ap - 6])
* (1 - trace[ap - 3])
+ (trace[ap - 6] * trace[ap - 4])
+ (trace[ap - 3] * trace[ap - 7])
)
# infinity of p + q = inf(p) and inf(q)
trace.append((trace[ap - 6]) * (trace[ap - 3]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment