
    Rie                     d   d Z ddlmZmZmZ ddlmZ ddlmZ ddl	m
Z
mZmZmZ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 ddlmZ dd	lm Z m!Z!m"Z" dd
l#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z) ddl*m+Z+m,Z, ddl-m.Z.m/Z/m0Z0m1Z1 ddl2m3Z3m4Z4m5Z5 ddl6m7Z7 ddl8m9Z9m:Z:m;Z; ddl<m=Z=m>Z>m?Z?m@Z@ ddlAmBZBmCZC ddlDmEZEmFZFmGZG ddlHmIZImJZJmKZK ddlLmMZMmNZN ddlOmPZPmQZQmRZR ddlSmTZTmUZUmVZVmWZWmXZX ddlYmZZZ ddl[m\Z\ ddl]m^Z^ ddl_m`Z` ddlambZb ddlcmdZd ddlemfZf ddlgmhZhmiZimjZj ddlkmlZlmmZm d  Znd! ZodFd#Zpd$ Zqed%             Zrd& Zsd' Ztd( Zud) Zvd* Zwd+ Zxd, ZydFd-ZzdFd.Z{dFd/Z|dFd0Z}d1 Z~d2 ZdFd3Z G d4 d5eQ          ZdFd6ZdFd7Zd8 Zed9             Zd: Zd; Zd< Zd= Zd> Zd? Z	 dGd@Z G dA dBeQ          ZdHdDZdE ZdCS )IzLaplace Transforms    )SpiI)Add)cacheit)	AppliedUndef
Derivativeexpandexpand_complex
expand_mulexpand_trigLambdaWildFunctiondiff)Mulprod)
_canonicalGeGtLt
UnequalityEq)ordered)DummysymbolsWild)reimargAbs
polar_liftperiodic_argument)explog)coshcothsinhasinh)MaxMinsqrt)	Piecewise)cossinatan)besselibesseljbesselkbessely)
DiracDelta	Heaviside)erferfcEi)digammagamma
lowergamma)	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)debugdebugfc                     fdfdfdfd}d }ddl m}  ||           }  || t                    }  || t          f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                 J    | k    rdS | j         r| j        k    r| j        S d S )N   )is_Powbaser#   )exss    7lib/python3.11/site-packages/sympy/integrals/laplace.pypowerz_simplifyconds.<locals>.powerH   s1    7719 	A6Mt    c                 `   |                                r|                               rdS t          | t                    r| j        d         } t          |t                    r|j        d         }|                                r d|z  d| z            S  |          }|dS 	 |dk    r3t          |           t                    |z  k    t          j        k    rdS |dk     r3t          |           t                    |z  k    t          j        k    rdS dS dS # t          $ r Y dS w xY w)z_ Return True only if |ex1| > |ex2|, False only if |ex1| < |ex2|.
            Else return None. Nr   rT   FT)has
isinstancer    argsr   true	TypeError)ex1ex2nabiggerrZ   rX   s      rY   rf   z_simplifyconds.<locals>.biggerO   s<    771:: 	#''!** 	4c3 	(1+Cc3 	(1+C771:: 	(6!C%3'''E#JJ94	1uu#c((c!ffai/AF::u1uu#c((c!ffai/AF::t u:: 	 	 	DD	s   )7D "7D 
D-,D-c                     | j         st          | t                    r|j         st          |t                    s| |k     S  | |          }|| S | |k     S )z simplify x < y )is_positiver^   r    )xyrrf   s      rY   repliez_simplifyconds.<locals>.repliee   sg     	*Q"4"4 		)3As););	ENF1aLL=5LAr[   c                 H     | |          }|dv rdS t          | |          S )NTFT)r   )ri   rj   brf   s      rY   repluez_simplifyconds.<locals>.replueo   s2    F1aLL4!Qr[   c                 <    | dv rt          |           S  | j        | S )Nrn   )boolreplace)rW   r_   s     rY   replz_simplifyconds.<locals>.replu   s'    88Orz4  r[   r   )collect_absc                      ||           S N )ri   rj   rl   s     rY   <lambda>z _simplifyconds.<locals>.<lambda>|   s    vva|| r[   )sympy.simplify.radsimpru   r   r   r   r   )	exprrX   re   rp   rt   ru   rf   rZ   rl   s	    ``   @@@rY   _simplifycondsr|   '   s    B           ,             ! ! ! 322222;tD4b&!!D4b333344D4j&))DT77Nr[   c                 R    t          | |                     t                              S )zs
    Expand an expression involving DiractDelta to get it as a linear
    combination of DiracDelta functions.
    )rG   atomsr4   r{   s    rY   expand_dirac_deltar      s     
 djj44555r[   Tc                    t          d          t          d| f           t          d|f           |                     t                    rdS t	          | t           z            z  t          j        t          j        f          }t          d|f           |                    t                    s;t          |                              |          t          j        t          j        fS |j        st          d           dS |j        d         \  }}|                    t                    rt          d           dS fd	fd
t#          |          D             }d |D             }|sd |D             }t%          t'          |                    }d |                    fd           |st          d           dS |d         \  }}	fd}
|r"t+          ||          }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.
    rX   z&[LT _l_t_i ] started with (%s, %s, %s)z [LT _l_t_i ]     and simplify=%sNz[LT _l_t_i ]     integrated: %sz[LT _l_t_i ]     not piecewise.r   z-[LT _l_t_i ]     integral in unexpected form.c                 	   ddl m} t          j        }t          j        }t          t          |                     } t          dt          g          \  }}}}}}	}
|t          t          |z   |z                      z  |k     |t          t          |z   |z                      z  |k    t          t          |z   |z  |z  |                    |k     t          t          |z   |z  |z  |                    |k    t          t          t          |z             |z  |z  |                    |k     t          t          t          |z             |z  |z  |                    |k    f}| D ]S}t          j        }g }t          |          D ]}|j        r|j        j        v r|j        }|j        r#t'          |t(          t*          f          r|j        }|D ]}|                    |          r nrG|         j        r:|         |         z  t2          dz  k    rt5          |         z              dk     }|                    |t7          |t          t          |
z                      z  |z            t          |z            |	z  z  z
  dk               sc|                    t7          |t          t          |z  |
z  |                    |z  z
            t          |z            |	z  z  dk               sp|                    |t7          t          t          t                    |z  |
z  |                    |z            t          |z            |	z  z  z
  dk               r9t9          fd||||	|
fD                       rt5                    |         k    }|                    t4          d                               t5                              }|j        r3|j        dv s*|                               s|                               s||gz  } ||          }|j        r	|j        dv r||gz  }|j!        k    rtE          d	             d
S tG          |j!        |          }|t          j        urtI          ||          }<tK          |tM          |           }U||j        r|j'        n|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   2   K   | ]}|         j         V  d S rw   )rh   ).0wildms     rY   	<genexpr>zH_laplace_transform_integration.<locals>.process_conds.<locals>.<genexpr>   s:       - -TQtW0 - - - - - -r[   c                 Z    |                                                                  d         S )Nr   )r
   as_real_imag)ri   s    rY   ry   zG_laplace_transform_integration.<locals>.process_conds.<locals>.<lambda>   s    !((**"9"9";";A"> r[   )z==z!=z/[LT _l_t_i ]     convergence not in half-plane.N)(sympy.solvers.inequalitiesr   r   NegativeInfinityr`   rB   rA   r   r   r    r   r"   r!   InfinityrC   is_Relationalrhsfree_symbolsreversedr^   r   r   reversedsignmatchrh   r   r   r-   allrs   subsrel_opr]   ltsrP   r*   r)   rE   rD   	canonical)condsr   re   auxpqw1w2w3w4w5patternsca_aux_dpatd_solnr   rX   ts                      @rY   process_condsz5_laplace_transform_integration.<locals>.process_conds   s"   @@@@@@f&--((#* dQC$9 $9 $9 1b"b"b c#q2vqj//"""R'c#q2vqj//"""b(!1r6A+a-4455:!1r6A+a-4455;!:a"f#5#5"9!";R@@AABF!:a"f#5#5"9!";R@@AARGI  .	* .	*ABDq\\ '+ '+? #qAE,>'>'>
A? 'z!b"X'>'> 'A#  CA  +1) +aeAaDjBqD.@.@A"I*AGGABs3qt99~~$5b$8 9 9#ae**b. HH1LMM ,A$5aeBh$B$B C CB FFGGArE

B')*+, ,A  2C 1*Q--2CB2F J JKKBN !!R%jj"n- -/012 2A  % - - - -BB>, - - - - - %1!AYY>>@ @@DRUUA  O/0x</G/G66!99 0H,.FF1II 0HQCKD((Q//) T[L-H-HQCKD8q==KLLL444TXr**BB##AJJ#r4y))3#4=#--#==r[   c                 &    g | ]} |          S rx   rx   )r   r   r   s     rY   
<listcomp>z2_laplace_transform_integration.<locals>.<listcomp>   s#    777!]]1777r[   c                 f    g | ].}|d          t           j        k    r|d         t           j        u,|/S )rT   r   )r   falser   r   ri   s     rY   r   z2_laplace_transform_integration.<locals>.<listcomp>   sH     : : :A!A$g# #A$a&888 888r[   c                 >    g | ]}|d          t           j        k    |S rT   )r   r   r   s     rY   r   z2_laplace_transform_integration.<locals>.<listcomp>   s#    666adagoo!ooor[   c                 6    | dv rdS |                                  S )Nrn   r   )	count_opsr   s    rY   cntz+_laplace_transform_integration.<locals>.cnt   s"    =  1~~r[   c                 8    | d           | d                   fS Nr   rT   rx   )ri   r   s    rY   ry   z0_laplace_transform_integration.<locals>.<lambda>   s    qteSS1YY/ r[   )keyz&[LT _l_t_i ]     no convergence found.c                 0    |                                S rw   )r   )r{   rX   s_s    rY   sbsz+_laplace_transform_integration.<locals>.sbs   s    yyBr[   )r   rQ   r]   r4   r<   r#   r   Zeror   r=   r>   r   r   r`   is_PiecewiserP   r_   rC   listr   sortr|   r   )fr   r   simplifyFcondr   conds2re   r   r   r   r   rX   s    ``        @@@rY   _laplace_transform_integrationr      s    	c

