I've spent some time looking through the fast_callable.pyx file and here is what I think the issue is.
The expression builder keeps track of the 'constants' it has come across so far in a dictionary. When it gets to a new power (or constant) it first checks if it is in the dictionary and uses that value if it is. So since 1==T(1), it is finding the power 1 in the list of constants as the power series element 1 even though the exponent is the integer 1. This logic does not seem to be the issue. So I think the correction here should not be in the expression builder, but just in evaluating Integer(T(1)), since the fact that 1==T(1) is True (correctly) is what is getting us into this problem in the first place. On Monday, March 17, 2014 12:03:41 PM UTC-4, David Roe wrote: > > The fact that Integer(T(1)) doesn't work is definitely a bug. A brief > glance at sage.ext.fast_callable (in particular, the code in > Expression.__pow__) suggests that fixing the first problem might yield an > expression that doesn't use an exponent in the coefficient ring. However, > I'm not as familiar with that code, so there may be a problem there as well. > > The best way to fix the problem for power series is to duplicate the > functionality from polynomials, defined in > sage.rings.polynomial.polynomial_element.PolynomialBaseringInjection and > used in > sage.rings.polynomial.polynomial_ring.PolynomialRing._coerce_map_from_. > David > > > On Sun, Mar 16, 2014 at 9:51 PM, Dillon Rose <[email protected]<javascript:> > > wrote: > >> Hello all, >> >> I am developing patch # 15780. We want to use fast_callable to increase the >> speed. >> >> The changes we have work for most cases. However, when we try to evaluate >> the expression tree built for a polynomial ring over a PowerSeriesRing, an >> exception is thrown. >> >> T.<z>=PowerSeriesRing(ZZ) >> P.<x,y>=PolynomialRing(T) >> f=x^2+x*y >> g=fast_callable(f) >> g(1,1) >> >> The cause is in generic_power_c() in sage/structure/element.pyx. Basically, >> the PowerSeriesRing element 1 fails to be recognized as the integer 1 >> causing the exception to be thrown. >> >> >> try: >> from sage.rings.integer import Integer >> n = int(Integer(nn)) >> except TypeError: >> raise NotImplementedError, "non-integral exponents not supported" >> >> >> This is occuring because the expression from fast_callable has a term >> ('ipow', n) where n is actually an integer, but whose parent is the >> coefficient ring of the polynomial ring. >> >> The question here is basically: what part of this needs to be fixed? It >> seems odd that the exponents being returned from fast_callable are in the >> base ring causing the call to generic_power. This expression should be fast >> to evaluate and, even if it worked, this is certainly slowing it down. But >> it also is odd that Integer() is unable to coerce a power series integer. >> >> >> Dillon Rose >> >> -- >> You received this message because you are subscribed to the Google Groups >> "sage-devel" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected] <javascript:>. >> To post to this group, send email to [email protected]<javascript:> >> . >> Visit this group at http://groups.google.com/group/sage-devel. >> For more options, visit https://groups.google.com/d/optout. >> > > -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.
