o
    oh                     @   st  d Z ddlmZ ddlmZmZ ddlmZ ddlm	Z	 ddl
mZmZmZ ddlmZ ddlmZ dd	lmZmZmZmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlm Z  ddl!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z. ddl!m/Z/m0Z0 ddl1m2Z2m3Z3m4Z4 ddl5m6Z6 ddl7m8Z8 ddl9m:Z: ddl;m<Z<m=Z= ddl>m?Z? G dd deZ@dd ZAG dd deZBG dd deBZCG dd  d eBZDG d!d" d"eZEG d#d$ d$eEZFG d%d& d&eEZGG d'd( d(eEZHG d)d* d*eEZIG d+d, d,eEZJG d-d. d.eEZKG d/d0 d0eEZLG d1d2 d2eEZMG d3d4 d4eEZNG d5d6 d6eEZOG d7d8 d8eEZPG d9d: d:eZQd;S )<z%Hypergeometric and Meijer G-functions    )Counter)SMod)Add)Expr)Function
DerivativeArgumentIndexError)Tuple)Mul)Ipioozoo)global_parameters)Ne)default_sort_key)Dummy)lcm)sqrtexplogsincosasinatansinhcoshasinhacoshatanhacoth)	factorialRisingFactorial)Absre
unpolarify)	exp_polar)ceiling)	Piecewise)AndOr)orderedc                   @   s&   e Zd ZdddddZd	ddZdS )
TupleArgNr   logxcdirc                   s   t  fdd| jD  S )Nc                    s   g | ]}|j  d qS )r.   )as_leading_term.0fr0   r/   x q/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/sympy/functions/special/hyper.py
<listcomp>&   s    z,TupleArg.as_leading_term.<locals>.<listcomp>)r-   args)selfr/   r0   r6   r7   r5   r8   r1   %   s   zTupleArg.as_leading_term+c                    s*   ddl m t fdd| jD  S )z  Compute limit x->xlim.
        r   )limitc                    s   g | ]	}| qS r7   r7   r2   dirr=   r6   xlimr7   r8   r9   ,   s    z"TupleArg.limit.<locals>.<listcomp>)sympy.series.limitsr=   r-   r:   )r;   r6   r@   r?   r7   r>   r8   r=   (   s   zTupleArg.limit)r<   )__name__
__module____qualname__r1   r=   r7   r7   r7   r8   r-      s    r-   c                 C   s   t dd | D  S )ay  
    Turn an iterable argument *v* into a tuple and unpolarify, since both
    hypergeometric and meijer g-functions are unbranched in their parameters.

    Examples
    ========

    >>> from sympy.functions.special.hyper import _prep_tuple
    >>> _prep_tuple([1, 2, 3])
    (1, 2, 3)
    >>> _prep_tuple((4, 5))
    (4, 5)
    >>> _prep_tuple((7, 8, 9))
    (7, 8, 9)

    c                 S   s   g | ]}t |qS r7   )r&   r3   r6   r7   r7   r8   r9   D       z_prep_tuple.<locals>.<listcomp>)r-   )vr7   r7   r8   _prep_tuple3   s   rH   c                   @   s   e Zd ZdZdZdd ZdS )TupleParametersBasezh Base class that takes care of differentiation, when some of
        the arguments are actually tuples. Tc              	   C   s   zCd}| j d |s| j d |r4t| jD ]\}}| j| |}|dkr3|| d|f| 7 }q|| d| j d |  W S  ttfyS   t| | Y S w )Nr            )	r:   has	enumerate	_diffargsdifffdiffr	   NotImplementedErrorr   )r;   sresipmr7   r7   r8   _eval_derivativeM   s     z$TupleParametersBase._eval_derivativeN)rB   rC   rD   __doc__is_commutativerX   r7   r7   r7   r8   rI   G   s    rI   c                       s   e Zd ZdZdd Zedd Zd#ddZd	d
 Zdd Z	d$ fdd	Z
