Skip to content

Instantly share code, notes, and snippets.

@tscholl2
Last active July 13, 2023 11:15
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tscholl2/b5d7a64fe9d283ee2b2bfe46588237a7 to your computer and use it in GitHub Desktop.
Save tscholl2/b5d7a64fe9d283ee2b2bfe46588237a7 to your computer and use it in GitHub Desktop.
plot of adding points on an elliptic curve
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
\documentclass{minimal}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[yscale=0.5]
%TODO: up sample size
\draw[domain=-4.060646:2,samples=100,smooth,variable=\x,blue] plot ({\x},{sqrt(\x^3 + 4*(\x)^2 + 1)});
\draw[domain=-4.060646:2,samples=100,smooth,variable=\x,blue] plot ({\x},{-sqrt(\x^3 + 4*(\x)^2 + 1)});
\node (P) at (-3.5, -2.66926956300783) {};
\node (Q) at (-0.25, 1.1102430216445) {};
\node (R) at (1.10295826812394, 2.68474117626385) {};
\node (P+Q) at (1.10295826812394, -2.68474117626385) {};
\draw[color=red,shorten >=-1cm,shorten <=-1cm] (P) -- (R);
\draw[color=red,shorten >=-1cm,shorten <=-1cm] (R) -- (P+Q);
\node[circle,draw=black,fill=green,label=above:{$P$}] at (P) {};
\node[circle,draw=black,fill=green,label=above:{$Q$}] at (Q) {};
\node[circle,draw=black,fill=green] at (R) {};
\node[circle,draw=black,fill=green,label=left:{$P+Q$}] at (P+Q) {};
\end{tikzpicture}
\end{document}
import matplotlib.pyplot as plt
plt.rc('text', usetex=True)
plt.rc('font',**{'family':'serif','serif':['Computer Modern Roman'],'size':14})
E = EllipticCurve([0,4,0,0,1])
P = E.change_ring(RR).lift_x(-0.25)[:2]
Q = E.change_ring(RR).lift_x(-3.5,all=true)[1][:2]
R2 = (E.change_ring(RR)(P) + E.change_ring(RR)(Q))[:2]
R1 = [i*x for i,x in zip(R2,[1,-1])]
L1 = [s*(vector(P) - vector(Q)) + vector(Q) for s in [-100,100]]
L2 = [s*(vector(R1) - vector(R2)) + vector(R2) for s in [-100,100]]
p = E.plot(axes=false,zorder=0)
p += line(L1,color="red",zorder=1)
p += line(L2,color="red",zorder=1)
p += point(P,size=100,zorder=2,color="green")
p += text("$\mathcal{P}$",[P[0]-0.5,P[1]],horizontal_alignment="left",color="black",fontsize=20)
p += point(Q,size=100,zorder=2,color="green")
p += text("$\mathcal{Q}$",[Q[0]-0.5,Q[1]],horizontal_alignment="left",color="black",fontsize=20)
p += point(R1,size=100,zorder=2,color="green")
p += text("$\mathcal{P} * \mathcal{Q}$",[R1[0]-0.8,R1[1]] ,horizontal_alignment="left",color="black",fontsize=20)
p += point(R2,size=100,zorder=2,color="green")
p += text("$\mathcal{P} + \mathcal{Q}$",[R2[0]+0.25,R2[1]],horizontal_alignment="left",color="black",fontsize=20)
p.show(xmin=-4.25,xmax=2,ymin=-4,ymax=4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment