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:19:21 +0000 (23:19 +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 4c85704..5f714fe 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 c4593dc..547cc59 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 35ba88e..bc38159 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 999d9b1..7ae0f04 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;