]> www.ginac.de Git - ginac.git/blobdiff - ginac/mul.cpp
Fix mul::info(info_flags::nonnegative).
[ginac.git] / ginac / mul.cpp
index cee5cd7a7a9f4faf3405eb1f4c9af0b52bd26c02..22133a74c06fc72ab9ad2d1a5b30b5f31a9ecc8e 100644 (file)
@@ -3,7 +3,7 @@
  *  Implementation of GiNaC's products of expressions. */
 
 /*
- *  GiNaC Copyright (C) 1999-2011 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2015 Johannes Gutenberg University Mainz, Germany
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -307,6 +307,13 @@ bool mul::info(unsigned inf) const
                }
                case info_flags::positive:
                case info_flags::negative: {
+                       if ((inf==info_flags::positive) && (flags & status_flags::is_positive))
+                               return true;
+                       else if ((inf==info_flags::negative) && (flags & status_flags::is_negative))
+                               return true;
+                       if (flags & status_flags::purely_indefinite)
+                               return false;
+
                        bool pos = true;
                        epvector::const_iterator i = seq.begin(), end = seq.end();
                        while (i != end) {
@@ -320,9 +327,12 @@ bool mul::info(unsigned inf) const
                        }
                        if (overall_coeff.info(info_flags::negative))
                                pos = !pos;
-                       return (inf ==info_flags::positive? pos : !pos);
+                       setflag(pos ? status_flags::is_positive : status_flags::is_negative);
+                       return (inf == info_flags::positive? pos : !pos);
                }
                case info_flags::nonnegative: {
+                       if  (flags & status_flags::is_positive)
+                               return true;
                        bool pos = true;
                        epvector::const_iterator i = seq.begin(), end = seq.end();
                        while (i != end) {
@@ -334,7 +344,7 @@ bool mul::info(unsigned inf) const
                                else
                                        return false;
                        }
-                       return (overall_coeff.info(info_flags::negative)? pos : !pos);
+                       return (overall_coeff.info(info_flags::negative)? !pos : pos);
                }
                case info_flags::posint:
                case info_flags::negint: {
@@ -373,6 +383,21 @@ bool mul::info(unsigned inf) const
                                return false;
                        return pos; 
                }
+               case info_flags::indefinite: {
+                       if (flags & status_flags::purely_indefinite)
+                               return true;
+                       if (flags & (status_flags::is_positive | status_flags::is_negative))
+                               return false;
+                       epvector::const_iterator i = seq.begin(), end = seq.end();
+                       while (i != end) {
+                               const ex& term = recombine_pair_to_ex(*i);
+                               if (term.info(info_flags::positive) || term.info(info_flags::negative))
+                                       return false;
+                               ++i;
+                       }
+                       setflag(status_flags::purely_indefinite);
+                       return true;
+               }
        }
        return inherited::info(inf);
 }
@@ -381,7 +406,7 @@ bool mul::is_polynomial(const ex & var) const
 {
        for (epvector::const_iterator i=seq.begin(); i!=seq.end(); ++i) {
                if (!i->rest.is_polynomial(var) ||
-                   (i->rest.has(var) && !i->coeff.info(info_flags::integer))) {
+                   (i->rest.has(var) && !i->coeff.info(info_flags::nonnegint))) {
                        return false;
                }
        }