
    Rier                       d Z ddlmZmZmZ ddlmZmZmZm	Z	m
Z
mZmZ ddlmZ ddlmZ ddlmZmZ ddlmZ ddlmZmZmZ dd	lmZmZmZ dd
lmZm Z  ddl!m"Z" ddl#m$Z$m%Z%m&Z& ddl'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z- ddl.m/Z/ ddl0m1Z1m2Z2 ddl3m4Z4 ddl5m6Z6 ddl7m8Z8 ddl9m:Z: ddl;m<Z<m=Z= ddl>m?Z? ddl@mAZA ddlBmCZC ddlDmEZE ddlFmGZG ddlHmIZI ddlJmKZK ddlLmMZM ddlNmOZO ddlPmQZQ dd lRmSZSmTZTmUZU dd!lVmWZWmXZXmYZYmZZZ d" Z[d# Z\ G d$ d%          Z] G d& d'          Z^ G d( d)          Z_d=d+Z`dd*d,e<fd-Za ed.          Zbd/acd/addd0lemfZf d>d1Zgd?d2Zhd3 Zid4 Zjd5 Zkd6 Zld7 Zmd@d8Zndd/d/e<d,fd9Zod,e<fd:Zpe<fd;Zqd< Zrd/S )AzL
This module implements Holonomic Functions and
various operations on them.
    )AddMulPow)NaNInfinityNegativeInfinityFloatIpiequal_valued)S)ordered)DummySymbol)sympify)binomial	factorialrf)	exp_polarexplog)coshsinh)sqrt)cossinsinc)CiShiSierferfcerfi)gamma)hypermeijerg)	meijerint)Matrix)PolyElement)FracElement)QQRR)DMF)roots)Poly)DomainMatrix)sstr)limit)Order)hyperexpand)	nsimplify)solve   )HolonomicSequenceRecurrenceOperatorRecurrenceOperators)NotPowerSeriesErrorNotHyperSeriesErrorSingularityErrorNotHolonomicErrorc                       fd}                      |          \  }}|j        d         } |d|f          |z  }||z                                   }|S )Nc                 8    t          j        | j                  S N)r0   onesdomain)shapers    9lib/python3.11/site-packages/sympy/holonomic/holonomic.py<lambda>z(_find_nonzero_solution.<locals>.<lambda>+   s    *5!(;;     r   r7   )_solverD   	transpose)rE   homosysrB   
particular	nullspacenullitynullpartsols   `       rF   _find_nonzero_solutionrQ   *   sf    ;;;;DHHW--J	oa GtQL!!I-H 
+
+
-
-CJrH   c                 4    t          | |          }||j        fS )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
    )DifferentialOperatorAlgebraderivative_operator)base	generatorrings      rF   DifferentialOperatorsrX   4   s"    D 'tY77D$*++rH   c                   (    e Zd ZdZd Zd ZeZd ZdS )rS   a  
    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        |j        g|           | _        |t          dd          | _        d S t          |t                    rt          |d          | _        d S t          |t
                    r	|| _        d S d S )NDxF)commutative)	rU   DifferentialOperatorzeroonerT   r   
gen_symbol
isinstancestr)selfrU   rV   s      rF   __init__z$DifferentialOperatorAlgebra.__init__   s    	#7Y!4$) $)  $Tu===DOOO)S)) ,"("F"F"FIv.. ,"+, ,rH   c                 n    dt          | j                  z   dz   | j                                        z   }|S )Nz9Univariate Differential Operator Algebra in intermediate z over the base ring )r1   r`   rU   __str__)rc   strings     rF   rf   z#DifferentialOperatorAlgebra.__str__   s>    L4?##$&<=Y!!" rH   c                 J    | j         |j         k    r| j        |j        k    rdS dS NTF)rU   r`   rc   others     rF   __eq__z"DifferentialOperatorAlgebra.__eq__   s*    9
""t%:J'J'J45rH   N)__name__
__module____qualname____doc__rd   rf   __repr__rl    rH   rF   rS   rS   Z   sS        $ $L, , ,   H    rH   rS   c                   f    e Zd ZdZdZd Zd Zd Zd ZeZ	d Z
d Zd	 Zd
 Zd Zd ZeZd Zd ZdS )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                    || _         | j         j        }t          |j        d         t                    r|j        d         n|j        d         d         | _        t          |          D ]k\  }}t          ||j                  s&|                    t          |                    ||<   @|                    |
                    |                    ||<   l|| _        t          | j                  dz
  | _        dS )z
        Parameters
        ==========

        list_of_poly:
            List of polynomials belonging to the base ring of the algebra.
        parent:
            Parent algebra of the operator.
        r   r7   N)parentrU   ra   gensr   x	enumeratedtype
from_sympyr   to_sympy
listofpolylenorder)rc   list_of_polyrv   rU   ijs         rF   rd   zDifferentialOperator.__init__   s     {!+DIaL&!A!AV1tyQR|TU
 l++ 	D 	DDAqa,, D"&//'!**"="=Q"&//$--2B2B"C"CQ&))A-


rH   c                      j         }t          |t                    sQt          | j        j        j                  s. j        j                            t          |                    g}n|g}n|j         }d } ||d         |          } fd}t          dt          |                    D ]-} ||          }t          | |||         |                    }.t          | j                  S )z
        Multiplies two DifferentialOperator and returns another
        DifferentialOperator instance using the commutation rule
        Dx*a = a*Dx + a'
        c                 z    t          |t                    r!g }|D ]}|                    || z             |S | |z  gS rA   )ra   listappend)blistofotherrP   r   s       rF   _mul_dmp_diffopz5DifferentialOperator.__mul__.<locals>._mul_dmp_diffop   sS    +t,, )$ & &AJJq1u%%%%
K((rH   r   c                    j         j        j        g}g }t          | t                    rB| D ]>}|                    |           |                    |                                           ?nv|                    j         j                            |                      |                    j         j                            |                                                      t          ||          S rA   )	rv   rU   r^   ra   r   r   diffr{   
_add_lists)r   sol1sol2r   rc   s       rF   
_mul_Dxi_bz0DifferentialOperator.__mul__.<locals>._mul_Dxi_b  s    K$)*DD!T"" C * *AKKNNNKK))))* DK,77::;;;DK,77::??AABBBdD)))rH   r7   )r}   ra   r]   rv   rU   rz   r{   r   ranger~   r   )rc   rk   
listofselfr   r   rP   r   r   s   `       rF   __mul__zDifferentialOperator.__mul__   s    _
%!566 	+eT[%5%;<< &#{/::75>>JJK  %g*K	) 	) 	) ojm[99	* 	* 	* 	* 	* q#j//** 	O 	OA$*[11KS//*Q-"M"MNNCC#C555rH   c                 8   t          |t                    st          || j        j        j                  s,| j        j                            t          |                    }g }| j        D ]}|                    ||z             t          || j                  S d S rA   )	ra   r]   rv   rU   rz   r{   r   r}   r   )rc   rk   rP   r   s       rF   __rmul__zDifferentialOperator.__rmul__  s    %!566 		:eT[%5%;<< F)55gennEEC_ & &

519%%%%'T[999		: 		:rH   c                    t          |t                    r/t          | j        |j                  }t          || j                  S | j        }t          || j        j        j                  s.| j        j                            t          |                    g}n|g}g }|	                    |d         |d         z              ||dd          z  }t          || j                  S )Nr   r7   )
ra   r]   r   r}   rv   rU   rz   r{   r   r   )rc   rk   rP   	list_self
list_others        rF   __add__zDifferentialOperator.__add__%  s    e122 	:T_e.>??C'T[999 IeT[%5%;<< % $1==gennMMN

#W
CJJy|jm34449QRR= C'T[999rH   c                     | d|z  z   S Nrr   rj   s     rF   __sub__zDifferentialOperator.__sub__9  s    rUl""rH   c                     d| z  |z   S r   rr   rj   s     rF   __rsub__zDifferentialOperator.__rsub__<  s    d{U""rH   c                     d| z  S r   rr   rc   s    rF   __neg__zDifferentialOperator.__neg__?      DyrH   c                 &    | t           j        |z  z  S rA   r   Onerj   s     rF   __truediv__z DifferentialOperator.__truediv__B      quu}%%rH   c                    |dk    r| S |dk    r%t          | j        j        j        g| j                  S | j        | j        j        j        k    rN| j        j        j        g|z  }|                    | j        j        j                   t          || j                  S |dz  dk    r| |dz
  z  }|| z  S |dz  dk    r| |dz  z  }||z  S d S )Nr7   r      )r]   rv   rU   r_   r}   rT   r^   r   )rc   nrP   	powreduces       rF   __pow__zDifferentialOperator.__pow__E  s    66K66')9)=(>LLL ?dk=HHH;#()!+CJJt{'+,,,'T[999 1uzz 1q5M	 4''Q! 1q5M	 9,, rH   c                    | j         }d}t          |          D ]\  }}|| j        j        j        k    r|dk    r|dt          |          z   dz   z  }:|r|dz  }|dk    r&|dt          |          z   d| j        j        z  z   z  }m|dt          |          z   dz   d| j        j        z  z   t          |          z   z  }|S )	N r   ()z + r7   z)*%sz*%s**)r}   ry   rv   rU   r^   r1   r`   )rc   r}   	print_strr   r   s        rF   rf   zDifferentialOperator.__str__Z  s    _
	j)) 	[ 	[DAqDK$)))AvvS477]S00	 #U"	AvvS477]Vdk6L-MMM	tAww,w9O/PPSWXYSZSZZZIIrH   c                     t          |t                    r$| j        |j        k    r| j        |j        k    rdS dS | j        d         |k    r*| j        dd          D ]}|| j        j        j        ur dS dS dS )NTFr   r7   )ra   r]   r}   rv   rU   r^   )rc   rk   r   s      rF   rl   zDifferentialOperator.__eq__s  s    e122 	%"222t{el7R7Rtuq!U**, % %A 0 555$uu 6turH   c                     | j         j        }|t          |                    | j        d                   | j                  v S )zH
        Checks if the differential equation is singular at x0.
        r   )rv   rU   r.   r|   r}   rx   )rc   x0rU   s      rF   is_singularz DifferentialOperator.is_singular  s8    
 {U4==)<==tvFFFFrH   N)rm   rn   ro   rp   _op_priorityrd   r   r   r   __radd__r   r   r   r   r   rf   rq   rl   r   rr   rH   rF   r]   r]      s        ! !F L. . .<36 36 36j
