o
    ohR                    @   sd  d Z ddlZddl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 ddl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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'm(Z(m)Z) ddl*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0 ddl1m2Z2m3Z3 ddl4m5Z5m6Z6m7Z7m8Z8 ddl9m:Z:m;Z;m<Z< ddl=m>Z>m?Z? ddl@mAZAmBZBmCZCmDZD ddlEmFZFmGZGmHZHmIZI ddlJmKZKmLZL ddlMmNZNmOZOmPZP ddlQmRZRmSZSmTZTmUZU ddlVmWZW ddlXmYZYmZZZ ddl[m\Z\m]Z]m^Z^ ddl_m`Z`maZambZbmcZcmdZd 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"lwmxZx dayd#d$ Zzd%d& Z{d'd( Z|ezd)d* Z}ezd+d, Z~ezd-d. Ze
d/d0 Zezd1d2 Zezd3d4 Zezd5d6 Zezd7d8 Zezd9d: Zezd;d< Zezd=d> Zezd?d@ ZezdAdB ZezdCdD ZezdEdF ZezdGdH ZezdIdJ ZezdKdL ZdMdN ZdOdP ZezdQdR ZG dSdT dTe]ZdzdVdWZezdXdY ZezdZd[ Ze
d\d] Zezd^d_ Zezd`da Zezdbdc Zezddde Zezdfdg Zezdhdi Zezdjdk Zezdldm Zezdndo Zezdpdq Zezdrds ZG dtdu due]Zd{dvdwZdxdy ZdS )|zLaplace Transforms    N)SpiI)Add)cacheit)Expr)
AppliedUndef
Derivativeexpandexpand_complex
expand_mulexpand_trigLambdaWildFunctiondiffSubs)Mulprod)
_canonicalGeGtLt
UnequalityEqNe
Relational)ordered)DummysymbolsWild)reimargAbs
polar_liftperiodic_argument)explog)coshcothsinhasinh)MaxMinsqrt)	Piecewisepiecewise_exclusive)cossinatansinc)besselibesseljbesselkbessely)
DiracDelta	Heaviside)erferfcEi)digammagamma
lowergamma
uppergamma)SingularityFunction)	integrateIntegral)	_simplifyIntegralTransformIntegralTransformError)to_cnf	conjuncts	disjunctsOrAnd)
MatrixBase)_lin_eq2dict)PolynomialError)roots)Poly)together)RootSum)sympy_deprecation_warningSymPyDeprecationWarningignore_warnings)debugfc                    s    fdd}|S )Nc                     s   ddl m} |s | i |S tdkrtdtjd tddt  j| f tjd td7 a jdks7 jd	krPd
t _tddt  tjd  | i |}dt _n | i |}td8 atddt |f tjd tdkrstdtjd |S )Nr   SYMPY_DEBUGzO
------------------------------------------------------------------------------filez-LT- %s%s%s     _laplace_transform_integration&_inverse_laplace_transform_integrationFz**** %sIntegrating ...Tz-LT- %s---> %szO------------------------------------------------------------------------------
)sympyrY   	_LT_levelprintsysstderr__name__)argskwargsrY   resultfunc k/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/sympy/integrals/laplace.pywrap1   s*   

zDEBUG_WRAP.<locals>.wraprk   )rj   rm   rk   ri   rl   
DEBUG_WRAP0   s   rn   c                 C   s2   ddl m} |rtddt | f tjd d S d S )Nr   rX   z	-LT- %s%sr\   rZ   )r`   rY   rb   ra   rc   rd   )textrY   rk   rk   rl   _debugN   s   rp   c                    s   fdd fddfddfdd}d	d
 }ddl m} || } || t} || tfdd} || t|} t| S )a  
    Naively simplify some conditions occurring in ``expr``,
    given that `\operatorname{Re}(s) > a`.

    Examples
    ========

    >>> from sympy.integrals.laplace import _simplifyconds
    >>> from sympy.abc import x
    >>> from sympy import sympify as S
    >>> _simplifyconds(abs(x**2) < 1, x, 1)
    False
    >>> _simplifyconds(abs(x**2) < 1, x, 2)
    False
    >>> _simplifyconds(abs(x**2) < 1, x, 0)
    Abs(x**2) < 1
    >>> _simplifyconds(abs(1/x**2) < 1, x, 1)
    True
    >>> _simplifyconds(S(1) < abs(x), x, 1)
    True
    >>> _simplifyconds(S(1) < abs(1/x), x, 1)
    False

    >>> from sympy import Ne
    >>> _simplifyconds(Ne(1, x**3), x, 1)
    True
    >>> _simplifyconds(Ne(1, x**3), x, 2)
    True
    >>> _simplifyconds(Ne(1, x**3), x, 0)
    Ne(1, x**3)
    c                    s&   |  krdS | j r| j kr| jS d S )Nr]   )is_Powbaser&   )exsrk   rl   powerw   s
   z_simplifyconds.<locals>.powerc                    s   |  r| rdS t| tr| jd } t|tr |jd }|  r.d| d|  S |}|du r8dS z.|dkrMt| t | ktjkrMW dS |dk rat| t | ktjkrdW dS W dS W dS  typ   Y dS w )z_ Return True only if |ex1| > |ex2|, False only if |ex1| < |ex2|.
            Else return None. Nr   r]   FT)has
isinstancer#   rf   r   true	TypeError)ex1ex2n)abiggerrv   ru   rk   rl   r   ~   s(   




""z_simplifyconds.<locals>.biggerc                    sH   | j st| tr|j st|ts| |k S  | |}|dur | S | |k S )z simplify x < y N)is_positiverx   r#   )xyrr   rk   rl   replie   s   
z_simplifyconds.<locals>.repliec                    s     | |}|dv rdS t | |S )NTFT)r   )r   r   br   rk   rl   replue   s   

z_simplifyconds.<locals>.repluec                 W   s   | dv rt | S | j| S )Nr   )boolreplace)rs   rf   rk   rk   rl   repl   s   
z_simplifyconds.<locals>.replr   )collect_absc                    s
    || S Nrk   )r   r   )r   rk   rl   <lambda>      
 z _simplifyconds.<locals>.<lambda>)sympy.simplify.radsimpr   r   r   r   r   )exprru   r~   r   r   r   rk   )r~   r   rv   r   ru   rl   _simplifycondsV   s   !
r   c                 C   s   t | | tS )zs
    Expand an expression involving DiractDelta to get it as a linear
    combination of DiracDelta functions.
    )rN   atomsr9   r   rk   rk   rl   expand_dirac_delta   s   r   c                   sR  t d| trdS t| t   tjtjf}|ts/t	|
|tjtjfS |js4dS |jd \}}|trBdS fddfddt|D }dd |D }|sdd	d |D }tt|}d
d  |j fddd |s|dS |d \}}	fdd}
|rt||}t|	|}	t	|
||
|t|
|	fS )z The backend function for doing Laplace transforms by integration.

    This backend assumes that the frontend has already split sums
    such that `f` is to an addition anymore.
    ru   Nr   c                    sx  ddl m} tj}tj}tt| } tdtgd\}}}}}}	}
|t	t
| |  |k |t	t
| |  |kt	t| | | ||k t	t| | | ||kt	tt| | | ||k t	tt| | | ||kf}| D ]3}tj}g }t|D ]}|jr|jjv r|j}|jrt|ttfr|j}|D ]}||  r nq rψ | jrψ |  |  td krt |   dk }||t|t	t
|
  | t	| |	   dk   s|t|t	t| |
 ||  t	| |	  dk   s0||tt	tt| |
 || t	| |	   dk   rLt fdd||||	|
fD rLt | k}|tdd	 t}|jrp|jd
v sp| sp| sv||g7 }q||}|jr|jd
v r||g7 }q|j!kr  dS t"|j!|}q|tjurt#||}q{t$|t%| }q{||jr|j&fS |fS )z7 Turn ``conds`` into a strip and auxiliary conditions. r   _solve_inequalityzp q w1 w2 w3 w4 w5clsexclude   c                 3   s    | ]} | j V  qd S r   )r   ).0wildmrk   rl   	<genexpr>       zH_laplace_transform_integration.<locals>.process_conds.<locals>.<genexpr>c                 S   s   |    d S Nr   )r
   as_real_imagr   rk   rk   rl   r      s    zG_laplace_transform_integration.<locals>.process_conds.<locals>.<lambda>)z==z!=N)'sympy.solvers.inequalitiesr   r   NegativeInfinityry   rI   rH   r   r   r#   r"   r%   r$   InfinityrJ   is_Relationalrhsfree_symbolsreversedrx   r   r   reversedsignmatchr   r   r    r1   allr   subsrel_oprw   ltsr-   r,   rL   rK   	canonical)condsr   r~   auxpqw1w2w3w4w5patternsca_aux_dpatd_soln)ru   tr   rl   process_conds   s     

