
    gai                       d Z ddlmZmZmZ ddlmZmZmZm	Z	m
Z
mZmZ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/m0Z0 ddl1m2Z2m3Z3 ddl4m5Z5 ddl6m7Z7 ddl8m9Z9 ddl:m;Z; ddl<m=Z=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lQmRZR dd lSmTZTmUZUmVZV dd!lWmXZXmYZYmZZZm[Z[ d" Z\d# Z] G d$ d%          Z^ G d& d'          Z_ G d( d)          Z`d=d+Zadd*d,e=fd-Zb ed.          Zcd/add/aedd0lfmgZg d>d1Zhd?d2Zid3 Zjd4 Zkd5 Zld6 Zmd7 Znd@d8Zodd/d/e=d,fd9Zpd,e=fd:Zqe=fd;Zrd< Zsd/S )AzL
This module implements Holonomic Functions and
various operations on them.
    )AddMulPow)NaNInfinityNegativeInfinityFloatIpiequal_valued
int_valued)S)ordered)DummySymbol)sympify)binomial	factorialrf)	exp_polarexplog)coshsinh)sqrt)cossinsinc)CiShiSierferfcerfi)gamma)hypermeijerg)	meijerint)Matrix)PolyElement)FracElement)QQRR)DMF)roots)Poly)DomainMatrix)sstr)limit)Order)hyperexpand)	nsimplify)solve   )HolonomicSequenceRecurrenceOperatorRecurrenceOperators)NotPowerSeriesErrorNotHyperSeriesErrorSingularityErrorNotHolonomicErrorc                       fd}                      |          \  }}|j        d         } |d|f          |z  }||z                                   }|S )Nc                 8    t          j        | j                  S N)r1   onesdomain)shapers    U/var/www/html/ai-engine/env/lib/python3.11/site-packages/sympy/holonomic/holonomic.py<lambda>z(_find_nonzero_solution.<locals>.<lambda>+   s    *5!(;;     r   r8   )_solverE   	transpose)rF   homosysrC   
particular	nullspacenullitynullpartsols   `       rG   _find_nonzero_solutionrR   *   sf    ;;;;DHHW--J	oa GtQL!!I-H 
+
+
-
-CJrI   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      rG   DifferentialOperatorsrY   4   s"    D 'tY77D$*++rI   c                   (    e Zd ZdZd Zd ZeZd ZdS )rT   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)	rV   DifferentialOperatorzeroonerU   r   
gen_symbol
isinstancestr)selfrV   rW   s      rG   __init__z$DifferentialOperatorAlgebra.__init__   s    	#7Y!4$) $)  $Tu===DOOO)S)) ,"("F"F"FIv.. ,"+, ,rI   c                 n    dt          | j                  z   dz   | j                                        z   }|S )Nz9Univariate Differential Operator Algebra in intermediate z over the base ring )r2   ra   rV   __str__)rd   strings     rG   rg   z#DifferentialOperatorAlgebra.__str__   s>    L4?##$&<=Y!!" rI   c                 B    | j         |j         k    o| j        |j        k    S rB   )rV   ra   rd   others     rG   __eq__z"DifferentialOperatorAlgebra.__eq__   s%    yEJ& 3%"22	3rI   N)__name__
__module____qualname____doc__re   rg   __repr__rl    rI   rG   rT   rT   Z   sS        $ $L, , ,   H3 3 3 3 3rI   rT   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   r8   N)parentrV   rb   gensr   x	enumeratedtype
from_sympyr   to_sympy
listofpolylenorder)rd   list_of_polyrv   rV   ijs         rG   re   zDifferentialOperator.__init__   s     {!+DIaL&!A!AV1tyQR|TU
 l++ 	D 	DDAqa,, D"&//'!**"="=Q"&//$--2B2B"C"CQ&))A-


rI   c                      j         }t          |t                    r|j         }nPt          | j        j        j                  r|g}n- j        j                            t          |                    g}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                 V     t          |t                    r fd|D             S  |z  gS )Nc                     g | ]}|z  S rr   rr   ).0r   bs     rG   
<listcomp>zIDifferentialOperator.__mul__.<locals>._mul_dmp_diffop.<locals>.<listcomp>   s    333!A333rI   )rb   list)r   listofothers   ` rG   _mul_dmp_diffopz5DifferentialOperator.__mul__.<locals>._mul_dmp_diffop   s<    +t,, 43333{3333O$$rI   r   c                    j         j        j        g}g }t          | t                    rB| D ]>}|                    |           |                    |                                           ?nv|                    j         j                            |                      |                    j         j                            |                                                      t          ||          S rB   )	rv   rV   r_   rb   r   appenddiffr{   
_add_lists)r   sol1sol2r   rd   s       rG   
_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)))rI   r8   )r}   rb   r^   rv   rV   rz   r{   r   ranger~   r   )rd   rk   
listofselfr   r   rQ   r   r   s   `       rG   __mul__zDifferentialOperator.__mul__   s    _
e122 	H*KKt{/566 	H 'KK;+66wu~~FFGK	% 	% 	%
 ojm[99	* 	* 	* 	* 	* q#j//** 	O 	OA$*[11KS//*Q-"M"MNNCC#C555rI   c                    t          t                    sst          | j        j        j                  s,| j        j                            t                              fd| j        D             }t          || j                  S d S )Nc                     g | ]}|z  S rr   rr   )r   r   rk   s     rG   r   z1DifferentialOperator.__rmul__.<locals>.<listcomp>  s    666519666rI   )rb   r^   rv   rV   rz   r{   r   r}   )rd   rk   rQ   s    ` rG   __rmul__zDifferentialOperator.__rmul__  s    %!566 	:eT[%5%;<< F)55gennEE6666do666C'T[999	: 	:rI   c                    t          |t                    r/t          | j        |j                  }t          || j                  S | j        }t          || j        j        j                  s.| j        j                            t          |                    g}n|g}|d         |d         z   g|dd          z   }t          || j                  S )Nr   r8   )	rb   r^   r   r}   rv   rV   rz   r{   r   )rd   rk   rQ   	list_self
list_others        rG   __add__zDifferentialOperator.__add__  s    e122 	:T_e.>??C'T[999O	%!1!788 	! K-99'%..IIJJJJ|jm+,y}<#C555rI   c                     | d|z  z   S Nrr   rj   s     rG   __sub__zDifferentialOperator.__sub__)  s    rUl""rI   c                     d| z  |z   S r   rr   rj   s     rG   __rsub__zDifferentialOperator.__rsub__,  s    d{U""rI   c                     d| z  S r   rr   rd   s    rG   __neg__zDifferentialOperator.__neg__/      DyrI   c                 &    | t           j        |z  z  S rB   r   Onerj   s     rG   __truediv__z DifferentialOperator.__truediv__2      quu}%%rI   c                 T   |dk    r| S t          | j        j        j        g| j                  }|dk    r|S | j        | j        j        j        k    r=| j        j        j        g|z  | j        j        j        gz   }t          || j                  S | }	 |dz  r||z  }|dz  }|sn||z  }|S )Nr8   r   T   )r^   rv   rV   r`   r}   rU   r_   )rd   nresultrQ   rx   s        rG   __pow__zDifferentialOperator.__pow__5  s    66K%t{'7';&<dkJJ66M?dk=HHH;#()!+t{/?/C.DDC'T[999	1u !!GA FA	 rI   c                    | j         }d}t          |          D ]\  }}|| j        j        j        k    r| j        j                            |          }|dk    r|dt          |          z   dz   z  }Y|r|dz  }|dk    r&|dt          |          z   d| j        j        z  z   z  }|dt          |          z   dz   d| j        j        z  z   t          |          z   z  }|S )	N r   ()z + r8   z)*%sz*%s**)r}   ry   rv   rV   r_   r|   r2   ra   )rd   r}   	print_strr   r   s        rG   rg   zDifferentialOperator.__str__I  s    _
	j)) 	[ 	[DAqDK$))) ))!,,AAvvS477]S00	 #U"	AvvS477]Vdk6L-MMM	tAww,w9O/PPSWXYSZSZZZIIrI   c                      t          |t                    r  j        |j        k    o j        |j        k    S  j        d         |k    o't	           fd j        dd          D                       S )Nr   c              3   >   K   | ]}|j         j        j        u V  d S rB   rv   rV   r_   r   r   rd   s     rG   	<genexpr>z.DifferentialOperator.__eq__.<locals>.<genexpr>i  s0      HHqT[%**HHHHHHrI   r8   )rb   r^   r}   rv   allrj   s   ` rG   rl   zDifferentialOperator.__eq__d  s    e122 	/?e&66 /;%,./q!U* IHHHHDOABB4GHHHHH	IrI   c                     | j         j        }|t          |                    | j        d                   | j                  v S )zH
        Checks if the differential equation is singular at x0.
        r   )rv   rV   r/   r|   r}   rx   )rd   x0rV   s      rG   is_singularz DifferentialOperator.is_singulark  s8    
 {U4==)<==tvFFFFrI   N)rm   rn   ro   rp   _op_priorityre   r   r   r   __radd__r   r   r   r   r   rg   rq   rl   r   rr   rI   rG   r^   r^      s        ! !F L. . .<,6 ,6 ,6\: : :6 6 6 H# # ## # #  & & &  (  2 HI I IG G G G GrI   r^   c                       e Zd ZdZdZd'dZd ZeZd Zd Z	d	 Z