: 
: 
:: : :$ H# # ## # #  & & &- - -*  . H  G G G G GrH   r]   c                       e Zd ZdZdZd'dZd ZeZd Zd Z	d	 Z
d
 Zd Zd(dZd Zd Zd ZeZd Zd Zd Zd Zd Zd Zd Zd)dZd)dZd*dZd Zd+d Zd! Zd" Zd,d#Z d$ Z!d-d%Z"d& Z#dS ).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

    rt   r   Nc                 >    || _         || _        || _        || _        dS )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   )rc   r   rx   r   r   s        rF   rd   zHolonomicFunction.__init__  s%    , &rH   c           
      8   |                                  rXdt          | j                  dt          | j                  dt          | j                  dt          | j                  d	}n-dt          | j                  dt          | j                  d}|S )NzHolonomicFunction(z, r   )_have_init_condrb   r   r1   rx   r   r   )rc   str_sols     rF   rf   zHolonomicFunction.__str__  s    !! 	 	=@AQ=R=R=R=RTVd47mmmmT$']]]]<GG	 699I5J5J5J5JTVG rH   c                 ^  	
 | j         j        j        	|j         j        j        
	j        }
j        }	
k    r| |fS |                    |                              | j                  }t          |t          | j         j        j	                            \  }}	fd| j         j
        D             }
fd|j         j
        D             }t          ||          }t          ||          }t          || j        | j        | j                  }t          ||j        |j        |j                  }||fS )z^
        Unifies the base polynomial ring of a given two Holonomic
        Functions.
        c                 :    g | ]}                     |          S rr   r|   ).0r   R1s     rF   
