
    Edur                       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 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l/m0Z0m1Z1 ddl2m3Z3 ddl4m5Z5 ddl6m7Z7 ddl8m9Z9 ddl:m;Z;m<Z< ddl=m>Z> ddl?m@Z@ ddlAmBZB ddlCmDZD ddlEmFZF ddlGmHZH ddlImJZJ ddlKmLZL ddlMmNZN ddlOmPZP dd lQmRZRmSZSmTZT dd!lUmVZVmWZWmXZXmYZY d" ZZd# Z[ G d$ d%          Z\ G d& d'          Z] G d( d)          Z^d=d+Z_dd*d,e;fd-Z` ed.          Zad/abd/acdd0ldmeZe d>d1Zfd?d2Zgd3 Zhd4 Zid5 Zjd6 Zkd7 Zld@d8Zmdd/d/e;d,fd9Znd,e;fd:Zoe;fd;Zpd< Zqd/S )AzL
This module implements Holonomic Functions and
various operations on them.
    )AddMulPow)NaNInfinityNegativeInfinityFloatIpi)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)r/   onesdomain)shapers    9lib/python3.11/site-packages/sympy/holonomic/holonomic.py<lambda>z(_find_nonzero_solution.<locals>.<lambda>*   s    *5!(;;     r   r6   )_solverC   	transpose)rD   homosysrA   
particular	nullspacenullitynullpartsols   `       rE   _find_nonzero_solutionrP   )   sf    ;;;;DHHW--J	oa GtQL!!I-H 
+
+
-
-CJrG   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      rE   DifferentialOperatorsrW   3   s"    D 'tY77D$*++rG   c                   (    e Zd ZdZd Zd ZeZd ZdS )rR   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)	rT   DifferentialOperatorzeroonerS   r   
gen_symbol
isinstancestr)selfrT   rU   s      rE   __init__z$DifferentialOperatorAlgebra.__init__   s    	#7Y!4$) $)   	,$Tu===DOOO)S)) ,"("F"F"FIv.. ,"+, ,rG   c                 n    dt          | j                  z   dz   | j                                        z   }|S )Nz9Univariate Differential Operator Algebra in intermediate z over the base ring )r0   r_   rT   __str__)rb   strings     rE   re   z#DifferentialOperatorAlgebra.__str__   s>    L4?##$&<=Y!!" rG   c                 J    | j         |j         k    r| j        |j        k    rdS dS NTF)rT   r_   rb   others     rE   __eq__z"DifferentialOperatorAlgebra.__eq__   s.    9
" 	t%:J'J 	45rG   N)__name__
__module____qualname____doc__rc   re   __repr__rk    rG   rE   rR   rR   Y   sS        $ $L, , ,   H    rG   rR   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   r6   N)parentrT   r`   gensr   x	enumeratedtype
from_sympyr   to_sympy
listofpolylenorder)rb   list_of_polyru   rT   ijs         rE   rc   zDifferentialOperator.__init__   s     {!+DIaL&!A!AV1tyQR|TU
 l++ 	D 	DDAqa,, D"&//'!**"="=Q"&//$--2B2B"C"CQ&))A-


rG   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 r@   )r`   listappend)blistofotherrO   r   s       rE   _mul_dmp_diffopz5DifferentialOperator.__mul__.<locals>._mul_dmp_diffop   sS    +t,, )$ & &AJJq1u%%%%
K((rG   r   c                    j         j        j        g}g }t          | t                    rB| D ]>}|                    |           |                    |                                           ?nv|                    j         j                            |                      |                    j         j                            |                                                      t          ||          S r@   )	ru   rT   r]   r`   r   r   diffrz   
_add_lists)r   sol1sol2r   rb   s       rE   
_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)))rG   r6   )r|   r`   r\   ru   rT   ry   rz   r   ranger}   r   )rb   rj   
listofselfr   r   rO   r   r   s   `       rE   __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5rG   c                 8   t          |t                    st          || j        j        j                  s,| j        j                            t          |                    }g }| j        D ]}|                    ||z             t          || j                  S d S r@   )	r`   r\   ru   rT   ry   rz   r   r|   r   )rb   rj   rO   r   s       rE   __rmul__zDifferentialOperator.__rmul__  s    %!566 		:eT[%5%;<< F)55gennEEC_ & &

519%%%%'T[999		: 		:rG   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   r6   )
r`   r\   r   r|   ru   rT   ry   rz   r   r   )rb   rj   rO   	list_self
list_others        rE   __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9rG   c                     | d|z  z   S Nrq   ri   s     rE   __sub__zDifferentialOperator.__sub__8  s    rUl""rG   c                     d| z  |z   S r   rq   ri   s     rE   __rsub__zDifferentialOperator.__rsub__;  s    d{U""rG   c                     d| z  S r   rq   rb   s    rE   __neg__zDifferentialOperator.__neg__>      DyrG   c                 &    | t           j        |z  z  S r@   r   Oneri   s     rE   __truediv__z DifferentialOperator.__truediv__A      quu}%%rG   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 )Nr6   r      )r\   ru   rT   r^   r|   rS   r]   r   )rb   nrO   	powreduces       rE   __pow__zDifferentialOperator.__pow__D  s    6 	K6 	M')9)=(>LLL ?dk=HH 	-;#()!+CJJt{'+,,,'T[999 1uz - 1q5M	 4''Q! - 1q5M	 9,,- -rG   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 + r6   z)*%sz*%s**)r|   rx   ru   rT   r]   r0   r_   )rb   r|   	print_strr   r   s        rE   re   zDifferentialOperator.__str__Y  s    _
	j)) 	[ 	[DAqDK$)) Av S477]S00	 #U"	Av S477]Vdk6L-MMM	tAww,w9O/PPSWXYSZSZZZIIrG   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   r6   )r`   r\   r|   ru   rT   r]   )rb   rj   r   s      rE   rk   zDifferentialOperator.__eq__r  s    e122 	%"22 t{el7R tuq!U* , % %A 0 55 %$uu%turG   c                     | j         j        }|t          |                    | j        d                   | j                  v S )zH
        Checks if the differential equation is singular at x0.
        r   )ru   rT   r-   r{   r|   rw   )rb   x0rT   s      rE   is_singularz DifferentialOperator.is_singular  s8    
 {U4==)<==tvFFFFrG   N)rl   rm   rn   ro   _op_priorityrc   r   r   r   __radd__r   r   r   r   r   re   rp   rk   r   rq   rG   rE   r\   r\      s        ! !F L. . .<36 36 36j