d
 Zd Zd(dZd Zd Zd ZeZd Zd Zd Zd Zd Zd Zd Zd)dZd)dZd*dZd Zd+d Zd! Zd" Zd,d#Z d$ Z!d-d%Z"d& Z#dS ).HolonomicFunctiona
  
    A Holonomic Function is a solution to a linear homogeneous ordinary
    differential equation with polynomial coefficients. This differential
    equation can also be represented by an annihilator i.e. a Differential
    Operator ``L`` such that :math:`L.f = 0`. For uniqueness of these functions,
    initial conditions can also be provided along with the annihilator.

    Explanation
    ===========

    Holonomic functions have closure properties and thus forms a ring.
    Given two Holonomic Functions f and g, their sum, product,
    integral and derivative is also a Holonomic Function.

    For ordinary points initial condition should be a vector of values of
    the derivatives i.e. :math:`[y(x_0), y'(x_0), y''(x_0) ... ]`.

    For regular singular points initial conditions can also be provided in this
    format:
    :math:`{s0: [C_0, C_1, ...], s1: [C^1_0, C^1_1, ...], ...}`
    where s0, s1, ... are the roots of indicial equation and vectors
    :math:`[C_0, C_1, ...], [C^0_0, C^0_1, ...], ...` are the corresponding initial
    terms of the associated power series. See Examples below.

    Examples
    ========

    >>> from sympy.holonomic.holonomic import HolonomicFunction, DifferentialOperators
    >>> from sympy import QQ
    >>> from sympy import symbols, S
    >>> x = symbols('x')
    >>> R, Dx = DifferentialOperators(QQ.old_poly_ring(x),'Dx')

    >>> p = HolonomicFunction(Dx - 1, x, 0, [1])  # e^x
    >>> q = HolonomicFunction(Dx**2 + 1, x, 0, [0, 1])  # sin(x)

    >>> p + q  # annihilator of e^x + sin(x)
    HolonomicFunction((-1) + (1)*Dx + (-1)*Dx**2 + (1)*Dx**3, x, 0, [1, 2, 1])

    >>> p * q  # annihilator of e^x * sin(x)
    HolonomicFunction((2) + (-2)*Dx + (1)*Dx**2, x, 0, [0, 1])

    An example of initial conditions for regular singular points,
    the indicial equation has only one root `1/2`.

    >>> HolonomicFunction(-S(1)/2 + x*Dx, x, 0, {S(1)/2: [1]})
    HolonomicFunction((-1/2) + (x)*Dx, x, 0, {1/2: [1]})

    >>> HolonomicFunction(-S(1)/2 + x*Dx, x, 0, {S(1)/2: [1]}).to_expr()
    sqrt(x)

    To plot a Holonomic Function, one can use `.evalf()` for numerical
    computation. Here's an example on `sin(x)**2/x` using numpy and matplotlib.

    >>> import sympy.holonomic # doctest: +SKIP
    >>> from sympy import var, sin # doctest: +SKIP
    >>> import matplotlib.pyplot as plt # doctest: +SKIP
    >>> import numpy as np # doctest: +SKIP
    >>> var("x") # doctest: +SKIP
    >>> r = np.linspace(1, 5, 100) # doctest: +SKIP
    >>> y = sympy.holonomic.expr_to_holonomic(sin(x)**2/x, x0=1).evalf(r) # doctest: +SKIP
    >>> plt.plot(r, y, label="holonomic function") # doctest: +SKIP
    >>> plt.show() # doctest: +SKIP

    rt   r   Nc                 >    || _         || _        || _        || _        dS )ap  

        Parameters
        ==========

        annihilator:
            Annihilator of the Holonomic Function, represented by a
            `DifferentialOperator` object.
        x:
            Variable of the function.
        x0:
            The point at which initial conditions are stored.
            Generally an integer.
        y0:
            The initial condition. The proper format for the initial condition
            is described in class docstring. To make the function unique,
            length of the vector `y0` should be equal to or greater than the
            order of differential equation.
        N)y0r   annihilatorrx   )rd   r   rx   r   r   s        rG   re   zHolonomicFunction.__init__  s%    , &rI   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_condrc   r   r2   rx   r   r   )rd   str_sols     rG   rg   zHolonomicFunction.__str__  s    !! 	 	=@AQ=R=R=R=RTVd47mmmmT$']]]]<GG	 699I5J5J5J5JTVG rI   c                 ^  	
 | j         j        j        	|j         j        j        
	j        }
j        }	
k    r| |fS |                    |                              | j                  }t          |t          | j         j        j	                            \  }}	fd| j         j
        D             }