<listcomp>z+HolonomicFunction.unify.<locals>.<listcomp>  s#    DDD1ADDDrH   c                 :    g | ]}                     |          S rr   r   )r   r   R2s     rF   r   z+HolonomicFunction.unify.<locals>.<listcomp>  s#    EEE1AEEErH   )r   rv   rU   domunifyold_poly_ringrx   rX   rb   r`   r}   r]   r   r   r   )rc   rk   dom1dom2R	newparent_r   r   r   r   s            @@rF   r   zHolonomicFunction.unify  s     $)%*vv88%= ZZ,,TV44,QD4D4K4V0W0WXX	1DDDD(8(CDDDEEEE(9(DEEE#D)44#D)44 tvtw@@ uw%(CCd|rH   c                 v    t          | j        t                    rdS t          | j        t                    rdS dS )z
        Returns True if the function have singular initial condition
        in the dictionary format.

        Returns False if the function have ordinary initial condition
        in the list format.

        Returns None for all other cases.
        TFN)ra   r   dictr   r   s    rF   is_singularicsz HolonomicFunction.is_singularics  s@     dgt$$ 	4&& 	5	 	rH   c                 *    t          | j                  S )z@
        Checks if the function have initial condition.
        )boolr   r   s    rF   r   z!HolonomicFunction._have_init_cond'  s     DG}}rH   c                    t          | j                  d         | j                 }t          | j                  dk    rt                    k    rdk    rg }t                    t	                    D ]!}|                    t          j                   "|fdt          |          D             z  }t          | j
        | j        | j        |          S dS dS dS )zP
        Converts a singular initial condition to ordinary if possible.
        r   r7   c                 @    g | ]\  }}|t          |z             z  S rr   r   )r   r   r   as      rF   r   z9HolonomicFunction._singularics_to_ord.<locals>.<listcomp>9  s.    AAADAq1yQ'''AAArH   N)r   r   r~   intr   r   r   Zerory   r   r   rx   r   )rc   r   r   r   r   s       @rF   _singularics_to_ordz%HolonomicFunction._singularics_to_ord-  s     MM!GAJtw<<1c!ffQBAA1XX " "		!&!!!!AAAAIaLLAAAAB$T%5tvtwKKK rH   c                    | j         j        j        |j         j        j        k    r|                     |          \  }}||z   S | j         j        }|j         j        }t          ||          }| j         j        j        }|                                }| j         g}	|j         g}
| j         j        j        }t          ||z
            D ]"}||	d         z  }|		                    |           #t          ||z
            D ]"}||
d         z  }|
	                    |           #|	|
z   }g }|D ]}g }t          |dz             D ]m}|t          |j                  k    r|	                    |j                   5|	                    |                    |j        |         j                             n|	                    |           t          |t          |          |dz   f|                                          }t          j        |dz   df|          }t%          ||          }|j        rO|dz  }||	d         z  }|		                    |           ||
d         z  }|
	                    |           |	|
z   }g }|D ]}g }t          |dz             D ]m}|t          |j                  k    r|	                    |j                   5|	                    |                    |j        |         j                             n|	                    |           t          |t          |          |dz   f|                                          }t          j        |dz   df|          }t%          ||          }|j        O|                                d |dz   |z
           }t+          || j         j                  }|| j         z  }t+          |j        | j         j        d          }|                                 r|                                st/          || j                  S |                                 dk    r|                                dk    rn| j        |j        k    r`t7          | |j                  }t7          ||j                  }d t9          ||          D             }t/          || j        | j        |          S | j                             d          }|j                             d          }| j        dk    r|s|s| |                    d          z   S |j        dk    r|s|s|                     d          |z   S | j                             | j                  }|j                             | j                  }|s|s| |                    | j                  z   S |                     |j                  |z   S | j        |j        k    rt/          || j                  S d }d }|                                 dk    rL|                                dk    r4d t?          | j                   D             }tB          j"        |i}|j         }n|                                 dk    rL|                                dk    r4d	 t?          |j                   D             }| j         }tB          j"        |i}n>|                                 dk    r&|                                dk    r| j         }|j         }i }|D ];}||v r*d
 t9          ||         ||                   D             ||<   0||         ||<   <|D ]}||vr||         ||<   t/          || j        | j        |          S )Nr   r7   Fnegativec                     g | ]
\  }}||z   S rr   rr   r   r   r   s      rF   r   z-HolonomicFunction.__add__.<locals>.<listcomp>  s     4441a!e444rH   r   Tc                 8    g | ]\  }}|t          |          z  S rr   r   r   r   r   s      rF   r   z-HolonomicFunction.__add__.<locals>.<listcomp>  '    CCC11y||#CCCrH   c                 8    g | ]\  }}|t          |          z  S rr   r   r   s      rF   r   z-HolonomicFunction.__add__.<locals>.<listcomp>  '    DDD11y||#DDDrH   c                     g | ]
\  }}||z   S rr   rr   r   s      rF   r   z-HolonomicFunction.__add__.<locals>.<listcomp>  s     ===41aQ===rH   )#r   rv   rU   r   r   max	get_fieldrT   r   r   r~   r}   r^   newrepr0   rJ   zerosrQ   is_zero_matrixflat
_normalizer   r   rx   r   r   
_extend_y0zipr   
change_icsry   r   r   r   )rc   rk   r   r   deg1deg2dimr   Krowsself	rowsothergenr   diff1diff2rowrE   exprprK   rP   r   y1y2r   selfat0otherat0selfatx0	otheratx0_y0s                                 rF   r   zHolonomicFunction.__add__=  sf   "'5+<+C+HHH::e$$DAqq5L% &$oo#(KKMM$%&'	%9 sTz"" 	# 	#A8B<'EOOE""""sTz"" 	$ 	$A9R=(EU####"  	 	DA37^^ < <DO,,,,HHQV$$$$HHQUU4?1#5#9::;;;;HHQKKKK SXXs1u-q11;;==$c!eQZ33$Q00   	51HC8B<'EOOE"""9R=(EU###Y&CA  sQw @ @AC0000((((tq'9'=!>!>???? QS3q5 1155??AAA"(#a%Q77G(G44C1   	5: hhjj#'D.)#t/677d&')9)@5QQQ$$&& 	25+@+@+B+B 	2$S$&111   E))e.B.B.D.D.M.M w%(""  ci00sy1144B444(dfdgrBBB *66q99 ,88;;7a<<<<%"2"21"5"555X]]7]8]??1--55  $/;;DGDDH % 1 = =dg F FI# AI A#e&6&6tw&?&???  $ux885@@7eh$S$&111   E))e.B.B.D.D.L.LCC	$'0B0BCCCC&#BBB  ""d**u/C/C/E/E/N/NDD	%(0C0CDDDCB&#BB  ""d**u/C/C/E/E/M/MBB  	 	A Bww==3r!ube+<+<===111 	 	A{{11 dfdgr:::rH   Fc           	      @	   | j         j        j        }|                                 dk    r|                                 }|r|                    ||          S i }| j        D ]}| j        |         }g }t          |          D ]q\  }	}
|
dk    r |                    t          j
                   +||	z   dz   dk    rt          d          |                    |
t          ||	z   dz             z             r|||dz   <   t          |d          rt          d          t          | j         |z  | j        | j        |          S |                                 sN|r/t          | j         |z  | j        | j        t          j
        g          S t          | j         |z  | j                  S t          |d          r>t#          |          dk    r*|d         | j        k    r| j        }|d         }|d	         }d}nd
}t          j
        g}|| j        z  }t          | j         |z  | j        | j        |          }|s|S ||k    rF	 |                                }n# t&          t(          f$ r d}Y nw xY w|rL|                    | j        |          }t-          |t.                    r|                    | j        |          }n|                    |          }|| j        k    r-|d         |z
  |d<   t          | j         |z  | j        ||          S t          |          j        rh|rL|                    | j        |          }t-          |t.                    r|                    | j        |          }n|                    |          }||z
  S || j        k    rt          | j         |z  | j        ||          S t          |          j        r	 t          | j         |z  | j        ||                                          }|                    | j        |          }t-          |t.                    s|S |                    | j        |          S # t&          t(          f$ r5 t          | j         |z  | j        ||                              |          cY S w xY wt          | j         |z  | j                  S )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)initcondr   r7   z1logarithmic terms in the series are not supported__iter__z4Definite integration for singular initial conditions   r   FN)r   rv   rT   r   r   	integrater   ry   r   r   r   NotImplementedErrorhasattrr   rx   r   r   r~   to_exprr<   r;   subsra   r   r2   evalf	is_Number)rc   limitsr  DrE   r   r   cc2r   cjr   r   r   definiteindefinite_integralindefinite_exprloweruppers
indefinites                        rF   r	  zHolonomicFunction.integrate  s   & #7   D((((**A >{{6H{=== BW  GAJ&q\\ 	5 	5EArQww		!&)))) Qa12efff		"qQ||"344441q5		vz** b)*`aaa$T%5%94647BOOO ##%% 	C Z()9A)=tvtwQRQWPXYYY$T%5%946BBB
 6:&& 		6{{aF1I$7$7W1I1I HfX
dg/0@10DdfdgWYZZ 	'&& 77'"5"="="?"?')<= ' ' '"&'  5',,TVQ77eS)) =+11$&!<<E+11!44DF{{11()9A)=tvr2NNN1 %" 9+00;;E!%-- A / 5 5dfa @ @/55a88Eu}$ ;;$T%5%9461bIII qTT^ 
	W	W%d&6&:DFA 		 VVDFA..
!*c22 .%%77461---')<= W W W()9A)=tvq"MMSSTUVVVVVW !!1A!5tv>>>s,   8I I#"I#<A"P: P: :AR ?R c                 b  	
 |                     dd           |rg|d         | j        k    rt          j        S t	          |          dk    r7| }t          |d                   D ]}|                    |d                   }|S | j        }|j        d         |j	        j
        j        k    r|j        dk    rt          j        S |j        d         |j	        j
        j        k    rt          |j        dd         |j	                  }|                                 rV|                                 dk    r)t!          || j        | j        | j        dd                   S t!          || j                  S t!          || j                  S |j	        j
        }|                                		fd|j        D             

fd	
dd         D             }|                    d	j                   t+          |          }t-          |	j        	j        g          }t1          |dd         | j        j	        d
          }|                                 r|                                 dk    rt!          || j                  S t3          | |j        dz             dd         }t!          || j        | j        |          S )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
        evaluateTr   r   r7   NFc                 D    g | ]}                     |j                  S rr   )r   r   r   r   r   s     rF   r   z*HolonomicFunction.diff.<locals>.<listcomp>  s%    888A155<<888rH   c                 &    g | ]}|d          z  S r   rr   )r   r   seq_dmfs     rF   r   z*HolonomicFunction.diff.<locals>.<listcomp>  s!    333!q71:~333rH   r   )
setdefaultrx   r   r   r~   r   r   r   r}   rv   rU   r^   r   r]   r   r   r   r   r   r   insert_derivate_diff_eqr   r_   r   r   )rc   argskwargsrP   r   annr   rhsr   r   r"  s            @@rF   r   zHolonomicFunction.diffT  s   , 	*d+++ 	Aw$&  vTatAw , ,A((47++CC
 >!
 444a6M ^A#*/"666&s~abb'93:FFC##%% 6&&((E11,S$&$'47122;OOO(df555(df555 JOKKMM8888888 4333wqrr{333

1af  $$ qvquo..QRR$"2"9EJJJ##%% 	2)<)<)>)>$)F)F$S$&111ci!m,,QRR0 dfdgr:::rH   c                     | j         |j         k    r`| j        |j        k    rN|                                 r8|                                r$| j        |j        k    r| j        |j        k    rdS dS dS dS dS ri   )r   rx   r   r   r   rj   s     rF   rl   zHolonomicFunction.__eq__  s    u000v  ''))  e.C.C.E.E  w%(**tw%(/B/B#t$u4u5rH   c           	      h   ! | j         }t          |t                    st          |          }|                    | j                  rt          d          |                                 s| S t          | |j	                  }g }|D ]7}|
                    t          j        || j                  |z  j                   8t          || j        | j        |          S | j         j        j        |j         j        j        k    r|                     |          \  z  S |j         }g !g  |j	        |j	        |j        j        }|                                |j        D ]/}!
                                        |j                             0|j        D ]/} 
                                        |j                             0!fdt)                    D             } fdt)                    D             }	fdt)          dz             D             j        d         d<   fdt)                    D             g}
t-          |
dz  f                                          }t-          j        z  df          }t3          ||          }|j        rOt)          dz
  dd          D ]؊t)          dz
  dd          D ]}         |dz   xx                  |         z  cc<   dz            |xx                  |         z  cc<   t                   |         j                  r%t9                   |                            |<            |                             | j                           |<   t)          dz             D ]b                  j        sMt)                    D ]-}         |xx         |	|                           z  z  cc<   .j                 <   ct)                    D ]a}         |         dk    sMt)                    D ]-         |xx         |                  |         z  z  cc<   .j                 |<   b|

                    fd	t)                    D                        t-          |
tA          |
          z  f                                          }t3          ||          }|j        OtC          |"                                | j         j        d
          }|                                 r|                                st          || j                  S | #                                d
k    r|#                                d
k    rp| j        |j        k    rat          | |j	                  }t          ||j	                  }|d         |d         z  g}t)          dtI          tA          |          tA          |                              D ]Њfdt)          dz             D             }t)          dz             D ]9}t)          dz             D ]$}||z   k    rtK          |          ||         |<   %:d}t)          dz             D ]:}t)          dz             D ]%}|||         |         ||         z  ||         z  z  }&;|
                    |           t          || j        | j        |          S | j         &                    d          }|j         &                    d          }| j        dk    r|s|s| |'                    d          z  S |j        dk    r|s|s| '                    d          |z  S | j         &                    | j                  }|j         &                    | j                  }|s|s| |'                    | j                  z  S | '                    |j                  |z  S | j        |j        k    rt          || j                  S d }d }| #                                d
k    rL|#                                dk    r4d tQ          | j)                  D             }tT          j+        |i}|j)        }n| #                                dk    rL|#                                d
k    r4d tQ          |j)                  D             }| j)        }tT          j+        |i}n>| #                                dk    r&|#                                dk    r| j)        }|j)        }i }|D ]|D ]}tI          tA          |                   tA          ||                             }g }t)          |          D ][tT          j+        }t)          dz             D ]%||                  ||         z
           z  z  }&|
                    |           \|z   |vr	|||z   <   d tY          |||z                      D             ||z   <   ߌt          || j        | j        |          S )Nz> Can't multiply a HolonomicFunction and expressions/functions.c                 4    g | ]}|                   z  S rr   rr   )r   r   r   r   s     rF   r   z-HolonomicFunction.__mul__.<locals>.<listcomp>  s(    CCCQYq\MIaL0CCCrH   c                 4    g | ]}|                   z  S rr   rr   )r   r   r   r   s     rF   r   z-HolonomicFunction.__mul__.<locals>.<listcomp>  s(    FFFjm^jm3FFFrH   c                 L    g | ] }fd t          dz             D             !S )c                     g | ]	}j         
S rr   )r^   r  s     rF   r   z8HolonomicFunction.__mul__.<locals>.<listcomp>.<listcomp>  s    333af333rH   r7   r   )r   r   r   r   s     rF   r   z-HolonomicFunction.__mul__.<locals>.<listcomp>  s8    JJJ3333eAEll333JJJrH   r7   r   c                 P    g | ]"}t                    D ]}|         |         #S rr   r0  r   r   r   r   	coeff_muls      rF   r   z-HolonomicFunction.__mul__.<locals>.<listcomp>  s4    QQQaQQ1Yq\!_QQQQrH   r   c                 P    g | ]"}t                    D ]}|         |         #S rr   r0  r2  s      rF   r   z-HolonomicFunction.__mul__.<locals>.<listcomp>  s8    $Y$Y$YPUVWPXPX$Y$Y1Yq\!_$Y$Y$Y$YrH   Fr   c                 H    g | ]}d  t          dz             D             S )c                     g | ]}d S r!  rr   r   r   s     rF   r   z8HolonomicFunction.__mul__.<locals>.<listcomp>.<listcomp>  s    666Aa666rH   r7   r0  )r   r   r   s     rF   r   z-HolonomicFunction.__mul__.<locals>.<listcomp>  s2    MMM166q1u666MMMrH   Tc                 8    g | ]\  }}|t          |          z  S rr   r   r   s      rF   r   z-HolonomicFunction.__mul__.<locals>.<listcomp>K  r   rH   c                 8    g | ]\  }}|t          |          z  S rr   r   r   s      rF   r   z-HolonomicFunction.__mul__.<locals>.<listcomp>O  r   rH   c                     g | ]
\  }}||z   S rr   rr   r   s      rF   r   z-HolonomicFunction.__mul__.<locals>.<listcomp>d  s      E E E41aQ E E ErH   )-r   ra   r   r   hasrx   r
  r   r   r   r   r/   r   r   r   rv   rU   r   r   r}   r   r_   r0   rJ   r   rQ   r   rz   DMFdiffr   is_zeror^   r~   r   r   r   minr   r   r   ry   r   r   r   r   )"rc   rk   ann_selfr   r   r   	ann_otherr   self_red	other_redlin_sys_elementslin_syshomo_sysrP   sol_anny0_selfy0_othercoeffkr   r  r  r  r   r  r  r  r   r   r   r3  r   r   r   s"                              @@@@@@@rF   r   zHolonomicFunction.__mul__  s
   #%!233 	HENNEyy   l)*jkkk'')) 	Hhn55 A AAIItx4622U:?@@@@(4647BGGG"'5+<+C+HHH::e$$DAqq5L%		
NOO KKMM$ 	+ 	+AQUU15\\****% 	, 	,AaeeAEll++++ DCCCC%((CCCFFFFFU1XXFFF	 KJJJJU1q5\\JJJ	%	!Q RQQQQeAhhQQQR/!QqS1==GGII%qsAh22$Wh77   	< 1q5"b)) G Gq1ub"-- G GAaLQ'''9Q<?:'''a!e$Q'''9Q<?:'''!)A,q/17;; G*1)A,q/*B*B	!Q*3A,q/*>*>tv*F*F	!QG 1q5\\ - - |A. -"1XX , ,!!Q9Q<%aLO,, ,&'fIaLO 1XX - - |A!++"1XX , ,!!Q8A;%aLO,, ,&'fIaLO##$Y$Y$Y$Y$YeAhh$Y$Y$YZZZ"#3c:J6K6KQqS5QSTUU__aaG((;;C?   	<B SXXZZ)9)@5QQQ$$&& 	65+@+@+B+B 	6$Wdf555  E))e.B.B.D.D.M.M w%("" %T7=99%eW];;aj8A;./ q#c'llCMM"B"BCC # #AMMMMa!eMMME"1q5\\ = =!&q1u = =A 1uzz.6q!nna= C"1q5\\ I I!&q1u I IA58A;
#:Xa[#HHCCI IIcNNNN($&$'2FFF
 *66q99 ,88;;7a<<<<%"2"21"5"555X]]7]8]??1--55  $/;;DGDDH % 1 = =dg F FI# AI A#e&6&6tw&?&???  $ux885@@7eh$Wdf555   E))e.B.B.D.D.L.LCC	$'0B0BCCCC&#BBB  ""d**u/C/C/E/E/N/NDD	%(0C0CDDDCB&#BB  ""d**u/C/C/E/E/M/MBB 	F 	FA F FBqE

C1JJ//q    AA"1q5\\ 5 5RU1X1a!e44HHQKKKK1u{{ !Bq1uII E E3q"QU)3D3D E E EBq1uIIF !$&$'2>>>rH   c                     | |dz  z   S r   rr   rj   s     rF   r   zHolonomicFunction.__sub__i  s    ebj  rH   c                     | dz  |z   S r   rr   rj   s     rF   r   zHolonomicFunction.__rsub__l  s    by5  rH   c                     d| z  S r   rr   r   s    rF   r   zHolonomicFunction.__neg__o  r   rH   c                 &    | t           j        |z  z  S rA   r   rj   s     rF   r   zHolonomicFunction.__truediv__r  r   rH   c                   
 | j         j        dk    r| j         }|j        
| j        d }nt	          | j                  d         |z  g}|j        d         }|j        d         }t          j        || j                  |z  j	        }
fd||fD             }t          |
          }t          || j        | j        |          S |dk     rt          d          |dk    r=| j         j        j        }t          || j        t          j        t          j        g          S |dk    r| S |dz  dk    r| |dz
  z  }	|	| z  S |dz  dk    r| |dz  z  }	|	|	z  S d S )Nr7   r   c                 D    g | ]}j                             |          S rr   )rU   r|   )r   r   rv   s     rF   r   z-HolonomicFunction.__pow__.<locals>.<listcomp>  s)    ===q6;''**===rH   z&Negative Power on a Holonomic Functionr   )r   r   rv   r   r   r}   r/   r   rx   r   r]   r   r   r>   rT   r   r   r   )rc   r   r(  r   p0p1rP   ddr[   r   rv   s             @rF   r   zHolonomicFunction.__pow__u  sl   !Q&&"CZFw47mmA&!+,"B"B(2tv&&*/B====RH===C%c622B$R"===q55#$LMMM66!(<B$R!%AAA66K1uzz 1q5M	 4''Q! 1q5M	 9,, rH   c                 L    d | j         j        D             }t          |          S )zF
        Returns the highest power of `x` in the annihilator.
        c                 6    g | ]}|                                 S rr   degreer7  s     rF   r   z,HolonomicFunction.degree.<locals>.<listcomp>  s     ???aqxxzz???rH   )r   r}   r   )rc   rP   s     rF   rW  zHolonomicFunction.degree  s)     @?4#3#>???3xxrH   c                 &     j         j        } j         j        }                     j                  } j         j        t                    D ]P\  }}t          | j         j        j        j	                  r' j         j        j        
                    |          |<   Q|                              j        i           fdt          |          D             }	d t          |          D             }
t          j        |
d<   |
g}t          d t          |          D             g                                          }	  fd|
D             }t          |dz
            D ]}||dz   xx         |
|         |z  z  cc<   t          |          D ]$}||xx         |
d         |	|         z  |z  z  cc<   %|}
|                    |
           t          |                                                              |          \  }}|j        durnt)          |          d         }|                    |d          }t+          |dd	         |d
          }|r#t-          | j        |d         |d                   S t-          | j                  S )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
        c                 \    g | ](}|                              j        i           z  )S rr   )r  rx   )r   r   r   r}   rE   rc   s     rF   r   z1HolonomicFunction.composition.<locals>.<listcomp>  s9    JJJ1A##TVDM222Q6JJJrH   c                 &    g | ]}t           j        S rr   r   r   r7  s     rF   r   z1HolonomicFunction.composition.<locals>.<listcomp>  s    +++Q!&+++rH   r   c                 &    g | ]}t           j        S rr   r[  r7  s     rF   r   z1HolonomicFunction.composition.<locals>.<listcomp>  s    888!qv888rH   Tc                 D    g | ]}|                     j                  S rr   )r   rx   )r   r   rc   s     rF   r   z1HolonomicFunction.composition.<locals>.<listcomp>  s%    :::a166$&>>:::rH   r7   r   NFr   )r   rv   r   r   rx   r}   ry   ra   rU   rz   r|   r  r   r   r   r(   rJ   r   gauss_jordan_solver   r   r   r   )rc   r   r&  r'  r   r   r   r   r   r  coeffssystemhomogeneouscoeffs_nextrP   taustaur}   rE   s   ``               @@rF   compositionzHolonomicFunction.composition  s   4 #"yy  %0
j)) 	I 	IDAq!T-49?@@ I $ 0 7 < E Ea H H
1qMt}--JJJJJJJq		JJJ++%((+++Eq	88uQxx8889::DDFF	::::6:::K1q5\\ 9 9AE"""vay4'78""""1XX @ @A6":Q#7$#>? FMM&!!!1133$$[11 C!--	 4jjmhhsAQRR!e444  	D$S$&$q'47CCC df---rH   Tc           
      D   | j         dk    r,|                     | j                                                   S | j                            | j                   r|                     |          S i }t          dd          }| j        j        j        j	        }t          |                    |          d          \  }}t          | j        j                  D ]\  }}|                                }	t          |	          dz
  }
t!          |
dz             D ]}|	|
|z
           }|dk    r||z
  |f|v r@|||z
  |fxx         |                    |          t%          ||z
  dz   |          z  z  cc<   ]|                    |          t%          ||z
  dz   |          z  |||z
  |f<   g }d |D             }t'          |          }t)          |          }|                                 }
||
z   }i }g }g }t!          ||dz             D ]}||v rgt,          j        }|                                D ]0}|d         |k    r"|||                             |||z
            z  }1|                    |           m|                    t,          j                   t7          ||          }|j        }t;          |j                            |j        d	                   |d
          }|                                }|r"t)          |          dz   }t)          ||          }||z  }t=          | |          }g }t          |          D ]*\  }}|                    |t?          |          z             +t          |          |k     rt!          |
          D ] }t,          j        }|D ]}||d         z   dk     rt,          j        |||d         z   <   n||d         z   t          |          k     r|||d         z            |||d         z   <   nX||d         z   |vrKt          d||d         z   z            |||d         z   <   |                    |||d         z                       |d         |k    r1|||                             ||          |||d         z            z  z  }|                    |           "tA          |g|R  }tC          |tD                    rt!          t          |          |          D ]b}||vrt          d|z            ||<   ||         |v r"|                    |||                             G|                    ||                    c|rtG          ||          |fgS tG          ||          gS t!          t          |          |          D ]l}||vrt          d|z            ||<   d}|D ]/}||         |v r#|                    |||                             d}0|s|                    ||                    m|rtG          ||          |fgS tG          ||          gS )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   )lbr   TintegerSnr7   c                     g | ]
}|d          S r!  rr   r7  s     rF   r   z1HolonomicFunction.to_sequence.<locals>.<listcomp>3  s    '''A1Q4'''rH   r   ZfilterC_%sF)$r   shift_xto_sequencer   r   
_frobeniusr   rv   rU   r   r:   r   ry   r}   
all_coeffsr~   r   r|   r   r>  r   rW  r   r   keysr  r   r9   r   r.   r   r   r6   ra   r   r8   )rc   rg  dict1r   r   r   r   r   r   	listofdmprW  rJ  rI  rP   keylistr  r  
smallest_ndummyseqsunknownstempr   	all_rootsmax_rootr   u0eqsoleqsr  s                                 rF   rq  zHolonomicFunction.to_sequence  s   h 7a<<<<((44666 ''00 	*??b?)))3%%%%*."3#4#4Q#7#7>>1 d.9:: 	Q 	QDAqI^^a'F6A:&& 	Q 	Q!&1*-A::E1:&&1q5!*%%%#,,u*=*=1q519a@P@P*PQ%%%%),e)<)<r!a%!)Q?O?O)OE1q5!*%%	Q '''''GG V^
 ueai(( 	# 	#AG||v < <AtqyyaaU ; ;;

4    

16"""" !a(( 	!&//#.*<==qMMM	NN$$	 	39~~)HXz22Je$$ bMM 	( 	(DAqIIa)A,,&'''' r77U??6]]  V E EA1Q4x!||+,6q1Q4x((QqTCGG+++-a!A$h<q1Q4x((1X//+1&1qt82D+E+Eq1Q4x( q1Q4x(8999tqyyeAhmmAq11F1qt84DDD

2 3****F&$'' 4s2ww.. 	- 	-A$*619$5$5q	ayF**		&"34444 		&),,,, F.sB77DEE)#r22333r77E** ) )F?? &vqy 1 1F1I ! !AayA~~		!F1I,///  )IIfQi((( 	>&sB//<==!#r**++rH   c                    |                                  }g }g }t          |                                          D ]b}|j        r |                    |g||         z             )|                                \  }}|                    |||fg||         z             c|                    d            |                    d            |                                 g }|D ]}d}	t          |          dk    r|                    |g           .|D ]@}
t          |
d         |z
            |
d         |z
  k    r|
                    |           d}	 nA|	s|                    |g           t          d |D                       rdnd}t          d |D                       }t          d	 |D                       }|                                 dk    rug }t          | j                                                  D ]K}t          |                                          D ]'}
t          |
|          r|                    |           (Ln|r|rt          |          g}n|rd
 |D             d |D             z   }n|s0g }|D ]*}t          |          |k    s|                    |           +n||sz|                                 r#t!          | j        d                   j        dk    rt          |          g}n2g }|D ]}|dk    r|                    |           t          |          g}t%          dd          }| j        j        j        j        }t/          |                    |          d          \  }}g }t3          d          }|D ]}i }t5          | j        j                  D ]\  }}
|
                                }t          |          dz
  }t;          |dz             D ]}|||z
           }|dk    r||z
  ||z
  f|v rF|||z
  ||z
  fxx         |                    |          t?          ||z
  dz   |z   |          z  z  cc<   f|                    |          t?          ||z
  dz   |z   |          z  |||z
  ||z
  f<   g }d |D             }t          |          }tA          |          }tA          d |D                       }t          d |D                       } ||z   }!i }"g }#g }$t;          ||dz             D ]}
|
|v rgt           j!        }%|                                D ]0}|d         |
k    r"|%||         "                    |||z
            z  }%1|                    |%           m|                    t           j!                   tG          ||          }|j$        }&tK          |j                            |j        d                   |d          }'|'                                }'|'r"tA          |'          dz   }(tA          |(|!          }!|&|!z  }&g })|                                 dk    r| j        |         })n|                                 dk    r|dk    rt          |          |k    rt          |          dk    rtM          | |&t          |          z             }*t          |*          t          |          k    rXt;          t          |          t          |*                    D ]-}|)                    |*|         tO          |          z             .t          |)          |&k     rt;          | |          D ]4}t           j!        }+|D ]}
||
d         z   dk     rt           j!        |"||
d         z   <   n||
d         z   t          |)          k     r|)||
d         z            |"||
d         z   <   nj||
d         z   |"vr]tQ          |          d||
d         z   z  z   },t%          |,          |"||
d         z   <   |$                    |"||
d         z                       |
d         |k    r1|+||
         "                    ||          |"||
d         z            z  z  }+|#                    |+           6tS          |#g|$R  }-tU          |-tV                    rt;          t          |)          |&          D ]t}||"vr'tQ          |          d|z  z   },t%          |,          |"|<   |"|         |-v r"|)                    |-|"|                             Y|)                    |"|                    u|r(|                    tY          ||)          ||!f           |                    tY          ||)          |f           t;          t          |)          |&          D ]~}||"vr'tQ          |          d|z  z   },t%          |,          |"|<   d}.|-D ]/}
|"|         |
v r#|)                    |
|"|                             d}.0|.s|)                    |"|                    |r'|                    tY          ||)          ||!f           n%|                    tY          ||)          |f           |dz  }|S )Nc                     | d         S )Nr7   rr   rx   s    rF   rG   z.HolonomicFunction._frobenius.<locals>.<lambda>  
    !A$ rH   )keyc                     | d         S Nr   rr   r  s    rF   rG   z.HolonomicFunction._frobenius.<locals>.<lambda>  r  rH   Fr   Tc              3   <   K   | ]}t          |          d k    V  dS r7   N)r~   r7  s     rF   	<genexpr>z/HolonomicFunction._frobenius.<locals>.<genexpr>  s,      !;!;!#a&&A+!;!;!;!;!;!;rH   c              3   "   K   | ]
}|d k    V  dS r   Nrr   r7  s     rF   r  z/HolonomicFunction._frobenius.<locals>.<genexpr>  s&      ++Q!V++++++rH   c              3   <   K   | ]}t          |          |k    V  d S rA   r   r7  s     rF   r  z/HolonomicFunction._frobenius.<locals>.<genexpr>  s,      00QSVVq[000000rH   c                     g | ]
}|d          S r!  rr   r7  s     rF   r   z0HolonomicFunction._frobenius.<locals>.<listcomp>  s    111qt111rH   c                     g | ]
}|d          S r!  rr   r   r   s     rF   r   z0HolonomicFunction._frobenius.<locals>.<listcomp>  s    4I4I4IaQqT4I4I4IrH   r   rh  rj  Cr7   c                     g | ]
}|d          S r!  rr   r7  s     rF   r   z0HolonomicFunction._frobenius.<locals>.<listcomp>  s    +++qt+++rH   c                     g | ]
}|d          S r7   rr   r7  s     rF   r   z0HolonomicFunction._frobenius.<locals>.<listcomp>  s    ...1!A$...rH   c                     g | ]
}|d          S r  rr   r7  s     rF   r   z0HolonomicFunction._frobenius.<locals>.<listcomp>  s    ///A1Q4///rH   r   rl  rm  z_%s)-	_indicialr   rt  is_realextendas_real_imagsortr~   r   r   allr   r   r   r>  r   r   	is_finiter   r   rv   rU   r   r:   r   ordry   r}   rs  r   r|   r   r   r   r  r9   r   r.   r   r   chrr6   ra   r   r8   )/rc   rg  indicialrootsrealscomplr   r   r   grpintdiffr   independentallposallintrootstoconsiderposrootsr   r   r   r   finalsolcharr   ru  rv  rW  rJ  rI  rP   rw  r  r  degree2rx  ry  rz  r{  r|  r   r}  r~  r  r   r  letterr  r  s/                                                  rF   rr  zHolonomicFunction._frobenius  s$   ((++--.. 	= 	=Ay =aS=#334444~~''1q!Qi[=+;;<<<< 	


'''


'''

  	  	 AG3xx1}}

A3  qtax==AaD1H,,HHQKKK"GE -   

A3 "!;!;s!;!;!;;;Fdd++U+++++00%00000   D(( OTW\\^^,, 2 2 !3!3!5!566 2 2A#Aq)) 2'..q11122
  	2 	2"5zzlOO 	211S1114I4I54I4I4IIOO 	2 O . .1vv{{#**1---.  
	2'')) 2Qtwqz]]-D-N-N#&u::,  + +AAvv ***#&x==/3%%%%*."3#4#4Q#7#7>>13xx  B	 B	AE!$"2"=>> ] ]1LLNN	Y!+vz** 	] 	]A%fqj1Ezz Aq1u~..q1ua!en---#,,u2E2E1q5ST9WX=Z[H\H\2\]----14e1D1Dr!a%RS)VW-YZG[G[1[q1ua!en--	] C++U+++GLLELLE.....//F/////00GJFCH5%!),, ' '<<6D"ZZ\\ @ @Q4199 E!HMM!QY$?$??DJJt$$$$JJqv&&&& %S!,,C IEafoocnR.@AA1SQQQI!((I 7y>>A- :66
ZEB""$$,,WQZ$$&&%//AFFs1vv{{sSbOcOcghOhOhec!ffn55r77SVV##"3q663r7733 8 8		"Q%)A,,"677772www// # #AB" I Iqt8a<</0vF1qt8,,1XB///1!ad(|F1qt8,,!"QqTV!3!3%(YYQqT1B%BF/5f~~F1qt8,$OOF1qt8,<===Q4199%(--1"5"5q1Q4x8H"HHBJJrNNNN s.X...fd++ !"3r77E22 
1 
1F??%(YY%9F(.vF1I!!9..IIfVAY&78888 IIfQi0000 ! ):3)C)CQ
(STTT  ):3)C)CQ(GHHH s2ww.. - -A!$TUAX!5$*6NNq	A# % %!!9>>IIaq	l333 $A -		&),,, A!23!;!;Q
 KLLLL !23!;!;Q ?@@@AIDDrH      c                 V   ||                                  }n|}t          |t                    rt          |          dk    r|d         }d}nt          |t                    r$t          |          dk    r|d         }|d         }nt          |          dk    r*t          |d                   dk    r|d         d         }d}n{t          |          dk    r6t          |d                   dk    r|d         d         }|d         d         }n2g }|D ]+}|                    |                     |                     ,|S |t          |          z
  }t          |j                  dz
  }	|j        j	        | j
        }
| j        }|j        j        }|j        j        j        }|                                }g t!          |          D ]2\  }}                    |                    |j                             3fdt'                    D             }t)          |j                  }|	dz   |k    rn}t'          |	dz   z
  |z
            D ]c}t*          j        }t'                    D ]0}||z   dk    r%|t/          ||         |          |||z            z  z  }1|                    |           d|r|S t*          j        }t!          |          D ]\  }}||
||z   z  |z  z  }|r&|t1          |
|t          |          z   z  |
          z  }|dk    r|                    |
|
|z
            S |S )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
        Nr   r   r  r7   )_recurc                 4    g | ]}|                   z  S rr   rr   )r   r   rJ  seqs     rF   r   z,HolonomicFunction.series.<locals>.<listcomp>  s(    222AAwQ222rH   )rq  ra   tupler~   r   seriesr   r  
recurrencer   rx   r   r}   rv   rU   r   ry   r   r   r   r   r   r   DMFsubsr3   r  )rc   r   coefficientr   r  r  constantpowerrP   r   lrx   r   seq_dmpr   r   r   subrI  serrJ  r  s                      @@rF   r  zHolonomicFunction.seriest  sX   : >))++JJJj%(( 	S__-A-A#AJMM
E** 	s:!/C/C&qMM#AJJ__!!c*Q-&8&8A&=&=#Aq)JMM__!!c*Q-&8&8A&=&=&qM!,M#Aq)JJC 2 2

4;;a;001111JM"""
"!'FW'2!(-KKMMg&& 	% 	%DAqJJquuQU||$$$$22222q222:=!!q5A:: 1q519a!e,, " "q A AA1uzzQ!3!3c!a%j!@@

5!!!! 	JfcNN 	. 	.DAq1q=()A--CC 	95Q]!3!334a888C7788Aq2v&&&
rH   c                 L  
 | j         dk    r,|                     | j                                                   S | j        j        }| j        j        j        
