Truncated Laurent series
Chevie.Truncs — Module
module Trunc: truncated Laurent series
This module depends on the package LaurentPolynomials.
The main function to construct a truncated series is:
julia> @Pol x
Pol{Int64}: x
julia> p=(x+x^2)^5
Pol{Int64}: x¹⁰+5x⁹+10x⁸+10x⁷+5x⁶+x⁵
julia> tp=Trunc(p,4)
Trunc(4): x⁵+5x⁶+10x⁷+10x⁸+O(x⁹)The result here is a truncated series with 4 terms. You can do various operations with series
julia> inv(tp)
Trunc(4): x⁻⁵-5x⁻⁴+15x⁻³-35x⁻²+O(x⁻¹)
julia> inv(tp)*tp
Trunc(4): 1+O(x⁴)
julia> tp*2
Trunc(4): 2x⁵+10x⁶+20x⁷+20x⁸+O(x⁹)By default the variable name to print Truncs is the same as for Pols. You can change that:
julia> Truncs.varname=:q
:q
julia> tp
Trunc(4): q⁵+5q⁶+10q⁷+10q⁸+O(q⁹)
julia> length(tp) # the number of terms
4
julia> tp+1 # "loss of precision"
Trunc(4): 1+O(q⁴)
julia> tp+Pol()^5 # ok here
Trunc(4): 2q⁵+5q⁶+10q⁷+10q⁸+O(q⁹)
julia> tp-Trunc(Pol()^5,4) # true loss of precision
Trunc(3): 5q⁶+10q⁷+10q⁸+O(q⁹)As for Pols, indexing gets the term of a given degree
julia> tp[1]
0
julia> tp[6]
5You can convert directly to Trunc a rational fraction:
julia> a=(3Pol()^-2+1)/p
Frac{Pol{Int64}}: (x²+3)/(x¹²+5x¹¹+10x¹⁰+10x⁹+5x⁸+x⁷)
julia> Trunc(a,4)
Trunc(4): 3q⁻⁷-15q⁻⁶+46q⁻⁵-110q⁻⁴+O(q⁻³)
julia> Trunc(a,4)*tp
Trunc(4): 3q⁻²+1+O(q²)We provide also convenience functions for Mvps.
julia> @Mvp x,y
julia> den=x-y
Mvp{Int64}: x-y
julia> frac=(x+y)/den
Frac{Mvp{Int64, Int64}}: (x+y)/(x-y)
julia> Truncs.varname=:x
:x
julia> tden=Trunc(den,4,:x) # convenience for Trunc(Pol(den,:x),4)
Trunc(4): -y+x+O(x⁴)
julia> tfrac=Trunc(frac,4,:x)
Trunc(4): -1-2y⁻¹x-2y⁻²x²-2y⁻³x³+O(x⁴)
julia> tden*tfrac
Trunc(4): y+x+O(x⁴)We also have Padé approximants:
ulia> pade(inv(Trunc(p,9)))
Frac{Pol{Rational{Int64}}}: ((1//70)x⁴+(-1//14)x³+(3//14)x²+(-1//2)x+1)/((9//5)x⁹+6x⁸+(54//7)x⁷+(9//2)x⁶+x⁵)
julia> pade(inv(Trunc(p,10)))
Frac{Pol{Rational{Int64}}}: 1/(x¹⁰+5x⁹+10x⁸+10x⁷+5x⁶+x⁵)Chevie.Truncs.Trunc — Type
Trunc(p::Pol,i::Integer)
returns the truncated Laurent series for p with i terms
julia> p=Pol([2,0,1],-1)
Pol{Int64}: x+2x⁻¹
julia> Trunc(p,4)
Trunc(4): 2x⁻¹+x+O(x³)Chevie.Truncs.pade — Function
pade(f::Trunc,i=length(f)) Padé approximant
returns the Padé approximant rational fraction for f. If i is given then uses only the i first terms of f.
julia> @Pol x
Pol{Int64}: x
julia> f=inv(Trunc(x^3+2x+1,6))
Trunc(6): 1-2x+4x²-9x³+20x⁴-44x⁵+O(x⁶)
julia> pade(f)
Frac{Pol{Rational{Int64}}}: 1/(x³+2x+1)The algorithm is based on (Sokal, 2023; refined algorithm 2.7).