fd|j         j
        D             }t          ||          }t          ||          }t          || j        | j        | j                  }t          ||j        |j        |j                  }||fS )z^
        Unifies the base polynomial ring of a given two Holonomic
        Functions.
        c                 :    g | ]}                     |          S rr   r|   )r   r   R1s     rG   r   z+HolonomicFunction.unify.<locals>.<listcomp>  s#    DDD1ADDDrI   c                 :    g | ]}                     |          S rr   r   )r   r   R2s     rG   r   z+HolonomicFunction.unify.<locals>.<listcomp>  s#    EEE1AEEErI   )r   rv   rV   domunifyold_poly_ringrx   rY   rc   ra   r}   r^   r   r   r   )rd   rk   dom1dom2R	newparent_r   r   r   r   s            @@rG   r   zHolonomicFunction.unify  s     $)%*vv88%= ZZ,,TV44,QD4D4K4V0W0WXX	1DDDD(8(CDDDEEEE(9(DEEE#D)44#D)44 tvtw@@ uw%(CCd|rI   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)rb   r   dictr   r   s    rG   is_singularicsz HolonomicFunction.is_singularics   s@     dgt$$ 	4&& 	5	 	rI   c                 *    t          | j                  S )z@
        Checks if the function have initial condition.
        )boolr   r   s    rG   r   z!HolonomicFunction._have_init_cond  s     DG}}rI   c                 |   t          | j                  d         | j                 }t          | j                  dk    rwt                    k    rfdk    rbt                    t          j        gz  }|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   r8   c                 @    g | ]\  }}|t          |z             z  S rr   r   )r   r   r   as      rG   r   z9HolonomicFunction._singularics_to_ord.<locals>.<listcomp>   s.    AAADAq1yQ'''AAArI   N)r   r   r~   intr   Zerory   r   r   rx   r   )rd   r   r   r   s      @rG   _singularics_to_ordz%HolonomicFunction._singularics_to_ord  s     MM!GAJtw<<1c!ffQAA&ABAAAAIaLLAAAAB$T%5tvtwKKK rI   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 ]z}|t          |j                  k    r|	                    |j                   5|	                    |                    |j        |                                                              {|	                    |           t          |t          |          |dz   f|                                          }t          j        |dz   df|          }t%          ||          }|j        r\|dz  }||	d         z  }|		                    |           ||
d         z  }|
	                    |           |	|
z   }g }|D ]}g }t          |dz             D ]z}|t          |j                  k    r|	                    |j                   5|	                    |                    |j        |                                                              {|	                    |           t          |t          |          |dz   f|                                          }t          j        |dz   df|          }t%          ||          }|j        \|                                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   r8   Fnegativec                     g | ]
\  }}||z   S rr   rr   r   r   r   s      rG   r   z-HolonomicFunction.__add__.<locals>.<listcomp>  s     4441a!e444rI   r   Tc                 8    g | ]\  }}|t          |          z  S rr   r   r   r   r   s      rG   r   z-HolonomicFunction.__add__.<locals>.<listcomp>  '    CCC11y||#CCCrI   c                 8    g | ]\  }}|t          |          z  S rr   r   r   s      rG   r   z-HolonomicFunction.__add__.<locals>.<listcomp>  '    DDD11y||#DDDrI   c                     g | ]
\  }}||z   S rr   rr   r   s      rG   r   z-HolonomicFunction.__add__.<locals>.<listcomp>  s     ===41aQ===rI   )#r   rv   rV   r   r   max	get_fieldrU   r   r   r~   r}   r_   newto_listr1   rK   zerosrR   is_zero_matrixflat
_normalizer   r   rx   r   r   
_extend_y0zipr   
change_icsry   r   r   r   )rd   rk   r   r   deg1deg2dimr   Krowsself	rowsothergenr   diff1diff2rowrF   exprprL   rQ   r   y1y2r   selfat0otherat0selfatx0	otheratx0_y0s                                 rG   r   zHolonomicFunction.__add__$  st   "'5+<+C+HHH::e$$DAqq5L% &$oo#(KKMM$%&'	%9 sTz"" 	# 	#A8B<'EOOE""""sTz"" 	$ 	$A9R=(EU####"  	 	DA37^^ B BDO,,,,HHQV$$$$HHQUU4?1#5#=#=#?#?@@AAAA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 F FAC0000((((tq'9'A'A'C'C!D!DEEEE QS3q5 1155??AAA"(#a%Q77G(G44C1   	5: hhjj#'D.)#t/677d&')9)@5QQQ$$&& 	25+@+@+B+B 	2$S$&111   E))e.B.B.D.D.M.M w%(""  ci00sy1144B444(dfdgrBBB &22155G(44Q77Hw!||G|H|e..q1111x1}}W}X}q))E11'33DG<<H)55dg>>I 8I 8e..tw7777??58,,u447eh$S$&111   E))e.B.B.D.D.L.LCC	$'0B0BCCCC&#BBB  ""d**u/C/C/E/E/N/NDD	%(0C0CDDDCB&#BB  ""d**u/C/C/E/E/M/MBB  	 	A Bww==3r!ube+<+<===111 	 	A{{11 dfdgr:::rI   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   r8   z1logarithmic terms in the series are not supported__iter__z4Definite integration for singular initial conditions   r   FN)r   rv   rU   r   r   	integrater   ry   r   r   r   NotImplementedErrorhasattrr   rx   r   r   r~   to_exprr=   r<   subsrb   r   r3   evalf	is_Number)rd   limitsr  DrF   r   r   cc2r   cjr   r   r   definiteindefinite_integralindefinite_exprloweruppers
indefinites                        rG   r  zHolonomicFunction.integrate  s   & #7   D((((**A >{{6H{=== BW  GAJ&q\\ 	5 	5EArQww		!&)))) Qa12efff		"qQ||"344441q5		vz** b)*`aaa$T%5%94647BOOO ##%% 	C Z()9A)=tvtwQRQWPXYYY$T%5%946BBB
 6:&& 		6{{aF1I$7$7W1I1I HfX
dg/0@10DdfdgWYZZ 	'&& 77'"5"="="?"?')<= ' ' '"&'  5',,TVQ77eS)) =+11$&!<<E+11!44DF{{11()9A)=tvr2NNN1 %" 9+00;;E!%-- A / 5 5dfa @ @/55a88Eu}$ ;;$T%5%9461bIII qTT^ 
	W	W%d&6&:DFA 		 VVDFA..
!*c22 .%%77461---')<= W W W()9A)=tvq"MMSSTUVVVVVW !!1A!5tv>>>s,   8I I#"I#<A"P: P: :AR ?R c                 d  	
 |                     dd           |rg|d         | j        k    rt          j        S t	          |          dk    r7| }t          |d                   D ]}|                    |d                   }|S | j        }|j        d         |j	        j
        j        k    r|j        dk    rt          j        S |j        d         |j	        j
        j        k    rt          |j        dd         |j	                  }|                                 rV|                                 dk    r)t!          || j        | j        | j        dd                   S t!          || j                  S t!          || j                  S |j	        j
        }|                                		fd|j        D             

fd	
dd         D             }|                    d	j                   t+          |	          }t-          |	j        	j        g          }t1          |dd         | j        j	        d
          }|                                 r|                                 dk    rt!          || j                  S t3          | |j        dz             dd         }t!          || j        | j        |          S )aK  
        Differentiation of the given Holonomic function.

        Examples
        ========

        >>> from sympy.holonomic.holonomic import HolonomicFunction, DifferentialOperators
        >>> from sympy import ZZ
        >>> from sympy import symbols
        >>> x = symbols('x')
        >>> R, Dx = DifferentialOperators(ZZ.old_poly_ring(x),'Dx')
        >>> HolonomicFunction(Dx**2 + 1, x, 0, [0, 1]).diff().to_expr()
        cos(x)
        >>> HolonomicFunction(Dx - 2, x, 0, [1]).diff().to_expr()
        2*exp(2*x)

        See Also
        ========

        integrate
        evaluateTr   r   r8   NFc                 ^    g | ])}                     |                                          *S rr   r   r   r   r   r   s     rG   r   z*HolonomicFunction.diff.<locals>.<listcomp>m  s-    >>>!155%%>>>rI   c                 &    g | ]}|d          z  S r   rr   )r   r   seq_dmfs     rG   r   z*HolonomicFunction.diff.<locals>.<listcomp>p  s!    333!q71:~333rI   r   )
setdefaultrx   r   r   r~   r   r   r   r}   rv   rV   r_   r   r^   r   r   r   r   r   r   insert_derivate_diff_eqr   r`   r   r   )rd   argskwargsrQ   r   annr   rhsr   r   r*  s            @@rG   r   zHolonomicFunction.diff4  s   , 	*d+++ 	Aw$&  vTatAw , ,A((47++CC
 >!
 444a6M ^A#*/"666&s~abb'93:FFC##%% 6&&((E11,S$&$'47122;OOO(df555(df555 JOKKMM>>>>s~>>> 4333wqrr{333

1af  Q'' qvquo..QRR$"2"9EJJJ##%% 	2)<)<)>)>$)F)F$S$&111ci!m,,QRR0 dfdgr:::rI   c                     | j         |j         k    s| j        |j        k    rdS |                                 r4|                                r | j        |j        k    o| j        |j        k    S dS )NFT)r   rx   r   r   r   rj   s     rG   rl   zHolonomicFunction.__eq__  so    u000DFeg4E4E5!! 	?e&;&;&=&= 	?7eh&>47eh+>>trI   c           	            j         }t          t                    st                                         j                  rt          d                                           s S t           |j	                  } fd|D             t          | j         j
                  S  j         j        j        j         j        j        k    r                               \  z  S j         }|j	        |j	        |j        j        }|                                fd|j        D             fd|j        D             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          }
t+          |	|
          }|j        rRt!          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&t1                                               <                                          j                           <   Ìt!          dz             D ]c                  j        rt!                    D ]-         xx         |                           z  z  cc<   .j                 <   dt!                    D ]b                  d	k    rt!                    D ]-         xx         |                           z  z  cc<   .j                 <   c|                    fdt!                    D                        t%          |t;          |          z  f                                          }	t+          |	|
          }|j        Rt=          |                                 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tC          t;          |          t;          |                              D ]Њfdt!          dz             D             }t!          dz             D ]9t!          dz             D ]$}|z   k    rtE                    |         |<   %: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 tK           j&                  D             }tN          j(        |ij&         n                                  dk    rL                                 dk    r4d tK          j&                  D             } j&        tN          j(        |i n>                                  dk    r&                                 dk    r j&        j&         i }D ] D ]tC          t;                             t;                                        } fdt!          |          D             }z   |vr	||z   <   fd tS          ||z                      D             |z   <   t          | j         j
        |          S )Nz> Can't multiply a HolonomicFunction and expressions/functions.c                 T    g | ]$}t          j        |j                  z  j        %S rr   )r0   r   rx   rep)r   r   rk   rd   s     rG   r   z-HolonomicFunction.__mul__.<locals>.<listcomp>  s/    @@@48Atv&&.3@@@rI   c                 ^    g | ])}                     |                                          *S rr   r&  r   r   r   s     rG   r   z-HolonomicFunction.__mul__.<locals>.<listcomp>  s-    EEEAQUU199;;''EEErI   c                 ^    g | ])}                     |                                          *S rr   r&  r7  s     rG   r   z-HolonomicFunction.__mul__.<locals>.<listcomp>  s-    GGGQaeeAIIKK((GGGrI   c                 4    g | ]}|                   z  S rr   rr   )r   r   r   r   s     rG   r   z-HolonomicFunction.__mul__.<locals>.<listcomp>  s(    CCCQYq\MIaL0CCCrI   c                 4    g | ]}|                   z  S rr   rr   )r   r   r   r   s     rG   r   z-HolonomicFunction.__mul__.<locals>.<listcomp>  s(    FFFjm^jm3FFFrI   c                 L    g | ] }fd t          dz             D             !S )c                     g | ]	}j         
S rr   )r_   r'  s     rG   r   z8HolonomicFunction.__mul__.<locals>.<listcomp>.<listcomp>  s    333af333rI   r8   r   )r   r   r   r   s     rG   r   z-HolonomicFunction.__mul__.<locals>.<listcomp>  s8    JJJ3333eAEll333JJJrI   r8   r   c                 P    g | ]"}t                    D ]}|         |         #S rr   r=  r   r   r   r   	coeff_muls      rG   r   z-HolonomicFunction.__mul__.<locals>.<listcomp>  s4    QQQaQQ1Yq\!_QQQQrI   r   c                 P    g | ]"}t                    D ]}|         |         #S rr   r=  r?  s      rG   r   z-HolonomicFunction.__mul__.<locals>.<listcomp>  s8    $Y$Y$YPUVWPXPX$Y$Y1Yq\!_$Y$Y$Y$YrI   Fr   c                 H    g | ]}d  t          dz             D             S )c                     g | ]}d S r)  rr   r   r   s     rG   r   z8HolonomicFunction.__mul__.<locals>.<listcomp>.<listcomp>  s    666Aa666rI   r8   r=  )r   r   r   s     rG   r   z-HolonomicFunction.__mul__.<locals>.<listcomp>  s2    MMM166q1u666MMMrI   Tc                 8    g | ]\  }}|t          |          z  S rr   r   r   s      rG   r   z-HolonomicFunction.__mul__.<locals>.<listcomp>  r   rI   c                 8    g | ]\  }}|t          |          z  S rr   r   r   s      rG   r   z-HolonomicFunction.__mul__.<locals>.<listcomp>  r   rI   c           	          g | ]=t          fd t          dz             D             t          j                  >S )c              3   X   K   | ]$}         |                  |z
           z  V  %d S rB   rr   )r   r   r   r   r   r  r  s     rG   r   z7HolonomicFunction.__mul__.<locals>.<listcomp>.<genexpr>!  s<      HHa"Q%(RU1q5\1HHHHHHrI   r8   start)sumr   r   r   )r   r   r   r   r  r  s    @rG   r   z-HolonomicFunction.__mul__.<locals>.<listcomp>!  sk     : : :+, HHHHHHHH5Q<<HHH v' ' ' : : :rI   c                     g | ]
\  }}||z   S rr   rr   r   s      rG   r   z-HolonomicFunction.__mul__.<locals>.<listcomp>&  s      E E E41aQ E E ErI   )*r   rb   r   r   hasrx   r  r   r   r   r   rv   rV   r   r   r}   r   r`   r1   rK   r   rR   r   rz   DMFdiffr   is_zeror_   r   r~   r   r   r   minr   r   r   ry   r   r   r   r   )!rd   rk   ann_selfr   	ann_otherr   self_red	other_redlin_sys_elementslin_syshomo_sysrQ   sol_anny0_selfy0_othercoeffkr  r  r	  r
  r  r  r   r   r   r@  r   r   r   r   r  r  s!   ``                     @@@@@@@@@@rG   r   zHolonomicFunction.__mul__  s
   #%!233 
	DENNEyy   l)*jkkk'')) D(.11B@@@@@R@@@B$XtvtwCCC"'5+<+C+HHH::e$$DAqq5L%	NOO KKMMEEEE1DEEE	GGGG)2FGGG
 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/1*E*E	!Q*3A,q/*>*>tv*F*F	!QG 1q5\\ ) )Q<?* q F FAaLOOOy|il1o'EEOOOO"#&	!Q 1XX ) )Q<?a''q E EAaLOOOx{Yq\!_'DDOOOO"#&	!Q##$Y$Y$Y$Y$YeAhh$Y$Y$YZZZ"#3c:J6K6KQqS5QSTUU__aaG((;;C?   	<B SXXZZ)9)@5QQQ$$&& 	65+@+@+B+B 	6$Wdf555  E))e.B.B.D.D.M.M w%("" %T7=99%eW];;aj8A;./ q#c'llCMM"B"BCC # #AMMMMa!eMMME"1q5\\ = =!&q1u = =A 1uzz.6q!nna= C"1q5\\ I I!&q1u I IA58A;
#:Xa[#HHCCI IIcNNNN($&$'2FFF &22155G(44Q77Hw!||G|H|e..q1111x1}}W}X}q))E11'33DG<<H)55dg>>I 8I 8e..tw7777??58,,u447eh$Wdf555   E))e.B.B.D.D.L.LCC	$'0B0BCCCC&#BBB  ""d**u/C/C/E/E/N/NDD	%(0C0CDDDCB&#BB  ""d**u/C/C/E/E/M/MBB 	F 	FA F FBqE

C1JJ//: : : : : : :05a: : :1u{{ !Bq1uII E E3q"QU)3D3D E E EBq1uIIF !$&$'2>>>rI   c                     | |dz  z   S r   rr   rj   s     rG   r   zHolonomicFunction.__sub__+  s    ebj  rI   c                     | dz  |z   S r   rr   rj   s     rG   r   zHolonomicFunction.__rsub__.  s    by5  rI   c                     d| z  S r   rr   r   s    rG   r   zHolonomicFunction.__neg__1  r   rI   c                 &    | t           j        |z  z  S rB   r   rj   s     rG   r   zHolonomicFunction.__truediv__4  r   rI   c                 n   | 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          | j         j        j        }t          || j        t          j        t          j        g          }	|dk    r|	S | }
	 |dz  r|	|
z  }	|dz  }|sn|
|
z  }
|	S )Nr8   r   c                 D    g | ]}j                             |          S rr   )rV   r|   )r   r   rv   s     rG   r   z-HolonomicFunction.__pow__.<locals>.<listcomp>F  s)    ===q6;''**===rI   z&Negative Power on a Holonomic FunctionTr   )r   r   rv   r   r   r}   r0   r   rx   r5  r^   r   r   r?   rU   r   r   r   )rd   r   r0  r   p0p1rQ   ddr\   r   rx   rv   s              @rG   r   zHolonomicFunction.__pow__7  sY   !Q&&"CZFw47mmA&!+,"B"B(2tv&&*/B====RH===C%c622B$R"===q55#$LMMM$8"2tvqvw??66M	1u !!GA FA	 rI   c                 H    t          d | j        j        D                       S )zF
        Returns the highest power of `x` in the annihilator.
        c              3   >   K   | ]}|                                 V  d S rB   degreerD  s     rG   r   z+HolonomicFunction.degree.<locals>.<genexpr>]  s*      CC!188::CCCCCCrI   )r   r   r}   r   s    rG   ri  zHolonomicFunction.degreeY  s'     CCt'7'BCCCCCCrI   c                 &     j         j        } j         j        }                     j                  } j         j        t                    D ]P\  }}t          | j         j        j        j	                  r' j         j        j        
                    |          |<   Q|                              j        i           fdt          |          D             }	d t          |          D             }
t          j        |
d<   |
g}t          d t          |          D             g                                          }	  fd|
D             }t          |dz
            D ]}||dz   xx         |
|         |z  z  cc<   t          |          D ]$}||xx         |
d         |	|         z  |z  z  cc<   %|}
|                    |
           t          |                                                              |          \  }}|j        durnt)          |          d         }|                    |d          }t+          |dd	         |d
          }|r#t-          | j        |d         |d                   S t-          | j                  S )a`  
        Returns function after composition of a holonomic
        function with an algebraic function. The method cannot compute
        initial conditions for the result by itself, so they can be also be
        provided.

        Examples
        ========

        >>> from sympy.holonomic.holonomic import HolonomicFunction, DifferentialOperators
        >>> from sympy import QQ
        >>> from sympy import symbols
        >>> x = symbols('x')
        >>> R, Dx = DifferentialOperators(QQ.old_poly_ring(x),'Dx')
        >>> HolonomicFunction(Dx - 1, x).composition(x**2, 0, [1])  # e^(x**2)
        HolonomicFunction((-2*x) + (1)*Dx, x, 0, [1])
        >>> HolonomicFunction(Dx**2 + 1, x).composition(x**2 - 1, 1, [1, 0])
        HolonomicFunction((4*x**3) + (-1)*Dx + (x)*Dx**2, x, 1, [1, 0])

        See Also
        ========

        from_hyper
        c                 \    g | ](}|                              j        i           z  )S rr   )r  rx   )r   r   r  r}   rF   rd   s     rG   r   z1HolonomicFunction.composition.<locals>.<listcomp>  s9    JJJ1A##TVDM222Q6JJJrI   c                 &    g | ]}t           j        S rr   r   r   rD  s     rG   r   z1HolonomicFunction.composition.<locals>.<listcomp>  s    +++Q!&+++rI   r   c                 &    g | ]}t           j        S rr   rm  rD  s     rG   r   z1HolonomicFunction.composition.<locals>.<listcomp>  s    888!qv888rI   Tc                 D    g | ]}|                     j                  S rr   )r   rx   )r   r  rd   s     rG   r   z1HolonomicFunction.composition.<locals>.<listcomp>  s%    :::a166$&>>:::rI   r8   r   NFr   )r   rv   r   r   rx   r}   ry   rb   rV   rz   r|   r  r   r   r   r)   rK   r   gauss_jordan_solver   r   r   r   )rd   r  r.  r/  r   r   r   r   r   r  coeffssystemhomogeneouscoeffs_nextrQ   taustaur}   rF   s   ``               @@rG   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---rI   Tc           
         | 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|v rQt-          fd	|                                D             t0          j        
          }|                    |           W|                    t0          j                   wt7          ||          }|j        }t;          |j                            |j        d                   d          }|                                }|r"t)          |          dz   }t)          ||          }||z  }t?          | |          }d t          |          D             }t          |          |k     rt!          |          D ] }t0          j        }|D ]|d         z   dk     rt0          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  }|                    |           "tC          |g|R  }tE          |tF                    rt!          t          |          |          D ]b}||vrt          d|z            ||<   ||         |v r"|                    |||                             G|                    ||                    c|rtI          ||          |fgS tI          ||          gS t!          t          |          |          D ]l}||vrt          d|z            ||<   d}|D ]/||         v r#|                    ||                             d}0|s|                    ||                    m|rtI          ||          |fgS tI          ||          gS )aG  
        Finds recurrence relation for the coefficients in the series expansion
        of the function about :math:`x_0`, where :math:`x_0` is the point at
        which the initial condition is stored.

        Explanation
        ===========

        If the point :math:`x_0` is ordinary, solution of the form :math:`[(R, n_0)]`
        is returned. Where :math:`R` is the recurrence relation and :math:`n_0` is the
        smallest ``n`` for which the recurrence holds true.

        If the point :math:`x_0` is regular singular, a list of solutions in
        the format :math:`(R, p, n_0)` is returned, i.e. `[(R, p, n_0), ... ]`.
        Each tuple in this vector represents a recurrence relation :math:`R`
        associated with a root of the indicial equation ``p``. Conditions of
        a different format can also be provided in this case, see the
        docstring of HolonomicFunction class.

        If it's not possible to numerically compute a initial condition,
        it is returned as a symbol :math:`C_j`, denoting the coefficient of
        :math:`(x - x_0)^j` in the power series about :math:`x_0`.

        Examples
        ========

        >>> from sympy.holonomic.holonomic import HolonomicFunction, DifferentialOperators
        >>> from sympy import QQ
        >>> from sympy import symbols, S
        >>> x = symbols('x')
        >>> R, Dx = DifferentialOperators(QQ.old_poly_ring(x),'Dx')
        >>> HolonomicFunction(Dx - 1, x, 0, [1]).to_sequence()
        [(HolonomicSequence((-1) + (n + 1)Sn, n), u(0) = 1, 0)]
        >>> HolonomicFunction((1 + x)*Dx**2 + Dx, x, 0, [0, 1]).to_sequence()
        [(HolonomicSequence((n**2) + (n**2 + n)Sn, n), u(0) = 0, u(1) = 1, u(2) = -1/2, 2)]
        >>> HolonomicFunction(-S(1)/2 + x*Dx, x, 0, {S(1)/2: [1]}).to_sequence()
        [(HolonomicSequence((n), n), u(0) = 1, 1/2, 1)]

        See Also
        ========

        HolonomicFunction.series

        References
        ==========

        .. [1] https://hal.inria.fr/inria-00070025/document
        .. [2] https://www3.risc.jku.at/publications/download/risc_2244/DIPLFORM.pdf

        r   )lbr   TintegerSnr8   c                     g | ]
}|d          S r)  rr   rD  s     rG   r   z1HolonomicFunction.to_sequence.<locals>.<listcomp>  s    '''A1Q4'''rI   c              3   h   K   | ],\  }}|d          k    |                     z
            V  -dS r   Nr  r   r\  vr   r  r   s      rG   r   z0HolonomicFunction.to_sequence.<locals>.<genexpr>  sR       C C#q!!		 FF1a%i008A			C CrI   rI  r   Zfilterc                 8    g | ]\  }}|t          |          z  S rr   r   r   s      rG   r   z1HolonomicFunction.to_sequence.<locals>.<listcomp>  s'    99941aa)A,,999rI   C_%sF)%r   shift_xto_sequencer   r   
_frobeniusr   rv   rV   r   r;   r   ry   r}   
all_coeffsr~   r   r|   r   rP  r   ri  rK  itemsr   r   r   r:   r   r/   keysr   r  r7   rb   r   r9   )rd   ry  dict1r   r   r   r   	listofdmpri  r\  r[  rQ   keylistr   
smallest_ndummyseqsunknownstempr   	all_rootsmax_rootr   u0eqsoleqsr!  r   r  r   s                              @@@rG   r  zHolonomicFunction.to_sequence  sk   h 7a<<<<((44666 ''00 	*??b?)))3%%%%*."3#4#4Q#7#7>>1 d.9:: 	Q 	QDAqI^^a'F6A:&& 	Q 	Q!&1*-A::E1:&&1q5!*%%%#,,u*=*=1q519a@P@P*PQ%%%%),e)<)<r!a%!)Q?O?O)OE1q5!*%%	Q '''''GG V^
 ueai(( 	# 	#AG|| C C C C C C',{{}}C C C!") ) ) 

4    

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

2 3****F&$'' 4s2ww.. 	- 	-A$*619$5$5q	ayF**		&"34444 		&),,,, F.sB77DEE)#r22333r77E** ) )F?? &vqy 1 1F1I ! !AayA~~		!F1I,///  )IIfQi((( 	>&sB//<==!#r**++rI   c                   *+,- |                                  }g }g }t          |                                          D ]b}|j        r |                    |g||         z             )|                                \  }}|                    |||fg||         z             c|                    d            |                    d            |                                 g }|D ]v}t          |          dk    r|                    |g           ,|D ]1*t          *d         |z
            r*                    |            n2|                    |g           wt          d |D                       }	t          d |D                       }
