Compare commits
4
Commits
patch-1
...
exptrigsimp
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3922fd9e58 | ||
|
|
f2ddf010e6 | ||
|
|
f482676842 | ||
|
|
d847103d96 |
@@ -8,7 +8,7 @@ from sympy.core.cache import cacheit
|
||||
from sympy.core.compatibility import reduce, iterable, SYMPY_INTS
|
||||
from sympy.core.function import count_ops, _mexpand
|
||||
from sympy.core.numbers import I, Integer
|
||||
from sympy.functions import sin, cos, exp, cosh, tanh, sinh, tan, cot, coth
|
||||
from sympy.functions import sin, cos, exp, cosh, tanh, sinh, tan, cot, coth, log
|
||||
from sympy.functions.elementary.hyperbolic import HyperbolicFunction
|
||||
from sympy.functions.elementary.trigonometric import TrigonometricFunction
|
||||
from sympy.polys import Poly, factor, cancel, parallel_poly_from_expr
|
||||
@@ -430,20 +430,21 @@ def trigsimp(expr, **opts):
|
||||
|
||||
method:
|
||||
- Determine the method to use. Valid choices are 'matching' (default),
|
||||
'groebner', 'combined', and 'fu'. If 'matching', simplify the
|
||||
'groebner', 'combined', 'exp' and 'fu'. If 'matching', simplify the
|
||||
expression recursively by targeting common patterns. If 'groebner', apply
|
||||
an experimental groebner basis algorithm. In this case further options
|
||||
are forwarded to ``trigsimp_groebner``, please refer to its docstring.
|
||||
If 'combined', first run the groebner basis algorithm with small
|
||||
default parameters, then run the 'matching' algorithm. 'fu' runs the
|
||||
collection of trigonometric transformations described by Fu, et al.
|
||||
(see the `fu` docstring).
|
||||
default parameters, then run the 'matching' algorithm. If 'exp', rewriting
|
||||
as ``exp``, ``log`` and ``cos`` will be attempted as appropriate. 'fu'
|
||||
runs the collection of trigonometric transformations described by Fu,
|
||||
et al.
|
||||
|
||||
|
||||
Examples
|
||||
========
|
||||
|
||||
>>> from sympy import trigsimp, sin, cos, log
|
||||
>>> from sympy import trigsimp, sin, cos, log, atanh
|
||||
>>> from sympy.abc import x, y
|
||||
>>> e = 2*sin(x)**2 + 2*cos(x)**2
|
||||
>>> trigsimp(e)
|
||||
@@ -466,6 +467,18 @@ def trigsimp(expr, **opts):
|
||||
>>> trigsimp(t)
|
||||
tanh(x)**7
|
||||
|
||||
Rewriting functions in terms of a common function can improve
|
||||
the simplifications. For example, hyperbolics can be rewritten
|
||||
in terms of ``log`` and the `exp` keyword can be used to enable
|
||||
that:
|
||||
|
||||
>>> trigsimp(log(3) - 2*atanh(3), method='exp')
|
||||
I*pi
|
||||
|
||||
|
||||
See Also
|
||||
========
|
||||
exptrigsimp, fu, groebner, trigsimp_groebner
|
||||
"""
|
||||
from sympy.simplify.fu import fu
|
||||
|
||||
@@ -499,6 +512,7 @@ def trigsimp(expr, **opts):
|
||||
trigsimpfunc = {
|
||||
'fu': (lambda x: fu(x, **opts)),
|
||||
'matching': (lambda x: futrig(x)),
|
||||
'exp': (lambda x: exptrigsimp(x)),
|
||||
'groebner': (lambda x: groebnersimp(x, **opts)),
|
||||
'combined': (lambda x: futrig(groebnersimp(x,
|
||||
polynomial=True, hints=[2, tan]))),
|
||||
@@ -510,18 +524,20 @@ def trigsimp(expr, **opts):
|
||||
|
||||
def exptrigsimp(expr):
|
||||
"""
|
||||
Simplifies exponential / trigonometric / hyperbolic functions.
|
||||
Simplifies logarithmic / exponential / trigonometric / hyperbolic functions.
|
||||
|
||||
Examples
|
||||
========
|
||||
|
||||
>>> from sympy import exptrigsimp, exp, cosh, sinh
|
||||
>>> from sympy import exptrigsimp, exp, cosh, sinh, atanh, log
|
||||
>>> from sympy.abc import z
|
||||
|
||||
>>> exptrigsimp(exp(z) + exp(-z))
|
||||
2*cosh(z)
|
||||
>>> exptrigsimp(cosh(z) - sinh(z))
|
||||
exp(-z)
|
||||
>>> exptrigsimp(log(3) - 2*atanh(3))
|
||||
I*pi
|
||||
"""
|
||||
from sympy.simplify.fu import hyper_as_trig, TR2i
|
||||
from sympy.simplify.simplify import bottom_up
|
||||
@@ -532,6 +548,8 @@ def exptrigsimp(expr):
|
||||
choices = [e]
|
||||
if e.has(*_trigs):
|
||||
choices.append(e.rewrite(exp))
|
||||
if e.has(log) and e.has(HyperbolicFunction):
|
||||
choices.append(e.rewrite(log))
|
||||
choices.append(e.rewrite(cos))
|
||||
return min(*choices, key=count_ops)
|
||||
newexpr = bottom_up(expr, exp_trig)
|
||||
@@ -598,7 +616,9 @@ def exptrigsimp(expr):
|
||||
newexpr = TR2i(newexpr)
|
||||
|
||||
# can we ever generate an I where there was none previously?
|
||||
if not (newexpr.has(I) and not expr.has(I)):
|
||||
# yes, if there are hyperbolics and logs
|
||||
if not (newexpr.has(I) and not expr.has(I)) or (
|
||||
expr.has(log) and expr.has(HyperbolicFunction)):
|
||||
expr = newexpr
|
||||
return expr
|
||||
|
||||
|
||||
Reference in New Issue
Block a user