pyranha.math
¶Math module.
pyranha.math.
binomial
(x, y)[source]¶Binomial coefficient.
This function is a wrapper around a lower level function. It will calculate the generalised binomial coefficient \({x \choose y}\), supporting various combinations of integral, rational, floating-point and arbitrary-precision floating-point types as input.
Parameters: |
|
---|---|
Returns: | x choose y |
Raises: |
|
Raises: | any exception raised by the invoked low-level function |
>>> binomial(3,2)
3
>>> binomial(-6,2)
21
>>> from fractions import Fraction as F
>>> binomial(F(-4,5),2)
Fraction(18, 25)
>>> binomial(10,2.4)
70.3995282...
>>> binomial('hello world',2.4)
Traceback (most recent call last):
...
TypeError: invalid argument type(s)
pyranha.math.
cos
(arg)[source]¶Cosine.
The supported types are int
, float
, Fraction
, mpf
and any symbolic type that supports
the operation.
Parameters: | arg (int , float , Fraction , mpf , or a supported symbolic type.) – cosine argument |
---|---|
Returns: | cosine of arg |
Raises: | TypeError if the type of arg is not supported, or any other exception raised by the invoked
low-level function |
>>> cos(0)
1
>>> cos(2)
Traceback (most recent call last):
...
ValueError: cannot compute the cosine of a non-zero integer
>>> cos(2.)
-0.4161468...
>>> from pyranha.types import poisson_series, polynomial, rational, int16, monomial
>>> t = poisson_series[polynomial[rational,monomial[int16]]]()
>>> cos(2 * t('x'))
cos(2*x)
>>> cos('hello')
Traceback (most recent call last):
...
TypeError: invalid argument type(s)
pyranha.math.
degree
(arg, names=None)[source]¶Degree.
This function will return the degree of the input argument. Various symbolic types are supported as input
(e.g., polynomials, Poisson series, etc.). If names is None
, then the total degree is
returned. Otherwise, names must be a list of strings enumerating the variables to be considered for the
computation of the partial degree.
Parameters: |
|
---|---|
Returns: | the degree of arg |
Raises: |
|
>>> from pyranha.types import polynomial, rational, k_monomial
>>> t = polynomial[rational,k_monomial]()
>>> x,y,z = t('x'),t('y'),t('z')
>>> degree(x**3+y*z) == 3
True
>>> degree(x**3+y*z,['z']) == 1
True
>>> from fractions import Fraction as F
>>> degree(F(1,2))
Traceback (most recent call last):
...
TypeError: invalid argument type(s)
pyranha.math.
evaluate
(arg, eval_dict)[source]¶Evaluation.
This function will evaluate arg according to the evaluation dictionary eval_dict. Evaluation is the replacement of all symbolic quantities with numerical values.
eval_dict must be a dictionary of (name,value)
pairs, where name
is a string referring to the symbol
to be replaced and value
is the value with which name
will be replaced. All values must be of the same type,
and this type needs to support the operations needed to compute the evaluation.
Parameters: |
|
---|---|
Returns: | the evaluation of arg according to eval_dict |
Raises: |
|
Raises: |
|
Raises: | any exception raised by the invoked low-level function |
>>> from pyranha.types import polynomial, rational, k_monomial
>>> pt = polynomial[rational,k_monomial]()
>>> x,y,z = pt('x'), pt('y'), pt('z')
>>> evaluate(x*y+4*(y/4)**2*z,{'x':3,'y':-3,'z':5})
Fraction(9, 4)
>>> evaluate(x*y+4*(y/4)**2*z,{'x':3.01,'y':-3.32,'z':5.34})
4.7217...
>>> evaluate(x*y+4*(y/4)**2*z,{'x':3.1,'y':-3.2,'z':5})
Traceback (most recent call last):
...
TypeError: all values in the evaluation dictionary must be of the same type
>>> evaluate(x*y+4*(y/4)**2*z,{})
Traceback (most recent call last):
...
ValueError: evaluation dictionary cannot be empty
>>> evaluate(x*y+4*(y/4)**2*z,{'x':3,'y':-3,5:5})
Traceback (most recent call last):
...
TypeError: all keys in the evaluation dictionary must be string objects
>>> evaluate(x*y+4*(y/4)**2*z,[1,2,3])
Traceback (most recent call last):
...
TypeError: evaluation dictionary must be a dict object
>>> evaluate(x*y+4*(y/4)**2*z,{'x':3,'y':-3})
Traceback (most recent call last):
...
ValueError: invalid positions map for evaluation
>>> evaluate(x*y+4*(y/4)**2*z,{'x':'a','y':'b', 'z':'c'})
Traceback (most recent call last):
...
TypeError: invalid argument type(s)
pyranha.math.
factorial
(n)[source]¶Factorial.
Will compute the factorial of n, which must be a non-negative instance of int
.
Parameters: | n (int ) – argument for the factorial |
---|---|
Returns: | factorial of n |
Raises: | TypeError if n is not an int |
Raises: | ValueError if n is negative or too large |
>>> factorial(0)
1
>>> factorial(6)
720
>>> factorial(-1)
Traceback (most recent call last):
...
ValueError: invalid argument value
>>> factorial(1.5)
Traceback (most recent call last):
...
TypeError: factorial argument must be an integer
pyranha.math.
gcd
(x, y)[source]¶Greatest common divisor.
This function is a wrapper around a lower level function. It will calculate the GCD of x and y,
supporting int
as argument type.
Parameters: |
|
---|---|
Returns: | the GCD of x and y |
Raises: |
|
Raises: | any exception raised by the invoked low-level function |
>>> gcd(12,9)
3
>>> from pyranha.types import polynomial, integer, k_monomial
>>> pt = polynomial[integer,k_monomial]()
>>> x,y = pt('x'), pt('y')
>>> gcd(x**-1,y)
Traceback (most recent call last):
...
TypeError: invalid argument type(s)
pyranha.math.
integrate
(arg, name)[source]¶Integration.
Compute the antiderivative of arg with respect to the variable name. arg must be a symbolic type and name a string. The success of the operation is not guaranteed, and depends both on the type and value of arg.
Parameters: |
|
---|---|
Returns: | antiderivative of arg with respect to name |
Raises: |
|
>>> from pyranha.types import polynomial, rational, k_monomial
>>> pt = polynomial[rational,k_monomial]()
>>> x,y = pt('x'), pt('y')
>>> integrate(x + 2*x*y,'x') == x**2/2 + x**2*y
True
>>> integrate(x**-1,'x')
Traceback (most recent call last):
...
ValueError: negative unitary exponent
>>> integrate(x**-1,1)
Traceback (most recent call last):
...
TypeError: invalid argument type(s)
pyranha.math.
invert
(arg)[source]¶Inverse.
Compute the multiplicative inverse of the argument.
The supported types are int
, float
, Fraction
, mpf
and any symbolic type that supports
the operation.
Parameters: | arg (int , float , Fraction , mpf , or a supported symbolic type.) – inversion argument |
---|---|
Returns: | inverse of arg |
Raises: | TypeError if the type of arg is not supported, or any other exception raised by the invoked
low-level function |
>>> from fractions import Fraction as F
>>> invert(F(1,2))
Fraction(2, 1)
>>> invert(1.23)
0.8130081...
>>> invert(0)
Traceback (most recent call last):
...
ZeroDivisionError: division by zero
>>> from pyranha.types import polynomial, rational, int16, monomial, divisor, divisor_series
>>> t = polynomial[rational,monomial[int16]]()
>>> invert(t('x'))
x**-1
>>> t = divisor_series[polynomial[rational,monomial[int16]],divisor[int16]]()
>>> invert(-2*t('x')+8*t('y'))
-1/2*1/[(x-4*y)]
>>> invert(t('x')+1)
Traceback (most recent call last):
...
ValueError: invalid argument for series exponentiation: negative integral value
>>> invert('hello')
Traceback (most recent call last):
...
TypeError: invalid argument type(s)
pyranha.math.
ipow_subs
(arg, name, n, x)[source]¶Integral power substitution.
This function will replace, in arg, the n-th power of the symbol called name with the generic object x. Internally, the functionality is implemented via a call to a lower-level C++ routine that supports various combinations for the types of arg and x.
Parameters: |
|
---|---|
Returns: | arg after the substitution of n-th power of the symbol called name with x |
Raises: |
|
Raises: | any exception raised by the invoked low-level function |
>>> from pyranha.types import rational, polynomial, int16, monomial
>>> pt = polynomial[rational,monomial[int16]]()
>>> x,y,z = pt('x'), pt('y'), pt('z')
>>> ipow_subs(x**5*y,'x',2,z)
x*y*z**2
>>> ipow_subs(x**6*y,'x',2,z**-1)
y*z**-3
>>> ipow_subs(x**6*y,0,2,z**-1)
Traceback (most recent call last):
...
TypeError: invalid argument type(s)
>>> ipow_subs(x**6*y,'x',2.1,z**-1)
Traceback (most recent call last):
...
TypeError: invalid argument type(s)
pyranha.math.
lambdify
(t, x, names, extra_map={})[source]¶Turn a symbolic object into a function.
This function is a wrapper around evaluate()
which returns a callable object that can be used
to evaluate the input argument x. The call operator of the returned object takes as input a collection of length
len(names)
of objects of type t which, for the purpose of evaluation, are associated to the list of
symbols names at the corresponding positions.
The optional argument extra_map is a dictionary that maps symbol names to callables, and it used to specify what values to assign to specific symbols based on the values of the symbols in names. For instance, suppose that \(z\) depends on \(x\) and \(y\) via \(z\left(x,y\right)=\sqrt{3x+y}\). We can then evaluate the expression \(x+y+z\) as follows:
>>> from pyranha.types import polynomial, rational, k_monomial
>>> pt = polynomial[rational,k_monomial]()
>>> x,y,z = x,y,z = pt('x'),pt('y'),pt('z')
>>> l = lambdify(float,x+y+z,['x','y'],{'z': lambda a: (3.*a[0] + a[1])**.5})
>>> l([1.,2.])
5.236067977...
The output value is \(1+2+\sqrt{5}\).
Parameters: |
|
---|---|
Returns: | a callable object that can be used to evaluate x with objects of type t |
Return type: | the type returned by the invoked low-level function |
Raises: |
|
Raises: |
|
Raises: |
|
>>> from pyranha.types import polynomial, rational, k_monomial
>>> pt = polynomial[rational,k_monomial]()
>>> x,y,z = x,y,z = pt('x'),pt('y'),pt('z')
>>> l = lambdify(int,2*x-y+3*z,['z','y','x'])
>>> l([1,2,3])
Fraction(7, 1)
>>> l([1,2,-3])
Fraction(-5, 1)
>>> l = lambdify(float,x+y+z,['x','y'],{'z': lambda a: (3.*a[0] + a[1])**.5})
>>> l([1.,2.])
5.236067977...
>>> l([1])
Traceback (most recent call last):
...
ValueError: invalid size of the evaluation vector
>>> l = lambdify(3,2*x-y+3*z,['z','y','x'])
Traceback (most recent call last):
...
TypeError: the 't' argument must be a type
>>> l = lambdify(int,2*x-y+3*z,[1,2,3])
Traceback (most recent call last):
...
TypeError: the 'names' argument must be a list of strings
>>> l = lambdify(int,2*x-y+3*z,['z','y','x','z'])
Traceback (most recent call last):
...
ValueError: the 'names' argument contains duplicates
>>> l = lambdify(float,x+y+z,['x','y'],{'z': 123})
Traceback (most recent call last):
...
TypeError: all the values in the 'extra_map' argument must be callables
pyranha.math.
ldegree
(arg, names=None)[source]¶Low degree.
This function will return the low degree of the input argument. Various symbolic types are supported as input
(e.g., polynomials, Poisson series, etc.). If names is None
, then the total low degree is
returned. Otherwise, names must be a list of strings enumerating the variables to be considered for the
computation of the partial low degree.
Parameters: |
|
---|---|
Returns: | the low degree of arg |
Raises: |
|
>>> from pyranha.types import polynomial, rational, k_monomial
>>> t = polynomial[rational,k_monomial]()
>>> x,y,z = t('x'),t('y'),t('z')
>>> ldegree(x**3+y*z) == 2
True
>>> ldegree(x**3+y*x,['x']) == 1
True
>>> from fractions import Fraction as F
>>> ldegree(F(1,2))
Traceback (most recent call last):
...
TypeError: invalid argument type(s)
pyranha.math.
partial
(arg, name)[source]¶Partial derivative.
Compute the partial derivative of arg with respect to the variable name. arg must be a symbolic type and name a string.
Parameters: |
|
---|---|
Returns: | partial derivative of arg with respect to name |
Raises: |
|
>>> from pyranha.types import polynomial, integer, int16, monomial
>>> pt = polynomial[integer,monomial[int16]]()
>>> x,y = pt('x'), pt('y')
>>> partial(x + 2*x*y,'y')
2*x
>>> partial(x + 2*x*y,1)
Traceback (most recent call last):
...
TypeError: invalid argument type(s)
pyranha.math.
pbracket
(f, g, p_list, q_list)[source]¶Poisson bracket.
Compute the Poisson bracket of f and g with respect to the momenta with names in p_list and coordinates with names in q_list. f and g must be symbolic objects of the same type, and p_list and q_list lists of strings with the same size and no duplicate entries.
Parameters: |
|
---|---|
Returns: | Poisson bracket of f and g with respect to momenta p_list and coordinates q_list |
Raises: |
|
Raises: |
|
Raises: | any exception raised by the invoked low-level function |
>>> from pyranha.types import polynomial, rational, int16, monomial
>>> pt = polynomial[rational,monomial[int16]]()
>>> x,v = pt('x'), pt('v')
>>> pbracket(x+v,x+v,['v'],['x']) == 0
True
>>> pbracket(x+v,x+v,[],['x'])
Traceback (most recent call last):
...
ValueError: the number of coordinates is different from the number of momenta
>>> pbracket(x+v,x+v,['v','v'],['x'])
Traceback (most recent call last):
...
ValueError: the list of momenta contains duplicate entries
>>> pbracket(v,x,['v'],[1])
Traceback (most recent call last):
...
TypeError: invalid argument type(s)
pyranha.math.
sin
(arg)[source]¶Sine.
The supported types are int
, float
, Fraction
, mpf
and any symbolic type that supports
the operation.
Parameters: | arg (int , float , Fraction , mpf , or a supported symbolic type.) – sine argument |
---|---|
Returns: | sine of arg |
Raises: | TypeError if the type of arg is not supported, or any other exception raised by the invoked
low-level function |
>>> sin(0)
0
>>> sin(2)
Traceback (most recent call last):
...
ValueError: cannot compute the cosine of a non-zero integer
>>> sin(2.)
0.9092974...
>>> from pyranha.types import poisson_series, polynomial, rational, int16, monomial
>>> t = poisson_series[polynomial[rational,monomial[int16]]]()
>>> sin(2 * t('x'))
sin(2*x)
>>> sin('hello')
Traceback (most recent call last):
...
TypeError: invalid argument type(s)
pyranha.math.
subs
(arg, subs_dict)[source]¶Substitution.
This function will replace, in arg, the symbols listed in the dictionary subs_dict with their mapped values. Internally, the functionality is implemented via a call to a lower-level C++ routine that supports various combinations of input argument types.
subs_dict must be a dictionary of (name,value)
pairs, where name
is a string referring to the symbol
to be substituted and value
is the value with which name
will be replaced. All values must be
of the same type, and this type needs to support the operations needed to compute the
substitution.
Parameters: |
|
---|---|
Returns: | arg after the substitution of the symbols in subs_dict with the mapped values |
Raises: |
|
Raises: |
|
Raises: | any exception raised by the invoked low-level function |
>>> from pyranha.types import polynomial, rational, k_monomial
>>> pt = polynomial[rational,k_monomial]()
>>> x,y,z = pt('x'), pt('y'), pt('z')
>>> subs(x*y+4*(y/4)**2*z,{'x':3,'y':-3,'z':2})
-9/2
>>> subs(x*y+4*(y/4)**2*z,{'x':3.01,'y':-3.32,'z':5.34})
4.7217...
>>> subs(x*y+4*(y/4)**2*z,{'x':3.1,'y':-3.2,'z':5})
Traceback (most recent call last):
...
TypeError: all values in an evaluation/substitution dictionary must be of the same type
>>> subs(x*y+4*(y/4)**2*z,{})
Traceback (most recent call last):
...
ValueError: an evaluation/substitution dictionary cannot be empty
>>> subs(x*y+4*(y/4)**2*z,{'x':3,'y':-3,5:5})
Traceback (most recent call last):
...
TypeError: all keys in an evaluation/substitution dictionary must be string objects
>>> subs(x*y+4*(y/4)**2*z,[1,2,3])
Traceback (most recent call last):
...
TypeError: an evaluation/substitution dictionary must be a dict object
>>> subs(x*y+4*(y/4)**2*z,{'x':'a','y':'b', 'z':'c'})
Traceback (most recent call last):
...
TypeError: invalid argument type(s)
pyranha.math.
t_degree
(arg, names=None)[source]¶Trigonometric degree.
This function will return the trigonometric degree of the input argument. Various symbolic types are supported as
input. If names is None
, then the total degree is returned. Otherwise, names must be a list of strings
enumerating the variables to be considered for the computation of the partial degree.
Parameters: |
|
---|---|
Returns: | the trigonometric degree of arg |
Raises: |
|
>>> from pyranha.types import poisson_series, polynomial, rational, k_monomial
>>> from pyranha.math import cos
>>> t = poisson_series[polynomial[rational,k_monomial]]()
>>> x,y,z = t('x'),t('y'),t('z')
>>> t_degree(cos(3*x+y-z)+cos(2*x)) == 3
True
>>> t_degree(cos(3*x+y+z)+cos(x),['z']) == 1
True
>>> from fractions import Fraction as F
>>> t_degree(F(1,2))
Traceback (most recent call last):
...
TypeError: invalid argument type(s)
pyranha.math.
t_ldegree
(arg, names=None)[source]¶Trigonometric low degree.
This function will return the trigonometric low degree of the input argument. Various symbolic types are supported as
input. If names is None
, then the total low degree is returned. Otherwise, names must be a list of strings
enumerating the variables to be considered for the computation of the partial low degree.
Parameters: |
|
---|---|
Returns: | the trigonometric low degree of arg |
Raises: |
|
>>> from pyranha.types import poisson_series, polynomial, rational, k_monomial
>>> from pyranha.math import cos
>>> t = poisson_series[polynomial[rational,k_monomial]]()
>>> x,y,z = t('x'),t('y'),t('z')
>>> t_ldegree(cos(3*x+y-z)+cos(2*x)) == 2
True
>>> t_ldegree(cos(3*x+y-z)+cos(2*y+z),['y']) == 1
True
>>> from fractions import Fraction as F
>>> t_ldegree(F(1,2))
Traceback (most recent call last):
...
TypeError: invalid argument type(s)
pyranha.math.
t_lorder
(arg, names=None)[source]¶Trigonometric low order.
This function will return the trigonometric low order of the input argument. Various symbolic types are supported as
input. If names is None
, then the total low order is returned. Otherwise, names must be a list of strings
enumerating the variables to be considered for the computation of the partial low order.
Parameters: |
|
---|---|
Returns: | the trigonometric low order of arg |
Raises: |
|
>>> from pyranha.types import poisson_series, polynomial, rational, k_monomial
>>> from pyranha.math import cos
>>> t = poisson_series[polynomial[rational,k_monomial]]()
>>> x,y,z = t('x'),t('y'),t('z')
>>> t_lorder(cos(4*x+y-z)+cos(2*x)) == 2
True
>>> t_lorder(cos(3*x+y-z)+cos(2*y+z),['y']) == 1
True
>>> from fractions import Fraction as F
>>> t_lorder(F(1,2))
Traceback (most recent call last):
...
TypeError: invalid argument type(s)
pyranha.math.
t_order
(arg, names=None)[source]¶Trigonometric order.
This function will return the trigonometric order of the input argument. Various symbolic types are supported as
input. If names is None
, then the total order is returned. Otherwise, names must be a list of strings
enumerating the variables to be considered for the computation of the partial order.
Parameters: |
|
---|---|
Returns: | the order of arg |
Raises: |
|
>>> from pyranha.types import poisson_series, polynomial, rational, k_monomial
>>> from pyranha.math import cos
>>> t = poisson_series[polynomial[rational,k_monomial]]()
>>> x,y,z = t('x'),t('y'),t('z')
>>> t_order(cos(3*x+y-z)+cos(x)) == 5
True
>>> t_order(cos(3*x+y-z)-sin(y),['z']) == 1
True
>>> from fractions import Fraction as F
>>> t_order(F(1,2))
Traceback (most recent call last):
...
TypeError: invalid argument type(s)
pyranha.math.
t_subs
(arg, name, x, y)[source]¶Trigonometric substitution.
This function will replace, in arg, the cosine and sine of the symbol called name with the generic objects x and y. Internally, the functionality is implemented via a call to a lower-level C++ routine that supports various combinations for the types of arg, x and y.
Parameters: |
|
---|---|
Returns: | arg after the substitution of the cosine and sine of the symbol called name with x and y |
Raises: |
|
Raises: | any exception raised by the invoked low-level function |
>>> from pyranha.types import poisson_series, rational, polynomial, int16, monomial
>>> pt = poisson_series[polynomial[rational,monomial[int16]]]()
>>> x,y = pt('x'), pt('y')
>>> t_subs(cos(x+y),'x',1,0)
cos(y)
>>> t_subs(sin(2*x+y),'x',0,1)
-sin(y)
>>> t_subs(sin(2*x+y),0,0,1)
Traceback (most recent call last):
...
TypeError: invalid argument type(s)
pyranha.math.
transformation_is_canonical
(new_p, new_q, p_list, q_list)[source]¶Test if transformation is canonical.
This function will check if a transformation of Hamiltonian momenta and coordinates is canonical using the Poisson bracket test. The transformation is expressed as two separate list of objects, new_p and new_q, representing the new momenta and coordinates as functions of the old momenta p_list and q_list.
The function requires new_p and new_q to be lists of symbolic objects of the same type, and p_list and q_list lists of strings with the same size and no duplicate entries.
Parameters: |
|
---|---|
Returns: |
|
Raises: |
|
Raises: |
|
Raises: | any exception raised by the invoked low-level function |
>>> from pyranha.types import polynomial, rational, k_monomial
>>> pt = polynomial[rational,k_monomial]()
>>> L,G,H,l,g,h = [pt(_) for _ in 'LGHlgh']
>>> transformation_is_canonical([-l],[L],['L'],['l'])
True
>>> transformation_is_canonical([l],[L],['L'],['l'])
False
>>> transformation_is_canonical([2*L+3*G+2*H,4*L+2*G+3*H,9*L+6*G+7*H],
... [-4*l-g+6*h,-9*l-4*g+15*h,5*l+2*g-8*h],['L','G','H'],['l','g','h'])
True
>>> transformation_is_canonical([2*L+3*G+2*H,4*L+2*G+3*H,9*L+6*G+7*H],
... [-4*l-g+6*h,-9*l-4*g+15*h,5*l+2*g-7*h],['L','G','H'],['l','g','h'])
False
>>> transformation_is_canonical(L,l,'L','l')
Traceback (most recent call last):
...
TypeError: non-list input type
>>> transformation_is_canonical([L,G],[l],['L'],['l'])
Traceback (most recent call last):
...
ValueError: the number of coordinates is different from the number of momenta
>>> transformation_is_canonical([],[],[],[])
Traceback (most recent call last):
...
ValueError: empty input list(s)
>>> transformation_is_canonical([L,1],[l,g],['L','G'],['l','g'])
Traceback (most recent call last):
...
TypeError: types in input lists are not homogeneous
>>> transformation_is_canonical([L,G],[l,g],['L','G'],['l',1])
Traceback (most recent call last):
...
TypeError: p_list and q_list must be lists of strings
>>> transformation_is_canonical(['a'],['b'],['c'],['d'])
Traceback (most recent call last):
...
TypeError: invalid argument type(s)
pyranha.math.
truncate_degree
(arg, max_degree, names=None)[source]¶Degree-based truncation.
This function will eliminate from arg parts whose degree is greater than max_degree. The truncation operates on symbolic types both by eliminating entire terms and by truncating recursively the coefficients, if possible.
If names is None
, then the total degree is considered for the truncation. Otherwise, names must be
a list of strings enumerating the variables to be considered for the computation of the degree.
Parameters: |
|
---|---|
Returns: | the truncated counterpart of arg |
Raises: |
|
Raises: | any exception raised by the invoked low-level function |
>>> from pyranha.types import polynomial, rational, k_monomial, poisson_series
>>> pt = polynomial[rational,k_monomial]()
>>> x,y,z = pt('x'), pt('y'), pt('z')
>>> truncate_degree(x**2*y+x*y+z,2)
x*y+z
>>> truncate_degree(x**2*y+x*y+z,0,['x'])
z
>>> pt = poisson_series[polynomial[rational,k_monomial]]()
>>> x,y,z,a,b = pt('x'), pt('y'), pt('z'), pt('a'), pt('b')
>>> truncate_degree((x+y*x+x**2*z)*cos(a+b)+(y-y*z+x**4)*sin(2*a+b),3)
(x+x*y+x**2*z)*cos(a+b)+(-y*z+y)*sin(2*a+b)
>>> truncate_degree((x+y*x+x**2*z)*cos(a+b)+(y-y*z+x**4)*sin(2*a+b),1,['x','y'])
x*cos(a+b)+(-y*z+y)*sin(2*a+b)
>>> truncate_degree((x+y*x+x**2*z)*cos(a+b)+(y-y*z+x**4)*sin(2*a+b),1,'x')
Traceback (most recent call last):
...
TypeError: the optional 'names' argument must be a list of strings
>>> truncate_degree((x+y*x+x**2*z)*cos(a+b)+(y-y*z+x**4)*sin(2*a+b),1,['x',1])
Traceback (most recent call last):
...
TypeError: the optional 'names' argument must be a list of strings