]> www.ginac.de Git - ginac.git/blobdiff - ginac/normal.cpp
- lcm_of_coefficients_denominators(1/2+x^10) returned 1024 instead of 2 and
[ginac.git] / ginac / normal.cpp
index 3eaf4206bbbe314d1ea2ff667db8a792c0d32853..669a59f8de12d0a7cfb3d3eba694eaa9703d275d 100644 (file)
@@ -23,7 +23,6 @@
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#include <stdexcept>
 #include <algorithm>
 #include <map>
 
@@ -45,9 +44,7 @@
 #include "symbol.h"
 #include "utils.h"
 
-#ifndef NO_NAMESPACE_GINAC
 namespace GiNaC {
-#endif // ndef NO_NAMESPACE_GINAC
 
 // If comparing expressions (ex::compare()) is fast, you can set this to 1.
 // Some routines like quo(), rem() and gcd() will then return a quick answer
@@ -243,8 +240,12 @@ static numeric lcmcoeff(const ex &e, const numeric &l)
                for (unsigned i=0; i<e.nops(); i++)
                        c *= lcmcoeff(e.op(i), _num1());
                return lcm(c, l);
-       } else if (is_ex_exactly_of_type(e, power))
-               return pow(lcmcoeff(e.op(0), l), ex_to_numeric(e.op(1)));
+       } else if (is_ex_exactly_of_type(e, power)) {
+               if (is_ex_exactly_of_type(e.op(0), symbol))
+                       return l;
+               else
+                       return pow(lcmcoeff(e.op(0), l), ex_to_numeric(e.op(1)));
+       }
        return l;
 }
 
@@ -283,7 +284,10 @@ static ex multiply_lcm(const ex &e, const numeric &lcm)
                        c += multiply_lcm(e.op(i), lcm);
                return c;
        } else if (is_ex_exactly_of_type(e, power)) {
-               return pow(multiply_lcm(e.op(0), lcm.power(ex_to_numeric(e.op(1)).inverse())), e.op(1));
+               if (is_ex_exactly_of_type(e.op(0), symbol))
+                       return e * lcm;
+               else
+                       return pow(multiply_lcm(e.op(0), lcm.power(ex_to_numeric(e.op(1)).inverse())), e.op(1));
        } else
                return e * lcm;
 }
@@ -621,9 +625,10 @@ typedef std::pair<ex, ex> ex2;
 typedef std::pair<ex, bool> exbool;
 
 struct ex2_less {
-       bool operator() (const ex2 p, const ex2 q) const 
+       bool operator() (const ex2 &p, const ex2 &q) const 
        {
-               return p.first.compare(q.first) < 0 || (!(q.first.compare(p.first) < 0) && p.second.compare(q.second) < 0);        
+               int cmp = p.first.compare(q.first);
+               return ((cmp<0) || (!(cmp>0) && p.second.compare(q.second)<0));
        }
 };
 
@@ -1183,6 +1188,8 @@ numeric ex::max_coefficient(void) const
        return bp->max_coefficient();
 }
 
+/** Implementation ex::max_coefficient().
+ *  @see heur_gcd */
 numeric basic::max_coefficient(void) const
 {
        return _num1();
@@ -1245,11 +1252,7 @@ ex basic::smod(const numeric &xi) const
 
 ex numeric::smod(const numeric &xi) const
 {
-#ifndef NO_NAMESPACE_GINAC
        return GiNaC::smod(*this, xi);
-#else // ndef NO_NAMESPACE_GINAC
-       return ::smod(*this, xi);
-#endif // ndef NO_NAMESPACE_GINAC
 }
 
 ex add::smod(const numeric &xi) const
@@ -1260,21 +1263,13 @@ ex add::smod(const numeric &xi) const
        epvector::const_iterator itend = seq.end();
        while (it != itend) {
                GINAC_ASSERT(!is_ex_exactly_of_type(it->rest,numeric));
-#ifndef NO_NAMESPACE_GINAC
                numeric coeff = GiNaC::smod(ex_to_numeric(it->coeff), xi);
-#else // ndef NO_NAMESPACE_GINAC
-               numeric coeff = ::smod(ex_to_numeric(it->coeff), xi);
-#endif // ndef NO_NAMESPACE_GINAC
                if (!coeff.is_zero())
                        newseq.push_back(expair(it->rest, coeff));
                it++;
        }
        GINAC_ASSERT(is_ex_exactly_of_type(overall_coeff,numeric));
-#ifndef NO_NAMESPACE_GINAC
        numeric coeff = GiNaC::smod(ex_to_numeric(overall_coeff), xi);
-#else // ndef NO_NAMESPACE_GINAC
-       numeric coeff = ::smod(ex_to_numeric(overall_coeff), xi);
-#endif // ndef NO_NAMESPACE_GINAC
        return (new add(newseq,coeff))->setflag(status_flags::dynallocated);
 }
 
@@ -1290,11 +1285,7 @@ ex mul::smod(const numeric &xi) const
 #endif // def DO_GINAC_ASSERT
        mul * mulcopyp=new mul(*this);
        GINAC_ASSERT(is_ex_exactly_of_type(overall_coeff,numeric));
-#ifndef NO_NAMESPACE_GINAC
        mulcopyp->overall_coeff = GiNaC::smod(ex_to_numeric(overall_coeff),xi);
-#else // ndef NO_NAMESPACE_GINAC
-       mulcopyp->overall_coeff = ::smod(ex_to_numeric(overall_coeff),xi);
-#endif // ndef NO_NAMESPACE_GINAC
        mulcopyp->clearflag(status_flags::evaluated);
        mulcopyp->clearflag(status_flags::hash_calculated);
        return mulcopyp->setflag(status_flags::dynallocated);
@@ -2064,8 +2055,8 @@ ex power::normal(lst &sym_lst, lst &repl_lst, int level) const
 }
 
 
-/** Implementation of ex::normal() for pseries. It normalizes each coefficient and
- *  replaces the series by a temporary symbol.
+/** Implementation of ex::normal() for pseries. It normalizes each coefficient
+ *  and replaces the series by a temporary symbol.
  *  @see ex::normal */
 ex pseries::normal(lst &sym_lst, lst &repl_lst, int level) const
 {
@@ -2244,6 +2235,4 @@ ex ex::to_rational(lst &repl_lst) const
 }
 
 
-#ifndef NO_NAMESPACE_GINAC
 } // namespace GiNaC
-#endif // ndef NO_NAMESPACE_GINAC