t          d |D                       }|                                 dk    rug }t          | j                                                  D ]K}t          |                                          D ]'*t          *|          r|                    |           (Ln|
r|rt          |          g}n|	rd	 |D             d
 |D             z   }nu|sd |D             }nf|
sd|                                 r#t!          | j        d                   j        dk    rt          |          g}nd |D             }t          |          g}t%          dd          ,| j        j        j        j        }t/          |                    ,          d          \  }}g }t3          d          }|D ]}i }t5          | j        j                  D ]\  }**                                }t          |          dz
  }t;          |dz             D ]}|||z
           }|dk    r||z
  ||z
  f|v rF|||z
  ||z
  fxx         |                    |          t?          ,|z
  dz   |z   |          z  z  cc<   f|                    |          t?          ,|z
  dz   |z   |          z  |||z
  ||z
  f<   g }d |D             }t          |          +tA          |          }tA          d |D                       }t          d |D                       }+|z   }i }g }g } t;          +|dz             D ]v**|v rQtC          *+,fd|"                                D             t           j#                  }!|                    |!           W|                    t           j#                   wtI          ||          }|j%        }"tM          |j                            |j        d                   ,d          }#|#                                }#|#r"tA          |#          dz   }$tA          |$|          }|"|z  }"g }%|                                 dk    r| j        |         }%n|                                 dk    r|dk    rtO          |          |k    rt          |          dk    rvtQ          | |"tO          |          z             -t          -          tO          |          k    r6-fdt;          tO          |          t          -                    D             }%t          |%          |"k     rt;          ||          D ]4}t           j#        }&|D ]*|*d         z   dk     rt           j#        ||*d         z   <   n|*d         z   t          |%          k     r|%|*d         z            ||*d         z   <   nj|*d         z   |vr]tS          |          d|*d         z   z  z   }'t%          |'          ||*d         z   <   |                     ||*d         z                       *d         |k    r1|&|*         *                    ,|          ||*d         z            z  z  }&|                    |&           6tW          |g| R  }(tY          |(tZ                    rt;          t          |%          |"          D ]t}||vr'tS          |          d|z  z   }'t%          |'          ||<   ||         |(v r"|%                    |(||                             Y|%                    ||                    u|r(|                    t]          ||%          ||f           |                    t]          ||%          |f           t;          t          |%          |"          D ]~}||vr'tS          |          d|z  z   }'t%          |'          ||<   d})|(D ]/*||         *v r#|%                    *||                             d})0|)s|%                    ||                    |r'|                    t]          ||%          ||f           n%|                    t]          ||%          |f           |dz  }|S )Nc                     | d         S )Nr8   rr   rx   s    rG   rH   z.HolonomicFunction._frobenius.<locals>.<lambda>j  
    !A$ rI   )keyc                     | d         S Nr   rr   r  s    rG   rH   z.HolonomicFunction._frobenius.<locals>.<lambda>k  r  rI   r   c              3   <   K   | ]}t          |          d k    V  dS r8   N)r~   rD  s     rG   r   z/HolonomicFunction._frobenius.<locals>.<genexpr>~  s,      33!#a&&A+333333rI   c              3   "   K   | ]
}|d k    V  dS r  rr   rD  s     rG   r   z/HolonomicFunction._frobenius.<locals>.<genexpr>  s&      ++Q!V++++++rI   c              3   4   K   | ]}t          |          V  d S rB   )r   rD  s     rG   r   z/HolonomicFunction._frobenius.<locals>.<genexpr>  s(      22qZ]]222222rI   Tc                     g | ]
}|d          S r)  rr   rD  s     rG   r   z0HolonomicFunction._frobenius.<locals>.<listcomp>  s    111qt111rI   c                     g | ]
}|d          S r)  rr   r   r   s     rG   r   z0HolonomicFunction._frobenius.<locals>.<listcomp>  s    4I4I4IaQqT4I4I4IrI   c                 8    g | ]}t          |          |k    |S rr   r   rD  s     rG   r   z0HolonomicFunction._frobenius.<locals>.<listcomp>  s#    CCCQs1vv{{q{{{rI   Fc                     g | ]
}|d k    |S r)  rr   rD  s     rG   r   z0HolonomicFunction._frobenius.<locals>.<listcomp>  s    777!QArI   r   rz  r|  Cr8   c                     g | ]
}|d          S r)  rr   rD  s     rG   r   z0HolonomicFunction._frobenius.<locals>.<listcomp>  s    +++qt+++rI   c              3   &   K   | ]}|d          V  dS r  rr   rD  s     rG   r   z/HolonomicFunction._frobenius.<locals>.<genexpr>  s&      --!1------rI   c              3   &   K   | ]}|d          V  dS r  rr   rD  s     rG   r   z/HolonomicFunction._frobenius.<locals>.<genexpr>  s&      ..1!A$......rI   c              3   h   K   | ],\  }}|d          k    |                     z
            V  -dS r  r  r  s      rG   r   z/HolonomicFunction._frobenius.<locals>.<genexpr>  sR        G  G#'1aAaDAII !"q!e) 4 4<EIII G  GrI   rI  r   r  r  c                 @    g | ]}|         t          |          z  S rr   r   )r   r   r   s     rG   r   z0HolonomicFunction._frobenius.<locals>.<listcomp>  s(    OOO1"Q%)A,,.OOOrI   z_%s)/	_indicialr   r  is_realextendas_real_imagsortr~   r   r   r   r   r   r   rP  r   r   	is_finiter   r   rv   rV   r   r;   r   ordry   r}   r  r   r|   r   r   rK  r  r   r:   r   r/   r   r   chrr  r7   rb   r   r9   ).rd   ry  indicialrootsrealscomplr   r   r   grpindependentallposallintrootstoconsiderposrootsr   r   r   finalsolcharr  r  r  ri  r\  r[  rQ   r  r   degree2r  r  r  r  r  r   r  r  r  r  letterr  r!  r   r  r   r   s.                                             @@@@rG   r  zHolonomicFunction._frobenius\  s
   ((++--.. 	= 	=Ay =aS=#334444~~''1q!Qi[=+;;<<<< 	


'''


'''

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

A3    adQh'' HHQKKKE 

A3 33s33333++U+++++22E22222   D(( OTW\\^^,, 2 2 !3!3!5!566 2 2A#Aq)) 2'..q11122
  	2 	2"5zzlOO 	211S1114I4I54I4I4IIOO 
	2CC%CCCOO 	2'')) 2Qtwqz]]-D-N-N#&u::, 87u777#&x==/3%%%%*."3#4#4Q#7#7>>13xx  @	 @	AE!$"2"=>> ] ]1LLNN	Y!+vz** 	] 	]A%fqj1Ezz Aq1u~..q1ua!en---#,,u2E2E1q5ST9WX=Z[H\H\2\]----14e1D1Dr!a%RS)VW-YZG[G[1[q1ua!en--	] C++U+++GLLELLE--u-----F.......GJFCH5%!),, ' '<<  G  G  G  G  G  G+0;;== G  G  G%&V- - -D JJt$$$$JJqv&&&& %S!,,C IEafoocnR.@AA1SQQQI!((I 7y>>A- :66
