o
    GZh&                     @   s  d Z ddlmZ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mZm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 ddl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'm(Z(m)Z)m*Z* ddl+m,Z, ddl-m.Z.m/Z/m0Z0 ddl1m2Z2 ddl3m4Z4m5Z5m6Z6m7Z7 ddl8m9Z9 ddl:m;Z; ddl<m=Z= ddl>m?Z? ddl@mAZAmBZB ddlCmDZD ddlEmFZFmGZGmHZHmIZImJZJ ddlKmLZL ddlMmNZNmOZO ddlPmQZQ ddlRmSZS ddlTmUZU G d d! d!eVZWG d"d# d#eZXd$d% ZYd&d' ZZeZd(Z[d)d* Z\e[e\d+fd,d-Z]G d.d/ d/eXZ^d0d1 Z_d2d3 Z`G d4d5 d5eaZbd6d7 ZceZd+dkd8d9Zdd:aeG d;d< d<eXZfd=d> ZgeZd+dld?d@ZhG dAdB dBeXZiG dCdD dDeiZjdEdF ZkG dGdH dHeiZldIdJ ZmeZd+dldKdLZnG dMdN dNeXZoG dOdP dPeoZpdQdR ZqG dSdT dTeoZrdUdV ZsG dWdX dXeoZtdYdZ ZuG d[d\ d\eoZvd]d^ ZweZd+dld_d`ZxG dadb dbeXZyG dcdd ddeyZzdedf Z{G dgdh dheyZ|didj Z}dd:l~m  mZ ejZejZejZejZejZejZd:S )mz Integral Transforms     )reducewraps)repeat)Spi)Add)AppliedUndef	count_opsexpand
expand_mulFunction)Mul)igcdilcm)default_sort_key)Dummy)postorder_traversal)	factorialrf)reargAbs)exp	exp_polar)coshcothsinhtanh)ceiling)MaxMinsqrt)piecewise_fold)coscotsintan)besselj)	Heaviside)gamma)meijerg)	integrateIntegral)_dummy)to_cnf	conjuncts	disjunctsOrAnd)roots)factorPoly)CRootOf)iterable)debugc                       s    e Zd ZdZ fddZ  ZS )IntegralTransformErrora  
    Exception raised in relation to problems computing transforms.

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

    This class is mostly used internally; if integrals cannot be computed
    objects representing unevaluated transforms are usually returned.

    The hint ``needeval=True`` can be used to disable returning transform
    objects, and instead raise this exception if an integral cannot be
    computed.
    c                    s   t  d||f  || _d S )Nz'%s Transform could not be computed: %s.)super__init__function)selfZ	transformr<   msg	__class__ I/var/www/auris/lib/python3.10/site-packages/sympy/integrals/transforms.pyr;   6   s   

zIntegralTransformError.__init__)__name__
__module____qualname____doc__r;   __classcell__rA   rA   r?   rB   r9   (   s    r9   c                   @   s|   e Zd Z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d Zdd Zdd Zedd Zdd ZdS )IntegralTransforma}  
    Base class for integral transforms.

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

    This class represents unevaluated transforms.

    To implement a concrete transform, derive from this class and implement
    the ``_compute_transform(f, x, s, **hints)`` and ``_as_integral(f, x, s)``
    functions. If the transform cannot be computed, raise :obj:`IntegralTransformError`.

    Also set ``cls._name``. For instance,

    >>> from sympy import LaplaceTransform
    >>> LaplaceTransform._name
    'Laplace'

    Implement ``self._collapse_extra`` if your function returns more than just a
    number and possibly a convergence condition.
    c                 C   
   | j d S )z! The function to be transformed. r   argsr=   rA   rA   rB   r<   S      
zIntegralTransform.functionc                 C   rI   )z; The dependent variable of the function to be transformed.    rJ   rL   rA   rA   rB   function_variableX   rM   z#IntegralTransform.function_variablec                 C   rI   )z% The independent transform variable.    rJ   rL   rA   rA   rB   transform_variable]   rM   z$IntegralTransform.transform_variablec                 C   s   | j j| jh| jh S )zj
        This method returns the symbols that will exist when the transform
        is evaluated.
        )r<   free_symbolsunionrQ   rO   rL   rA   rA   rB   rR   b   s   zIntegralTransform.free_symbolsc                 K      t NNotImplementedErrorr=   fxshintsrA   rA   rB   _compute_transformk      z$IntegralTransform._compute_transformc                 C   rT   rU   rV   r=   rY   rZ   r[   rA   rA   rB   _as_integraln   r^   zIntegralTransform._as_integralc                 C   s$   t | }|dkrt| jjd d|S )NF )r2   r9   r@   name)r=   extracondrA   rA   rB   _collapse_extraq   s   z!IntegralTransform._collapse_extrac                    s   d }t  fdd jtD  }|r4z j j j jfi |}W n ty3   td d }Y nw  j}|j	s>t
|}||fS )Nc                 3   s    | ]	}|  jV  qd S rU   )hasrO   ).0funcrL   rA   rB   	<genexpr>y   s    z2IntegralTransform._try_directly.<locals>.<genexpr>z6[IT _try ] Caught IntegralTransformError, returns None)anyr<   atomsr   r]   rO   rQ   r9   r8   is_Addr   )r=   r\   TZtry_directlyfnrA   rL   rB   _try_directlyw   s&   


zIntegralTransform._try_directlyc                    s    dd}  dd}| d< jdi  \}}|dur |S |jr| d<  fdd|jD }g }g }|D ].}	t|	tsB|	g}	||	d  t|	d	krW||	d
  q8t|	d	krf||	d
d g7 }q8|dkrrt| 	 }nt| }|sz|S z
|}t|r|ft| W S ||fW S  ty   Y nw |rtjjjd|j\}
}|
jt| gtjd
d    S )a  
        Try to evaluate the transform in closed form.

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

        This general function handles linearity, but apart from that leaves
        pretty much everything to _compute_transform.

        Standard hints are the following:

        - ``simplify``: whether or not to simplify the result
        - ``noconds``: if True, do not return convergence conditions
        - ``needeval``: if True, raise IntegralTransformError instead of
                        returning IntegralTransform objects

        The default values of these hints depend on the concrete transform,
        usually the default is
        ``(simplify, noconds, needeval) = (True, False, False)``.
        needevalFsimplifyTNc                    s6   g | ]}j |gtjd d   jdi  qS )rN   NrA   )r@   listrK   doitrg   rZ   r\   r=   rA   rB   
