Gaussian Primes¶
The Gaussian integers are
$$ \mathbb Z[i]=\{a+bi\mid a,b\in\mathbb Z\}. $$
Their multiplicative norm is
$$ N(a+bi)=(a+bi)(a-bi)=a^2+b^2. $$
Away from the coordinate axes, a Gaussian integer is prime exactly when its integer norm is prime.
Enumerate a finite lattice patch¶
Egison's set matcher chooses unordered pairs from $\{1,\ldots,10\}$. This covers one open quadrant without listing symmetric associates produced by signs, conjugation, or multiplication by the units $\{\pm1,\pm i\}$.
def gaussianPoints : [(Integer, Integer)] :=
matchAll take 10 nats as set integer with
| $x :: $y :: _ -> (x, y)
def gaussianInteger (x : Integer) (y : Integer) : MathValue :=
x + y * i
def gaussianNorm (x : Integer) (y : Integer) : Integer :=
x ^ 2 + y ^ 2
def gaussianNorms : [(MathValue, Integer)] :=
map
(\(x, y) -> (gaussianInteger x y, gaussianNorm x y))
gaussianPoints
Norms are ordinary integers¶
The first entries show both the algebraic integer and its exact norm. For example, $N(1+i)=2$, while $N(2+2i)=8$.
take 10 gaussianNorms
Filter by prime norm¶
Because both coordinates in this patch are nonzero, testing the integer norm is sufficient. Axis primes require the complementary rule that an ordinary prime $p$ remains Gaussian-prime precisely when $p\equiv3\pmod4$.
def gaussianPrimes : [(MathValue, Integer)] :=
filter (\(_, n) -> isPrime n) gaussianNorms
take 20 gaussianPrimes
Multiplicativity in one line¶
The rational prime $2$ is not prime in $\mathbb Z[i]$:
$$ 2=(1+i)(1-i). $$
The same expression also exhibits the norm of $1+i$.
((1 + i) * (1 - i), gaussianNorm 1 1)
Takeaway¶
A two-dimensional primality question has been reduced to an ordinary integer test through the multiplicative norm. Egison's pattern matching handles the lattice enumeration, while exact symbolic arithmetic keeps each Gaussian integer readable.