Created
June 3, 2019 10:58
-
-
Save estensen/dc01a7e784cc92e94f07a54e67fdb271 to your computer and use it in GitHub Desktop.
Visualize point addition on elliptic curves
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| a = -1 | |
| b = 1 | |
| y, x = np.ogrid[-2:2:100j, -2:2:100j] | |
| fig = plt.figure() | |
| ax = fig.add_subplot(1, 1, 1) | |
| # Move left y-axis and bottim x-axis to centre, passing through (0,0) | |
| ax.spines['left'].set_position('center') | |
| ax.spines['bottom'].set_position('center') | |
| # Eliminate upper and right axes | |
| ax.spines['right'].set_color('none') | |
| ax.spines['top'].set_color('none') | |
| # Show ticks in the left and lower axes only | |
| ax.xaxis.set_ticks_position('bottom') | |
| ax.yaxis.set_ticks_position('left') | |
| # Line | |
| lx = np.linspace(-2, 2) | |
| ly = np.linspace(.4, 2) | |
| plt.plot(lx, ly, 'red') | |
| # Elliptic Curve | |
| plt.contour(x.ravel(), y.ravel(), pow(y, 2) - pow(x, 3) - x * a - b, [0], colors='blue') | |
| # Manually add labels to line intersections | |
| plt.text(-1.3, .8, 'P') | |
| plt.text(-0.3, 1.2, 'Q') | |
| plt.text(1.5, 1.9, 'R') | |
| plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment