#17554: Unable to substitute univariate Laurent polynomial into usual polynomial
-------------------------------------------------+-------------------------
       Reporter:  tscrim                         |        Owner:  tscrim
           Type:  defect                         |       Status:  new
       Priority:  major                          |    Milestone:  sage-6.5
      Component:  commutative algebra            |   Resolution:
       Keywords:  Laurent polynomial,            |    Merged in:
  substitution                                   |    Reviewers:
        Authors:                                 |  Work issues:
Report Upstream:  N/A                            |       Commit:
         Branch:                                 |     Stopgaps:
   Dependencies:                                 |
-------------------------------------------------+-------------------------

Comment (by nbruin):

 The following seems to be the issue
 {{{
 sage: p() #evaluating with no arguments should probably be a no-op
 q^4 + q^2 - 2*q + 3
 sage: x() #but it raises an error for laurent polynomials
 IndexError: tuple index out of range
 }}}
 The problem gets triggered by
 `sage.rings.polynomial.polynomial_element.Polynomial.__call__`, which for
 keyword arguments does:
 {{{
           P = self.parent()
             name = P.variable_name()
             if name in kwds:
                 if len(x) > 0:
                     raise ValueError("must not specify both a keyword and
 positional argument")
                 a = self(kwds[name])
                 del kwds[name]
                 try:
                     return a(**kwds)
                 except TypeError:
                     return a
 }}}
 The command `return a(**kwds)` fails, because it's effectively
 `a(*(),**{})`. Furthermore, it fails with an `IndexError` which doesn't
 get caught.

 The better solution is probably to amend laurentpolynomial's `__call__` to
 do the right thing. Presently, it doesn't support keyword arguments at all
 and it expects non-empty arguments. Its implementation is
 {{{
     def __call__(self, *x):
         if isinstance(x[0], tuple):
             x = x[0]
         return self.__u(x) * (x[0]**self.__n)
 }}}
 which expects there is at least one argument and doesn't handle keyword
 arguments.

--
Ticket URL: <http://trac.sagemath.org/ticket/17554#comment:2>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" 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-trac.
For more options, visit https://groups.google.com/d/optout.

Reply via email to