<listcomp>   s    .z*IntegralTransform.doit.<locals>.<listcomp>r   rP   rN   rA   )popro   rl   rK   
isinstancetupleappendlenr   rq   re   r7   r9   r@   _namer<   as_coeff_mulrO   r   rr   )r=   r\   rp   rq   rn   rm   resrc   ressrZ   coeffrestrA   ru   rB   rs      sR   


&zIntegralTransform.doitc                 C   s   |  | j| j| jS rU   )r`   r<   rO   rQ   rL   rA   rA   rB   as_integral   s   zIntegralTransform.as_integralc                 O   s   | j S rU   )r   )r=   rK   kwargsrA   rA   rB   _eval_rewrite_as_Integral      z+IntegralTransform._eval_rewrite_as_IntegralN)rC   rD   rE   rF   propertyr<   rO   rQ   rR   r]   r`   re   ro   rs   r   r   rA   rA   rA   rB   rH   <   s$    



G
rH   c                 C   s4   |rddl m} ddlm} ||t| ddS | S )Nr   )rq   )	powdenestT)Zpolar)sympy.simplifyrq   Zsympy.simplify.powsimpr   r"   )exprrs   rq   r   rA   rA   rB   	_simplify   s
   r   c                    s    fdd}|S )aV  
    This is a decorator generator for dropping convergence conditions.

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

    Suppose you define a function ``transform(*args)`` which returns a tuple of
    the form ``(result, cond1, cond2, ...)``.

    Decorating it ``@_noconds_(default)`` will add a new keyword argument
    ``noconds`` to it. If ``noconds=True``, the return value will be altered to
    be only ``result``, whereas if ``noconds=False`` the return value will not
    be altered.

    The default value of the ``noconds`` keyword will be ``default`` (i.e. the
    argument of this function).
    c                    s   t  d fdd
}|S )Nnocondsc                    s    |i |}| r|d S |S Nr   rA   )r   rK   r   r~   rh   rA   rB   wrapper   s   z0_noconds_.<locals>.make_wrapper.<locals>.wrapper)r   )rh   r   defaultr   rB   make_wrapper   s   z_noconds_.<locals>.make_wrapperrA   )r   r   rA   r   rB   	_noconds_   s   r   Fc                 C   s   t | |tjtjfS rU   )r+   r   ZeroInfinity)rY   rZ   rA   rA   rB   _default_integrator     r   Tc                    s   t dd| ||d  |  |}|ts't|||tjtjftjfS |j	s0t
d| d|jd \}}|trBt
d| dfdd	  fd
dt|D }dd |D }|jdd d |sjt
d| d|d \}}	}
t|||||	f|
fS )z0 Backend function to compute Mellin transforms. r[   zmellin-transformrN   Mellincould not compute integralr   integral in unexpected formc                    sH  ddl m} tj}tj}tj}tt| }tddd}|D ]}tj}tj}	g }
t	|D ]M}|
tdd t |}|jrM|jdv sM| sM||sS|
|g7 }
q+|||}|jr`|jdv rf|
|g7 }
q+|j|krrt|j|	}	q+t|j|}q+|tjur||krt||}q|	tjur|	|krt|	|}qt|t|
 }q|||fS )	zN
        Turn ``cond`` into a strip (a, b), and auxiliary conditions.
        r   )_solve_inequalitytT)realc                 S   s   |   d S r   )as_real_imagrZ   rA   rA   rB   <lambda>)  s    z:_mellin_transform.<locals>.process_conds.<locals>.<lambda>)z==z!=)Zsympy.solvers.inequalitiesr   r   NegativeInfinityr   truer/   r.   r   r0   replacer   subsZis_RelationalZrel_oprf   Zltsr   Zgtsr    r2   r1   )rd   r   abauxcondsr   ca_b_Zaux_dZd_Zsoln)r[   rA   rB   process_conds  sL   






z(_mellin_transform.<locals>.process_condsc                    s   g | ]} |qS rA   rA   rg   r   )r   rA   rB   rv   @      z%_mellin_transform.<locals>.<listcomp>c                 S   s   g | ]
}|d  dkr|qS )rP   FrA   rt   rA   rA   rB   rv   A      c                 S   s   | d | d  t | d fS )Nr   rN   rP   )r	   r   rA   rA   rB   r   B  r   z#_mellin_transform.<locals>.<lambda>keyzno convergence found)r-   rf   r,   r   r   r   r   r   r   is_Piecewiser9   rK   r0   sort)rY   rZ   Zs_Z
integratorrq   Frd   r   r   r   r   rA   )r   r[   rB   _mellin_transform  s&   
"
'r   c                   @   s,   e Zd ZdZdZdd Zdd Zdd Zd	S )
MellinTransformz
    Class representing unevaluated Mellin transforms.

    For usage of this class, see the :class:`IntegralTransform` docstring.

    For how to compute Mellin transforms, see the :func:`mellin_transform`
    docstring.
    r   c                 K   s   t |||fi |S rU   )r   rX   rA   rA   rB   r]   W  r   z"MellinTransform._compute_transformc                 C   s    t |||d   |tjtjfS NrN   )r,   r   r   r   r_   rA   rA   rB   r`   Z  s    zMellinTransform._as_integralc           	      C   s   g }g }g }|D ]\\}}}||g7 }||g7 }||g7 }qt | t| ft| f}|d d |d d kdks>|d dkrDtdd d|S )Nr   rN   TFr   zno combined convergence.)r   r    r2   r9   )	r=   rc   r   r   rd   sasbr   r~   rA   rA   rB   re   ]  s   