&: 



z5_laplace_transform_integration.<locals>.process_condsc                    s   g | ]} |qS rk   rk   )r   r   )r   rk   rl   
<listcomp>      z2_laplace_transform_integration.<locals>.<listcomp>c                 S   s,   g | ]}|d  t jkr|d t jur|qS )r]   r   )r   falser   r   r   rk   rk   rl   r     s    c                 S   s   g | ]}|d  t jkr|qS r]   )r   r   r   rk   rk   rl   r     s    c                 S   s   | dv rdS |   S )Nr   r   )	count_opsr   rk   rk   rl   cnt  s   z+_laplace_transform_integration.<locals>.cntc                    s   | d   | d fS Nr   r]   rk   r   )r   rk   rl   r         z0_laplace_transform_integration.<locals>.<lambda>keyc                    s   |   S r   r   r   )ru   s_rk   rl   sbs"     z+_laplace_transform_integration.<locals>.sbs)r   rw   r9   rC   r&   r   Zeror   rD   rE   r   r   ry   is_Piecewiserf   rJ   listr   sortr   r   )fr   r   simplifyFcondr   conds2r~   r   r   rk   )r   r   ru   r   r   rl   r^      s6   
"

?$r^   c                    sJ   t | ts| S |   }dur| S | j} fdd| jD }|| S )a  
    This is an internal helper function that traverses through the epression
    tree of `f(t)` and collects arguments. The purpose of it is that
    anything like `f(w*t-1*t-c)` will be written as `f((w-1)*t-c)` such that
    it can match `f(a*t+b)`.
    Nc                       g | ]}t | qS rk   _laplace_deep_collectr   r"   r   rk   rl   r   7  r   z)_laplace_deep_collect.<locals>.<listcomp>)rx   r   as_polyas_exprrj   rf   )r   r   r   rj   rf   rk   r   rl   r   *  s   
r   c               	      s~  t d t d} td gd}td gd}td gd}td gd}td gd} fd	d
}td g |||  tjtj|ft|  | t|  | | t| t	t
|dk|dkt
|dk |dktj|ft|  | tdt	t
|dk |dkt
|dk|dktj|ft|  | t|  | | |  t
|dk|dktj|ft|  | dt|  | |  |  t
|dk |dk tj|ft|  | d|  t
|dk|dktj|ft|  | dt
|dk |dktj|f d| d  tjtj|fd|  |  t| | |   t| | |   | tt|| tk tj|fdt|  |  t|t |  t|| |   tt|| |   | tt|| tk tj|f|  | td d  d|td d   dt|  | tdd   t|| |   tt|| |   |  tt|| tk tj|ft  |  tt|  tt| t||   tt||    tt|tk tj|fd|t   d   t|tdd   t||   tt||   tjtj|f | t|d | |d   |dktj|f|  | | t|d || |  t| | |   | |d   | t
|dktt|| tk tj|f |  |  || t|d  t| ||   t
|dktt|tk tj|ft|  | t| | |  tjt||f t|  |  t| | | d  tjt||f | t|   t|d | | |d   t|dkt||ft|  d  ttd | t| d d |  t| td|   t|dktj|f t|  d   dd|  dtt d| tdd   |  t| td|    t|dktj|ft|   dt||   tddt||    t|dktj|ft t|    tdd tt| d   ddt||     tdt||    t|dktj|ft|   t  tt|  tdt||    t|dktj|ft|    t   tt| tdt||    t|dktj|f | t|    d||  |d d   t|d dt||    t|dktj|ftdt|   | d tt| | td d   t||   tt||    tt|tk tj|ftdt|   t  t|  tdd  t||   tt||   tt|tk tj|ft| t   ||   t| | tjtj|ft| t  ||  t|  | t|dktj|ft|  tttj|  |  |  |dktj|ftd|   t| |  |  t|  |  tt|tk tj|ft|  | t|t| | | |  | t|  |   |  | t
|dktt|tk tj|ft t  tt|   td|  ttj  tjtj|f | t  t|d | | d   t|d t|   t|dktj|ft|  d tttj|  | d td d  |  |dktj|ft|  || d |d   tjtt||ftt|  || d |d   tt|  d |  |dktj|ft|    t||  tjtt||ft|  d   tdd|d  | d   d tjdtt| |ft|  d  d  |td| |   | tdd|d  | d    d  tjdtt| |ftdt|   tt| |  t|  t| |   tjtj|ftdt|     ttt||   tjtj|ft|  | | d |d   tjtt||ft|  d | d d|d   | d d|d    |  tjdtt| |ft tdt|    ttd | td d   | d|   t| |   tjtj|ftdt|   t  tt|  t| |   tjtj|ft|  t|   d| | |  | d || d   | d || d   tjtt|tt| |ft|  t|   || d |d  |d   | d || d   | d || d   tjtt|tt| |ft|  t|   | | d |d  |d   | d || d   | d || d   tjtt|tt| |ft |  || d |d   tjtt||ft!|  | | d |d   tjtt||ft |  d d|d  | d d|d  |    tjdtt| |ft!|  d | d d|d   | d d|d  |    tjdtt| |ft |    t| | | |  d tjtt||f | t |   t|d d | | | d  | | | d    |dkt||f | t!|   t|d d | | | d  | | | d    |dkt||ft dt|   tt| |  t|  t||   tjtj|ft!dt|   d|  tt| |  t|  t||   tt||    tjtj|ft t dt|    ttdd  | td d   | d |  t||   tt||   |tdd  | d   tjtj|ft t!dt|    ttdd  | td d   | d |  t||   tjtj|ft dt|   t  ttdd  | td d   t||   tt||   tjtj|ft!dt|   t  ttdd  | td d   t||   tjtj|ft t|  d t  ttdd  d | td d   t||  d  tjtj|ft!t|  d t  ttdd  d | td d   t||  d  tjtj|ft|  t| d d| d  t| d|   |  dtt| tk tj|ftt|  t|t| |  |  tjt"tjt| |ft|  tt|   t|t|  | |  tjt"tjt||ftt|  d dtt||    |  t|dktj|ftt|  t| | t| t| |  |  tjt| |ft|  tt|   d| t||    tjtj|ftt|  d tt||   |  t|dktj|ft#||  || t| d |d  | t| d |d   |   t|dktt||f | t#||   d| tt t|tj$  ||  | d |d  | tj$   t
t|tj$ kt%||tt||f | t#||   d|d  tt t|tdd   ||  |  | d |d  | tdd    t
t|dkt%||d tt||ft#ddt|   t| |  |  tjtj|f | t#|dt|    ||d  | | d   t| |   t
t|dkt%||tj$ tj|ft#d|t d |    t||  |t| d |d    t| d |d   tt|tk tt||ft&||  || t| d |d  | t| d |d   |   t|dktt||f | t&||   d| tt t|tj$  ||  | d |d  | tj$   t
t|tj$ kt%||tt||f | t&||   d|d  tt t|tdd   ||  |  | d |d  | tdd    t
t|dkt%||d tt||f | t&|dt|    ||d  | | d   t||   t
t|dkt%||tj$ tj|ft'd|  dt t(| |  t| d |d   tjtt||ftd|  t| t| d |d   | t| d |d   tjt| |f}| | fS )aY  
    This is an internal helper function that returns the table of Laplace
    transform rules in terms of the time variable `t` and the frequency
    variable `s`.  It is used by ``_laplace_apply_rules``.  Each entry is a
    tuple containing:

        (time domain pattern,
         frequency-domain replacement,
         condition for the rule to be applied,
         convergence plane,
         preparation function)

    The preparation function is a function with one argument that is applied
    to the expression before matching. For most rules it should be
    ``_laplace_deep_collect``.
    r   ru   r~   r   r   r}   tauomegac                    s
   t |  S r   r   r   r   rk   rl   dcoT  r   z!_laplace_build_rules.<locals>.dcoz&_laplace_build_rules is building rulesr   r]   r      g      ?         ))r   r   rp   r   ry   r   r9   r&   r#   rK   rL   r   r:   r=   r"   r   r.   r<   r?   rA   r    r7   r@   r'   
