-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Abs([-1,1] range real function - 1) -> redundant Abs #21359
Comments
Here is a possible solution to have Abs recognize this: diff --git a/sympy/functions/elementary/complexes.py b/sympy/functions/elementary/complexes.py
diff --git a/sympy/functions/elementary/complexes.py b/sympy/functions/elementary/complexes.py
index b34ca3a7de..7deddeb713 100644
--- a/sympy/functions/elementary/complexes.py
+++ b/sympy/functions/elementary/complexes.py
@@ -7,10 +7,11 @@
from sympy.core.numbers import pi, I, oo
from sympy.core.relational import Eq
from sympy.functions.elementary.exponential import exp, exp_polar, log
+from sympy.functions.elementary.hyperbolic import tanh
from sympy.functions.elementary.integers import ceiling
from sympy.functions.elementary.miscellaneous import sqrt
from sympy.functions.elementary.piecewise import Piecewise
-from sympy.functions.elementary.trigonometric import atan, atan2
+from sympy.functions.elementary.trigonometric import atan, atan2, cos, sin
###############################################################################
######################### REAL and IMAGINARY PARTS ############################
@@ -589,9 +590,18 @@ def eval(cls, arg):
return exp(re(arg.args[0]))
if isinstance(arg, AppliedUndef):
return
- if arg.is_Add and arg.has(S.Infinity, S.NegativeInfinity):
- if any(a.is_infinite for a in arg.as_real_imag()):
- return S.Infinity
+ if arg.is_Add:
+ if arg.has(S.Infinity, S.NegativeInfinity):
+ if any(a.is_infinite for a in arg.as_real_imag()):
+ return S.Infinity
+ else:
+ c, t = arg.as_independent(cos, sin, tanh)
+ if t:
+ m, t = t.as_independent(cos, sin, tanh)
+ if isinstance(t, (cos, sin, tanh)) and t.is_real:
+ if arg.subs(t, Dummy(nonnegative=True) - 1).is_nonnegative:
+ return arg
+ return
if arg.is_zero:
return S.Zero
if arg.is_extended_nonnegative: related to #21351 |
The proposed diff seems too much to me. It should inspect the args but not call In [25]: t = Symbol('t', real=True)
In [26]: e = 1+cos(t)
In [27]: e
Out[27]: cos(t) + 1
In [28]: e.is_nonnegative I think that maybe Maybe Lines 789 to 798 in b76553a
I'm not sure if is_ge would end up recursing back to Add.is_nonnegative though...
|
sympy/sympy/core/relational.py Lines 1235 to 1244 in 05f5021
In the following code above for any of the expression like |
if you look in the relational.py file you will see handlers/functions that get dispatched to for different types of arguments. |
Abs(cos(Dummy(real=1)) + 1)
-> arg without abs; the same forsin
andtanh
whose ranges are in [-1, 1]The text was updated successfully, but these errors were encountered: