hermann on Tue, 27 May 2025 13:34:35 +0200 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: How to determine Mod(a,b) with t_COMPLEX b? |
On 2025-05-27 01:59, Karim Belabas wrote:
Thank you for that approach of using t_COMPLEX (t_POL in Bill's approach).* hermann@stamm-wilbrandt.de [2025-05-27 00:01]: [...]The minimal residue of 1+4*I modulo 3+2*I is the yellow point -I in theexample: 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 uniquequotient 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.
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.