d% fdd	Zedd Zedd Zedd Zedd Zedd Zedd Zedd  Zd!d" Z  ZS )&hypera  
    The generalized hypergeometric function is defined by a series where
    the ratios of successive terms are a rational function of the summation
    index. When convergent, it is continued analytically to the largest
    possible domain.

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

    The hypergeometric function depends on two vectors of parameters, called
    the numerator parameters $a_p$, and the denominator parameters
    $b_q$. It also has an argument $z$. The series definition is

    .. math ::
        {}_pF_q\left(\begin{matrix} a_1, \cdots, a_p \\ b_1, \cdots, b_q \end{matrix}
                     \middle| z \right)
        = \sum_{n=0}^\infty \frac{(a_1)_n \cdots (a_p)_n}{(b_1)_n \cdots (b_q)_n}
                            \frac{z^n}{n!},

    where $(a)_n = (a)(a+1)\cdots(a+n-1)$ denotes the rising factorial.

    If one of the $b_q$ is a non-positive integer then the series is
    undefined unless one of the $a_p$ is a larger (i.e., smaller in
    magnitude) non-positive integer. If none of the $b_q$ is a
    non-positive integer and one of the $a_p$ is a non-positive
    integer, then the series reduces to a polynomial. To simplify the
    following discussion, we assume that none of the $a_p$ or
    $b_q$ is a non-positive integer. For more details, see the
    references.

    The series converges for all $z$ if $p \le q$, and thus
    defines an entire single-valued function in this case. If $p =
    q+1$ the series converges for $|z| < 1$, and can be continued
    analytically into a half-plane. If $p > q+1$ the series is
    divergent for all $z$.

    Please note the hypergeometric function constructor currently does *not*
    check if the parameters actually yield a well-defined function.

    Examples
    ========

    The parameters $a_p$ and $b_q$ can be passed as arbitrary
    iterables, for example:

    >>> from sympy import hyper
    >>> from sympy.abc import x, n, a
    >>> h = hyper((1, 2, 3), [3, 4], x); h
    hyper((1, 2), (4,), x)
    >>> hyper((3, 1, 2), [3, 4], x, evaluate=False)  # don't remove duplicates
    hyper((1, 2, 3), (3, 4), x)

    There is also pretty printing (it looks better using Unicode):

    >>> from sympy import pprint
    >>> pprint(h, use_unicode=False)
      _
     |_  /1, 2 |  \
     |   |     | x|
    2  1 \  4  |  /

    The parameters must always be iterables, even if they are vectors of
    length one or zero:

    >>> hyper((1, ), [], x)
    hyper((1,), (), x)

    But of course they may be variables (but if they depend on $x$ then you
    should not expect much implemented functionality):

    >>> hyper((n, a), (n**2,), x)
    hyper((a, n), (n**2,), x)

    The hypergeometric function generalizes many named special functions.
    The function ``hyperexpand()`` tries to express a hypergeometric function
    using named special functions. For example:

    >>> from sympy import hyperexpand
    >>> hyperexpand(hyper([], [], x))
    exp(x)

    You can also use ``expand_func()``:

    >>> from sympy import expand_func
    >>> expand_func(x*hyper([1, 1], [2], -x))
    log(x + 1)

    More examples:

    >>> from sympy import S
    >>> hyperexpand(hyper([], [S(1)/2], -x**2/4))
    cos(x)
    >>> hyperexpand(x*hyper([S(1)/2, S(1)/2], [S(3)/2], x**2))
    asin(x)

    We can also sometimes ``hyperexpand()`` parametric functions:

    >>> from sympy.abc import a
    >>> hyperexpand(hyper([-a], [], x))
    (1 - x)**a

    See Also
    ========

    sympy.simplify.hyperexpand
    gamma
    meijerg

    References
    ==========

    .. [1] Luke, Y. L. (1969), The Special Functions and Their Approximations,
           Volume 1
    .. [2] https://en.wikipedia.org/wiki/Generalized_hypergeometric_function

    c                 K   s   | dtjrBtt| }tt| }||@ }g g f }\}}t||fD ]\}	}
|
|8 }
t|
D ]}||	 |g|
|   q1q%ntt|}tt|}t	j
| t|t||fi |S )Nevaluate)popr   r\   r   r
   rN   r,   extendlistr   __new__rH   )clsapbqzkwargscacbcommonargrU   ckr7   r7   r8   r`      s    zhyper.__new__c                 C   s\   t |t |kst |t |d kr*t|dkdkr,t|}||kr(t|||S d S d S d S )NrJ   T)lenr$   r&   r[   )ra   rb   rc   rd   nzr7   r7   r8   eval   s   4z
hyper.evalrK   c                 C   s`   |dkr	t | |tdd | jD  }tdd | jD  }t| j t| j  }|t||| j S )NrK   c                 S      g | ]}|d  qS rJ   r7   r3   ar7   r7   r8   r9      rF   zhyper.fdiff.<locals>.<listcomp>c                 S   ro   rp   r7   r3   br7   r7   r8   r9      rF   )r	   r
   rb   rc   r   r[   argument)r;   argindexnapnbqfacr7   r7   r8   rQ      s   
zhyper.fdiffc                 K   s   ddl m} ddlm} t| jdkrAt| jdkrA| jdkrA| j\}}| jd }||||| |  |||  |||  S || S )Nr   gammahyperexpandrL   rJ   )'sympy.functions.special.gamma_functionsr{   sympy.simplify.hyperexpandr}   rl   rb   rc   ru   )r;   hintsr{   r}   rr   rt   rj   r7   r7   r8   _eval_expand_func   s   &

0zhyper._eval_expand_funcc           	         s|   ddl m} tddd  fdd|D } fdd|D }t| t|  }t|||   t   dtf| jf| dfS )	Nr   )SumnT)integerc                       g | ]}t | qS r7   r#   rq   r   r7   r8   r9          z.hyper._eval_rewrite_as_Sum.<locals>.<listcomp>c                    r   r7   r   rs   r   r7   r8   r9      r   )sympy.concrete.summationsr   r   r   r)   r"   r   convergence_statement)	r;   rb   rc   rd   re   r   rfaprfbqcoeffr7   r   r8   _eval_rewrite_as_Sum   s    zhyper._eval_rewrite_as_SumNr   c                    s`   | j d }||d}|tju r|j|dt|jrdndd}|tju r'tjS t	 j
|||dS )NrL   r   -r<   )r?   r.   )r:   subsr   NaNr=   r%   is_negativeZeroOnesuper_eval_as_leading_term)r;   r6   r/   r0   ri   x0	__class__r7   r8   r     s   


zhyper._eval_as_leading_termc                    s   ddl m} | jd }||d}| jd }| jd }	||kr#|dks3ddlm}
 |