ZEB""$$,,WQZ$$&&%//AFFs1vv{{sSbOcOcghOhOhec!ffn55r77SVV##OOOOc!ffc"gg8N8NOOOB2www// # #AB" I Iqt8a<</0vF1qt8,,1XB///1!ad(|F1qt8,,!"QqTV!3!3%(YYQqT1B%BF/5f~~F1qt8,$OOF1qt8,<===Q4199%(--1"5"5q1Q4x8H"HHBJJrNNNN s.X...fd++ !"3r77E22 
1 
1F??%(YY%9F(.vF1I!!9..IIfVAY&78888 IIfQi0000 ! ):3)C)CQ
(STTT  ):3)C)CQ(GHHH s2ww.. - -A!$TUAX!5$*6NNq	A# % %!!9>>IIaq	l333 $A -		&),,, A!23!;!;Q
 KLLLL !23!;!;Q ?@@@AIDDrI      c                     |                                  }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nWt          |          dk    r6t          |d                   dk    r|d         d         |d         d         }n fd|D             S |t	                    z
  }t          |j                  dz
  }|j        j         j         j	        }|j        j
        }|j        j        j        }	|	                                fd|D             fdt                    D             t          |j                  |dz   |k     rgt          |dz   z
  |z
            D ]Mt!          fd	t                    D             t"          j        
          }
                    |
           N|rS t!          fdt)                    D             t"          j        
          }|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  r8   c                 <    g | ]}                     |           S ))_recur)seriesr   s     rG   r   z,HolonomicFunction.series.<locals>.<listcomp>X  s'    >>>aDKKqK))>>>rI   c                 ^    g | ])}                     |                                          *S rr   r&  r7  s     rG   r   z,HolonomicFunction.series.<locals>.<listcomp>b  s-    333aquuQYY[[!!333rI   c                 4    g | ]}|                   z  S rr   rr   )r   r   r\  seqs     rG   r   z,HolonomicFunction.series.<locals>.<listcomp>c  s(    222AAwQ222rI   c              3   n   K   | ]/}|z   d k    t          |                   |z            z  V  0dS r  )DMFsubs)r   r   r   rQ   subs     rG   r   z+HolonomicFunction.series.<locals>.<genexpr>i  sS       = = !Q! %SVQ//#a!e*<1;= =rI   rI  c              3   4   K   | ]\  }}|z   z  |z  V  d S rB   rr   )r   r   r   constantpowerrx   s      rG   r   z+HolonomicFunction.series.<locals>.<genexpr>p  s6      II$!Q1q=()A-IIIIIIrI   )r  rb   tupler~   r   r  
