]> www.ginac.de Git - ginac.git/commitdiff
- info(info_flags::has_indices) now works for sums and products. It
authorJens Vollinga <vollinga@thep.physik.uni-mainz.de>
Mon, 15 Oct 2007 23:39:01 +0000 (23:39 +0000)
committerJens Vollinga <vollinga@thep.physik.uni-mainz.de>
Mon, 15 Oct 2007 23:39:01 +0000 (23:39 +0000)
returns true if the expression has indices (no matter dummy or free),
and false otherwise [Sheplyakov].

ginac/expairseq.cpp
ginac/flags.h
ginac/idx.cpp
ginac/power.cpp
ginac/symbol.cpp

index 757f3c3989a62bf6b46378e41367a90974555010..79c741abdeccddf532dfd46dac3921aef2b93206 100644 (file)
@@ -24,6 +24,7 @@
 #include <algorithm>
 #include <string>
 #include <stdexcept>
 #include <algorithm>
 #include <string>
 #include <stdexcept>
+#include <iterator>
 
 #include "expairseq.h"
 #include "lst.h"
 
 #include "expairseq.h"
 #include "lst.h"
@@ -267,8 +268,26 @@ void expairseq::do_print_tree(const print_tree & c, unsigned level) const
 
 bool expairseq::info(unsigned inf) const
 {
 
 bool expairseq::info(unsigned inf) const
 {
-       if (inf == info_flags::expanded)
-               return (flags & status_flags::expanded);
+       switch(inf) {
+               case info_flags::expanded:
+                       return (flags & status_flags::expanded);
+               case info_flags::has_indices: {
+                       if (flags & status_flags::has_indices)
+                               return true;
+                       else if (flags & status_flags::has_no_indices)
+                               return false;
+                       for (epvector::const_iterator i = seq.begin(); i != seq.end(); ++i) {
+                               if (i->rest.info(info_flags::has_indices)) {
+                                       this->setflag(status_flags::has_indices);
+                                       this->clearflag(status_flags::has_no_indices);
+                                       return true;
+                               }
+                       }
+                       this->clearflag(status_flags::has_indices);
+                       this->setflag(status_flags::has_no_indices);
+                       return false;
+               }
+       }
        return inherited::info(inf);
 }
 
        return inherited::info(inf);
 }
 
index 86d823844f80558242cd3bb18bfc7e148270758e..372b89932ec995a4f8fe1c2de6c778163cb02150 100644 (file)
@@ -193,7 +193,9 @@ public:
                evaluated       = 0x0002, ///< .eval() has already done its job
                expanded        = 0x0004, ///< .expand(0) has already done its job (other expand() options ignore this flag)
                hash_calculated = 0x0008, ///< .calchash() has already done its job
                evaluated       = 0x0002, ///< .eval() has already done its job
                expanded        = 0x0004, ///< .expand(0) has already done its job (other expand() options ignore this flag)
                hash_calculated = 0x0008, ///< .calchash() has already done its job
-               not_shareable   = 0x0010  ///< don't share instances of this object between different expressions unless explicitly asked to (used by ex::compare())
+               not_shareable   = 0x0010, ///< don't share instances of this object between different expressions unless explicitly asked to (used by ex::compare())
+               has_indices     = 0x0020,
+               has_no_indices  = 0x0040  // ! (has_indices || has_no_indices) means "don't know"
        };
 };
 
        };
 };
 
index 3e17569a1a869f37bff5f3916288639b66781a05..e966b14a968672b67ce8ec8d72a2d8c3843ce979 100644 (file)
@@ -234,8 +234,11 @@ void spinidx::do_print_tree(const print_tree & c, unsigned level) const
 
 bool idx::info(unsigned inf) const
 {
 
 bool idx::info(unsigned inf) const
 {
-       if (inf == info_flags::idx)
-               return true;
+       switch(inf) {
+               case info_flags::idx:
+               case info_flags::has_indices:
+                       return true;
+       }
        return inherited::info(inf);
 }
 
        return inherited::info(inf);
 }
 
index 68bec71c949c4866fd2c949c2c9df0db78ec2112..10de528d06ad9cf09381b4376f61ff433ca414f6 100644 (file)
@@ -241,6 +241,21 @@ bool power::info(unsigned inf) const
                               basis.info(inf);
                case info_flags::expanded:
                        return (flags & status_flags::expanded);
                               basis.info(inf);
                case info_flags::expanded:
                        return (flags & status_flags::expanded);
+               case info_flags::has_indices: {
+                       if (flags & status_flags::has_indices)
+                               return true;
+                       else if (flags & status_flags::has_no_indices)
+                               return false;
+                       else if (basis.info(info_flags::has_indices)) {
+                               setflag(status_flags::has_indices);
+                               clearflag(status_flags::has_no_indices);
+                               return true;
+                       } else {
+                               clearflag(status_flags::has_indices);
+                               setflag(status_flags::has_no_indices);
+                               return false;
+                       }
+               }
        }
        return inherited::info(inf);
 }
        }
        return inherited::info(inf);
 }
index 9f3b1c62df576c4afeaa04f68ed58f9ff6ee978e..b68fed87fe5f7a8d36485859485d863f843fe2c7 100644 (file)
@@ -207,22 +207,25 @@ void symbol::do_print_python_repr(const print_python_repr & c, unsigned level) c
 
 bool symbol::info(unsigned inf) const
 {
 
 bool symbol::info(unsigned inf) const
 {
-       if (inf == info_flags::symbol)
-               return true;
-       if (inf == info_flags::polynomial ||
-           inf == info_flags::integer_polynomial ||
-           inf == info_flags::cinteger_polynomial ||
-           inf == info_flags::rational_polynomial ||
-           inf == info_flags::crational_polynomial ||
-           inf == info_flags::rational_function ||
-                       inf == info_flags::expanded)
-               return true;
-       if (inf == info_flags::real)
-               return domain==domain::real || domain==domain::positive;
-       if (inf == info_flags::positive || inf == info_flags::nonnegative)
-               return domain == domain::positive;
-       else
-               return inherited::info(inf);
+       switch (inf) {
+               case info_flags::symbol:
+               case info_flags::polynomial:
+               case info_flags::integer_polynomial: 
+               case info_flags::cinteger_polynomial: 
+               case info_flags::rational_polynomial: 
+               case info_flags::crational_polynomial: 
+               case info_flags::rational_function: 
+               case info_flags::expanded:
+                       return true;
+               case info_flags::real:
+                       return domain == domain::real || domain == domain::positive;
+               case info_flags::positive:
+               case info_flags::nonnegative:
+                       return domain == domain::positive;
+               case info_flags::has_indices:
+                       return false;
+       }
+       return inherited::info(inf);
 }
 
 ex symbol::eval(int level) const
 }
 
 ex symbol::eval(int level) const