(f, t, s_, simplify=True)
return _simplify(F.subs(s, s_), simplify), sbs(a), sbs(aux)
The backend function for Laplace transforms.
The backend function for Laplace transforms.
The backend function for Laplace transforms .
def _laplace_transform(f, t, s_, simplify=True):
    """ The backend function for Laplace transforms. """
    from sympy import (re, Max, exp, pi, Abs, Min, periodic_argument as arg,
                       cos, Wild, symbols, polar_lift)
    s = Dummy('s')
    F = integrate(exp(-s*t) * f, (t, 0, oo))

    if not F.has(Integral):
        return _simplify(F.subs(s, s_), simplify), -oo, True

    if not F.is_Piecewise:
        raise IntegralTransformError(
            'Laplace', f, 'could not compute integral')

    F, cond = F.args[0]
    if F.has(Integral):
        raise IntegralTransformError(
            'Laplace', f, 'integral in unexpected form')

    def process_conds(conds):
        """ Turn ``conds`` into a strip and auxiliary conditions. """
        a = -oo
        aux = True
        conds = conjuncts(to_cnf(conds))
        u = Dummy('u', real=True)
        p, q, w1, w2, w3, w4, w5 = symbols(
            'p q w1 w2 w3 w4 w5', cls=Wild, exclude=[s])
        for c in conds:
            a_ = oo
            aux_ = []
            for d in disjuncts(c):
                m = d.match(abs(arg((s + w3)**p*q, w1)) < w2)
                if not m:
                    m = d.match(abs(arg((s + w3)**p*q, w1)) <= w2)
                if not m:
                    m = d.match(abs(arg((polar_lift(s + w3))**p*q, w1)) < w2)
                if not m:
                    m = d.match(abs(arg((polar_lift(s + w3))**p*q, w1)) <= w2)
                if m:
                    if m[q] > 0 and m[w2]/m[p] == pi/2:
                        d = re(s + m[w3]) > 0
                m = d.match(
                    0 < cos(abs(arg(s**w1*w5, q))*w2)*abs(s**w3)**w4 - p)
                if not m:
                    m = d.match(0 < cos(abs(
                        arg(polar_lift(s)**w1*w5, q))*w2)*abs(s**w3)**w4 - p)
                if m and all(m[wild] > 0 for wild in [w1, w2, w3, w4, w5]):
                    d = re(s) > m[p]
                d_ = d.replace(
                    re, lambda x: x.expand().as_real_imag()[0]).subs(re(s), t)
                if not d.is_Relational or \
                    d.rel_op not in ('>', '>=', '<', '<=') \
                        or d_.has(s) or not d_.has(t):
                    aux_ += [d]
                    continue
                soln = _solve_inequality(d_, t)
                if not soln.is_Relational or \
                        soln.rel_op not in ('>', '>=', '<', '<='):
                    aux_ += [d]
                    continue
                if soln.lts == t:
                    raise IntegralTransformError('Laplace', f,
                                         'convergence not in half-plane?')
                else:
                    a_ = Min(soln.lts, a_)
            if a_ != oo:
                a = Max(a_, a)
            else:
                aux = And(aux, Or(*aux_))
        return a, aux

    conds = [process_conds(c) for c in disjuncts(cond)]
    conds2 = [x for x in conds if x[1] != False and x[0] != -oo]
    if not conds2:
        conds2 = [x for x in conds if x[1] != False]
    conds = conds2

    def cnt(expr):
        if expr == True or expr == False:
            return 0
        return expr.count_ops()
    conds.sort(key=lambda x: (-x[0], cnt(x[1])))

    if not conds:
        raise IntegralTransformError('Laplace', f, 'no convergence found')
    a, aux = conds[0]

    def sbs(expr):
        if expr == S.true or expr == S.false:
            return bool(expr)
        return expr.subs(s, s_)
    if simplify:
        F = _simplifyconds(F, s, a)
        aux = _simplifyconds(aux, s, a)
    return _simplify(F.subs(s, s_), simplify), sbs(a), sbs(aux)