EulerGammar>   r2   r!   r)   r3   r;   r1   r*   r(   r,   r6   Halfr   r5   r8   r+   )ru   r~   r   r}   r   r   r   laplace_transform_rulesrk   r   rl   _laplace_build_rules;  s@  
&$$"	&
6HX@D
D "0"$&&,(F*,B0/1B2466D8:@H=$?
"A$C,EBG0I
:K6MO4QS0UW66Z
(\
^8`Pb
2d
LfXhXjln0p8r$tDvDx4z
L|
,

 R
  <
  F	
  N
  N
  4  $  0  *  0  ,
  &  B  @&  "T&  $%
  B'"  )6  B,  .@&  1T&  @4"  26  >8  
;r   c                 C   s   t d|gd}tddd}| |}|rU|| jd |}||| }|rU|| jrU|| dkrUtd td||  || | ||||  dd	\}}	}
||	|
fS d
S )z
    This function applies the time-scaling rule of the Laplace transform in
    a straight-forward way. For example, if it gets ``(f(a*t), t, s)``, it will
    compute ``LaplaceTransform(f(t)/a, t, s/a)`` if ``a>0``.
    r~   r   gr]   )nargsr   z     rule: time scaling (4.1.4)Fr   N)	r   r   r   rf   collectr   rp   _laplace_transformrj   )r   r   ru   r~   r   ma1r"   ma2r   prcrrk   rk   rl   _laplace_rule_timescale  s   
&
r   c                 C   sZ  t d|gd}t d}t d}| t||  }r|| ||  }rl|| jrQtd t|| ||||  ||dd\}}	}
t||  | | |	|
fS || jrltd t|| ||dd\}}	}
||	|
fS || ||  }r|| jrtd	 td
t|||   ||  ||dd\}}	}
||	|
fS || jrtd ddt	j
fS dS )a  
    This function deals with time-shifted Heaviside step functions. If the time
    shift is positive, it applies the time-shift rule of the Laplace transform.
    For example, if it gets ``(Heaviside(t-a)*f(t), t, s)``, it will compute
    ``exp(-a*s)*LaplaceTransform(f(t+a), t, s)``.

    If the time shift is negative, the Heaviside function is simply removed
    as it means nothing to the Laplace transform.

    The function does not remove a factor ``Heaviside(t)``; this is done by
    the simple rules.
    r~   r   r   r   z     rule: time shift (4.1.4)Fr   z8     rule: Heaviside factor; negative time shift (4.1.4)z      rule: Heaviside window openr]   z"     rule: Heaviside window closedr   N)r   r   r:   r   rp   r   r   r&   is_negativer   ry   )r   r   ru   r~   r   r   r   r   r   r   r   rk   rk   rl   _laplace_rule_heaviside*  s8   



 

r   c                 C   s   t d|gd}t d}t d}| t|| }|rH|| ||| }|rHtd t|| ||||  dd\}}	}
||	t||  |
fS dS )	a  
    If this function finds a factor ``exp(a*t)``, it applies the
    frequency-shift rule of the Laplace transform and adjusts the convergence
    plane accordingly.  For example, if it gets ``(exp(-a*t)*f(t), t, s)``, it
    will compute ``LaplaceTransform(f(t), t, s+a)``.
    r~   r   r   zz$     rule: multiply with exp (4.1.5)Fr   N)r   r   r&   r   rp   r   r    )r   r   ru   r~   r   r   r   r   r   r   r   rk   rk   rl   _laplace_rule_expT  s   	r  c           
         s  t dgd t dgdt d}t d| t| rԈ tsԈ|    rtd     }t|dkrt|dkrt        }|t	t
rn|t } fdd	| D \}}|dkr||   tjtjfS d
S dtjtjfS | rt| }|i krt| dhkrt| tfdd	t| D  }	|	tjtjfS d
S )z
    If this function finds a factor ``DiracDelta(b*t-a)``, it applies the
    masking property of the delta distribution. For example, if it gets
    ``(DiracDelta(t-a)*f(t), t, s)``, it will return
    ``(f(a)*exp(-a*s), -a, True)``.
    r~   r   r   r   r   z#     rule: multiply with DiracDeltar   c                    s$   g | ]}|     qS rk   r   r   )r~   r   r   r   rk   rl   r        $ z'_laplace_rule_delta.<locals>.<listcomp>Nr]   c                    sN   g | ]#}t |d krt|d krt|     | qS )r   )r!   r    r&   r   r   )r   ru   sloper   r   rk   rl   r     s    ()r   r   r9   rw   r   rp   r    r!   r&   r2   r1   rewriter4   ratsimpas_numer_denomr   r   ry   is_polynomialrP   setvaluesr   r   r   keys)
r   r   ru   r   locfnr}   r   ror   rk   )r~   r   r   r   ru   r  r   r   rl   _laplace_rule_deltak  s<   
" 
r  c                 C   s`   t jg}t jg}t| D ]}|ttttt	r|
| q|
| qt| }t| }||fS )z
    Helper function for `_laplace_rule_trig`.  This function returns two terms
    `f` and `g`.  `f` contains all product terms with sin, cos, sinh, cosh in
    them; `g` contains everything else.
    )r   Oner   	make_argsrw   r2   r1   r*   r(   r&   append)r  trigsothertermr   r   rk   rk   rl   _laplace_trig_split  s   r  c           
      C   s   t d|gd}t d|gd}t d|gd}g }g }| t }t|D ]T}||s:|d|ddtdt	di q%t
|jdd	|}||t|| |   }	d
urt|d|	| t|	|  d|	| tt|	| t	t	|	| i q%|| q%||fS )a  
    Helper function for `_laplace_rule_trig`.  This function expects the `f`
    from `_laplace_trig_split`.  It returns two lists `xm` and `xn`.  `xm` is
    a list of dictionaries with keys `k` and `a` representing a function
    `k*exp(a*t)`.  `xn` is a list of all terms that cannot be brought into
    that form, which may happen, e.g., when a trigonometric function has
    another function in its argument.
    c1r   c0r   kr~   r   r&   )combineN)r   r  r&   r
   r   r  rw   r  r    r!   r   powsimpr   )
r   r   r  r  r   xmxnx1r  r   rk   rk   rl   _laplace_trig_expsum  s$   

"r  c                    s  g }g }dd   fdd} fdd} fdd} fd	d
}dd }	t | dkrM|  }
d}d}d}tt | D ]X}|
t | | t k}|
t | | t  k}|
t | | t k}|
t | | t  k}|rz|rz|
t dkrz|
t dkrz|}q;|r|r|
t dkr|}q;|r|r|
t dkr|}q;|dur|dur|dur|||
| | d | | d | | d | |tt|
d  |||g}|jdd |D ]}| | qno|dur|||
| | d | ||
t  | | nQ|dur|||
| | d | |t|
t  | | n0|dur8|||
| | d | |t|
t  | | n||	|
| ||
t  t | dks+t| t	| fS )a  
    Helper function for `_laplace_rule_trig`.  This function takes the list of
    exponentials `xm` from `_laplace_trig_expsum` and simplifies complex
    conjugate and real symmetric poles.  It returns the result as a sum and
    the convergence plane.
    c                 S   sj   |   }tt|D ](}||  }|d tr#|| t||< q
|d t|d   t||< q
|S r   )	copyrangelenr   rw   r!   r  r1   r   )coeffsncr  rirk   rk   rl   _simpc  s    z"_laplace_trig_ltex.<locals>._simpcc              	      s  | d | d | t  | t f\}}}}|| | | ||| | |  dt | |  dt | |  |d | | | |  |dt | | dt | |    d|d  |  d|d  |  |d | | | |  |d dt | | dt | |  dt | |  dt | |    |d|d  | d|d  |    g}	tjtjd|d  d|d   tj|d d|d  |d   |d  g}
t fddt|	tt	|	d d d D  }t fd	dt|
tt	|
d d d D  }|| S )
Nr~   r  r   r   r   c                       g | ]
\}}| |  qS rk   rk   r   r   r   rt   rk   rl   r         z9_laplace_trig_ltex.<locals>._quadpole.<locals>.<listcomp>r   c                    r&  rk   rk   r'  rt   rk   rl   r     r(  )
r    r!   r   r   r  r   r   zipr   r!  )t1k1k2k3ru   r~   k0a_ra_ir#  dcr}   r   r%  rt   rl   	_quadpole  s4   $2"F"&,(z%_laplace_trig_ltex.<locals>._quadpolec                    s   | d | d | t  | t f\}}}}|| | | ||  dt | |  g}tjd| |d |d  g}t fddt|tt|d d d D  }	t fddt|tt|d d d D  }
|	|
 S )	Nr~   r  r   r   c                    r&  rk   rk   r'  rt   rk   rl   r     r(  z7_laplace_trig_ltex.<locals>._ccpole.<locals>.<listcomp>r   c                    r&  rk   rk   r'  rt   rk   rl   r     r(  	r    r!   r   r   r  r   r)  r   r!  )r*  r+  ru   r~   r.  r/  r0  r#  r1  r}   r   r2  rt   rl   _ccpole  s   $*,(z#_laplace_trig_ltex.<locals>._ccpolec                    s   | d | d | t  | t f\}}}}|| || ||  dt | |  g}tjdt | |d  |d  g}t fddt|tt|d d d D  }	t fddt|tt|d d d D  }
