File:Point-doubling.R.svg

From Elliptic Curve Crypto
Revision as of 04:00, 10 January 2025 by Rational Point (talk | contribs) (R program)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Original file(SVG file, nominally 504 × 504 pixels, file size: 195 KB)

R is not a symbolic algrebra program, but it does have that capability of manipulating expressions and polynomials.

Merely a graphical demonstration.

#! /usr/bin/R -f
# Point doubling illustrated

E <- y^2 ~ x^3 - x + 1
xrange <- seq(-1.5,1.5,length=4001)
point1 <- 1.0

stopifnot(E[[1]] == "~", E[[2]] == quote(y^2))

f <- call("sqrt", E[[3]])
g <- D(f,"x")
slope <- eval(g,list(x=point1))
intercept <- eval(f,list(x=point1)) - point1 * slope

r <- function(x){((intercept + slope * x)^2
        - eval(E[[3]],list(x=x)))/(x-point1)^2 }

point2 <- uniroot(r,lower=min(xrange),upper=max(xrange))$root

yrange <- eval(f,list(x=xrange))

xvals <- c(rev(xrange),xrange)
yvals <- c(rev(yrange),-yrange)

svg("point-doubling.R.svg")
plot(xvals,yvals,xlab="x",ylab="y",
        type="l",asp=1,lwd=3,lty="22",col="red",
        main=paste("point-doubling on the elliptic curve ",
                as.character(as.expression(E[[2]])),
                " = ", as.character(as.expression(E[[3]]))))
abline(0,0,col="blue")
abline(intercept,slope)
lines(c(point2,point2),
      c(-intercept-slope*point2,intercept+slope*point2),
      col=c("green","black"),lwd=2)
points(c(point1,point2,point2),
       c(eval(f,list(x=point1)),
         -intercept-slope*point2,
         intercept+slope*point2))
text(point1,eval(f,list(x=point1)),"P_1",pos=4)
text(point2,-intercept-slope*point2,"P_2 = 2*P_1",pos=4)

File history

Click on a date/time to view the file as it appeared at that time.

Date/TimeThumbnailDimensionsUserComment
current03:08, 10 January 2025Thumbnail for version as of 03:08, 10 January 2025504 × 504 (195 KB)Rational Point (talk | contribs)

The following page uses this file:

Metadata