t |||S g }t|D ]' t	 fdd|D  }t	 fdd|	D  }|
|| |   t   q9t| ||| | S )	Nr   )OrderrL   rJ   r|   c                    r   r7   r   rq   rU   r7   r8   r9     r   z'hyper._eval_nseries.<locals>.<listcomp>c                    r   r7   r   rs   r   r7   r8   r9      r   )sympy.series.orderr   r:   r=   r   r}   r   _eval_nseriesranger   appendr"   r   )r;   r6   r   r/   r0   r   ri   r   rb   rc   r}   termsnumdenr   r   r8   r     s   


 zhyper._eval_nseriesc                 C   
   | j d S )z* Argument of the hypergeometric function. rL   r:   r;   r7   r7   r8   ru   %     
zhyper.argumentc                 C      t | jd  S )z6 Numerator parameters of the hypergeometric function. r   r
   r:   r   r7   r7   r8   rb   *     zhyper.apc                 C   r   )z8 Denominator parameters of the hypergeometric function. rJ   r   r   r7   r7   r8   rc   /  r   zhyper.bqc                 C      | j | j S Nrb   rc   r   r7   r7   r8   rO   4     zhyper._diffargsc                 C      t | jt | j S )z6 A quantity related to the convergence of the series. )sumrb   rc   r   r7   r7   r8   eta8  s   z	hyper.etac                 C   s   t dd | j| j D rOdd | jD }dd | jD }t|t|k r(tjS d}|D ]}d}|rA| }||kr=d}nd}|s2|sHtj  S q,|sM|rOtS t| jt| jd kr^tjS t| jt| jkrjtS tjS )	a  
        Compute the radius of convergence of the defining series.

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

        Note that even if this is not ``oo``, the function may still be
        evaluated outside of the radius of convergence by analytic
        continuation. But if this is zero, then the function is not actually
        defined anywhere else.

        Examples
        ========

        >>> from sympy import hyper
        >>> from sympy.abc import z
        >>> hyper((1, 2), [3], z).radius_of_convergence
        1
        >>> hyper((1, 2, 3), [4], z).radius_of_convergence
        0
        >>> hyper((1, 2), (3, 4), z).radius_of_convergence
        oo

        c                 s   s"    | ]}|j o|d kdkV  qdS )r   TN)
