Copyright | Copyright (C) 2022 Yoo Chung |
---|---|
License | GPL-3.0-or-later |
Maintainer | dev@chungyc.org |
Safe Haskell | Safe-Inferred |
Language | GHC2021 |
Part of Ninety-Nine Haskell Problems. Some solutions are in Solutions.P44.
Synopsis
- isGaussianPrime :: Complex Integer -> Bool
Documentation
isGaussianPrime :: Complex Integer -> Bool Source #
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
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.