A
3aAY???
-|<<<uuZ t!C1II+161:677A
,qe44455?? N21113EqvMM> /000tfQiGAtuuX =>>>t>> >> >> >> >> >>@ 8777y777E: : : : :F 766U666!!E      
JJ////J000 6777t1XFAs            (1a##S!Q''QVVAr]]H--ss1vvz##c((7K7KKKr[   c                     | j         }t          | j                  }t          | j                  dk    r| S fd|D             }|j        r ||                               S  || 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)`.
    r   c                 0    g | ]}t          |          S rx   _laplace_deep_collect)r   r   r   s     rY   r   z)_laplace_deep_collect.<locals>.<listcomp>  s$    >>>#%c1-->>>r[   )funcr   r_   lenis_Addcollect)r   r   r   r_   s    `  rY   r   r      sz     6D<<D
16{{a>>>>>>>; 	4;&&q)))4;r[   c                  N   t          d          t          d          } t          dg          }t          dg          }t          dg          }t          dg          }t          dg          }fd	}t          d
           g ||| z  t          j        t          j        |ft          |z  |z
            t          |  |z  |z            t          |          z  t          t          |dk    |dk              t          |dk     |dk                        t          j        |ft          |z  |z
            t          d          t          t          |dk     |dk              t          |dk    |dk                        t          j        |ft          |z  |z
            t          |  |z  |z            | z  t          |dk    |dk              t          j        |ft          |z  |z
            dt          |  |z  |z            z
  | z  t          |dk     |dk               t          j        |ft          |z  |z
            d| z  t          |dk    |dk              t          j        |ft          |z  |z
            dt          |dk     |dk              t          j        |fd| dz  z  t          j        t          j        |fd|z  |z   z  t          | |z  | z             t          | |z  | z            z  |z  t          t          ||z                      t          k     t          j        |fdt!          |z  |z             z  t!          |t          z  | z            t          ||z  | z            z  t#          t!          ||z  | z                      z  |z  t          t          ||z                      t          k     t          j        |f|z  |z   t          d           dz  z  d|t          d           dz  z  z  dt          | z  |z  t          d          dz  z  z  t          ||z  | z            z  t#          t!          ||z  | z                      z  |z  z
  t          t          ||z                      t          k     t          j        |ft!                    |z   z  t!          t          | z            t          t!          |          z  t          || z            z  t#          t!          || z                      z  z
  t          t          |                    t          k     t          j        |fd|t!                    z  dz  z   z  t          |t          d          dz  z  z  t          || z            z  t#          t!          || z                      z  t          j        t          j        |f|z  t%          |dz             | |dz   z  z  |dk    t          j        |f|z  |z   |z  t'          |dz   ||z  | z            t          | |z  | z            z  | |dz   z  z  |z  t          |dk    t          t          ||z                      t          k               t          j        |f|z  |z   z  ||z  t%          |dz             z  t'          | || z            z  t          |dk    t          t          |                    t          k               t          j        |ft          |z  |z
            t          |           | |z
  z  t          j        t)          |          |ft          |z  |z
            z  t          |           | |z
  dz  z  t          j        t)          |          |f|z  t          |z            z  t%          |dz             | |z
  |dz   z  z  t)          |          dk    t)          |          |ft          | dz  z            t!          t          dz  |z            t          | dz  dz  |z            z  t#          | t!          d|z            z            z  t)          |          dk    t          j        |ft          | dz  z            z  dd|z  z  dt!          t                    z  d|z  t          d          dz  z  z  | z  t#          | t!          d|z            z            z  z
  t)          |          dk    t          j        |ft          | z            dt!          || z            z  t+          ddt!          || z            z            z  t)          |          dk    t          j        |ft!                    t          | z            z  t          d          dz  t!          t          | dz  z            z  ddt!          || z            z  z   z  t          dt!          || z            z            z  t)          |          dk    t          j        |ft          | z            t!                    z  t!          t          | z            t          dt!          || z            z            z  t)          |          dk    t          j        |ft          | z            t!                    z  z  t!          t          |z            t          dt!          || z            z            z  t)          |          dk    t          j        |f|z  t          | z            z  d|| z  |dz   dz  z  z  t+          |dz   dt!          || z            z            z  t)          |          dk    t          j        |ft          dt!          |z            z            | dz  t!          t          |z            | t          d           dz  z  z  t          || z            z  t#          t!          || z                      z  z
  t          t          |                    t          k     t          j        |ft          dt!          |z            z            t!                    z  t          | z  t          d          dz  z  t          || z            z  t#          t!          || z                      z  t          t          |                    t          k     t          j        |ft-          |z            t-          t          t          j                  | z  |z             | z  |dk    t          j        |ft-          d|z  z             t          | |z             | z  t          |  |z            z  t          t          |                    t          k     t          j        |ft-          |z  |z             t-          |          t          | |z  |z            | z  |z  t          |  |z            z  z
  | z  |z  t          |dk    t          t          |                    t          k               t          j        |ft-                    t!                    z  t!          t          | z             t-          d| z  t          t          j                  z            z  t          j        t          j        |f|z  t-                    z  t%          |dz             | | dz
  z  z  t1          |dz             t-          |           z
  z  t)          |          dk    t          j        |ft-          |z            dz  t-          t          t          j                  | z  |z            dz  t          dz  dz  z   | z  |dk    t          j        |ft3          |z            || dz  |dz  z   z  t          j        t          t5          |                    |ft          t3          |z                      || dz  |dz  z   z  t7          t          | z  dz  |z            z  |dk    t          j        |ft3          |z            z  t9          || z            t          j        t          t5          |                    |ft3          |z            dz  z  t-          dd|dz  z  | dz  z  z             dz  t          j        dt          t5          |                    z  |ft3          |z            dz  dz  z  |t9          d|z  | z            z  | t-          dd|dz  z  | dz  z  z             z  dz  z
  t          j        dt          t5          |                    z  |ft3          dt!          |z            z            t!          t          |z            | z  t!          |           z  t          | | z            z  t          j        t          j        |ft3          dt!          |z            z            z  t          t;          t!          || z                      z  t          j        t          j        |ft=          |z            | | dz  |dz  z   z  t          j        t          t5          |                    |ft=          |z            dz  | dz  d|dz  z  z   | dz  d|dz  z  z   z  | z  t          j        dt          t5          |                    z  |ft!                    t=          dt!          |z            z            z  t!          t                    dz  | t          d           dz  z  z  | d|z  z
  z  t          | | z            z  t          j        t          j        |ft=          dt!          |z            z            t!                    z  t!          t          | z            t          | | z            z  t          j        t          j        |ft3          |z            t3          |z            z  d|z  |z  | z  | dz  ||z   dz  z   z  | dz  ||z
  dz  z   z  t          j        t          t5          |                    t          t5          |                    z   |ft=          |z            t3          |z            z  || dz  |dz  z
  |dz  z   z  | dz  ||z   dz  z   z  | dz  ||z
  dz  z   z  t          j        t          t5          |                    t          t5          |                    z   |ft=          |z            t=          |z            z  | | dz  |dz  z   |dz  z   z  | dz  ||z   dz  z   z  | dz  ||z
  dz  z   z  t          j        t          t5          |                    t          t5          |                    z   |ft?          |z            || dz  |dz  z
  z  t          j        t          t)          |                    |ftA          |z            | | dz  |dz  z
  z  t          j        t          t)          |                    |ft?          |z            dz  d|dz  z  | dz  d|dz  z  | z  z
  z  t          j        dt          t)          |                    z  |ftA          |z            dz  | dz  d|dz  z  z
  | dz  d|dz  z  | z  z
  z  t          j        dt          t)          |                    z  |ft?          |z            z  t-          | |z   | |z
  z            dz  t          j        t          t)          |                    |f|z  t?          |z            z  t%          |dz             dz  | |z
  | dz
  z  | |z   | dz
  z  z
  z  |dk    t          |          |f|z  tA          |z            z  t%          |dz             dz  | |z
  | dz
  z  | |z   | dz
  z  z   z  |dk    t          |          |ft?          dt!          |z            z            t!          t          |z            | z  t!          |           z  t          || z            z  t          j        t          j        |ftA          dt!          |z            z            d| z  t!          t          |z            | z  t!          |           z  t          || z            z  t;          t!          || z                      z  z   t          j        t          j        |ft!                    t?          dt!          |z            z            z  t          t          d          dz  z  | t          d           dz  z  z  | dz  |z   z  t          || z            z  t;          t!          || z                      z  |t          d          dz  z  | dz  z  z
  t          j        t          j        |ft!                    tA          dt!          |z            z            z  t          t          d          dz  z  | t          d           dz  z  z  | dz  |z   z  t          || z            z  t          j        t          j        |ft?          dt!          |z            z            t!                    z  t          t          d          dz  z  | t          d           dz  z  z  t          || z            z  t;          t!          || z                      z  t          j        t          j        |ftA          dt!          |z            z            t!                    z  t          t          d          dz  z  | t          d           dz  z  z  t          || z            z  t          j        t          j        |ft?          t!          |z                      dz  t!                    z  t          t          d          dz  z  dz  | t          d           dz  z  z  t          || z            dz
  z  t          j        t          j        |ftA          t!          |z                      dz  t!                    z  t          t          d          dz  z  dz  | t          d           dz  z  z  t          || z            dz   z  t          j        t          j        |ft;          |z            t          | dz  d|z  dz  z            t#          | d|z  z            z  | z  dt          t          |                    z  t          k     t          j        |ft;          t!          |z                      t!          |          t!          | |z             z  | z  t          j        tC          t          j        t)          |                     |ft          |z            t;          t!          |z                      z  t!          |          t!          |           z  | |z
  z  t          j        tC          t          j        t)          |                    |ft;          t!          |z            dz            dt          t!          || z                       z
  | z  t)          |          dk    t          j        |ft#          t!          |z                      t!          | |z             t!          |          z
  t!          | |z             z  | z  t          j        t)          |           |ft          |z            t#          t!          |z                      z  d| t!          || z            z   z  t          j        t          j        |ft#          t!          |z            dz            t          t!          || z                       | z  t)          |          dk    t          j        |ftE          ||z            ||z  t!          | dz  |dz  z             | t!          | dz  |dz  z             z   |z  z  z  t)          |          dk    t          t5          |                    |f|z  tE          ||z            z  d|z  t!          t                    z  t%          |t          j#        z             z  ||z  z  | dz  |dz  z   | t          j#        z
  z  z  t          t)          |          t          j#         k    tI          ||                    t          t5          |                    |f|z  tE          ||z            z  d|dz   z  t!          t                    z  t%          |t          d          dz  z             z  ||z  z  | z  | dz  |dz  z   | t          d          dz  z
  z  z  t          t)          |          dk    tI          ||dz                       t          t5          |                    |ftE          ddt!          |z            z            t          | | z            | z  t          j        t          j        |f|z  tE          |dt!          |z            z            z  ||dz  z  | | dz
  z  z  t          | | z            z  t          t)          |          dk    tI          ||t          j#        z                      t          j        |ftE          d|t!          dz  |z  z             z            t          || z  |t!          | dz  |dz  z             z  z
            t!          | dz  |dz  z             z  t          t          |                    t          k     t          t5          |                    |ftK          ||z            ||z  t!          | dz  |dz  z
            | t!          | dz  |dz  z
            z   |z  z  z  t)          |          dk    t          t)          |                    |f|z  tK          ||z            z  d|z  t!          t                    z  t%          |t          j#        z             z  ||z  z  | dz  |dz  z
  | t          j#        z
  z  z  t          t)          |          t          j#         k    tI          ||                    t          t)          |                    |f|z  tK          ||z            z  d|dz   z  t!          t                    z  t%          |t          d          dz  z             z  ||z  z  | z  | dz  |dz  z
  | t          d          dz  z
  z  z  t          t)          |          dk    tI          ||dz                       t          t)          |                    |f|z  tK          |dt!          |z            z            z  ||dz  z  | | dz
  z  z  t          || z            z  t          t)          |          dk    tI          ||t          j#        z                      t          j        |ftM          d|z            dt          z  tO          | |z            z  t!          | dz  |dz  z             z  t          j        t          t5          |                    |ft+          d|z            t-          | t!          | dz  |dz  z
            z   |z            t!          | dz  |dz  z
            z  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   rX   re   r   ro   rd   tauomegac                 $    t          |           S rw   r   )r   r   s    rY   dcoz!_laplace_build_rules.<locals>.dco+  s    ,Q222r[   z&_laplace_build_rules is building rulesr   rT   r      g      ?         )(r   r   rP   r   r`   r   r4   r#   r    rD   rE   r   r5   r8   r   r   r+   r7   r:   r;   r   r2   r$   
EulerGammar9   r.   r   r&   r/   r6   r-   r'   r%   r)   r1   Halfr   r0   r3   r(   )	rX   re   ro   rd   r   r   r   laplace_transform_rulesr   s	           @rY   _laplace_build_rulesr     s-#   $ 	c

Ac

AS1#AS1#AS1#A
uqc
"
"
"C1#&&&E22222	
2333u	
AaC	
	u 
AaCE		C1QKKA.	CAqAvAE16 2 2	3	3	
	S	"u 
AaCE		AaDD	CAqAvAE16 2 2	3	3	
	S	"u 
1Q3q5		3r!tAv;;q=	QUAE		AFC	)u 
1Q3q5		Ac1"Q$q&kkM1,	QUAE		AFC	)u 
1Q3q5		1Q3	QUAF		QVS	*u 
1Q3q5		1	QUAE		AFC	)u" 
AadF	
	#u& 
AaCES!Aa[[LQBqDF+A-	S1XX	QVS	*'u* 
4!A;;QrT!VS1QZZ/T!A#a%[[0A0AA!C	S1XX	QVS	*+u. A#a%AaDD57		
1!uQw<2a46QqTT!V,,S1QZZ7$tAaCE{{:K:KKAM	M	S1XX	QVS	*/u4 
a!A#RT

2d1gg:c!A#hh#6tD1II#FF	SVVr	163	(5u8 
Ad1ggIC 	!2a!A$$q&k>#ac((#:4QqS		??#J	
	9u< 
AuQqSzz!ac("	
R	=u@ A#a%!Z!QqSU++C1QKK7AaC@B	QVSQqS]]R'	(	(!&#	7AuD 
AqsQT%!**_ZAaC%8%88	QVSQ[[2%	&	&	5EuH 
QqSWsC4yy!A#	
A	IuL 
3qs3w<<cTAaC!8+	
A	MuP 
Ac!A#hhac

AaC1Q3</	ARUUC	!QuT 
aR1WtBqDF||C1QqMM1$qac{2C2CC	AAFC	!UuX 
3r!Q$w<<	
AaC488QqSAaDDFO+A-d1T!A#YY;.?.??	?	AAFC	!Yu^ 
aRTAd1Q3iiK1T!A#YY; 7 77	A!QVS	"_ub 
aaRT		
1aR1W	q4!99}	-c"T!A#YY,.?.?	?	A!QVS	"cuh 
aRT477	DAJJs2d1Q3ii<'8'88	A!QVS	"iul 
aRTAd1ggI	RT

3r$qs))|+<+< <	AAFC	!mup 
Ac1"Q$iiAaCAaC7++GAaC4!99,E,EE	AAFC	!qut 
RQqS		\			
RbdA1aL(QqS1DacOOC	C	SVVr	163	(uuz 
RQqS		\		477	"RTQqTT!V$4S1XX$=d4!99oo$M	SVVr	163	({u~ 
QqSCAL))!+A-...q0	
Q	uB 
QqsUc!A#hhYq[QBqD)	SVVr	163	(CuF 
QqSUc!ffS1QZZ\!^Br!tHH44a79	QUCAKK"$	%	%qvs	4GuJ 
QQ$r!t**S1S->->)>%?%??	
	KuN 
Ac!ffeAaCjjaRT*GAaCLLQ,?@	AQVS	"OuR 
QqS1s3q|,,Q.q01114RU1W<a?	
Q	SuV 
U1Wuad5!8m,	
RYY	&WuZ 
Sq\\		E1a4q=1$r!tAve|2D2DD	AFC	![u^ 
U1WaeAg	
RYY	&_ub 
U1Wq	C!E1H*QT/ 12214	
3r%yy>>!3	(cuf 
U1WqA		tAeGAI	qQqz!Q$%6!7!779	9	
3r%yy>>!3	(gul 
QtAaCyy[		41::a<Q/QBqD		9	
	mup 
QtAaCyy[		!	RD1II.	
	qut 
U1Wq!Q$uax-(	
RYY	&uux 
U1Wq1a4%(
?QT!E1H*_=a?	
3r%yy>>!3	(yu| 
aQtAaCyy[!!	!488A:a1Q44%'l#:AacE#B3r!t99#L	
	}u@ 
QtAaCyy[		$q''	!41::c1"Q$ii#7	
	AuD 
QqS#ac((	AaCE!GQT1Q3(]3QT1Q3(]C	
RUUC1JJ&	-EuH 
QqS#ac((	Aq!tAqDyA~.1acAX>1acAXN	
RUUC1JJ&	-IuL 
QqS#ac((	Aq!tAqDyA~.1acAX>1acAXN	
RUUC1JJ&	-MuP 
acAq!tAqDyM	
RUUS	"QuT 
acAq!tAqDyM	
RUUS	"UuX 
acAqAvq!tAadF1H}-	
3r!uu::s	$Yu\ 
acA1Qq!tVad1QT6!8m4	
3r!uu::s	$]u` 
ac1c1Q31+&&q(	
RUUS	"aud 
Ad1Q3iiqsA!r!t}acaRT]'BC	
RQ	euh 
Ad1Q3iiqsA!r!t}acaRT]'BC	
RQ	iul 
aQqS		k		DAJJqLa0QqS9	
	mup 
