Anonymous user
Elliptic curve arithmetic: Difference between revisions
m
→{{header|Haskell}}
(→{{header|Haskell}}: Added Haskell solution) |
|||
Line 431:
=={{header|Haskell}}==
First, some
<lang haskell>import Data.Monoid
import Control.Monad (guard)
import Test.QuickCheck (quickCheck)</lang>
The datatype for a point on an elliptic curve
<lang haskell>import Data.Monoid
Line 511:
We use QuickCheck to test general properties of points on arbitrary elliptic curve.
<lang haskell>-- for given a, b and x returns a point on the positive branch of elliptic curve (
do let y2 = x**3 + a*x + b
guard (y2 > 0)
return $ Elliptic x (sqrt y2)
addition a b x1 x2 =
let p = elliptic a b
s = p x1 <> p x2
in (s /= Nothing) ==> (s <> (inv <$> s) == Just Zero)
associativity a b x1 x2 x3 =
let p =
in (p x1 <> p x2) <> p x3 == p x1 <> (p x2 <> p x3)
commutativity a b x1 x2 =
let p =
in p x1 <> p x2 == p x2 <> p x1</lang>
<pre>λ> quickCheck
+++ OK, passed 100 tests.
λ> quickCheck associativity
+++ OK, passed 100 tests.
λ> quickCheck commutativity
|