]> www.ginac.de Git - ginac.git/blobdiff - ginac/add.cpp
* Added output-support for Python bindings and LaTeX printing for
[ginac.git] / ginac / add.cpp
index bdcd49999a59182538517f877625197813e4b14f..279933d3ecb3f907e1940e4ebeee83357aefb0c1 100644 (file)
@@ -27,7 +27,6 @@
 #include "mul.h"
 #include "matrix.h"
 #include "archive.h"
-#include "debugmsg.h"
 #include "utils.h"
 
 namespace GiNaC {
@@ -35,12 +34,11 @@ namespace GiNaC {
 GINAC_IMPLEMENT_REGISTERED_CLASS(add, expairseq)
 
 //////////
-// default constructor, destructor, copy constructor assignment operator and helpers
+// default ctor, dtor, copy ctor, assignment operator and helpers
 //////////
 
 add::add()
 {
-       debugmsg("add default constructor",LOGLEVEL_CONSTRUCT);
        tinfo_key = TINFO_add;
 }
 
@@ -55,7 +53,6 @@ DEFAULT_DESTROY(add)
 
 add::add(const ex & lh, const ex & rh)
 {
-       debugmsg("add constructor from ex,ex",LOGLEVEL_CONSTRUCT);
        tinfo_key = TINFO_add;
        overall_coeff = _ex0;
        construct_from_2_ex(lh,rh);
@@ -64,7 +61,6 @@ add::add(const ex & lh, const ex & rh)
 
 add::add(const exvector & v)
 {
-       debugmsg("add constructor from exvector",LOGLEVEL_CONSTRUCT);
        tinfo_key = TINFO_add;
        overall_coeff = _ex0;
        construct_from_exvector(v);
@@ -73,7 +69,6 @@ add::add(const exvector & v)
 
 add::add(const epvector & v)
 {
-       debugmsg("add constructor from epvector",LOGLEVEL_CONSTRUCT);
        tinfo_key = TINFO_add;
        overall_coeff = _ex0;
        construct_from_epvector(v);
@@ -82,7 +77,6 @@ add::add(const epvector & v)
 
 add::add(const epvector & v, const ex & oc)
 {
-       debugmsg("add constructor from epvector,ex",LOGLEVEL_CONSTRUCT);
        tinfo_key = TINFO_add;
        overall_coeff = oc;
        construct_from_epvector(v);
@@ -91,7 +85,6 @@ add::add(const epvector & v, const ex & oc)
 
 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;
@@ -114,8 +107,6 @@ DEFAULT_ARCHIVING(add)
 
 void add::print(const print_context & c, unsigned level) const
 {
-       debugmsg("add print", LOGLEVEL_PRINT);
-
        if (is_a<print_tree>(c)) {
 
                inherited::print(c, level);
@@ -161,10 +152,22 @@ void add::print(const print_context & c, unsigned level) const
                                c.s << '+';
                        overall_coeff.print(c, precedence());
                }
-       
+               
                if (precedence() <= level)
                        c.s << ")";
 
+       } else if (is_a<print_python_repr>(c)) {
+
+               c.s << class_name() << '(';
+               unsigned end = nops();
+               if (end)
+                       op(0).print(c);
+               for (unsigned i=1; i<end; ++i) {
+                       c.s << ',';
+                       op(i).print(c);
+               }
+               c.s << ')';
+
        } else {
 
                if (precedence() <= level) {
@@ -316,8 +319,6 @@ ex add::coeff(const ex & s, int n) const
  *  @param level cut-off in recursive evaluation */
 ex add::eval(int level) const
 {
-       debugmsg("add eval",LOGLEVEL_MEMBER_FUNCTION);
-       
        epvector *evaled_seqp = evalchildren(level);
        if (evaled_seqp) {
                // do more evaluation later
@@ -378,7 +379,7 @@ ex add::evalm(void) const
                                sum = sum.add(ex_to<matrix>(m));
                } else
                        all_matrices = false;
-               it++;
+               ++it;
        }
 
        if (all_matrices) {
@@ -456,7 +457,7 @@ expair add::split_ex_to_pair(const ex & e) const
 {
        if (is_ex_exactly_of_type(e,mul)) {
                const mul &mulref(ex_to<mul>(e));
-               ex numfactor = mulref.overall_coeff;
+               const ex &numfactor = mulref.overall_coeff;
                mul *mulcopyp = new mul(mulref);
                mulcopyp->overall_coeff = _ex1;
                mulcopyp->clearflag(status_flags::evaluated);
@@ -473,7 +474,7 @@ expair add::combine_ex_with_coeff_to_pair(const ex & e,
        GINAC_ASSERT(is_exactly_a<numeric>(c));
        if (is_ex_exactly_of_type(e, mul)) {
                const mul &mulref(ex_to<mul>(e));
-               ex numfactor = mulref.overall_coeff;
+               const ex &numfactor = mulref.overall_coeff;
                mul *mulcopyp = new mul(mulref);
                mulcopyp->overall_coeff = _ex1;
                mulcopyp->clearflag(status_flags::evaluated);
@@ -512,7 +513,7 @@ ex add::recombine_pair_to_ex(const expair & p) const
        if (ex_to<numeric>(p.coeff).is_equal(_num1))
                return p.rest;
        else
-               return p.rest*p.coeff;
+               return (new mul(p.rest,p.coeff))->setflag(status_flags::dynallocated);
 }
 
 ex add::expand(unsigned options) const