| j        
j        }
j	        }
fdd |D             }t          |          }dt          d|          t          d| j        j                  z   z  fd} ||d                   }t          dt          |                    D ]$}t          | |||                   |z
            }%t          |          D ]]\  }}|                                }	t          |	          dz
  }| |z
  dk    r ||z
  |z
  dk    r||	||z
  |z
           |z  z   }||z
  z  }^t#          
                    |                    S )z:
        Computes roots of the Indicial equation.
        r   c                     t                              |           d          }d|                                v r|d         S dS )Nrl  rm  r   )r.   r|   rt  )polyroot_allr   rx   s     rF   _pole_degreez1HolonomicFunction._indicial.<locals>._pole_degree  sE    QZZ--q===HHMMOO##{"qrH   c                 6    g | ]}|                                 S rr   rV  r  s     rF   r   z/HolonomicFunction._indicial.<locals>.<listcomp>  s     111!((**111rH   
   r7   c                 ,    | j         rn
 |           S rA   )r=  )qr  infs    rF   rG   z-HolonomicFunction._indicial.<locals>.<lambda>  s    qy=ll1oo rH   )r   rp  r  r   r}   rv   rU   rx   r^   r_   r   r   r   r~   r>  ry   rs  r.   r|   )rc   
list_coeffr  yrW  degr   r   r   rv  r   r  r  rx   s             @@@@rF   r  zHolonomicFunction._indicial  s   
 7a<<<<((22444%0
#(FFE	 	 	 	 	 	 21j111VC6NNSD,<,B%C%CCD=====C
1q#j//** 	/ 	/AAss:a=))A-..AAj)) 	 	DAqI^^a'FsQw!||
Q! 3 3	&1*q.1A55QJAAQZZ]]A&&&rH   RK4皙?c                    ddl m} d}t          |d          sd}t          |          }| j        |k    r || |g||          d         S |j        st          | j        }||k    r| }t          ||z
  |z            }	||z   g}t          |	dz
            D ] }
