ninetynine-1.3.0: Ninety-Nine Haskell Problems
CopyrightCopyright (C) 2022 Yoo Chung
LicenseGPL-3.0-or-later
Maintainerdev@chungyc.org
Safe HaskellSafe-Inferred
LanguageGHC2021

Solutions.P45

Description

Some solutions to Problems.P45 of Ninety-Nine Haskell Problems.

Synopsis

Documentation

isGaussianPrime' :: Complex Integer -> Bool Source #

Using Fermat's two-square theorem, it can be shown that a Gaussian integer \(a+bi\) is prime if and only if it falls into one of the following categories:

  • |a| is prime and \(|a| \equiv 3 \mod 4\), if \(b=0\).
  • |b| is prime and \(|b| \equiv 3 \mod 4\), if \(a=0\).
  • \( a^2 + b^2 \) is prime, if \( a \neq 0 \) and \( b \neq 0 \).

Use this property to determine whether a Gaussian integer is a Gaussian prime.