|	|
 S )	Nr~   r  r   r   c                    r&  rk   rk   r'  rt   rk   rl   r     r(  z7_laplace_trig_ltex.<locals>._rspole.<locals>.<listcomp>r   c                    r&  rk   rk   r'  rt   rk   rl   r   	  r(  r4  )r*  r,  ru   r~   r.  r/  r0  r#  r1  r}   r   r2  rt   rl   _rspole  s   $(",(z#_laplace_trig_ltex.<locals>._rspolec           	         s   | d | d }}|| |||  g}t jt j|d  g}t fddt|tt|d d d D  }t fddt|tt|d d d D  }|| S )Nr~   r  r   c                    r&  rk   rk   r'  rt   rk   rl   r     r(  z7_laplace_trig_ltex.<locals>._sypole.<locals>.<listcomp>r   c                    r&  rk   rk   r'  rt   rk   rl   r     r(  )r   r  r   r   r)  r   r!  )	r*  r-  ru   r~   r.  r#  r1  r}   r   r2  rt   rl   _sypole  s   ,(z#_laplace_trig_ltex.<locals>._sypolec                 S   s&   | d | d }}|}|| }|| S )Nr~   r  rk   )r*  ru   r~   r.  r}   r   rk   rk   rl   _simplepole  s   z'_laplace_trig_ltex.<locals>._simplepoler   Nr  r~   T)reverse)
r!  popr   r    r!   r  r#   r   r   r,   )r  r   ru   resultsplanesr3  r5  r6  r7  r8  r*  	i_imagsym	i_realsym
i_pointsymireal_eqrealsymimag_eqimagsymindices_to_poprk   r2  rl   _laplace_trig_ltex  sn   



 



:rF  c              
   C   s   t ddd}| ttttsdS t| ||\}}t||\}}t	|dkr)dS ||s>t
|||\}}	|| |	tjfS g }
g }t|||dd\}}}|D ]}||d ||||d	    |
|t|d	   qOt| ||t|
 |fS )
z
    This rule covers trigonometric factors by splitting everything into a
    sum of exponential functions and collecting complex conjugate poles and
    real symmetric poles.
    r   TrealNr   Fr   r  r~   )r   rw   r2   r1   r*   r(   r  r   r  r!  rF  r   ry   r   r  r    r   r,   )r  t_ru   r   r   r   r  r  r   r   r<  r;  GG_planeG_condr  rk   rk   rl   _laplace_rule_trigY  s"   
"rM  c                    s"  t d gd}t d gd}td}| |t| |f }|r|| jr fdd|| jD }t|dkrtd g }t|| D ]+}	|	d	krR|| 	 d	}
nt||  |	f	 d	}
|
||| |	 d  |
  qCt||  |d
d\}}}|| |||  | t|   ||fS dS )a  
    This function looks for derivatives in the time domain and replaces it
    by factors of `s` and initial conditions in the frequency domain. For
    example, if it gets ``(diff(f(t), t), t, s)``, it will compute
    ``s*LaplaceTransform(f(t), t, s) - f(0)``.
    r~   r   r}   r   c                       g | ]}|  qS rk   rw   )r   r   r   rk   rl   r     r   z&_laplace_rule_diff.<locals>.<listcomp>r]   z"     rule: time derivative (4.1.8)r   Fr   N)r   r   r   r	   
is_integerrf   sumrp   r   r   r  r   r   )r   r   ru   r~   r}   r   r   r   r   r  r   r   r   r   rk   r   rl   _laplace_rule_diffz  s"   	 &rR  c              	      s  | j rdg}dg}t| D ]}||r|| q|| qt|dkrt|}t|| t  dkrt|}t	|||dd\}}	}
|gd}z
t
d | }W n tyc   d}Y nw |trt d D ]}d|d  t|||d   qon|r| t d D ]}t
d |  q|rt fddt D  }||	|
fS td|gd	}td
}| || |  }r|| jr|| jrt	|| ||dd\}}	}
d||  t
|||| f |	|
fS dS )a  
    This function looks for multiplications with polynoimials in `t` as they
    correspond to differentiation in the frequency domain. For example, if it
    gets ``(t*f(t), t, s)``, it will compute
    ``-Derivative(LaplaceTransform(f(t), t, s), s)``.
    r]   Fr   r   r   c                    s$   g | ]} | d   |  qS r   rk   )r   r}   Nderipcrk   rl   r     r  z'_laplace_rule_sdiff.<locals>.<listcomp>r}   r   r   N)is_Mulr   r  r  r  r!  r   rQ   
all_coeffsr   r   
ValueErrorrw   LaplaceTransformr   r	   r   r   r   rP  r   )r   r   ru   pfacofacfacpexoexr_p_c_d1r  r   r}   r   r   rk   rS  rl   _laplace_rule_sdiff  sN   	

$

$rd  c                 C   s   t | dd}|jrt|||ddS t| }|jr t|||ddS t | }|jr/t|||ddS || kr;t|||ddS t t| }|jrLt|||ddS dS )a  
    This function tries to expand its argument with successively stronger
    methods: first it will expand on the top level, then it will expand any
    multiplications in depth, then it will try all avilable expansion methods,
    and finally it will try to expand trigonometric functions.

    If it can expand, it will then compute the Laplace transform of the
    expanded term.
    Fdeepr   N)r
   is_Addr   r   r   )r   r   ru   r   rk   rk   rl   _laplace_expand  s   rh  c                 C   s<   t ttttttg}|D ]}|| || }dur|  S qdS )zk
    This function applies all program rules and returns the result if one
    of them gives a result.
    N)r   r  r   r  rM  rR  rd  )r   r   ru   
prog_rulesp_ruleLrk   rk   rl   _laplace_apply_prog_rules  s   rl  c              	   C   s   t  \}}}d}d}|D ]F\}}	}
}}||kr"|| ||i}|}||}|rRz|
|}W n	 ty9   Y qw |tjkrR|	|||i||tjf  S qdS )zj
    This function applies all simple rules and returns the result if one
    of them gives a result.
     N)r   r   r   xreplacerz   r   ry   )r   r   ru   simple_rulesrI  r   prep_oldprep_ft_doms_domcheckplaneprepmar   rk   rk   rl   _laplace_apply_simple_rules  s(   

rx  c           	      C   st  |j stddd}t| ||i|||iS t| }g }|jD ]\}}t|trH||jv rHt|tt	fr:|   S |
t|j|j |  q!t|trst|jdkrs|jD ]}|j|krl|
t|j|j |  qW|     S q!t|trt|jdkr|j\}}|j|kr|j|krd|jv r||}}|
t|j|j t|j|j  |  q!|   S |   S t| S )z
    This function converts a Piecewise expression to an expression written
    with Heaviside. It is not exact, but valid in the context of the Laplace
    transform.
    r   TrG  r   >)is_realr   _piecewise_to_heavisidern  r0   rf   rx   r   r   r   r  r:   gtsr   rK   r!  lhsrL   r   r   )	r   r   r   r   r  r   c2r  r  rk   rk   rl   r{    s>   




r{  c                   s   t d}t d}t d}t d}t| tr| ts!| ts!| S   D ]C\}}| t|||| }durH|| || krH|||   S | t||||| }durh|| || krh|||   S q%| j}	 fdd| j	D }
|	|
 S )a  
    This helper function takes a function `f` that is the result of a
    ``laplace_transform`` or an ``inverse_laplace_transform``.  It replaces all
    unevaluated ``LaplaceTransform(y(t), t, s)`` by `Y(s)` for any `s` and
    all ``InverseLaplaceTransform(Y(s), s, t)`` by `y(t)` for any `t` if
    ``fdict`` contains a correspondence ``{y: Y}``.

    Parameters
    ==========

    f : sympy expression
        Expression containing unevaluated ``LaplaceTransform`` or
        ``LaplaceTransform`` objects.
    fdict : dictionary
        Dictionary containing one or more function correspondences,
        e.g., ``{x: X, y: Y}`` meaning that ``X`` and ``Y`` are the
        Laplace transforms of ``x`` and ``y``, respectively.

    Examples
    ========

    >>> from sympy import laplace_transform, diff, Function
    >>> from sympy import laplace_correspondence, inverse_laplace_transform
    >>> from sympy.abc import t, s
    >>> y = Function("y")
    >>> Y = Function("Y")
    >>> z = Function("z")
    >>> Z = Function("Z")
    >>> f = laplace_transform(diff(y(t), t, 1) + z(t), t, s, noconds=True)
    >>> laplace_correspondence(f, {y: Y, z: Z})
    s*Y(s) + Z(s) - y(0)
    >>> f = inverse_laplace_transform(Y(s), s, t)
    >>> laplace_correspondence(f, {y: Y})
    y(t)
    r   ru   r   r~   Nc                    r   rk   )laplace_correspondencer   fdictrk   rl   r   |  r   z*laplace_correspondence.<locals>.<listcomp>)
