diff --git a/Math/NumberTheory/EisensteinIntegers.hs b/Math/NumberTheory/EisensteinIntegers.hs index 82ace13d4..661bb4970 100644 --- a/Math/NumberTheory/EisensteinIntegers.hs +++ b/Math/NumberTheory/EisensteinIntegers.hs @@ -26,10 +26,14 @@ module Math.NumberTheory.EisensteinIntegers , quotRemE , quotE , remE + + -- * Primality functions + , isPrime ) where import GHC.Generics (Generic) +import qualified Math.NumberTheory.Primes.Testing as Testing infix 6 :+ @@ -127,4 +131,17 @@ conjugate (a :+ b) = (a - b) :+ (-b) -- | The square of the magnitude of a Eisenstein integer. norm :: EisensteinInteger -> Integer -norm (a :+ b) = a*a - a * b + b*b \ No newline at end of file +norm (a :+ b) = a*a - a * b + b*b + +-- | Checks if a given @EisensteinInteger@ is prime. @EisensteinInteger@s +-- whose norm is a prime congruent to @0@ or @1@ module 3 are prime. +-- See , +-- page 12. +isPrime :: EisensteinInteger -> Bool +isPrime e@(a :+ b) + | e == 0 = False + | b == 0 && a `mod` 3 == 2 = Testing.isPrime a + | a == 0 && b `mod` 3 == 2 = Testing.isPrime b + | nE `mod` 3 == 0 || nE `mod` 3 == 1 = Testing.isPrime nE + | otherwise = False + where nE = norm e \ No newline at end of file