|	                    |d         |z              !t          | j        j        j                            | j        j        d                   | j                  D ]!}
|
| j        k    s|
|v rt#          | |
          "|r || |||          d         S  || |||          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   )_evalfFr  T)methodderivativesr   r7   )sympy.holonomic.numericalr  r  r   r   r  r
  r   r   r   r.   r   rv   rU   r|   r}   rx   r=   )rc   pointsr  hr  r  lpr   r   r   r   s              rF   r  zHolonomicFunction.evalf  s   \ 	544444 vz** 	.B&		Aw!||vdQCKPPPQSTT; *))A1uuBQUaK  A!eWF1q5\\ . .fRj1n----t'.3<<T=M=XY[=\]]_c_eff 	0 	0ADG||qF{{&tQ///  +  	T6$v;OOOPRSSvdF6{KKKKrH   c                 >   | j         j        j        j        }|                    |          }t          |d          \  }}g }| j         j        D ]%}|                     ||j                             &t          ||          }t          ||| j        | j                  S )z
        Changes only the variable of Holonomic Function, for internal
        purposes. For composition use HolonomicFunction.composition()
        r[   )r   rv   rU   r   r   rX   r}   r   r   r]   r   r   r   )rc   zr   r   rv   r   rP   r   s           rF   change_xzHolonomicFunction.change_xC  s     %*.a  )!T22	!, 	! 	!AJJqqxx    #C00 a$':::rH   c                 .   | j         | j        j        }| j        j        j        fd|D             }t          || j        j                  }| j        z
  }|                                 st          |          S t          ||| j	                  S )z-
        Substitute `x + a` for `x`.
        c           	          g | ]A}                                         |                              z                       BS rr   )r{   r|   r  )r   r   r   rU   rx   s     rF   r   z-HolonomicFunction.shift_x.<locals>.<listcomp>[  sE    XXXAtt}}Q//44QA>>??XXXrH   )
