#18940: Polynomials ignore the step argument in __getitem__
-------------------------------------+-------------------------------------
       Reporter:  pbruin             |        Owner:
           Type:  defect             |       Status:  needs_info
       Priority:  major              |    Milestone:  sage-6.10
      Component:  algebra            |   Resolution:
       Keywords:                     |    Merged in:
        Authors:  Peter Bruin        |    Reviewers:
Report Upstream:  N/A                |  Work issues:
         Branch:                     |       Commit:
  u/pbruin/18940-getitem_step        |  1c56779b3140d12fbe5d0973cdcad0ac9dbb8054
   Dependencies:  #19409             |     Stopgaps:
-------------------------------------+-------------------------------------

Comment (by jhpalmieri):

 Mathematically, I can certainly imagine wanting the part of the polynomial
 between degrees 2 and 5: I might want this:
 {{{
 sage: f
 -10*x^6 + 1/2*x^5 - x^4 + 7*x^3 - 2*x^2 + x - 3
 sage: f[2:6]
 1/2*x^5 - x^4 + 7*x^3 - 2*x^2
 }}}
 I don't know if I would ever want `f[2:6]` to return the polynomial with
 same coefficients but translated down in degree (i.e., `1/2*x^3 - x^2 +
 7*x - 2`). Computationally, though, if I have that second result, I can
 easily get back to the first one by multiplying by `x^2`. If I have the
 first, I can get to the second by dividing, but that puts the result in
 the fraction field, which is probably not what I want. Alternatively, I
 can also get to the second by creating a polynomial from `list(f)[2:6]`,
 which is not as intuitive, but not too hard.

 Surely different mathematicians will have different points of view on
 this.

 I think this is the issue for me: do we want
 {{{
 sage: list(pol[5:]) == list(pol)[5:]
 True
 }}}
 or do we want
 {{{
 sage: pol[:5] + pol[5:] == pol
 True
 }}}
 We can't have both, right? I prefer the second. That is, I tend to think
 of polynomials as graded objects and slicing is returning some of their
 homogeneous components, and it seems most natural to do this without
 regrading the result: if a term is in degree 3 in the original polynomial,
 it should still be in degree 3 after slicing. I would also like this:
 {{{
 sage: pol[0:10:2] + pol[1:10:2] == pol[0:10]
 True
 }}}
 Adding the even terms to the odd terms should yield the original
 polynomial.

 A related question: should `f[2]` return `-2` or `-2 * x^2`?

 -----------

 When it comes down to it, I'm not sure I care which option is implemented
 as `__getitem__`, but perhaps both should be implemented as methods which
 are visible via tab-completion, or as a single method with a keyword which
 determines which option to use.

--
Ticket URL: <http://trac.sagemath.org/ticket/18940#comment:32>
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