(zMellinTransform._collapse_extraN)rC   rD   rE   rF   r|   r]   r`   re   rA   rA   rA   rB   r   K  s    	r   c                 K      t | ||jdi |S )a  
    Compute the Mellin transform `F(s)` of `f(x)`,

    .. math :: F(s) = \int_0^\infty x^{s-1} f(x) \mathrm{d}x.

    For all "sensible" functions, this converges absolutely in a strip
      `a < \operatorname{Re}(s) < b`.

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

    The Mellin transform is related via change of variables to the Fourier
    transform, and also to the (bilateral) Laplace transform.

    This function returns ``(F, (a, b), cond)``
    where ``F`` is the Mellin transform of ``f``, ``(a, b)`` is the fundamental strip
    (as above), and ``cond`` are auxiliary convergence conditions.

    If the integral cannot be computed in closed form, this function returns
    an unevaluated :class:`MellinTransform` object.

    For a description of possible hints, refer to the docstring of
    :func:`sympy.integrals.transforms.IntegralTransform.doit`. If ``noconds=False``,
    then only `F` will be returned (i.e. not ``cond``, and also not the strip
    ``(a, b)``).

    Examples
    ========

    >>> from sympy import mellin_transform, exp
    >>> from sympy.abc import x, s
    >>> mellin_transform(exp(-x), x, s)
    (gamma(s), (0, oo), True)

    See Also
    ========

    inverse_mellin_transform, laplace_transform, fourier_transform
    hankel_transform, inverse_hankel_transform
    NrA   )r   rs   )rY   rZ   r[   r\   rA   rA   rB   mellin_transforml  s   )r   c                 C   sp   | \}}t |t }t |t }t| | | d  }t|| | | td| | ||  d| t fS )a  
    Re-write the sine function ``sin(m*s + n)`` as gamma functions, compatible
    with the strip (a, b).

    Return ``(gamma1, gamma2, fac)`` so that ``f == fac/(gamma1 * gamma2)``.

    Examples
    ========

    >>> from sympy.integrals.transforms import _rewrite_sin
    >>> from sympy import pi, S
    >>> from sympy.abc import s
    >>> _rewrite_sin((pi, 0), s, 0, 1)
    (gamma(s), gamma(1 - s), pi)
    >>> _rewrite_sin((pi, 0), s, 1, 0)
    (gamma(s - 1), gamma(2 - s), -pi)
    >>> _rewrite_sin((pi, 0), s, -1, 0)
    (gamma(s + 1), gamma(-s), -pi)
    >>> _rewrite_sin((pi, pi/2), s, S(1)/2, S(3)/2)
    (gamma(s - 1/2), gamma(3/2 - s), -pi)
    >>> _rewrite_sin((pi, pi), s, 0, 1)
    (gamma(s), gamma(1 - s), -pi)
    >>> _rewrite_sin((2*pi, 0), s, 0, S(1)/2)
    (gamma(2*s), gamma(1 - 2*s), pi)
    >>> _rewrite_sin((2*pi, 0), s, S(1)/2, 1)
    (gamma(2*s - 1), gamma(2 - 2*s), -pi)
    r   rN   )r   r   r   r   r)   )Zm_nr[   r   r   mnrrA   rA   rB   _rewrite_sin  s
   %6r   c                   @   s   e Zd ZdZdS )MellinTransformStripErrorzF
    Exception raised by _rewrite_gamma. Mainly for internal use.
    N)rC   rD   rE   rF   rA   rA   rA   rB   r     s    r   c           -         s  t ||g\  fdd}g }tD ]#}|sq|jd }|jr-|d }|\}}	||g7 }qtt	t
tD ]%}|sJqB|jd }|jrY|d }|\}}	||t g7 }qBdd |D }t j|D ]	}
|
js}|
 nqtfdd|D }tdd	 |D rjstd
ddttdd |D t j }|krt|dkr}nttdd |D  }| t j| }t j| } durڈ |9  dur|9  \}}t|}t|}tt|tdtt|td }g }g }g }g }g }fdd|r| \r(||}}|}n||}}|}fdd}sD|g7 }njsNtt rjrYj!}j }nt"d}j }|j#r{}|dk rn| }|||fgt$| 7 }q|s||\}}sd| }||| g7 }||| g7 }ng%r#t&}|' dkr|( d }t)|}t||' krt*+|}||g7 }|fdd|D 7 }q|, \}}||g7 }||  }||r|t j| d fg7 }|t j| fg7 }n|dg7 }|t j-|d fg7 }|t j-|fg7 }nttra|jd \}}rY|dkrE|| | dksU|dk rY|| | dkrYt.d|||fg7 }nttrjd }rt|t td|t  t} }!}"nt/|| \} }!}"||  f|! fg7 }||"g7 }nett
rÈjd }|t|ddfttd | dd fg7 }nBtt	rވjd }|ttd | ddfg7 }n'ttrjd }|ttd | ddft|dd fg7 }n|s|t| t|  9 }g g g g f\}#}$}%}&||#|%df||&|$dffD ]\}'}(})|'r|' \}}|dkr|dkrt$t |}|| }*|| }+|j#sWt0dt1|D ]},|'|*|+|,|  fg7 }'q[r|dt d| d  ||t j2   9 }||| g7 }n|dt d| d  ||t j2    }|||  g7 }q.|dkr|(3d|  n|)3| |'s1q(t| }|#j4t5d |$j4t5d |%j4t5d |&j4t5d |#|$f|%|&f|||fS )a  
    Try to rewrite the product f(s) as a product of gamma functions,
    so that the inverse Mellin transform of f can be expressed as a meijer
    G function.

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

    Return (an, ap), (bm, bq), arg, exp, fac such that
    G((an, ap), (bm, bq), arg/z**exp)*fac is the inverse Mellin transform of f(s).

    Raises IntegralTransformError or MellinTransformStripError on failure.

    It is asserted that f has no poles in the fundamental strip designated by
    (a, b). One of a and b is allowed to be None. The fundamental strip is
    important, because it determines the inversion contour.

    This function can handle exponentials, linear factors, trigonometric
    functions.

    This is a helper function for inverse_mellin_transform that will not
    attempt any transformations on f.

    Examples
    ========

    >>> from sympy.integrals.transforms import _rewrite_gamma
    >>> from sympy.abc import s
    >>> from sympy import oo
    >>> _rewrite_gamma(s*(s+3)*(s-1), s, -oo, oo)
    (([], [-3, 0, 1]), ([-2, 1, 2], []), 1, 1, -1)
    >>> _rewrite_gamma((s-1)**2, s, -oo, oo)
    (([], [1, 1]), ([2, 2], []), 1, 1, 1)

    Importance of the fundamental strip:

    >>> _rewrite_gamma(1/s, s, 0, oo)
    (([1], []), ([], [0]), 1, 1, 1)
    >>> _rewrite_gamma(1/s, s, None, oo)
    (([1], []), ([], [0]), 1, 1, 1)
    >>> _rewrite_gamma(1/s, s, 0, None)
    (([1], []), ([], [0]), 1, 1, 1)
    >>> _rewrite_gamma(1/s, s, -oo, 0)
    (([], [1]), ([0], []), 1, 1, -1)
    >>> _rewrite_gamma(1/s, s, None, 0)
    (([], [1]), ([0], []), 1, 1, -1)
    >>> _rewrite_gamma(1/s, s, -oo, None)
    (([], [1]), ([0], []), 1, 1, -1)

    >>> _rewrite_gamma(2**(-s+3), s, -oo, oo)
    (([], []), ([], []), 1/2, 1, 8)
    c                    s   t t| }  du rtju rdS  du r| k S du r!|  kS | kdkr)dS |  kdkr1dS |r5dS  js>js>| jr@dS td)zU
        Decide whether pole at c lies to the left of the fundamental strip.
        NTFzPole inside critical strip?)r
   r   r   r   rR   r   )r   is_numer)r   r   rA   rB   left  s    z_rewrite_gamma.<locals>.leftr   rN   c                 S   s   g | ]}|j rt|n|qS rA   )is_extended_realr   rt   rA   rA   rB   rv   8  s    z"_rewrite_gamma.<locals>.<listcomp>c                    s   g | ]}|  qS rA   rA   rt   )common_coefficientrA   rB   rv   >  r   c                 s   s    | ]}|j V  qd S rU   )is_Rationalrt   rA   rA   rB   ri   ?  s    z!_rewrite_gamma.<locals>.<genexpr>GammaNzNonrational multiplierc                 S      g | ]}t |jqS rA   )r   qrt   rA   rA   rB   rv   B  s    c                 S   r   rA   )r   prt   rA   rA   rB   rv   I  s    TFc                    s   t d d|  S )NInverse MellinzUnrecognised form '%s'.)r9   )fact)rY   rA   rB   	exceptiona     z!_rewrite_gamma.<locals>.exceptionc                    s8   |  s	 t| }| dkr | S )z7 Test if arg is of form a*s+b, raise exception if not. rN   )is_polynomialr5   degree
all_coeffs)r   r   )r   r   r[   rA   rB   
linear_argl  s   

z"_rewrite_gamma.<locals>.linear_argc                    s   g | ]}|  fqS rA   rA   r   )r   r[   rA   rB   rv     s    r   z Gammas partially over the strip.)evaluaterP   za is not an integerr   )6r   rk   r)   rf   rK   rl   Zas_independentr}   r%   r#   r&   r$   r   Oner   allr   r9   r   r   r{   r   r   Zas_numer_denomr   Z	make_argsrr   zipr   rw   Zis_Powrx   r   baser   Z
is_Integerr   r   r5   r   LTr3   r6   Z	all_rootsr   ZNegativeOnerW   r   	TypeErrorrangeZHalfrz   r   r   )-rY   r[   r   r   r   Zs_multipliersgr   r   _rZ   Zs_multiplierfacexponentZnumerdenomrK   ZfacsZdfacsZnumer_gammasZdenom_gammasZexponentialsZugammasZlgammasZufacsr   r   Zexp_rd   r   rsr   Zgamma1Zgamma2Zfac_ZanapZbmbqZgammasplusminusZnewaZnewckrA   )r   r   r   r   rY   r   r   r[   rB   _rewrite_gamma  sT  ?







$










  
&

 
h

&&

r   c              	      sB  t dd| dd| t} t| t| t| fD ]}|jrT fdd|jD }dd |D }dd |D }t| } sHt||	t
d	}||t| f  S zt|d
 d \}	}
}}}W n	 tyo   Y qw zt|	|
||  }W n	 ty   Y qw  r|}nDzd
dlm} ||}W n ty   td| dw |jrt|jdkrt
t| |jd
 jd
  t
t| |jd jd
   }tt|j|jt k g}|ttt|jt|jkd
t|jd ktt|j|jt kg7 }t| }|dkrtd| d|| ||f  S td| d)zs A helper for the real inverse_mellin_transform function, this one here
        assumes x to be real and positive. r   zinverse-mellin-transformT)Zpositivec              
      s    g | ]}t | d dqS )Fr   )_inverse_mellin_transform)rg   G
as_meijergr[   striprZ   rA   rB   rv     s
    
z-_inverse_mellin_transform.<locals>.<listcomp>c                 S      g | ]}|d  qS )rN   rA   rg   r   rA   rA   rB   rv     r   c                 S   r   )r   rA   r   rA   rA   rB   rv     r   )Zgensr   rN   )hyperexpandr   zCould not calculate integral   Fzdoes not convergera   ) r-   Zrewriter)   r4   r   r
   rl   rK   r   rk   r(   r   r2   r   r9   r*   
ValueErrorr   r   rW   r   r{   r   r   argumentdeltar   r1   r   r   r   nu)r   r[   Zx_r   r   r   r   r   r~   r   r   Cer   r   hr   rd   rA   r   rB   r     s`   
$*
r   Nc                   @   sH   e Zd ZdZdZedZedZdd Ze	dd Z
d	d
 Zdd ZdS )InverseMellinTransformz
    Class representing unevaluated inverse Mellin transforms.

    For usage of this class, see the :class:`IntegralTransform` docstring.

    For how to compute inverse Mellin transforms, see the
    :func:`inverse_mellin_transform` docstring.
    r   Noner   c                 K   s8   |d u rt j}|d u rt j}tj| |||||fi |S rU   )r   _none_sentinelrH   __new__)clsr   r[   rZ   r   r   optsrA   rA   rB   r   C  s
   zInverseMellinTransform.__new__c                 C   s:   | j d | j d }}|tju rd }|tju rd }||fS )Nr      )rK   r   r   )r=   r   r   rA   rA   rB   fundamental_stripJ  s   

