Re: How to determine Mod(a,b) with t_COMPLEX b?

Karim Belabas <[email protected]>
Newsgroups gmane.comp.mathematics.pari.user
Message-ID <[email protected]>
* [email protected] [2025-05-27 00:01]:
[...]
> The minimal residue of 1+4*I modulo 3+2*I is the yellow point -I in the
> example:
> https://en.wikipedia.org/wiki/Gaussian_integer#Describing_residue_classes
> 
> How can minimal residue of an input gaussian integer modulo a gaussian
> integer be computed in PARI/GP?

? a = 1+4*I; b = 3+2*I;
? a - round(a/b)*b
%2 = -I

This is not exacly the same normalization as in the Wikipedia article,
because ties are rounded up (= floor(x+1/2)), not down (= ceil(x-1/2)),
but it has the same properties (defines a Euclidean division with unique
quotient and remainder).

If you insist on the same (awkward) normalization, then you must use
something like

  myround(z) = ceil(real(z)-1/2) + I * ceil(imag(z)-1/2);
  a - myround(a/b)*b

instead.

? round(1/2 + I/2)
%3 = 1 + I
? myround(1/2 + I/2)
%4 = 0

Cheers,

    K.B.
-- 
Pr. Karim Belabas, U. Bordeaux, Vice-président en charge du Numérique
Institut de Mathématiques de Bordeaux UMR 5251 - (+33) 05 40 00 29 77
http://www.math.u-bordeaux.fr/~kbelabas/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.