recurrencer   rx   r   r}   rv   rV   r   r   r   rK  r   r   r   ry   r4   r  )rd   r   coefficientr   r  r  lr   seq_dmpr   r[  serr   r  r   r\  r  rQ   r  rx   s   `           @@@@@@@@rG   r  zHolonomicFunction.series(  s   : >))++JJJj%(( 	?S__-A-A#AJMM
E** 	?s:!/C/C&qMM#AJJ__!!c*Q-&8&8A&=&=#Aq)JMM__!!c*Q-&8&8A&=&=&qM!,M#Aq)JJ>>>>:>>>>M"""
"!'FW'2!(-KKMM3333733322222q222:=!!q51991q519a!e,, " " = = = = = =%*1XX= = =DEFL L L

5!!!! 	JIIIII)C..III      	95Q]!3!334a888C7788Aq2v&&&
rI   c                   	
 | j         dk    r,|                     | j                                                   S | j        j        }| j        j        j        	| j        	j        }	j	        }	fd
t          d |D                       }dt          d|          t          d| j        j                  z   z  
fdt          fdt          |          D                       }t          |          D ]m\  }}|                                }t          |          dz
  }d||z   cxk    r|k    rn n||||z
  |z
           |z  z   }|	                    |z
            z  }nt#          	                    |                    S )z:
        Computes roots of the Indicial equation.
        r   c                     t                              |           d          }d|                                v r|d         S dS )Nr  r  r   )r/   r|   r  )polyroot_allr   rx   s     rG   _pole_degreez1HolonomicFunction._indicial.<locals>._pole_degree  sE    QZZ--q===HHMMOO##{"qrI   c              3   >   K   | ]}|                                 V  d S rB   rh  r  s     rG   r   z.HolonomicFunction._indicial.<locals>.<genexpr>  s*      44AQXXZZ444444rI   
   r8   c                 ,    | j         rn
 |           S rB   )rO  )qr  infs    rG   rH   z-HolonomicFunction._indicial.<locals>.<lambda>  s    qy=ll1oo rI   c              3   :   K   | ]\  }} |          |z
  V  d S rB   rr   )r   r   r  degs      rG   r   z.HolonomicFunction._indicial.<locals>.<genexpr>  s3      ==tq!A
======rI   )r   r  r  r   r}   rv   rV   rx   r_   r`   r   r   rP  ry   r  r~   r{   r/   r|   )rd   
list_coeffr!  yri  r   r   r   r  r   r  r  r  rx   s            @@@@@rG   r  zHolonomicFunction._indicialx  s   
 7a<<<<((22444%0
#(FFE	 	 	 	 	 	 4444444C6NNSD,<,B%C%CCD=========y'<'<=====j)) 	% 	%DAqI^^a'FAE####V#####	&1*q.1A55a!e$$$AAQZZ]]A&&&rI   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   r8   )sympy.holonomic.numericalr  r  r   r   r  r  r   r   r   r/   r   rv   rV   r|   r}   rx   r>   )rd   pointsr  hr  r  lpr   r   r   r   s              rG   r  zHolonomicFunction.evalf  s   \ 	544444 vz** 	.B&		Aw!||vdQCKPPPQSTT; *))A1uuBQUaK  A!eWF1q5\\ . .fRj1n----t'.3<<T=M=XY[=\]]_c_eff 	0 	0ADG||qF{{&tQ///  +  	T6$v;OOOPRSSvdF6{KKKKrI   c                    | j         j        j        j        }|                    |          t          d          \  }}fd| j         j        D             }t          ||          }t          ||| j	        | j
                  S )z
        Changes only the variable of Holonomic Function, for internal
        purposes. For composition use HolonomicFunction.composition()
        r\   c                 J    g | ]} |                                            S rr   )r   )r   r   r   s     rG   r   z.HolonomicFunction.change_x.<locals>.<listcomp>  s)    CCC!qq~~CCCrI   )r   rv   rV   r   r   rY   r}   r^   r   r   r   )rd   zr   rv   r   rQ   r   s         @rG   change_xzHolonomicFunction.change_x  s     %*.a  )!T22	CCCCt'7'BCCC#C00 a$':::rI   c                 .   | j         | j        j        }| j        j        j        fd|D             }t          || j        j                  }| j        z
  }|                                 st          |          S t          ||| j	                  S )z-
        Substitute `x + a` for `x`.
        c           	          g | ]A}                                         |                              z                       BS rr   )r{   r|   r  )r   r   r   rV   rx   s     rG   r   z-HolonomicFunction.shift_x.<locals>.<listcomp>  sE    XXXAtt}}Q//44QA>>??XXXrI   )
