Improve abs(arg).
authorVladimir Kisil <kisilv@maths.leeds.ac.uk>
Wed, 22 Apr 2015 21:21:53 +0000 (23:21 +0200)
committerRichard Kreckel <kreckel@ginac.de>
Wed, 22 Apr 2015 21:21:53 +0000 (23:21 +0200)
Make abs(arg) return -arg if arg is negative or if -arg is known to be
nonnegative.

ginac/inifcns.cpp

index 28d54fe..ecb6e00 100644 (file)
@@ -273,6 +273,9 @@ static ex abs_eval(const ex & arg)
        if (arg.info(info_flags::nonnegative))
                return arg;
 
+       if (arg.info(info_flags::negative) || (-arg).info(info_flags::nonnegative))
+               return -arg;
+
        if (is_ex_the_function(arg, abs))
                return arg;