aQqS		k		AaCRT

1T!WW 4S1XX =c$qs))nn LL	
	quv GGD4!99%%%1aLaddU1W%qs1u-!HHac^^$$%!QKB$78FAFC		!uu~ 
aaQqS		k""	"B1aLaddU1W$=qs1u$Ec!A#hh$N	
	uB 
aQqS		k		477	"	add1fa1Q44%'l	"3qs88	+c$qs))nn	<FAFC	!CuH 
aQqS		k		477	"B1aLaddU1W$=c!A#hh$F	
	IuL 
d1Q3ii!	DGG	#R!A$$q&\!^A1aL%@#ac((1*%M	
	MuP 
d1Q3ii!	DGG	#R!A$$q&\!^A1aL%@#ac((1*%M	
	QuT 
QqS3q!tQqS1H}%%d1ac7mm3A5	
3s1vv;;	QVS	*UuX 
T!A#YYaac*1,	
QVbeeV$$c	+Yu\ 
QqS#d1Q3ii..	 $q''$q''/1Q3"7	
QVRUU##S	*]u` 
T!A#YYq[		Ac4!99*oo-q0	AAFC	!aud 
d1Q3ii4!99T!WW,d1Q3ii79	
"Q%%	euh 
QqS$tAaCyy//	!1aQqS		k?	
	iul 
