(expr, simplify=True)
return expr
Simplifies exponential / trigonometric / hyperbolic functions.
    When ``simplify`` is True (default) the expression obtained after the
    simplification step will be then be passed through simplify to
    precondition it so the final transformations will be applied.

    Examples
    ========

    >>> from sympy import exptrigsimp, exp, cosh, sinh
    >>> from sympy.abc import z

    >>> exptrigsimp(exp(z) + exp(-z))
    2*cosh(z)
    >>> exptrigsimp(cosh(z) - sinh(z))
    exp(-z)
Simplifies exponential / trigonometric / hyperbolic functions.
    When ``simplify`` is True (default) the expression obtained after the
    simplification step will be then be passed through simplify to
    precondition it so the final transformations will be applied.
Simplifies exponential / trigonometric / hyperbolic functions . When simplify is True ( default ) the expression obtained after the simplification step will be then be passed through simplify to precondition it so the final transformations will be applied .
def exptrigsimp(expr, simplify=True):
    """
    Simplifies exponential / trigonometric / hyperbolic functions.
    When ``simplify`` is True (default) the expression obtained after the
    simplification step will be then be passed through simplify to
    precondition it so the final transformations will be applied.

    Examples
    ========

    >>> from sympy import exptrigsimp, exp, cosh, sinh
    >>> from sympy.abc import z

    >>> exptrigsimp(exp(z) + exp(-z))
    2*cosh(z)
    >>> exptrigsimp(cosh(z) - sinh(z))
    exp(-z)
    """
    from sympy.simplify.fu import hyper_as_trig, TR2i

    def exp_trig(e):
        # select the better of e, and e rewritten in terms of exp or trig
        # functions
        choices = [e]
        if e.has(*_trigs):
            choices.append(e.rewrite(exp))
        choices.append(e.rewrite(cos))
        return min(*choices, key=count_ops)
    newexpr = bottom_up(expr, exp_trig)

    if simplify:
        newexpr = newexpr.simplify()

    # conversion from exp to hyperbolic
    ex = newexpr.atoms(exp, S.Exp1)
    ex = [ei for ei in ex if 1/ei not in ex]
    ## sinh and cosh
    for ei in ex:
        e2 = ei**-2
        if e2 in ex:
            a = e2.args[0]/2 if not e2 is S.Exp1 else S.Half
            newexpr = newexpr.subs((e2 + 1)*ei, 2*cosh(a))
            newexpr = newexpr.subs((e2 - 1)*ei, 2*sinh(a))
    ## exp ratios to tan and tanh
    for ei in ex:
        n, d = ei - 1, ei + 1
        et = n/d
        etinv = d/n  # not 1/et or else recursion errors arise
        a = ei.args[0] if ei.func is exp else S.One
        if a.is_Mul or a is S.ImaginaryUnit:
            c = a.as_coefficient(I)
            if c:
                t = S.ImaginaryUnit*tan(c/2)
                newexpr = newexpr.subs(etinv, 1/t)
                newexpr = newexpr.subs(et, t)
                continue
        t = tanh(a/2)
        newexpr = newexpr.subs(etinv, 1/t)
        newexpr = newexpr.subs(et, t)

    # sin/cos and sinh/cosh ratios to tan and tanh, respectively
    if newexpr.has(C.HyperbolicFunction):
        e, f = hyper_as_trig(newexpr)
        newexpr = f(TR2i(e))
    if newexpr.has(C.TrigonometricFunction):
        newexpr = TR2i(newexpr)

    # can we ever generate an I where there was none previously?
    if not (newexpr.has(I) and not expr.has(I)):
        expr = newexpr
    return expr
def exptrigsimp ( expr , simplify = True ) : from sympy . simplify . fu import hyper_as_trig , TR2i def exp_trig ( e ) : # select the better of e, and e rewritten in terms of exp or trig # functions choices = [ e ] if e . has ( * _trigs ) : choices . append ( e . rewrite ( exp ) ) choices . append ( e . rewrite ( cos ) ) return min ( * choices , key = count_ops ) newexpr = bottom_up ( expr , exp_trig ) if simplify : newexpr = newexpr . simplify ( ) # conversion from exp to hyperbolic ex = newexpr . atoms ( exp , S . Exp1 ) ex = [ ei for ei in ex if 1 / ei not in ex ] ## sinh and cosh for ei in ex : e2 = ei ** - 2 if e2 in ex : a = e2 . args [ 0 ] / 2 if not e2 is S . Exp1 else S . Half newexpr = newexpr . subs ( ( e2 + 1 ) * ei , 2 * cosh ( a ) ) newexpr = newexpr . subs ( ( e2 - 1 ) * ei , 2 * sinh ( a ) ) ## exp ratios to tan and tanh for ei in ex : n , d = ei - 1 , ei + 1 et = n / d etinv = d / n # not 1/et or else recursion errors arise a = ei . args [ 0 ] if ei . func is exp else S . One if a . is_Mul or a is S . ImaginaryUnit : c = a . as_coefficient ( I ) if c : t = S . ImaginaryUnit * tan ( c / 2 ) newexpr = newexpr . subs ( etinv , 1 / t ) newexpr = newexpr . subs ( et , t ) continue t = tanh ( a / 2 ) newexpr = newexpr . subs ( etinv , 1 / t ) newexpr = newexpr . subs ( et , t ) # sin/cos and sinh/cosh ratios to tan and tanh, respectively if newexpr . has ( C . HyperbolicFunction ) : e , f = hyper_as_trig ( newexpr ) newexpr = f ( TR2i ( e ) ) if newexpr . has ( C . TrigonometricFunction ) : newexpr = TR2i ( newexpr ) # can we ever generate an I where there was none previously? if not ( newexpr . has ( I ) and not expr . has ( I ) ) : expr = newexpr return expr