z(InverseMellinTransform.fundamental_stripc                 K   s   | dd td u rtttttttt	t
ttthat|D ]}|jr3||r3|jtvr3td|d| q| j}t||||fi |S )Nrq   Tr   zComponent %s not recognised.)rw   _allowedr   r)   r%   r#   r&   r$   r   r   r   r   r   r   r   Zis_Functionrf   rh   r9   r   r   )r=   r   r[   rZ   r\   rY   r   rA   rA   rB   r]   S  s   z)InverseMellinTransform._compute_transformc                 C   sJ   | j j}t|||   ||tjtj  |tjtj  fdtj tj  S NrP   )r@   _cr,   r   ImaginaryUnitr   Pi)r=   r   r[   rZ   r   rA   rA   rB   r`   c  s    
z#InverseMellinTransform._as_integralN)rC   rD   rE   rF   r|   r   r   r  r   r   r   r]   r`   rA   rA   rA   rB   r   5  s    	
r   c                 K   s$   t | |||d |d jdi |S )a"  
    Compute the inverse Mellin transform of `F(s)` over the fundamental
    strip given by ``strip=(a, b)``.

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

    This can be defined as

    .. math:: f(x) = \frac{1}{2\pi i} \int_{c - i\infty}^{c + i\infty} x^{-s} F(s) \mathrm{d}s,

    for any `c` in the fundamental strip. Under certain regularity
    conditions on `F` and/or `f`,
    this recovers `f` from its Mellin transform `F`
    (and vice versa), for positive real `x`.

    One of `a` or `b` may be passed as ``None``; a suitable `c` will be
    inferred.

    If the integral cannot be computed in closed form, this function returns
    an unevaluated :class:`InverseMellinTransform` object.

    Note that this function will assume x to be positive and real, regardless
    of the SymPy assumptions!

    For a description of possible hints, refer to the docstring of
    :func:`sympy.integrals.transforms.IntegralTransform.doit`.

    Examples
    ========

    >>> from sympy import inverse_mellin_transform, oo, gamma
    >>> from sympy.abc import x, s
    >>> inverse_mellin_transform(gamma(s), s, x, (0, oo))
    exp(-x)

    The fundamental strip matters:

    >>> f = 1/(s**2 - 1)
    >>> inverse_mellin_transform(f, s, x, (-oo, -1))
    x*(1 - 1/x**2)*Heaviside(x - 1)/2
    >>> inverse_mellin_transform(f, s, x, (-1, 1))
    -x*Heaviside(1 - x)/2 - Heaviside(x - 1)/(2*x)
    >>> inverse_mellin_transform(f, s, x, (1, oo))
    (1/2 - x**2/2)*Heaviside(1 - x)/x

    See Also
    ========

    mellin_transform
    hankel_transform, inverse_hankel_transform
    r   rN   NrA   )r   rs   )r   r[   rZ   r   r\   rA   rA   rB   inverse_mellin_transformi  s   $5r  c           
      C   s   t ||  t|tj | |  |tjtjf}|ts$t||tj	fS t | |tjtjf}|tjtjtj