d1Q3iik		Cac
OOA-	AAFC	!mup 
AaC!Q$QT!Q$Y41QT	??1BQ0F FG	ASAZZ	&qut 
Aga1oo		
Ad2hhuQqvX	&q!t	+QT!Q$Y1"QV),D	D	RUUafW_bAhh	'	'RUUS	:uuz 
Aga1oo		
QqS$r((	51Q446??	*1a4	/	11a4191Q446	2J	J	RUURZAqs	$	$c"Q%%jj#	7{u@ 
Ad1Q3iiK	 	 #qbd))A+	
	AuD 
Q1T!A#YY;''	'QqS!qbd));C1II)E	RUURZAqx	)	)163	8EuH 
Ad1a4!8nn$	%	%	QqS41QT	??""	#	#DAadOO	3	SVVr	3r!uu::s	,IuN 
AaC!Q$QT!Q$Y41QT	??1BQ0F FG	ASAZZ	&OuR 
Aga1oo		
Ad2hhuQqvX	&q!t	+QT!Q$Y1"QV),D	D	RUUafW_bAhh	'	'RUUS	:SuX 
Aga1oo		
QqS$r((	51Q446??	*1a4	/	11a4191Q446	2J	J	RUURZAqs	$	$c"Q%%jj#	7Yu^ 
Q1T!A#YY;''	'QqS!qbd));C!HH)D	RUURZAqx	)	)163	8_ub 
AaC"R%ac

*41QT	??:	
RUUS	"cuf 
AaC#q41QT	??2A566QT!Q$YH	
"Q%%	gul #Aq((r[   c                    t          d|g          }t          dd          }|                     |          }|r||         j        d                             |          } |j        ||z            }|r||         j        r||         dk    r{t          d           t          d| ||f           t          d	           t          d||         z  ||         	                    |          z  ||||         z  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``.
    re   r   grT   )nargsr   z _laplace_apply_prog rules match:z      f:    %s _ %s, %s )z       rule: time scaling (4.1.4)Fr   N)
r   r   r   r_   r   rh   rP   rQ   _laplace_transformr   )r   r   rX   re   r   ma1r   ma2rk   prcrs              rY   _laplace_rule_timescaler     s"    	S1#AS"""A
''!**C
 	!fk!n$$Q''ci!nn 	3q6% 	#a&A++4555.C>>>4555*1SV8CFKKNN+B+,aAhH H HIAr2r2;4r[   c                    t          d|g          }t          d          }t          d          }|                     t          |          |z            }|r||                             ||z
            }|r||         j        rt	          d           t          d| ||f           t	          d           t          ||                             ||||         z             ||d	          \  }}	}
t          ||          |z            |z  |	|
fS |r`||         j	        rSt	          d           t          d| ||f           t	          d
           t          ||         ||d	          \  }}	}
||	|
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.
    re   r   rj   r    _laplace_apply_prog_rules match:      f:    %s ( %s, %s )z      rule: time shift (4.1.4)Fr   z9      rule: Heaviside factor, negative time shift (4.1.4)N)
r   r   r5   rh   rP   rQ   r   r   r#   is_negative)r   r   rX   re   rj   r   r   r   rk   r   r   s              rY   _laplace_rule_heavisider     s    	S1#AS		AS		A
'')A,,q.
!
!C
 !fll1Q3 	.3q6% 	.4555.C>>>2333*3q6;;q!CF(+C+CQ49; ; ;IAr2Q	NN1$b"-- 	3q6% 	4555.C>>>MNNN*3q61a%HHHIAr2r2;4r[   c                    t          d|g          }t          d          }t          d          }|                     t          |          |z            }|r||                             |                              ||z            }|rrt	          d           t          d| ||f           t	          d           t          ||         ||||         z
  d	          \  }}	}
||	t          ||                   z   |
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)``.
    re   r   rj   zr   r   z%      rule: multiply with exp (4.1.5)Fr   N)r   r   r#   r   rP   rQ   r   r   )r   r   rX   re   rj   r   r   r   rk   r   r   s              rY   _laplace_rule_expr   "  s    	S1#AS		AS		A
''#a&&(

C
 *!fnnQ%%ac** 	*4555.C>>>9:::*3q61aAh49; ; ;IAr2r"SV**}b))4r[   c                   
 t          dg          }t          dg          }t          d          }t          d          |                     t          |          z            

r
                             t                    s
|                                                           |z  |z
            }|rt          d           t          d| 
|f           t          d           ||         ||         z  }t          |          d	k    rt          |          d	k    rpt          ||          ||         z  z            
         
                    ||         ||         z            z  ||         z  }|t          j        t          j        fS d	t          j        t          j        fS 
|                                       rt          
|                   }	t          i urt!          |	                                          d
hk    rgt%          
|                   t'          
f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)``.
    re   r   ro   rj   r   r   r   z$      rule: multiply with DiracDeltar   rT   c                     g | ]o}t          |          d k    t          |          d k    (t          | z                                                   z                      |          z  pS )r   )r   r   r#   r   )r   ri   r   rX   sloper   r   s     rY   r   z'_laplace_rule_delta.<locals>.<listcomp>Z  sv     M M M"Q%%1**A! 1"Q$iiAAq 1 11%**Q2B2BBAKr[   N)r   r   r4   r]   r   rP   rQ   r   r   r#   r   r   r   r`   is_polynomialrI   setvaluesr   r   r   keys)r   r   rX   re   ro   rj   r   locrk   ror   r   r   s    ``       @@@rY   _laplace_rule_deltar   :  sa    	S1#AS1#AS		AS		A
''*Q--/
"
"C
 73q6::j)) 7!fnnQ%%ac!e,, 		74555.C>>>8999a&Q-C#ww!||31QAq())#a&++aQA*G*GGAN1-qv661-qv66q6"" 	7s1vq!!BB3ryy{{#3#3s#:#:SVQM M M M M M M M#BGGIIM M MN 1-qv664r[   c                 J   t           j        g}t           j        g}t          j        |           D ]_}|                    t
          t          t          t          t                    r|
                    |           J|
                    |           `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_argsr]   r.   r-   r'   r%   r#   append)fntrigsothertermr   r   s         rY   _laplace_trig_splitr  `  s     UGEUGEb!!  88CdD#.. 	LLLLUAUAa4Kr[   c                    t          d          }t          d|g          }g }g }|                     t                                                    }t	          j        |          D ]u}|                    |          s(|                    d|ddt          dt          di           @|
                    d          }|                    |t          |          z            x}||                             |          x}	|	                                }
t          |
          d
k    rq|                    d||         t          |
d                   z  d|
d         t          t          |
d                   t          t          |
d                   i           2|                    |           I|                    |           `|                    |           w||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.
    r   r   r   kre   r   r#   )combineNr   rT   )r   rewriter#   r
   r   r  r]   r  r   r   powsimpr   as_poly
all_coeffsr   )r   r   r   r   xmxnx1r  rk   mpmcs              rY   _laplace_trig_expsumr  r  s    	S		AS1#A	B	B	
3			 	 Bb!!  xx{{ 	IIsD#q"aQ7888||E|**Ac!ffH%%%A2dll1oo%2]]__r77a<<IIQqT#be**_c2a5Br!uIIr2be996 7 7 7 7 IIdOOOO		$IIdOOOOr6Mr[   c           	      f   g }g }d fd}fd}fd}fd}d }	t          |           dk    rm|                                 }
d}d}d}t          t          |                     D ]}|
t                   | |         t                   k    }|
t                   | |         t                    k    }|
t                   | |         t                   k    }|
t                   | |         t                    k    }|r'|r%|
t                   dk    r|
t                   dk    r|}|r|r|
t                   dk    r|}|r|r|
t                   dk    r|}||||                     ||
| |         d	         | |         d	         | |         d	         |                     |                    t          t          |
d
                                        |||g}|                    d           |D ]}|                     |           n|c|                     ||
| |         d	         |                     |                    |
t                              |                     |           n!|o|                     ||
| |         d	         |                     |                    t          |
t                                        |                     |           n|o|                     ||
| |         d	         |                     |                    t          |
t                                        |                     |           n?|                     |	|
|                     |                    |
t                              t          |           dk    mt          | 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                    |                                  }t          t          |                    D ]}||                                         }|d                             t
                    r$||                             t                    ||<   `|d         t          |d         z  z                       t                    ||<   |S r   )	copyranger   r   r]   r   r  r-   r   )coeffsncr	  ris       rY   _simpcz"_laplace_trig_ltex.<locals>._simpc  s    [[]]s2ww 	7 	7AA##%%B!uyy}} 71c**1A2a511#661	r[   c                 N   | d         | d         | t                    | t                   f\  }}}}||z   |z   |z   |||z   |z
  |z
  z  dt          z  |z  |z  z
  dt          z  |z  |z  z   |dz  | |z
  |z
  |z
  z  |dt          z  |z  |z  dt          z  |z  |z  z   z  z   d|dz  z  |z  z   d|dz  z  |z  z   |dz  | |z
  |z   |z   z  |dz  dt          z  |z  |z  dt          z  |z  |z  z   dt          z  |z  |z  z
  dt          z  |z  |z  z
  z  z   |d|dz  z  |z  d|dz  z  |z  z
  z  z   g}	t          j        t          j        d|dz  z  d|dz  z  z
  t          j        |dz  d|dz  z  |dz  z  z   |dz  z   g}