def _laplace_transform ( f , t , s_ , simplify = True ) : from sympy import ( re , Max , exp , pi , Abs , Min , periodic_argument as arg , cos , Wild , symbols , polar_lift ) s = Dummy ( 's' ) F = integrate ( exp ( - s * t ) * f , ( t , 0 , oo ) ) if not F . has ( Integral ) : return _simplify ( F . subs ( s , s_ ) , simplify ) , - oo , True if not F . is_Piecewise : raise IntegralTransformError ( 'Laplace' , f , 'could not compute integral' ) F , cond = F . args [ 0 ] if F . has ( Integral ) : raise IntegralTransformError ( 'Laplace' , f , 'integral in unexpected form' ) def process_conds ( conds ) : """ Turn ``conds`` into a strip and auxiliary conditions. """ a = - oo aux = True conds = conjuncts ( to_cnf ( conds ) ) u = Dummy ( 'u' , real = True ) p , q , w1 , w2 , w3 , w4 , w5 = symbols ( 'p q w1 w2 w3 w4 w5' , cls = Wild , exclude = [ s ] ) for c in conds : a_ = oo aux_ = [ ] for d in disjuncts ( c ) : m = d . match ( abs ( arg ( ( s + w3 ) ** p * q , w1 ) ) < w2 ) if not m : m = d . match ( abs ( arg ( ( s + w3 ) ** p * q , w1 ) ) <= w2 ) if not m : m = d . match ( abs ( arg ( ( polar_lift ( s + w3 ) ) ** p * q , w1 ) ) < w2 ) if not m : m = d . match ( abs ( arg ( ( polar_lift ( s + w3 ) ) ** p * q , w1 ) ) <= w2 ) if m : if m [ q ] > 0 and m [ w2 ] / m [ p ] == pi / 2 : d = re ( s + m [ w3 ] ) > 0 m = d . match ( 0 < cos ( abs ( arg ( s ** w1 * w5 , q ) ) * w2 ) * abs ( s ** w3 ) ** w4 - p ) if not m : m = d . match ( 0 < cos ( abs ( arg ( polar_lift ( s ) ** w1 * w5 , q ) ) * w2 ) * abs ( s ** w3 ) ** w4 - p ) if m and all ( m [ wild ] > 0 for wild in [ w1 , w2 , w3 , w4 , w5 ] ) : d = re ( s ) > m [ p ] d_ = d . replace ( re , lambda x : x . expand ( ) . as_real_imag ( ) [ 0 ] ) . subs ( re ( s ) , t ) if not d . is_Relational or d . rel_op not in ( '>' , '>=' , '<' , '<=' ) or d_ . has ( s ) or not d_ . has ( t ) : aux_ += [ d ] continue soln = _solve_inequality ( d_ , t ) if not soln . is_Relational or soln . rel_op not in ( '>' , '>=' , '<' , '<=' ) : aux_ += [ d ] continue if soln . lts == t : raise IntegralTransformError ( 'Laplace' , f , 'convergence not in half-plane?' ) else : a_ = Min ( soln . lts , a_ ) if a_ != oo : a = Max ( a_ , a ) else : aux = And ( aux , Or ( * aux_ ) ) return a , aux conds = [ process_conds ( c ) for c in disjuncts ( cond ) ] conds2 = [ x for x in conds if x [ 1 ] != False and x [ 0 ] != - oo ] if not conds2 : conds2 = [ x for x in conds if x [ 1 ] != False ] conds = conds2 def cnt ( expr ) : if expr == True or expr == False : return 0 return expr . count_ops ( ) conds . sort ( key = lambda x : ( - x [ 0 ] , cnt ( x [ 1 ] ) ) ) if not conds : raise IntegralTransformError ( 'Laplace' , f , 'no convergence found' ) a , aux = conds [ 0 ] def sbs ( expr ) : if expr == S . true or expr == S . false : return bool ( expr ) return expr . subs ( s , s_ ) if simplify : F = _simplifyconds ( F , s , a ) aux = _simplifyconds ( aux , s , a ) return _simplify ( F . subs ( s , s_ ) , simplify ) , sbs ( a ) , sbs ( aux )