fv s=|trCt|| d|jsLt|| d|jd \}}	|tr^t|| dt|||	fS )z
    Compute a general Fourier-type transform

    .. math::

        F(k) = a \int_{-\infty}^{\infty} e^{bixk} f(x)\, dx.

    For suitable choice of *a* and *b*, this reduces to the standard Fourier
    and inverse Fourier transforms.
    z$function not integrable on real axisr   r   r   )r+   r   r   r  r   r   rf   r,   r   r   NaNr9   r   rK   )
rY   rZ   r   r   r   rb   rq   r   Z
integral_frd   rA   rA   rB   _fourier_transform  s   .

r  c                   @   0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )FourierTypeTransformz# Base class for Fourier transforms.c                 C      t d| j Nz,Class %s must implement a(self) but does notrW   r@   rL   rA   rA   rB   r        zFourierTypeTransform.ac                 C   r
  Nz,Class %s must implement b(self) but does notr  rL   rA   rA   rB   r     r  zFourierTypeTransform.bc                 K   s&   t ||||  |  | jjfi |S rU   )r  r   r   r@   r|   r=   rY   rZ   r   r\   rA   rA   rB   r]     s   z'FourierTypeTransform._compute_transformc                 C   s>   |   }|  }t|| t|tj | |  |tjtjfS rU   )r   r   r,   r   r   r  r   r   )r=   rY   rZ   r   r   r   rA   rA   rB   r`     s   .z!FourierTypeTransform._as_integralNrC   rD   rE   rF   r   r   r]   r`   rA   rA   rA   rB   r	    s    r	  c                   @   $   e Zd ZdZdZdd Zdd ZdS )FourierTransformz
    Class representing unevaluated Fourier transforms.

    For usage of this class, see the :class:`IntegralTransform` docstring.

    For how to compute Fourier transforms, see the :func:`fourier_transform`
    docstring.
    ZFourierc                 C      dS r   rA   rL   rA   rA   rB   r     r^   zFourierTransform.ac                 C   
   dt j S )Nr   r  rL   rA   rA   rB   r        
