Is there a computer-usable algorithm for division of Gaussian Integers?

84 Views Asked by At

I've just read Gaussian Integer - Wikipedia, and it mentions the possibility of euclidean division in $ℤ[i]$. Is there a computable formula of the form $(x_1 + iy_1) / (x_2 + iy_2) = f(x_1, y_1, x_2, y_2) + ig(x_1, y_1, x_2, y_2)$ where $f$ and $g$ are directly or recursively defined?

Sorry for the imprecise language. I'm trying to code something, and you can't implicitly define things in most programming languages (except Prolog)

2

There are 2 best solutions below

0
On BEST ANSWER

Assuming that $f, g, x_i, y_i$ are required to be real, this uniquely determines $f$ and $g$, so I wonder if you’re just asking how to divide complex numbers:

$$\frac{x_1 + iy_1}{x_2+iy_2} = \frac{x_1 + iy_1}{x_2+iy_2} \frac{x_2- iy_2}{x_2-iy_2} = \frac{x_1 x_2 + y_1 y_2}{x_2^2 + y_2^2} + i \frac{x_2 y_1 - x_1 y_2}{x_2^2 + y_2^2}.$$

It is certainly possible, though unnecessary, to derive this by solving a small system of linear equations: is that what you meant by implicit?

Edit: I see from your question on Code Review that you are interested in integer division. In that case as Brian Moehring comments above, you just round nearest on the fractional values of $f$ and $g$ (note that the remainder is not guaranteed to have positive components like in the integer case). I suspect you are using / to mean division with rounding which is a confusing way to phrase a math question :). I would use something that doesn’t look like exact division, such as DIV.

0
On

Sure there is. $\mathbb{Z}[i]$ is a Euclidean domain, so the Euclidean algorithm Just Works (TM) when you use the norm $N(a+bi) = a^2+b^2$.

There are answers at Prove that the Gaussian Integer's ring is a Euclidean domain which go into more detail.