K ifdZddlmZmZmZddlmZmZmZm Z m Z m Z m Z m Z ddlmZddlmZddlmZmZddlmZddlmZmZmZdd lmZmZmZdd lm Z m!Z!dd l"m#Z#dd l$m%Z%m&Z&m'Z'dd l(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.ddl/m0Z0ddl1m2Z2m3Z3ddl4m5Z5ddl6m7Z7ddl8m9Z9ddl:m;Z;ddlZ>ddl?m@Z@ddlAmBZBddlCmDZDddlEmFZFddlGmHZHddlImJZJddlKmLZLddlMmNZNddlOmPZPddlQmRZRdd lSmTZTmUZUmVZVdd!lWmXZXmYZYmZZZm[Z[d"Z\d#Z]Gd$d%Z^Gd&d'Z_Gd(d)Z`d=d+Zadd*d,e=fd-Zbed.Zcd/add/aedd0lfmgZgd>d1Zhd?d2Zid3Zjd4Zkd5Zld6Zmd7Znd@d8Zodd/d/e=d,fd9Zpd,e=fd:Zqe=fd;ZrdAd<Zsy/)BzL This module implements Holonomic Functions and various operations on them. )AddMulPow)NaNInfinityNegativeInfinityFloatIpi equal_valued int_valued)S)ordered)DummySymbol)sympify)binomial factorialrf) exp_polarexplog)coshsinh)sqrt)cossinsinc)CiShiSierferfcerfi)gamma)hypermeijerg) meijerint)Matrix) PolyElement) FracElement)QQRR)DMF)roots)Poly) DomainMatrix)sstr)limit)Order) hyperexpand) nsimplify)solve)HolonomicSequenceRecurrenceOperatorRecurrenceOperators)NotPowerSeriesErrorNotHyperSeriesErrorSingularityErrorNotHolonomicErrorcfd}j|\}}|jd}|d|f|z}||zj}|S)NcDtj|jSN)r1onesdomain)shapers _/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/holonomic/holonomic.pyz(_find_nonzero_solution..+s**5!((;rr8)_solverE transpose)rFhomosysrC particular nullspacenullitynullpartsols` rG_find_nonzero_solutionrR*sT ;DHHW-J ooa GQL!I-H  + + -C JrIc6t||}||jfS)a This function is used to create annihilators using ``Dx``. Explanation =========== Returns an Algebra of Differential Operators also called Weyl Algebra and the operator for differentiation i.e. the ``Dx`` operator. Parameters ========== base: Base polynomial ring for the algebra. The base polynomial ring is the ring of polynomials in :math:`x` that will appear as coefficients in the operators. generator: Generator of the algebra which can be either a noncommutative ``Symbol`` or a string. e.g. "Dx" or "D". Examples ======== >>> from sympy import ZZ >>> from sympy.abc import x >>> from sympy.holonomic.holonomic import DifferentialOperators >>> R, Dx = DifferentialOperators(ZZ.old_poly_ring(x), 'Dx') >>> R Univariate Differential Operator Algebra in intermediate Dx over the base ring ZZ[x] >>> Dx*x (1) + (x)*Dx )DifferentialOperatorAlgebraderivative_operator)base generatorrings rGDifferentialOperatorsrY4s"D 'tY 7D $** ++rIc&eZdZdZdZdZeZdZy)rTa An Ore Algebra is a set of noncommutative polynomials in the intermediate ``Dx`` and coefficients in a base polynomial ring :math:`A`. It follows the commutation rule: .. math :: Dxa = \sigma(a)Dx + \delta(a) for :math:`a \subset A`. Where :math:`\sigma: A \Rightarrow A` is an endomorphism and :math:`\delta: A \rightarrow A` is a skew-derivation i.e. :math:`\delta(ab) = \delta(a) b + \sigma(a) \delta(b)`. If one takes the sigma as identity map and delta as the standard derivation then it becomes the algebra of Differential Operators also called a Weyl Algebra i.e. an algebra whose elements are Differential Operators. This class represents a Weyl Algebra and serves as the parent ring for Differential Operators. Examples ======== >>> from sympy import ZZ >>> from sympy import symbols >>> from sympy.holonomic.holonomic import DifferentialOperators >>> x = symbols('x') >>> R, Dx = DifferentialOperators(ZZ.old_poly_ring(x), 'Dx') >>> R Univariate Differential Operator Algebra in intermediate Dx over the base ring ZZ[x] See Also ======== DifferentialOperator c||_t|j|jg||_|t dd|_yt|trt |d|_yt|t r||_yy)NDxF) commutative) rVDifferentialOperatorzeroonerUr gen_symbol isinstancestr)selfrVrWs rG__init__z$DifferentialOperatorAlgebra.__init__sl #7 YY !4$)   $Tu=DO)S)"("FIv."+/rIcrdt|jzdz|jjz}|S)Nz9Univariate Differential Operator Algebra in intermediate z over the base ring )r2rarV__str__)rdstrings rGrgz#DifferentialOperatorAlgebra.__str__s<L4??#$&<= YY   !" rIcj|j|jk(xr|j|jk(SrB)rVrardothers rG__eq__z"DifferentialOperatorAlgebra.__eq__s.yyEJJ&3%"2"22 3rIN)__name__ __module__ __qualname____doc__rerg__repr__rlrIrGrTrTZs$L ,H3rIrTcdeZdZdZdZdZdZdZdZeZ dZ dZ d Z d Z d Zd ZeZd ZdZy)r^a Differential Operators are elements of Weyl Algebra. The Operators are defined by a list of polynomials in the base ring and the parent ring of the Operator i.e. the algebra it belongs to. Explanation =========== Takes a list of polynomials for each power of ``Dx`` and the parent ring which must be an instance of DifferentialOperatorAlgebra. A Differential Operator can be created easily using the operator ``Dx``. See examples below. Examples ======== >>> from sympy.holonomic.holonomic import DifferentialOperator, DifferentialOperators >>> from sympy import ZZ >>> from sympy import symbols >>> x = symbols('x') >>> R, Dx = DifferentialOperators(ZZ.old_poly_ring(x),'Dx') >>> DifferentialOperator([0, 1, x**2], R) (1)*Dx + (x**2)*Dx**2 >>> (x*Dx*x + 1 - Dx**2)**2 (2*x**2 + 2*x + 1) + (4*x**3 + 2*x**2 - 4)*Dx + (x**4 - 6*x - 2)*Dx**2 + (-2*x**2)*Dx**3 + (1)*Dx**4 See Also ======== DifferentialOperatorAlgebra c||_|jj}t|jdtr|jdn|jdd|_t |D]\\}}t||js|jt|||<:|j|j|||<^||_ t|jdz |_ y)z Parameters ========== list_of_poly: List of polynomials belonging to the base ring of the algebra. parent: Parent algebra of the operator. rr8N)parentrVrbgensrx enumeratedtype from_sympyrto_sympy listofpolylenorder)rd list_of_polyrvrVijs rGrezDifferentialOperator.__init__s {{!+DIIaL&!A1tyyQR|TU l+ DDAqa,"&//'!*"= Q"&//$--2B"C Q  D ')A- rIcj}t|tr |j}n]t|jjj r|g}n/jjj t|g}d}||d|}fd}tdt|D] }||}t|||||}"t|jS)z Multiplies two DifferentialOperator and returns another DifferentialOperator instance using the commutation rule Dx*a = a*Dx + a' c^t|tr|Dcgc]}||z c}S||zgScc}wrB)rblist)b listofotherrs rG_mul_dmp_diffopz5DifferentialOperator.__mul__.._mul_dmp_diffops3+t,'23!A33 O$ $4s *rcjjjg}g}t|tr8|D]2}|j ||j |j 4nv|j jjj||j jjj|j t||SrB) rvrVr_rbrappenddiffr{ _add_lists)rsol1sol2rrds rG _mul_Dxi_bz0DifferentialOperator.__mul__.._mul_Dxi_bsKK$$))*DD!T"*AKKNKK)* DKK,,77:; DKK,,77:??ABdD) )rIr8) r}rbr^rvrVrzr{rranger~r)rdrk listofselfrrrQrrs` rG__mul__zDifferentialOperator.__mul__s__ e1 2**K t{{//55 6 'K;;++66wu~FGK % jm[9 *q#j/* OA$[1KS/*Q-"MNC  O $C55rIcBt|tst||jjjs.|jjj t |}|jDcgc]}||z }}t||jSycc}wrB)rbr^rvrVrzr{rr})rdrkrrQs rG__rmul__zDifferentialOperator.__rmul__s{%!56eT[[%5%5%;%;<))55genE&*oo65196C6'T[[9 9 7 7s7 Bct|tr6t|j|j}t||jS|j}t||jj j s0|jj jt|g}n|g}|d|dzg|ddz}t||jS)Nrr8) rbr^rr}rvrVrzr{r)rdrkrQ list_self list_others rG__add__zDifferentialOperator.__add__s e1 2T__e.>.>?C'T[[9 9OO %!1!1!7!78 KK--99'%.IJJJ|jm+,y}<#C55rIc|d|zzSNrrrjs rG__sub__zDifferentialOperator.__sub__)srUl""rIcd|z|zSrrrrjs rG__rsub__zDifferentialOperator.__rsub__,sd{U""rIc d|zSrrrrds rG__neg__zDifferentialOperator.__neg__/ DyrIc.|tj|z zSrBrOnerjs rG __truediv__z DifferentialOperator.__truediv__2quuu}%%rIc|dk(r|St|jjjg|j}|dk(r|S|j|jj jk(r\|jjj g|z|jjjgz}t||jS|} |dzr||z}|dz}|s |S||z})Nr8r)r^rvrVr`r}rUr_)rdnresultrQrxs rG__pow__zDifferentialOperator.__pow__5s 6K%t{{'7'7';';&z.DifferentialOperator.__eq__..is&HqT[[%%***Hs,/r8)rbr^r}rvallrjs` rGrlzDifferentialOperator.__eq__dsp e1 2??e&6&66/;;%,,. /q!U*I HDOOAB4GH H IrIc|jj}|t|j|jd|j vS)zH Checks if the differential equation is singular at x0. r)rvrVr/r|r}rx)rdx0rVs rG is_singularz DifferentialOperator.is_singularks; {{U4==)<=tvvFFFrIN)rmrnrorp _op_priorityrerrr__radd__rrrrrrgrqrlrrrrIrGr^r^s\!FL.<,6\: 6H##&(2HIGrIr^ceZdZdZdZd!dZdZeZdZdZ dZ d Z d Z d"d Z d Zd ZdZeZdZdZdZdZdZdZdZd#dZd#dZd$dZdZd%dZdZdZd&dZ dZ!d'dZ"d Z#y)(HolonomicFunctiona A Holonomic Function is a solution to a linear homogeneous ordinary differential equation with polynomial coefficients. This differential equation can also be represented by an annihilator i.e. a Differential Operator ``L`` such that :math:`L.f = 0`. For uniqueness of these functions, initial conditions can also be provided along with the annihilator. Explanation =========== Holonomic functions have closure properties and thus forms a ring. Given two Holonomic Functions f and g, their sum, product, integral and derivative is also a Holonomic Function. For ordinary points initial condition should be a vector of values of the derivatives i.e. :math:`[y(x_0), y'(x_0), y''(x_0) ... ]`. For regular singular points initial conditions can also be provided in this format: :math:`{s0: [C_0, C_1, ...], s1: [C^1_0, C^1_1, ...], ...}` where s0, s1, ... are the roots of indicial equation and vectors :math:`[C_0, C_1, ...], [C^0_0, C^0_1, ...], ...` are the corresponding initial terms of the associated power series. See Examples below. Examples ======== >>> from sympy.holonomic.holonomic import HolonomicFunction, DifferentialOperators >>> from sympy import QQ >>> from sympy import symbols, S >>> x = symbols('x') >>> R, Dx = DifferentialOperators(QQ.old_poly_ring(x),'Dx') >>> p = HolonomicFunction(Dx - 1, x, 0, [1]) # e^x >>> q = HolonomicFunction(Dx**2 + 1, x, 0, [0, 1]) # sin(x) >>> p + q # annihilator of e^x + sin(x) HolonomicFunction((-1) + (1)*Dx + (-1)*Dx**2 + (1)*Dx**3, x, 0, [1, 2, 1]) >>> p * q # annihilator of e^x * sin(x) HolonomicFunction((2) + (-2)*Dx + (1)*Dx**2, x, 0, [0, 1]) An example of initial conditions for regular singular points, the indicial equation has only one root `1/2`. >>> HolonomicFunction(-S(1)/2 + x*Dx, x, 0, {S(1)/2: [1]}) HolonomicFunction((-1/2) + (x)*Dx, x, 0, {1/2: [1]}) >>> HolonomicFunction(-S(1)/2 + x*Dx, x, 0, {S(1)/2: [1]}).to_expr() sqrt(x) To plot a Holonomic Function, one can use `.evalf()` for numerical computation. Here's an example on `sin(x)**2/x` using numpy and matplotlib. >>> import sympy.holonomic # doctest: +SKIP >>> from sympy import var, sin # doctest: +SKIP >>> import matplotlib.pyplot as plt # doctest: +SKIP >>> import numpy as np # doctest: +SKIP >>> var("x") # doctest: +SKIP >>> r = np.linspace(1, 5, 100) # doctest: +SKIP >>> y = sympy.holonomic.expr_to_holonomic(sin(x)**2/x, x0=1).evalf(r) # doctest: +SKIP >>> plt.plot(r, y, label="holonomic function") # doctest: +SKIP >>> plt.show() # doctest: +SKIP rtNc<||_||_||_||_y)ap Parameters ========== annihilator: Annihilator of the Holonomic Function, represented by a `DifferentialOperator` object. x: Variable of the function. x0: The point at which initial conditions are stored. Generally an integer. y0: The initial condition. The proper format for the initial condition is described in class docstring. To make the function unique, length of the vector `y0` should be equal to or greater than the order of differential equation. N)y0r annihilatorrx)rdrrxrrs rGrezHolonomicFunction.__init__s!,&rIc >|jr]dt|jdt|jdt|j dt|j d }|Sdt|jdt|jd}|S)NzHolonomicFunction(z, r)_have_init_condrcrr2rxrr)rdstr_sols rGrgzHolonomicFunction.__str__sw    !=@AQAQ=RTVV d477mT$'']|j3dk(r+|j3dk(r|j@}|j@}i}|D]:} | |vr,t9|| || Dcgc] \}}||z c}}|| <3|| || <<|D]} | |vs|| || <t/||j0|j4|Scc}}wcc}} wcc}} wcc}}w)Nrr8FnegativerT)$rrvrVrrmax get_fieldrUrrr~r}r_newto_listr1rKzerosrRis_zero_matrixflat _normalizerrrxrr _extend_y0zipr change_icsryrrrr)rdrkrrdeg1deg2dimrKrowsself rowsothergenrdiff1diff2rowrFexprprLrQry1y2rselfat0otherat0selfatx0 otheratx0r_y0s rGrzHolonomicFunction.__add__$s    " " ' '5+<+<+C+C+H+H H::e$DAqq5L%%  &&$o    # # ( ( KKM$$%&&' %%99sTz" #A8B<'E OOE " #sTz" $A9R=(E   U # $"  DA37^ BDOO,,HHQVV$HHQUU4??1#5#=#=#?@A  B HHQK  SXs1u-q 1 ; ; =$$c!eQZ3$Q0  1HC8B<'E OOE "9R=(E   U #Y&CA sQwFAC00(tq'9'A'A'C!DE F   QS3q5 115??AA"((#a%Q7G(G4C1  :hhj#'D.)#t//667d&&')9)9)@)@5Q$$&5+@+@+B$S$&&1 1    E )e.B.B.D.Mww%((" cii0syy1(+B 41a!e44(dffdggrBB&&2215G((44Q7Hww!|GHe..q111xx1}WXq)E11''33DGGIIe..tww777??588,u4 4 77ehh $S$&&1 1     E )e.B.B.D.L09$''0BC11y|#CCC&&#BB  "d *u/C/C/E/N09%((0CD11y|#DCDB&&#B  "d *u/C/C/E/MBB ABw+.r!ube+<=41aQ=111   A{11 !dffdggr::e54DE>s3_ &__6_c  |jjj}|jdk(r|j }|r|j ||Si}|j D]}|j |}g}t|D]c\} } | dk(r |jtj+|| zdzdk(r td|j| t|| zdzz e|||dz<t|dr tdt|j|z|j|j|S|j!sc|r>t|j|z|j|jtjgSt|j|z|jSt|dr9t#|dk(r-|d|jk(r|j} |d} |d } d}nd }tjg}||j z }t|j|z|j|j|}s|S  k7r& |j%}|rI|j+|j| }t-|t.r.|j1|j| }n|j3| } |jk(r0|d|z |d<t|j|z|j| |St| j4re|rM|j+|j| }t-|t.r|j1|j| }||z S|j3| }||z S |jk(r%t|j|z|j| |St| j4r~ t|j|z|j| |j%}|j+|j| }t-|t.s|S|j1|j| St|j|z|jS#t&t(f$rd }YwxYw#t&t(f$r7t|j|z|j| |j3| cYSwxYw) az Integrates the given holonomic function. Examples ======== >>> from sympy.holonomic.holonomic import HolonomicFunction, DifferentialOperators >>> from sympy import QQ >>> from sympy import symbols >>> x = symbols('x') >>> R, Dx = DifferentialOperators(QQ.old_poly_ring(x),'Dx') >>> HolonomicFunction(Dx - 1, x, 0, [1]).integrate((x, 0, x)) # e^x - 1 HolonomicFunction((-1)*Dx + (1)*Dx**2, x, 0, [0, 1]) >>> HolonomicFunction(Dx**2 + 1, x, 0, [1, 0]).integrate((x, 0, x)) HolonomicFunction((1)*Dx + (1)*Dx**3, x, 0, [0, 1, 0]) T)initcondrr8z1logarithmic terms in the series are not supported__iter__z4Definite integration for singular initial conditionsrFN)rrvrUrr integraterryrrrNotImplementedErrorhasattrrrxrrr~to_exprr=r<subsrbrr3evalf is_Number)rdlimitsrDrFrrcc2rcjrrrdefiniteindefinite_integralindefinite_exprloweruppers indefinites rGrzHolonomicFunction.integratesT&    # # 7 7    D (((*A{{6H{==BWW GGAJ&q\ 5EArQw !&&)Qa12eff "qQ|"34 51q5  vz*)*`aa$T%5%5%9466477BO O##%()9)9A)=tvvtwwQRQWQWPXYY$T%5%5%9466B B 6: &6{aF1I$7WW1I1IHffX dgg /0@0@10DdffdggWYZ& & 7 '"5"="="?',,TVVQ7eS)+11$&&!>U()<= '"& 'N()<= W()9)9A)=tvvq"MSSTUVV Ws,Q A Q8!Q8 Q54Q58AR>=R>c|jdd|r[|d|jk7rtjSt |dk(r+|}t |dD]}|j |d}|S|j}|jd|jjjk(r|jdk(rtjS|jd|jjjk(rt|jdd|j}|jrX|jdk(r/t!||j|j"|j$ddSt!||jSt!||jS|jj}|j'}|jDcgc]!}|j)|j+#}}|ddDcgc] }||dz  } }| j-d|jt/| |}t1||j|j2g}t5|dd|jjd}|jr|jdk(rt!||jSt7||jdzdd} t!||j|j"| Scc}wcc}w) aK Differentiation of the given Holonomic function. Examples ======== >>> from sympy.holonomic.holonomic import HolonomicFunction, DifferentialOperators >>> from sympy import ZZ >>> from sympy import symbols >>> x = symbols('x') >>> R, Dx = DifferentialOperators(ZZ.old_poly_ring(x),'Dx') >>> HolonomicFunction(Dx**2 + 1, x, 0, [0, 1]).diff().to_expr() cos(x) >>> HolonomicFunction(Dx - 2, x, 0, [1]).diff().to_expr() 2*exp(2*x) See Also ======== integrate evaluateTrrr8NFr) setdefaultrxrrr~rrrr}rvrVr_rr^rrrrrrrrinsert_derivate_diff_eqrr`rr) rdargskwargsrQrannrrseq_dmfrhsrs rGrzHolonomicFunction.diff4ss, *d+ Aw$&& vv TatAw,A((47+C,  >>!   4 4 4a66M^^A #**//"6"6 6&s~~ab'93::FC##%&&(E1,S$&&$''47712;OO(dff55(dff55 JJOO KKM/2~~>!155%>>(/qr{3!q71:~33 1aff Q'qvvquuo.QR$"2"2"9"9EJ##%)<)<)>$)F$S$&&1 1 cii!m ,QR 0 dffdggr::%?4s &K6?K;c|j|jk7s|j|jk7ry|jrD|jr4|j|jk(xr|j|jk(Sy)NFT)rrxrrrrjs rGrlzHolonomicFunction.__eq__sg   u00 0DFFegg4E    !e&;&;&=77ehh&>477ehh+> >rIc $  |j}t|tst|}|j |j r t d|js|St||j}|Dcgc]/}tj||j |zj1c}t||j |jS|jjj|jjjk7r|j!|\}|zS|j}|j|j}|jj}|j#}|j$Dcgc]!}|j|j'#} }|j$Dcgc]!}|j|j'#} }t)D cgc]} | |  | z } } t)|D cgc]} | |  | |z } } t)dzD cgc](}t)|dzD cgc]} |j*c} *}}} |j,|dd<t)D cgc]} t)|D] }|| | c}} g}t/|d|zf|j1}t/j2|zdf|}t5||}|j6rt)dz ddD] t)|dz ddD]| dzxx| z cc<| dzxx| z cc<t| |j8rt;| || <j| j=|j | <t)dzD]S | |j>rt)|D]| xx| | |zz cc< |j*| |<Ut)|D]L|dk(rt)D] | xx| |zz cc< |j*|<N|jAt)D cgc]} t)|D] }|| | c}} t/|tC||zf|j1}t5||}|j6rtE|jG|jjd}|jr|jst||j S|jIdk(r|jIdk(ru|j|jk(rMt||j}t||j}|d|dzg}t)dtKtC|tC|D] t) dzDcgc]}t) dzD cgc]} dc}  }}t) dzD]0t) dzD]}|z k(s tM ||<2d}t) dzD],t) dzD]}||||z||zz }.|jA|t||j |j|S|jjOd}|jjOd}|jdk(r|s|s||jQdzS|jdk(r|s|s|jQd|zS|jjO|j}|jjO|j}|s |s||jQ|jzS|jQ|j|zS|j|jk7rt||j Sdd |jIdk(re|jIdk(rRtS|jTD cgc]\} }|tW| z }} }tXjZ|i|jT n|jIdk(re|jIdk(rRtS|jTD cgc]\} }|tW| z }} }|jTtXjZ|i n>|jIdk(r+|jIdk(r|jT|jT i}D] D]tKtC tC }t)|Dcgc]6t]  fdt)dzDtXjZ 8}} z|vr || z<t_|| zDcgc] \}}||z c}}| z<t||j |j|Scc}wcc}wcc}wcc} wcc} wcc} wcc} }wcc}} wcc}} wcc} wcc}wcc}} wcc}} wcc}wcc}}w) Nz> Can't multiply a HolonomicFunction and expressions/functions.r8rrFrTc3FK|]}||z zywrBrr)rrrrrrrs rGrz,HolonomicFunction.__mul__..!s*Ha"Q%(RU1q5\1Hs!start)0rrbrrhasrxrrrrr0rreprrvrVrrr}rrr_r`r1rKrrRrrzDMFdiffris_zerorr~rrrminrrrryrrrrsumr)!rdrkann_selfrrr ann_otherrrrrrself_red other_red coeff_mullin_sys_elementslin_syshomo_sysrQsol_anny0_selfy0_othercoeffkrrrrrrrrrs! ` ` ` @@rGrzHolonomicFunction.__mul__s ##%!23ENEyy )*jkk'') D(..1B=?@488Atvv&.33@B$XtvvtwwC C    " " ' '5+<+<+C+C+H+H H::e$DAqq5L%% NN OO OO  KKM191D1DEAQUU199;'E E2;2F2FGQaeeAIIK(G G;@(CQYq\MIaL0CC=B1XFjm^jm3F F>C1q5\JeAEl3aff3J J%% ! Q7*>tvv*F ! Q G G1q5\ )Q<?**qFAaLOy|il1o'EEOF"#&& ! Q  )1X )Q<?a'qEAaLOx{Yq\!_'DDOE"#&& ! Q  )  # #eAh$YPUVWPX$Y1Yq\!_$Y_$Y Z"#3c:J6KQqS5QSTU__aG((;C?  BSXXZ)9)9)@)@5Q$$&5+@+@+B$Wdff5 5    E )e.B.B.D.Mww%(("%T7==9%eW]];aj8A;./q#c'lCM"BC #A@Ea!e M1q1u6Aa6MEM"1q5\=!&q1u=A 1uz.6q!na == C"1q5\I!&q1uIA58A; #:Xa[#HHCIIIIcN #)$&&$''2FF&&2215G((44Q7Hww!|GHe..q111xx1}WXq)E11''33DGGIIe..tww777??588,u4 4 77ehh $Wdff5 5     E )e.B.B.D.L09$''0BC11y|#CCC&&#BB  "d *u/C/C/E/N09%((0CD11y|#DCDB&&#B  "d *u/C/C/E/MBB  FA FBqE C1J/05a:+,H5Q<H vv'::1u{ !Bq1uI36q"QU)3D E41aQ EBq1uI F F!$&&$''2>>gAFGDF4JRH%Z.7MLDE: !Fsr?4i &i&i 5ii=ii %i i%i+ i6. i1 7i62i;*j ;jj i1i6c||dzzSrrrrjs rGrzHolonomicFunction.__sub__+sebj  rIc|dz|zSrrrrjs rGrzHolonomicFunction.__rsub__.sby5  rIc d|zSrrrrs rGrzHolonomicFunction.__neg__1rrIc.|tj|z zSrBrrjs rGrzHolonomicFunction.__truediv__4rrIc|jjdkr|j}|j}|jd}nt |jd|zg}|j d}|j d}t j||j|zj}||fDcgc]}|jj|}}t||} t| |j|j|S|dkr td|jjj } t| |jt"j$t"j&g} |dk(r| S|} |dzr| | z} |dz}|s | S| | z} cc}w)Nr8rz&Negative Power on a Holonomic Functionr)rrrvrrr}r0rrxr"rVr|r^rrr?rUrrr) rdrrrvrp0p1rrQddr\rrxs rGrzHolonomicFunction.__pow__7sm    ! !Q &""CZZFww477mA&!+,"B"B((2tvv&*//B57H=q6;;''*=C=%c62B$R"= = q5#$LM M    $ $ 8 8"2tvvqvvw? 6M 1u!  !GA  FA >s."F cNtd|jjDS)zF Returns the highest power of `x` in the annihilator. c3<K|]}|jywrBdegreerrs rGrz+HolonomicFunction.degree..]sC!188:C)rrr}rs rGr?zHolonomicFunction.degreeYs!Ct'7'7'B'BCCCrIc|jj}|jj}|j|j}|jj }t |D]l\}} t| |jjjjs;|jjjj| ||<n||j|j|i} t|Dcgc]&}||j|j|i | z (} }t|Dcgc]}tj} }tj| d<| g} t!t|Dcgc]}tjc}gj#} | Dcgc]}|j|j}}t|dz D]}||dzxx| ||zz cc<t|D]}||xx| d| |z|zz cc<|} | j%| t!| j#j'|\}}|j(durnt+|d}|j|d}t-|dd|d}|rt/||j|d|dSt/||jScc}wcc}wcc}wcc}w)a` Returns function after composition of a holonomic function with an algebraic function. The method cannot compute initial conditions for the result by itself, so they can be also be provided. Examples ======== >>> from sympy.holonomic.holonomic import HolonomicFunction, DifferentialOperators >>> from sympy import QQ >>> from sympy import symbols >>> x = symbols('x') >>> R, Dx = DifferentialOperators(QQ.old_poly_ring(x),'Dx') >>> HolonomicFunction(Dx - 1, x).composition(x**2, 0, [1]) # e^(x**2) HolonomicFunction((-2*x) + (1)*Dx, x, 0, [1]) >>> HolonomicFunction(Dx**2 + 1, x).composition(x**2 - 1, 1, [1, 0]) HolonomicFunction((4*x**3) + (-1)*Dx + (x)*Dx**2, x, 1, [1, 0]) See Also ======== from_hyper rTr8rNFr)rrvrrrxr}ryrbrVrzr|rrrrrr)rKrgauss_jordan_solverrrr)rdrrrrrrr}rrrFrcoeffssystem homogeneousr coeffs_nextrQtaustaus rG compositionzHolonomicFunction.composition_s4    # #    " "yy %%00 j) IDAq!T--4499??@ $ 0 0 7 7 < < E Ea H 1  I qM  t} -@Eq J1A##TVVDM22Q6JJ"'(+Q!&&++EEq uQx8!qvv89:DDF 39:a166$&&>:K:1q5\ 9AE"vay4'78" 91X @A6":Q#7$#>? @ F MM& !113$$[1 C!!-4jmhhsAQR!e4 $S$&&$q'47C C dff--5K+9:s+K?K"K'2"K,c  |jdk7r)|j|jjS|jj |jr|j |Si}t dd|jjjj}t|jd\}}t|jjD]\}j}t|dz }t!|dzD]z} ||| z } | dk(r|| z | f|vr5||| z | fxx|j#| t%| z dz|zz cc<O|j#| t%| z dz|z||| z | f<|g} |Dcgc]}|d } }t'| t)| } |j+}|z}i}g}g}t!| dzD]k| vrFt-fd|j/Dt0j2 }| j5|M| j5t0j2mt7| |} | j8}t;|jj#| jd d }|j=}|rt)|dz}t)||}||z }t?||}t|Dcgc]\}}|tA|z }}}t||krt!|D]}t0j2}|D]|dzdkrt0j2||dz<nj|dzt|kr||dz||dz<nA|dz|vr7t d |dzz||dz<|j5||dzd|ks||jC|||dzzz }|j5|tE|g|}tG|tHrt!t||D]J}||vrt d |z||<|||vr|j5|||7|j5||L|rtK| ||fgStK| |gSt!t||D]X}||vrt d |z||<d}|D]#||vs |j5||d}%|rE|j5||Z|rtK| ||fgStK| |gScc}wcc}}w)aG Finds recurrence relation for the coefficients in the series expansion of the function about :math:`x_0`, where :math:`x_0` is the point at which the initial condition is stored. Explanation =========== If the point :math:`x_0` is ordinary, solution of the form :math:`[(R, n_0)]` is returned. Where :math:`R` is the recurrence relation and :math:`n_0` is the smallest ``n`` for which the recurrence holds true. If the point :math:`x_0` is regular singular, a list of solutions in the format :math:`(R, p, n_0)` is returned, i.e. `[(R, p, n_0), ... ]`. Each tuple in this vector represents a recurrence relation :math:`R` associated with a root of the indicial equation ``p``. Conditions of a different format can also be provided in this case, see the docstring of HolonomicFunction class. If it's not possible to numerically compute a initial condition, it is returned as a symbol :math:`C_j`, denoting the coefficient of :math:`(x - x_0)^j` in the power series about :math:`x_0`. Examples ======== >>> from sympy.holonomic.holonomic import HolonomicFunction, DifferentialOperators >>> from sympy import QQ >>> from sympy import symbols, S >>> x = symbols('x') >>> R, Dx = DifferentialOperators(QQ.old_poly_ring(x),'Dx') >>> HolonomicFunction(Dx - 1, x, 0, [1]).to_sequence() [(HolonomicSequence((-1) + (n + 1)Sn, n), u(0) = 1, 0)] >>> HolonomicFunction((1 + x)*Dx**2 + Dx, x, 0, [0, 1]).to_sequence() [(HolonomicSequence((n**2) + (n**2 + n)Sn, n), u(0) = 0, u(1) = 1, u(2) = -1/2, 2)] >>> HolonomicFunction(-S(1)/2 + x*Dx, x, 0, {S(1)/2: [1]}).to_sequence() [(HolonomicSequence((n), n), u(0) = 1, 1/2, 1)] See Also ======== HolonomicFunction.series References ========== .. [1] https://hal.inria.fr/inria-00070025/document .. [2] https://www3.risc.jku.at/publications/download/risc_2244/DIPLFORM.pdf r)lbrTintegerSnr8c3^K|]$\}}|dk(r|jz &ywrNrrr3vrrrs rGrz0HolonomicFunction.to_sequence..s8C#q!! FF1a%i0C*-rrZfilterC_%sF)&rshift_x to_sequencerr _frobeniusrrvrVrr;rryr} all_coeffsr~rr|rr%rr?r&itemsrrrr:rr/keysrrrr7rbrr9)rdrLdict1rrrr listofdmpr?r3r2rQkeylistr smallest_ndummyseqsunknownstempr all_rootsmax_rootrru0eqsoleqsrrrs ` @@rGr[zHolonomicFunction.to_sequencesfh 77a<<<(446 6    ' ' 0??b?) ) 3 %%%**.."3#4#4Q#7>1 d..99: QDAq I^a'F6A:& Q!&1*-A:E1:&1q5!*%#,,u*=1q519a@P*PQ%),e)}t|jD] t |s| j|"@n| r| r t|g} n| r(|Dcgc]}|d c}|D cgc]} | d c} z} n| s|Dcgc]}t||k(r|} }ne| sc|j!r%t#|jdj$d k(r t|g} n!|Dcgc] }|dk\s | }}t|g} t'd d -|j(j*j,j.}t1|j3-d \}}g}t5d } D]}i}t7|j(j8D]\} j;}t|dz }t=|dzD]}|||z }|dk(r||z ||z f|vr;|||z ||z fxx|j?|tA-|z dz|z|zz cc<X|j?|tA-|z dz|z|z|||z ||z f<g}|Dcgc]}|d }}t|,tC|}tCd|D}td|D},|z}i}g} g}!t=,|dzD]k |vrFtE ,-fd|jGDt"jH}"|j|"M|jt"jHmtK||}|jL}#tO|j,j?|j8d-d}$|$j}$|$rtC|$dz}%tC|%|}|#|z }#g}&|jdk(r|j|}&n|jd k(r|dk\rt||k(rwt| dk(ritQ||#t|z}'t|'t|kDr:t=t|t|'Dcgc]}|'|tS|z }&}t|&|#krNt=||D]}t"jH}(|D] | dzdkrt"jH|| dz<nx| dzt|&kr|&| dz|| dz<nO| dz|vrEtU|d| dzzz})t'|)|| dz<|!j|| dz d|ks|(| jW-||| dzzz }(| j|(tY| g|!}*t[|*t\rt=t|&|#D]X}||vrtU|d|zz})t'|)||<|||*vr|&j|*||E|&j||Z|r |jt_||&||f|jt_||&|ft=t|&|#D]f}||vrtU|d|zz})t'|)||<d }+|*D]# || vs |&j ||d}+%|+rS|&j||h|r|jt_||&||fn|jt_||&|f|dz }|Scc}wcc} wcc}wcc}wcc}wcc}w)Nc |dS)Nr8rrrxs rGrHz.HolonomicFunction._frobenius..j !A$rI)keyc |dSNrrrros rGrHz.HolonomicFunction._frobenius..krprIrc38K|]}t|dk(ywr8N)r~r@s rGrz/HolonomicFunction._frobenius..~s3!#a&A+3sc3&K|] }|dk\ ywrQrrr@s rGrz/HolonomicFunction._frobenius..s+Q!V+c32K|]}t|ywrB)r r@s rGrz/HolonomicFunction._frobenius..s2qZ]2sTFrrMrOCr8c3&K|] }|d ywrurrr@s rGrz/HolonomicFunction._frobenius..s-!1-rwc3&K|] }|d ywrurrr@s rGrz/HolonomicFunction._frobenius..s.1!A$.rwc3^K|]$\}}|dk(r|jz &ywrQrRrSs rGrz/HolonomicFunction._frobenius..s8 G#'1aAaDAI!"q!e) 4 GrUrrrVrWz_%s)0 _indicialrr_is_realextend as_real_imagsortr~rr rrrr r%rrr is_finiterrrvrVrr;rordryr}r]rr|rrr&r^rr:rr/rrchrrr7rbrr9).rdrL indicialrootsrealscomplrrrgrp independentallposallintrootstoconsiderrposrootsrrrfinalsolcharrr`rar?r3r2rQrbrdegree2rcrdrerfrgrrhrirjrrkletterrlrrrs. ` @@rGr\zHolonomicFunction._frobenius\s( ++-. =Ayy aS=#334~~'1 q!Qi[=+;;<  =   '  '  A3x1} A3 adQh'HHQK  A3 3s33 +U++2E22    D ( OTWW\\^, 2 !3!3!562A#Aq)'..q12 2 "5zlO -01qt154IaQqT4IIO*/CQs1v{qCOC'')Qtwwqz]-D-D-N#&u:,(-7!QA77#&x=/ 3 %%%**.."3#4#4Q#7>13x @ AE!$"2"2"="=> ]1LLN Y!+vz* ]A%fqj1Ez Aq1u~.q1ua!en-#,,u2E1q5ST9WX=Z[H\2\]-14e1Dr!a%RS)VW-YZG[1[q1ua!en- ]  ] C%*+qt+G+LELE-u--F...GJFCH5%!), '< G+0;;= G%&VV-DJJt$JJqvv& '%S!,CIIEaffoocnnR.@A1SQI!(Iy>A- :6 Z EB""$,WWQZ$$&%/AFs1v{sSbOcghOhec!fn5r7SV#8=c!fc"g8NO1"Q%)A,.OBO2ww/#AB" Iqt8aIIaq l3 $A% &), -!23!;Q KL!23!;Q ?@ AIDA@ Bm24ID8<,TPs0- b? bb$+b$: b)b)& b.b3c||j}n|}t|trt|dk(r|d}dnt|trt|dk(r |d|d}nzt|dk(rt|ddk(r |dd}dnPt|dk(r"t|ddk(r|dd|dd}n |Dcgc]}|j |c}S|t z }t|j dz }|jj}|j|j} |jj} |jjj} | j} | D cgc]!} | j| j!#}} t#|Dcgc]}|| ||z c}t%|j |dz|krZt#|dz|z ||z D]Bt'fdt#|Dt(j*}j-|D|rSt'fdt/Dt(j*}|r|t1|t zzz }| dk7r|j3| z S|Scc}wcc} wcc}w) a Finds the power series expansion of given holonomic function about :math:`x_0`. Explanation =========== A list of series might be returned if :math:`x_0` is a regular point with multiple roots of the indicial equation. Examples ======== >>> from sympy.holonomic.holonomic import HolonomicFunction, DifferentialOperators >>> from sympy import QQ >>> from sympy import symbols >>> x = symbols('x') >>> R, Dx = DifferentialOperators(QQ.old_poly_ring(x),'Dx') >>> HolonomicFunction(Dx - 1, x, 0, [1]).series() # e^x 1 + x + x**2/2 + x**3/6 + x**4/24 + x**5/120 + O(x**6) >>> HolonomicFunction(Dx**2 + 1, x, 0, [0, 1]).series(n=8) # sin(x) x - x**3/6 + x**5/120 - x**7/5040 + O(x**8) See Also ======== HolonomicFunction.to_sequence rrrr8)_recurc3^K|]$}|zdk\rt||zz&ywrQ)DMFsubs)rrrrQsubs rGrz+HolonomicFunction.series..is;= !Q!%SVQ/#a!e*<=rUrc3:K|]\}}|zz|zywrBrr)rrr constantpowerrxs rGrz+HolonomicFunction.series..ps$I$!Q1q=()A-I)r[rbtupler~seriesrrj recurrencerrxrr}rvrVrrrrrr&rrrryr4r)rdr coefficientrrrrlr3rseq_dmprrrseqr2serrrQrrxs ` @@@@rGrzHolonomicFunction.series(s: >))+JJ j% (S_-A#AJM  E *s:!/C&qMM#AJ _ !c*Q-&8A&=#Aq)JM _ !c*Q-&8A&=&qM!,M#Aq)J3=>aDKKqK)> > M" "   "  ! ! ' ' FF WW''22  ! ! ( ( - - KKM+23aquuQYY[!33).q2AAwQ2:==! q5191q519a!e, "=%*1X=DEFFL 5! " JI)C.I   5Q]!334a8 8C 788Aq2v& & =?42sJ2&J77J<c |jdk7r)|j|jjS|jj}|jj j |j j} j} fd td|D}dtd|td|jjzz fd t fdt|D}t|D]\\}}|j}t|dz }d||zcxkr|krnn||||z |z |zz}| j! |z z}^t# j%| S)z: Computes roots of the Indicial equation. rcntj|d}d|jvr|dSy)NrVrWr)r/r|r_)polyroot_allrrxs rG _pole_degreez1HolonomicFunction._indicial.._pole_degrees5QZZ-q=HHMMO#{"rIc3<K|]}|jywrBr>)rrs rGrz.HolonomicFunction._indicial..s4AQXXZ4rA r8c0|jrS|SrB)r$)qrinfs rGrHz-HolonomicFunction._indicial..sqyyl1orIc3:K|]\}}||z ywrBrr)rrrdegs rGrz.HolonomicFunction._indicial..s=tq!A =r)rrZr}rr}rvrVrxr_r`rrr%ryr]r~r{r/r|)rd list_coeffryr?rrrrarrrrrxs @@@@@rGr}zHolonomicFunction._indicialxsT 77a<<<(224 4%%00    # # ( ( FF FF EE 444C6NSD,<,<,B,B%CCD= =y'<= =j) %DAq I^a'FAE#V# &1*q.1A55 a!e$ $A  %QZZ]A&&rIcddlm}d}t|dsd}t|}|j|k(r|||g||dS|j st |j}||kDr| }t||z |z } ||zg}t| dz D]} |j|d|zt|jjjj|jjd|j D]!} | |jk(s| |vst#|| |r|||||dS|||||S) a Finds numerical value of a holonomic function using numerical methods. (RK4 by default). A set of points (real or complex) must be provided which will be the path for the numerical integration. Explanation =========== The path should be given as a list :math:`[x_1, x_2, \dots x_n]`. The numerical values will be computed at each point in this order :math:`x_1 \rightarrow x_2 \rightarrow x_3 \dots \rightarrow x_n`. Returns values of the function at :math:`x_1, x_2, \dots x_n` in a list. Examples ======== >>> from sympy.holonomic.holonomic import HolonomicFunction, DifferentialOperators >>> from sympy import QQ >>> from sympy import symbols >>> x = symbols('x') >>> R, Dx = DifferentialOperators(QQ.old_poly_ring(x),'Dx') A straight line on the real axis from (0 to 1) >>> r = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1] Runge-Kutta 4th order on e^x from 0.1 to 1. Exact solution at 1 is 2.71828182845905 >>> HolonomicFunction(Dx - 1, x, 0, [1]).evalf(r) [1.10517083333333, 1.22140257085069, 1.34985849706254, 1.49182424008069, 1.64872063859684, 1.82211796209193, 2.01375162659678, 2.22553956329232, 2.45960141378007, 2.71827974413517] Euler's method for the same >>> HolonomicFunction(Dx - 1, x, 0, [1]).evalf(r, method='Euler') [1.1, 1.21, 1.331, 1.4641, 1.61051, 1.771561, 1.9487171, 2.14358881, 2.357947691, 2.5937424601] One can also observe that the value obtained using Runge-Kutta 4th order is much more accurate than Euler's method. r)_evalfFrT)method derivativesrr8)sympy.holonomic.numericalrrrrrrrrrr/rrvrVr|r}rxr>) rdpointsrhrrlprrrrs rGrzHolonomicFunction.evalfsP\ 5 vz*B& Aww!|dQCKPQSTT;;))A1uBQUaK A!eWF1q5\ . fRj1n- .t''..33<?XX"3(8(8(?(?@ WWq[##%$S!, , aTWW55 Ys:C&c  ||j}n|}t|trt|dk(r |d}|d}d}nt|trt|dk(r|d}|d}|d}nt|dk(r$t|ddk(r|dd}|dd}d}npt|dk(r*t|ddk(r|dd}|dd}|dd}n8|j ||d}|ddD]}||j ||z }|S|j }|j |j} |j} j} | dk(r]tjjjjd|jd} t j"}t%| D]\} }|dks t'|st)|}|t|kr>t||t*t,fr||j/||<|||| |zzz }n|t1d | z| |zzz }t|t*t,fr|j/| |zz}n|| |zz}|r | dk7r|j3| | | z fgS|fgS| dk7r|j3| | | z S|S|| zt|kDr t5d t7fd jdd Drt9||jjd}jd }t|j;t*t,fryt!|j;j/| |j=zz t!|j;j/| |j=zzz }n\t!|j;| |j=zz t!|j;| |j=zzz }d}tjjj||j}tjjj||j}|rg}t?|| zD]}||krU|r;jAt!||| ||zzzj3| | | z fn|t!||| |zzz }^t!||dk(rpg}g}tC|jED])}|jGtI||z | z g||z+tC|jED])}|jGtI||z | z g||z+d|vr|jKdn|jAd|rajAt!||| ||zzzj3| | | z tM|||| | zzj3| | | z f|t!||tM|||| | zzz| |zzz }|rS|| |zz}| dk7r|j3| | | z S|S) a Returns a hypergeometric function (or linear combination of them) representing the given holonomic function. Explanation =========== Returns an answer of the form: `a_1 \cdot x^{b_1} \cdot{hyper()} + a_2 \cdot x^{b_2} \cdot{hyper()} \dots` This is very useful as one can now use ``hyperexpand`` to find the symbolic expressions/functions. Examples ======== >>> from sympy.holonomic.holonomic import HolonomicFunction, DifferentialOperators >>> from sympy import ZZ >>> from sympy import symbols >>> x = symbols('x') >>> R, Dx = DifferentialOperators(ZZ.old_poly_ring(x),'Dx') >>> # sin(x) >>> HolonomicFunction(Dx**2 + 1, x, 0, [0, 1]).to_hyper() x*hyper((), (3/2,), -x**2/4) >>> # exp(x) >>> HolonomicFunction(Dx - 1, x, 0, [1]).to_hyper() hyper((), (), x) See Also ======== from_hyper, from_meijerg Nrr8rr)as_listrrrWrYz+Can't compute sufficient Initial Conditionsc3dK|]'}|jjjk7)ywrBrrrrFs rGrz-HolonomicFunction.to_hyper..ms$C1qAHHMM&&&Cs-0r)'r[rbrr~to_hyperrjrrxrrr/rvrVr|r}rrrryr rr*r+as_exprrrranyr=LCr?rrrr_rr6remover&)rdrrrrcrrQrrjrxrm nonzerotermsrrrrarg1arg2 listofsolapbqr3rFs @rGrzHolonomicFunction.to_hypersKF >))+JJ j% (S_-A#AJ#AJM  E *s:!/C#AJ&qMM#AJ _ !c*Q-&8A&=#Aq)J#Aq)JM _ !c*Q-&8A&=#Aq)J&qM!,M#Aq)J-- 1 -FC^ @t}}WQ}?? @J ]]  ! ! FF WW GG 6 !7!7 Q!H*,,_bcL&&C!,/ 41q5 1 Fs2w;!"Q%+{)CD "1 12a51a4<'C6&!),q!t33C 4# [9:kkma&66A},,7 XXaR0344y Qwxx1r6**J >CG #%&ST T C Qr0BC C%dDGG4 4 LLO LL  addf{K8 9QTTV^^%&QXXZ89Qqttv~~?O=PSTWXW_W_WaSb=bcAQTTV9q188:./1QTTV9q188:3NOAQXX]]++A. =QXX]]++A. = IzA~&% AA :~$$qAx!a o2F'F&L&LQPQRTPT&U%XY1RU8ad?*C Ax1}BBTYY[) > 9a!eq[12T!W<= >TYY[) > 9a!eq[12T!W<= >Bw !  !   1RU8A-,@#@"F"Fq!B$"ORWXZ\^`abcefbf`fRgQmQmnoqrsuquQv!wxqAx%BAqD"99AqD@@K% AL  A}$$ 788Aq2v& & rIcPt|jjS)a_ Converts a Holonomic Function back to elementary functions. Examples ======== >>> from sympy.holonomic.holonomic import HolonomicFunction, DifferentialOperators >>> from sympy import ZZ >>> from sympy import symbols, S >>> x = symbols('x') >>> R, Dx = DifferentialOperators(ZZ.old_poly_ring(x),'Dx') >>> HolonomicFunction(x**2*Dx**2 + x*Dx + (x**2 - 1), x, 0, [0, S(1)/2]).to_expr() besselj(1, x) >>> HolonomicFunction((1 + x)*Dx**3 + Dx**2, x, 0, [1, 1, 1]).to_expr() x*log(x + 1) + log(x + 1) + 1 )r5rsimplifyrs rGrzHolonomicFunction.to_exprs&4==?+4466rIcd}|At|j|jjkDrt|j}|jjj j } t|j|j|||}|rj|k(r|S|j|d}t|j|j||S#ttf$rd}Y[wxYw)a Changes the point `x0` to ``b`` for initial conditions. Examples ======== >>> from sympy.holonomic import expr_to_holonomic >>> from sympy import symbols, sin, exp >>> x = symbols('x') >>> expr_to_holonomic(sin(x)).change_ics(1) HolonomicFunction((1) + (1)*Dx**2, x, 1, [sin(1), cos(1)]) >>> expr_to_holonomic(exp(x)).change_ics(2) HolonomicFunction((-1) + (1)*Dx, x, 2, [exp(2)]) T)rxrlenicsrDF)r)r~rrrrvrVrDexpr_to_holonomicrrxr<r=rrr)rdrrsymbolicrrQrs rGrzHolonomicFunction.change_icss$ >c$''lT-=-=-C-CC\F%%**11 #DLLNdff6Z]^C ! J ZZtZ , !1!14661bAA$%89 H s1(C!!C54C5c|jd}tj}|D]?}t|dk(r ||dz }t|dk(s)||dt |dzz }A|S)a Returns a linear combination of Meijer G-functions. Examples ======== >>> from sympy.holonomic import expr_to_holonomic >>> from sympy import sin, cos, hyperexpand, log, symbols >>> x = symbols('x') >>> hyperexpand(expr_to_holonomic(cos(x) + sin(x)).to_meijerg()) sin(x) + cos(x) >>> hyperexpand(expr_to_holonomic(log(x)).to_meijerg()).simplify() log(x) See Also ======== to_hyper T)rr8rr)rrrr~_hyper_to_meijerg)rdr"rQrs rG to_meijergzHolonomicFunction.to_meijergss,mmDm)ff 6A1v{qt Q1qt/!555  6 rIrQFT)FTN)RK4g?F)FNrB)$rmrnrorprrergrqrrrrrrrrlrrrrrrrr?rJr[r\rr}rrrZrrrrrrrIrGrrts@DL:H<  LO;b}?~K;Z_?BH!!& DD >.@{,zJXN`"'HILV ;6 n`7*!BF rIrFc|j}|j}|jd}|jtj }t tj|d\}}||z} d} |D] } | | | zz} | dz } |} |D] }| | |zz} | | z }t|}|ttfvrt||j|St|ts[t!||||j"d}|s"|dz }t!||||j"d}|s"t||j|||St|tr_d}t!||||j"|d}|s#|dz }t!||||j"|d}|s#t||j|||St||j|S)a Converts a hypergeometric function to holonomic. ``func`` is the Hypergeometric Function and ``x0`` is the point at which initial conditions are required. Examples ======== >>> from sympy.holonomic.holonomic import from_hyper >>> from sympy import symbols, hyper, S >>> x = symbols('x') >>> from_hyper(hyper([], [S(3)/2], x**2/4)) HolonomicFunction((-x) + (2)*Dx + (x)*Dx**2, x, 1, [sinh(1), -sinh(1) + cosh(1)]) rr\r8F use_limit)rrratomsrpoprYr,rr5rrrrJrbr&_find_conditionsr)funcrrrrrrxrr\xDxr1aixDx_1r2birQsimprs rG from_hyperrs A A ! A A !""2"21"5t >> from sympy.holonomic.holonomic import from_meijerg >>> from sympy import symbols, meijerg, S >>> x = symbols('x') >>> from_meijerg(meijerg(([], []), ([S(1)/2], [0]), x**2/4)) HolonomicFunction((1) + (1)*Dx**2, x, 0, [0, 1/sqrt(pi)]) rr\r8rFr)rrr~anbmrrrrrYrrrJr5rrrbr'rr)rrrrrDrrrrrrrxrr\rxDx1rrrrrQrrs rG from_meijergrNs" A A DGG A DGG A AA ! A A !&"6"6q"94 @EAr B$C 7D B!a%!)  B dRi B cBh r'C  a(44Q77 t D *++ a(44Q77 dG $ dAr399 F !GB!$2syyEJB!a(44QB??$  dAr399eu M !GB!$2syy%5QB!a(44QB?? S! $ 0 0 33rIx_1N)_mytypec t|}|j}|s*t|dk(r|j}n t d||vr|j |t |}|C|jtrt}nt}t|dk7r||j}t|||||||} | r| Sts|aia tt|n|tk7r|aia tt||j rd|j#|t$} t'| t$} | tvr!t| } | ddj)|} nt+||d|} | st,|r|| _|s|s || _| S|s| j2j4}t7||||}|s|dz }t7||||}|st9| j2|||S|s|s0| j;|j<d} |r|| _|| _| S|s| j2j4}t7||||}|s|dz }t7||||}|s| j;|j<d||S|j<}|j>} tA|d|d|} | tBur0tEdt|D]}| tA|||d|z } nH| tFur0tEdt|D]}| tA|||d|z} n| tHur| |dz} || _| st,|r|| _|s|s| S| j.r| S|s| j2j4}| j2jK|r| jM}t |} t|dk(r||| dtNjPk(rc| d}|||z |zz }t7||||}tS|Dcgc]\}}|tU|z }}}||i}t9| j2|||St7||||}|s|dz }t7||||}|st9| j2|||Scc}}w) a Converts a function or an expression to a holonomic function. Parameters ========== func: The expression to be converted. x: variable for the function. x0: point at which initial condition must be computed. y0: One can optionally provide initial condition if the method is not able to do it automatically. lenics: Number of terms in the initial condition. By default it is equal to the order of the annihilator. domain: Ground domain for the polynomials in ``x`` appearing as coefficients in the annihilator. initcond: Set it false if you do not want the initial conditions to be computed. Examples ======== >>> from sympy.holonomic.holonomic import expr_to_holonomic >>> from sympy import sin, exp, symbols >>> x = symbols('x') >>> expr_to_holonomic(sin(x)) HolonomicFunction((1) + (1)*Dx**2, x, 0, [0, 1]) >>> expr_to_holonomic(exp(x)) HolonomicFunction((-1) + (1)*Dx, x, 0, [1]) See Also ======== sympy.integrals.meijerint._rewrite1, _convert_poly_rat_alg, _create_table r8z%Specify the variable for the functionr)rrrrDr)rDFrrD)rxrrD)+r free_symbolsr~r ValueErrorrrr!r r-r,r_convert_poly_rat_alg _lookup_tabledomain_for_table _create_table is_Functionrrrr_convert_meijerintrrrrrrrrJrrrrrrrrr}rrryr)rrxrrrrDrsyms extra_symssolpolyftrrQrrrrFg singular_icsrs rGrrsXR 4=D   D t9>xxzADE E d AdJ ~ 88E?FF z?a J'113F$D!r&QWbjkG ! mF3 # #! mF3  IIa  AsO a AA$q'""1%C$T1uVLC)) .."4B7Ca&tQF;%S__aSA A X//$))A,/CCFJ__**FtQF3 !GB"4B7Ctyy|R55 99D A DGq5 HCCxq#d)$ RA $T!WE&Q QC R cq#d)$ RA $T!WE&Q QC R c47l CF !!    vv && ""2& MMO G q6Q;1QqT7aee+!AB{"A+Aq"f=L9B<9PQAA ! ,QLQL!B$S__aR@ @ 4B /C atQF3 S__aS 99Rs!Qcg}g}|j}|j}|jtj}g}t |D]\} } t | |jr/|j|j| jnQt | |js*|j|jt| n|j| |j|| j|j|| j|D]} | j|}|r| }|j|j}t |D] \} } | |z|| <||dj|djz j} |D]} | j| } |j| j} t |D]B\} } | | z } || j| jz j|| <Dt!||S)z' Normalize a given annihilator r)rVrr{rrryrbrzrrrrnumerdenomlcmgcdr^) list_ofrvrnumrrVr lcm_denom list_of_coeffrr gcd_numerfrac_anss rGrr; s% C E ;;D A&IM'" /1 a $  qyy{!3 4Aqww'  gaj!9 :   # =#))+,  ]1%++-. /%EE)$ %J i'')*I-()1y= a)mB'--/-2C2I2I2KKTTVWI%EE)$ %i'')*I-(Q1y=!1HNN4D!D M M OP aQ v 66rIcg}t|dz }|jt|d|t|ddD]&\}}|jt||||z(|j|||S)a* Let a differential equation a0(x)y(x) + a1(x)y'(x) + ... = 0 where a0, a1,... are polynomials or rational functions. The function returns b0, b1, b2... such that the differential equation b0(x)y(x) + b1(x)y'(x) +... = 0 is formed after differentiating the former equation. r8rN)r~rr#ry)r}rrQrrrs rGrrt s~ C J!AJJwz!}a()*QR.)21 71a=:a=012JJz!} JrIcn|j}|j}td|Dr t|S|jd}d|D}d}t j f}d|D}t j}|D]} |t| z}|D]} |t| z }|t||||| zS)z( Converts a `hyper` to meijerg. c3FK|]}|dkxrt||k(ywrQ)rr@s rGrz$_hyper_to_meijerg.. s$ .a16 !c!fk ! .s!rc3&K|] }d|z  ywrurrr@s rGrz$_hyper_to_meijerg.. s A!a% rwrrc3&K|] }d|z  ywrurrr@s rGrz$_hyper_to_meijerg.. s Q1q5 rw) rrrr5rrrrr%r') rrrrranprbmqr3rs rGrr s B B .2 ..4   ! A  B C &&B " C A  aL aL wr3C!, ,,rIct|t|kr3t||Dcgc] \}}||z c}}|t|dz}|St||Dcgc] \}}||z c}}|t|dz}|Scc}}wcc}}w)zvTakes polynomial sequences of two annihilators a and b and returns the list of polynomials of sum of a and b. N)r~r)list1list2rrrQs rGrr s 5zSZ!$UE!23Aq1u3eCJK6HH J"%UE!23Aq1u3eCJK6HH J43s A>Bc |jj|js|jdk(r |jS|j}|j }g}|j}|j j}|j}|jD][}t||j jjs.|j|j|j]t||ks|t|kr|St!|D cgc]} ||  ||z } } |dt#t||} t!||z D]} d} t%| | D]\\}}t'||j}t)|dds|ccSt|t*t,fr|j/}| ||zz } ^| j| t1| |} || t|dzScc} w)zy Tries to find more initial conditions by substituting the initial value point in the differential equation. TNrr)rrrrrrrvrVrr}rbrzrrrr~rr%rrgetattrr*r+rr) Holonomicrrrr}rrrrrlist_redrrrQrrFs rGrr s ((6):R:R:TX\:\||''KAJ BA A  # #2 a++0066 7   aeeAIIK0 12 2w{a3r7l q#AA.#H# SR!_ B 1q5\ 2H% DAq9<<(A1k40 !k;78IIK 1q5LC   #$Xq1 2 3r78 #s&Hc,t|ts|jS|j|}|j |}| |jz||jzz}|dz}||j |j fSrs)rbr.rrrr)fracrrrsol_num sol_denoms rGr#r# s{ dC yy{  A  AcAFFHnq1668|+G1I goo!2!2!4 5 66rIc|t|ts|S|j}|j}tj }tj }|rddlm}tt|D]6\}} |r$t| jj} || ||zzz }8tt|D]6\}} |r$t| jj} || ||zzz }8t|ttfr|j}t|ttfr|j}||z S)Nr)mp)rbr.rdenrrmpmathrryreversedr _to_mpmathprecr*r+r) rrmpmrrsol_psol_qrrrs rGrr s dC   A A FFE FFE (1+&1  %%bgg.A RU (1+&1  %%bgg.A RU %+{34 %+{34  5=rIc|j}|s|j}nd}|sj|sh|j\} } | jrB| jr6t | t r t | } | j| j} } d} nd} nd} |s|s| sy|j|}t|d\}}|j|st||d|gS|r||z|j|z }t|j|j d}|j#|}|*|dk(r$|r!|j%|j'}t)t+|D]%\}}|dk(r t-t+||d}|}nt)D]/\}}t |t.t0fs|j3||<1t5|i}nz|ri|j7\}}||z|z||j|zz||j|zz }t|j|j d}n| r  | z z|zdz }t||j9 j:}|j#|}||dk(r|r||dkr|j%| j'}t)t+|D]N\}}|dk(r t |t.t0fr|j3}t5| z}t5|| z}nt t.t0fr|j3}t5|gi}|s|st|||S|s j<}j#|rt|||j?}t-|}tA|dk(rr||dt4jBk(rY|d}|||z |zz }tE||||}t)|Dcgc]\}}|tG|z }}}||i}t||||StE||||}|s|dz }tE||||}|st||||Scc}}w)zO Converts polynomials, rationals and algebraic functions to holonomic. TFNr\rrr8)$ is_polynomialis_rational_function as_base_exprrbr r6rrrrYr!rrrr}rvrr{rryr"rr*r+rras_numer_denomrJrrr}r~rrr)rrxrrrrDrispolyisratbasepolyratexprris_algrrr\rQrr"rrr2indicialrrrFrrrs rGrr s:    !F ))+ e++-&  ! ! #(8(8&%("6*88VXXqAFF evQA !!T *EAr 88A; QD622 Ri$))A,&eDoob)  :"'k,,t$,,.C!(3-0 16Xc]+AB/   "%( +1a+{!;< yy{E!H +AeH%B ""$1!ebj1qvvay=(1qvvay=8eD 1q5kB"Q'33H=IIoob)  :"'k ^v{,,x(002C!(3-0 16a+{!;< A!f Q4&= %+{!;< AugJ'B  aR00  r c1b ) 3 3 5 G q6Q;1QqT7aee+!AB{"A+Aq"f=L9B<9PQAA ! ,QLQL!B$S!R4 4 $2v .B a dAr6 2 S!R ,,Rs>Qc"tj|}|r|\}}}}ny|D cgc] } || dz } } |j} | dk(r| dntj} |D cgc] } | | dz } } |D cgc]} | d }} fd}||d| d\}}| d|zt |||z}t dt|D].} ||| | | \}}|| | |zt |||zz }0|Scc} wcc} wcc} w)Nrr8rc8 |jd}|jtr|jtt }|j d}t|d}||}|j}|d k(r|dntj}||z fd|jddD} fd|jddD} fd|jddD} fd |jddD} | zt||f| | f|fS) NrF)rrr8c3(K|] }|z ywrBrrrs rGrz5_convert_meijerint.._shift..  -a!e -c3(K|] }|z ywrBrrrs rGrz5_convert_meijerint.._shift.. r6r7c3(K|] }|z ywrBrrrs rGrz5_convert_meijerint.._shift.. r6r7c3(K|] }|z ywrBrrrs rGrz5_convert_meijerint.._shift.. r6r7) rr!r rrrcollectrr+rrr') rrrdrrrrrrrrFrxs @rG_shiftz"_convert_meijerint.._shift~ s IIbM 558y#&A IIa%I ( GAJ aD MMOaDAIAaD166 E -TYYq\!_ - -TYYq\!_ - -TYYq\!_ - -TYYq\!_ -1"ugr2hR!444rIr)r( _rewrite1r+rrrrr~)rrxrrDrfacporrrfac_listrrpo_listG_listr=r2rrQs ` rGrrn sC   tQ 'D  RA%&&qad &H& A! !qvvA!"#Aq1Q4x#G# qad F 5&fQi,HE1 1+  Q& Q QC1c&k "W&)WQZ0q x{U"\!hv%VVVW JE'$ sD)D> D c Jd fd }|jt}t|d\}}|tt|dzdztdddg|t t|dzdztdddg|t t|dz tdd|t t|t|dzzztdddg|ttdtz|z|dzztdddttz g|ttdtz|z|dzztdddttz g|ttdtz|z|dzztdddttz g|tt|dzdz tdddg|tt|dzdz tdddg|tttd|zzt|dzzzt|ttt|zd|dzzzt|dzzzt|t!tt|zd|dzzzt|dzzzt|t#tt |zd|dzzzt|dzzzty) zi Creates the look-up table. For a similar implementation see meijerint._create_lookup_table. rc jt|tgj|t ||||fy)z2 Adds a formula in the dictionary N)rrrrr)formularargrrtables rGaddz_create_table..add s< #.3::G k3B 7<9 :rIr\rr8rN)rrr)rrrYrrrrr"rr r#r$rrrr!rr )rHrDrIrrr\s` rGrr s- : S!A !!T *EArC"a%!)S!aV,C"a%!)S!aV,C"q&#q!$C"s2q5y.#q1a&1C!C%(RU"CQ$r( O<S 1S58b!e#S!aDH-=>S 2c6"9r1u$c1q!DH*o>S 2q519c1q!f-S 2q519c1q!f-S 32:BE )3/3R!BE'!CAI-s33R!BE'!CAI-s3C3$r'Ab!eG#c"a%i/5rIc4g}t|D]}|j||}|r|j}|rt|tr t |||}|j dust|try|j||j|}|S)NF) rrrrbrr3rrr) rrxrrrrrrvals rGrr s B 5\ ii2 ))+C C-a$C ==E !ZS%9 #yy|  IrI)rF)NrNNNTrr)FT)trp sympy.corerrrsympy.core.numbersrrrr r r r r sympy.core.singletonrsympy.core.sortingrsympy.core.symbolrrsympy.core.sympifyr(sympy.functions.combinatorial.factorialsrrr&sympy.functions.elementary.exponentialrrr%sympy.functions.elementary.hyperbolicrr(sympy.functions.elementary.miscellaneousr(sympy.functions.elementary.trigonometricrrr'sympy.functions.special.error_functionsrr r!r"r#r$'sympy.functions.special.gamma_functionsr%sympy.functions.special.hyperr&r'sympy.integralsr(sympy.matricesr)sympy.polys.ringsr*sympy.polys.fieldsr+sympy.polys.domainsr,r-sympy.polys.polyclassesr.sympy.polys.polyrootsr/sympy.polys.polytoolsr0sympy.polys.matricesr1sympy.printingr2sympy.series.limitsr3sympy.series.orderr4sympy.simplify.hyperexpandr5sympy.simplify.simplifyr6sympy.solvers.solversr7rr9r:r;holonomicerrorsr<r=r>r?rRrYrTr^rrrrrrsympy.integrals.meijerintrrrrrrrr#rrrrrrrrIrGrlsQ %$""""&+&LLFF>9EERR98%!)*&''&-%$2-'RR))#,LA3A3HSGSGlXXv4<4~54@4F El -_:H67r(-:&R 7>'(DbSWg-T*.b+\!#"6J rI