rx   r   r}   rv   rU   r]   r   r   r   r   )rc   r   listaftershiftrP   r   rU   rx   s    `   @@rF   rp  zHolonomicFunction.shift_xR  s    
 F)4&+XXXXXXXXX"3(8(?@@Wq[##%% 	-$S!,,, aTW555rH   c                 x   ||                                  }n|}t          |t                    r't          |          dk    r|d         }|d         }d}n)t          |t                    r,t          |          dk    r|d         }|d         }|d         }nt          |          dk    r8t          |d                   dk    r|d         d         }|d         d         }d}nt          |          dk    rDt          |d                   dk    r+|d         d         }|d         d         }|d         d         }nF|                     ||d                   }|dd         D ]}||                     ||          z  }|S |j        }|j        }	| j        }
| j        }|	j	        }|dk    rt          |	j        j                            |	j        d                   |j        d          }t           j        }t%          |          D ]\  }}|dk     st'          |          |k    rt'          |          }|t          |          k     rQt          ||         t(          t*          f          r||                                         ||<   |||         |
|z  z  z  }|t/          d	|z            |
|z  z  z  }t          |t(          t*          f          r|                                |
|z  z  }n||
|z  z  }|r%|dk    r|                    |
|
|z
            fgS |fgS |dk    r|                    |
|
|z
            S |S ||z   t          |          k    rt3          d
          d}t5          dt          |	j                  dz
            D ]&}|	j        |         |	j        j        j        k    rd} n'|st9          | | j                  |	j        d         }|	j        d         }t          |j        d         t(          t*          f          rt!          |j        d                                                   ||                                z  z   t!          |j        d                                                   ||                                z  z  z  }nft!          |j        d                   ||                                z  z   t!          |j        d                   ||                                z  z  z  }d}t          |	j        j                            |          |j                  }t          |	j        j                            |          |j                  }|rg }t5          ||z             D ]}||k     rk|rJ|                    t!          ||                   |
||z   z  z                      |
|
|z
            f           n|t!          ||                   |
|z  z  z  }tt!          ||                   dk    rg }g }tA          |!                                          D ]4}|"                    tG          ||z
  |z            g||         z             5tA          |!                                          D ]4}|"                    tG          ||z
  |z            g||         z             5d|v r|$                    d           n|                    d           |rx|                    t!          ||                   |
||z   z  z                      |
|
|z
            tK          ||||
|z  z                                |
|
|z
            f           |t!          ||                   tK          ||||
|z  z            z  |
|z  z  z  }|r|S ||
|z  z  }|dk    r|                    |
|
|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
        Nr   r7   r   r  )as_listr  r   rm  ro  z+Can't compute sufficient Initial ConditionsTFr   )&rq  ra   r  r~   to_hyperr  r  rx   r   r   r.   rv   rU   r|   r}   r   r   r   ry   r   r)   r*   as_exprr   r  r
  r   r^   r<   r   rW  r   r   rt  r  r5   remover%   )rc   r  r  r  rx  r  rP   r   r  rE   rx   r   mnonzerotermsr   is_hyperr   r   r  arg1arg2	listofsolapbqrJ  s                            rF   r  zHolonomicFunction.to_hyperb  s   F >))++JJJj%(( 	S__-A-A#AJ#AJMM
E** 	s:!/C/C#AJ&qMM#AJJ__!!c*Q-&8&8A&=&=#Aq)J#Aq)JMM__!!c*Q-&8&8A&=&=#Aq)J&qM!,M#Aq)JJ--
1-FFC^ @ @t}}WQ}???J]!FW G 66 !7!7Q!H!H*,_bcccL&C!,// 4 41q55CFFaKKFFs2ww;;!"Q%+{)CDD 0 "112a51a4<'CC 6&!),,q!t33CC#[9:: -kkmma&66A},, !77 XXaR00344y Qwwxx1r6***J>CGG##%&STTT q#al++A-.. 	 	A|A!(-"444  5  	5%dDG444LOL aeAhk :;; 	TQU1X%%''((1qxxzz?:;qqAQAQASAS?T?TWX[\[c[c[e[eWf?fgAAQU1X;;QXXZZ01QquQx[[1qxxzz?5RSAQX]++A..
==QX]++A..
==  	IzA~&& %	A %	AA :~~ +$$qAxx!ao2F'F&L&LQPQRTPT&U&U%XYYYY1RU88ad?*C
 Axx1}}BB TYY[[)) > >		9a!eq[112T!W<====TYY[[)) > >		9a!eq[112T!W<==== Bww		!		! A  1RU88A-,@#@"F"Fq!B$"O"ORWXZ\^`abcefbf`fRgRgQmQmnoqrsuquQvQv!wxxxxqAxx%BAqD"9"99AqD@@ 	A}$$7788Aq2v&&&
rH   c                 h    t          |                                                                           S )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

        )r4   r  simplifyr   s    rF   r  zHolonomicFunction.to_expr  s&    & 4==??++44666rH   c                    d}|6t          | j                  | j        j        k    rt          | j                  }| j        j        j        j        }	 t          |                                 | j	        |||          }n# t          t          f$ r d}Y nw xY w|r|j        |k    r|S |                     |d          }t          | j        | j	        ||          S )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)])
        TN)rx   r   lenicsrC   F)r  )r~   r   r   r   rv   rU   rC   expr_to_holonomicr  rx   r;   r<   r   r  r   )rc   r   r  symbolicr   rP   r   s          rF   r   zHolonomicFunction.change_ics.  s    $ >c$'llT-=-CCC\\F%*1	#DLLNNdf6Z]^^^CC#%89 	 	 	HHH	  	!JZZtZ,, !1461bAAAs   +A> >BBc                     |                      d          }t          j        }|D ]U}t          |          dk    r||d         z  }!t          |          dk    r!||d         t	          |d                   z  z  }V|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)r  r7   r   r   )r  r   r   r~   _hyper_to_meijerg)rc   r   rP   r   s       rF   
to_meijergzHolonomicFunction.to_meijergQ  s    , mmDm))f 	6 	6A1vv{{qtQ1qt/!5555
rH   r  FT)r  FTN)r  r  F)FNrA   )$rm   rn   ro   rp   r   rd   rf   rq   r   r   r   r   r   r	  r   rl   r   r   r   r   r   r   r   rW  re  rq  rr  r  r  r  r  rp  r  r  r   r  rr   rH   rF   r   r     sJ       @ @D L   :   H  <     L L L V; V; V;p}? }? }? }?~K; K; K;Z  u? u? u?n H! ! !! ! !  & & &- - -B  >. >. >.@, , , ,BT T T TlZ Z Z Zx&' &' &'PIL IL IL ILV; ; ;6 6 6 u u u un7 7 7*!B !B !B !BF         rH   r   Fc                    | j         }| j        }| j        d         }|                    t                                                    }t          t          j        |          d          \  }}||z  }	d}
|D ]
}|
|	|z   z  }
|	dz
  }|}|D ]
}|||z   z  }|
|z
  }t          |           }|t          t          fv r#t          ||                              |          S dd}t          |t                    sT |||||j                  }|s|dz  } |||||j                  }|t          ||                              |||          S t          |t                    rXd} |||||j        |          }|s|dz  } |||||j        |          }|t          ||                              |||          S t          ||                              |          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)])
    r   r[   r7   Fc                 F   g }t          |          D ]}|r)|                     ||                                          }n|                     ||          }|j        du st	          |t
                    r d S |                    |           |                     |          } |S NFr   r  r  r  ra   r   r   r   simprx   r   r   r  r   r   vals           rF   _find_conditionsz$from_hyper.<locals>._find_conditions  s    u 		  		 A 'ii2&&,,..ii2&&}%%C)=)=%ttIIcNNN99Q<<DD	rH   r  )r  r  r&  atomsr   poprX   r+   r   r4   r   r   r   re  ra   r%   r   )funcr   r  r   r   r  rx   r   r[   xDxr1aixDx_1r2birP   r  r  r   s                      rF   
from_hyperr  t  s;     	AA	!A	A!""21"5"5t<<EAr B$C	
B  
cBh!GE	B  
ebj
r'CtD*+++ a((44Q777    dE"" 	@dAr3955 	: !GB!!$2sy99B  	: !a((44QB???$ @dAr39e<< 	A!GB!!$2sy%@@B  	A !a((44QB???S!$$00333rH   Tc                    | j         }| j        }t          | j                  }t          | j                  }t          |          }	| j        d         }
|
                    t                                                    }t          |
                    |          d          \  }}||z  }|dz   }|d||z   |	z
  z  z  }|D ]
}|||z
  z  }d}|D ]
}|||z
  z  }||z
  }|s#t          ||                              |
          S t          |           }|t          t          fv r#t          ||                              |
          S dd}t!          |t"                    sT |||||j                  }|s|dz  } |||||j                  }|t          ||                              |
||          S t!          |t"                    rXd} |||||j        |          }|s|dz  } |||||j        |          }|t          ||                              |
||          S t          ||                              |
          S )a  
    Converts a Meijer G-function to Holonomic.
    ``func`` is the G-Function and ``x0`` is the point at
    which initial conditions are required.

    Examples
    ========

    >>> 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)])
    r   r[   r7   r   Fc                 F   g }t          |          D ]}|r)|                     ||                                          }n|                     ||          }|j        du st	          |t
                    r d S |                    |           |                     |          } |S r  r  r  s           rF   r  z&from_meijerg.<locals>._find_conditions  s    u 	  	 A 'ii2&&,,..ii2&&}%%C)=)=%ttIIcNNN99Q<<DD	rH   r  )r  r  r~   anbmr&  r  r   r  rX   r   r   re  r4   r   r   ra   r&   r   )r  r   r  r  rC   r   r   r   r  r   r  rx   r   r[   r  xDx1r  r   r  r  rP   r  r  r   s                           rF   from_meijergr
    s     	AADGADGAAA	!A	A!&"6"6q"9"94@@EAr B$C7D	
B!a%!)	B  
dRi	
B  
cBh
r'C 8 a((44Q777tD*+++ a((44Q777    dG$$ @dAr3955 	:!GB!!$2sy99B  	: !a((44QB???$   @dAr39e<< 	A!GB!!$2sy%@@B  	A !a((44QB???S!$$00333rH   x_1N)_mytypec           	      |	   t          |           } | j        }|s7t          |          dk    r|                                }n(t	          d          ||v r|                    |           t          |          }|V|                     t                    rt          }nt          }t          |          dk    r||                                         }t          | ||||||          }	|	r|	S t          s|ai at          t          |           n%|t          k    r|ai at          t          |           | j        r|                     |t$                    }
t'          |
t$                    }|t          v r/t          |         }|d         d                             |          }nt+          | |d|          }|st,          |r||_        |s|s	||_        |S |s|j        j        }t7          | |||          }|s|dz  }t7          | |||          }|t9          |j        |||          S |s|s2|                    | j        d                   }|r||_        ||_        |S |s|j        j        }t7          | |||          }|s|dz  }t7          | |||          }||                    | j        d         ||          S | j        }| j        }
tA          |d         |d|	          }|
tB          u r=tE          dt          |                    D ]}|tA          ||         |d|	          z  }nZ|
tF          u r=tE          dt          |                    D ]}|tA          ||         |d|	          z  }n|
tH          u r||d         z  }||_        |st,          |r||_        |s|s|S |j        r|S |s|j        j        }|j        %                    |          r|&                                }t          |          }t          |          dk    ru||d                  tN          j(        k    rY|d         }| ||z
  |z  z  }t7          ||||          }d
 tS          |          D             }||i}t9          |j        |||          S t7          | |||          }|s|dz  }t7          | |||          }|t9          |j        |||          S )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
    r7   z%Specify the variable for the functionNr   )r   r   r  rC   r  )rC   Fr  rC   )rx   r  rC   c                 8    g | ]\  }}|t          |          z  S rr   r   r   s      rF   r   z%expr_to_holonomic.<locals>.<listcomp>	  '    QQQAA	!,QQQrH   )*r   free_symbolsr~   r  
ValueErrorr  r   r;  r	   r,   r+   r   _convert_poly_rat_alg_lookup_tabledomain_for_table_create_tableis_Functionr  r  r  r  _convert_meijerintr
  r   r   r   r   r  r   re  r&  r  r  r   r   r   r   r   r  r   r   ry   )r  rx   r   r   r  rC   r  syms
extra_symssolpolyftr  rP   r  r&  r   rE   gsingular_icss                       rF   r  r  	  s]   R 4==DD t99>>xxzzAADEEE	
dAdJ~88E?? 	FFFz??aJ'1133F $D!r&QWbjkkkG   4!mF33333	#	#	#!mF3333  $6IIaAsOOa AA$q'""1%%CC$T1uVLLLC *))   
 /."4B77C <a&tQF;;  < %S_aSAAA 	X 	//$)A,//C CFJ 	+_*FtQF33 	8!GB"4B77C  	8 ty|R555 9D	A
DGq5
H
H
HCCxxq#d))$$ 	R 	RA$T!WE&QQQQCC	R 
cq#d))$$ 	R 	RA$T!WE&QQQQCC	R 
c47lCF "!!	 	  

v 
 '&
""2&& 	AMMOOGGq66Q;;1QqT7ae++!AB{"A+Aq"f==LQQ<9P9PQQQLL!B$S_aR@@@
4B
/
/C 4
atQF33  4 S_aS999rH   c                    g }g }|j         }|                                }|                    t          j                  }g }t          |           D ]\  }	}
t          |
|j                  r.|                    |	                    |
j
                             n`t          |