r   rx   r   rw   rZ  InverseLaplaceTransformitemsr   rj   rf   )r   r  r   ru   r   r~   r   Yr   rj   rf   rk   r  rl   r  D  s0   $r  c             	   C   s   |  D ]E\}}tt|D ]:}|dkr| |d|d } q|dkr5| tt||||d|d } q| tt||||f|d|| } qq| S )a  
    This helper function takes a function `f` that is the result of a
    ``laplace_transform``.  It takes an fdict of the form ``{y: [1, 4, 2]}``,
    where the values in the list are the initial value, the initial slope, the
    initial second derivative, etc., of the function `y(t)`, and replaces all
    unevaluated initial conditions.

    Parameters
    ==========

    f : sympy expression
        Expression containing initial conditions of unevaluated functions.
    t : sympy expression
        Variable for which the initial conditions are to be applied.
    fdict : dictionary
        Dictionary containing a list of initial conditions for every
        function, e.g., ``{y: [0, 1, 2], x: [3, 4, 5]}``. The order
        of derivatives is ascending, so `0`, `1`, `2` are `y(0)`, `y'(0)`,
        and `y''(0)`, respectively.

    Examples
    ========

    >>> from sympy import laplace_transform, diff, Function
    >>> from sympy import laplace_correspondence, laplace_initial_conds
    >>> from sympy.abc import t, s
    >>> y = Function("y")
    >>> Y = Function("Y")
    >>> f = laplace_transform(diff(y(t), t, 3), t, s, noconds=True)
    >>> g = laplace_correspondence(f, {y: Y})
    >>> laplace_initial_conds(g, t, {y: [2, 4, 8, 16, 32]})
    s**3*Y(s) - 2*s**2 - 4*s - 8
    r   r]   )r  r   r!  r   r   r	   )r   r   r  r   icr  rk   rk   rl   laplace_initial_conds  s   "$(r  c                   s>  t | }g }g }g }g }|D ]c}	|	j dd\}
}|tr?t |t}|D ]}|j dd\}}||
| |f q)q|jt	krk|t
 skt t| }|D ]}|j dd\}}||
| |f qUq||
|f q|D ]\}
}|trt| |tjdf}ne|t r|t
 s|t d}t| | }dust| | }dust| | }durn0t fdd|tD rt| |tjdf}nt| ||d }durn
t| |tjdf}|\}}}||
|  || || qut | }|r|jdd	}t| }t| }|||fS )
z
    Front-end function of the Laplace transform. It tries to apply all known
    rules recursively, and if everything else fails, it tries to integrate.
    Fas_AddTr]   Nc                 3       | ]}|  V  qd S r   rO  r   undefrI  rk   rl   r     r   z%_laplace_transform.<locals>.<genexpr>r   doit)r   r  as_independentrw   rB   r  r:   r  rj   r/   r9   r{  rZ  r   r   r   rx  rl  rh  anyr   r   r^   r   r,   rL   )r  rI  r   r   terms_tterms_stermsr<  
conditionsffr  ft_terms_termr+  f1r   ri_pi_ci_rh   ru  	conditionrk   r  rl   r     sh   





r   c                   @   s,   e Zd ZdZdZdd Zdd Zdd Zd	S )
rZ  a  
    Class representing unevaluated Laplace transforms.

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

    For how to compute Laplace transforms, see the :func:`laplace_transform`
    docstring.

    If this is called with ``.doit()``, it returns the Laplace transform as an
    expression. If it is called with ``.doit(noconds=False)``, it returns a
    tuple containing the same expression, a convergence plane, and conditions.
    Laplacec                 K   s    | dd}t||||d}|S )Nr   Fr   )getr^   )selfr   r   ru   hintsrE   LTrk   rk   rl   _compute_transform  s   z#LaplaceTransform._compute_transformc                 C   s"   t |t| |  |tjtjfS r   )rD   r&   r   r   r   )r  r   r   ru   rk   rk   rl   _as_integral  s   "zLaplaceTransform._as_integralc                 K   s`   | dd}| dd}td| j| j| jf | j}| j}| j}t||||d}|r.|d S |S )j  
        Try to evaluate the transform in closed form.

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

        Standard hints are the following:
        - ``noconds``:  if True, do not return convergence conditions. The
        default setting is `True`.
        - ``simplify``: if True, it simplifies the final result. The
        default setting is `False`.
        nocondsTr   Fz[LT doit] (%s, %s, %s)r   r   )r  rW   functionfunction_variabletransform_variabler   )r  r  _nocondsrE   rI  r   r  r   rk   rk   rl   r  	  s   zLaplaceTransform.doitN)re   
__module____qualname____doc___namer  r  r  rk   rk   rk   rl   rZ    s    rZ  Tc                    s,    dd}  dd}t| trt| dr  dd }|rJ|rJd}tdd|d tt |  fd	d
W  d   S 1 sDw   Y  n5 fdd| D }	|rst|	 \}
}}t	| g | j
|
R  }|t| t| fS t	| g | j
|	R  S t| jd|d\}}}|s|||fS |S )a  
    Compute the Laplace Transform `F(s)` of `f(t)`,

    .. math :: F(s) = \int_{0^{-}}^\infty e^{-st} f(t) \mathrm{d}t.

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

    For all sensible functions, this converges absolutely in a
    half-plane

    .. math :: a < \operatorname{Re}(s)

    This function returns ``(F, a, cond)`` where ``F`` is the Laplace
    transform of ``f``, `a` is the half-plane of convergence, and `cond` are
    auxiliary convergence conditions.

    The implementation is rule-based, and if you are interested in which
    rules are applied, and whether integration is attempted, you can switch
    debug information on by setting ``sympy.SYMPY_DEBUG=True``. The numbers
    of the rules in the debug information (and the code) refer to Bateman's
    Tables of Integral Transforms [1].

    The lower bound is `0-`, meaning that this bound should be approached
    from the lower side. This is only necessary if distributions are involved.
    At present, it is only done if `f(t)` contains ``DiracDelta``, in which
    case the Laplace transform is computed implicitly as

    .. math ::
        F(s) = \lim_{\tau\to 0^{-}} \int_{\tau}^\infty e^{-st}
        f(t) \mathrm{d}t

    by applying rules.

    If the Laplace transform cannot be fully computed in closed form, this
    function returns expressions containing unevaluated
    :class:`LaplaceTransform` objects.

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

    .. deprecated:: 1.9
        Legacy behavior for matrices where ``laplace_transform`` with
        ``noconds=False`` (the default) returns a Matrix whose elements are
        tuples. The behavior of ``laplace_transform`` for matrices will change
        in a future release of SymPy to return a tuple of the transformed
        Matrix and the convergence conditions for the matrix as a whole. Use
        ``legacy_matrix=False`` to enable the new behavior.

    Examples
    ========

    >>> from sympy import DiracDelta, exp, laplace_transform
    >>> from sympy.abc import t, s, a
    >>> laplace_transform(t**4, t, s)
    (24/s**5, 0, True)
    >>> laplace_transform(t**a, t, s)
    (gamma(a + 1)/(s*s**a), 0, re(a) > -1)
    >>> laplace_transform(DiracDelta(t)-a*exp(-a*t), t, s, simplify=True)
    (s/(a + s), -re(a), True)

    There are also helper functions that make it easy to solve differential
    equations by Laplace transform. For example, to solve

    .. math :: m x''(t) + d x'(t) + k x(t) = 0

    with initial value `0` and initial derivative `v`:

    >>> from sympy import Function, laplace_correspondence, diff, solve
    >>> from sympy import laplace_initial_conds, inverse_laplace_transform
    >>> from sympy.abc import d, k, m, v
    >>> x = Function('x')
    >>> X = Function('X')
    >>> f = m*diff(x(t), t, 2) + d*diff(x(t), t) + k*x(t)
    >>> F = laplace_transform(f, t, s, noconds=True)
    >>> F = laplace_correspondence(F, {x: X})
    >>> F = laplace_initial_conds(F, t, {x: [0, v]})
    >>> F
    d*s*X(s) + k*X(s) + m*(s**2*X(s) - v)
    >>> Xs = solve(F, X(s))[0]
    >>> Xs
    m*v/(d*s + k + m*s**2)
    >>> inverse_laplace_transform(Xs, s, t)
    2*v*exp(-d*t/(2*m))*sin(t*sqrt((-d**2 + 4*k*m)/m**2)/2)*Heaviside(t)/sqrt((-d**2 + 4*k*m)/m**2)

    References
    ==========

    .. [1] Erdelyi, A. (ed.), Tables of Integral Transforms, Volume 1,
           Bateman Manuscript Prooject, McGraw-Hill (1954), available:
           https://resolver.caltech.edu/CaltechAUTHORS:20140123-101456353

    See Also
    ========

    inverse_laplace_transform, mellin_transform, fourier_transform
    hankel_transform, inverse_hankel_transform

    r  Fr   	applyfuncz#deprecated-laplace-transform-matrixz