: 
: 
:: : :$ H# # ## # #  & & &- - -*  . H  G G G G GrG   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

    rs   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   annihilatorrw   )rb   r   rw   r   r   s        rE   rc   zHolonomicFunction.__init__  s%    , &rG   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_condra   r   r0   rw   r   r   )rb   str_sols     rE   re   zHolonomicFunction.__str__  s    !! 	 	=@AQ=R=R=R=RTVd47mmmmT$']]]]<GG	 699I5J5J5J5JTVG rG   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 rq   r{   ).0r   R1s     rE   
<listcomp>z+HolonomicFunction.unify.<locals>.<listcomp>  s#    DDD1ADDDrG   c                 :    g | ]}                     |          S rq   r   )r   r   R2s     rE   r   z+HolonomicFunction.unify.<locals>.<listcomp>  s#    EEE1AEEErG   )r   ru   rT   domunifyold_poly_ringrw   rW   ra   r_   r|   r\   r   r   r   )rb   rj   dom1dom2R	newparent_r   r   r   r   s            @@rE   r   zHolonomicFunction.unify  s#    $)%*vv8 	!%= 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|rG   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)r`   r   dictr   r   s    rE   is_singularicsz HolonomicFunction.is_singularics  s@     dgt$$ 	4&& 	5	 	rG   c                 *    t          | j                  S )z@
        Checks if the function have initial condition.
        )boolr   r   s    rE   r   z!HolonomicFunction._have_init_cond&  s     DG}}rG   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   r6   c                 @    g | ]\  }}|t          |z             z  S rq   r   )r   r   r   as      rE   r   z9HolonomicFunction._singularics_to_ord.<locals>.<listcomp>8  s.    AAADAq1yQ'''AAArG   N)r   r   r}   intr   r   r   Zerorx   r   r   rw   r   )rb   r   r   r   r   s       @rE   _singularics_to_ordz%HolonomicFunction._singularics_to_ord,  s     MM!GAJtw<<1 	Lc!ff 	LQ 	LBAA1XX " "		!&!!!!AAAAIaLLAAAAB$T%5tvtwKKK	L 	L 	L 	L 	L 	LrG   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   r6   Fnegativec                     g | ]
\  }}||z   S rq   rq   r   r   r   s      rE   r   z-HolonomicFunction.__add__.<locals>.<listcomp>  s     4441a!e444rG   r   Tc                 8    g | ]\  }}|t          |          z  S rq   r   r   r   r   s      rE   r   z-HolonomicFunction.__add__.<locals>.<listcomp>  '    CCC11y||#CCCrG   c                 8    g | ]\  }}|t          |          z  S rq   r   r   s      rE   r   z-HolonomicFunction.__add__.<locals>.<listcomp>  '    DDD11y||#DDDrG   c                     g | ]
\  }}||z   S rq   rq   r   s      rE   r   z-HolonomicFunction.__add__.<locals>.<listcomp>  s     ===41aQ===rG   )#r   ru   rT   r   r~   max	get_fieldrS   r   r   r}   r|   r]   newrepr/   rI   zerosrP   is_zero_matrixflat
_normalizer   r   rw   r   r   
_extend_y0zipr   
change_icsrx   r   r   r   )rb   rj   r   r   deg1deg2dimr   Krowsself	rowsothergenr   diff1diff2rowrD   exprprJ   rO   r   y1y2r   selfat0otherat0selfatx0	otheratx0_y0s                                 rE   r   zHolonomicFunction.__add__<  s   "'5+<+C+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 @((((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) 	Ae.B.B.D.D.M 	A w%(" A  ci00sy1144B444(dfdgrBBB *66q99 ,88;;7a< A A A%"2"21"5"555X] A7 A8 A??1--55  $/;;DGDDH % 1 = =dg F FI# AI A#e&6&6tw&?&???  $ux885@@7eh 	2$S$&111   E) 	e.B.B.D.D.L 	CC	$'0B0BCCCC&#BBB  ""d* 	u/C/C/E/E/N 	DD	%(0C0CDDDCB&#BB  ""d* 	u/C/C/E/E/M 	BB  	 	A Bw ==3r!ube+<+<===111 	 	A{ 11 dfdgr:::rG   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   r6   z1logarithmic terms in the series are not supported__iter__z4Definite integration for singular initial conditions   r   FN)r   ru   rS   r   r   	integrater   rx   r   r   r   NotImplementedErrorhasattrr   rw   r   r   r}   to_exprr;   r:   subsr`   r   r1   evalf	is_Number)rb   limitsr  DrD   r   r   cc2r   cjr   r   r   definiteindefinite_integralindefinite_exprloweruppers
indefinites                        rE   r  zHolonomicFunction.integrate  s   & #7   D( 	P((**A >{{6H{=== BW  GAJ&q\\ 	5 	5EArQw 5		!&)))) Qa 5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  W1I1I HfX
dg/0@10DdfdgWYZZ 	'&& 7 	%'"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}$ ; 	W$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 )aN  
        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   r6   NFc                 D    g | ]}                     |j                  S rq   )r   r   r   r   r   s     rE   r   z*HolonomicFunction.diff.<locals>.<listcomp>  s%    888A155<<888rG   c                 &    g | ]}|d          z  S r   rq   )r   r   seq_dmfs     rE   r   z*HolonomicFunction.diff.<locals>.<listcomp>  s!    333!q71:~333rG   r   )
setdefaultrw   r   r   r}   r   r   r   r|   ru   rT   r]   r~   r\   r   r   r   r   r   r   insert_derivate_diff_eqr   r^   r   r   )rb   argskwargsrO   r   annr   rhsr   r   r!  s            @@rE   r   zHolonomicFunction.diffS  s   , 	*d+++ 	Aw$&  vTa tAw , ,A((47++CC
 >!
 44 	6a 	66M ^A#*/"66 	6&s~abb'93:FFC##%% 6&&((E1 P,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 	2$S$&111ci!m,,QRR0 dfdgr:::rG   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 rh   )r   rw   r   r   r   ri   s     rE   rk   zHolonomicFunction.__eq__  s    u00 	v  	''))  e.C.C.E.E  w%(* %tw%(/B %#t$u4u5rG   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 rq   rq   )r   r   r   r   s     rE   r   z-HolonomicFunction.__mul__.<locals>.<listcomp>  s(    CCCQYq\MIaL0CCCrG   c                 4    g | ]}|                   z  S rq   rq   )r   r   r   r   s     rE   r   z-HolonomicFunction.__mul__.<locals>.<listcomp>  s(    FFFjm^jm3FFFrG   c                 L    g | ] }fd t          dz             D             !S )c                     g | ]	}j         
S rq   )r]   r  s     rE   r   z8HolonomicFunction.__mul__.<locals>.<listcomp>.<listcomp>  s    333af333rG   r6   r   )r   r   r   r   s     rE   r   z-HolonomicFunction.__mul__.<locals>.<listcomp>  s8    JJJ3333eAEll333JJJrG   r6   r   c                 P    g | ]"}t                    D ]}|         |         #S rq   r/  r   r   r   r   	coeff_muls      rE   r   z-HolonomicFunction.__mul__.<locals>.<listcomp>  s4    QQQaQQ1Yq\!_QQQQrG   r   c                 P    g | ]"}t                    D ]}|         |         #S rq   r/  r1  s      rE   r   z-HolonomicFunction.__mul__.<locals>.<listcomp>  s8    $Y$Y$YPUVWPXPX$Y$Y1Yq\!_$Y$Y$Y$YrG   Fr   c                 H    g | ]}d  t          dz             D             S )c                     g | ]}d S r   rq   r   r   s     rE   r   z8HolonomicFunction.__mul__.<locals>.<listcomp>.<listcomp>  s    666Aa666rG   r6   r/  )r   r   r   s     rE   r   z-HolonomicFunction.__mul__.<locals>.<listcomp>  s2    MMM166q1u666MMMrG   Tc                 8    g | ]\  }}|t          |          z  S rq   r   r   s      rE   r   z-HolonomicFunction.__mul__.<locals>.<listcomp>J  r   rG   c                 8    g | ]\  }}|t          |          z  S rq   r   r   s      rE   r   z-HolonomicFunction.__mul__.<locals>.<listcomp>N  r   rG   c                     g | ]
\  }}||z   S rq   rq   r   s      rE   r   z-HolonomicFunction.__mul__.<locals>.<listcomp>c  s      E E E41aQ E E ErG   )-r   r`   r   r   hasrw   r	  r   r   r~   r   r.   r   r   r   ru   rT   r   r   r|   r   r^   r/   rI   r   rP   r   ry   DMFdiffr   is_zeror]   r}   r   r   r   minr   r   r   rx   r   r   r   r   )"rb   rj   ann_selfr   r   r   	ann_otherr   self_red	other_redlin_sys_elementslin_syshomo_sysrO   sol_anny0_selfy0_othercoeffkr   r   r  r  r   r  r  r  r   r   r   r2  r   r   r   s"                              @@@@@@@rE   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 	::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) 0	Ae.B.B.D.D.M 0	A w%(" -A %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z =.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< A A A%"2"21"5"555X] A7 A8 A??1--55  $/;;DGDDH % 1 = =dg F FI# AI A#e&6&6tw&?&???  $ux885@@7eh 	6$Wdf555   E) 
	e.B.B.D.D.L 
	CC	$'0B0BCCCC&#BBB  ""d* 	u/C/C/E/E/N 	DD	%(0C0CDDDCB&#BB  ""d* 	u/C/C/E/E/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{ F !Bq1uII E E3q"QU)3D3D E E EBq1uIIF !$&$'2>>>rG   c                     | |dz  z   S r   rq   ri   s     rE   r   zHolonomicFunction.__sub__h  s    ebj  rG   c                     | dz  |z   S r   rq   ri   s     rE   r   zHolonomicFunction.__rsub__k  s    by5  rG   c                     d| z  S r   rq   r   s    rE   r   zHolonomicFunction.__neg__n  r   rG   c                 &    | t           j        |z  z  S r@   r   ri   s     rE   r   zHolonomicFunction.__truediv__q  r   rG   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 )Nr6   r   c                 D    g | ]}j                             |          S rq   )rT   r{   )r   r   ru   s     rE   r   z-HolonomicFunction.__pow__.<locals>.<listcomp>  s)    ===q6;''**===rG   z&Negative Power on a Holonomic Functionr   )r   r~   ru   r   r   r|   r.   r   rw   r   r\   r   r   r=   rS   r   r   r   )rb   r   r'  r   p0p1rO   ddrZ   r   ru   s             @rE   r   zHolonomicFunction.__pow__t  s   !Q& 	>"CZFw -47mmA&!+,"B"B(2tv&&*/B====RH===C%c622B$R"===q5 	N#$LMMM6 	B!(<B$R!%AAA6 	-K1uz - 1q5M	 4''Q! - 1q5M	 9,,- -rG   c                 L    d | j         j        D             }t          |          S )zF
        Returns the highest power of `x` in the annihilator.
        c                 6    g | ]}|                                 S rq   degreer6  s     rE   r   z,HolonomicFunction.degree.<locals>.<listcomp>  s     ???aqxxzz???rG   )r   r|   r   )rb   rO   s     rE   rV  zHolonomicFunction.degree  s)     @?4#3#>???3xxrG   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 )ab  
        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 rq   )r  rw   )r   r   r   r|   rD   rb   s     rE   r   z1HolonomicFunction.composition.<locals>.<listcomp>  s9    JJJ1A##TVDM222Q6JJJrG   c                 &    g | ]}t           j        S rq   r   r   r6  s     rE   r   z1HolonomicFunction.composition.<locals>.<listcomp>  s    +++Q!&+++rG   r   c                 &    g | ]}t           j        S rq   rZ  r6  s     rE   r   z1HolonomicFunction.composition.<locals>.<listcomp>  s    888!qv888rG   Tc                 D    g | ]}|                     j                  S rq   )r   rw   )r   r   rb   s     rE   r   z1HolonomicFunction.composition.<locals>.<listcomp>  s%    :::a166$&>>:::rG   r6   r   NFr   )r   ru   r~   r   rw   r|   rx   r`   rT   ry   r{   r  r   r   r   r'   rI   r   gauss_jordan_solver   r   r   r   )rb   r   r%  r&  r   r   r   r   r   r  coeffssystemhomogeneouscoeffs_nextrO   taustaur|   rD   s   ``               @@rE   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---rG   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] http://www.risc.jku.at/publications/download/risc_2244/DIPLFORM.pdf

        r   )lbr   TintegerSnr6   c                     g | ]
}|d          S r   rq   r6  s     rE   r   z1HolonomicFunction.to_sequence.<locals>.<listcomp>2  s    '''A1Q4'''rG   r   ZfilterC_%sF)$r   shift_xto_sequencer   r   
_frobeniusr   ru   rT   r   r9   r   rx   r|   
all_coeffsr}   r   r{   r   r=  r   rV  r   r   keysr  r   r8   r~   r-   r   r   r5   r`   r   r7   )rb   rf  dict1r   r   r   r   r   r   	listofdmprV  rI  rH  rO   keylistr  r  
smallest_ndummyseqsunknownstempr~   	all_rootsmax_rootr   u0eqsoleqsr  s                                 rE   rp  zHolonomicFunction.to_sequence  s   h 7a< 	7<<((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:& Q1q5!*%%%#,,u*=*=1q519a@P@P*PQ%%%%),e)<)<r!a%!)Q?O?O)OE1q5!*%%	Q '''''GG V^
 ueai(( 	# 	#AG| #v < <Atqy <aaU ; ;;

4    

16"""" !a(( 	!&//#.*<==qMMM	NN$$	 	39~~)HXz22Je$$ bMM 	( 	(DAqIIa)A,,&'''' r77U? 5	)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tqy EeAhmmAq11F1qt84DDD

2 3****F&$'' 4s2ww.. 	- 	-A 6$*619$5$5q	ayF* -		&"34444 		&),,,, F.sB77DEE)#r22333r77E** ) )F? 2 &vqy 1 1F1I ! !AayA~ !		!F1I,///  )IIfQi((( 	>&sB//<==!#r**++rG   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    rkg }t          | j                                                  D ]A}t          |                                          D ]}
|
|k    r|                    |           Bn|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 }t1          d          }|D ]}i }t3          | j        j                  D ]\  }}
|
                                }t          |          dz
  }t9          |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          |          }t?          |          }t?          d |D                       }t          d |D                       } ||z   }!i }"g }#g }$t9          ||dz             D ]}
|
|v rgt          j         }%|                                D ]0}|d         |
k    r"|%||         !                    |||z
            z  }%1|                    |%           m|                    t          j                    tE          ||          }|j#        }&tI          |j                            |j        d                   |d          }'|'                                }'|'r"t?          |'          dz   }(t?          |(|!          }!|&|!z  }&g })|                                 dk    r| j        |         })n|                                 dk    r|dk    rt          |          |k    rt          |          dk    rtK          | |&t          |          z             }*t          |*          t          |          k    rXt9          t          |          t          |*                    D ]-}|)                    |*|         tM          |          z             .t          |)          |&k     rt9          | |          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]tO          |          d||
d         z   z  z   },t#          |,          |"||
d         z   <   |$                    |"||
d         z                       |
d         |k    r1|+||
         !                    ||          |"||
d         z            z  z  }+|#                    |+           6tQ          |#g|$R  }-tS          |-tT                    rt9          t          |)          |&          D ]t}||"vr'tO          |          d|z  z   },t#          |,          |"|<   |"|         |-v r"|)                    |-|"|                             Y|)                    |"|                    u|r(|                    tW          ||)          ||!f           |                    tW          ||)          |f           t9          t          |)          |&          D ]~}||"vr'tO          |          d|z  z   },t#          |,          |"|<   d}.|-D ]/}
|"|         |
v r#|)                    |
|"|                             d}.0|.s|)                    |"|                    |r'|                    tW          ||)          ||!f           n%|                    tW          ||)          |f           |dz  }|S )Nc                     | d         S )Nr6   rq   rw   s    rE   rF   z.HolonomicFunction._frobenius.<locals>.<lambda>  
    !A$ rG   )keyc                     | d         S Nr   rq   r  s    rE   rF   z.HolonomicFunction._frobenius.<locals>.<lambda>  r  rG   Fr   Tc              3   <   K   | ]}t          |          d k    V  dS r6   N)r}   r6  s     rE   	<genexpr>z/HolonomicFunction._frobenius.<locals>.<genexpr>  s,      !;!;!#a&&A+!;!;!;!;!;!;rG   c              3   "   K   | ]
}|d k    V  dS r   Nrq   r6  s     rE   r  z/HolonomicFunction._frobenius.<locals>.<genexpr>  s&      ++Q!V++++++rG   c              3   <   K   | ]}t          |          |k    V  d S r@   r   r6  s     rE   r  z/HolonomicFunction._frobenius.<locals>.<genexpr>  s,      00QSVVq[000000rG   c                     g | ]
}|d          S r   rq   r6  s     rE   r   z0HolonomicFunction._frobenius.<locals>.<listcomp>  s    111qt111rG   c                     g | ]
}|d          S r   rq   r   r   s     rE   r   z0HolonomicFunction._frobenius.<locals>.<listcomp>  s    4I4I4IaQqT4I4I4IrG   r   rg  ri  Cr6   c                     g | ]
}|d          S r   rq   r6  s     rE   r   z0HolonomicFunction._frobenius.<locals>.<listcomp>  s    +++qt+++rG   c                     g | ]
}|d          S r6   rq   r6  s     rE   r   z0HolonomicFunction._frobenius.<locals>.<listcomp>  s    ...1!A$...rG   c                     g | ]
}|d          S r  rq   r6  s     rE   r   z0HolonomicFunction._frobenius.<locals>.<listcomp>  s    ///A1Q4///rG   r   rk  rl  z_%s),	_indicialr   rs  is_realextendas_real_imagsortr}   r   r   allr   r   r=  r   r   	is_finiter   r   ru   rT   r   r9   r   ordrx   r|   rr  r   r{   r   r   r   r  r8   r~   r-   r   r   chrr5   r`   r   r7   )/rb   rf  indicialrootsrealscomplr   r   r   grpintdiffr   independentallposallintrootstoconsiderposrootsr   r   r   r   finalsolcharr   rt  ru  rV  rI  rH  rO   rv  r  r  degree2rw  rx  ry  rz  r{  r~   r|  r}  r~  r   r  letterr  r  s/                                                  rE   rq  zHolonomicFunction._frobenius  sa   ((++--.. 	= 	=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( 	2 OTW\\^^,, 2 2 !3!3!5!566 2 2AAv 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 2#&u::,  + +AAv + ***#&x==/3%%%%*."3#4#4Q#7#7>>13xx  B	 B	AE!$"2"=>> ] ]1LLNN	Y!+vz** 	] 	]A%fqj1Ez ! 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\\ @ @Q419 @ 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""$$, 8WQZ$$&&%/ 8AF 8s1vv{ 8sSbOcOcghOh 8ec!ffn55r77SVV# 8"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 >%(YYQqT1B%BF/5f~~F1qt8,$OOF1qt8,<===Q419 I%(--1"5"5q1Q4x8H"HHBJJrNNNN s.X...fd++ !"3r77E22 
1 
1F? 7%(YY%9F(.vF1I!!9. 1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 3!$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rG      c                 P   ||                                  }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             }d |j        D             }|	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&|t/          |
|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  r6   )_recurc                 4    g | ]}|                   z  S rq   rq   )r   r   rI  seqs     rE   r   z,HolonomicFunction.series.<locals>.<listcomp>  s(    222AAwQ222rG   c                     g | ]}|S rq   rq   r6  s     rE   r   z,HolonomicFunction.series.<locals>.<listcomp>  s    (((Qq(((rG   )rp  r`   tupler}   r   seriesr   r~  
recurrencer~   rw   r   r|   ru   rT   r   rx   r   r   r   r   r   DMFsubsr2   r  )rb   r   coefficientr~   r  r  constantpowerrO   r   lrw   r   seq_dmpr   r   r   subrH  serrI  r  s                      @@rE   r  zHolonomicFunction.seriess  sw   :  	 ))++JJJj%(( 	S__-A 	#AJMM
E** 	s:!/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z AQ!3!3c!a%j!@@

5!!!! 	JfcNN 	. 	.DAq1q=()A--CC 	95Q]!3!334a888C7 	'88Aq2v&&&
rG   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 )Nrk  rl  r   )r-   r{   rs  )polyroot_allr   rw   s     rE   _pole_degreez1HolonomicFunction._indicial.<locals>._pole_degree  sG    QZZ--q===HHMMOO# {"qrG   c                 6    g | ]}|                                 S rq   rU  r  s     rE   r   z/HolonomicFunction._indicial.<locals>.<listcomp>  s     111!((**111rG   
   r6   c                 ,    | j         rn
 |           S r@   )r<  )qr  infs    rE   rF   z-HolonomicFunction._indicial.<locals>.<lambda>  s    qy=ll1oo rG   )r   ro  r  r   r|   ru   rT   rw   r]   r^   r   r~   r   r}   r=  rx   rr  r-   r{   )rb   
list_coeffr  yrV  degr   r   r   ru  r   r  r  rw   s             @@@@rE   r  zHolonomicFunction._indicial  s   
 7a< 	5<<((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!| 6
Q! 3 6	&1*q.1A55QJAAQZZ]]A&&&rG   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   r6   )sympy.holonomic.numericalr  r
  r   r   r  r	  r   r   r   r-   r   ru   rT   r{   r|   rw   r<   )rb   pointsr  hr  r  lpr   r   r   r   s              rE   r  zHolonomicFunction.evalf  s   \ 	544444 vz** 	.B&		Aw!| UvdQCKPPPQSTT; *))A1u BQUaK  A!eWF1q5\\ . .fRj1n----t'.3<<T=M=XY[=\]]_c_eff 	0 	0ADG| 0qF{ 0&tQ///0  	T6$v;OOOPRSSvdF6{KKKKrG   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()
        rZ   )r   ru   rT   r   r   rW   r|   r   r   r\   r   r   r   )rb   zr   r   ru   r   rO   r   s           rE   change_xzHolonomicFunction.change_xB  s     %*.a  )!T22	!, 	! 	!AJJqqxx    #C00 a$':::rG   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 rq   )rz   r{   r  )r   r   r   rT   rw   s     rE   r   z-HolonomicFunction.shift_x.<locals>.<listcomp>Z  sE    XXXAtt}}Q//44QA>>??XXXrG   )
rw   r   r|   ru   rT   r\   r   r   r   r   )rb   r   listaftershiftrO   r   rT   rw   s    `   @@rE   ro  zHolonomicFunction.shift_xQ  s    
 F)4&+XXXXXXXXX"3(8(?@@Wq[##%% 	-$S!,,, aTW555rG   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   r6   r   r  )as_listr  r   rl  rn  z+Can't compute sufficient Initial ConditionsTFr   )&rp  r`   r  r}   to_hyperr~  r  rw   r   r~   r-   ru   rT   r{   r|   r   r   r   rx   r   r(   r)   as_exprr   r  r	  r   r]   r;   r   rV  r   r   rs  r  r4   remover$   )rb   r  r  r  rw  r  rO   r   r~  rD   rw   r   mnonzerotermsr   is_hyperr   r   r  arg1arg2	listofsolapbqrI  s                            rE   r  zHolonomicFunction.to_hypera  s   F  	 ))++JJJj%(( 	S__-A 	#AJ#AJMM
E** 	s:!/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 6 	 !7!7Q!H!H*,_bcccL&C!,// 4 41q5 CFFaK FFs2ww; 4!"Q%+{)CDD 0 "112a51a4<'CC 6&!),,q!t33CC#[9:: -kkmma&66A},, !7 5 XXaR00344y Qw +xx1r6***J>CGG# 	U%&STTT q#al++A-.. 	 	A|A!(-"44    	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<==== Bw 		!		! A  1RU88A-,@#@"F"Fq!B$"O"ORWXZ\^`abcefbf`fRgRgQmQmnoqrsuquQvQv!wxxxxqAxx%BAqD"9"99AqD@@ 	A}$$7 	'88Aq2v&&&
rG   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

        )r3   r  simplifyr   s    rE   r  zHolonomicFunction.to_expr  s&    & 4==??++44666rG   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)rw   r   lenicsrB   F)r  )r}   r   r   r~   ru   rT   rB   expr_to_holonomicr  rw   r:   r;   r   r  r   )rb   r   r  symbolicr   rO   r   s          rE   r   zHolonomicFunction.change_ics-  s    $  	"c$'llT-=-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  r6   r   r   )r  r   r   r}   _hyper_to_meijerg)rb   r   rO   r   s       rE   
to_meijergzHolonomicFunction.to_meijergP  s    , mmDm))f 	6 	6A1vv{ 6qtQ1 6qt/!5555
rG   r  FT)r  FTN)r  r  F)FNr@   )$rl   rm   rn   ro   r   rc   re   rp   r   r   r   r   r   r  r   rk   r   r   r   r   r   r   r   rV  rd  rp  rq  r  r  r  r  ro  r  r  r   r  rq   rG   rE   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         rG   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   rZ   r6   Fc                 F   g }t          |          D ]}|r)|                     ||                                          }n|                     ||          }|j        du st	          |t
                    r d S |                    |           |                     |          } |S NFr   r  r  r  r`   r   r   r   simprw   r   r~   r  r   r   vals           rE   _find_conditionsz$from_hyper.<locals>._find_conditions  s    u 		  		 A 'ii2&&,,..ii2&&}% C)=)= ttIIcNNN99Q<<DD	rG   r  )r  r  r%  atomsr   poprW   r*   r   r3   r   r   r   rd  r`   r$   r~   )funcr   r  r   r   r  rw   r   rZ   xDxr1aixDx_1r2birO   r  r  r   s                      rE   
from_hyperr  s  s=     	AA	!A	A!""21"5"5t<<EAr B$C	
B  
cBh!GE	B  
ebj
r'CtD*++ 8 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3rG   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   rZ   r6   r   Fc                 F   g }t          |          D ]}|r)|                     ||                                          }n|                     ||          }|j        du st	          |t
                    r d S |                    |           |                     |          } |S r  r  r  s           rE   r  z&from_meijerg.<locals>._find_conditions  s    u 	  	 A 'ii2&&,,..ii2&&}% C)=)= ttIIcNNN99Q<<DD	rG   r  )r  r  r}   anbmr%  r  r   r  rW   r   r   rd  r3   r   r   r`   r%   r~   )r  r   r  r  rB   r   r   r   r  r   r  rw   r   rZ   r  xDx1r  r   r  r  rO   r  r  r   s                           rE   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*++ 8 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3rG   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
    r6   z%Specify the variable for the functionNr   )r   r   r  rB   r  )rB   Fr  rB   )rw   r  rB   c                 8    g | ]\  }}|t          |          z  S rq   r   r   s      rE   r   z%expr_to_holonomic.<locals>.<listcomp>	  '    QQQAA	!,QQQrG   )*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   rd  r%  r  r  r   r   r   r   r   r  r   r   rx   )r  rw   r   r   r  rB   r  syms
extra_symssolpolyftr  rO   r  r%  r   rD   gsingular_icss                       rE   r  r  	  s~   R 4==DD t99> 	FxxzzAADEEE	
d AdJ 488E?? 	FFFz??a 	4J'1133F $D!r&QWbjkkkG   4!mF33333	#	# 4!mF3333  $6IIaAsOO 	B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Cx 	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; 	A1QqT7ae+ 	A!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9rG   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   )rT   r   rz   r   r   rx   r`   ry   r   r   r   r   numerdenomlcmgcdr\   )list_ofru   r   numr"  rT   r   	lcm_denomlist_of_coeffr   r   	gcd_numerfrac_anss                rE   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6rG   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.
    r6   r   N)r}   r   r;  rx   )r|   rO   r   r   r   s        rE   r$  r$  	  s     CJ!AJJwz!}%%&&&*QRR.)) / /1

71::
1-....JJz!}JrG   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  r6  s     rE   r  z$_hyper_to_meijerg.<locals>.<genexpr>
  s5      44Aa'CFFaK444444rG   r   c              3       K   | ]	}d |z
  V  
dS r  rq   r6  s     rE   r  z$_hyper_to_meijerg.<locals>.<genexpr>
  s&      		A!a%						rG   rq   c              3       K   | ]	}d |z
  V  
dS r  rq   r6  s     rE   r  z$_hyper_to_meijerg.<locals>.<genexpr>
  s&      

Q1q5





rG   )
r  r  anyr3   r%  r   r   r   r#   r%   )r  r  r  ispolyr  r  anpr  bmqrI  r   s              rE   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!,,,,rG   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 rq   rq   r   s      rE   r   z_add_lists.<locals>.<listcomp>*
       333Aq1u333rG   Nc                     g | ]
\  }}||z   S rq   rq   r   s      rE   r   z_add_lists.<locals>.<listcomp>,
  r6  rG   )r}   r   )list1list2rO   s      rE   r   r   %
  s     5zzSZZ I33UE!2!2333eCJJKK6HH33UE!2!2333eCJJKK6HHJrG   c                 Z   | 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d D             }t#          |z
            D ]}d}	t%          ||          D ]i\  }
t'          |
| j                  }t)          |dd          sc c S t          |t*          t,          f          r|                                }|	|z  z  }	j|                    |	           t1          |          }|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 rq   rq   )r   r   r   r|   s     rE   r   z_extend_y0.<locals>.<listcomp>I
  s8     ' ' '  ]NZ]2 ' ' 'rG   c                      g | ]
}|         S rq   rq   )r   r   r   s     rE   r   z_extend_y0.<locals>.<listcomp>L
  s    ***A"Q%***rG   c                     g | ]}|S rq   rq   r6  s     rE   r   z_extend_y0.<locals>.<listcomp>N
  s    !!!!!!!rG   r   r  N)r   r   r   r   r   r~   ru   rT   r   rx   r|   r`   ry   r   r   r   r}   r   r   r  getattrr(   r)   r  r$  )	Holonomicr   r   r   r   r   r   list_redr   rO   r   rD   r   r|   r   s               @@@rE   r   r   0
  sI    ((66 ):R:R:T:TX\:\ |'KAJ	BA	A+011 0 01![/4:;; 0!!!%%,,///
2ww{ !a3r77l !	' ' ' ' '"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  rG   c                 N   t          | t                    s|                                 S | j        }|                    |           }|                    |           }| |                                z  ||                                z  z   }|dz  } ||j        |j        f          S r  )r`   r,   r   rV   r!  r"  r   )fracr   r   r  sol_num	sol_denoms         rE   r;  r;  ^
  s    dC   yy{{	A	A	AcAFFHHnq16688|+G1I1gk9=)***rG   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)r`   r,   r&  denr   r   mpmathrF  rx   reversedr   
_to_mpmathprecr(   r)   r  )
rB  r   mpmr   r  sol_psol_qrF  r   r   s
             rE   r  r  k
  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=rG   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.
    TFNrZ   r   r   r6   c                 8    g | ]\  }}|t          |          z  S rq   r   r   s      rE   r   z)_convert_poly_rat_alg.<locals>.<listcomp>
  r  rG   )#is_polynomialis_rational_functionas_base_expr  r`   r	   r4   r   r  r   rW   r:  r   r   r   r|   ru   r   rz   r   rx   rI  r   r(   r)   r  r   as_numer_denomrd  r   r~   r  r}   r   r  )r  rw   r   r   r  rB   r  r1  isratbasepolyratexpr  r   is_algr   r   rZ   rO   r   r   r   r   rH  indicialr   r  rD   r  r  r  s                                 rE   r  r  
  sA   
 !!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6  #//3E H!%(( + +1a+{!;<< + yy{{E!HAeHH%B	 (""$$1!ebj1qvvayy=(1qvvayy=8eDDD	 (1q5kB"Q''33H==Ioob))  	("' 	(k 	(	(%{	(,,x((,C!(3--00  16 a+{!;<< $		A!fQ44&=%+{!;<< (AugJJ'B	 1 1 aR000 
r 	5c1b))3355GGq66Q; 	51QqT7ae+ 	5!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,,,rG   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   rq   )r   r   facs     rE   r   z&_convert_meijerint.<locals>.<listcomp>
  s!    &&&qad
&&&rG   r   r6   c                 &    g | ]}|d          z   S r  rq   )r   r   r  s     rE   r   z&_convert_meijerint.<locals>.<listcomp>  s!    ###Aq1Q4x###rG   c                     g | ]
}|d          S )r   rq   r6  s     rE   r   z&_convert_meijerint.<locals>.<listcomp>  s    qadrG   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   r6   c              3   "   K   | ]	}|z   V  
d S r@   rq   r   r   rD   s     rE   r  z5_convert_meijerint.<locals>._shift.<locals>.<genexpr>  '      --a!e------rG   c              3   "   K   | ]	}|z   V  
d S r@   rq   ra  s     rE   r  z5_convert_meijerint.<locals>._shift.<locals>.<genexpr>  rb  rG   c              3   "   K   | ]	}|z   V  
d S r@   rq   ra  s     rE   r  z5_convert_meijerint.<locals>._shift.<locals>.<genexpr>  rb  rG   c              3   "   K   | ]	}|z   V  
d S r@   rq   ra  s     rE   r  z5_convert_meijerint.<locals>._shift.<locals>.<genexpr>  rb  rG   )r%  r:  r
   r  r   r   collectr   rS  r   r   r%   )r  r  r  dr   r   r  r  r  r  r  rD   rw   s              @rE   _shiftz"_convert_meijerint.<locals>._shift  sD   IbM5588 	'y#&&AIIa%I((GGAJaDMMOOaDAI)AaDD16E----TYq\!_-------TYq\!_-------TYq\!_-------TYq\!_---1"ugr2hR!4444rG   r  )r&   	_rewrite1rS  r   r   r
  r   r}   )r  rw   r  rB   r%  por  r   fac_listr  po_listG_listrh  rH  r  rO   r   r\  r  s    `               @@rE   r  r  
  sm   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JrG   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   rq   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        rE   addz_create_table.<locals>.add)  sY     	#..33::Gk3B77<9 	: 	: 	: 	: 	:rG   rZ   r   r6   r  N)r   rq   )r   r  rW   r   r   r   r   r    r   r   r!   r"   r   r   r   r   r   r   )rr  rB   rs  r   r   rZ   s   `     rE   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5rG   c                 <   g }t          |          D ]}|                     ||          }t          |t                    rt	          | ||          }|j        du st          |t                    r d S |                    |           |                     |          } |S r  )r   r  r`   r   r1   r  r   r   )r  rw   r   r~   r   r   r  s          rE   r  r  H  s    	B5\\  ii2c3 	%a$$C=E! 	ZS%9%9 	44
		#yy||IrG   )r   F)Nr   NNNTr  r  )rro   
sympy.corer   r   r   sympy.core.numbersr   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.matricesr/   sympy.printingr0   sympy.series.limitsr1   sympy.series.orderr2   sympy.simplify.hyperexpandr3   sympy.simplify.simplifyr4   sympy.solvers.solversr5   r  r7   r8   r9   holonomicerrorsr:   r;   r<   r=   rP   rW   rR   r\   r   r  r
  r  r  r  sympy.integrals.meijerintr  r  r   r$  r  r   r   r;  r  r  r  r  r  rq   rG   rE   <module>r     s    
 % $ $ $ $ $ $ $ $ $ L L L L L L L L L L L L L L L L " " " " " " & & & & & & + + + + + + + + & & & & & & 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
 
 
 
 
rG   