Problems.P44

Description

Part of Ninety-Nine Haskell Problems. Some solutions are in Solutions.P44.

Synopsis

# Documentation

A Gaussian integer $$x$$ is said to be a Gaussian prime when it has no divisors except for the units and associates of $$x$$. The units are $$1$$, $$i$$, $$-1$$, and $$-i$$. The associates are defined by the numbers obtained when $$x$$ is multiplied by each unit.

Determine whether a Gaussian integer is a Gaussian prime.

### Examples

Since $$5i = (2+i)(1+2i)$$,

>>> isGaussianPrime (0 :+ 5)
False


Since $$17 = (4+i)(4-i)$$,

>>> isGaussianPrime (17 :+ 0)
False


No non-unit proper divisors divide $$5+2i$$, so

>>> isGaussianPrime (5 :+ 2)
True


### Hint

Expand

Recall that $$|xy| = |x| \, |y|$$ for complex $$x$$ and $$y$$. This implies that for any proper divisor $$y$$ of a Gaussian integer $$x$$ where $$|x| > 1$$, it will be the case that $$|y| < |x|$$. In fact, it will be the case that there will be a non-unit divisor $$z$$ such that $$|z|^2 \leq |x|$$, if any non-unit proper divisor exists.