Calling laplace_transform() on a Matrix with noconds=False (the default) is
deprecated. Either noconds=True or use legacy_matrix=False to get the new
behavior.
                z1.9)deprecated_since_versionactive_deprecations_targetc                    s   t | fi  S r   laplace_transform)fijr  ru   r   rk   rl   r     r   z#laplace_transform.<locals>.<lambda>Nc                    s    g | ]}t |fi  qS rk   r  )r   r  r  rk   rl   r     s    
z%laplace_transform.<locals>.<listcomp>r  r   )r  rx   rM   hasattrrT   rV   rU   r  r)  typeshaper,   rL   rZ  r  )r   r   ru   legacy_matrixr  r  rE   r   adtelements_transelementsavalsr  	f_laplacer  r   r   rk   r  rl   r  )  s<   g
"
r  c                   s  ddl m}m  ddlm} tddd fdd}| r%| } | jrBt	fd	d
| j
D  }t||dfS z|| t dtjfddd\}}	W n tya   d}Y nw |du r|| }|du rrdS |jr|j
d \}}	|trdS ntj}	|t|}|jr|||	fS tdtjffdd	}
|t|
}dd }|t|}t|||	fS )z6 The backend function for inverse Laplace transforms. r   )meijerint_inversion_get_coeff_exp)inverse_mellin_transformr   TrG  c                     s   t | dkr
t|  S | d jd j} |\}}| d jd }| d jd }tdt| |  | t| dt|  |  S )z3 Simplify a piecewise expression from hyperexpand. r   r   r   r]   )r!  r/   rf   argumentr:   r#   )rf   r"   coeffexponente1e2)r  r   rk   rl   pw_simp  s   z7_inverse_laplace_transform_integration.<locals>.pw_simpc                    s   g | ]
}t | qS rk   )r_   )r   X)ru  ru   r   r   rk   rl   r     s    z:_inverse_laplace_transform_integration.<locals>.<listcomp>NF)needevalr  uc                    s|   |  t  }| rt| |S ddlm} ||dk}|jkr1t|j}t | |S t|j}t |  |S )Nr   r   )	r   r&   rw   r:   r   r   r   r'   r|  )r"   H0r~   r   relr  )r   r  rk   rl   simp_heaviside  s   




z>_inverse_laplace_transform_integration.<locals>.simp_heavisidec                 S   s   t t| S r   )r   r&   )r"   rk   rk   rl   simp_exp  r   z8_inverse_laplace_transform_integration.<locals>.simp_exp)sympy.integrals.meijerintr  r  sympy.integrals.transformsr  r   is_rational_functionapartrg  r   rf   rE   r   r&   r   r   rG   r   rw   rD   ry   r   r/   r   r:   )r   ru   rI  ru  r   r  r  r  r   r   r  r  rk   )r  ru  ru   r   r   r  rl   r_     sN   


r_   c           	      C   s~   ddl m} || \}}||r;|| }t|dkr;|\}}}|||d|   d ||  |d|  d   }|| S )Nr   )fractionr   r   )r   r  r  r   rX  r!  )	r   ru   r  r}   r   cfr~   r   r   rk   rk   rl   _complete_the_square_in_denom  s   

0r  c               	   C   sT  t d} t d}td| gd}td| gd}td| gd}td dd	 }d
d }||  |tj|df|| | |   ||d  t| |  t| tj|dfd| d |d  d  t|| || t||   d|d   tj|dfd| |  ||d  t| tj|dfd| | | |   t	||| || t|  tj|dfg}|| |fS )z
    This is an internal helper function that returns the table of inverse
    Laplace transform rules in terms of the time variable `t` and the
    frequency variable `s`.  It is used by `_inverse_laplace_apply_rules`.
    ru   r   r~   r   r   r   z._inverse_laplace_build_rules is building rulesc                 S   s$   z|  |W S  ty   |  Y S w r   )factorrO   )r   ru   rk   rk   rl   _frac&  s
   z+_inverse_laplace_build_rules.<locals>._fracc                 S   s   | S r   rk   r   rk   rk   rl   same,  s    z*_inverse_laplace_build_rules.<locals>.samer]   r   r   )
r   r   rp   r   ry   r&   r?   r2   r1   r@   )ru   r   r~   r   r   r  r  
_ILT_rulesrk   rk   rl   _inverse_laplace_build_rules  s*   0@&.
r  c                    s   | dkrt d t|tjfS t \}}}d}| ||i}|D ]N\}}	}
}}|||fkr7||| }||f}||  rn|
}|tjurV fdd|d D }|d | }|tjkrnt||	 ||i tjf  S q dS )@
    Helper function for the class InverseLaplaceTransform.
    r]   z     rule: 1 o---o DiracDelta()rm  c                    rN  rk   )rn  r   rw  rk   rl   r   U  r   z7_inverse_laplace_apply_simple_rules.<locals>.<listcomp>r   N)	rp   r9   r   ry   r  r   r   r:   rn  )r   ru   r   r  r   rI  _prepfsubsrs  rr  rt  rv  r]  _Fr   rf   rk   r  rl   #_inverse_laplace_apply_simple_rules@  s(   


&r  c           
      C   s   t d|gd}t d|gd}t d}| |t|||f }|rB|| jrBtd t|| |||ddd\}}	| ||  | |	fS dS )	r  r~   r   r}   r   z3     rule: t**n*f(t) o---o (-1)**n*diff(F(s), s, n)Fr   
dorationalN)r   r   r	   rP  rp   _inverse_laplace_transform)
r   ru   r   ru  r~   r}   r   rw  r   r   rk   rk   rl   _inverse_laplace_diff]  s   
r  c                 C   s   t d|gd}t d}| |s| t| tjfS | ts dS | t|| }|rI|| jr?td t|||  tjfS t	| |||tjfS | t|| | }|ry|| jrotd t
|| ||||  |ddd	S t	| |||tjfS dS )
r  r~   r   r   Nz*     rule: exp(-a*s) o---o DiracDelta(t-a)z5     rule: exp(-a*s)*F(s) o---o Heaviside(t-a)*f(t-a)FTr  )r   rw   r9   r   ry   r&   r   r   rp   r  r  )r   ru   r   ru  r~   r   r   rk   rk   rl   _inverse_laplace_time_shiftn  s*   



r  c                 C   s   |  |s| t| tjfS t| j }dkrJtd|gd}|d ||  }rJt|| j	rJt
d t||  | t| |||| tjfS dS )r  r]   r~   r   r   z&     rule: F(s-a) o---o exp(-a*t)*f(t)N)rw   r9   r   ry   r!  rf   r   r   r    r   rp   r&   r  rj   )r   ru   r   ru  rf   r~   rw  rk   rk   rl   _inverse_laplace_freq_shift  s   
$r  c           	      C   s   t d|gd}t d}| || | }|rW|| jrW|| jrWtd t|| |||ddd\}}|t|d}|t	rIt
|||| |fS t|t
||||  |fS d	S )
r  r}   r   r   z+     rule: s**n*F(s) o---o diff(f(t), t, n)FTr  r]   N)r   r   rP  r   rp   r  r   r:   rw   r  r   )	r   ru   r   ru  r}   r   r   r   r   rk   rk   rl   _inverse_laplace_time_diff  s   

