X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Fncmul.cpp;h=7cd8014931db652672366b61bf9762ebb760603c;hp=9e14edc0f875677d5c7d524922b105dd4d952d94;hb=af0c47009ca7a15af966430bdf1a72fe05c1c6f9;hpb=afdd7fa8c6c0a587f7c80789198551383e8beb7b diff --git a/ginac/ncmul.cpp b/ginac/ncmul.cpp index 9e14edc0..7cd80149 100644 --- a/ginac/ncmul.cpp +++ b/ginac/ncmul.cpp @@ -3,7 +3,7 @@ * Implementation of GiNaC's non-commutative products of expressions. */ /* - * GiNaC Copyright (C) 1999 Johannes Gutenberg University Mainz, Germany + * GiNaC Copyright (C) 1999-2000 Johannes Gutenberg University Mainz, Germany * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -28,11 +28,15 @@ #include "ex.h" #include "add.h" #include "mul.h" +#include "archive.h" #include "debugmsg.h" +#include "utils.h" -#ifndef NO_GINAC_NAMESPACE +#ifndef NO_NAMESPACE_GINAC namespace GiNaC { -#endif // ndef NO_GINAC_NAMESPACE +#endif // ndef NO_NAMESPACE_GINAC + +GINAC_IMPLEMENT_REGISTERED_CLASS(ncmul, exprseq) ////////// // default constructor, destructor, copy constructor assignment operator and helpers @@ -52,13 +56,13 @@ ncmul::~ncmul() destroy(0); } -ncmul::ncmul(ncmul const & other) +ncmul::ncmul(const ncmul & other) { debugmsg("ncmul copy constructor",LOGLEVEL_CONSTRUCT); copy(other); } -ncmul const & ncmul::operator=(ncmul const & other) +const ncmul & ncmul::operator=(const ncmul & other) { debugmsg("ncmul operator=",LOGLEVEL_ASSIGNMENT); if (this != &other) { @@ -70,14 +74,14 @@ ncmul const & ncmul::operator=(ncmul const & other) // protected -void ncmul::copy(ncmul const & other) +void ncmul::copy(const ncmul & other) { - exprseq::copy(other); + inherited::copy(other); } void ncmul::destroy(bool call_parent) { - if (call_parent) exprseq::destroy(call_parent); + if (call_parent) inherited::destroy(call_parent); } ////////// @@ -86,53 +90,76 @@ void ncmul::destroy(bool call_parent) // public -ncmul::ncmul(ex const & lh, ex const & rh) : - exprseq(lh,rh) +ncmul::ncmul(const ex & lh, const ex & rh) : + inherited(lh,rh) { debugmsg("ncmul constructor from ex,ex",LOGLEVEL_CONSTRUCT); tinfo_key = TINFO_ncmul; } -ncmul::ncmul(ex const & f1, ex const & f2, ex const & f3) : - exprseq(f1,f2,f3) +ncmul::ncmul(const ex & f1, const ex & f2, const ex & f3) : + inherited(f1,f2,f3) { debugmsg("ncmul constructor from 3 ex",LOGLEVEL_CONSTRUCT); tinfo_key = TINFO_ncmul; } -ncmul::ncmul(ex const & f1, ex const & f2, ex const & f3, - ex const & f4) : exprseq(f1,f2,f3,f4) +ncmul::ncmul(const ex & f1, const ex & f2, const ex & f3, + const ex & f4) : inherited(f1,f2,f3,f4) { debugmsg("ncmul constructor from 4 ex",LOGLEVEL_CONSTRUCT); tinfo_key = TINFO_ncmul; } -ncmul::ncmul(ex const & f1, ex const & f2, ex const & f3, - ex const & f4, ex const & f5) : exprseq(f1,f2,f3,f4,f5) +ncmul::ncmul(const ex & f1, const ex & f2, const ex & f3, + const ex & f4, const ex & f5) : inherited(f1,f2,f3,f4,f5) { debugmsg("ncmul constructor from 5 ex",LOGLEVEL_CONSTRUCT); tinfo_key = TINFO_ncmul; } -ncmul::ncmul(ex const & f1, ex const & f2, ex const & f3, - ex const & f4, ex const & f5, ex const & f6) : - exprseq(f1,f2,f3,f4,f5,f6) +ncmul::ncmul(const ex & f1, const ex & f2, const ex & f3, + const ex & f4, const ex & f5, const ex & f6) : + inherited(f1,f2,f3,f4,f5,f6) { debugmsg("ncmul constructor from 6 ex",LOGLEVEL_CONSTRUCT); tinfo_key = TINFO_ncmul; } -ncmul::ncmul(exvector const & v, bool discardable) : exprseq(v,discardable) +ncmul::ncmul(const exvector & v, bool discardable) : inherited(v,discardable) { debugmsg("ncmul constructor from exvector,bool",LOGLEVEL_CONSTRUCT); tinfo_key = TINFO_ncmul; } -ncmul::ncmul(exvector * vp) : exprseq(vp) +ncmul::ncmul(exvector * vp) : inherited(vp) { debugmsg("ncmul constructor from exvector *",LOGLEVEL_CONSTRUCT); tinfo_key = TINFO_ncmul; } + +////////// +// 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); +} + ////////// // functions overriding virtual functions from bases classes @@ -146,6 +173,39 @@ basic * ncmul::duplicate() const return new ncmul(*this); } +void ncmul::print(ostream & os, unsigned upper_precedence) const +{ + debugmsg("ncmul print",LOGLEVEL_PRINT); + printseq(os,'(','%',')',precedence,upper_precedence); +} + +void ncmul::printraw(ostream & os) const +{ + debugmsg("ncmul printraw",LOGLEVEL_PRINT); + + os << "%("; + for (exvector::const_iterator it=seq.begin(); it!=seq.end(); ++it) { + (*it).bp->printraw(os); + os << ","; + } + os << ",hash=" << hashvalue << ",flags=" << flags; + os << ")"; +} + +void ncmul::printcsrc(ostream & os, 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 << ")"; +} + bool ncmul::info(unsigned inf) const { throw(std::logic_error("which flags have to be implemented in ncmul::info()?")); @@ -172,7 +232,7 @@ ex ncmul::expand(unsigned options) const for (exvector::const_iterator cit=expanded_seq.begin(); cit!=last; ++cit) { if (is_ex_exactly_of_type((*cit),add)) { positions_of_adds[number_of_adds]=current_position; - add const & expanded_addref=ex_to_add(*cit); + const add & expanded_addref=ex_to_add(*cit); number_of_add_operands[number_of_adds]=expanded_addref.seq.size(); number_of_expanded_terms *= expanded_addref.seq.size(); number_of_adds++; @@ -201,7 +261,7 @@ ex ncmul::expand(unsigned options) const term=expanded_seq; for (l=0; lsetflag(status_flags::dynallocated | @@ -220,7 +280,7 @@ ex ncmul::expand(unsigned options) const status_flags::expanded); } -int ncmul::degree(symbol const & s) const +int ncmul::degree(const symbol & s) const { int deg_sum=0; for (exvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) { @@ -229,7 +289,7 @@ int ncmul::degree(symbol const & s) const return deg_sum; } -int ncmul::ldegree(symbol const & s) const +int ncmul::ldegree(const symbol & s) const { int deg_sum=0; for (exvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) { @@ -238,7 +298,7 @@ int ncmul::ldegree(symbol const & s) const return deg_sum; } -ex ncmul::coeff(symbol const & s, int const n) const +ex ncmul::coeff(const symbol & s, int n) const { exvector coeffseq; coeffseq.reserve(seq.size()); @@ -269,29 +329,29 @@ ex ncmul::coeff(symbol const & s, int const n) const if (coeff_found) return (new ncmul(coeffseq,1))->setflag(status_flags::dynallocated); - return exZERO(); + return _ex0(); } -unsigned ncmul::count_factors(ex const & e) const +unsigned ncmul::count_factors(const ex & e) const { if ((is_ex_exactly_of_type(e,mul)&&(e.return_type()!=return_types::commutative))|| (is_ex_exactly_of_type(e,ncmul))) { unsigned factors=0; - for (int i=0; i 1 - if (assocseq.size()==0) return exONE(); + if (assocseq.size()==0) return _ex1(); // determine return types unsignedvector rettypes; @@ -461,12 +521,12 @@ exvector ncmul::get_indices(void) const return iv; } -ex ncmul::subs(lst const & ls, lst const & lr) const +ex ncmul::subs(const lst & ls, const lst & lr) const { return ncmul(subschildren(ls, lr)); } -ex ncmul::thisexprseq(exvector const & v) const +ex ncmul::thisexprseq(const exvector & v) const { return (new ncmul(v))->setflag(status_flags::dynallocated); } @@ -478,9 +538,16 @@ ex ncmul::thisexprseq(exvector * vp) const // protected -int ncmul::compare_same_type(basic const & other) const +/** Implementation of ex::diff() for a non-commutative product. It always returns 0. + * @see ex::diff */ +ex ncmul::derivative(const symbol & s) const +{ + return _ex0(); +} + +int ncmul::compare_same_type(const basic & other) const { - return exprseq::compare_same_type(other); + return inherited::compare_same_type(other); } unsigned ncmul::return_type(void) const @@ -552,7 +619,7 @@ exvector ncmul::expandchildren(unsigned options) const return s; } -exvector const & ncmul::get_factors(void) const +const exvector & ncmul::get_factors(void) const { return seq; } @@ -571,21 +638,21 @@ unsigned ncmul::precedence=50; ////////// const ncmul some_ncmul; -type_info const & typeid_ncmul=typeid(some_ncmul); +const type_info & typeid_ncmul=typeid(some_ncmul); ////////// // friend functions ////////// -ex nonsimplified_ncmul(exvector const & v) +ex nonsimplified_ncmul(const exvector & v) { return (new ncmul(v))->setflag(status_flags::dynallocated); } -ex simplified_ncmul(exvector const & v) +ex simplified_ncmul(const exvector & v) { if (v.size()==0) { - return exONE(); + return _ex1(); } else if (v.size()==1) { return v[0]; } @@ -593,6 +660,6 @@ ex simplified_ncmul(exvector const & v) status_flags::evaluated); } -#ifndef NO_GINAC_NAMESPACE +#ifndef NO_NAMESPACE_GINAC } // namespace GiNaC -#endif // ndef NO_GINAC_NAMESPACE +#endif // ndef NO_NAMESPACE_GINAC