rx   r   r}   rv   rV   r^   r   r   r   r   )rd   r   listaftershiftrQ   r   rV   rx   s    `   @@rG   r  zHolonomicFunction.shift_x  s    
 F)4&+XXXXXXXXX"3(8(?@@Wq[##%% 	-$S!,,, aTW555rI   c                 h   ||                                  }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'          |          st)          |          }|t          |          k     rQt          ||         t*          t,          f          r||                                         ||<   |||         |	|z  z  z  }|t1          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t5          d
          t7          fdj        dd         D                       rt9          | | j                  j        d         }j        d         }t          |                                t*          t,          f          rt!          |                                                                          ||                                z  z   t!          |                                                                          ||                                z  z  z  }ntt!          |                                          ||                                z  z   t!          |                                          ||                                z  z  z  }d}t          j        j                            |          |j                  }t          j        j                            |          |j                  }|rg }t?          ||z             D ]}||k     rk|rJ|                     t!          ||                   |	||z   z  z                      |	|	|
z
            f           n|t!          ||                   |	|z  z  z  }tt!          ||                   dk    rg }g }tC          |"                                          D ]4}|#                    tI          ||z
  |z            g||         z             5tC          |"                                          D ]4}|#                    tI          ||z
  |z            g||         z             5d|v r|%                    d           n|                     d           |rx|                     t!          ||                   |	||z   z  z                      |	|	|
z
            tM          ||||	|z  z                                |	|	|
z
            f           |t!          ||                   tM          ||||	|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   r8   r   r  )as_listr  r   r  r  z+Can't compute sufficient Initial Conditionsc              3   B   K   | ]}|j         j        j        k    V  d S rB   r   r   r   rF   s     rG   r   z-HolonomicFunction.to_hyper.<locals>.<genexpr>m  s/      CC1qAHM&&CCCCCCrI   r   )'r  rb   r  r~   to_hyperr  r  rx   r   r   r/   rv   rV   r|   r}   r   r   r   ry   r   r   r*   r+   as_exprr   r  r  anyr=   LCri  r   r   r   r  r  r6   remover&   )rd   r  r  r  r  r  rQ   r   r  rx   r   mnonzerotermsr   r   r   r  arg1arg2	listofsolapbqr\  rF   s                          @rG   r  zHolonomicFunction.to_hyper  s   F >))++JJJj%(( 	S__-A-A#AJ#AJMM
E** 	s:!/C/C#AJ&qMM#AJJ__!!c*Q-&8&8A&=&=#Aq)J#Aq)JMM__!!c*Q-&8&8A&=&=#Aq)J&qM!,M#Aq)JJ--
1-FFC^ @ @t}}WQ}???J]!FW G 66 !7!7Q!H!H*,_bcccL&C!,// 4 41q55
15FFs2ww;;!"Q%+{)CDD 0 "112a51a4<'CC 6&!),,q!t33CC#[9:: -kkmma&66A},, !77 XXaR00344y Qwwxx1r6***J>CGG##%&STTT CCCCQrT0BCCCCC 	5%dDG444LOL addff{K899 	PQTTVV^^%%&&QXXZZ89Qqttvv~~?O?O=P=PSTWXW_W_WaWaSb=bcAAQTTVV99q188::./1QTTVV99q188::3NOAQX]++A..
==QX]++A..
==  	IzA~&& %	A %	AA :~~ +$$qAxx!ao2F'F&L&LQPQRTPT&U&U%XYYYY1RU88ad?*C
 Axx1}}BB TYY[[)) > >		9a!eq[112T!W<====TYY[[)) > >		9a!eq[112T!W<==== Bww		!		! A  1RU88A-,@#@"F"Fq!B$"O"ORWXZ\^`abcefbf`fRgRgQmQmnoqrsuquQvQv!wxxxxqAxx%BAqD"9"99AqD@@ 	A}$$7788Aq2v&&&
rI   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

        )r5   r  simplifyr   s    rG   r  zHolonomicFunction.to_expr  s&    & 4==??++44666rI   c                    d}|6t          | j                  | j        j        k    rt          | j                  }| j        j        j        j        }	 t          |                                 | j	        |||          }n# t          t          f$ r d}Y nw xY w|r|j        |k    r|S |                     |d          }t          | j        | j	        ||          S )a  
        Changes the point `x0` to ``b`` for initial conditions.

        Examples
        ========

        >>> from sympy.holonomic import expr_to_holonomic
        >>> from sympy import symbols, sin, exp
        >>> x = symbols('x')

        >>> expr_to_holonomic(sin(x)).change_ics(1)
        HolonomicFunction((1) + (1)*Dx**2, x, 1, [sin(1), cos(1)])

        >>> expr_to_holonomic(exp(x)).change_ics(2)
        HolonomicFunction((-1) + (1)*Dx, x, 2, [exp(2)])
        TN)rx   r   lenicsrD   F)r  )r~   r   r   r   rv   rV   rD   expr_to_holonomicr  rx   r<   r=   r   r  r   )rd   r   r  symbolicr   rQ   r   s          rG   r   zHolonomicFunction.change_ics  s    $ >c$'llT-=-CCC\\F%*1	#DLLNNdf6Z]^^^CC#%89 	 	 	HHH	  	!JZZtZ,, !1461bAAAs   +A> >BBc                     |                      d          }t          j        }|D ]U}t          |          dk    r||d         z  }!t          |          dk    r!||d         t	          |d                   z  z  }V|S )a  
        Returns a linear combination of Meijer G-functions.

        Examples
        ========

        >>> from sympy.holonomic import expr_to_holonomic
        >>> from sympy import sin, cos, hyperexpand, log, symbols
        >>> x = symbols('x')
        >>> hyperexpand(expr_to_holonomic(cos(x) + sin(x)).to_meijerg())
        sin(x) + cos(x)
        >>> hyperexpand(expr_to_holonomic(log(x)).to_meijerg()).simplify()
        log(x)

        See Also
        ========

        to_hyper
        T)r  r8   r   r   )r  r   r   r~   _hyper_to_meijerg)rd   r5  rQ   r   s       rG   
to_meijergzHolonomicFunction.to_meijerg  s    , mmDm))f 	6 	6A1vv{{qtQ1qt/!5555
rI   r  FT)r  FTN)r  r  F)FNrB   )$rm   rn   ro   rp   r   re   rg   rq   r   r   r   r   r   r  r   rl   r   r   r   r   r   r   r   ri  rw  r  r  r  r  r  r  r  r  r  r   r  rr   rI   rG   r   r   t  sM       @ @D L   :   H  <     L L LO; O; O;b}? }? }? }?~K; K; K;Z  _? _? _?B H! ! !! ! !  & & &     DD D D>. >. >.@{, {, {, {,zJ J J JXN N N N`"' "' "'HIL IL IL ILV; ; ;6 6 6 n n n n`7 7 7*!B !B !B !BF         rI   r   Fc                    | j         }| j        }| j        d         }|                    t                                                    }t          t          j        |          d          \  }}||z  }	d}
|D ]
}|
|	|z   z  }
|	dz
  }|}|D ]
}|||z   z  }|
|z
  }t          |           }|t          t          fv r#t          ||                              |          S dd}t          |t                    sT |||||j                  }|s|dz  } |||||j                  }|t          ||                              |||          S t          |t                    rXd} |||||j        |          }|s|dz  } |||||j        |          }|t          ||                              |||          S t          ||                              |          S )a  
    Converts a hypergeometric function to holonomic.
    ``func`` is the Hypergeometric Function and ``x0`` is the point at
    which initial conditions are required.

    Examples
    ========

    >>> from sympy.holonomic.holonomic import from_hyper
    >>> from sympy import symbols, hyper, S
    >>> x = symbols('x')
    >>> from_hyper(hyper([], [S(3)/2], x**2/4))
    HolonomicFunction((-x) + (2)*Dx + (x)*Dx**2, x, 1, [sinh(1), -sinh(1) + cosh(1)])
    r   r\   r8   Fc                 F   g }t          |          D ]}|r)|                     ||                                          }n|                     ||          }|j        du st	          |t
                    r d S |                    |           |                     |          } |S NFr   r  r  r  rb   r   r   r   simprx   r   r   r  r   r   vals           rG   _find_conditionsz$from_hyper.<locals>._find_conditions6  s    u 		  		 A 'ii2&&,,..ii2&&}%%C)=)=%ttIIcNNN99Q<<DD	rI   r  )r  r  r.  atomsr   poprY   r,   r   r5   r   r   r   rw  rb   r&   r   )funcr   r  r   r   r  rx   r   r\   xDxr1aixDx_1r2birQ   r  r  r   s                      rG   
from_hyperr%    s;     	AA	!A	A!""21"5"5t<<EAr B$C	
B  
cBh!GE	B  
ebj
r'CtD*+++ a((44Q777    dE"" 	@dAr3955 	: !GB!!$2sy99B  	: !a((44QB???$ @dAr39e<< 	A!GB!!$2sy%@@B  	A !a((44QB???S!$$00333rI   Tc                    | j         }| j        }t          | j                  }t          | j                  }t          |          }	| j        d         }
|
                    t                                                    }t          |
                    |          d          \  }}||z  }|dz   }|d||z   |	z
  z  z  }|D ]
}|||z
  z  }d}|D ]
}|||z
  z  }||z
  }|s#t          ||                              |
          S t          |           }|t          t          fv r#t          ||                              |
          S dd}t!          |t"                    sT |||||j                  }|s|dz  } |||||j                  }|t          ||                              |
||          S t!          |t"                    rXd} |||||j        |          }|s|dz  } |||||j        |          }|t          ||                              |
||          S t          ||                              |
          S )a  
    Converts a Meijer G-function to Holonomic.
    ``func`` is the G-Function and ``x0`` is the point at
    which initial conditions are required.

    Examples
    ========

    >>> from sympy.holonomic.holonomic import from_meijerg
    >>> from sympy import symbols, meijerg, S
    >>> x = symbols('x')
    >>> from_meijerg(meijerg(([], []), ([S(1)/2], [0]), x**2/4))
    HolonomicFunction((1) + (1)*Dx**2, x, 0, [0, 1/sqrt(pi)])
    r   r\   r8   r   Fc                 F   g }t          |          D ]}|r)|                     ||                                          }n|                     ||          }|j        du st	          |t
                    r d S |                    |           |                     |          } |S r  r  r  s           rG   r  z&from_meijerg.<locals>._find_conditions  s    u 	  	 A 'ii2&&,,..ii2&&}%%C)=)=%ttIIcNNN99Q<<DD	rI   r  )r  r  r~   anbmr.  r  r   r  rY   r   r   rw  r5   r   r   rb   r'   r   )r  r   r  r  rD   r   r   r   r  r  r  rx   r   r\   r  xDx1r   r!  r#  r$  rQ   r  r  r   s                           rG   from_meijergr+  \  s     	AADGADGAAA	!A	A!&"6"6q"9"94@@EAr B$C7D	
B!a%!)	B  
dRi	
B  
cBh
r'C 8 a((44Q777tD*+++ a((44Q777    dG$$ @dAr3955 	:!GB!!$2sy99B  	: !a((44QB???$   @dAr39e<< 	A!GB!!$2sy%@@B  	A !a((44QB???S!$$00333rI   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
    r8   z%Specify the variable for the functionNr   )r   r   r  rD   r  )rD   Fr  rD   )rx   r  rD   c                 8    g | ]\  }}|t          |          z  S rr   r   r   s      rG   r   z%expr_to_holonomic.<locals>.<listcomp>H	  '    QQQAA	!,QQQrI   )*r   free_symbolsr~   r  
ValueErrorr  r   rM  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   rw  r.  r  r  r   r   r   r   r   r  r   r   ry   )r  rx   r   r   r  rD   r  syms
extra_symssolpolyftr  rQ   r  r.  r   rF   gsingular_icss                       rG   r  r    s]   R 4==DD t99>>xxzzAADEEE	
dAdJ~88E?? 	FFFz??aJ'1133F $D!r&QWbjkkkG   4!mF33333	#	#	#!mF3333  $6IIaAsOOa AA$q'""1%%CC$T1uVLLLC *))   
 /."4B77C <a&tQF;;  < %S_aSAAA 	X 	//$)A,//C CFJ 	+_*FtQF33 	8!GB"4B77C  	8 ty|R555 9D	A
DGq5
H
H
HCCxxq#d))$$ 	R 	RA$T!WE&QQQQCC	R 
cq#d))$$ 	R 	RA$T!WE&QQQQCC	R 
c47lCF "!!	 	  

v 
 '&
""2&& 	AMMOOGGq66Q;;1QqT7ae++!AB{"A+Aq"f==LQQ<9P9PQQQLL!B$S_aR@@@
4B
/
/C 4
atQF33  4 S_aS999rI   c                    g }g }|j         }|                                }|                    t          j                  }g }t          |           D ]\  }	}
t          |
|j                  r;|                    |	                    |

                                                     n`t          |
|j                  s6|                    |                    t          |
                               n|                    |
           |                    ||	                                                    |                    ||	                                                    |D ]}	|	                    |          }|r| }|	                    |
                                          }t          |          D ]\  }	}
|
|z  ||	<    ||d                                         |d                                         z  
                                          }|D ]}	|	                    |          }|	                    |
                                          }t          |          D ]Q\  }	}
|
|z  } ||                                |                                z  
                                          ||	<   Rt!          ||          S )z'
    Normalize a given annihilator
    r   )rV   r   r{   r   r   ry   rb   rz   r   r   r   r   numerdenomlcmgcdr^   )list_ofrv   r   numrC  rV   r   	lcm_denomlist_of_coeffr   r   	gcd_numerfrac_anss                rG   r   r   V	  s   
 CE;DA&&IM '"" / /1a$$ 	$  qyy{{!3!34444Aqw'' 	$  gajj!9!9::::  ### 	

=#))++,,, 	]1%++--....  % %EE)$$		 J	i''))**I -(( ) )1y=amB'--//-2C2I2I2K2KKTTVVWWI  % %EE)$$		i''))**I -(( Q Q1y=4!1!1HNN4D4D!D M M O OPPav666rI   c                 H   g }t          |           dz
  }|                    t          | d         |                     t          | dd                   D ]1\  }}|                    t          ||          | |         z              2|                    | |                    |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.
    r8   r   N)r~   r   rN  ry   )r}   r   rQ   r   r   r   s         rG   r-  r-  	  s     CJ!AJJwz!}a(()))*QRR.)) 2 21

71a==:a=01111JJz!}JrI   c                 x   | 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  rD  s     rG   r   z$_hyper_to_meijerg.<locals>.<genexpr>	  s5      
.
.a16!c!ffk
.
.
.
.
.
.rI   r   c              3       K   | ]	}d |z
  V  
dS r  rr   rD  s     rG   r   z$_hyper_to_meijerg.<locals>.<genexpr>	  s&      		A!a%						rI   rr   c              3       K   | ]	}d |z
  V  
dS r  rr   rD  s     rG   r   z$_hyper_to_meijerg.<locals>.<genexpr>	  s&      

Q1q5





rI   )
r  r  r  r5   r.  r   r   r   r%   r'   )
r  r  r  r  r(  anpr)  bmqr\  r   s
             rG   r  r  	  s     
B	B

.
.2
.
.
... !4   	!A 
				B
C
&B

"


C	A  aL  aLwr3C!,,,,rI   c                    t          |           t          |          k    r3d t          | |          D             |t          |           d         z   }n2d t          | |          D             | t          |          d         z   }|S )zvTakes polynomial sequences of two annihilators a and b and returns
    the list of polynomials of sum of a and b.
    c                     g | ]
\  }}||z   S rr   rr   r   s      rG   r   z_add_lists.<locals>.<listcomp>	       333Aq1u333rI   Nc                     g | ]
\  }}||z   S rr   rr   r   s      rG   r   z_add_lists.<locals>.<listcomp>	  rU  rI   )r~   r   )list1list2rQ   s      rG   r   r   	  s     5zzSZZ33UE!2!2333eCJJKK6HH33UE!2!2333eCJJKK6HHJrI   c                 (   | j                             | j                  s|                                 dk    r| j        S | j         }|j        g | j        }|j        j        }|                                }|j	        D ][}t          ||j        j        j                  r:                    |                    |                                                     \t          |          k     s|t          |          k    r|S fdt!                    D             }|dt#          t          |                             }t!          |z
            D ]}	d}
