error in simplification

24 views
Skip to first unread message

van...@asu.cas.cz

unread,
Feb 13, 2015, 8:15:50 AM2/13/15
to sy...@googlegroups.com
Here is an example of problem, the program is self-explanatory:

from sympy import Symbol,cos,sqrt,simplify,cosh

m=Symbol("m",positive=True)
e=Symbol("e",real=True,negative=False)

a1=4*cos(e)**2-4*cos(e)**4-1+4*(cos(e)-cosh(m))**2+cos(2*e)**2
b1=4*(cos(e)-cosh(m))**2
print simplify(a1)-b1    # a1 is equal to b1, so the result is zero
# however, the original version and the simplified version yield
#  different results in the following two identical expressions
# the first result is wrong, it is not -2, but +2 because cosh(m) > cos(e),
#  the second result is true
# it looks that sqrt(a1) results in 2*(cos(e)-cosh(m)), which is wrong,
#  it must be 2*Abs(cos(e)-cosh(m))
print simplify(sqrt(a1)/(cosh(m)-cos(e)))
print simplify(sqrt(simplify(a1))/(cosh(m)-cos(e)))

"""
Python 2.7.8 (default, Sep 30 2014, 15:34:38) [GCC] on linux2

output:

0
-2
-2*Abs(cos(e) - cosh(m))/(cos(e) - cosh(m))

"""


Chris Smith

unread,
Feb 13, 2015, 4:11:56 PM2/13/15
to sy...@googlegroups.com
Try the most recent git version of SymPy in which I get

>>> from sympy import *

>>> m=Symbol("m",positive=True)
>>> e=Symbol("e",real=True,negative=False)
>>>
>>> a1=4*cos(e)**2-4*cos(e)**4-1+4*(cos(e)-cosh(m))**2+cos(2*e)**2
>>> b1=4*(cos(e)-cosh(m))**2
>>> sqrt(a1)/(cosh(m)-cos(e))
sqrt
(4*(cos(e) - cosh(m))**2 - 4*cos(e)**4 + 4*cos(e)**2 + cos(2*e)**2 - 1)/(-co
s
(e) + cosh(m))
>>> simplify(_)

-2*Abs(cos(e) - cosh(m))/(cos(e) - cosh(m))
Reply all
Reply to author
Forward
0 new messages