|j                  s6|                    |                    t          |
                               n|                    |
           |                    ||	                                                    |                    ||	                                                    |D ]}	|	                    |          }|r| }|	                    |j
                  }t          |          D ]\  }	}
|
|z  ||	<    ||d                                         |d                                         z  j
                  }|D ]}	|	                    |          }|	                    |j
                  }t          |          D ]D\  }	}
|
|z  } ||                                |                                z  j
                  ||	<   Et!          ||          S )z'
    Normalize a given annihilator
    r   )rU   r   r{   r   r   ry   ra   rz   r   r   r   r   numerdenomlcmgcdr]   )list_ofrv   r   numr"  rU   r   	lcm_denomlist_of_coeffr   r   	gcd_numerfrac_anss                rF   r   r   	  s}   
 CE;DA&&IM '"" / /1a$$ 	$  qu....Aqw'' 	$  gajj!9!9::::  ### 	

=#))++,,, 	]1%++--....  % %EE)$$		 J	im$$I -(( ) )1y=amB'--//-2C2I2I2K2KKPQQI  % %EE)$$		im$$I -(( K K1y=4!1!1HNN4D4D!D IJJav666rH   c                 D   g }t          |           dz
  }|                    t          | d                              t          | dd                   D ]0\  }}|                    t          |          | |         z              1|                    | |                    |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.
    r7   r   N)r~   r   r<  ry   )r}   rP   r   r   r   s        rF   r%  r%  	  s     CJ!AJJwz!}%%&&&*QRR.)) / /1

71::
1-....JJz!}JrH   c                 |   | j         }| j        }t          d |D                       }|rt          |           S | j        d         }d |D             }d}t
          j        f}d |D             }t
          j        }	|D ]}
|	t          |
          z  }	|D ]}
|	t          |
          z  }	|	t          |||||           z  S )z(
    Converts a `hyper` to meijerg.
    c              3   H   K   | ]}|d k    ot          |          |k    V  dS r  r  r7  s     rF   r  z$_hyper_to_meijerg.<locals>.<genexpr>
  s5      44Aa'CFFaK444444rH   r   c              3       K   | ]	}d |z
  V  
dS r  rr   r7  s     rF   r  z$_hyper_to_meijerg.<locals>.<genexpr>
  s&      		A!a%						rH   rr   c              3       K   | ]	}d |z
  V  
dS r  rr   r7  s     rF   r  z$_hyper_to_meijerg.<locals>.<genexpr>
  s&      

Q1q5





rH   )
r  r  anyr4   r&  r   r   r   r$   r&   )r  r  r  ispolyr  r  anpr  bmqrJ  r   s              rF   r  r  
  s     
B	B4444444F !4   	!A 
				B
C
&B

"


C	A  aL  aLwr3C!,,,,rH   c                    t          |           t          |          k    r3d t          | |          D             |t          |           d         z   }n2d t          | |          D             | t          |          d         z   }|S )zvTakes polynomial sequences of two annihilators a and b and returns
    the list of polynomials of sum of a and b.
    c                     g | ]
\  }}||z   S rr   rr   r   s      rF   r   z_add_lists.<locals>.<listcomp>+
       333Aq1u333rH   Nc                     g | ]
\  }}||z   S rr   rr   r   s      rF   r   z_add_lists.<locals>.<listcomp>-
  r6  rH   )r~   r   )list1list2rP   s      rF   r   r   &
  s     5zzSZZ33UE!2!2333eCJJKK6HH33UE!2!2333eCJJKK6HHJrH   c                 `   | j                             | j                  s|                                 dk    r| j        S | j         }|j        g | j        |j        j        }|                                }t          |j
                  D ]Q\  }}t          ||j        j        j                  r-                    |                    |j                             Rt!                    k     s|t!                    k    rS fdt#                    D             }t!                    k    rfdt#                    D             }nt%                    }t#          |z
            D ]}d}	t'          ||          D ]i\  }
t)          |
| j                  }t+          |dd          sc c S t          |t,          t.          f          r|                                }|	|z  z  }	j|                    |	           t3          |          }|t!                    d         z   S )zy
    Tries to find more initial conditions by substituting the initial
    value point in the differential equation.
    Tc                 4    g | ]}|                   z  S rr   rr   )r   r   r   r}   s     rF   r   z_extend_y0.<locals>.<listcomp>J
  s8     ' ' '  ]NZ]2 ' ' 'rH   c                      g | ]
}|         S rr   rr   )r   r   r   s     rF   r   z_extend_y0.<locals>.<listcomp>M
  s    ***A"Q%***rH   r   r  N)r   r   r   r   r   r   rv   rU   r   ry   r}   ra   rz   r   r   r   r~   r   r   r   r  getattrr)   r*   r  r%  )	Holonomicr   r   r   r   r   r   list_redr   rP   r   rE   r   r}   r   s               @@@rF   r   r   1
  s6    ((66 ):R:R:T:TX\:\:\|'KAJ	BA	A+011 0 01![/4:;; 0!!!%%,,///
2ww{{a3r77ll	' ' ' ' '"1XX' ' 'r77Q;;****q***BBbBq1u 
	3 
	3ACB))  1Ay|,,q+t44 IIIIIa+{!;<< $		Aq1uIIcNNN(22HHBs2wwxxL  rH   c                 N   t          | t                    s|                                 S | j        }|                    |           }|                    |           }| |                                z  ||                                z  z   }|dz  } ||j        |j        f          S r  )ra   r-   r   rW   r!  r"  r   )fracr   r   r  sol_num	sol_denoms         rF   r<  r<  _
  s    dC   yy{{	A	A	AcAFFHHnq16688|+G1I1gk9=)***rH   c                    t          | t                    s| S | j        }| j        }t          j        }t          j        }|rddlm} t          t          |                    D ]9\  }}	|r't          |	                              |j                  }	||	||z  z  z  }:t          t          |                    D ]9\  }}	|r't          |	                              |j                  }	||	||z  z  z  }:t          |t          t          f          r|                                }t          |t          t          f          r|                                }||z  S )Nr   )mp)ra   r-   r&  denr   r   mpmathrE  ry   reversedr   
_to_mpmathprecr)   r*   r  )
rA  r   mpmr   r  sol_psol_qrE  r   r   s
             rF   r  r  l
  sQ   dC   AAFEFE
 (1++&&  1 	/

%%bg..ARU(1++&&  1 	/

%%bg..ARU%+{344  %+{344  5=rH   c                 	   |                                  }|s|                                 }nd}|sl|sj|                                 \  }	}
|	                                 r<|
j        r5t	          |
t
                    rt          |
          }
|
j        |
j        }}d}nd}nd}|s|s|sdS |	                    |          }t          |d          \  }}|                     |          st          ||d| g          S |r| |z  |                     |          z
  }t          |j        |j        d          }|                    |          }||dk    r|r|                    |           j        }t)          t+          |                    D ]2\  }}|dk    rt-          t+          |                    |d         }|} t)          |          D ]8\  }}t	          |t.          t0          f          r|                                ||<   9|t5          |          i}n|ro|                                 \  }}||z  |z  ||                    |          z  z   ||                    |          z  z
  }t          |j        |j        d          }n9|r6|||z  z  |z  dz
  }t          ||                              |	          j        }|                    |          }||dk    r|r||dk    r|                    |	          j        }t)          t+          |                    D ]`\  }}|dk    rt	          |t.          t0          f          r|                                }t5          |          |