t          fdt           |	          t          t          |	                    d d d                   D              }t          fdt          |
t          t          |
                    d d d                   D              }t          d	||f           ||z  S )
Nre   r	  r   r   r   c                 &    g | ]\  }}||z  z  S rx   rx   r   ri   rj   rX   s      rY   r   z9_laplace_trig_ltex.<locals>._quadpole.<locals>.<listcomp>  %    GGGAa1fGGGr[   r   c                 &    g | ]\  }}||z  z  S rx   rx   r  s      rY   r   z9_laplace_trig_ltex.<locals>._quadpole.<locals>.<listcomp>  %    ???Aa1f???r[   z        quadpole: (%s) / (%s))r   r   r   r   r   r   r   zipr  r   rQ   )t1k1k2k3rX   re   k0a_ra_ir  dcrd   r   r  s       `        rY   	_quadpolez%_laplace_trig_ltex.<locals>._quadpole  s}   S'2c7BrFBrF:2sCGbL2rBw|b !AaCGBJ.1S;1rcBhmb()1Q3s72:!C
*+,#q&Qhrk* 1rcBhmb()1ac#gbj1Q3s72:-!C
:QqSWRZGHI1S!V8B;36",-.
 E161S!V8aQh.FCFQsAvXc1f_,sAv57 GGGGVVBZZs2ww"1E!F!FGGGI????Rs2ww")=!>!>???A.A777s
r[   c                 2   | d         | d         | t                    | t                   f\  }}}}||z   | |z  ||z  z
  dt          z  |z  |z  z   g}t          j        d|z  |dz  |dz  z   g}t          fdt           |          t          t          |                    d d d                   D              }	t          fdt          |t          t          |                    d d d                   D              }
t          d|	|
f           |	|
z  S )	Nre   r	  r   r   c                 &    g | ]\  }}||z  z  S rx   rx   r  s      rY   r   z7_laplace_trig_ltex.<locals>._ccpole.<locals>.<listcomp>  r   r[   r   c                 &    g | ]\  }}||z  z  S rx   rx   r  s      rY   r   z7_laplace_trig_ltex.<locals>._ccpole.<locals>.<listcomp>  r"  r[   z        ccpole: (%s) / (%s)
r   r   r   r   r   r   r#  r  r   rQ   )r$  r%  rX   re   r(  r)  r*  r  r+  rd   r   r  s     `        rY   _ccpolez#_laplace_trig_ltex.<locals>._ccpole  s!   S'2c7BrFBrF:2sC2gr"uqt|ac#gbj01eRVS!Vc1f_-GGGGVVBZZs2ww"1E!F!FGGGI????Rs2ww")=!>!>???A,q!f555s
r[   c                 B   | d         | d         | t                    | t                   f\  }}}}||z   ||z  ||z  z
  dt          z  |z  |z  z
  g}t          j        dt          z  |z  |dz   |dz  z
  g}t          fdt           |          t          t          |                    d d d                   D              }	t          fdt          |t          t          |                    d d d                   D              }
t          d|	|
f           |	|
z  S )	Nre   r	  r   r   c                 &    g | ]\  }}||z  z  S rx   rx   r  s      rY   r   z7_laplace_trig_ltex.<locals>._rspole.<locals>.<listcomp>  r   r[   r   c                 &    g | ]\  }}||z  z  S rx   rx   r  s      rY   r   z7_laplace_trig_ltex.<locals>._rspole.<locals>.<listcomp>  r"  r[   z        rspole: (%s) / (%s)r0  )r$  r&  rX   re   r(  r)  r*  r  r+  rd   r   r  s     `        rY   _rspolez#_laplace_trig_ltex.<locals>._rspole  s&   S'2c7BrFBrF:2sC2gqtad{QqSWRZ/0eRT#XQwa/0GGGGVVBZZs2ww"1E!F!FGGGI????Rs2ww")=!>!>???A,q!f555s
r[   c                    | d         | d         }}||z   |||z
  z  g}t           j        t           j        |dz   g}t          fdt	           	|          t          t          |                    d d d                   D              }t          fdt	          |t          t          |                    d d d                   D              }t          d||f           ||z  S )Nre   r	  r   c                 &    g | ]\  }}||z  z  S rx   rx   r  s      rY   r   z7_laplace_trig_ltex.<locals>._sypole.<locals>.<listcomp>  r   r[   r   c                 &    g | ]\  }}||z  z  S rx   rx   r  s      rY   r   z7_laplace_trig_ltex.<locals>._sypole.<locals>.<listcomp>  r"  r[   z        sypole: (%s) / (%s))r   r   r   r   r#  r  r   rQ   )
r$  r'  rX   re   r(  r  r+  rd   r   r  s
     `      rY   _sypolez#_laplace_trig_ltex.<locals>._sypole  s    3C22gq"r'{#eQVadU#GGGGVVBZZs2ww"1E!F!FGGGI????Rs2ww")=!>!>???A,q!f555s
r[   c                 ^    | d         | d         }}|}||z
  }t          d||f           ||z  S )Nre   r	  z        simplepole: (%s) / (%s))rQ   )r$  rX   re   r(  rd   r   s         rY   _simplepolez'_laplace_trig_ltex.<locals>._simplepole  s?    3C2E01a&999s
r[   r   Nr	  re   T)reverse)
r   popr  r   r   r  r    r   r   r)   )r  r   rX   resultsplanesr,  r1  r5  r9  r;  r$  	i_imagsym	i_realsym
i_pointsymireal_eqrealsymimag_eqimagsymindices_to_popr  s                       @rY   _laplace_trig_ltexrI    s    GF      0	 	 	 	 		 	 	 	 		 	 	 	 	   b''A++VVXX		

 s2ww 
	 
	Af1b	)GfAr
*Gf1b	)GfAr
*G 7 r"v{{r"v{{

 W B1		 W B1	 %)*?*NN	"Y-,bmC.@Z.-q2 23 3 3 MM#bCkk**+++ (J?N---#  q				"NN772r)}S'91==>>>MM"R&!!!FF9"NN772r)}S'91==>>>MM#bf++&&&FF9#NN772r*~c':A>>???MM#bf++&&&FF:NN;;r1--...MM"R&!!!q b''A++t =#v,&&r[   c           
      t   t          dd          }|                     t          t          t          t
                    sdS t          d| ||f           t          |                     ||                    \  }}t          d||f           t          ||          \  }}	t          d||	f           t          |	          dk    rt          d	           dS |                    |          s&t          |||          \  }
}||
z  |t          j        fS g }g }t          |||          \  }}}|D ]h}|                    |d
         |                    |||d         z
            z             |                    |t#          |d                   z              it%          |                     ||          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realNz _laplace_rule_trig: (%s, %s, %s)z    f = %s
    g = %sz    xm = %s
    xn = %sr   z#    --> xn is not empty; giving up.r	  re   )r   r]   r.   r-   r'   r%   rQ   r  r   r  r   rP   rI  r   r`   r   r  r   r   r)   )r  t_rX   doithintsr   r   r   r  r  rk   r   r?  r>  GG_planeG_condr  s                     rY   _laplace_rule_trigrS  (  s    	cA66#sD$'' t
-B{;;;rwwr1~~..DAq
#aV,,,!!Q''FB
%Bx000
2ww{{3444t5588 
/!"a++1sAqv~ /1a887F 	/ 	/BNN2c7166!Qr#wY#7#77888MM'"RW++-....=a$$c6lF::r[   c                 H   t          dg          }t          dg          }t          d          }|                     |t          ||f          z            }|rB||         j        r4fd||         j        D             }	t          |	          dk    rt          d           t          d| ||         f           t          d	           g }
t          ||                   D ]x}|d
k    r||         
                    d
          }n,t          ||         |f          
                    d
          }|
                    |||         |z
  dz
  z  |z             yt          ||         |d          \  }}}||         |||         z  |z  t          |
 z
  z  ||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)``.
    re   r   rd   r   c                 :    g | ]}|                               S rx   r]   )r   r   r   s     rY   r   z&_laplace_rule_diff.<locals>.<listcomp>[  s#    +++!QUU1XX+++r[   rT   _laplace_apply_rules match:      f, n: %s, %sz#      rule: time derivative (4.1.8)r   Fr   N)r   r   r   r	   
is_integerr_   sumrP   rQ   r  r   r  r   r   )r   r   rX   rN  rO  re   rd   r   r   r   r   r	  rj   rk   r   r   s    `              rY   _laplace_rule_diffr[  N  s    	S1#AS1#ASA
''!Jq1a&)))
*
*C
 =s1v  =++++s1v{+++q66Q;;/000'!SV5557888A3q6]] , ,66AAq))AA"3q6Aq622771==ASVAXaZ*++++*3q61a%HHHIAr2FAs1vIaK#q'12R<<4r[   c           
      Z   | j         rdg}dg}t          j        |           D ]B}|                    |          r|                    |           -|                    |           Ct          |          dk    rt          |          }t          ||                                          t                    dk    rgt          d           t          d| |f           t          d           t          |          }	t          |	||d          \  }
}}|
gd}	 t          d         |           }n# t          $ r d}Y nw xY w|
                    t                    rFt!          dz
            D ]2}                    d|dz   z  t#          |
||dz             z             3nV|rT                    |           t!          dz
            D ],}                    t          d         |                      -|r)t%          fd	t!                    D              }|||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)``.
    rT   rW  rX  z(      rule: frequency derivative (4.1.6)Fr   r   r   c                 >    g | ]}|z
  d z
           |         z  S r   rx   )r   rd   Nderipcs     rY   r   z'_laplace_rule_sdiff.<locals>.<listcomp>  s.    BBBAb1QiQ/BBBr[   N)is_Mulr   r  r   r  r   r   rJ   r  rP   rQ   r   r   
ValueErrorr]   LaplaceTransformr  r	   r   )r   r   rX   rN  rO  pfacofacfacpexoexr_p_c_d1r	  rk   r^  r_  r`  s                   @@@rY   _laplace_rule_sdiffrm  l  sj    	x "'ss=## 	! 	!C  ## !C    C    t99q==t**Cc1((**BBA1uu3444+aY777@AAA4jj/QEJJJ
BttBx+++BB!   BBB66*++ <"1Q3ZZ H HR1Q3K
2q!A#0F0F$FGGGGH  <B!&qs < <A KKd2h):):(:;;;; 'BBBBBBqBBBCAr2;&4s    D8 8EEc                    | j         rdS t          | d          }|j         rt          |||d          S t          |           }|j         rt          |||d          S t          |           }|j         rt          |||d          S || k    rt          |||d          S t          t	          |                     }|j         rt          |||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.
    NFdeepr   )r   r
   r   r   r   )r   r   rX   rN  rO  rk   s         rY   _laplace_expandrq    s     	x tquAx ;!!QE::::1Ax ;!!QE::::q		Ax ;!!QE::::Avv!!QE::::{1~~Ax ;!!QE::::4r[   c                     t           t          t          t          t          t
          t          g}|D ]} || ||          x}|c S 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   rS  r[  rm  )r   r   rX   