r  c                    s  t dgd t dgdt dgdt dgdd}tj}|  } fdd|D }d|v r8dS tj}g }	g }
g }|D ](}|  d	krP|| }qC| jr[|	| qC| jrf|
| qC|| qCt|
fd
dd}
t|	fddd}	t	|d	krdS t	|
dkrjt	|	d	krj|
d	  dkr|
d	  tj
kr|
d	  |
d	    }d|
d	    | }|jr|tt t| || t|d |  t|t|   }td 
nf|
d	  dkrK|
d	  tj
krK|
d	  |
d	    }|d }d|
d	   d  | }|jrI|ddtt t| t|  dd| |  t||  tt|t| d    }td 
n|
d	  dkr|
d	  tj
kr|
d	  |
d	    }d|
d	   d  | }|jr|dtt |d | d  t| || t|d |  d|d  | d  t|t|    }td 	n|
d	  dkr-|
d	  tj
kr-|
d	  |
d	    }d|
d	   d  | d }|jr+||d|d  |d  d|d  |  d  t|d |  t|t|  dtt |d  |tdd   d|d  | d    }td 	n|
d	  tj
 krh|
d	  dkrht|
d	  |
d	    }dt|
d	    | }|td	||  }td nt	|
dkrot	|	dkro|
d	  dkr|
d	  tj
kr|	d	  tj
kr|	d	  d	kr|
d	  }t|	d	   |
d	    | }|d|d  |d  d|d  |  d  t|d |  t|t|  dtt | |d | d  t|  }td |
d	  dkrm|
d	  dkrm|	d	  tj
krm|	d	  dkrm|	d	  |	d	    }|
d	  |
d	    }t|	d	   |
d	    | }|t| | t| tt t|| t| |  tt|| t|    }td nt	|
dkr/t	|	d	kr/|
d	  dkr|
d	  dkr|
d  tj
 kr|
d  dkr|
d  d	kr|
d	   |
d	    }dt|
d    |
d	    | }|jr|t| t||  tt|t|  }td na|
d	  dkrU|
d	  dkrU|
d	  d	krU|
d  dkrU|
d  tj
krU|
d  |
d    }d|
d	    |
d    | | }|jrS|dt|d | t|t|    }td  n|
d	  dkr|
d	  tj
kr|
d  tj
 kr|
d  dkr|
d  d	kr|
d	  |
d	    }d|
d	   t|
d     | }|jr|t|d |  t|t|  }td! n|
d	  td d krB|
d	  dkrB|
d	  d	krB|
d  dkrB|
d  tj
krB|
d  |
d    }d|
d	   tdd  |
d     |d  | }|jr@|dtt | t| t|d | t|t|   d  }td" n
|
d	  dkr|
d	  tj
kr|
d  dkr|
d  dkr|
d  d	kr|
d	  |
d	    }|d }d|
d	   d  |
d    | }|jr|d| d| d|  t||  tt|t|   dtt t| t|   }td# n|
d	  dkrD|
d	  tj
krD|
d  tj
 krD|
d  dkrD|
d  d	krD|
d	  |
d	    }d|
d	   d  t|
d    | }|jrB|dtt t| d| | t|d |  t|t|    }td$ n|
d	  dkr|
d	  tj
kr|
d  tj
 kr|
d  dkr|
d  d	kr|
d	  }|t|
d    |
d	    }|d|d  | d | t|d |  t|t|  dtt | |tdd     }td% n|
d	  dkr-|
d	  dkr-|
d  tj
 kr-|
d  dkr-|
d	  |
d	    }|
d  |
d    }|t|
d    |
d	    }|dt||  t| |  tt|| t|   }td& nt	|
dk	rt	|	dk	r|
d	  dkr|
d	  dkr|
d  dkr|
d  tj
kr|	d	  tj
kr|	d	  dkr|	d	  d	kr|
d  |
d    }|d }|
d	   |
d	    }t|	d	   |
d	    |
d    ||  | }|jr|jr||t||  tt|t|  t|t| t||  tt|t|   |t||    }td' nU|
d	  dkr|
d	  dkr|
d	  d	kr|
d  dkr|
d  tj
kr|	d	  dkr|	d	  tj
kr|	d	  |	d	    }|
d  |
d    }|| d	kr|	d	   |
d	    |
d    | }|dt|d |  t|t|  d  }td( n|
d  dk	r-|
d  dk	r-|
d  d	k	r-|
d	  dk	r-|
d	  tj
k	r-|	d	  dk	r-|	d	  tj
k	r-|	d	  |	d	    }|
d	  |
d	    }|| d	k	r+|	d	   d |
d    |
d	   d  | }|dd)|d  | t|d |  t|t|   d)tt | t|   }td* n|
d  dk	r|
d  dk	r|
d  d	k	r|
d	  dk	r|
d	  tj
k	r|	d	  dk	r|	d	  tj
k	r|	d	  |	d	    }|
d	  |
d	    }|| d	k	r|	d	   d |
d    |
d	   d  | }|dd)|d  |d  d)|d  |  d  t|d |  t|t|  d)tt | t| d|d  | d   d  }td+ nat	|
dkrLt	|	d	krL|
d	  dk
r|
d	  d	k
r|
d	  dk
r|
d  dk
r|
d  dk
r|
d  tj
 k
r|
d  dk
r|
d   |
d    }d|
d	    |
d    t|
d    | }|j
r||td d  t||  tt|t|  d| tt t|   }td, n|
d	  dkrL|
d	  dkrL|
d  dkrL|
d  tj
krL|
d  tj
 krL|
d  dkrL|
d  d	krL|
d  |
d    }|d }|
d	   |
d	    }d|
d	    |
d    t|
d    t|||   }|jrL|jrL|t|t||  tt|t|  t|t||  tt|t|   t|t||    }td- |du rSdS t|| |fS ).r  r~   r   r   r   r}   Nc                    s&   g | ]}|      qS rk   )r   r   r~   r   r   r}   ru   rk   rl   r     s   & z/_inverse_laplace_irrational.<locals>.<listcomp>r   c                       |  |   dk|   fS r   rk   r   r   r}   rk   rl   r         z-_inverse_laplace_irrational.<locals>.<lambda>r   c                    r  r   rk   r   r  rk   rl   r     r  r]   r   r   z     rule 5.3.4r   z     rule 5.3.10r   z     rule 5.3.13r      r   z     rule 5.3.16z     rule 5.3.35/44z     rule 5.3.14z     rule 5.3.22z     rule 5.3.1z     rule 5.3.5z     rule 5.3.7z     rule 5.3.8z     rule 5.3.11z     rule 5.3.12z     rule 5.3.15z     rule 5.3.23z     rule 5.3.6z     rule 5.3.17   z     rule 5.3.18z     rule 5.3.19z     rule 5.3.2z     rule 5.3.9)r   r   ry   as_ordered_factorsr  r   r  r   sortedr!  r   r.   r   r&   r<   rp   r;   r6   r:   )r  ru   r   ru  rh   r  farw  	constantszerospolesrestr  r   k_a_sqb_a_numrk   r  rl   _inverse_laplace_irrational  s>  


"&& 2&$:&<6(&& :&$& ($($,6&$(&($$.$4>&$$8&((*&( 6$( 4$&&4".$$&(&$$&02$$&0:*6$(00$&(*&&
r  c                 C   s2   t g}|D ]}|| ||| }dur|  S qdS r  N)r  r   ru   r   ru  ri  rj  r   rk   rk   rl   !_inverse_laplace_early_prog_rules  s   r  c                 C   s:   t ttttg}|D ]}|| ||| }dur|  S q	dS r  )r  r  r  r  r  r  rk   rk   rl   !_inverse_laplace_apply_prog_rules  s   r   c                 C   s   | j rdS t| dd}|j rt||||dddS t| }|j r)t||||dddS t| }|j r:t||||dddS | |rF| | }|j rSt||||dddS dS )r  NFre  Tr  )rg  r
   r  r   r  r  r  )r  ru   r   ru  r   rk   rk   rl   _inverse_laplace_expand  s0   
r  c             	      s  t d}| |}t|}g }tjg}	|D ]&}
|
 \}}|| }|d   fdd|D } fdd|| D }t	|dkrU|d t