z  }t5          |          |
z  } t	          |t.          t0          f          r|                                }|t5          |g          i}|s|st          ||||          S |s|j        }|                    |          rt          |||                                          }t-          |          }tA          |          dk    rp||d                  t4          j!        k    rT|d         }| ||z
  |z  z  }tE          ||||          }d t)          |          D             }||i}t          ||||          S tE          | |||          }|s|dz  }tE          | |||          }|t          ||||          S )	zO
    Converts polynomials, rationals and algebraic functions to holonomic.
    TFNr[   r   r   r7   c                 8    g | ]\  }}|t          |          z  S rr   r   r   s      rF   r   z)_convert_poly_rat_alg.<locals>.<listcomp>
  r  rH   )#is_polynomialis_rational_functionas_base_expr  ra   r	   r5   r   r  r   rX   r;  r   r   r   r}   rv   r   r{   r   ry   rH  r   r)   r*   r  r   as_numer_denomre  r   r   r  r~   r   r  )r  rx   r   r   r  rC   r  r1  isratbasepolyratexpr  r   is_algr   r   r[   rP   r   r   r   r   rI  indicialr   r  rE   r  r  r  s                                 rF   r  r  
  s   
 !!F ))++ 
e 
++--&!!## 	(8 	&%(( +"6**8VXqAFFFF e v tQA!!T**EAr 88A;; 3 QD6222 /(Ri$))A,,&eDDDoob)) :"''k',,t$$(C!(3--00  166 #//3E H!%(( + +1a+{!;<< + yy{{E!HAeHH%B	 (""$$1!ebj1qvvayy=(1qvvayy=8eDDD	 (1q5kB"Q''33H==Ioob)) :"''k'^v{{,,x((,C!(3--00  166a+{!;<< $		A!fQ44&=%+{!;<< (AugJJ'B	 1 1 aR000 
r 	5c1b))3355GGq66Q;;1QqT7ae++!AB{"A+Aq"f==LQQ<9P9PQQQLL!B$S!R444	$2v	.	.B 3
adAr622  3 S!R,,,rH   c                 :   t          j        |           }|r|\  }}}nd S fd|D             }|                                }	|	d         k    r|	d         nt          j        fd|D             }
d |D             }fd} ||d         |
d                   \  }}|d         |z  t          |||          z  }t          dt          |                    D ]>} |||         |
|                   \  }}|||         |z  t          |||          z  z  }?|S )Nc                 &    g | ]}|d          z  S r!  rr   )r   r   facs     rF   r   z&_convert_meijerint.<locals>.<listcomp>
  s!    &&&qad
&&&rH   r   r7   c                 &    g | ]}|d          z   S r  rr   )r   r   r  s     rF   r   z&_convert_meijerint.<locals>.<listcomp>  s!    ###Aq1Q4x###rH   c                     g | ]
}|d          S )r   rr   r7  s     rF   r   z&_convert_meijerint.<locals>.<listcomp>  s    qadrH   c                    | j         d         }|                    t                    r |                    t          t
                    }|                    d          }t          |          d         }||         }|                                }|d         k    r|d         nt          j
        }||z  fd| j         d         d         D             }fd| j         d         d         D             }fd| j         d         d         D             }	fd	| j         d         d         D             }
| z  t          ||f|	|
f|          fS )
Nr   F)r  r   r7   c              3   "   K   | ]	}|z   V  
d S rA   rr   r   r   rE   s     rF   r  z5_convert_meijerint.<locals>._shift.<locals>.<genexpr>  '      --a!e------rH   c              3   "   K   | ]	}|z   V  
d S rA   rr   r`  s     rF   r  z5_convert_meijerint.<locals>._shift.<locals>.<genexpr>  ra  rH   c              3   "   K   | ]	}|z   V  
d S rA   rr   r`  s     rF   r  z5_convert_meijerint.<locals>._shift.<locals>.<genexpr>  ra  rH   c              3   "   K   | ]	}|z   V  
d S rA   rr   r`  s     rF   r  z5_convert_meijerint.<locals>._shift.<locals>.<genexpr>  ra  rH   )r&  r;  r
   r  r   r   collectr   rR  r   r   r&   )r  r  r  dr   r   r  r  r  r  r  rE   rx   s              @rF   _shiftz"_convert_meijerint.<locals>._shift  sC   IbM5588 	'y#&&AIIa%I((GGAJaDMMOOaDAIIAaDD16E----TYq\!_-------TYq\!_-------TYq\!_-------TYq\!_---1"ugr2hR!4444rH   r  )r'   	_rewrite1rR  r   r   r
  r   r~   )r  rx   r  rC   r&  por  r   fac_listr  po_listG_listrg  rI  r  rP   r   r[  r  s    `               @@rF   r  r  
  sl   tQ''D RAAt '&&&A&&&H
A!		!qvA#######GAF5 5 5 5 5& vfQi,,HE1
1+
Q& Q Q Q
QC 1c&kk"" W W6&)WQZ00qx{U"\!hv%V%V%VVVJrH   c                 ~    d
 fd	}|                     t                    }t          |d          \  }} |t          t                    |dz  dz   t          dddg            |t	          t                    |dz  dz   t          dddg            |t          t                    |dz
  t          dd            |t          t                    |t          |dz  z  z   t          dddg            |t          t                    dt          z  |z  |dz  z   t          dddt          t                    z  g            |t          t                    dt          z  |z  |dz  z   t          dddt          t                    z  g            |t          t                    dt          z  |z  |dz  z   t          dddt          t                    z  g            |t          t                    |dz  dz
  t          dddg            |t          t                    |dz  dz
  t          dddg            |t          t                    t          d|z  z   t          |dz  z  z   t                      |t          t                    t          |z  d|dz  z  z   t          |dz  z  z   t                      |t!          t                    t          |z  d|dz  z  z   t          |dz  z  z   t                      |t#          t                    t           |z  d|dz  z  z   t          |dz  z  z   t                     d	S )zi
    Creates the look-up table. For a similar implementation
    see meijerint._create_lookup_table.
    r   rr   c           	                               t          | t                    g                               | t	          ||||          f           dS )z2
        Adds a formula in the dictionary
        N)r#  r  r  r   r   )formular   argr   r   tables        rF   addz_create_table.<locals>.add*  sY     	#..33::Gk3B77<9 	: 	: 	: 	: 	:rH   r[   r   r7   r  N)r   rr   )r   r  rX   r   r   r   r   r!   r   r   r"   r#   r   r   r   r    r   r   )rq  rC   rr  r   r   r[   s   `     rF   r  r  $  s   : : : : : : 	S!!A!!T**EAr CC"a%!)S!aV,,,CC"a%!)S!aV,,,CC"q&#q!$$$CC"s2q5y.#q1a&111CC!C%(RU"CQ$r((
O<<<CS		1S58b!e#S!aDHH-=>>>CS		2c6"9r1u$c1q!DHH*o>>>CS		2q519c1q!f---CS		2q519c1q!f---CS		32:BE	)3///C3R!BE'!CAI-s333C3R!BE'!CAI-s333CC3$r'Ab!eG#c"a%i/55555rH   c                 <   g }t          |          D ]}|                     ||          }t          |t                    rt	          | ||          }|j        du st          |t                    r d S |                    |           |                     |          } |S r  )r   r  ra   r   r2   r  r   r   )r  rx   r   r   r   r   r  s          rF   r  r  I  s    	B5\\  ii2c3 	%a$$C=E!!ZS%9%9!44
		#yy||IrH   )r   F)Nr   NNNTr  r  )srp   
sympy.corer   r   r   sympy.core.numbersr   r   r   r	   r
   r   r   sympy.core.singletonr   sympy.core.sortingr   sympy.core.symbolr   r   sympy.core.sympifyr   (sympy.functions.combinatorial.factorialsr   r   r   &sympy.functions.elementary.exponentialr   r   r   %sympy.functions.elementary.hyperbolicr   r   (sympy.functions.elementary.miscellaneousr   (sympy.functions.elementary.trigonometricr   r   r   'sympy.functions.special.error_functionsr   r   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.polytoolsr/   sympy.polys.matricesr0   sympy.printingr1   sympy.series.limitsr2   sympy.series.orderr3   sympy.simplify.hyperexpandr4   sympy.simplify.simplifyr5   sympy.solvers.solversr6   r  r8   r9   r:   holonomicerrorsr;   r<   r=   r>   rQ   rX   rS   r]   r   r  r
  r  r  r  sympy.integrals.meijerintr  r  r   r%  r  r   r   r<  r  r  r  r  r  rr   rH   rF   <module>r     sJ   
 % $ $ $ $ $ $ $ $ $                  " " " " " " & & & & & & + + + + + + + + & & & & & & L L L L L L L L L L F F F F F F F F F F > > > > > > > > 9 9 9 9 9 9 E E E E E E E E E E R R R R R R R R R R R R R R R R 9 9 9 9 9 9 8 8 8 8 8 8 8 8 % % % % % % ! ! ! ! ! ! ) ) ) ) ) ) * * * * * * & & & & & & & & ' ' ' ' ' ' ' ' ' ' ' ' & & & & & & - - - - - -       % % % % % % $ $ $ $ $ $ 2 2 2 2 2 2 - - - - - - ' ' ' ' ' ' R R R R R R R R R R) ) ) ) ) ) ) ) ) ) ) )  #, #, #,LC C C C C C C CLhG hG hG hG hG hG hG hGVf f f f f f f fR7J4 J4 J4 J4Z 54 M4 M4 M4 M4` eEll  - - - - - -_: _: _: _:H67 67 67 67r  (- - -<  +! +! +!\
+ 
+ 
+   > '(DbSW h- h- h- h-V *.b + + + +\ !# "6 "6 "6 "6J
 
 
 
 
rH   