Elliptic curve arithmetic: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: reduce the rootI function.) |
m (→{{header|REXX}}: simplified the ROOTi function.) |
||
Line 845: | Line 845: | ||
Also, some code was added to have the output better aligned (for instance, negative and positive numbers). |
Also, some code was added to have the output better aligned (for instance, negative and positive numbers). |
||
<lang rexx>/*REXX program defines (for any 2 points on the curve), returns the sum of the 2 points.*/ |
<lang rexx>/*REXX program defines (for any 2 points on the curve), returns the sum of the 2 points.*/ |
||
numeric digits 100 /*try to ensure a min. of accuracy loss*/ |
|||
a=func(1) ; say 'a = ' show(a) |
|||
b=func(2) ; say 'b = ' show(b) |
|||
c=add(a, b) ; say 'c = (a+b) =' show(c) |
|||
d=neg(c) ; say 'd = -c =' show(d) |
|||
e=add(c, d) ; say 'e = (c+d) =' show(e) |
|||
g=add(a, add(b, d)) ; say 'g = (a+b+d) =' show(g) |
|||
exit /*stick a fork in it, we're all done. */ |
|||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
|||
cbrt: procedure; parse arg x; return root(x,3) |
cbrt: procedure; parse arg x; return root(x,3) |
||
root: procedure; parse arg x,y; if x=0 | y=1 then return x/1; d=5; return rootI() |
root: procedure; parse arg x,y; if x=0 | y=1 then return x/1; d=5; return rootI()/1 |
||
rootG: parse value format(x,2,1,,0) 'E0' with ? 'E' _ .; return (?/y'E'_%y) + (x>1) |
rootG: parse value format(x,2,1,,0) 'E0' with ? 'E' _ .; return (?/y'E'_%y) + (x>1) |
||
func: procedure; parse arg y,k; if k=='' then k=7; return cbrt(y**2-k) y |
func: procedure; parse arg y,k; if k=='' then k=7; return cbrt(y**2-k) y |
||
Line 881: | Line 872: | ||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
rootI: ox=x; oy=y; x=abs(x); y=abs(y); a=digits()+5; numeric form; g=rootG(); m=y-1 |
rootI: ox=x; oy=y; x=abs(x); y=abs(y); a=digits()+5; numeric form; g=rootG(); m=y-1 |
||
do until d==a; d=min(d+d,a); numeric digits d; o=0 |
|||
do until o=g; o=g; g=format((m*g**y+x)/y/g**m,,d-2); end /*until o=g*/ |
|||
end /*until d==a*/; _=g*sign(ox); if oy<0 then _=1/_; return _</lang> |
|||
'''output''' |
'''output''' |
||
<pre> |
<pre> |