is_integerrq   r7   r7   r8   	<genexpr>W  s     z.hyper.radius_of_convergence.<locals>.<genexpr>c                 S   "   g | ]}|j r|d kdkr|qS r   T
is_Integerrq   r7   r7   r8   r9   X     " z/hyper.radius_of_convergence.<locals>.<listcomp>c                 S   r   r   r   rq   r7   r7   r8   r9   Y  r   FTrJ   )	anyrb   rc   rl   r   r   r]   r   r   )r;   aintsbintspoppedrt   	cancelledrr   r7   r7   r8   radius_of_convergence=  s2   
zhyper.radius_of_convergencec                 C   s   | j }|dkr	dS |tkrdS | j}| j}tt|dk t|dk}tdt|kt|dk t|dkt|d}tt|dkt|dk }t|||S )z; Return a condition on z under which the series converges. r   FTrJ   )	r   r   r   ru   r*   r%   absr   r+   )r;   Rerd   c1c2c3r7   r7   r8   r   r  s   ,zhyper.convergence_statementc                 K      ddl m} || S Nr   r|   r   r}   )r;   re   r}   r7   r7   r8   _eval_simplify     zhyper._eval_simplifyrK   Nr   )r   )rB   rC   rD   rY   r`   classmethodrn   rQ   r   r   r   r   propertyru   rb   rc   rO   r   r   r   r   __classcell__r7   r7   r   r8   r[   Z   s2    v

		






4
r[   c                   @   s   e Zd ZdZdd Zd+ddZdd Zd	d
 Zdd Zdd Z	d,ddZ
dd Zedd Zedd Zedd Zedd Zedd Zedd  Zed!d" Zed#d$ Zed%d& Zed'd( Zed)d* ZdS )-meijergaN  
    The Meijer G-function is defined by a Mellin-Barnes type integral that
    resembles an inverse Mellin transform. It generalizes the hypergeometric
    functions.

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

    The Meijer G-function depends on four sets of parameters. There are
    "*numerator parameters*"
    $a_1, \ldots, a_n$ and $a_{n+1}, \ldots, a_p$, and there are
    "*denominator parameters*"
    $b_1, \ldots, b_m$ and $b_{m+1}, \ldots, b_q$.
    Confusingly, it is traditionally denoted as follows (note the position
    of $m$, $n$, $p$, $q$, and how they relate to the lengths of the four
    parameter vectors):

    .. math ::
        G_{p,q}^{m,n} \left(\begin{matrix}a_1, \cdots, a_n & a_{n+1}, \cdots, a_p \\
                                        b_1, \cdots, b_m & b_{m+1}, \cdots, b_q
                          \end{matrix} \middle| z \right).

    However, in SymPy the four parameter vectors are always available
    separately (see examples), so that there is no need to keep track of the
    decorating sub- and super-scripts on the G symbol.

    The G function is defined as the following integral:

    .. math ::
         \frac{1}{2 \pi i} \int_L \frac{\prod_{j=1}^m \Gamma(b_j - s)
         \prod_{j=1}^n \Gamma(1 - a_j + s)}{\prod_{j=m+1}^q \Gamma(1- b_j +s)
         \prod_{j=n+1}^p \Gamma(a_j - s)} z^s \mathrm{d}s,

    where $\Gamma(z)$ is the gamma function. There are three possible
    contours which we will not describe in detail here (see the references).
    If the integral converges along more than one of them, the definitions
    agree. The contours all separate the poles of $\Gamma(1-a_j+s)$
    from the poles of $\Gamma(b_k-s)$, so in particular the G function
    is undefined if $a_j - b_k \in \mathbb{Z}_{>0}$ for some
    $j \le n$ and $k \le m$.

    The conditions under which one of the contours yields a convergent integral
    are complicated and we do not state them here, see the references.

    Please note currently the Meijer G-function constructor does *not* check any
    convergence conditions.

    Examples
    ========

    You can pass the parameters either as four separate vectors:

    >>> from sympy import meijerg, Tuple, pprint
    >>> from sympy.abc import x, a
    >>> pprint(meijerg((1, 2), (a, 4), (5,), [], x), use_unicode=False)
     __1, 2 /1, 2  4, a |  \
    /__     |           | x|
    \_|4, 1 \ 5         |  /

    Or as two nested vectors:

    >>> pprint(meijerg([(1, 2), (3, 4)], ([5], Tuple()), x), use_unicode=False)
     __1, 2 /1, 2  3, 4 |  \
    /__     |           | x|
    \_|4, 1 \ 5         |  /

    As with the hypergeometric function, the parameters may be passed as
    arbitrary iterables. Vectors of length zero and one also have to be
    passed as iterables. The parameters need not be constants, but if they
    depend on the argument then not much implemented functionality should be
    expected.

    All the subvectors of parameters are available:

    >>> from sympy import pprint
    >>> g = meijerg([1], [2], [3], [4], x)
    >>> pprint(g, use_unicode=False)
     __1, 1 /1  2 |  \
    /__     |     | x|
    \_|2, 2 \3  4 |  /
    >>> g.an
    (1,)
    >>> g.ap
    (1, 2)
    >>> g.aother
    (2,)
    >>> g.bm
    (3,)
    >>> g.bq
    (3, 4)
    >>> g.bother
    (4,)

    The Meijer G-function generalizes the hypergeometric functions.
    In some cases it can be expressed in terms of hypergeometric functions,
    using Slater's theorem. For example:

    >>> from sympy import hyperexpand
    >>> from sympy.abc import a, b, c
    >>> hyperexpand(meijerg([a], [], [c], [b], x), allow_hyper=True)
    x**c*gamma(-a + c + 1)*hyper((-a + c + 1,),
                                 (-b + c + 1,), -x)/gamma(-b + c + 1)

    Thus the Meijer G-function also subsumes many named functions as special
    cases. You can use ``expand_func()`` or ``hyperexpand()`` to (try to)
    rewrite a Meijer G-function in terms of named special functions. For
    example:

    >>> from sympy import expand_func, S
    >>> expand_func(meijerg([[],[]], [[0],[]], -x))
    exp(x)
    >>> hyperexpand(meijerg([[],[]], [[S(1)/2],[0]], (x/2)**2))
    sin(x)/sqrt(pi)

    See Also
    ========

    hyper
    sympy.simplify.hyperexpand

    References
    ==========

    .. [1] Luke, Y. L. (1969), The Special Functions and Their Approximations,
           Volume 1
    .. [2] https://en.wikipedia.org/wiki/Meijer_G-function

    c                    s   t |dkr|d |d f|d |d f|d g}t |dkr#tddd	 }||d ||d } t| ttt rCtd
t fdd|d D rTtdtj	| | |d fi |S )N   r   rJ   rL   rK      z4args must be either as, as', bs, bs', z or as, bs, zc                 S   s<   t | dkr
tddd | D } tt| d t| d S )NrL   zwrong argumentc                 S   s   g | ]}t t|qS r7   )r_   r,   )r3   rU   r7   r7   r8   r9     s    z/meijerg.__new__.<locals>.tr.<locals>.<listcomp>r   rJ   )rl   	TypeErrorr-   rH   )rV   r7   r7   r8   tr  s   zmeijerg.__new__.<locals>.trz$G-function parameters must be finitec                 3   s4    | ]} d  D ]}|| j o|| d kV  qqdS )r   Nr   )r3   rr   rt   arg1r7   r8   r     s     z"meijerg.__new__.<locals>.<genexpr>zNno parameter a1, ..., an may differ from any b1, ..., bm by a positive integer)
rl   r   r
   rM   r   r   
ValueErrorr   r   r`   )ra   r:   re   r   arg0r7   r   r8   r`   
  s   &zmeijerg.__new__rK   c                 C   s   |dkr|  |d S t| jdkr;t| j}|d  d8  < t|| j| j| j| j}d| j | jd d |  |  S t| jdkrit| j}|d  d7  < t| j| j|| j| j}d| j | jd |  |  S t	j
S )NrK   rJ   r   )_diff_wrt_parameterrl   anr_   r   aotherbmbotherru   r   r   )r;   rv   rr   Grt   r7   r7   r8   rQ   "  s   
 
zmeijerg.fdiffc                 C   sH  t | j}t | j}t | j}t | j}|t|k r || n-|t|8 }|t|k r2|| n|t|8 }|t|k rD|| n	||t|  g }g }|||f|||ffD ]=\}}	}
|r| }d }t|	D ]\}}t|| 	 ds}|} nql|d u rt
d|	| }|	| |
||f |sbq[t| j|  }|D ]>\}}d}|| }|}|dk rd}|| }|}t|D ]!}||t| j|| d f | j| j| j|| d f | j 8 }qq|D ]>\}}d}|| }|}|dk rd}|| }|}t|D ]!}||t| j| j|| d f | j|| d f | j| j 8 }qq|S )NrJ   z)Derivative not expressible as G-function?r   )r_   r   r   r   r   rl   r]   rN   r   simplifyrR   r   r   ru   r   r   )r;   idxr   rb   r   rc   pairs1pairs2l1l2pairsr6   foundrU   yrT   rr   rt   signr   baserk   r7   r7   r8   r   2  sz   






zmeijerg._diff_wrt_parameterc                 C   s|   dd }|| j }|| j}t| jt| j}}||kr.t||fv r%tS dt t|| S ||k r8dt | S dt | S )a  
        Return a number $P$ such that $G(x*exp(I*P)) == G(x)$.

        Examples
        ========

        >>> from sympy import meijerg, pi, S
        >>> from sympy.abc import z

        >>> meijerg([1], [], [], [], z).get_period()
        2*pi
        >>> meijerg([pi], [], [], [], z).get_period()
        oo
        >>> meijerg([1, 2], [], [], [], z).get_period()
        oo
        >>> meijerg([1,1], [2], [1, S(1)/2, S(1)/3], [1], z).get_period()
        12*pi

        c                 S   sl   t | D ](\}}|jst  S t|d t| D ]}t|| |   ds+t    S qqtdd | D  S )NrJ   c                 s   s    | ]}|j V  qd S r   )qrE   r7   r7   r8   r     s    z6meijerg.get_period.<locals>.compute.<locals>.<genexpr>)rN   is_Rationalr   r   rl   r   r   r   )lrU   rt   jr7   r7   r8   compute  s   z#meijerg.get_period.<locals>.computerL   )r   r   rl   rb   rc   r   r   r   )r;   r   betaalpharV   r   r7   r7   r8   
get_period  s   
	
zmeijerg.get_periodc                 K   r   r   r   )r;   r   r}   r7   r7   r8   r     r   zmeijerg._eval_expand_funcc                    s  dd l }| j }|tr(|t\}}t|dkrd S |d jd t }nt	j
}tt|t d }|t	j|  tt| |  }z fdd|d| | jd | jd fD \}}}}	W n
 tyi   Y d S w |  |||	||}
W d    n1 sw   Y  t|
 S )Nr   rJ   c                    s   g | ]}|  qS r7   )
_to_mpmath)r3   ri   precr7   r8   r9     s    z'meijerg._eval_evalf.<locals>.<listcomp>)mpmathru   _eval_evalfrM   r'   as_coeff_mulrl   r:   r   r   r   r(   r   r   r   r   r   workprecr   r   _from_mpmath)r;   r   r   znumbranchr   rd   rrb   rc   rG   r7   r   r8   r     s*   

zmeijerg._eval_evalfNr   c                 C   s    ddl m} || j|||dS )Nr   r|   r.   )r   r}   r1   )r;   r6   r/   r0   r}   r7   r7   r8   r     s   zmeijerg._eval_as_leading_termc                    s~   ddl m  | j t fdd| jD   t fdd| jD   t fdd| jD   t fdd| jD   S )z" Get the defining integrand D(s). r   rz   c                 3       | ]	} | V  qd S r   r7   rs   r{   rS   r7   r8   r         z$meijerg.integrand.<locals>.<genexpr>c                 3        | ]} d |  V  qdS rJ   Nr7   rq   r   r7   r8   r         c                 3   r   r   r7   rs   r   r7   r8   r     r  c                 3   r   r   r7   rq   r   r7   r8   r     r   )r~   r{   ru   r   r   r   r   r   )r;   rS   r7   r   r8   	integrand  s   zmeijerg.integrandc                 C   r   )z$ Argument of the Meijer G-function. rL   r   r   r7   r7   r8   ru     r   zmeijerg.argumentc                 C      t | jd d  S )z$ First set of numerator parameters. r   r   r   r7   r7   r8   r        z
meijerg.anc                 C   s    t | jd d | jd d   S )z  Combined numerator parameters. r   rJ   r   r   r7   r7   r8   rb         z
meijerg.apc                 C      t | jd d  S )z% Second set of numerator parameters. r   rJ   r   r   r7   r7   r8   r     r  zmeijerg.aotherc                 C   r  )z& First set of denominator parameters. rJ   r   r   r   r7   r7   r8   r     r  z
meijerg.bmc                 C   s    t | jd d | jd d   S )z" Combined denominator parameters. rJ   r   r   r   r7   r7   r8   rc     r  z
meijerg.bqc                 C   r  )z' Second set of denominator parameters. rJ   r   r   r7   r7   r8   r     r  zmeijerg.botherc                 C   r   r   r   r   r7   r7   r8   rO     r   zmeijerg._diffargsc                 C   r   )\ A quantity related to the convergence region of the integral,
            c.f. references. )r   rc   rb   r   r7   r7   r8   nu
  s   z
meijerg.nuc                 C   s0   t | jt | j tt | jt | j d  S )r  rL   )rl   r   r   r   rb   rc   r   r7   r7   r8   delta  s   0zmeijerg.deltac                 C   s   | j  S )z3 Returns true if expression has numeric data only. )free_symbolsr   r7   r7   r8   	is_number  s   zmeijerg.is_numberr   r   )rB   rC   rD   rY   r`   rQ   r   r   r   r   r   r  r   ru   r   rb   r   r   rc   r   rO   r  r	  r  r7   r7   r7   r8   r     sB     
V*
 	









