Re: How to determine Mod(a,b) with t_COMPLEX b?
| Newsgroups | gmane.comp.mathematics.pari.user |
|---|---|
| Message-ID | <[email protected]> |
On 2025-05-27 01:59, Karim Belabas wrote: > * [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. > Thank you for that approach of using t_COMPLEX (t_POL in Bill's approach). I cannot find a difference in set of minimal residues for both normalizations: $ gp -q ? a = 1+4*I; b = 3+2*I; ? myround(z) = ceil(real(z)-1/2) + I * ceil(imag(z)-1/2); ? S=Set([a - round(a/b)*b | r<-[-real(b)..real(b)];i<-[-imag(b)..imag(b)];a<-[r+i*I]]); ? myS=Set([a - myround(a/b)*b | r<-[-real(b)..real(b)];i<-[-imag(b)..imag(b)];a<-[r+i*I]]); ? #S==norml2(b)&&#myS==norml2(b) 1 ? setminus(S,myS) [] ? setminus(myS,S) [] ? Regards, Hermann.