t%          ||          D ]i\  }t'          || j                  }t)          |dd          s|c c S t          |t*          t,          f          r|                                }|
|z  z  }
j|                    |
           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 rr   rr   )r   r   r   r}   s     rG   r   z_extend_y0.<locals>.<listcomp>	  s8     # # # AA. # # #rI   Nr   r  )r   r   r   r   r   r   rv   rV   r   r}   rb   rz   r   r   r   r~   r   rP  r   r  getattrr*   r+   r  r-  )	Holonomicr   r   r   r   r   r   list_redr  r   rQ   r   rF   r   r}   s                @@rG   r   r   	  s    ((66 ):R:R:T:TX\:\:\|'KAJ	BA	A# 2 2a+0677 	2aeeAIIKK00111
2ww{{a3r77ll	# # # # #q# # #H	SR!__	B1q5\\ 
2 
2H%% 	 	DAq9<((A1k400 					!k;788  IIKK1q5LCC
		#$Xq113r7788rI   c                 t   t          | t                    s|                                 S |                    |           }|                    |           }| |                                z  ||                                z  z   }|dz  } ||                                |                                f          S r  )rb   r.   r   rB  rC  r   )fracr   r  r  sol_num	sol_denoms         rG   rN  rN  	  s    dC   yy{{	A	AcAFFHHnq16688|+G1I1goo!2!2!4!45666rI   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)rb   r.   rG  denr   r   mpmathrc  ry   reversedr   
_to_mpmathprecr*   r+   r  )
r_  r   mpmr  r  sol_psol_qrc  r   r   s
             rG   r  r   
  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=rI   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|                    |                                           }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          }nF|rC|||z  z  |z  dz
  }t          ||                              |	          j        }|                    |          }||dk    r|r||dk    r|                    |	                                          }t)          t+          |                    D ]`\  }}|dk    rt	          |t.          t0          f          r|                                }t5          |          |
z  }t5          |          |
z  } t	          |t.          t0          f          r|                                }|t5          |g          i}|s|st          ||||          S |s|j        }|                    |          rt          |||                                          }t-          |          }tA          |          dk    rp||d                  t4          j!        k    rT|d         }| ||z
  |z  z  }tE          ||||          }d t)          |          D             }||i}t          ||||          S tE          | |||          }|s|dz  }tE          | |||          }|t          ||||          S )	zO
    Converts polynomials, rationals and algebraic functions to holonomic.
    TFNr\   r   r   r8   c                 8    g | ]\  }}|t          |          z  S rr   r   r   s      rG   r   z)_convert_poly_rat_alg.<locals>.<listcomp>}
  r1  rI   )#is_polynomialis_rational_functionas_base_expr  rb   r	   r6   r  r  r   rY   rM  r   r   r   r}   rv   r   r{   r   ry   rf  r   r*   r+   r  r   as_numer_denomrw  r   r   r  r~   r   r  )r  rx   r   r   r  rD   r  ispolyisratbasepolyratexpr  r   is_algr   r   r\   rQ   r   r5  r   r   r[  indicialr  r  rF   r  r?  r@  s                                 rG   r4  r4  
  s/   
 !!F ))++ 
e 
++--&!!## 	(8 	&%(( +"6**8VXqAFFFF e v tQA!!T**EAr 88A;; 3 QD6222 .(Ri$))A,,&eDDDoob)) :"''k',,t$$,,..C!(3--00  166Xc]]++ABB/!%(( + +1a+{!;<< + yy{{E!HAeHH%B	 (""$$1!ebj1qvvayy=(1qvvayy=8eDDD	 (1q5kB"Q''33H==Ioob)) :"''k'^v{{,,x((0022C!(3--00  166a+{!;<< $		A!fQ44&=%+{!;<< (AugJJ'B	 1 1 aR000 
r 	5c1b))3355GGq66Q;;1QqT7ae++!AB{"A+Aq"f==LQQ<9P9PQQQLL!B$S!R444	$2v	.	.B 3
adAr622  3 S!R,,,rI   c                 :   t          j        |           }|r|\  }}}nd S fd|D             }|                                }	|	d         k    r|	d         nt          j        fd|D             }
d |D             }fd} ||d         |
d                   \  }}|d         |z  t          |||          z  }t          dt          |                    D ]>} |||         |
|                   \  }}|||         |z  t          |||          z  z  }?|S )Nc                 &    g | ]}|d          z  S r)  rr   )r   r   facs     rG   r   z&_convert_meijerint.<locals>.<listcomp>
  s!    &&&qad
&&&rI   r   r8   c                 &    g | ]}|d          z   S )r8   rr   )r   r   r!  s     rG   r   z&_convert_meijerint.<locals>.<listcomp>
  s!    ###Aq1Q4x###rI   c                     g | ]
}|d          S )r   rr   rD  s     rG   r   z&_convert_meijerint.<locals>.<listcomp>
  s    qadrI   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   r8   c              3   "   K   | ]	}|z   V  
d S rB   rr   r  s     rG   r   z5_convert_meijerint.<locals>._shift.<locals>.<genexpr>
  '      --a!e------rI   c              3   "   K   | ]	}|z   V  
d S rB   rr   r  s     rG   r   z5_convert_meijerint.<locals>._shift.<locals>.<genexpr>
  r  rI   c              3   "   K   | ]	}|z   V  
d S rB   rr   r  s     rG   r   z5_convert_meijerint.<locals>._shift.<locals>.<genexpr>
  r  rI   c              3   "   K   | ]	}|z   V  
d S rB   rr   r  s     rG   r   z5_convert_meijerint.<locals>._shift.<locals>.<genexpr>
  r  rI   )r.  rM  r
   r  r   r   collectr   rp  r   r   r'   )r  r!  r  dr   r   r>  r(  r  r)  r  rF   rx   s              @rG   _shiftz"_convert_meijerint.<locals>._shift
  sC   IbM5588 	'y#&&AIIa%I((GGAJaDMMOOaDAIIAaDD16E----TYq\!_-------TYq\!_-------TYq\!_-------TYq\!_---1"ugr2hR!4444rI   r/  )r(   	_rewrite1rp  r   r   r+  r   r~   )r  rx   r  rD   r.  por?  r   fac_listr>  po_listG_listr  r[  r  rQ   r   rz  r!  s    `               @@rG   r9  r9  
  sl   tQ''D RAAt '&&&A&&&H
A!		!qvA#######GAF5 5 5 5 5& vfQi,,HE1
1+
Q& Q Q Q
QC 1c&kk"" W W6&)WQZ00qx{U"\!hv%V%V%VVVJrI   c                 ~    d
 fd	}|                     t                    }t          |d          \  }} |t          t                    |dz  dz   t          dddg            |t	          t                    |dz  dz   t          dddg            |t          t                    |dz
  t          dd            |t          t                    |t          |dz  z  z   t          dddg            |t          t                    dt          z  |z  |dz  z   t          dddt          t                    z  g            |t          t                    dt          z  |z  |dz  z   t          dddt          t                    z  g            |t          t                    dt          z  |z  |dz  z   t          dddt          t                    z  g            |t          t                    |dz  dz
  t          dddg            |t          t                    |dz  dz
  t          dddg            |t          t                    t          d|z  z   t          |dz  z  z   t                      |t          t                    t          |z  d|dz  z  z   t          |dz  z  z   t                      |t!          t                    t          |z  d|dz  z  z   t          |dz  z  z   t                      |t#          t                    t           |z  d|dz  z  z   t          |dz  z  z   t                     d	S )zi
    Creates the look-up table. For a similar implementation
    see meijerint._create_lookup_table.
    r   rr   c           	                               t          | t                    g                               | t	          ||||          f           dS )z2
        Adds a formula in the dictionary
        N)r+  r-  r,  r   r   )formular   argr   r   tables        rG   addz_create_table.<locals>.add
  sY     	#..33::Gk3B77<9 	: 	: 	: 	: 	:rI   r\   r   r8   r  N)r   rr   )r   r,  rY   r   r   r   r   r"   r   r   r#   r$   r   r   r   r!   r   r    )r  rD   r  r   r   r\   s   `     rG   r7  r7  
  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5rI   c                 <   g }t          |          D ]}|                     ||          }t          |t                    rt	          | ||          }|j        du st          |t                    r d S |                    |           |                     |          } |S r  )r   r  rb   r   r3   r  r   r   )r  rx   r   r   r   r   r  s          rG   r  r  
  s    	B5\\  ii2c3 	%a$$C=E!!ZS%9%9!44
		#yy||IrI   )r   F)Nr   NNNTr  r  )trp   
sympy.corer   r   r   sympy.core.numbersr   r   r   r	   r
   r   r   r   sympy.core.singletonr   sympy.core.sortingr   sympy.core.symbolr   r   sympy.core.sympifyr   (sympy.functions.combinatorial.factorialsr   r   r   &sympy.functions.elementary.exponentialr   r   r   %sympy.functions.elementary.hyperbolicr   r   (sympy.functions.elementary.miscellaneousr   (sympy.functions.elementary.trigonometricr   r   r   'sympy.functions.special.error_functionsr   r    r!   r"   r#   r$   'sympy.functions.special.gamma_functionsr%   sympy.functions.special.hyperr&   r'   sympy.integralsr(   sympy.matricesr)   sympy.polys.ringsr*   sympy.polys.fieldsr+   sympy.polys.domainsr,   r-   sympy.polys.polyclassesr.   sympy.polys.polyrootsr/   sympy.polys.polytoolsr0   sympy.polys.matricesr1   sympy.printingr2   sympy.series.limitsr3   sympy.series.orderr4   sympy.simplify.hyperexpandr5   sympy.simplify.simplifyr6   sympy.solvers.solversr7   r  r9   r:   r;   holonomicerrorsr<   r=   r>   r?   rR   rY   rT   r^   r   r%  r+  r,  r5  r6  sympy.integrals.meijerintr-  r  r   r-  r  r   r   rN  r  r4  r9  r7  r  rr   rI   rG   <module>r     sT   
 % $ $ $ $ $ $ $ $ $" " " " " " " " " " " " " " " " " " " " " " " " " " & & & & & & + + + + + + + + & & & & & & 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A3 A3 A3 A3 A3 A3 A3 A3HSG SG SG SG SG SG SG SGlX X X X X X X Xv4J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  (- - -:  & & &R	7 	7 	7   > '(DbSW g- g- g- g-T *.b + + + +\ !# "6 "6 "6 "6J
 
 
 
 
rI   