r   c                   @   s\   e Zd ZdZedd Zedd Zedd Zedd	 Zed
d Z	dd Z
dd ZdS )HyperRepa  
    A base class for "hyper representation functions".

    This is used exclusively in ``hyperexpand()``, but fits more logically here.

    pFq is branched at 1 if p == q+1. For use with slater-expansion, we want
    define an "analytic continuation" to all polar numbers, which is
    continuous on circles and on the ray t*exp_polar(I*pi). Moreover, we want
    a "nice" expression for the various cases.

    This base class contains the core logic, concrete derived classes only
    supply the actual functions.

    c                 G   s6   t tt|d d |dd   }||kr| | S d S )Nr   )tuplemapr&   )ra   r:   newargsr7   r7   r8   rn   -  s   "zHyperRep.evalc                 C      t )z1 An expression for F(x) which holds for |x| < 1. rR   ra   r6   r7   r7   r8   _expr_small3     zHyperRep._expr_smallc                 C   r  )z2 An expression for F(-x) which holds for |x| < 1. r  r  r7   r7   r8   _expr_small_minus8  r  zHyperRep._expr_small_minusc                 C   r  )z6 An expression for F(exp_polar(2*I*pi*n)*x), |x| > 1. r  ra   r6   r   r7   r7   r8   	_expr_big=  r  zHyperRep._expr_bigc                 C   r  )z= An expression for F(exp_polar(2*I*pi*n + pi*I)*x), |x| > 1. r  r  r7   r7   r8   _expr_big_minusB  r  zHyperRep._expr_big_minusc           
      O   s   | j d jdd\}}d}| j d d |f }|js!d}|tj8 }||f }|r3| j| }| j| }	n
