# Big O for various types (power series, p-adics, etc.)#

sage.rings.big_oh.O(*x, **kwds)[source]#

Big O constructor for various types.

EXAMPLES:

This is useful for writing power series elements:

sage: R.<t> = ZZ[['t']]
sage: (1+t)^10 + O(t^5)
1 + 10*t + 45*t^2 + 120*t^3 + 210*t^4 + O(t^5)

>>> from sage.all import *
>>> R = ZZ[['t']]; (t,) = R._first_ngens(1)
>>> (Integer(1)+t)**Integer(10) + O(t**Integer(5))
1 + 10*t + 45*t^2 + 120*t^3 + 210*t^4 + O(t^5)


A power series ring is created implicitly if a polynomial element is passed:

sage: R.<x> = QQ['x']
sage: O(x^100)
O(x^100)
sage: 1/(1+x+O(x^5))
1 - x + x^2 - x^3 + x^4 + O(x^5)
sage: R.<u,v> = QQ[[]]
sage: 1 + u + v^2 + O(u, v)^5
1 + u + v^2 + O(u, v)^5

>>> from sage.all import *
>>> R = QQ['x']; (x,) = R._first_ngens(1)
>>> O(x**Integer(100))
O(x^100)
>>> Integer(1)/(Integer(1)+x+O(x**Integer(5)))
1 - x + x^2 - x^3 + x^4 + O(x^5)
>>> R = QQ[['u, v']]; (u, v,) = R._first_ngens(2)
>>> Integer(1) + u + v**Integer(2) + O(u, v)**Integer(5)
1 + u + v^2 + O(u, v)^5


This is also useful to create $$p$$-adic numbers:

sage: O(7^6)                                                                    # needs sage.rings.padics
O(7^6)
sage: 1/3 + O(7^6)                                                              # needs sage.rings.padics
5 + 4*7 + 4*7^2 + 4*7^3 + 4*7^4 + 4*7^5 + O(7^6)

>>> from sage.all import *
O(7^6)
>>> Integer(1)/Integer(3) + O(Integer(7)**Integer(6))                                                              # needs sage.rings.padics
5 + 4*7 + 4*7^2 + 4*7^3 + 4*7^4 + 4*7^5 + O(7^6)


It behaves well with respect to adding negative powers of $$p$$:

sage: a = O(11^-32); a                                                          # needs sage.rings.padics
O(11^-32)
11-adic Field with capped relative precision 20

>>> from sage.all import *
>>> a = O(Integer(11)**-Integer(32)); a                                                          # needs sage.rings.padics
O(11^-32)
11-adic Field with capped relative precision 20


There are problems if you add a rational with very negative valuation to an $$O$$-Term:

sage: 11^-12 + O(11^15)                                                         # needs sage.rings.padics
11^-12 + O(11^8)

>>> from sage.all import *
>>> Integer(11)**-Integer(12) + O(Integer(11)**Integer(15))                                                         # needs sage.rings.padics
11^-12 + O(11^8)


The reason that this fails is that the constructor doesn’t know the right precision cap to use. If you cast explicitly or use other means of element creation, you can get around this issue:

sage: # needs sage.rings.padics
sage: K = Qp(11, 30)
sage: K(11^-12) + O(11^15)
11^-12 + O(11^15)
sage: 11^-12 + K(O(11^15))
11^-12 + O(11^15)
sage: K(11^-12, absprec=15)
11^-12 + O(11^15)
sage: K(11^-12, 15)
11^-12 + O(11^15)

>>> from sage.all import *
>>> K = Qp(Integer(11), Integer(30))
>>> K(Integer(11)**-Integer(12)) + O(Integer(11)**Integer(15))
11^-12 + O(11^15)
>>> Integer(11)**-Integer(12) + K(O(Integer(11)**Integer(15)))
11^-12 + O(11^15)
>>> K(Integer(11)**-Integer(12), absprec=Integer(15))
11^-12 + O(11^15)
>>> K(Integer(11)**-Integer(12), Integer(15))
11^-12 + O(11^15)


We can also work with asymptotic expansions:

sage: A.<n> = AsymptoticRing(growth_group='QQ^n * n^QQ * log(n)^QQ',            # needs sage.symbolic
....:                        coefficient_ring=QQ); A
Asymptotic Ring <QQ^n * n^QQ * log(n)^QQ * Signs^n> over Rational Field
sage: O(n)                                                                      # needs sage.symbolic
O(n)

>>> from sage.all import *
>>> A = AsymptoticRing(growth_group='QQ^n * n^QQ * log(n)^QQ',            # needs sage.symbolic
...                        coefficient_ring=QQ, names=('n',)); (n,) = A._first_ngens(1); A
Asymptotic Ring <QQ^n * n^QQ * log(n)^QQ * Signs^n> over Rational Field
>>> O(n)                                                                      # needs sage.symbolic
O(n)


Application with Puiseux series:

sage: P.<y> = PuiseuxSeriesRing(ZZ)
sage: y^(1/5) + O(y^(1/3))
y^(1/5) + O(y^(1/3))
sage: y^(1/3) + O(y^(1/5))
O(y^(1/5))

>>> from sage.all import *
>>> P = PuiseuxSeriesRing(ZZ, names=('y',)); (y,) = P._first_ngens(1)
>>> y**(Integer(1)/Integer(5)) + O(y**(Integer(1)/Integer(3)))
y^(1/5) + O(y^(1/3))
>>> y**(Integer(1)/Integer(3)) + O(y**(Integer(1)/Integer(5)))
O(y^(1/5))