Comment #10 on issue 3052 by smi...@gmail.com: evaluating Abs should result
in a positive number
http://code.google.com/p/sympy/issues/detail?id=3052
Abs is now left in place. And since sign(nearlyzeroexpression).n()._prec
may not be 1 (i.e. since the sign of an expression which might be nearly
zero can be evaluated to a significant value) that can be used to determine
what to return from Abs:
b = Float(str(int((pi*1e20).n(22))))
e = abs(b*(cos(x)**2+sin(x)**2)-b)
e.subs(x,Rational('.1'))
Abs(-3.14159265358979e+20 + 3.14159265358979e+20*sin(1/10)**2 +
3.14159265358979
e+20*cos(1/10)**2)
OK, that's good in that it didn't return an evaluated value that is wrong
but it would have been better if the sign of the argument had been
evaluated to find that it was negative so the negative of the expression
could be returned without the Abs() wrapping it:
sign(e.subs(x,Rational('.1')).args[0]).n()
-1.00000000000000
_._prec
53
I don't understand why the sign(expr) can be evaluated accurately while
expr itself cannot be. But, that being the case, I think Abs just needs to
check the sign of a numerical argument to see if the sign can be determined
with precision, and if so then the expression can be returned multiplied by
the sign rather than being wrapped in Abs:
in Abs somewhere...
if arg.is_number:
s = sign(arg).n()
if s._prec != 1:
if s < 0: return -arg
else: return arg
return Abs(arg) # unevaluated
--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings
--
You received this message because you are subscribed to the Google Groups
"sympy-issues" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to sympy-issues+unsubscr...@googlegroups.com.
To post to this group, send email to sympy-issues@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy-issues?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.