| j| }| j| }	|	|krC|S t	|	t
|dkf|dfS )Nr   T
allow_halfFrJ   )r:   extract_branch_factorr   r   Halfr  r  r  r  r)   r   )
r;   r:   re   r6   r   minusr  	newerargssmallbigr7   r7   r8   _eval_rewrite_as_nonrepG  s   




z HyperRep._eval_rewrite_as_nonrepc                 O   sD   | j d jdd\}}| j d d |f }|js| j| S | j| S )Nr   Tr  )r:   r  r   r  r  )r;   r:   re   r6   r   r7   r7   r8   _eval_rewrite_as_nonrepsmallZ  s
   

z%HyperRep._eval_rewrite_as_nonrepsmallN)rB   rC   rD   rY   r   rn   r  r  r  r  r!  r"  r7   r7   r7   r8   r    s    




r  c                   @   @   e Zd ZdZedd Zedd Zedd Zedd	 Zd
S )HyperRep_power1z? Return a representative for hyper([-a], [], z) == (1 - z)**a. c                 C   s   d| | S NrJ   r7   ra   rr   r6   r7   r7   r8   r  e  r   zHyperRep_power1._expr_smallc                 C   s   d| | S r%  r7   r&  r7   r7   r8   r  i  r   z!HyperRep_power1._expr_small_minusc                 C   s:   |j r	| ||S |d | td| d t t |  S NrJ   rL   )r   r  r   r   r   ra   rr   r6   r   r7   r7   r8   r  m  s   (zHyperRep_power1._expr_bigc                 C   s6   |j r	| ||S d| | td| t t |  S r'  )r   r  r   r   r   r(  r7   r7   r8   r  s  s   $zHyperRep_power1._expr_big_minusN	rB   rC   rD   rY   r   r  r  r  r  r7   r7   r7   r8   r$  b  s    


r$  c                   @   r#  )HyperRep_power2z< Return a representative for hyper([a, a - 1/2], [2*a], z). c                 C   s,   dd| d  dt d|  dd|    S NrL   rJ   r   r&  r7   r7   r8   r  }     ,zHyperRep_power2._expr_smallc                 C   s,   dd| d  dt d|  dd|    S r+  r,  r&  r7   r7   r8   r    r-  z!HyperRep_power2._expr_small_minusc                 C   sb   d}|j rd}|d8 }dd| d  d|t t|d   dd|    td| t t |  S )Nr   rJ   rL   )is_oddr   r   r   r   ra   rr   r6   r   sgnr7   r7   r8   r    s   2zHyperRep_power2._expr_bigc                 C   sV   d}|j rd}|dd| d   td| | dd|    tdt t | |  S )NrJ   r   rL   r.  )r/  r   r   r   r   r0  r7   r7   r8   r    s   HzHyperRep_power2._expr_big_minusNr)  r7   r7   r7   r8   r*  z  s    


r*  c                   @   r#  )HyperRep_log1z3 Represent -z*hyper([1, 1], [2], z) == log(1 - z). c                 C   s   t d| S r%  r   r  r7   r7   r8   r    r   zHyperRep_log1._expr_smallc                 C   s   t d| S r%  r3  r  r7   r7   r8   r    r   zHyperRep_log1._expr_small_minusc                 C   s    t |d d| d t t  S r'  r   r   r   r  r7   r7   r8   r    s    zHyperRep_log1._expr_bigc                 C   s   t d| d| t t  S r'  r4  r  r7   r7   r8   r    s   zHyperRep_log1._expr_big_minusNr)  r7   r7   r7   r8   r2        


r2  c                   @   s4   e Zd ZdZedd Zdd Zdd Zdd	 Zd
S )HyperRep_atanhz@ Represent hyper([1/2, 1], [3/2], z) == atanh(sqrt(z))/sqrt(z). c                 C      t t|t| S r   )r    r   r  r7   r7   r8   r       zHyperRep_atanh._expr_smallc                 C   r7  r   )r   r   r  r7   r7   r8   r    s   z HyperRep_atanh._expr_small_minusc                 C   sF   |j rtt|tt d  t| S tt|tt d  t| S NrL   )is_evenr!   r   r   r   r  r7   r7   r8   r    s     zHyperRep_atanh._expr_bigc                 C   s2   |j rtt|t| S tt|t t| S r   )r:  r   r   r   r  r7   r7   r8   r    s   zHyperRep_atanh._expr_big_minusNr)  r7   r7   r7   r8   r6    s    
r6  c                   @   r#  )HyperRep_asin1zA Represent hyper([1/2, 1/2], [3/2], z) == asin(sqrt(z))/sqrt(z). c                 C   r7  r   )r   r   ra   rd   r7   r7   r8   r    r8  zHyperRep_asin1._expr_smallc                 C   r7  r   )r   r   r<  r7   r7   r8   r    r8  z HyperRep_asin1._expr_small_minusc                 C   s8   t j| t j| t t| ttt| t|   S r   )r   NegativeOner  r   r   r   r   ra   rd   r   r7   r7   r8   r    s   8zHyperRep_asin1._expr_bigc                 C   s2   t j| tt|t| |t t t|   S r   )r   r=  r   r   r   r   r>  r7   r7   r8   r    s   2zHyperRep_asin1._expr_big_minusNr)  r7   r7   r7   r8   r;    r5  r;  c                   @   r#  )HyperRep_asin2zG Represent hyper([1, 1], [3/2], z) == asin(sqrt(z))/sqrt(z)/sqrt(1-z). c                 C      t |ttj| S r   )r;  r  r$  r   r  r<  r7   r7   r8   r       zHyperRep_asin2._expr_smallc                 C   r@  r   )r;  r  r$  r   r  r<  r7   r7   r8   r    rA  z HyperRep_asin2._expr_small_minusc                 C      t ||ttj|| S r   )r;  r  r$  r   r  r>  r7   r7   r8   r       
zHyperRep_asin2._expr_bigc                 C   rB  r   )r;  r  r$  r   r  r>  r7   r7   r8   r    rC  zHyperRep_asin2._expr_big_minusNr)  r7   r7   r7   r8   r?    s    