prog_rulesp_ruleLs         rY   _laplace_apply_prog_rulesrv    s[     *+>)+<$$&9;J
   1a A-HHH .4r[   c                 V   t                      \  }}}d}d}|D ]\  }}	}
}}||k    r" ||                     ||i                    }|}|                    |          }|r	 |
                    |          }n# t          $ r Y kw xY w|t
          j        k    rt          d           t          d| f           t          d||	f           t          d|f           |	                    |                              ||i          |                    |          t
          j        fc S dS )zj
    This function applies all simple rules and returns the result if one
    of them gives a result.
     z"_laplace_apply_simple_rules match:z      f:     %sz      rule:  %s o---o %sz      match: %sN)	r   r   r   xreplacera   r   r`   rP   rQ   )r   r   rX   simple_rulesrM  r   prep_oldprep_ft_doms_domcheckplaneprepmar   s                  rY   _laplace_apply_simple_rulesr    s_   
 011L"bHF,8 4 4(ueUDtT!&&!R//**FH\\%   	4NN2&&     AF{{:;;;(1$///1E5>BBB(2&111r**//Q88r**AF4 4 4 44s   "A88
BBc                 &   t          d| |f           t          j        |           }g }g }g }|D ](}|                    d          \  }	}
t	          |
|          x}nt          |
|          x}nt          |
|          x}nt          fd|
                    t                    D                       rt          |
|          t          j        df}n5t          |
||          x}	 nt          |
|          t          j        df}|\  }}}|                    |	|z             |                    |           |                    |           *t          | }|r|                    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.
    z[LT _l_t] (%s, %s, %s)Fas_AddNc              3   B   K   | ]}|                               V  d S rw   rV  )r   undefrM  s     rY   r   z%_laplace_transform.<locals>.<genexpr>  s-      CC52CCCCCCr[   Tr   rN  )rQ   r   r  as_independentr  rv  rq  anyr~   r   rc  r   r   r   r  r   r)   rE   )r  rM  r   r   termsterms_sr?  
conditionsffr	  ftrk   ri_pi_ci_resultr  	conditions    `                rY   r   r     s   
 #b"b\222M"EGFJ  !!"U!332,RR888AE,RR888aE"2r2...a;CCCCBHH\,B,BCCCCC 		I ""b"--q/A4HAA1BX/ / / /a7;<!"b"--q/A4HAc3quc#']F -e,,LEZ I5)##r[   c                   .    e Zd ZdZdZd Zd Zd Zd ZdS )rc  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                 X    |                     dd          }t          ||||          }|S )Nr   Fr   )getr   )selfr   r   rX   rO  r>   LTs          rY   _compute_transformz#LaplaceTransform._compute_transform"  s0    IIj%00	+Aq!iHHH	r[   c                 x    t          |t          | |z            z  |t          j        t          j        f          S rw   )r=   r#   r   r   r   )r  r   r   rX   s       rY   _as_integralzLaplaceTransform._as_integral'  s-    #qbd))a%<===r[   c                     g }g }|D ]/\  }}|                     |           |                     |           0t          | }t          | }|t          j        k    rt          dd d          ||fS )Nr  zNo combined convergence.)r  rE   r)   r   r   r@   )r  extrar   r?  r  r   s         rY   _collapse_extraz LaplaceTransform._collapse_extra*  s      	! 	!KE4LLMM%    E{V17??(4!;= = =d{r[   c                    |                     dd          }|                     dd          }t          d| j        | j        | j        f           | j        }| j        }| j        }t          ||||          }|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  rQ   functionfunction_variabletransform_variabler   )r  rO  _nocondsr>   rM  r   r  rk   s           rY   rN  zLaplaceTransform.doit7  s     99Y--IIj%00	'$-*.*@*.*A*C 	D 	D 	D #$]r2rI>>> 	Q4KHr[   N)	__name__
__module____qualname____doc___namer  r  r  rN  rx   r[   rY   rc  rc    sa          E  
> > >      r[   rc  c                                         dd          }                     dd          }t          | t                    rt          | d          r                     dd           }|r]|r[d}t	          dd|           t          t                    5  |                     fd	          cd
d
d
           S # 1 swxY w Y   njfd| D             }	|r<t          |	 \  }
}} t          |           g | j
        |
R  }|t          | t          | fS  t          |           g | j
        |	R  S t          |                               d|          }|s|S |d         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)

    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                 "    t          | fi S rw   laplace_transform)fijrO  rX   r   s    rY   ry   z#laplace_transform.<locals>.<lambda>  s     1#q! E Eu E E r[   Nc                 .    g | ]}t          |fi S rx   r  )r   r  rO  rX   r   s     rY   r   z%laplace_transform.<locals>.<listcomp>  sG     2 2 2(+ 0Q$ $"$ $ 2 2 2r[   )r  r   r   )r  r^   rF   hasattrrM   rO   rN   r  r#  typeshaper)   rE   rc  rN  )r   r   rX   legacy_matrixrO  r  r>   r   adtelements_transelementsavalsr  	f_laplacer  s    `` `          rY   r  r  W  s'   ^ yyE**H		*e,,I!Z   9WQ%<%< 9IIi/// 	9] 	97C%
 */+.    !!899 G G{{EEEEEEG GG G G G G G G G G G G G G G G G G2 2 2 2 2 2/02 2 2N 9.1>.B+%#DGG7QW7h777	 #u+sJ/???tAww888888	!Q	"	"	'	'		'	J	JB 	!us   B??CCc                    ddl m}m ddlm} t          dd          fd}|                               r|                               } | j        rCt          fd| j
        D              }t          |                    |                    dfS 	  || t                     d	t          j        fdd
          \  }}	n# t           $ r d	}Y nw xY w|l ||           }|d	S |j        r-|j
        d         \  }}	|                    t&                    rd	S nt          j        }	|                    t,          |          }|j        r|                    |          |	fS t          d          t          j        ffd	}
|                    t0          |
          }d }|                    t          |          }t          |                    |                    |	fS )z6 The backend function for inverse Laplace transforms. r   )meijerint_inversion_get_coeff_exp)inverse_mellin_transformr   TrK  c                  x   t          |           dk    r	t          |  S | d         j        d         j        } |          \  }}| d         j        d         }| d         j        d         }t	          dt          |          z  |z  z
            |z  t	          |z  dt          |          z  z
            |z  z   S )z3 Simplify a piecewise expression from hyperexpand. r   r   r   rT   )r   r,   r_   argumentr5   r    )r_   r   coeffexponente1e2r  r   s         rY   pw_simpz7_inverse_laplace_transform_integration.<locals>.pw_simp  s     t99>>d##1gl1o&(.a00x!W\!_!W\!_aE