zFourierTransform.bNrC   rD   rE   rF   r|   r   r   rA   rA   rA   rB   r    
    	r  c                 K   r   )a  
    Compute the unitary, ordinary-frequency Fourier transform of ``f``, defined
    as

    .. math:: F(k) = \int_{-\infty}^\infty f(x) e^{-2\pi i x k} \mathrm{d} x.

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

    If the transform cannot be computed in closed form, this
    function returns an unevaluated :class:`FourierTransform` object.

    For other Fourier transform conventions, see the function
    :func:`sympy.integrals.transforms._fourier_transform`.

    For a description of possible hints, refer to the docstring of
    :func:`sympy.integrals.transforms.IntegralTransform.doit`.
    Note that for this transform, by default ``noconds=True``.

    Examples
    ========

    >>> from sympy import fourier_transform, exp
    >>> from sympy.abc import x, k
    >>> fourier_transform(exp(-x**2), x, k)
    sqrt(pi)*exp(-pi**2*k**2)
    >>> fourier_transform(exp(-x**2), x, k, noconds=False)
    (sqrt(pi)*exp(-pi**2*k**2), True)

    See Also
    ========

    inverse_fourier_transform
    sine_transform, inverse_sine_transform
    cosine_transform, inverse_cosine_transform
    hankel_transform, inverse_hankel_transform
    mellin_transform, laplace_transform
    NrA   )r  rs   rY   rZ   r   r\   rA   rA   rB   fourier_transform     'r  c                   @   r  )InverseFourierTransformz
    Class representing unevaluated inverse Fourier transforms.

    For usage of this class, see the :class:`IntegralTransform` docstring.

    For how to compute inverse Fourier transforms, see the
    :func:`inverse_fourier_transform` docstring.
    zInverse Fourierc                 C   r  r   rA   rL   rA   rA   rB   r   #  r^   zInverseFourierTransform.ac                 C   r  r  r  rL   rA   rA   rB   r   &  r  zInverseFourierTransform.bNr  rA   rA   rA   rB   r    r  r  c                 K   r   )a  
    Compute the unitary, ordinary-frequency inverse Fourier transform of `F`,
    defined as

    .. math:: f(x) = \int_{-\infty}^\infty F(k) e^{2\pi i x k} \mathrm{d} k.

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

    If the transform cannot be computed in closed form, this
    function returns an unevaluated :class:`InverseFourierTransform` object.

    For other Fourier transform conventions, see the function
    :func:`sympy.integrals.transforms._fourier_transform`.

    For a description of possible hints, refer to the docstring of
    :func:`sympy.integrals.transforms.IntegralTransform.doit`.
    Note that for this transform, by default ``noconds=True``.

    Examples
    ========

    >>> from sympy import inverse_fourier_transform, exp, sqrt, pi
    >>> from sympy.abc import x, k
    >>> inverse_fourier_transform(sqrt(pi)*exp(-(pi*k)**2), k, x)
    exp(-x**2)
    >>> inverse_fourier_transform(sqrt(pi)*exp(-(pi*k)**2), k, x, noconds=False)
    (exp(-x**2), True)

    See Also
    ========

    fourier_transform
    sine_transform, inverse_sine_transform
    cosine_transform, inverse_cosine_transform
    hankel_transform, inverse_hankel_transform
    mellin_transform, laplace_transform
    NrA   )r  rs   r   r   rZ   r\   rA   rA   rB   inverse_fourier_transform*  r  r  c           
      C   s   t ||  ||| |  |tjtjf}|ts!t||tjfS |js*t	|| d|j
d \}}	|tr<t	|| dt|||	fS )a  
    Compute a general sine or cosine-type transform
        F(k) = a int_0^oo b*sin(x*k) f(x) dx.
        F(k) = a int_0^oo b*cos(x*k) f(x) dx.

    For suitable choice of a and b, this reduces to the standard sine/cosine
    and inverse sine/cosine transforms.
    r   r   r   )r+   r   r   r   rf   r,   r   r   r   r9   rK   )