r?  c                   @   r#  )HyperRep_sqrts1z= Return a representative for hyper([-a, 1/2 - a], [1/2], z). c                 C   s,   dt | d|  dt | d|   d S r'  r,  ra   rr   rd   r7   r7   r8   r    r-  zHyperRep_sqrts1._expr_smallc                 C   s$   d| | t d| tt|  S r'  )r   r   r   rE  r7   r7   r8   r    s   $z!HyperRep_sqrts1._expr_small_minusc                 C   s   |j r3t|d d|  tdt t | |  t|d d|  tdt t |d  |   d S |d8 }t|d d|  tdt t | |d   t|d d|  tdt t | |   d S r'  r:  r   r   r   r   ra   rr   rd   r   r7   r7   r8   r    s   *..*zHyperRep_sqrts1._expr_bigc                 C   s   |j r!d| | tdt t | |  td| tt|  S d| | tdt t | |  td| tt| dt |   S r'  )r:  r   r   r   r   r   r   rG  r7   r7   r8   r    s   <HzHyperRep_sqrts1._expr_big_minusNr)  r7   r7   r7   r8   rD    s    


	rD  c                   @   <   e Zd ZdZedd Zedd Zedd Zdd	 Zd
S )HyperRep_sqrts2z Return a representative for
          sqrt(z)/2*[(1-sqrt(z))**2a - (1 + sqrt(z))**2a]
          == -2*z/(2*a+1) d/dz hyper([-a - 1/2, -a], [1/2], z)c                 C   s4   t |dt | d|  dt | d|    d S r'  r,  rE  r7   r7   r8   r    s   4zHyperRep_sqrts2._expr_smallc                 C   s,   t |d| |  td| tt |  S r'  )r   r   r   rE  r7   r7   r8   r    r-  z!HyperRep_sqrts2._expr_small_minusc                 C   s   |j r7t|d t|d d|  tdt t | |d   t|d d|  tdt t | |    S |d8 }t|d t|d d|  tdt t | |d   t|d d|  tdt t | |    S r+  rF  rG  r7   r7   r8   r    s   8*8*zHyperRep_sqrts2._expr_bigc                 C   s   |j r%d| | tdt t | |  t| td| tt|  S d| | tdt t | |  t| td| tt| dt |   S r'  )r:  r   r   r   r   r   r   rG  r7   r7   r8   r    s
   D*"zHyperRep_sqrts2._expr_big_minusNr)  r7   r7   r7   r8   rI    s    


	rI  c                   @   rH  )HyperRep_log2zJ Represent log(1/2 + sqrt(1 - z)/2) == -z/4*hyper([3/2, 1, 1], [2, 2], z) c                 C   s   t tjtd| d  S r'  r   r   r  r   r<  r7   r7   r8   r  )     zHyperRep_log2._expr_smallc                 C   s   t tjtd| d  S r'  rK  r<  r7   r7   r8   r  -  rL  zHyperRep_log2._expr_small_minusc                 C   sr   |j r|tj t t tt|d  ttdt|   S |tj t t tt|d  ttdt|   S r+  )r:  r   r  r   r   r   r   r   r>  r7   r7   r8   r  1  s   66zHyperRep_log2._expr_bigc                 C   sR   |j rtt | ttjtd| d   S tt | ttd| d tj  S r'  )r:  r   r   r   r   r  r   r>  r7   r7   r8   r  8  s   &&zHyperRep_log2._expr_big_minusNr)  r7   r7   r7   r8   rJ  &  s    


