Elliptic curve arithmetic: Difference between revisions
m
J: style changes - maybe slightly easier to read
m (J: style changes - maybe slightly easier to read) |
|||
Line 541:
Follows the C contribution.
<lang j>
isZero=: 1e20 < |@{.@+.
neg=: +
dbl=: monad define
L=. 1.5 * p_x*p_x % p_y
r=. (L*L) - 2*p_x
r j. (L * p_x-r) - p_y
)
'p_x p_y'=. +. p=. x
'q_x q_y'=. +. q=. y
if. x=y do. dbl x return. end.▼
if. isZero y do. x return. end.
L=. %~/ +. q-p
r=. (L*L) - p_x + q_x
r j. (L * p_x-r) - p_y
)
a=. zero
for_bit.|.#:y do.
end.
x=. dbl x
end.
a
)
NB. C is 7
▲add=: 4 :0
▲if. x=y do. dbl x return. end.
▲if. isZero x do. y return. end.
show=: monad define
▲if. isZero y do. x return. end.
if. isZero y do. 'Zero' else.
▲'px py'=. +. x
'
'(',a,', ', b,')'
end.
)
▲from=: j.~[:(**3&%:@|)C-~*~
task=: 3 :0
a=. from 1
b=. from 2
)</lang>
{{out}}
<lang j> task '
a = (
b = (
c = a + b = (
d = -c = (
c + d = Zero
a + b + d = Zero
a * 12345 = (
=={{header|Java}}==
|