rY   rZ   r   r   r   Krb   rq   r   rd   rA   rA   rB   _sine_cosine_transformX  s   (


r!  c                   @   r  )SineCosineTypeTransformzK
    Base class for sine and cosine transforms.
    Specify cls._kern.
    c                 C   r
  r  r  rL   rA   rA   rB   r   w  r  zSineCosineTypeTransform.ac                 C   r
  r  r  rL   rA   rA   rB   r   {  r  zSineCosineTypeTransform.bc                 K   s,   t ||||  |  | jj| jjfi |S rU   )r!  r   r   r@   _kernr|   r  rA   rA   rB   r]     s   z*SineCosineTypeTransform._compute_transformc                 C   s@   |   }|  }| jj}t|| ||| |  |tjtjfS rU   )r   r   r@   r#  r,   r   r   r   )r=   rY   rZ   r   r   r   r   rA   rA   rB   r`     s   (z$SineCosineTypeTransform._as_integralNr  rA   rA   rA   rB   r"  q  s    r"  c                   @   (   e Zd ZdZdZeZdd Zdd ZdS )SineTransformz
    Class representing unevaluated sine transforms.

    For usage of this class, see the :class:`IntegralTransform` docstring.

    For how to compute sine transforms, see the :func:`sine_transform`
    docstring.
    ZSinec                 C      t dt t S r  r!   r   rL   rA   rA   rB   r     r   zSineTransform.ac                 C      t jS rU   r   r   rL   rA   rA   rB   r     r   zSineTransform.bN	rC   rD   rE   rF   r|   r%   r#  r   r   rA   rA   rA   rB   r%        	r%  c                 K   r   )a1  
    Compute the unitary, ordinary-frequency sine transform of `f`, defined
    as

    .. math:: F(k) = \sqrt{\frac{2}{\pi}} \int_{0}^\infty f(x) \sin(2\pi x k) \mathrm{d} x.

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

    If the transform cannot be computed in closed form, this
    function returns an unevaluated :class:`SineTransform` object.

    For a description of possible hints, refer to the docstring of
    :func:`sympy.integrals.transforms.IntegralTransform.doit`.
    Note that for this transform, by default ``noconds=True``.

    Examples
    ========

    >>> from sympy import sine_transform, exp
    >>> from sympy.abc import x, k, a
    >>> sine_transform(x*exp(-a*x**2), x, k)
    sqrt(2)*k*exp(-k**2/(4*a))/(4*a**(3/2))
    >>> sine_transform(x**(-a), x, k)
    2**(1/2 - a)*k**(a - 1)*gamma(1 - a/2)/gamma(a/2 + 1/2)

    See Also
    ========

    fourier_transform, inverse_fourier_transform
    inverse_sine_transform
    cosine_transform, inverse_cosine_transform
    hankel_transform, inverse_hankel_transform
    mellin_transform, laplace_transform
    NrA   )r%  rs   r  rA   rA   rB   sine_transform     $r,  c                   @   r$  )InverseSineTransformz
    Class representing unevaluated inverse sine transforms.

    For usage of this class, see the :class:`IntegralTransform` docstring.

    For how to compute inverse sine transforms, see the
    :func:`inverse_sine_transform` docstring.
    zInverse Sinec                 C   r&  r  r'  rL   rA   rA   rB   r     r   zInverseSineTransform.ac                 C   r(  rU   r)  rL   rA   rA   rB   r     r   zInverseSineTransform.bNr*  rA   rA   rA   rB   r.    r+  r.  c                 K   r   )am  
    Compute the unitary, ordinary-frequency inverse sine transform of `F`,
    defined as

    .. math:: f(x) = \sqrt{\frac{2}{\pi}} \int_{0}^\infty F(k) \sin(2\pi x k) \mathrm{d} k.

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

    If the transform cannot be computed in closed form, this
    function returns an unevaluated :class:`InverseSineTransform` object.

    For a description of possible hints, refer to the docstring of
    :func:`sympy.integrals.transforms.IntegralTransform.doit`.
    Note that for this transform, by default ``noconds=True``.

    Examples
    ========

    >>> from sympy import inverse_sine_transform, exp, sqrt, gamma
    >>> from sympy.abc import x, k, a
    >>> inverse_sine_transform(2**((1-2*a)/2)*k**(a - 1)*
    ...     gamma(-a/2 + 1)/gamma((a+1)/2), k, x)
    x**(-a)
    >>> inverse_sine_transform(sqrt(2)*k*exp(-k**2/(4*a))/(4*sqrt(a)**3), k, x)
    x*exp(-a*x**2)

    See Also
    ========

    fourier_transform, inverse_fourier_transform
    sine_transform
    cosine_transform, inverse_cosine_transform
    hankel_transform, inverse_hankel_transform
    mellin_transform, laplace_transform
    NrA   )r.  rs   r  rA   rA   rB   inverse_sine_transform  s   %r/  c                   @   r$  )CosineTransformz
    Class representing unevaluated cosine transforms.

    For usage of this class, see the :class:`IntegralTransform` docstring.

    For how to compute cosine transforms, see the :func:`cosine_transform`
    docstring.
    ZCosinec                 C   r&  r  r'  rL   rA   rA   rB   r     r   zCosineTransform.ac                 C   r(  rU   r)  rL   rA   rA   rB   r     r   zCosineTransform.bN	rC   rD   rE   rF   r|   r#   r#  r   r   rA   rA   rA   rB   r0    r+  r0  c                 K   r   )a:  
    Compute the unitary, ordinary-frequency cosine transform of `f`, defined
    as

    .. math:: F(k) = \sqrt{\frac{2}{\pi}} \int_{0}^\infty f(x) \cos(2\pi x k) \mathrm{d} x.

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

    If the transform cannot be computed in closed form, this
    function returns an unevaluated :class:`CosineTransform` object.

    For a description of possible hints, refer to the docstring of
    :func:`sympy.integrals.transforms.IntegralTransform.doit`.
    Note that for this transform, by default ``noconds=True``.

    Examples
    ========

    >>> from sympy import cosine_transform, exp, sqrt, cos
    >>> from sympy.abc import x, k, a
    >>> cosine_transform(exp(-a*x), x, k)
    sqrt(2)*a/(sqrt(pi)*(a**2 + k**2))
    >>> cosine_transform(exp(-a*sqrt(x))*cos(a*sqrt(x)), x, k)
    a*exp(-a**2/(2*k))/(2*k**(3/2))

    See Also
    ========

    fourier_transform, inverse_fourier_transform,
    sine_transform, inverse_sine_transform
    inverse_cosine_transform
    hankel_transform, inverse_hankel_transform
    mellin_transform, laplace_transform
    NrA   )r0  rs   r  rA   rA   rB   cosine_transform  r-  r2  c                   @   r$  )InverseCosineTransformz
    Class representing unevaluated inverse cosine transforms.

    For usage of this class, see the :class:`IntegralTransform` docstring.

    For how to compute inverse cosine transforms, see the
    :func:`inverse_cosine_transform` docstring.
    zInverse Cosinec                 C   r&  r  r'  rL   rA   rA   rB   r   L  r   zInverseCosineTransform.ac                 C   r(  rU   r)  rL   rA   rA   rB   r   O  r   zInverseCosineTransform.bNr1  rA   rA   rA   rB   r3  ?  r+  r3  c                 K   r   )a(  
    Compute the unitary, ordinary-frequency inverse cosine transform of `F`,
    defined as

    .. math:: f(x) = \sqrt{\frac{2}{\pi}} \int_{0}^\infty F(k) \cos(2\pi x k) \mathrm{d} k.

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

    If the transform cannot be computed in closed form, this
    function returns an unevaluated :class:`InverseCosineTransform` object.

    For a description of possible hints, refer to the docstring of
    :func:`sympy.integrals.transforms.IntegralTransform.doit`.
    Note that for this transform, by default ``noconds=True``.

    Examples
    ========

    >>> from sympy import inverse_cosine_transform, sqrt, pi
    >>> from sympy.abc import x, k, a
    >>> inverse_cosine_transform(sqrt(2)*a/(sqrt(pi)*(a**2 + k**2)), k, x)
    exp(-a*x)
    >>> inverse_cosine_transform(1/sqrt(k), k, x)
    1/sqrt(x)

    See Also
    ========

    fourier_transform, inverse_fourier_transform,
    sine_transform, inverse_sine_transform
    cosine_transform
    hankel_transform, inverse_hankel_transform
    mellin_transform, laplace_transform
    NrA   )r3  rs   r  rA   rA   rB   inverse_cosine_transformS  r-  r4  c                 C   s   t | t|||  | |tjtjf}|ts t||tjfS |j	s)t
|| d|jd \}}|tr;t
|| dt|||fS )zv
    Compute a general Hankel transform

    .. math:: F_\nu(k) = \int_{0}^\infty f(r) J_\nu(k r) r \mathrm{d} r.
    r   r   r   )r+   r'   r   r   r   rf   r,   r   r   r   r9   rK   )rY   r   r   r   rb   rq   r   rd   rA   rA   rB   _hankel_transform~  s   &

