On 11/18/2012 01:31 AM, Nils Bruin wrote:
> 
> That can be cleaned up quite a bit if this were rewritten to use
> maxima_lib. In that case the multiplications would probably be actual
> sage multiplications too, so would likely lead to the same errors as
> in Sage, though.
> 
> The issue really is whether "rational number"*"finite field element"
> should be supported. The problem is of course that there is no common
> parent for *all* possible element pairs, so the coercion framework
> rightfully refuses. It would be awfully convenient if it were allowed
> when it makes sense (and just throw a ZeroDivision otherwise).
> 
> Conversion does do the right thing,you just need to phrase your
> problem in a way that allows conversion rules come into play:
> 
> sage: Qx.<x>=QQ[]
> sage: Fy.<y>=GF(101)[]
> sage: f=legendr
> legendre_P       legendre_Q       legendre_symbol
> sage: f=legendre_P(3,x)
> sage: f
> 5/2*x^3 - 3/2*x
> sage: Fy(f)
> 53*y^3 + 49*y
> 
> After that you can of course evaluate the converted polynomial. The
> issue of course is that Legendre polynomials cannot be defined this
> way in all characteristics:
> 
> sage: Fz.<z>=GF(2)[]
> sage: Fz(f)
> ZeroDivisionError: Inverse does not exist.
> 

This works with the current legendre_P (as does Robert's solution)
thanks to the string magic, but wouldn't work with my scaled
implementation that tries to multiply/divide `x` by terms involving the
endpoints of the interval.

Ultimately it works if I stick to ZZ, and I was able to work around this
one regression by checking for the special case where the endpoints are
in ZZ. I just had to rearrange the terms a bit to avoid creating a rational.

These both work:

  sage: ZZ(5) * GF(11)(5)
  3
  sage: GF(11)(5) / ZZ(8)
  2

but this doesn't:

  sage: (ZZ(5)/ZZ(8)) * GF(11)(5)
  ...
  TypeError: unsupported operand parent(s) for '*': 'Rational Field'
  and 'Finite Field of size 11'

I think it might as well be allowed, since this is:

  sage: GF(2)(1) / ZZ(2)
  ...
  ZeroDivisionError: Inverse does not exist.

I left the case with rational endpoints unhandled; I don't think anyone
is evaluating Legendre polynomials in GF(11), but I didn't want to cause
an unnecessary regression.

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To post to this group, send email to sage-devel@googlegroups.com.
To unsubscribe from this group, send email to 
sage-devel+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel?hl=en.


Reply via email to