Opened 4 years ago

#18419 new enhancement

Extend truncation of polynomials and harmonize with __getitem__

Reported by: vdelecroix Owned by:
Priority: major Milestone: sage-6.7
Component: algebra Keywords:
Cc: Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Description

The current truncate methods of polynomials is

cpdef truncate(self, n):
    r"""
    return self modulo X^n
    """

In many algorithms it is desirable to have a more general truncation

cpdef truncate(self, l, h):
   r"""
   Given a polynomial p = a_0 + a_1 X + ... + a_d X^d return the polynomial

    a_l + a_{l+1} X + ... + a_{h-1] X^h
   """

It would be the very same semantic than for the __getitem__.

sage: R.<x> = QQ[]
sage: p = 0 + 1*x + 2*x^2 + 3*x^3 + 4*x^4
sage: p[1:3]
2*x^2 + x
sage: p[2:]
4*x^4 + 3*x^3 + 2*x^2

Currently the __getitem__ method is a generic one. But for slices of the form (a,b,1) we should rely on truncate that can be optimized in derived classes.

Change History (0)

Note: See TracTickets for help on using tickets.