X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Fncmul.cpp;h=e775d82e9e2d85207dd1330bd494d801d195ab9e;hp=44c5d30e074a686873f4e866a7c7a54782098bcb;hb=a8030df4915df6a1ea0312cbffb79ace4795c865;hpb=b1f684b10d31daafc4e4a5bdaee02ba455abe747 diff --git a/ginac/ncmul.cpp b/ginac/ncmul.cpp index 44c5d30e..e775d82e 100644 --- a/ginac/ncmul.cpp +++ b/ginac/ncmul.cpp @@ -28,6 +28,7 @@ #include "ex.h" #include "add.h" #include "mul.h" +#include "print.h" #include "archive.h" #include "debugmsg.h" #include "utils.h" @@ -40,25 +41,14 @@ GINAC_IMPLEMENT_REGISTERED_CLASS(ncmul, exprseq) // default constructor, destructor, copy constructor assignment operator and helpers ////////// -// public - ncmul::ncmul() { debugmsg("ncmul default constructor",LOGLEVEL_CONSTRUCT); tinfo_key = TINFO_ncmul; } -// protected - -void ncmul::copy(const ncmul & other) -{ - inherited::copy(other); -} - -void ncmul::destroy(bool call_parent) -{ - if (call_parent) inherited::destroy(call_parent); -} +DEFAULT_COPY(ncmul) +DEFAULT_DESTROY(ncmul) ////////// // other constructors @@ -115,24 +105,7 @@ ncmul::ncmul(exvector * vp) : inherited(vp) // archiving ////////// -/** Construct object from archive_node. */ -ncmul::ncmul(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst) -{ - debugmsg("ncmul constructor from archive_node", LOGLEVEL_CONSTRUCT); -} - -/** Unarchive the object. */ -ex ncmul::unarchive(const archive_node &n, const lst &sym_lst) -{ - return (new ncmul(n, sym_lst))->setflag(status_flags::dynallocated); -} - -/** Archive the object. */ -void ncmul::archive(archive_node &n) const -{ - inherited::archive(n); -} - +DEFAULT_ARCHIVING(ncmul) ////////// // functions overriding virtual functions from bases classes @@ -140,36 +113,28 @@ void ncmul::archive(archive_node &n) const // public -void ncmul::print(std::ostream & os, unsigned upper_precedence) const +void ncmul::print(const print_context & c, unsigned level) const { - debugmsg("ncmul print",LOGLEVEL_PRINT); - printseq(os,'(','*',')',precedence,upper_precedence); -} + debugmsg("ncmul print", LOGLEVEL_PRINT); -void ncmul::printraw(std::ostream & os) const -{ - debugmsg("ncmul printraw",LOGLEVEL_PRINT); - os << "ncmul("; - for (exvector::const_iterator it=seq.begin(); it!=seq.end(); ++it) { - (*it).bp->printraw(os); - os << ","; - } - os << ",hash=" << hashvalue << ",flags=" << flags; - os << ")"; -} + if (is_of_type(c, print_tree)) { -void ncmul::printcsrc(std::ostream & os, unsigned type, unsigned upper_precedence) const -{ - debugmsg("ncmul print csrc",LOGLEVEL_PRINT); - exvector::const_iterator it; - exvector::const_iterator itend = seq.end()-1; - os << "ncmul("; - for (it=seq.begin(); it!=itend; ++it) { - (*it).bp->printcsrc(os,precedence); - os << ","; - } - (*it).bp->printcsrc(os,precedence); - os << ")"; + inherited::print(c, level); + + } else if (is_of_type(c, print_csrc)) { + + c.s << "ncmul("; + exvector::const_iterator it = seq.begin(), itend = seq.end()-1; + while (it != itend) { + it->print(c, precedence); + c.s << ","; + it++; + } + it->print(c, precedence); + c.s << ")"; + + } else + printseq(c, '(', '*', ')', precedence, level); } bool ncmul::info(unsigned inf) const @@ -246,7 +211,7 @@ ex ncmul::expand(unsigned options) const status_flags::expanded); } -int ncmul::degree(const symbol & s) const +int ncmul::degree(const ex & s) const { int deg_sum=0; for (exvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) { @@ -255,7 +220,7 @@ int ncmul::degree(const symbol & s) const return deg_sum; } -int ncmul::ldegree(const symbol & s) const +int ncmul::ldegree(const ex & s) const { int deg_sum=0; for (exvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) { @@ -264,7 +229,7 @@ int ncmul::ldegree(const symbol & s) const return deg_sum; } -ex ncmul::coeff(const symbol & s, int n) const +ex ncmul::coeff(const ex & s, int n) const { exvector coeffseq; coeffseq.reserve(seq.size()); @@ -336,7 +301,7 @@ ex ncmul::eval(int level) const // *(c1,c2,ncmul(...)) (pull out commutative elements) // ncmul(x1,y1,x2,y2) -> *(ncmul(x1,x2),ncmul(y1,y2)) // (collect elements of same type) - // ncmul(x1,x2,x3,...) -> x::eval_ncmul(x1,x2,x3,...) + // ncmul(x1,x2,x3,...) -> x::simplify_ncmul(x1,x2,x3,...) // the following rule would be nice, but produces a recursion, // which must be trapped by introducing a flag that the sub-ncmuls() // are already evaluated (maybe later...)