Coverage for local/lib/python2.7/site-packages/sage/rings/laurent_series_ring_element.pyx : 75%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
""" Laurent Series
EXAMPLES::
sage: R.<t> = LaurentSeriesRing(GF(7), 't'); R Laurent Series Ring in t over Finite Field of size 7 sage: f = 1/(1-t+O(t^10)); f 1 + t + t^2 + t^3 + t^4 + t^5 + t^6 + t^7 + t^8 + t^9 + O(t^10)
Laurent series are immutable::
sage: f[2] 1 sage: f[2] = 5 Traceback (most recent call last): ... IndexError: Laurent series are immutable
We compute with a Laurent series over the complex mpfr numbers.
::
sage: K.<q> = Frac(CC[['q']]) sage: K Laurent Series Ring in q over Complex Field with 53 bits of precision sage: q 1.00000000000000*q
Saving and loading.
::
sage: loads(q.dumps()) == q True sage: loads(K.dumps()) == K True
IMPLEMENTATION: Laurent series in Sage are represented internally as a power of the variable times the unit part (which need not be a unit - it's a polynomial with nonzero constant term). The zero Laurent series has unit part 0.
AUTHORS:
- William Stein: original version
- David Joyner (2006-01-22): added examples
- Robert Bradshaw (2007-04): optimizations, shifting
- Robert Bradshaw: Cython version """ #***************************************************************************** # Copyright (C) 2005 William Stein <wstein@gmail.com> # 2017 Vincent Delecroix <20100.delecroix@gmail.com> # # Distributed under the terms of the GNU General Public License (GPL) # # This code is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # The full text of the GPL is available at: # # http://www.gnu.org/licenses/ #*****************************************************************************
from __future__ import print_function, absolute_import
from .infinity import infinity
import sage.rings.polynomial.polynomial_element as polynomial import sage.misc.latex from sage.rings.integer import Integer from sage.rings.polynomial.laurent_polynomial import LaurentPolynomial_univariate from .power_series_ring_element cimport PowerSeries from sage.structure.element cimport Element, ModuleElement, RingElement, AlgebraElement from sage.structure.richcmp cimport richcmp_not_equal, rich_to_bool from sage.misc.derivative import multi_derivative
def is_LaurentSeries(x): return isinstance(x, LaurentSeries)
cdef class LaurentSeries(AlgebraElement): """ A Laurent Series.
We consider a Laurent series of the form `t^n \cdot f` where `f` is a power series.
INPUT:
- ``parent`` -- a Laurent series ring
- ``f`` -- a power series (or something can be coerced to one); note that ``f`` does *not* have to be a unit
- ``n`` -- (default: 0) integer """ def __init__(self, parent, f, n=0): r""" Initialize ``self``.
OUTPUT: a Laurent series
EXAMPLES::
sage: R.<q> = LaurentSeriesRing(ZZ) sage: R([1,2,3]) 1 + 2*q + 3*q^2 sage: R([1,2,3],-5) q^-5 + 2*q^-4 + 3*q^-3
::
sage: S.<s> = LaurentSeriesRing(GF(5)) sage: T.<t> = PowerSeriesRing(pAdicRing(5)) sage: S(t) s sage: parent(S(t)) Laurent Series Ring in s over Finite Field of size 5 sage: parent(S(t)[1]) Finite Field of size 5 """
else: ## now this is a power series, over a different ring ... ## requires that power series rings with same vars over the ## same parent are unique.
# self is that t^n * u: else: else: else:
def __reduce__(self):
def change_ring(self, R): """ Change the base ring of ``self``.
EXAMPLES::
sage: R.<q> = LaurentSeriesRing(ZZ) sage: p = R([1,2,3]); p 1 + 2*q + 3*q^2 sage: p.change_ring(GF(2)) 1 + q^2 """
def is_unit(self): """ Return ``True`` if this is Laurent series is a unit in this ring.
EXAMPLES::
sage: R.<t> = LaurentSeriesRing(QQ) sage: (2+t).is_unit() True sage: f = 2+t^2+O(t^10); f.is_unit() True sage: 1/f 1/2 - 1/4*t^2 + 1/8*t^4 - 1/16*t^6 + 1/32*t^8 + O(t^10) sage: R(0).is_unit() False sage: R.<s> = LaurentSeriesRing(ZZ) sage: f = 2 + s^2 + O(s^10) sage: f.is_unit() False sage: 1/f Traceback (most recent call last): ... ValueError: constant term 2 is not a unit
ALGORITHM: A Laurent series is a unit if and only if its "unit part" is a unit. """
def is_zero(self): """ EXAMPLES::
sage: x = Frac(QQ[['x']]).0 sage: f = 1/x + x + x^2 + 3*x^4 + O(x^7) sage: f.is_zero() 0 sage: z = 0*f sage: z.is_zero() 1 """
def is_monomial(self): """ Return True if this element is a monomial. That is, if self is `x^n` for some integer `n`.
EXAMPLES::
sage: k.<z> = LaurentSeriesRing(QQ, 'z') sage: (30*z).is_monomial() False sage: k(1).is_monomial() True sage: (z+1).is_monomial() False sage: (z^-2909).is_monomial() True sage: (3*z^-2909).is_monomial() False """
def __nonzero__(self): """ EXAMPLES::
sage: R.<t> = LaurentSeriesRing(ZZ) sage: bool(t) True sage: bool(1/t) True sage: bool(2 + t) True sage: bool(1/(1-t)) True sage: bool(1 + O(t^3)) True sage: bool(t + O(t^3)) True sage: bool(O(t^3)) False sage: bool(O(t^-3)) False sage: bool(R.zero()) False """
def _im_gens_(self, codomain, im_gens):
cdef __normalize(self): r""" A Laurent series is a pair (u(t), n), where either u=0 (to some precision) or u is a unit. This pair corresponds to `t^n\cdot u(t)`. """ return self.__n += v self.__u = self.__u.valuation_zero_part()
def _repr_(self): """ EXAMPLES::
sage: R.<t> = LaurentSeriesRing(QQ) sage: (2 + (2/3)*t^3).__repr__() '2 + 2/3*t^3' """ else: else: else: return bigoh
def _latex_(self): r""" EXAMPLES::
sage: x = Frac(QQ[['x']]).0 sage: f = (17/2)*x^-2 + x + x^2 + 3*x^4 + O(x^7) sage: latex(f) \frac{\frac{17}{2}}{x^{2}} + x + x^{2} + 3x^{4} + O(x^{7})
Verify that :trac:`6656` has been fixed::
sage: R.<a,b>=PolynomialRing(QQ) sage: T.<x>=LaurentSeriesRing(R) sage: y = a*x+b*x sage: y._latex_() '\\left(a + b\\right)x' sage: latex(y) \left(a + b\right)x """ if self.prec() == infinity: return "0" else: return "0 + \\cdots" else: # negative e else: bigoh = "O(1)" bigoh = "O(%s)"%(X,) else: return bigoh
def __hash__(self):
def __getitem__(self, i): """ EXAMPLES::
sage: R.<t> = LaurentSeriesRing(QQ) sage: f = -5/t^(10) + t + t^2 - 10/3*t^3; f -5*t^-10 + t + t^2 - 10/3*t^3 sage: f[-10] -5 sage: f[1] 1 sage: f[3] -10/3 sage: f[-9] 0 sage: f = -5/t^(10) + 1/3 + t + t^2 - 10/3*t^3 + O(t^5); f -5*t^-10 + 1/3 + t + t^2 - 10/3*t^3 + O(t^5)
Slicing is deprecated::
sage: f[-10:2] doctest:...: DeprecationWarning: polynomial slicing with a start index is deprecated, use list() and slice the resulting list instead See http://trac.sagemath.org/18940 for details. -5*t^-10 + 1/3 + t + O(t^5) sage: f[0:] 1/3 + t + t^2 - 10/3*t^3 + O(t^5) """ start = 0
def __iter__(self): """ Iterate through the coefficients from the first nonzero one to the last nonzero one.
EXAMPLES::
sage: R.<t> = LaurentSeriesRing(QQ) sage: f = -5/t^(2) + t + t^2 - 10/3*t^3; f -5*t^-2 + t + t^2 - 10/3*t^3 sage: for a in f: print(a) -5 0 0 1 1 -10/3 """
def list(self): """ EXAMPLES::
sage: R.<t> = LaurentSeriesRing(QQ) sage: f = -5/t^(2) + t + t^2 - 10/3*t^3 sage: f.list() [-5, 0, 0, 1, 1, -10/3] """
def coefficients(self): """ Return the nonzero coefficients of ``self``.
EXAMPLES::
sage: R.<t> = LaurentSeriesRing(QQ) sage: f = -5/t^(2) + t + t^2 - 10/3*t^3 sage: f.coefficients() [-5, 1, 1, -10/3] """
def residue(self): r""" Return the residue of ``self``.
Consider the Laurent series
.. MATH::
f = \sum_{n \in \ZZ} a_n t^n = \cdots + \frac{a_{-2}}{t^2} + \frac{a_{-1}}{t} + a_0 + a_1 t + a_2 t^2 + \cdots,
then the residue of `f` is `a_{-1}`. Alternatively this is the coefficient of `1/t`.
EXAMPLES::
sage: t = LaurentSeriesRing(ZZ,'t').gen() sage: f = 1/t**2+2/t+3+4*t sage: f.residue() 2 sage: f = t+t**2 sage: f.residue() 0 sage: f.residue().parent() Integer Ring """
def exponents(self): """ Return the exponents appearing in self with nonzero coefficients.
EXAMPLES::
sage: R.<t> = LaurentSeriesRing(QQ) sage: f = -5/t^(2) + t + t^2 - 10/3*t^3 sage: f.exponents() [-2, 1, 2, 3] """
def laurent_polynomial(self): """ Return the corresponding Laurent polynomial.
EXAMPLES::
sage: R.<t> = LaurentSeriesRing(QQ) sage: f = t^-3 + t + 7*t^2 + O(t^5) sage: g = f.laurent_polynomial(); g t^-3 + t + 7*t^2 sage: g.parent() Univariate Laurent Polynomial Ring in t over Rational Field """
def __setitem__(self, n, value): """ EXAMPLES::
sage: R.<t> = LaurentSeriesRing(QQ) sage: f = t^2 + t^3 + O(t^10) sage: f[2] = 5 Traceback (most recent call last): ... IndexError: Laurent series are immutable """
def _unsafe_mutate(self, i, value): """ Never use this unless you really know what you are doing.
.. WARNING::
This could easily introduce subtle bugs, since Sage assumes everywhere that Laurent series are immutable. It's OK to use this if you really know what you're doing.
EXAMPLES::
sage: R.<t> = LaurentSeriesRing(QQ) sage: f = t^2 + t^3 + O(t^10); f t^2 + t^3 + O(t^10) sage: f._unsafe_mutate(2, -3) sage: f -3*t^2 + t^3 + O(t^10) """ else: # off to the left if value != 0: self.__n = self.__n + j R = self._parent.base_ring() coeffs = [value] + [R(0) for _ in range(1,-j)] + self.__u.list() self.__u = self.__u._parent(coeffs)
cpdef _add_(self, right_m): """ Add two power series with the same parent.
EXAMPLES::
sage: R.<t> = LaurentSeriesRing(QQ) sage: t + t 2*t sage: f = 1/t + t^2 + t^3 - 17/3 * t^4 + O(t^5) sage: g = 1/(1-t + O(t^7)); g 1 + t + t^2 + t^3 + t^4 + t^5 + t^6 + O(t^7) sage: f + g t^-1 + 1 + t + 2*t^2 + 2*t^3 - 14/3*t^4 + O(t^5) sage: f + 0 t^-1 + t^2 + t^3 - 17/3*t^4 + O(t^5) sage: 0 + f t^-1 + t^2 + t^3 - 17/3*t^4 + O(t^5) sage: R(0) + R(0) 0 sage: (t^3 + O(t^10)) + (t^-3 +O(t^9)) t^-3 + t^3 + O(t^9)
ALGORITHM: Shift the unit parts to align them, then add. """ cdef long m
# 1. Special case when one or the other is 0.
# 2. Align the unit parts. else: # 3. Add
cpdef _sub_(self, right_m): """ Subtract two power series with the same parent.
EXAMPLES::
sage: R.<t> = LaurentSeriesRing(QQ) sage: t - t 0 sage: t^5 + 2 * t^-5 2*t^-5 + t^5
ALGORITHM: Shift the unit parts to align them, then subtract. """ cdef long m
# 1. Special case when one or the other is 0.
# 2. Align the unit parts. else: # 3. Subtract
def add_bigoh(self, prec): """ EXAMPLES::
sage: R.<t> = LaurentSeriesRing(QQ) sage: f = t^2 + t^3 + O(t^10); f t^2 + t^3 + O(t^10) sage: f.add_bigoh(5) t^2 + t^3 + O(t^5) """
def O(self, prec): r""" Return the Laurent series of precision at most ``prec`` obtained by adding `O(q^\text{prec})`, where `q` is the variable.
The precision of ``self`` and the integer ``prec`` can be arbitrary. The resulting Laurent series will have precision equal to the minimum of the precision of ``self`` and ``prec``. The term `O(q^\text{prec})` is the zero series with precision ``prec``.
EXAMPLES::
sage: R.<t> = LaurentSeriesRing(QQ) sage: f = t^-5 + t^-4 + t^3 + O(t^10); f t^-5 + t^-4 + t^3 + O(t^10) sage: f.O(-4) t^-5 + O(t^-4) sage: f.O(15) t^-5 + t^-4 + t^3 + O(t^10) """
def degree(self): """ Return the degree of a polynomial equivalent to this power series modulo big oh of the precision.
EXAMPLES::
sage: x = Frac(QQ[['x']]).0 sage: g = x^2 - x^4 + O(x^8) sage: g.degree() 4 sage: g = -10/x^5 + x^2 - x^4 + O(x^8) sage: g.degree() 4 sage: (x^-2 + O(x^0)).degree() -2 """
def __neg__(self): """ EXAMPLES::
sage: R.<t> = LaurentSeriesRing(QQ) sage: -(1+t^5) -1 - t^5 sage: -(1/(1+t+O(t^5))) -1 + t - t^2 + t^3 - t^4 + O(t^5) """
cpdef _mul_(self, right_r): """ EXAMPLES::
sage: x = Frac(QQ[['x']]).0 sage: f = 1/x^3 + x + x^2 + 3*x^4 + O(x^7) sage: g = 1 - x + x^2 - x^4 + O(x^8) sage: f*g x^-3 - x^-2 + x^-1 + 4*x^4 + O(x^5) """
cpdef _rmul_(self, Element c):
cpdef _lmul_(self, Element c):
def __pow__(_self, r, dummy): """ EXAMPLES::
sage: x = Frac(QQ[['x']]).0 sage: f = x + x^2 + 3*x^4 + O(x^7) sage: g = 1/x^10 - x + x^2 - x^4 + O(x^8) sage: f^7 x^7 + 7*x^8 + 21*x^9 + 56*x^10 + 161*x^11 + 336*x^12 + O(x^13) sage: g^7 x^-70 - 7*x^-59 + 7*x^-58 - 7*x^-56 + O(x^-52) """ raise ValueError("exponent must be an integer")
def shift(self, k): r""" Returns this Laurent series multiplied by the power `t^n`. Does not change this series.
.. NOTE::
Despite the fact that higher order terms are printed to the right in a power series, right shifting decreases the powers of `t`, while left shifting increases them. This is to be consistent with polynomials, integers, etc.
EXAMPLES::
sage: R.<t> = LaurentSeriesRing(QQ['y']) sage: f = (t+t^-1)^4; f t^-4 + 4*t^-2 + 6 + 4*t^2 + t^4 sage: f.shift(10) t^6 + 4*t^8 + 6*t^10 + 4*t^12 + t^14 sage: f >> 10 t^-14 + 4*t^-12 + 6*t^-10 + 4*t^-8 + t^-6 sage: t << 4 t^5 sage: t + O(t^3) >> 4 t^-3 + O(t^-1)
AUTHORS:
- Robert Bradshaw (2007-04-18) """
def __lshift__(LaurentSeries self, k):
def __rshift__(LaurentSeries self, k):
def truncate(self, long n): r""" Return the Laurent series of degree ` < n` which is equivalent to self modulo `x^n`.
EXAMPLES::
sage: A.<x> = LaurentSeriesRing(ZZ) sage: f = 1/(1-x) sage: f 1 + x + x^2 + x^3 + x^4 + x^5 + x^6 + x^7 + x^8 + x^9 + x^10 + x^11 + x^12 + x^13 + x^14 + x^15 + x^16 + x^17 + x^18 + x^19 + O(x^20) sage: f.truncate(10) 1 + x + x^2 + x^3 + x^4 + x^5 + x^6 + x^7 + x^8 + x^9 """ else:
def truncate_laurentseries(self, long n): r""" Replace any terms of degree >= n by big oh.
EXAMPLES::
sage: A.<x> = LaurentSeriesRing(ZZ) sage: f = 1/(1-x) sage: f 1 + x + x^2 + x^3 + x^4 + x^5 + x^6 + x^7 + x^8 + x^9 + x^10 + x^11 + x^12 + x^13 + x^14 + x^15 + x^16 + x^17 + x^18 + x^19 + O(x^20) sage: f.truncate_laurentseries(10) 1 + x + x^2 + x^3 + x^4 + x^5 + x^6 + x^7 + x^8 + x^9 + O(x^10) """ return self._parent.zero() else:
def truncate_neg(self, long n): r""" Return the Laurent series equivalent to ``self`` except without any degree ``n`` terms.
This is equivalent to::
self - self.truncate(n)
EXAMPLES::
sage: A.<t> = LaurentSeriesRing(ZZ) sage: f = 1/(1-t) sage: f.truncate_neg(15) t^15 + t^16 + t^17 + t^18 + t^19 + O(t^20) """
cpdef _div_(self, right_r): """ EXAMPLES::
sage: x = Frac(QQ[['x']]).0 sage: f = x + x^2 + 3*x^4 + O(x^7) sage: g = 1/x^7 - x + x^2 - x^4 + O(x^8) sage: f/x 1 + x + 3*x^3 + O(x^6) sage: f/g x^8 + x^9 + 3*x^11 + O(x^14) """ raise ZeroDivisionError # todo: this could also make something in the formal fraction field. raise ArithmeticError("division not defined")
def common_prec(self, other): r""" Return the minimum precision of ``self`` and ``other``.
EXAMPLES::
sage: R.<t> = LaurentSeriesRing(QQ)
::
sage: f = t^(-1) + t + t^2 + O(t^3) sage: g = t + t^3 + t^4 + O(t^4) sage: f.common_prec(g) 3 sage: g.common_prec(f) 3
::
sage: f = t + t^2 + O(t^3) sage: g = t^(-3) + t^2 sage: f.common_prec(g) 3 sage: g.common_prec(f) 3
::
sage: f = t + t^2 sage: g = t^2 sage: f.common_prec(g) +Infinity
::
sage: f = t^(-3) + O(t^(-2)) sage: g = t^(-5) + O(t^(-1)) sage: f.common_prec(g) -2
::
sage: f = O(t^2) sage: g = O(t^5) sage: f.common_prec(g) 2 """
def common_valuation(self, other): """ Return the minimum valuation of ``self`` and ``other``.
EXAMPLES::
sage: R.<t> = LaurentSeriesRing(QQ)
::
sage: f = t^(-1) + t + t^2 + O(t^3) sage: g = t + t^3 + t^4 + O(t^4) sage: f.common_valuation(g) -1 sage: g.common_valuation(f) -1
::
sage: f = t + t^2 + O(t^3) sage: g = t^(-3) + t^2 sage: f.common_valuation(g) -3 sage: g.common_valuation(f) -3
::
sage: f = t + t^2 sage: g = t^2 sage: f.common_valuation(g) 1
::
sage: f = t^(-3) + O(t^(-2)) sage: g = t^(-5) + O(t^(-1)) sage: f.common_valuation(g) -5
::
sage: f = O(t^2) sage: g = O(t^5) sage: f.common_valuation(g) +Infinity """
cpdef _richcmp_(self, right_r, int op): r""" Comparison of ``self`` and ``right``.
We say two approximate Laurent series are equal, if they agree for all coefficients up to the *minimum* of the precisions of each. Comparison is done in dictionary order from lowest degree to highest degree coefficients. This is different than polynomials, but consistent with the idea that the variable of a Laurent series is considered to be "very small".
See :meth:`power_series_ring_element._richcmp_` for more information.
EXAMPLES::
sage: R.<x> = LaurentSeriesRing(QQ) sage: f = x^(-1) + 1 + x + O(x^2) sage: g = x^(-1) + 1 + O(x) sage: f == g True
::
sage: f = x^(-1) + 1 + x + O(x^2) sage: g = x^(-1) + 2 + O(x) sage: f == g False sage: f < g True sage: f > g False
::
sage: f = x^(-2) + 1 + x + O(x^2) sage: g = x^(-1) + 2 + O(x) sage: f == g False sage: f < g False sage: f > g True
Check that :trac:`19664` is fixed::
sage: R.<x> = LaurentSeriesRing(RR) sage: x^(10^9) > 0 True """
cdef long i cdef int c
def valuation_zero_part(self): """ EXAMPLES::
sage: x = Frac(QQ[['x']]).0 sage: f = x + x^2 + 3*x^4 + O(x^7) sage: f/x 1 + x + 3*x^3 + O(x^6) sage: f.valuation_zero_part() 1 + x + 3*x^3 + O(x^6) sage: g = 1/x^7 - x + x^2 - x^4 + O(x^8) sage: g.valuation_zero_part() 1 - x^8 + x^9 - x^11 + O(x^15) """
def valuation(self): """ EXAMPLES::
sage: R.<x> = LaurentSeriesRing(QQ) sage: f = 1/x + x^2 + 3*x^4 + O(x^7) sage: g = 1 - x + x^2 - x^4 + O(x^8) sage: f.valuation() -1 sage: g.valuation() 0
Note that the valuation of an element undistinguishable from zero is infinite::
sage: h = f - f; h O(x^7) sage: h.valuation() +Infinity
TESTS:
The valuation of the zero element is ``+Infinity`` (see :trac:`15088`)::
sage: zero = R(0) sage: zero.valuation() +Infinity """
def variable(self): """ EXAMPLES::
sage: x = Frac(QQ[['x']]).0 sage: f = 1/x + x^2 + 3*x^4 + O(x^7) sage: f.variable() 'x' """
def prec(self): """ This function returns the n so that the Laurent series is of the form (stuff) + `O(t^n)`. It doesn't matter how many negative powers appear in the expansion. In particular, prec could be negative.
EXAMPLES::
sage: x = Frac(QQ[['x']]).0 sage: f = x^2 + 3*x^4 + O(x^7) sage: f.prec() 7 sage: g = 1/x^10 - x + x^2 - x^4 + O(x^8) sage: g.prec() 8 """
def precision_absolute(self): """ Return the absolute precision of this series.
By definition, the absolute precision of `...+O(x^r)` is `r`.
EXAMPLES::
sage: R.<t> = ZZ[[]] sage: (t^2 + O(t^3)).precision_absolute() 3 sage: (1 - t^2 + O(t^100)).precision_absolute() 100 """
def precision_relative(self): """ Return the relative precision of this series, that is the difference between its absolute precision and its valuation.
By convention, the relative precision of `0` (or `O(x^r)` for any `r`) is `0`.
EXAMPLES::
sage: R.<t> = ZZ[[]] sage: (t^2 + O(t^3)).precision_relative() 1 sage: (1 - t^2 + O(t^100)).precision_relative() 100 sage: O(t^4).precision_relative() 0 """ if self.is_zero(): return 0 else: return self.prec() - self.valuation()
def __copy__(self): return type(self)(self._parent, self.__u.copy(), self.__n)
def derivative(self, *args): """ The formal derivative of this Laurent series, with respect to variables supplied in args.
Multiple variables and iteration counts may be supplied; see documentation for the global derivative() function for more details.
.. SEEALSO::
:meth:`_derivative`
EXAMPLES::
sage: R.<x> = LaurentSeriesRing(QQ) sage: g = 1/x^10 - x + x^2 - x^4 + O(x^8) sage: g.derivative() -10*x^-11 - 1 + 2*x - 4*x^3 + O(x^7) sage: g.derivative(x) -10*x^-11 - 1 + 2*x - 4*x^3 + O(x^7)
::
sage: R.<t> = PolynomialRing(ZZ) sage: S.<x> = LaurentSeriesRing(R) sage: f = 2*t/x + (3*t^2 + 6*t)*x + O(x^2) sage: f.derivative() -2*t*x^-2 + (3*t^2 + 6*t) + O(x) sage: f.derivative(x) -2*t*x^-2 + (3*t^2 + 6*t) + O(x) sage: f.derivative(t) 2*x^-1 + (6*t + 6)*x + O(x^2) """
def _derivative(self, var=None): """ The formal derivative of this Laurent series with respect to var.
If var is None or the generator of this ring, it's the formal derivative as expected. Otherwise, _derivative(var) gets called recursively on each coefficient.
.. SEEALSO::
:meth:`derivative`
EXAMPLES::
sage: x = Frac(QQ[['x']]).0 sage: f = x^2 + 3*x^4 + O(x^7) sage: f._derivative() 2*x + 12*x^3 + O(x^6) sage: f._derivative(x) 2*x + 12*x^3 + O(x^6) sage: g = 1/x^10 - x + x^2 - x^4 + O(x^8) sage: g._derivative() -10*x^-11 - 1 + 2*x - 4*x^3 + O(x^7)
Differentiating with respect to something other than the generator gets recursed into the base ring::
sage: R.<t> = PolynomialRing(ZZ) sage: S.<x> = LaurentSeriesRing(R) sage: f = 2*t/x + (3*t^2 + 6*t)*x + O(x^2) sage: f._derivative(t) 2*x^-1 + (6*t + 6)*x + O(x^2) """ # call _derivative() recursively on coefficients
# compute formal derivative with respect to generator
def integral(self): r""" The formal integral of this Laurent series with 0 constant term.
EXAMPLES: The integral may or may not be defined if the base ring is not a field.
::
sage: t = LaurentSeriesRing(ZZ, 't').0 sage: f = 2*t^-3 + 3*t^2 + O(t^4) sage: f.integral() -t^-2 + t^3 + O(t^5)
::
sage: f = t^3 sage: f.integral() Traceback (most recent call last): ... ArithmeticError: Coefficients of integral cannot be coerced into the base ring
The integral of 1/t is `\log(t)`, which is not given by a Laurent series::
sage: t = Frac(QQ[['t']]).0 sage: f = -1/t^3 - 31/t + O(t^3) sage: f.integral() Traceback (most recent call last): ... ArithmeticError: The integral of is not a Laurent series, since t^-1 has nonzero coefficient.
Another example with just one negative coefficient::
sage: A.<t> = QQ[[]] sage: f = -2*t^(-4) + O(t^8) sage: f.integral() 2/3*t^-3 + O(t^9) sage: f.integral().derivative() == f True """
else:
def nth_root(self, long n, prec=None): r""" Return the ``n``-th root of this Laurent power series.
INPUT:
- ``n`` -- integer
- ``prec`` -- integer (optional) - precision of the result. Though, if this series has finite precision, then the result can not have larger precision.
EXAMPLES::
sage: R.<x> = LaurentSeriesRing(QQ) sage: (x^-2 + 1 + x).nth_root(2) x^-1 + 1/2*x + 1/2*x^2 - ... - 19437/65536*x^18 + O(x^19) sage: (x^-2 + 1 + x).nth_root(2)**2 x^-2 + 1 + x + O(x^18)
sage: j = j_invariant_qexp() sage: q = j.parent().gen() sage: j(q^3).nth_root(3) q^-1 + 248*q^2 + 4124*q^5 + ... + O(q^29) sage: (j(q^2) - 1728).nth_root(2) q^-1 - 492*q - 22590*q^3 - ... + O(q^19) """ else: prec = min(self.prec(), prec)
raise ValueError('n must be positive')
raise ValueError('valuation must be divisible by n')
def power_series(self): """ EXAMPLES::
sage: R.<t> = LaurentSeriesRing(ZZ) sage: f = 1/(1-t+O(t^10)); f.parent() Laurent Series Ring in t over Integer Ring sage: g = f.power_series(); g 1 + t + t^2 + t^3 + t^4 + t^5 + t^6 + t^7 + t^8 + t^9 + O(t^10) sage: parent(g) Power Series Ring in t over Integer Ring sage: f = 3/t^2 + t^2 + t^3 + O(t^10) sage: f.power_series() Traceback (most recent call last): ... TypeError: self is not a power series
TESTS:
Check whether a polynomial over a Laurent series ring is contained in the polynomial ring over the power series ring (see :trac:`19459`):
sage: L.<t> = LaurentSeriesRing(GF(2)) sage: R.<x,y> = PolynomialRing(L) sage: O = L._power_series_ring sage: S.<x,y> = PolynomialRing(O) sage: t**(-1)*x*y in S False """
def inverse(self): """ Return the inverse of self, i.e., self^(-1).
EXAMPLES::
sage: R.<t> = LaurentSeriesRing(ZZ) sage: t.inverse() t^-1 sage: (1-t).inverse() 1 + t + t^2 + t^3 + t^4 + t^5 + t^6 + t^7 + t^8 + ... """
def __call__(self, *x, **kwds): """ Compute value of this Laurent series at x.
EXAMPLES::
sage: P.<x, y> = ZZ[] sage: R.<t> = LaurentSeriesRing(P) sage: f = x*t^-2 + y*t^2 + O(t^8) sage: f(t^3) x*t^-6 + y*t^6 + O(t^24) sage: f(t=t^3) x*t^-6 + y*t^6 + O(t^24) sage: f(t + O(t^5)) x*t^-2 + O(t^2) sage: f(y=x) x*t^-2 + x*t^2 + O(t^8) sage: f(t^3, x=2, y=x+x^2) 2*t^-6 + (x^2 + x)*t^6 + O(t^24) sage: f(t^3, 2, x+x^2) 2*t^-6 + (x^2 + x)*t^6 + O(t^24) sage: f(x=2, t=t^3, y=x+x^2) 2*t^-6 + (x^2 + x)*t^6 + O(t^24) sage: f(2, x+x^2, t=t^3) Traceback (most recent call last): ... ValueError: must not specify t keyword and positional argument
It is only possible to substitute elements of positive valuation::
sage: f(t^-2) Traceback (most recent call last): ... ValueError: Can only substitute elements of positive valuation
Test for :trac:`23928`::
sage: R.<x> = PowerSeriesRing(QQ, implementation='pari') sage: f = LaurentSeries(R, x).add_bigoh(7) sage: f(x) x + O(x^7) """ except TypeError: return a except TypeError: return a else: # keywords but no positional arguments
x = x[0]
|