ore_algebra.dfinite_function¶
Differentially finite functions and sequences
The dfinite_function module provides functionality for doing computations with D-finite functions and sequences.
A D-finite sequence can be represented by an ore operator which annihilates the sequence (for further information
about ore operators check the ore_algebra package), the operators singularities and a finite amount of initial values.
A D-finite function can be envisioned as a power series, therefore it can be represented via a D-finite sequence which describes the coefficient sequence and an ore operator which annhilates the function.
D-finite sequences and functions are elements of D-finite function rings. D-finite function rings are ring objects created by the
function DFiniteFunctionRing as described below.
Depending on the particular parent ring, D-finite functions/sequences may support different functionality. For example, for D-finite sequences, there is a method for computing an interlacing sequence, an operation which does not make sense for D-finite functions. However basic arithmetic, such as addition and multiplication is implemented for both cases.
AUTHOR:
- Manuel Kauers, Stephanie Schwaiger, Clemens Hofstadler (2017-07-15)
Classes
DFiniteFunction(parent, ann, initial_val[, …]) |
An abstract class representing objects depending on one or more differential and one or more discrete variables defined by an annihilating holonomic system and a suitable set of initial conditions. |
DFiniteFunctionRing(ore_algebra[, domain, …]) |
A Ring of Dfinite objects (functions or sequences) |
UnivariateDFiniteFunction(parent, ann, …) |
D-finite function in a single differentiable variable. |
UnivariateDFiniteSequence(parent, ann, …) |
D-finite sequence in a single discrete variable. |
-
class
ore_algebra.dfinite_function.DFiniteFunction(parent, ann, initial_val, is_gen=False, construct=False, cache=True)¶ An abstract class representing objects depending on one or more differential and one or more discrete variables defined by an annihilating holonomic system and a suitable set of initial conditions.
-
ann()¶ Return the annihilating operator of
self
-
base_ring()¶ Return the base ring of the parent of
self.
-
change_ring(R)¶ Return a copy of
selfbut with an annihilating operator of an Ore algebra overR
-
change_variable_name(var)¶ Return a copy of
selfbut with an Ore operator in the variablevarINPUT:
var– the new variable
EXAMPLES:
sage: from ore_algebra import * sage: A = OreAlgebra(ZZ['n'],'Sn') sage: D = DFiniteFunctionRing(A,ZZ) sage: a = UnivariateDFiniteSequence(D, "Sn**2 - Sn - 1", [0,1]) sage: c = a.change_variable_name('x') sage: a Univariate D-finite sequence defined by the annihilating operator Sn^2 - Sn - 1 and the initial conditions {0: 0, 1: 1} sage: c Univariate D-finite sequence defined by the annihilating operator x^2 - x - 1 and the initial conditions {0: 0, 1: 1}
-
compress()¶ Tries to compress the D-finite object
selfas much as possible by trying to find a smaller annihilating operator and deleting redundant initial conditions.OUTPUT:
A D-finite object which is equal to
selfbut may consist of a smaller operator (in terms of the order) and less initial conditions. In the worst case if no compression is possibleselfis returned.EXAMPLES:
sage: from ore_algebra import * sage: A = OreAlgebra(QQ['n'],'Sn') sage: D1 = DFiniteFunctionRing(A) sage: UnivariateDFiniteSequence(D1,"((n-3)*(n-5))*(Sn^2 - Sn - 1)",{0:0,1:1,5:5,7:13}) Univariate D-finite sequence defined by the annihilating operator (n^2 - 8*n + 15)*Sn^2 + (-n^2 + 8*n - 15)*Sn - n^2 + 8*n - 15 and the initial conditions {0: 0, 1: 1, 5: 5, 7: 13} sage: _.compress() Univariate D-finite sequence defined by the annihilating operator -Sn^2 + Sn + 1 and the initial conditions {0: 0, 1: 1} sage: from ore_algebra import * sage: B = OreAlgebra(QQ[x],'Dx') sage: D2 = DFiniteFunctionRing(B) sage: D2(sin(x)^2*cos(x)^2) Univariate D-finite function defined by the annihilating operator Dx^5 + 20*Dx^3 + 64*Dx and the coefficient sequence defined by (n^14 + 10*n^13 + 5*n^12 - 250*n^11 - 753*n^10 + 1230*n^9 + 8015*n^8 + 5450*n^7 - 21572*n^6 - 35240*n^5 + 480*n^4 + 28800*n^3 + 13824*n^2)*Sn^4 + (20*n^12 + 60*n^11 - 560*n^10 - 1800*n^9 + 4260*n^8 + 16380*n^7 - 5480*n^6 - 49200*n^5 - 21280*n^4 + 34560*n^3 + 23040*n^2)*Sn^2 + 64*n^10 - 1920*n^8 + 17472*n^6 - 52480*n^4 + 36864*n^2 and {0: 0, 1: 0, 2: 1, 3: 0, 4: -4/3, 5: 0, 6: 32/45, 7: 0, 8: -64/315} sage: _.compress() Univariate D-finite function defined by the annihilating operator Dx^3 + 16*Dx and the coefficient sequence defined by (n^3 + 3*n^2 + 2*n)*Sn^2 + 16*n and {0: 0, 1: 0, 2: 1}
-
critical_points(order=None, backwards=False)¶ Returns the singularities of
selfand the values around those singularities that can be affected.INPUT:
order(default: the order of the annihilating operator ofself) – nonnegative integer that determines how many values after or before each singularity are returnedbackwards(defaultFalse) – boolean value that determines whether we are interested in the critial points for forward calculation, i.e. the singularities of the leading coefficent andordermany values after each singularity, or in those for backward calculation, i.e. the singularities of the coefficient of minimal degree (regarding Sn or Dx`respectively) and ``order` many values before each singularity.
OUTPUT:
A set containing the critical points for forward calculation (if
backwardsis False) or those for backward calculation.EXAMPLES:
sage: from ore_algebra import * sage: A = OreAlgebra(QQ['n'],'Sn') sage: D = DFiniteFunctionRing(A,ZZ) sage: a = UnivariateDFiniteSequence(D,"(n-3)*(n+2)*Sn^3 + n^2*Sn^2 - (n-1)*(n+5)*Sn", {0:0,1:1,2:2,6:1,-4:1}) sage: a.critical_points() {1, 2, 3, 4, 6, 7, 8, 9} sage: a.critical_points(2,True) {-6, -5, -4}
-
initial_conditions()¶ Return all initial conditions of
self.In the discrete case the initial conditions are all values that are saved, i.e. the initial values and all singularities. In the differential case this method will return the coefficient sequence of
selfin form of a UnivariateDFiniteSequence object. To get all saved values of a UnivariateDFiniteFunction one has to call this method twice (see examples).EXAMPLES:
#discrete case sage: from ore_algebra import * sage: A = OreAlgebra(QQ['n'],'Sn') sage: D1 = DFiniteFunctionRing(A,ZZ) sage: a = UnivariateDFiniteSequence(D1, "(n+3)*(n-2)*Sn^2 + Sn + 4*n", {0:0,1:1,4:3,-1:2}) sage: a.initial_conditions() {-1: 2, 0: 0, 1: 1, 4: 3} #differential case sage: from ore_algebra import * sage: B = OreAlgebra(QQ['x'],'Dx') sage: D2 = DFiniteFunctionRing(B) sage: b = UnivariateDFiniteFunction(D2, "(x-3)*Dx - 1", {0:-3}) sage: b.initial_conditions() Univariate D-finite sequence defined by the annihilating operator (-3*n - 3)*Sn + n - 1 and the initial conditions {0: -3} sage: b.initial_conditions().initial_conditions() {0: -3}
-
initial_values()¶ Return the initial values of
selfin form of a list.In the discrete case those are the first r sequence terms, where r is the order of the annihilating operator of
self. In the differential case those are the first r coefficients ofself, where r is again the order of the annihilating operator ofself. Singularities that might be saved will not be considered, unless they are within the first r terms. To get all saved values (initial values plus singularities) use the methodinitial_conditionsEXAMPLES:
#discrete case sage: from ore_algebra import * sage: A = OreAlgebra(QQ['n'],'Sn') sage: D1 = DFiniteFunctionRing(A,ZZ) sage: a = UnivariateDFiniteSequence(D1, "(n+3)*(n-2)*Sn^2 + Sn + 4*n", {0:0,1:1,4:3,-1:2}) sage: a.initial_values() [0, 1] #differential case sage: from ore_algebra import * sage: B = OreAlgebra(QQ['x'],'Dx') sage: D2 = DFiniteFunctionRing(B) sage: b = UnivariateDFiniteFunction(D2, "(x-3)*Dx - 1", {0:-3}) sage: b.initial_values() [-3]
-
is_gen()¶ Return
False; the parent ring is not finitely generated.
-
is_unit()¶ Return
Trueifselfis a unit.This is the case if the annihialting operator of
selfhas order 1. Otherwise we can not decide whetherselfis a unit or not.
-
prec()¶ Return the precision of this object.
-
reduce_factors()¶ Tries to delete factors of order 0 of the annihilating operator of
selfwhich appear more than once. Additionally this method tries to delete redundant initial conditions. This method is a subroutine of compressOUTPUT:
A D-finite object which is equal to
selfbut may consist of a smaller operator (in terms of the degree) and less initial conditions. In the worst case if no reduction is possibleselfis returned.EXAMPLES:
sage: from ore_algebra import * sage: A = OreAlgebra(QQ['n'],'Sn') sage: D1 = DFiniteFunctionRing(A) sage: UnivariateDFiniteSequence(D1,"((n-3)*(n-5))*(Sn^2 - Sn - 1)",{0:0,1:1,5:5,7:13}) Univariate D-finite sequence defined by the annihilating operator (n^2 - 8*n + 15)*Sn^2 + (-n^2 + 8*n - 15)*Sn - n^2 + 8*n - 15 and the initial conditions {0: 0, 1: 1, 5: 5, 7: 13} sage: _.reduce_factors() Univariate D-finite sequence defined by the annihilating operator Sn^2 - Sn - 1 and the initial conditions {0: 0, 1: 1} sage: B = OreAlgebra(QQ[x],'Dx') sage: D2 = DFiniteFunctionRing(B) sage: D2(sin(x)^2*cos(x)^2) Univariate D-finite function defined by the annihilating operator Dx^5 + 20*Dx^3 + 64*Dx and the coefficient sequence defined by (n^14 + 10*n^13 + 5*n^12 - 250*n^11 - 753*n^10 + 1230*n^9 + 8015*n^8 + 5450*n^7 - 21572*n^6 - 35240*n^5 + 480*n^4 + 28800*n^3 + 13824*n^2)*Sn^4 + (20*n^12 + 60*n^11 - 560*n^10 - 1800*n^9 + 4260*n^8 + 16380*n^7 - 5480*n^6 - 49200*n^5 - 21280*n^4 + 34560*n^3 + 23040*n^2)*Sn^2 + 64*n^10 - 1920*n^8 + 17472*n^6 - 52480*n^4 + 36864*n^2 and {0: 0, 1: 0, 2: 1, 3: 0, 4: -4/3, 5: 0, 6: 32/45, 7: 0, 8: -64/315} sage: _.reduce_factors() Univariate D-finite function defined by the annihilating operator Dx^5 + 20*Dx^3 + 64*Dx and the coefficient sequence defined by (n^9 + 20*n^8 + 170*n^7 + 800*n^6 + 2273*n^5 + 3980*n^4 + 4180*n^3 + 2400*n^2 + 576*n)*Sn^4 + (20*n^7 + 260*n^6 + 1340*n^5 + 3500*n^4 + 4880*n^3 + 3440*n^2 + 960*n)*Sn^2 + 64*n^5 + 640*n^4 + 2240*n^3 + 3200*n^2 + 1536*n and {0: 0, 1: 0, 2: 1, 3: 0, 4: -4/3}
-
singularities(backwards=False)¶ Returns the integer singularities of the annihilating operator of
self.INPUT:
backwards(defaultFalse) – boolean value that decides whether the singularities needed for the forward calculation are returned or those for backward calculation.
OUTPUT:
- If
backwardsisFalse, a set containing the roots of the leading coefficient of the annihilator ofselfshifted by its order is returned - If
backwardsisTrue, a set containing the roots of the coefficient corresponding to the term of minimal order (regarding Sn or Dx respectively) is returned; shifted by the order of this term
EXAMPLES:
sage: from ore_algebra import * sage: A = OreAlgebra(QQ['n'],'Sn') sage: D = DFiniteFunctionRing(A,ZZ) sage: a = UnivariateDFiniteSequence(D,"(n-3)*(n+2)*Sn^3 + n^2*Sn^2 - (n-1)*(n+5)*Sn", {0:0,1:1,2:2,6:1,-4:1}) sage: a.singularities() {1, 6} sage: a.singularities(True) {-4, 2}
-
-
class
ore_algebra.dfinite_function.DFiniteFunctionRing(ore_algebra, domain=Non negative integer semiring, name=None, element_class=None, category=None)¶ A Ring of Dfinite objects (functions or sequences)
-
base_ring()¶ Return the base ring over which the Ore algebra of the DFiniteFunctionRing is defined
-
change_base_ring(R)¶ Return a copy of
selfbut with the base ring R
-
change_domain(R)¶ Return a copy of
selfbut with the domain R
-
characteristic()¶ Return the characteristic of this DFiniteFunctionRing, which is the same as that of its base ring.
-
construction()¶
-
domain()¶ Return the domain over which the DFiniteFunctionRing is defined
-
is_commutative()¶ Returns whether
selfis commutative. This is true for the function ring as well as the sequence ring
-
is_exact()¶ Return True if the Ore algebra over which the DFiniteFunctionRing is defined is exact
-
is_field(proof=True)¶ A DFiniteFunctionRing is not a field
-
is_finite()¶ Return False since DFiniteFunctionRings are not finite (unless the base ring is 0.)
-
is_integral_domain(proof=True)¶ Returns whether
selfis an integral domain. In the discrete case this is False; in the differential case this is true.
-
is_noetherian()¶
-
ore_algebra()¶ Return the Ore algebra over which the DFiniteFunctionRing is defined
-
random_element(degree=2, *args, **kwds)¶ Return a random D-finite object.
INPUT:
-
degree(default 2) – the degree of the ore operator of the random D-finite objectOUTPUT:
A D-finite sequence/function with a random ore operator of degree
degreeand random initial values constisting of integers between -100 and 100.EXAMPLES:
#discrete case sage: from ore_algebra import * sage: A = OreAlgebra(QQ['n'],'Sn') sage: D1 = DFiniteFunctionRing(A,ZZ) sage: D1.random_element() # random Univariate D-finite sequence defined by the annihilating operator (-n^2 + n)*Sn^2 + (22/9*n - 1/622)*Sn - 5/6*n^2 - n - 1 and the initial conditions {0: -88, 1: 18, 2: -49, 3: -67} #differential case sage: from ore_algebra import * sage: B = OreAlgebra(QQ['x'],'Dx') sage: D2 = DFiniteFunctionRing(B) sage: D2.random_element(3) # random Univariate D-finite function defined by the annihilating operator 20*x*Dx^3 + (2/31*x^2 + 1/2*x + 1/2)*Dx^2 + (2*x^2 - 2*x + 1)*Dx + x^2 - 1/6 and the coefficient sequence defined by (20*n^3 + 361/2*n^2 + 1047/2*n + 486)*Sn^4 + (1/2*n^2 + 7/2*n + 6)*Sn^3 + (2/31*n^2 - 56/31*n - 751/186)*Sn^2 + (2*n + 2)*Sn + 1 and {0: -53, 1: 69, 2: -90, 3: -86}
-
-
class
ore_algebra.dfinite_function.UnivariateDFiniteFunction(parent, ann, initial_val, is_gen=False, construct=False, cache=True)¶ D-finite function in a single differentiable variable.
-
evaluate(z, n=0)¶ Tries to numerically evaluate the n-th derivative of
selfat zINPUT:
- z – either a datatype that can be transformed into a float or a list of floating point numbers starting with 0 and ending
with the value that which the derivation should be computed. The list should provide a path from 0 to the evaluation point, not
crossing any singularities of the annihilating operator of
self(for further information see the documentation of the methodnumerical_solutionof the OreAlgebra package). - n (default 0) – a non-negative integer
OUTPUT:
The evaluation of the n-th derivative of
selfat z if z is a floating point number. If z is a list, then the evaluation of the n-th derivative ofselfat the last point of the list is computed.EXAMPLES:
sage: from ore_algebra import * sage: A = OreAlgebra(QQ['x'],'Dx') sage: D = DFiniteFunctionRing(A) sage: x = A.base_ring().gen() sage: a = D(3*x^5 + 4*x^2 - 8*x +13) sage: sin = D(sin(x)) sage: a.evaluate(0,0) 13 sage: a.evaluate(0,1) [-8.00000000000000000000000000000000000000000000000...] sage: sin.evaluate(pi/2,0) [1.000000000000000000000000000000000000000000000000...] sage: sin.evaluate(pi,1) [-1.00000000000000000000000000000000000000000000000...]
- z – either a datatype that can be transformed into a float or a list of floating point numbers starting with 0 and ending
with the value that which the derivation should be computed. The list should provide a path from 0 to the evaluation point, not
crossing any singularities of the annihilating operator of
-
expand(n, deriv=False)¶ Return a list of the first n+1 coefficients of
selfifderiv``is False. If ``derivis True the first n+1 derivations of self at x=0 are returned.INPUT:
- n – a non-negative integer
deriv(defaultFalse) – boolean value. Determines whether the coefficients (default) or derivations ofselfare returned
EXAMPLES:
sage: from ore_algebra import * sage: A = OreAlgebra(QQ['x'],'Dx') sage: D = DFiniteFunctionRing(A) sage: x = A.base_ring().gen() sage: e = D(exp(x)) sage: e.expand(10) [1, 1, 1/2, 1/6, 1/24, 1/120, 1/720, 1/5040, 1/40320, 1/362880, 1/3628800] sage: e.expand(10,True) [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
-
hadamard_product(right)¶ Return the D-finite function corresponding to the Hadamard product of
selfandright. The Hadamard product of two formal power series a(x) = sum_{n=0}^infty a_n x^n and b(x) = sum_{n=0}^infty b_n x^n is defined as a(x) odot b(x) := sum_{n=0}^infty a_nb_n x^n
-
integral()¶ Return the D-finite function corresponding to the integral of
self. By integral the formal integral of a power series is meant, i.e. int a(x) = int_0^x sum_{n=0}^infty a_n x^n = sum_{n=0}^infty frac{a_n}{n+1} x^{n+1}EXAMPLES:
sage: from ore_algebra import * sage: A = OreAlgebra(QQ[x],'Dx') sage: D = DFiniteFunctionRing(A) sage: c = D(cos(x)) sage: c.integral() Univariate D-finite function defined by the annihilating operator Dx^3 + Dx and the coefficient sequence defined by (n^7 + n^6 - 5*n^5 - 5*n^4 + 4*n^3 + 4*n^2)*Sn^2 + n^5 - 2*n^4 - n^3 + 2*n^2 and {0: 0, 1: 1, 2: 0, 3: -1/6, 4: 0} sage: _ == D(sin(x)) True
-
to_polynomial()¶ Try to convert
selfinto a polynomial.OUTPUT:
Either a polynomial f(x) from the base ring of the OreAlgebra of the annihilating operator of
selfsuch that f(x) is the explicit form ofself(ifselfrepresents a polynomial) or an error message if no such polynomial exists.EXAMPLES:
sage: from ore_algebra import * sage: A = OreAlgebra(QQ['x'],'Dx') sage: D = DFiniteFunctionRing(A) sage: x = A.base_ring().gen() sage: a = D(3*x^3 + 5*x - 10) sage: a.to_polynomial() 3*x^3 + 5*x - 10 sage: l = D(legendre_P(5,x)) sage: l Univariate D-finite function defined by the annihilating operator (63/8*x^5 - 35/4*x^3 + 15/8*x)*Dx - 315/8*x^4 + 105/4*x^2 - 15/8 and the coefficient sequence defined by (15/8*n + 45/8)*Sn^4 + (-35/4*n + 35/4)*Sn^2 + 63/8*n - 315/8 and {0: 0, 1: 15/8, 2: 0, 3: -35/4} sage: l.to_polynomial() 63/8*x^5 - 35/4*x^3 + 15/8*x
-
to_rational()¶ Try to convert
selfinto a rational function.OUTPUT:
Either a rational function r(x) from the fraction field of the base ring of the OreAlgebra of the annihilating operator of
selfsuch that r(x) is the explicit form ofself(ifselfrepresents a rational function) or an error message if no such function exists.EXAMPLES:
sage: from ore_algebra import * sage: A = OreAlgebra(QQ['x'],'Dx') sage: D = DFiniteFunctionRing(A) sage: x = A.base_ring().gen() sage: a = D((x^2+3*x-4)/(x^5+4*x^3+10)) sage: a.to_rational() (x^2 + 3*x - 4)/(x^5 + 4*x^3 + 10) sage: l = D(legendre_P(5,x)/legendre_P(3,x)) sage: l Univariate D-finite function defined by the annihilating operator (63/20*x^6 - 539/100*x^4 + 57/20*x^2 - 9/20)*Dx - 63/10*x^5 + 189/25*x^3 - 27/10*x and the coefficient sequence defined by (-9/20*n - 27/10)*Sn^6 + (57/20*n + 87/10)*Sn^4 + (-539/100*n - 161/50)*Sn^2 + 63/20*n - 63/10 and {0: -5/4, 1: 0, 2: 15/4, 3: 0, 4: 1, 5: 0} sage: l.to_rational() (63/20*x^4 - 7/2*x^2 + 3/4)/(x^2 - 3/5)
-
-
class
ore_algebra.dfinite_function.UnivariateDFiniteSequence(parent, ann, initial_val, is_gen=False, construct=False, cache=True)¶ D-finite sequence in a single discrete variable.
-
cauchy_product(right)¶ Return the cauchy product of
selfandrightThe result is the cauchy product of
selfandright. To get the termwise product (Hadamard product) use the method_mul_. This method uses the methodsymmetric_product(but in an OreAlgebra with the differential operator) of the OreAlgebra package to get the new annihilator. Ifselforrightcontains aNonevalue at a certain position, then the cauchy product will haveNoneentries at this position and all positions afterwards.EXAMPLES:
sage: from ore_algebra import * sage: A = OreAlgebra(QQ['n'],'Sn') sage: D = DFiniteFunctionRing(A,ZZ) sage: a = UnivariateDFiniteSequence(D,"(n + 1)*Sn + n + 1", {0:1,-1:0}) #Taylor coefficients of 1/(x+1) sage: a.expand(10) [1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1] sage: b = UnivariateDFiniteSequence(D,"(n + 1)*Sn + n - 1",{0:1,1:1}) #Taylor coefficients of x+1 sage: b.expand(10) [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0] sage: a.cauchy_product(b).expand(10) [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
-
dict()¶
-
expand(n)¶ Return all the terms of
selfbetween 0 andnINPUT:
n– an integer; ifselfis defined over the domain ZZ thenncan also be negative
OUTPUT:
A list starting with the 0-th term up to the n-th term of
self.EXAMPLES:
sage: from ore_algebra import * sage: A = OreAlgebra(QQ['n'],'Sn') sage: D = DFiniteFunctionRing(A,ZZ) sage: a = UnivariateDFiniteSequence(D, "Sn^2 - Sn - 1", [0,1]) #the Fibonacci numbers sage: a.expand(10) [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55] sage: a.expand(-10) [0, 1, -1, 2, -3, 5, -8, 13, -21, 34, -55]
-
generating_function()¶
-
interlace(right)¶ Return the interlaced sequence of
selfandright.interlaceuses the methodannihilator_of_interlacingof the OreAlgebra package to get the new operator.OUTPUT:
If
selfis of the form a_0,a_1,a_2,dots andrightis of the form b_0,b_1,b_2,dots, then the result is a UnivariateDFiniteSequence object that represents the sequence a_0,b_0,a_1,b_1,a_2,b_2,dotsEXAMPLES:
sage: from ore_algebra import * sage: A = OreAlgebra(QQ['n'],'Sn') sage: D = DFiniteFunctionRing(A,ZZ) sage: n = A.base_ring().gen() sage: a = D(n) sage: b = D(1/n) sage: c = a.interlace(b) sage: c.expand(10) [0, None, 1, 1, 2, 1/2, 3, 1/3, 4, 1/4, 5]
-
list()¶
-
sum()¶ Return the sequence (s_n)_{n=0}^infty with s_n = sum_{k=0}^n self[k].
EXAMPLES:
sage: from ore_algebra import * sage: A = OreAlgebra(QQ['n'],'Sn') sage: D = DFiniteFunctionRing(A) sage: n = A.base_ring().gen() sage: a = D(1/(n+1)) sage: a.sum() Univariate D-finite sequence defined by the annihilating operator (n + 3)*Sn^2 + (-2*n - 5)*Sn + n + 2 and the initial conditions {0: 1, 1: 3/2} sage: _ == D(harmonic_number(n+1)) True
-
to_polynomial()¶ Try to convert
selfinto a polynomial.OUTPUT:
Either a polynomial f(n) from the base ring of the OreAlgebra of the annihilating operator of
selfsuch that self(n) = f(n) for all n in NN or an error message if no such polynomial exists.EXAMPLES:
sage: from ore_algebra import * sage: A = OreAlgebra(QQ['n'],'Sn') sage: D = DFiniteFunctionRing(A,ZZ) sage: n = A.base_ring().gen() sage: a = D(3*n^3 + 5*n - 10) sage: a.to_polynomial() 3*n^3 + 5*n - 10 sage: l = D(legendre_P(5,n)) sage: l Univariate D-finite sequence defined by the annihilating operator (63/8*n^5 - 35/4*n^3 + 15/8*n)*Sn - 63/8*n^5 - 315/8*n^4 - 70*n^3 - 105/2*n^2 - 15*n - 1 and the initial conditions {-1: -1, 0: 0, 1: 1} sage: l.to_polynomial() 63/8*n^5 - 35/4*n^3 + 15/8*n
-
to_rational()¶ Try to convert
selfinto a rational function.OUTPUT:
Either a rational function r(n) from the fraction field of the base ring of the OreAlgebra of the annihilating operator of
selfsuch that self(n) = r(n) for all n in NN (eventually except from pols) or an error message if no such rational function exists.EXAMPLES:
sage: from ore_algebra import * sage: A = OreAlgebra(QQ['n'],'Sn') sage: D = DFiniteFunctionRing(A,ZZ) sage: n = A.base_ring().gen() sage: a = D((n^2+3*n-4)/(n^5+4*n^3+10*n)) sage: a.to_rational() (n^2 + 3*n - 4)/(n^5 + 4*n^3 + 10*n) sage: l = D(legendre_P(5,n)/legendre_P(3,n)) sage: l Univariate D-finite sequence defined by the annihilating operator (63/20*n^6 + 63/10*n^5 - 56/25*n^4 - 7*n^3 - 13/20*n^2 + 3/2*n + 3/10)*Sn - 63/20*n^6 - 63/5*n^5 - 1351/100*n^4 + 49/25*n^3 + 221/25*n^2 + 84/25*n + 6/25 and the initial conditions {0: -5/4} sage: l.to_rational() (63/20*n^4 - 7/2*n^2 + 3/4)/(n^2 - 3/5)
-