On Mar 26, 2:15 pm, Alan Bromborsky <abro...@verizon.net> wrote:
> I have copied the trigsimp code from simplify.py and modified it to work
> with hyperbolic trig functions (see below).  I am not ready to submit it
> as a patch yet.  I want to get more complicated examples of hyperbolic
> trig simplification (ones that require the recursion option) and would
> also like to get examples that contain both trig and hyperbolic trig
> functions to see if sequential application of trigsimp and
> hyperbolicsimp would work and if the order of application is important.  
> Would anyone who have any possible examples please post them (or just
> take the code below and run their own examples).
>
> from sympy import SYMPY_DEBUG
>
> from sympy.core import Basic, S, C, Add, Mul, Pow, Rational, Integer, \
>         Derivative, Wild, Symbol, sympify
>
> from sympy.core.numbers import igcd
>
> from sympy.utilities import make_list, all
> from sympy.functions import gamma, exp, sqrt
>
> from sympy.simplify.cse_main import cse
>
> from sympy.polys import Poly
>
> import sympy.mpmath as mpmath
>
> from sympy import *
>
> def hyperbolicsimp(expr, deep=False, recursive=False):
>     """
>     Usage
>     =====
>         hyperbolicsimp(expr) -> reduces expression by using known
>         hyperbolic trig identities
>
>     Notes
>     =====
>
>     deep ........ apply hyperbolicsimp inside functions
>     recursive ... use common subexpression elimination (cse()) and apply
>                   hyperbolicsimp recursively (recursively==True is quite
> expensive
>                   operation of the expression is large)
>
>     Examples
>     ========
>         >>> from sympy import *
>         >>> x = Symbol('x')
>         >>> y = Symbol('y')
>         >>> e = 2*cosh(x)**2 - 2*sinh(x)**2
>         >>> hyperbolicsimp(e)
>         2
>         >>> hyperbolicsimp(log(e))
>         log(2*cosh(x)**2 - 2*sinh(x)**2)
>         >>> hyperbolicsimp(log(e), deep=True)
>         log(2)
>     """
>     if recursive:
>         w, g = cse(expr)
>         g = hyperbolicsimp_nonrecursive(g[0])
>         for sub in reversed(w):
>             g = g.subs(sub[0], sub[1])
>             g = hyperbolicsimp_nonrecursive(g)
>         return(g)
>     else:
>         return hyperbolicsimp_nonrecursive(expr, deep)
>
> def hyperbolicsimp_nonrecursive(expr, deep=False):
>     """
>     A nonrecursive hyperbolic trig simplifier, used from hyperbolicsimp.
>
>     Usage
>     =====
>         hyperbolicsimp_nonrecursive(expr) -> reduces expression by
>         using known hyperbolic trig identities
>
>     Notes
>     =====
>
>     deep ........ apply hyperbolicsimp inside functions
>
>     Examples
>     ========
>         >>> from sympy import *
>         >>> x = Symbol('x')
>         >>> y = Symbol('y')
>         >>> e = 2*cosh(x)**2 - 2*sinh(x)**2
>         >>> hyperbolicsimp(e)
>         2
>         >>> hyperbolicsimp(log(e))
>         log(2*cosh(x)**2 - 2*sinh(x)**2)
>         >>> hyperbolicsimp(log(e), deep=True)
>         log(2)
>     """
>     from sympy.core.basic import S
>     sinh, cosh, tanh, coth = C.sinh, C.cosh, C.tanh, C.coth
>
>     #XXX this stopped working:
>     if expr == 1 - 1/cosh(Symbol("x"))**2:
>         return tanh(Symbol("x"))**2
      ^^^
I think this should rather use pattern matching for the sake of not
only working with cosh(x).

Vinzent
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sympy-patches" group.
To post to this group, send email to sympy-patches@googlegroups.com
To unsubscribe from this group, send email to 
sympy-patches+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sympy-patches?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to