lQ[011"4akAc%jjL011"45	6r[   c           	      6    g | ]}t          |          S rx   )&_inverse_laplace_transform_integration)r   Xr  rX   r   r   s     rY   r   z:_inverse_laplace_transform_integration.<locals>.<listcomp>  s9        5Q1eXNN   r[   NF)needevalr  uc                 l    | j         t                               }|                              rt          | |          S ddlm}  ||dk              }|j        k    r't          |j                  }t          |z   |          S t          |j                  }t          |z    |          S )Nr   r   )	r   r#   r]   r5   r   r   r   r$   gts)r   H0re   r   relr	  r   r  s         rY   simp_heavisidez>_inverse_laplace_transform_integration.<locals>.simp_heaviside  s    CHS!WWa  5588 	&S"%%%@@@@@@Aq))7a<<CGAQUB'''CGAq1uXr***r[   c                 :    t          t          |                     S rw   )r   r#   )r   s    rY   simp_expz8_inverse_laplace_transform_integration.<locals>.simp_exp  s    c#hh'''r[   )sympy.integrals.meijerintr  r  sympy.integrals.transformsr  r   is_rational_functionapartr   r   r_   r>   r   r#   r   r   r@   r   r]   r=   r`   rs   r,   r   r5   )r   rX   rM  r  r   r  r  r  r   r   r  r  r  r   r  s    ` ``       @@@rY   r  r    s   MMMMMMMMCCCCCC 	cA6 6 6 6 6 6 	a   GGAJJx 8      v    211477**1aaR4:L48%I I I44!   y1a((94> 	fQiGAtuuX t 6DIIi))~ # vva}}d""c

A v + + + + + + + 	
		)^,,A( ( ( 	
		#x  A
 QVVAr]]H--t33s   !.C CCc                 $   ddl m}  ||           \  }}|                    |          rc|                    |                                          }t          |          dk    r)|\  }}}|||d|z  z  z   dz  ||z  z   |d|z  z  dz  z
  z  }||z  S )Nr   )fractionr   r   )rz   r  r   r  r  r   )	r   rX   r  rd   r   cfre   ro   r   s	            rY   _complete_the_square_in_denomr  "  s    //////Xa[[FQq 4YYq\\$$&&r77a<<GAq!Aa1gI>!A#%q!A#wl23AQ3Jr[   c            
         t          d          } t          d          }t          d| g          }t          d| g          }t          d| g          }t          d           d }d	 }|| z  |t          j        |d
f|| |z   | z  z  ||d
z
  z  t          | |z            z  t          |          z  |dk    |d
fd
| dz  |dz  z   dz  z  t          ||z            ||z  t          ||z            z  z
  d|dz  z  z  t          j        |d
fd
| |z  z  ||d
z
  z  t          |          z  t          j        |d
fd
| | |z   |z  z  z  t          |||z            ||z  t          |          z  z  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`.
    rX   r   re   r   ro   r   z._inverse_laplace_build_rules is building rulesc                 R    	 |                      |          S # t          $ r | cY S w xY wrw   )factorrH   )r   rX   s     rY   _fracz+_inverse_laplace_build_rules.<locals>._frac<  s;    	88A;; 	 	 	HHH	s    &&c                     | S rw   rx   )r   s    rY   samez*_inverse_laplace_build_rules.<locals>.sameB  s    r[   rT   r   r   r   )
r   r   rP   r   r`   r#   r:   r.   r-   r;   )rX   r   re   ro   r   r  r  
_ILT_ruless           rY   _inverse_laplace_build_rulesr  -  s    	c

Ac

AS1#AS1#AS1#A	
:;;;    
1aq!	
AaCA2;AaCaRT*5883QUD!D	
AqDAI>	C!HHqs3qs88|3a1f=	
q	 
AqD1q1u:eAhh&a8	
AqsQhJAqs++QT%((];	
q	J q!r[   c                    | dk    rKt          d           t          dd           t          d|f           t          |          t          j        fS t                      \  }}}d}|                     ||i          }|D ]\  }}	}
}}|||fk    r |||z            }||f}|                    |          }|r	 |
                    |          }n# t          $ r Y \w xY w|t          j        k    rt          d           t          d| f           t          d||	f           t          d|f           t          |          |	                    |                              ||i          z  t          j        fc S d	S )
@
    Helper function for the class InverseLaplaceTransform.
    rT   z*_inverse_laplace_apply_simple_rules match:      f:    %sr   z"      rule: 1 o---o DiracDelta(%s)rx  z      rule: %s o---o %s      ma:   %sN)rP   rQ   r4   r   r`   r  r   r   ry  ra   r5   )r   rX   r   r  r   rM  _prepfsubsr~  r}  r  r  rf  _Fr  r   s                   rY   #_inverse_laplace_apply_simple_rulesr  T  s    	Avv:;;;&&&3aT:::!}}af$$577JBEFFAr7OOE*4 M M&ueT3T3KeCiB3KEXXe__ 
	MNN2&&   AF{{BCCC'!...05%.AAA'"/// ||ENN2$6$6$;$;RG$D$DDafLLLL4s   9C
CCc                    t          d|g          }t          d          }|                     |          s| t          |          z  t          j        fS |                     t          ||z                      }|r||         j        rdt          d           t          d| f           t          d           t          d|f           t          |||         z             t          j        fS t          d           t          | |||          t          j        fS |                     t          ||z            |z            }|r||         j        rat          d           t          d| f           t          d	           t          d|f           t          ||         ||||         z   |          S t          d           t          | |||          t          j        fS d
S )r  re   r   r   z"_inverse_laplace_time_shift match:r  z+      rule: exp(-a*s) o---o DiracDelta(t-a)r  z6_inverse_laplace_time_shift match: negative time shiftz6      rule: exp(-a*s)*F(s) o---o Heaviside(t-a)*f(t-a)N)r   r]   r4   r   r`   r   r#   r   rP   rQ   InverseLaplaceTransform_inverse_laplace_transform)r   rX   r   r  re   r   r   s          rY   _inverse_laplace_time_shiftr  v  s    	S1#AS		A5588 'A&&
''#ac((

C
 	Cq6 	C6777#aT***?@@@#cV,,,aAh''//JKKK*1aE::AFBB
''#ac((1*

C
 	Cq6 	C6777#aT***JKKK#cV,,,-c!fa3q65IIIJKKK*1aE::AFBB4r[   c                 j   t          d|g          }t          d          }|                     ||z  |z            }|r||         j        r||         j        rt	          d           t          d| f           t	          d           t          d|f           t          ||         |||          \  }}|                    t          |          d          }|	                    t                    rt          ||||                   |fS t          |          t          ||||                   z  |fS d	S )
r  rd   r   r   z!_inverse_laplace_time_diff match:r  z,      rule: s**n*F(s) o---o diff(f(t), t, n)r  rT   N)r   r   rY  rh   rP   rQ   r  rs   r5   r]   r  r   )	r   rX   r   r  rd   r   r   rk   r   s	            rY   _inverse_laplace_time_diffr    s1    	S1#AS		A
''!Q$q&//C
 
6s1v  
6SV%7 
61222!&&&<===#((()#a&!Q>>1IIillA&&55()) 	61c!f%%q((Q<<Q3q6 2 22A554r[   c                 T    t           t          g}|D ]} || |||          x}|c S dS )r  N)r  r  )r   rX   r   r  rs  rt  rk   s          rY   !_inverse_laplace_apply_prog_rulesr    sP     .,.J   1a'''A4HHH 54r[   c                    | j         rdS t          | d          }|j         rt          ||||          S t          |           }|j         rt          ||||          S t          |           }|j         rt          ||||          S |                     |          r'|                     |                                          }|j         rt          ||||          S dS )r  NFro  )r   r
   r  r   r  r  rN  )r  rX   r   r  rk   s        rY   _inverse_laplace_expandr    s     
y trAx :)!Q59992Ax :)!Q5999r

Ax :)!Q5999	q!! HHQKKx :)!Q59994r[   c           	         t          d| ||f           t          d          }|                     |          }t          j        |          }g }t
          j        g}	|D ]V}
|
                                \  }}|                    |          	                                }|d         fd|D             }fd|                    |          	                                D             }t          |          dk    r.|d         t          |          z  }|                    |           t          |          dk    rI|d         t          |d          |z            z  }|                    t          |          |z             't          |          dk    r|d         dz  }|d         |dz  z
                                  }t          |          dk    rt
          j        g|z   }t#          |          \  }}|dk    r'||z  |d||z  z
  z  z   t          | |z            z  }n%d	}|j        r| }d
}t'          t)          |dz  |z
  |                                                    d         }t-          |                                          }|r]|t          | |z            z  t1          ||z            z  |||z  z
  |z  t          | |z            z  t3          ||z            z  z   }n\|t          | |z            z  t5          ||z            z  |||z  z
  |z  t          | |z            z  t7          ||z            z  z   }|                    t          |          |z             t9          | |||d
