On 20 February 2012 05:01, William Stein <[email protected]> wrote: > On Sun, Feb 19, 2012 at 8:25 PM, D. S. McNeil <[email protected]> wrote: >>> sage seems to think that the gcd of 6 and (-2 mod 6) is -2 mod 6, which it >>> converts to 4. A mathematician would say that the gcd is 2. >>> Is this a bug, or does sage have a higher purpose here? >> >> Sage is actually reasoning slightly differently, I think. First it >> decides whether there's a canonical coercion to a common parent. In >> this case, it concludes that the common parent should be the ring of >> integers modulo 6: >> >> sage: parent(Mod(4,6)) >> Ring of integers modulo 6 >> sage: parent(6) >> Integer Ring >> sage: z = cm.canonical_coercion(Mod(4,6), 6) >> sage: z >> (4, 0) >> sage: parent(z[0]), parent(z[1]) >> (Ring of integers modulo 6, Ring of integers modulo 6) >> >> There's no gcd method defined in this ring, > > I think that we should define a gcd method for this ring.
Agreed; after all it is a PID. And easy to define too since gcd(Mod(a,n),Mod(b,n)) = Mod(gcd(a,b,n),n), where (as Ken will no doubt be happy about) we can use any lift of a and b; and the output will always have the form Mod(d,n) where d is a positive divisor of n (or 0 rather than n itself). John > >> so it falls back to >> attempting to coerce 4 mod 6 and 0 mod 6 to ZZ, which succeeds, and we >> get the integer version under which we have >> >> sage: gcd(4,0) >> 4 >> >> It's not clear to me what the best way to handle this case is. Paging >> Simon King.. :^) >> >> >> Doug >> >> -- >> To post to this group, send email to [email protected] >> To unsubscribe from this group, send email to >> [email protected] >> For more options, visit this group at >> http://groups.google.com/group/sage-support >> URL: http://www.sagemath.org > > > > -- > William Stein > Professor of Mathematics > University of Washington > http://wstein.org > > -- > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/sage-support > URL: http://www.sagemath.org -- To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