r5  c                   @   s4   e Zd ZdZdd Zdd Zdd Zedd	 Zd
S )HankelTypeTransformz+
    Base class for Hankel transforms.
    c                 K   s$   | j | j| j| j| jd fi |S Nr   )r]   r<   rO   rQ   rK   )r=   r\   rA   rA   rB   rs     s   zHankelTypeTransform.doitc                 K   s   t ||||| jfi |S rU   )r5  r|   )r=   rY   r   r   r   r\   rA   rA   rB   r]     s   z&HankelTypeTransform._compute_transformc                 C   s&   t |t|||  | |tjtjfS rU   )r,   r'   r   r   r   )r=   rY   r   r   r   rA   rA   rB   r`     s   &z HankelTypeTransform._as_integralc                 C   s   |  | j| j| j| jd S r7  )r`   r<   rO   rQ   rK   rL   rA   rA   rB   r     s
   zHankelTypeTransform.as_integralN)	rC   rD   rE   rF   rs   r]   r`   r   r   rA   rA   rA   rB   r6    s    r6  c                   @      e Zd ZdZdZdS )HankelTransformz
    Class representing unevaluated Hankel transforms.

    For usage of this class, see the :class:`IntegralTransform` docstring.

    For how to compute Hankel transforms, see the :func:`hankel_transform`
    docstring.
    ZHankelNrC   rD   rE   rF   r|   rA   rA   rA   rB   r9        	r9  c                 K      t | |||jdi |S )a  
    Compute the Hankel transform of `f`, defined as

    .. math:: F_\nu(k) = \int_{0}^\infty f(r) J_\nu(k r) r \mathrm{d} r.

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

    If the transform cannot be computed in closed form, this
    function returns an unevaluated :class:`HankelTransform` object.

    For a description of possible hints, refer to the docstring of
    :func:`sympy.integrals.transforms.IntegralTransform.doit`.
    Note that for this transform, by default ``noconds=True``.

    Examples
    ========

    >>> from sympy import hankel_transform, inverse_hankel_transform
    >>> from sympy import exp
    >>> from sympy.abc import r, k, m, nu, a

    >>> ht = hankel_transform(1/r**m, r, k, nu)
    >>> ht
    2*k**(m - 2)*gamma(-m/2 + nu/2 + 1)/(2**m*gamma(m/2 + nu/2))

    >>> inverse_hankel_transform(ht, k, r, nu)
    r**(-m)

    >>> ht = hankel_transform(exp(-a*r), r, k, 0)
    >>> ht
    a/(k**3*(a**2/k**2 + 1)**(3/2))

    >>> inverse_hankel_transform(ht, k, r, 0)
    exp(-a*r)

    See Also
    ========

    fourier_transform, inverse_fourier_transform
    sine_transform, inverse_sine_transform
    cosine_transform, inverse_cosine_transform
    inverse_hankel_transform
    mellin_transform, laplace_transform
    NrA   )r9  rs   )rY   r   r   r   r\   rA   rA   rB   hankel_transform     .r=  c                   @   r8  )InverseHankelTransformz
    Class representing unevaluated inverse Hankel transforms.

    For usage of this class, see the :class:`IntegralTransform` docstring.

    For how to compute inverse Hankel transforms, see the
    :func:`inverse_hankel_transform` docstring.
    zInverse HankelNr:  rA   rA   rA   rB   r?    r;  r?  c                 K   r<  )a  
    Compute the inverse Hankel transform of `F` defined as

    .. math:: f(r) = \int_{0}^\infty F_\nu(k) J_\nu(k r) k \mathrm{d} k.

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

    If the transform cannot be computed in closed form, this
    function returns an unevaluated :class:`InverseHankelTransform` object.

    For a description of possible hints, refer to the docstring of
    :func:`sympy.integrals.transforms.IntegralTransform.doit`.
    Note that for this transform, by default ``noconds=True``.

    Examples
    ========

    >>> from sympy import hankel_transform, inverse_hankel_transform
    >>> from sympy import exp
    >>> from sympy.abc import r, k, m, nu, a

    >>> ht = hankel_transform(1/r**m, r, k, nu)
    >>> ht
    2*k**(m - 2)*gamma(-m/2 + nu/2 + 1)/(2**m*gamma(m/2 + nu/2))

    >>> inverse_hankel_transform(ht, k, r, nu)
    r**(-m)

    >>> ht = hankel_transform(exp(-a*r), r, k, 0)
    >>> ht
    a/(k**3*(a**2/k**2 + 1)**(3/2))

    >>> inverse_hankel_transform(ht, k, r, 0)
    exp(-a*r)

    See Also
    ========

    fourier_transform, inverse_fourier_transform
    sine_transform, inverse_sine_transform
    cosine_transform, inverse_cosine_transform
    hankel_transform
    mellin_transform, laplace_transform
    NrA   )r?  rs   )r   r   r   r   r\   rA   rA   rB   inverse_hankel_transform  r>  r@  )F)T)rF   	functoolsr   r   	itertoolsr   Z
sympy.corer   r   Zsympy.core.addr   Zsympy.core.functionr   r	   r
   r   r   Zsympy.core.mulr   Zsympy.core.intfuncr   r   Zsympy.core.sortingr   Zsympy.core.symbolr   Zsympy.core.traversalr   Z(sympy.functions.combinatorial.factorialsr   r   Z$sympy.functions.elementary.complexesr   r   r   Z&sympy.functions.elementary.exponentialr   r   Z%sympy.functions.elementary.hyperbolicr   r   r   r   Z#sympy.functions.elementary.integersr   Z(sympy.functions.elementary.miscellaneousr   r    r!   Z$sympy.functions.elementary.piecewiser"   Z(sympy.functions.elementary.trigonometricr#   r$   r%   r&   Zsympy.functions.special.besselr'   Z'sympy.functions.special.delta_functionsr(   Z'sympy.functions.special.gamma_functionsr)   Zsympy.functions.special.hyperr*   Zsympy.integralsr+   r,   Zsympy.integrals.meijerintr-   Zsympy.logic.boolalgr.   r/   r0   r1   r2   Zsympy.polys.polyrootsr3   Zsympy.polys.polytoolsr4   r5   Zsympy.polys.rootoftoolsr6   Zsympy.utilities.iterablesr7   Zsympy.utilities.miscr8   rW   r9   rH   r   r   Z_nocondsr   r   r   r   r   r   r   r   r   r   r   r  r  r	  r  r  r  r  r!  r"  r%  r,  r.  r/  r0  r2  r3  r4  r5  r6  r9  r=  r?  r@  Zsympy.integrals.laplaceZ	integralsZlaplaceZ_laplaceZLaplaceTransformZlaplace_transformZlaplace_correspondenceZlaplace_initial_condsZInverseLaplaceTransformZinverse_laplace_transformrA   rA   rA   rB   <module>   s     D!,-  -:4<*.'('+16