| }|| qt	|dkrr|d t|d  |  }|t||  qt	|dkr'|d d }|d |d   }t	|dkrtjg| }t|\}}|dkr|| |d||    t| |  }njd	}|jr| }d
}tt|d | | d }t| }|r|t| |  t||  |||  | t| |  t||   }n$|t| |  t||  |||  | t| |  t||   }|t||  qt|
||||d	d\}}|| |	| qt| }|rK|jd	d}|t|	 fS )r  x_r   c                       g | ]}|  qS rk   rk   r   dc_leadrk   rl   r   4  r   z-_inverse_laplace_rational.<locals>.<listcomp>c                    r  rk   rk   r   r  rk   rl   r   5  r   r]   r   r   FTr  r  )r   r  r   r  r   ry   r  r   rX  r!  r9   r  r&   r:   r  r   tupler   r   rP   r
  r.   r   r(   r*   r1   r2   r  rL   )r  ru   r   ru  r   r  r   r  r  r  r  r}   r   r1  r#  r   r~   r   lr   hypb2bsr  r   rh   rk   r  rl   _inverse_laplace_rational&  sf   


(&
H

r  c                   s~  t | }g }g }|D ]}	|	tr |	       }	|	j dd\}
}|r=|	 r=t| |||d }dusht	| | }dusht
| || }dusht| || }dusht| || }durin1t fdd|tD rt| ||tjf}nt| |||d }durn
t| ||tjf}|\}}||
|  || qt | }|r|jdd}t| }||fS )z
    Front-end function of the inverse Laplace transform. It tries to apply all
    known rules recursively.  If everything else fails, it tries to integrate.
    Fr  r   Nc                 3   r  r   rO  r  r   rk   rl   r     r   z-_inverse_laplace_transform.<locals>.<genexpr>r  )r   r  rw   r&   r   rR   r  r  r  r  r  r  r   r  r   r   r  r   ry   r_   r  r   rL   )r  r   rI  ru  r   r  r  r  r  r  r  r   r   r  r  rh   r  rk   r  rl   r  ^  s\   



r  c                   @   sP   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d ZdS )r  z
    Class representing unevaluated inverse Laplace transforms.

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

    For how to compute inverse Laplace transforms, see the
    :func:`inverse_laplace_transform` docstring.
    zInverse LaplaceNoner   c                 K   s(   |d u rt j}tj| ||||fi |S r   )r  _none_sentinelrF   __new__)r   r   ru   r   ru  optsrk   rk   rl   r    s   zInverseLaplaceTransform.__new__c                 C   s   | j d }|tju rd }|S )Nr   )rf   r  r  )r  ru  rk   rk   rl   fundamental_plane  s   

z)InverseLaplaceTransform.fundamental_planec                 K   s   t |||| jfi |S r   )r_   r  )r  r   ru   r   r  rk   rk   rl   r    s
   
z*InverseLaplaceTransform._compute_transformc                 C   sL   | j j}tt|| | ||tjtj  |tjtj  fdtj tj  S )Nr   )	__class___crD   r&   r   ImaginaryUnitr   Pi)r  r   ru   r   r   rk   rk   rl   r    s    z$InverseLaplaceTransform._as_integralc           	      K   sj   | dd}| dd}td| j| j| jf | j}| j}| j}| j}t|||||dd}|r3|d S |S )r  r  Tr   Fz[ILT doit] (%s, %s, %s)r  r   )r  rW   r  r  r  r  r  )	r  r  r  rE   r   rI  r  ru  r   rk   rk   rl   r    s    zInverseLaplaceTransform.doitN)re   r  r  r  r  r   r  r  r  propertyr  r  r  r  rk   rk   rk   rl   r    s    	
r  c           	         sp     dd}  dd}t| tr"t| dr"|  fddS t| jd|d\}}|r4|S ||fS )	a  
    Compute the inverse Laplace transform of `F(s)`, defined as

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

    for `c` so large that `F(s)` has no singularites in the
    half-plane `\operatorname{Re}(s) > c-\epsilon`.

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

    The plane can be specified by
    argument ``plane``, but will be inferred if passed as None.

    Under certain regularity conditions, this recovers `f(t)` from its
    Laplace Transform `F(s)`, for non-negative `t`, and vice
    versa.

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

    Note that this function will always assume `t` to be real,
    regardless of the SymPy assumption on `t`.

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

    Examples
    ========

    >>> from sympy import inverse_laplace_transform, exp, Symbol
    >>> from sympy.abc import s, t
    >>> a = Symbol('a', positive=True)
    >>> inverse_laplace_transform(exp(-a*s)/s, s, t)
    Heaviside(-a + t)

    See Also
    ========

    laplace_transform
    hankel_transform, inverse_hankel_transform
    r  Tr   Fr  c                    s   t | fi  S r   )inverse_laplace_transform)Fijr  ru  ru   r   rk   rl   r   	  r   z+inverse_laplace_transform.<locals>.<lambda>r  )r  rx   rM   r  r  r  r  )	r   ru   r   ru  r  r  rE   r   r   rk   r  rl   r    s   -
r  c                    sl   t dtgd\fdd  fdd fdd	fd	d
 fdd | S )zEFast inverse Laplace transform of rational function including RootSumza, b, nr   c                    sN   |  s| S | jr | S | jr| S | jr| S t| tr%| S tr   )rw   rg  rW  rq   rx   rS   NotImplementedErrore)_ilt_add_ilt_mul_ilt_pow_ilt_rootsumru   rk   rl   _ilt	  s   

z#_fast_inverse_laplace.<locals>._iltc                    s   | j t | j S r   )rj   maprf   r  r!  rk   rl   r  -	  s   z'_fast_inverse_laplace.<locals>._ilt_addc                    s$   |  \}}|jrt| | S r   )r  rW  r  )r  r  r   )r!  ru   rk   rl   r  0	  s   z'_fast_inverse_laplace.<locals>._ilt_mulc                    s   |      }|d urM| |  | }}}|jr>|dk r>| d  t||    ||  t|   S |dkrMt||   | S tr   )r   
is_Integerr&   r?   r  )r  r   nmambm)r~   r   r}   ru   r   rk   rl   r  6	  s   4z'_fast_inverse_laplace.<locals>._ilt_powc                    s,   | j j}| j j\}t| jt|t |S r   )funr   	variablesrS   polyr   rR   )r  r   variabler#  rk   rl   r   @	  s   
z+_fast_inverse_laplace.<locals>._ilt_rootsum)r   r   )r  ru   r   rk   )
r!  r  r  r  r   r~   r   r}   ru   r   rl   _fast_inverse_laplace	  s   
r,  )Tr   )r  rc   r`   
sympy.corer   r   r   sympy.core.addr   sympy.core.cacher   sympy.core.exprr   sympy.core.functionr   r	   r
   r   r   r   r   r   r   r   sympy.core.mulr   r   sympy.core.relationalr   r   r   r   r   r   r   r   sympy.core.sortingr   sympy.core.symbolr   r   r   $sympy.functions.elementary.complexesr    r!   r"   r#   r$   r%   &sympy.functions.elementary.exponentialr&   r'   %sympy.functions.elementary.hyperbolicr(   r)   r*   r+   (sympy.functions.elementary.miscellaneousr,   r-   r.   $sympy.functions.elementary.piecewiser/   r0   (sympy.functions.elementary.trigonometricr1   r2   r3   r4   sympy.functions.special.besselr5   r6   r7   r8   'sympy.functions.special.delta_functionsr9   r:   'sympy.functions.special.error_functionsr;   r<   r=   'sympy.functions.special.gamma_functionsr>   r?   r@   rA   -sympy.functions.special.singularity_functionsrB   sympy.integralsrC   rD   r  rE   rF   rG   sympy.logic.boolalgrH   rI   rJ   rK   rL   sympy.matrices.matrixbaserM   sympy.polys.matrices.linsolverN   sympy.polys.polyerrorsrO   sympy.polys.polyrootsrP   sympy.polys.polytoolsrQ   sympy.polys.rationaltoolsrR   sympy.polys.rootoftoolsrS   sympy.utilities.exceptionsrT   rU   rV   sympy.utilities.miscrW   ra   rn   rp   r   r   r^   r   r   r   r   r  r  r  r  rF  rM  rR  rd  rh  rl  rx  r{  r  r  r   rZ  r  r_   r  r  r  r  r  r  r  r  r  r   r  r  r  r  r  r,  rk   rk   rk   rl   <module>   s    0( [

o

 Y

)

,

 
 
 

2



/<-
C
8 
P

(





  <



7
8
G=