]> www.ginac.de Git - ginac.git/blobdiff - ginac/add.cpp
- introduced info_flag::algebraic.
[ginac.git] / ginac / add.cpp
index 5db2045c6c4f15687f5b3195806e917a37b464da..8a7e9041fff631cfdb78d29bb833cad64e97d950 100644 (file)
@@ -91,7 +91,7 @@ add::add(const ex & lh, const ex & rh)
 {
     debugmsg("add constructor from ex,ex",LOGLEVEL_CONSTRUCT);
     tinfo_key = TINFO_add;
-    overall_coeff=_ex0();
+    overall_coeff = _ex0();
     construct_from_2_ex(lh,rh);
     GINAC_ASSERT(is_canonical());
 }
@@ -100,7 +100,7 @@ add::add(const exvector & v)
 {
     debugmsg("add constructor from exvector",LOGLEVEL_CONSTRUCT);
     tinfo_key = TINFO_add;
-    overall_coeff=_ex0();
+    overall_coeff = _ex0();
     construct_from_exvector(v);
     GINAC_ASSERT(is_canonical());
 }
@@ -126,7 +126,7 @@ add::add(const epvector & v)
 {
     debugmsg("add constructor from epvector",LOGLEVEL_CONSTRUCT);
     tinfo_key = TINFO_add;
-    overall_coeff=_ex0();
+    overall_coeff = _ex0();
     construct_from_epvector(v);
     GINAC_ASSERT(is_canonical());
 }
@@ -135,7 +135,7 @@ add::add(const epvector & v, const ex & oc)
 {
     debugmsg("add constructor from epvector,ex",LOGLEVEL_CONSTRUCT);
     tinfo_key = TINFO_add;
-    overall_coeff=oc;
+    overall_coeff = oc;
     construct_from_epvector(v);
     GINAC_ASSERT(is_canonical());
 }
@@ -145,7 +145,7 @@ add::add(epvector * vp, const ex & oc)
     debugmsg("add constructor from epvector *,ex",LOGLEVEL_CONSTRUCT);
     tinfo_key = TINFO_add;
     GINAC_ASSERT(vp!=0);
-    overall_coeff=oc;
+    overall_coeff = oc;
     construct_from_epvector(*vp);
     delete vp;
     GINAC_ASSERT(is_canonical());
@@ -290,28 +290,35 @@ void add::printcsrc(ostream & os, unsigned type, unsigned upper_precedence) cons
 
 bool add::info(unsigned inf) const
 {
-    // TODO: optimize
-    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) {
-        for (epvector::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
-            if (!(recombine_pair_to_ex(*it).info(inf)))
-                return false;
+    switch (inf) {
+        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: {
+            for (epvector::const_iterator i=seq.begin(); i!=seq.end(); ++i) {
+                if (!(recombine_pair_to_ex(*i).info(inf)))
+                    return false;
+            }
+            return overall_coeff.info(inf);
+        }
+        case info_flags::algebraic: {
+            for (epvector::const_iterator i=seq.begin(); i!=seq.end(); ++i) {
+                if ((recombine_pair_to_ex(*i).info(inf)))
+                    return true;
+            }
+            return false;
         }
-        return overall_coeff.info(inf);
-    } else {
-        return inherited::info(inf);
     }
+    return inherited::info(inf);
 }
 
 int add::degree(const symbol & s) const
 {
-    int deg=INT_MIN;
+    int deg = INT_MIN;
     if (!overall_coeff.is_equal(_ex0())) {
-        deg=0;
+        deg = 0;
     }
     int cur_deg;
     for (epvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
@@ -323,13 +330,13 @@ int add::degree(const symbol & s) const
 
 int add::ldegree(const symbol & s) const
 {
-    int deg=INT_MAX;
+    int deg = INT_MAX;
     if (!overall_coeff.is_equal(_ex0())) {
-        deg=0;
+        deg = 0;
     }
     int cur_deg;
     for (epvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
-        cur_deg=(*cit).rest.ldegree(s);
+        cur_deg = (*cit).rest.ldegree(s);
         if (cur_deg<deg) deg=cur_deg;
     }
     return deg;
@@ -365,7 +372,7 @@ ex add::eval(int level) const
         return (new add(evaled_seqp,overall_coeff))->
                    setflag(status_flags::dynallocated);
     }
-
+    
 #ifdef DO_GINAC_ASSERT
     for (epvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
         GINAC_ASSERT(!is_ex_exactly_of_type((*cit).rest,add));
@@ -375,13 +382,13 @@ ex add::eval(int level) const
         GINAC_ASSERT(!is_ex_exactly_of_type((*cit).rest,numeric));
     }
 #endif // def DO_GINAC_ASSERT
-
+    
     if (flags & status_flags::evaluated) {
         GINAC_ASSERT(seq.size()>0);
         GINAC_ASSERT((seq.size()>1)||!overall_coeff.is_equal(_ex0()));
         return *this;
     }
-
+    
     int seq_size=seq.size();
     if (seq_size==0) {
         // +(;c) -> c
@@ -528,12 +535,16 @@ ex add::recombine_pair_to_ex(const expair & p) const
 
 ex add::expand(unsigned options) const
 {
-    epvector * vp=expandchildren(options);
+    if (flags & status_flags::expanded)
+        return *this;
+    
+    epvector * vp = expandchildren(options);
     if (vp==0) {
         return *this;
     }
-    return (new add(vp,overall_coeff))->setflag(status_flags::expanded    |
-                                                status_flags::dynallocated );
+    return (new add(vp,overall_coeff))->
+        setflag(status_flags::expanded |
+                status_flags::dynallocated);
 }
 
 //////////
@@ -554,14 +565,14 @@ ex add::expand(unsigned options) const
 
 // protected
 
-unsigned add::precedence=40;
+unsigned add::precedence = 40;
 
 //////////
 // global constants
 //////////
 
 const add some_add;
-const type_info & typeid_add=typeid(some_add);
+const type_info & typeid_add = typeid(some_add);
 
 #ifndef NO_NAMESPACE_GINAC
 } // namespace GiNaC