Elliptic curve arithmetic: Difference between revisions
→{{header|Raku}}: cleaning
(→{{header|Raku}}: cleaning) |
|||
Line 2,019:
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang="raku" line>
our ($A, $B) = (0, 7);
our class Point {▼
▲class Point {
has ($.x, $.y);
multi method new(
$x, $y where $y**2
) {
multi method
multi method gist(::?CLASS:U:) {
}
multi prefix:<->(Point $p) is export { Point.new: x => $p.x, y => -$p.y }
multi prefix:<->(
multi infix:<->(Point $a, Point $b) is export { $a + -$b }
multi infix:<+>(
multi infix:<+>(Point $p,
multi infix:<*>(Point $u, Int $n) is export { $n * $u }
multi infix:<*>(Int $n,
multi infix:<*>(0, Point) is export {
multi infix:<*>(1, Point $p) is export { $p }
multi infix:<*>(2, Point $p) is export {
my $l = (3*$p.x**2 + $A) / (2 *$p.y);
my $y = $l*($p.x - my $x = $l**2 - 2*$p.x) - $p.y;
$p.
}
multi infix:<*>(Int $n where $n > 2, Point $p) is export {
2 * ($n div 2 * $p) + $n % 2 * $p;
}
multi infix:<+>(Point $p, Point $q) is export {
if $p.x ~~ $q.x {
}
else {
}
}
}
import EC;
say my $p = Point.new: x => $_, y => sqrt(abs($_**3 + $A*$_ + $B)) given 1;▼
say my $q = Point.new: x => $_, y => sqrt(abs($_**3 + $A*$_ + $B)) given 2;▼
▲say my $p = EC::Point.new: x => $_, y => sqrt(abs($_**3 + $EC::A*$_ + $EC::B)) given 1;
▲say my $q = EC::Point.new: x => $_, y => sqrt(abs($_**3 + $EC::A*$_ + $EC::B)) given 2;
say my $s = $p + $q;
use Test;
{{out}}
<pre>EC Point at x=1, y=2.8284271247461903
EC Point at x=2, y=3.872983346207417
EC Point at x=-1.9089023002066448, y=0.21008487055753378
ok 1 - S, P and Q are aligned</pre>
=={{header|REXX}}==
|