rJ  c                   @   r#  )HyperRep_cosasinz? Represent hyper([a, -a], [1/2], z) == cos(2*a*asin(sqrt(z))). c                 C      t d| tt| S r9  )r   r   r   rE  r7   r7   r8   r  D     zHyperRep_cosasin._expr_smallc                 C   rN  r9  )r   r   r   rE  r7   r7   r8   r  H  rO  z"HyperRep_cosasin._expr_small_minusc                 C   s0   t d| tt| |t t d| d   S r+  )r   r   r   r   r   rG  r7   r7   r8   r  L  s   0zHyperRep_cosasin._expr_bigc                 C   s,   t d| tt| d| t t |  S r9  )r   r   r   r   r   rG  r7   r7   r8   r  P  r-  z HyperRep_cosasin._expr_big_minusNr)  r7   r7   r7   r8   rM  ?  s    


rM  c                   @   r#  )HyperRep_sinasinze Represent 2*a*z*hyper([1 - a, 1 + a], [3/2], z)
        == sqrt(z)/sqrt(1-z)*sin(2*a*asin(sqrt(z))) c                 C   s,   t |t d|  td| tt |  S r'  )r   r   r   rE  r7   r7   r8   r  Y  r-  zHyperRep_sinasin._expr_smallc                 C   s.   t | t d|  td| tt |  S r'  )r   r   r   rE  r7   r7   r8   r  ]  s   .z"HyperRep_sinasin._expr_small_minusc                 C   sD   dt dd|   td| tt | |t t d| d    S Nr   rJ   rL   )r   r   r   r   r   rG  r7   r7   r8   r  a  s   DzHyperRep_sinasin._expr_bigc                 C   s@   dt dd|   td| tt | d| t t |   S rQ  )r   r   r   r   r   rG  r7   r7   r8   r  e  s   @z HyperRep_sinasin._expr_big_minusNr)  r7   r7   r7   r8   rP  U  s    


rP  c                   @   s&   e Zd ZdZedd ZdddZdS )	appellf1a  
    This is the Appell hypergeometric function of two variables as:

    .. math ::
        F_1(a,b_1,b_2,c,x,y) = \sum_{m=0}^{\infty} \sum_{n=0}^{\infty}
        \frac{(a)_{m+n} (b_1)_m (b_2)_n}{(c)_{m+n}}
        \frac{x^m y^n}{m! n!}.

    Examples
    ========

    >>> from sympy import appellf1, symbols
    >>> x, y, a, b1, b2, c = symbols('x y a b1 b2 c')
    >>> appellf1(2., 1., 6., 4., 5., 6.)
    0.0063339426292673
    >>> appellf1(12., 12., 6., 4., 0.5, 0.12)
    172870711.659936
    >>> appellf1(40, 2, 6, 4, 15, 60)
    appellf1(40, 2, 6, 4, 15, 60)
    >>> appellf1(20., 12., 10., 3., 0.5, 0.12)
    15605338197184.4
    >>> appellf1(40, 2, 6, 4, x, y)
    appellf1(40, 2, 6, 4, x, y)
    >>> appellf1(a, b1, b2, c, x, y)
    appellf1(a, b1, b2, c, x, y)

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Appell_series
    .. [2] https://functions.wolfram.com/HypergeometricFunctions/AppellF1/

    c                 C   s   t |t |kr||}}||}}| ||||||S ||kr5t |t |kr5||}}| ||||||S |dkr@|dkrBtjS d S d S r   )r   r   r   )ra   rr   b1b2rj   r6   r   r7   r7   r8   rn     s   


zappellf1.evalr   c                 C   s   | j \}}}}}}|dkr"|| | t|d |d ||d || S |dkr;|| | t|d ||d |d || S |dv rIt| | j |d  S t| |)Nr   rJ      )rJ   rL   rK   r   )r:   rR  r   r	   )r;   rv   rr   rS  rT  rj   r6   r   r7   r7   r8   rQ     s   **
zappellf1.fdiffN)r   )rB   rC   rD   rY   r   rn   rQ   r7   r7   r7   r8   rR  i  s
    "
rR  N)RrY   collectionsr   
sympy.corer   r   sympy.core.addr   sympy.core.exprr   sympy.core.functionr   r   r	   sympy.core.containersr
   sympy.core.mulr   sympy.core.numbersr   r   r   r   sympy.core.parametersr   sympy.core.relationalr   sympy.core.sortingr   sympy.core.symbolr   sympy.external.gmpyr   sympy.functionsr   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   $sympy.functions.elementary.complexesr$   r%   r&   &sympy.functions.elementary.exponentialr'   #sympy.functions.elementary.integersr(   $sympy.functions.elementary.piecewiser)   sympy.logic.boolalgr*   r+   sympyr,   r-   rH   rI   r[   r   r  r$  r*  r2  r6  r;  r?  rD  rI  rJ  rM  rP  rR  r7   r7   r7   r8   <module>   sZ    <  /   F