On Thu, May 15, 2008 at 4:00 PM, John H Palmieri <[EMAIL PROTECTED]> wrote:
>
> The fact that i is not in CC doesn't bother me too much, since i is a
> "formal square root of -1":
>
>  sage: i in CC
>  False
>
> I can force it to be in CC by doing this:
>
>  sage: CC(i)
>  1.00000000000000*I
>
> But then I think I should be able to do this:
>
>  sage: GF(5)(i)
>
> Someone who knows more number theory than I do can come up with a
> better solution, but coercion code like this ought to work: replace
> the end ("raise TypeError...") of the _coerc_impl() method for
> Finite_Field_prime_modn (in sage.rings.finite_field_prime_modn.py)
> with this:
>
>        from sage.functions.constants import I
>        from sage.rings.arith import primitive_root
>        p = self.__char
>        if x == i and p % 4 == 1:
>            return self(primitive_root(p))**((p-1)/4)
>        raise TypeError, "no canonical coercion of x"
>
> But this isn't the right place to patch.  When I do this,
> GF(5)._coerce_(i) works, but GF(5)(i) doesn't.
>
> Perhaps IntegerMod in the file integer_mod.pyx should be patched, but
> I don't want to mess around with Cython.  Perhaps some other file
> should be patched.  Can anyone help?

You should put the code in __call__.  _coerce_ is only
for canonical coercions, which the above definitely isn't.

By the way, it would be (asymptotically) a lot faster to
choose a random element of GF(p) and raise it to the
power (p-1)/4 and check the resulting power is not +/-1.
Finding a primitive root requires factoring p-1, which is
potentially very slow.

 -- William

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to