d	          \  }}|                    |           |	                    |           Xt          | }|r|                    d	          }t          d|f           |t;          |	 fS )r  z[ILT _i_l_r] (%s, %s, %s)x_r   c                     g | ]}|z  S rx   rx   r   ri   dc_leads     rY   r   z-_inverse_laplace_rational.<locals>.<listcomp>  s    $$$Aai$$$r[   c                     g | ]}|z  S rx   rx   r  s     rY   r   z-_inverse_laplace_rational.<locals>.<listcomp>  s    ;;;Aai;;;r[   rT   r   r   FT)r   
dorationalr  z[ILT _i_l_r]   returns %s)rQ   r   r  r   r  r   r`   as_numer_denomr  r  r   r4   r  r#   r5   r  r   tupler   r   rI   r   r+   r   r%   r'   r-   r.   r  rE   )r  rX   r   r  r   r  r   r  terms_tr  r  rd   r   r+  r  rk   re   ro   lr   hypb2bsr  r   r  r  s                             @rY   _inverse_laplace_rationalr    s    &Q
333	B
AM!EG&J &$ &$$$&&AYYq\\$$&&Q%$$$$$$$;;;;1!8!8!:!:;;;r77a<<1jmm#ANN1WW\\1c2a5&(mm#ANN9Q<<>****WW\\1aAAq!t##%%A2ww!||fX]99DAqAvvqSAacE]C1II-= AC%Aa,,113344Q7!WW%%'' O#qbd))DAJJ.!AaC%2r!t992%%)"Q$ZZ20 0 A #qbd))C1II-1Q3
3r!t990DSAYY0NNANN9Q<<>****1Aq%$5B B BHBNN2d####']F -e,,
&	2223
###r[   c                 F   t          j        |           }g }g }t          d| |f           |D ]D}	|	                    d          \  }
}|r,|	                              rt          ||||          x}	 nt          ||          x}nt          |||          x}nt          |||          x}	 nt          fd|
                    t                    D                       rt          |||          t          j        f}n6t          ||||          x}	 nt          |||          t          j        f}|\  }}|                    |
|z             |                    |           Ft          | }|r|                    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.
    z[ILT _i_l_t] (%s, %s, %s)Fr  Nc              3   B   K   | ]}|                               V  d S rw   rV  )r   r  r   s     rY   r   z-_inverse_laplace_transform.<locals>.<genexpr>'  s-      BB52BBBBBBr[   r   r  )r   r  rQ   r  r  r  r  r  r  r  r~   r   r  r   r`   r  r  r   rE   )r  r   rM  r  r   r  r  r  r  r  r	  r   rk   r  r  r  r  s    `               rY   r  r    s    M"EGJ
&R555  ""2e"441	D#88<<	D 32r5(4 4 4A<@A 6q"bAAAaN*1b"e<<<aI72r5IIIBBBBAGGL,A,ABBBBB 
	D )BE::AFCAA;r2ux9 9 9 9AEF (BE::AFCA
cqu#']F -e,,Z I9r[   c                   p    e Zd ZdZdZ ed          Z ed          Zd Ze	d             Z
d Zd Z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                 J    |t           j        }t          j        | ||||fi |S rw   )r  _none_sentinelr?   __new__)r   r   rX   ri   r  optss         rY   r  zInverseLaplaceTransform.__new__L  s0    =+:E (aAuEEEEEr[   c                 @    | j         d         }|t          j        u rd }|S )Nr   )r_   r  r  )r  r  s     rY   fundamental_planez)InverseLaplaceTransform.fundamental_planeQ  s&    	!+:::Er[   c                 ,    t          |||| j        fi |S rw   )r  r  )r  r   rX   r   rO  s        rY   r  z*InverseLaplaceTransform._compute_transformX  s-    5q!T+6 6/46 6 	6r[   c                    | j         j        }t          t          ||z            |z  ||t          j        t          j        z  z
  |t          j        t          j        z  z   f          dt          j        z  t          j        z  z  S )Nr   )	__class___cr=   r#   r   ImaginaryUnitr   Pi)r  r   rX   r   r   s        rY   r  z$InverseLaplaceTransform._as_integral\  sn    NS1XXaZ!Q)C%C"#aoaj&@"@"B C CqtVAO#%	&r[   c                    |                     dd          }|                     dd          }t          d| j        | j        | j        f           | j        }| j        }| j        }| j        }t          |||||          }|r|d         S |S )r  r  Tr   Fz[ILT doit] (%s, %s, %s)r   r   )r  rQ   r  r  r  r  r  )	r  rO  r  r>   r   rM  r  r  rk   s	            rY   rN  zInverseLaplaceTransform.doitc  s     99Y--IIj%00	(4=+/+A+/+B+D 	E 	E 	E #$]&&r2r59MMM 	Q4KHr[   N)r  r  r  r  r  r   r  r  r  propertyr  r  r  rN  rx   r[   rY   r  r  >  s          EU6]]N	sBF F F
   X6 6 6& & &    r[   r  Nc                     t          | t                    r+t          | d          r|                     fd          S  t	          |           j        di 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  c                 $    t          | fi S rw   )inverse_laplace_transform)FijrO  r  rX   r   s    rY   ry   z+inverse_laplace_transform.<locals>.<lambda>  s    1#q!ULLeLL r[   rx   )r^   rF   r  r  r  rN  )r   rX   r   r  rO  s    ````rY   r  r    s    Z !Z   NWQ%<%< N{{LLLLLLLN N 	N7"1aE227@@%@@@r[   c                    	
 t          dt          g          \  	
fdfdfd	
fdfd |           S )zEFast inverse Laplace transform of rational function including RootSumza, b, nr   c                     |                                s| S | j        r |           S | j        r |           S | j        r |           S t	          | t
                    r |           S t          rw   )r]   r   ra  rU   r^   rL   NotImplementedError)e_ilt_add_ilt_mul_ilt_pow_ilt_rootsumrX   s    rY   _iltz#_fast_inverse_laplace.<locals>._ilt  s    uuQxx 	&HX 		&8A;;X 	&8A;;X 	&8A;;7## 	&<??"%%r[   c                 >     | j         t          | j                   S rw   )r   mapr_   )r!  r&  s    rY   r"  z'_fast_inverse_laplace.<locals>._ilt_add  s    qvs4(())r[   c                 l    |                                \  }}|j        rt          | |          z  S rw   )r  ra  r   )r!  r  r{   r&  rX   s      rY   r#  z'_fast_inverse_laplace.<locals>._ilt_mul  s=    &&q))t; 	&%%ttDzz!!r[   c                 J   |                      z  z   z            }|||         |         |         }}}|j        r>|dk     r8	| dz
  z  t          ||z   	z            z  || z  t          |           z  z  S |dk    rt          ||z   	z            |z  S t          r   )r   
is_Integerr#   r:   r   )
r!  r   nmambmre   ro   rd   rX   r   s
        rY   r$  z'_fast_inverse_laplace.<locals>._ilt_pow  s    1q1%%q58U1XBB} GaB3q5z#2hqj//12s75"::3EFFQwwRU8A:++!!r[   c                     | j         j        }| j         j        \  }t          | j        t          |t           |                                        S rw   )funr{   	variablesrL   polyr   rK   )r!  r{   variabler&  s      rY   r%  z+_fast_inverse_laplace.<locals>._ilt_rootsum  sC    uzU_
qvvhd0D0DEEFFFr[   )r   r   )r!  rX   r   r&  r"  r#  r$  r%  re   ro   rd   s    ``@@@@@@@@rY   _fast_inverse_laplacer4    s    iTA3777GAq!& & & & & & & & &* * * * *" " " " " "" " " " " " " " "G G G G G
 477Nr[   )T)TTrw   )r  
sympy.corer   r   r   sympy.core.addr   sympy.core.cacher   sympy.core.functionr   r	   r
   r   r   r   r   r   r   sympy.core.mulr   r   sympy.core.relationalr   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,   (sympy.functions.elementary.trigonometricr-   r.   r/   sympy.functions.special.besselr0   r1   r2   r3   'sympy.functions.special.delta_functionsr4   r5   'sympy.functions.special.error_functionsr6   r7   r8   'sympy.functions.special.gamma_functionsr9   r:   r;   sympy.integralsr<   r=   r  r>   r?   r@   sympy.logic.boolalgrA   rB   rC   rD   rE   sympy.matrices.matricesrF   sympy.polys.matrices.linsolverG   sympy.polys.polyerrorsrH   sympy.polys.polyrootsrI   sympy.polys.polytoolsrJ   sympy.polys.rationaltoolsrK   sympy.polys.rootoftoolsrL   sympy.utilities.exceptionsrM   rN   rO   sympy.utilities.miscrP   rQ   r|   r   r   r   r   r   r   r   r   r  r  rI  rS  r[  rm  rq  rv  r  r   rc  r  r  r  r  r  r  r  r  r  r  r  r  r  r4  rx   r[   rY   <module>rR     s                     $ $ $ $ $ $                                            % $ $ $ $ $ $ $ H H H H H H H H H H H H H H H H & & & & & & 2 2 2 2 2 2 2 2 2 25 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 ; ; ; ; ; ; ; ; I I I I I I I I I I I I C C C C C C C C C C : : : : : : C C C C C C C C C C M M M M M M M M M M M M I I I I I I I I A A A A A A A A A A N N N N N N N N N N / / / / / / / /: : : : : : : : : : E E E E E E E E E E E E E E . . . . . . 6 6 6 6 6 6 2 2 2 2 2 2 ' ' ' ' ' ' & & & & & & . . . . . . + + + + + +I I I I I I I I I I . . . . . . . .W W Wt6 6 6sL sL sL sLl  & 	Q) Q) 	Q)h  .! ! !H  0# # #L  $" " "JN' N' N'b#; #; #; #;L   <+ + + +\   <  "  <($ ($ ($ ($VB B B B B( B B BJu u u upP4 P4 P4 P4f   	# # 	#L  D     F  ,
 
 
  ,6$ 6$ 6$t 6:0 0 0 0fC C C C C/ C C CL0A 0A 0A 0Af* * * * *r[   