Add mul::info() and add::info() support for numeric info_flags.
authorRichard Kreckel <kreckel@ginac.de>
Sun, 11 Oct 2009 21:19:21 +0000 (23:19 +0200)
committerRichard Kreckel <kreckel@ginac.de>
Sun, 11 Oct 2009 21:24:25 +0000 (23:24 +0200)
This way, GiNaC knows that the sum or product of a number of positive
expressions is again a positive expression. [by Vladimir Kisil]

ginac/add.cpp
ginac/flags.h
ginac/mul.cpp
ginac/power.cpp

index 4c857044d5df509892cce89bfbafe8bd99b45c79..5f714fef36b4a393ae00d34c12cd0df7db8c5f45 100644 (file)
@@ -224,6 +224,16 @@ bool add::info(unsigned inf) const
                case info_flags::integer_polynomial:
                case info_flags::cinteger_polynomial:
                case info_flags::rational_polynomial:
+               case info_flags::real:
+               case info_flags::rational:
+               case info_flags::integer:
+               case info_flags::crational:
+               case info_flags::cinteger:
+               case info_flags::positive:
+               case info_flags::nonnegative:
+               case info_flags::posint:
+               case info_flags::nonnegint:
+               case info_flags::even:
                case info_flags::crational_polynomial:
                case info_flags::rational_function: {
                        epvector::const_iterator i = seq.begin(), end = seq.end();
@@ -232,6 +242,8 @@ bool add::info(unsigned inf) const
                                        return false;
                                ++i;
                        }
+                       if (overall_coeff.is_zero() && (inf == info_flags::positive || inf == info_flags::posint))
+                               return true;
                        return overall_coeff.info(inf);
                }
                case info_flags::algebraic: {
index c4593dc47c4c33627c2f2cdb44ba71fb1b96f032..547cc5949262b27ad9920b01d4ba284c7ff7f995 100644 (file)
@@ -204,7 +204,7 @@ public:
 class info_flags {
 public:
        enum {
-               // answered by class numeric and symbols/constants in particular domains
+               // answered by class numeric, add, mul and symbols/constants in particular domains
                numeric,
                real,
                rational,
index 35ba88e4431dbf90ee7475117ed3623c2c7d24e0..bc38159d5d3713288fb6b6db1d66220b16270bc6 100644 (file)
@@ -278,6 +278,16 @@ bool mul::info(unsigned inf) const
                case info_flags::integer_polynomial:
                case info_flags::cinteger_polynomial:
                case info_flags::rational_polynomial:
+               case info_flags::real:
+               case info_flags::rational:
+               case info_flags::integer:
+               case info_flags::crational:
+               case info_flags::cinteger:
+               case info_flags::positive:
+               case info_flags::nonnegative:
+               case info_flags::posint:
+               case info_flags::nonnegint:
+               case info_flags::even:
                case info_flags::crational_polynomial:
                case info_flags::rational_function: {
                        epvector::const_iterator i = seq.begin(), end = seq.end();
@@ -286,6 +296,8 @@ bool mul::info(unsigned inf) const
                                        return false;
                                ++i;
                        }
+                       if (overall_coeff.is_equal(*_num1_p) && inf == info_flags::even)
+                               return true;
                        return overall_coeff.info(inf);
                }
                case info_flags::algebraic: {
index 999d9b147284f894f1e18298f6bd9a5465c2e9e8..7ae0f04d69e4de2760d8eab81c3e17de90b989b0 100644 (file)
@@ -240,6 +240,8 @@ bool power::info(unsigned inf) const
                               basis.info(inf);
                case info_flags::expanded:
                        return (flags & status_flags::expanded);
+               case info_flags::positive:
+                       return basis.info(info_flags::positive) && exponent.info(info_flags::real);
                case info_flags::has_indices: {
                        if (flags & status_flags::has_indices)
                                return true;