#18940: Polynomials ignore the step argument in __getitem__
-------------------------------------+-------------------------------------
       Reporter:  pbruin             |        Owner:
           Type:  defect             |       Status:  new
       Priority:  major              |    Milestone:  sage-6.8
      Component:  algebra            |   Resolution:
       Keywords:                     |    Merged in:
        Authors:  Peter Bruin        |    Reviewers:
Report Upstream:  N/A                |  Work issues:
         Branch:                     |       Commit:
  u/pbruin/18940-getitem_step        |  97f95822da2ae740aa9a19bcc75f73c216879aeb
   Dependencies:  #19409             |     Stopgaps:
-------------------------------------+-------------------------------------
Changes (by pbruin):

 * commit:   => 97f95822da2ae740aa9a19bcc75f73c216879aeb
 * branch:   => u/pbruin/18940-getitem_step


Old description:

> Sage should support a `step` different from 1 in the `__getitem__()`
> method of polynomials:
> {{{
> sage: R.<x> = ZZ[]
> sage: f = sum(x^j for j in range(5))
> sage: f
> x^4 + x^3 + x^2 + x + 1
> sage: f[-2:4:2]
> x^3 + x^2 + x + 1  # should be x^2 + 1
> }}}

New description:

 Sage should support a `step` different from 1 in the `__getitem__()`
 method of polynomials:
 {{{
 sage: R.<x> = ZZ[]
 sage: f = sum(x^j for j in range(5))
 sage: f
 x^4 + x^3 + x^2 + x + 1
 sage: f[-2:4:2]
 x^3 + x^2 + x + 1  # should be x^2 + 1
 }}}
 We fix this for most classes by implementing a generic `__getitem__()`
 method, which depends on a new Cython method `get_unsafe()` to get single
 coefficients.  Overall, this greatly simplifies the code.  It is
 conceivable that there is a small performance loss (I have not tested
 this), but it is unlikely that there is any speed-critical code that
 heavily depends on `__getitem__()` with a slice argument.  For the
 remaining affected classes (Python classes, sparse polynomials), we fix
 `__getitem__()` in a similar way.

 This fix allows us to simplify the method
 `PowerSeries_poly.__getitem__()`.  Also, the patch corrects some
 (previously wrong) slice bounds in
 `LaurentPolynomial_univariate.__getitem__()`.

--

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