3 * Implementation of GiNaC's exprseq.
4 * This file was generated automatically by container.pl.
5 * Please do not modify it directly, edit the perl script instead!
6 * container.pl options: $CONTAINER=exprseq
15 * GiNaC Copyright (C) 1999 Johannes Gutenberg University Mainz, Germany
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
38 #define RESERVE(s,size) (s).reserve(size)
41 // default constructor, destructor, copy constructor assignment operator and helpers
46 exprseq::exprseq() : basic(TINFO_exprseq)
48 debugmsg("exprseq default constructor",LOGLEVEL_CONSTRUCT);
53 debugmsg("exprseq destructor",LOGLEVEL_DESTRUCT);
57 exprseq::exprseq(exprseq const & other)
59 debugmsg("exprseq copy constructor",LOGLEVEL_CONSTRUCT);
63 exprseq const & exprseq::operator=(exprseq const & other)
65 debugmsg("exprseq operator=",LOGLEVEL_ASSIGNMENT);
75 void exprseq::copy(exprseq const & other)
81 void exprseq::destroy(bool call_parent)
84 if (call_parent) basic::destroy(call_parent);
93 exprseq::exprseq(exvector const & s, bool discardable) : basic(TINFO_exprseq)
95 debugmsg("exprseq constructor from exvector",
98 seq.swap(const_cast<exvector &>(s));
104 exprseq::exprseq(exvector * vp) : basic(TINFO_exprseq)
106 debugmsg("exprseq constructor from exvector *",LOGLEVEL_CONSTRUCT);
112 exprseq::exprseq(ex const & e1) : basic(TINFO_exprseq)
114 debugmsg("exprseq constructor from 1 ex",
120 exprseq::exprseq(ex const & e1, ex const & e2) : basic(TINFO_exprseq)
122 debugmsg("exprseq constructor from 2 ex",
129 exprseq::exprseq(ex const & e1, ex const & e2, ex const & e3)
130 : basic(TINFO_exprseq)
132 debugmsg("exprseq constructor from 3 ex",
140 exprseq::exprseq(ex const & e1, ex const & e2, ex const & e3,
141 ex const & e4) : basic(TINFO_exprseq)
143 debugmsg("exprseq constructor from 4 ex",
152 exprseq::exprseq(ex const & e1, ex const & e2, ex const & e3,
153 ex const & e4, ex const & e5) : basic(TINFO_exprseq)
155 debugmsg("exprseq constructor from 5 ex",
165 exprseq::exprseq(ex const & e1, ex const & e2, ex const & e3,
166 ex const & e4, ex const & e5, ex const & e6)
167 : basic(TINFO_exprseq)
169 debugmsg("exprseq constructor from 6 ex",
180 exprseq::exprseq(ex const & e1, ex const & e2, ex const & e3,
181 ex const & e4, ex const & e5, ex const & e6,
182 ex const & e7) : basic(TINFO_exprseq)
184 debugmsg("exprseq constructor from 7 ex",
196 exprseq::exprseq(ex const & e1, ex const & e2, ex const & e3,
197 ex const & e4, ex const & e5, ex const & e6,
198 ex const & e7, ex const & e8) : basic(TINFO_exprseq)
200 debugmsg("exprseq constructor from 8 ex",
213 exprseq::exprseq(ex const & e1, ex const & e2, ex const & e3,
214 ex const & e4, ex const & e5, ex const & e6,
215 ex const & e7, ex const & e8, ex const & e9)
216 : basic(TINFO_exprseq)
218 debugmsg("exprseq constructor from 9 ex",
232 exprseq::exprseq(ex const & e1, ex const & e2, ex const & e3,
233 ex const & e4, ex const & e5, ex const & e6,
234 ex const & e7, ex const & e8, ex const & e9,
236 : basic(TINFO_exprseq)
238 debugmsg("exprseq constructor from 10 ex",
254 // functions overriding virtual functions from bases classes
259 basic * exprseq::duplicate() const
261 debugmsg("exprseq duplicate",LOGLEVEL_DUPLICATE);
262 return new exprseq(*this);
265 void exprseq::printraw(ostream & os) const
267 debugmsg("exprseq printraw",LOGLEVEL_PRINT);
270 for (exvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
271 (*cit).bp->printraw(os);
277 void exprseq::print(ostream & os, unsigned upper_precedence) const
279 debugmsg("exprseq print",LOGLEVEL_PRINT);
280 // always print brackets around seq, ignore upper_precedence
281 printseq(os,'(',',',')',precedence,precedence+1);
284 void exprseq::printtree(ostream & os, unsigned indent) const
286 debugmsg("exprseq printtree",LOGLEVEL_PRINT);
288 os << string(indent,' ') << "type=" << typeid(*this).name()
289 << ", hash=" << hashvalue << " (0x" << hex << hashvalue << dec << ")"
290 << ", flags=" << flags
291 << ", nops=" << nops() << endl;
292 for (exvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
293 (*cit).printtree(os,indent+delta_indent);
295 os << string(indent+delta_indent,' ') << "=====" << endl;
298 // exprseq::info() will be implemented by user elsewhere";
300 int exprseq::nops() const
305 // exprseq::let_op() will be implemented by user elsewhere
307 ex exprseq::expand(unsigned options) const
310 RESERVE(s,seq.size());
311 for (exvector::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
312 s.push_back((*it).expand(options));
315 return thisexprseq(s);
318 // a exprseq 'has' an expression if it is this expression itself or a child 'has' it
320 bool exprseq::has(ex const & other) const
323 if (is_equal(*other.bp)) return true;
324 for (exvector::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
325 if ((*it).has(other)) return true;
330 ex exprseq::eval(int level) const
335 return thisexprseq(evalchildren(level));
338 ex exprseq::evalf(int level) const
340 return thisexprseq(evalfchildren(level));
343 /** Implementation of ex::normal() for exprseqs. It normalizes the arguments
344 * and replaces the exprseq by a temporary symbol.
346 ex exprseq::normal(lst &sym_lst, lst &repl_lst, int level) const
348 ex n=thisexprseq(normalchildren(level));
349 return n.bp->basic::normal(sym_lst,repl_lst,level);
352 ex exprseq::diff(symbol const & s) const
354 return thisexprseq(diffchildren(s));
357 ex exprseq::subs(lst const & ls, lst const & lr) const
359 exvector * vp=subschildren(ls,lr);
363 return thisexprseq(vp);
368 int exprseq::compare_same_type(basic const & other) const
370 ASSERT(is_of_type(other,exprseq));
371 exprseq const & o=static_cast<exprseq const &>
372 (const_cast<basic &>(other));
374 exvector::const_iterator it1=seq.begin();
375 exvector::const_iterator it2=o.seq.begin();
377 for (; (it1!=seq.end())&&(it2!=o.seq.end()); ++it1, ++it2) {
378 cmpval=(*it1).compare(*it2);
379 if (cmpval!=0) return cmpval;
382 if (it1==seq.end()) {
383 return (it2==o.seq.end() ? 0 : -1);
389 bool exprseq::is_equal_same_type(basic const & other) const
391 ASSERT(is_of_type(other,exprseq));
392 exprseq const & o=static_cast<exprseq const &>
393 (const_cast<basic &>(other));
394 if (seq.size()!=o.seq.size()) return false;
396 exvector::const_iterator it1=seq.begin();
397 exvector::const_iterator it2=o.seq.begin();
399 for (; it1!=seq.end(); ++it1, ++it2) {
400 if (!(*it1).is_equal(*it2)) return false;
406 unsigned exprseq::return_type(void) const
408 return return_types::noncommutative_composite;
412 // new virtual functions which can be overridden by derived classes
417 exprseq & exprseq::append(ex const & b)
419 ensure_if_modifiable();
428 void exprseq::printseq(ostream & os, char openbracket, char delim,
429 char closebracket, unsigned this_precedence,
430 unsigned upper_precedence) const
432 if (this_precedence<=upper_precedence) os << openbracket;
434 exvector::const_iterator it,it_last;
438 for (; it!=it_last; ++it) {
439 (*it).bp->print(os,this_precedence);
442 (*it).bp->print(os,this_precedence);
444 if (this_precedence<=upper_precedence) os << closebracket;
447 ex exprseq::thisexprseq(exvector const & v) const
452 ex exprseq::thisexprseq(exvector * vp) const
458 // non-virtual functions in this class
467 bool exprseq::is_canonical() const
469 if (seq.size()<=1) { return 1; }
471 exvector::const_iterator it=seq.begin();
472 exvector::const_iterator it_last=it;
473 for (++it; it!=seq.end(); it_last=it, ++it) {
474 if ((*it_last).compare(*it)>0) {
475 if ((*it_last).compare(*it)>0) {
476 cout << *it_last << ">" << *it << "\n";
485 exvector exprseq::evalchildren(int level) const
488 RESERVE(s,seq.size());
493 if (level == -max_recursion_level) {
494 throw(std::runtime_error("max recursion level reached"));
497 for (exvector::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
498 s.push_back((*it).eval(level));
503 exvector exprseq::evalfchildren(int level) const
506 RESERVE(s,seq.size());
511 if (level == -max_recursion_level) {
512 throw(std::runtime_error("max recursion level reached"));
515 for (exvector::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
516 s.push_back((*it).evalf(level));
521 exvector exprseq::normalchildren(int level) const
524 RESERVE(s,seq.size());
529 if (level == -max_recursion_level) {
530 throw(std::runtime_error("max recursion level reached"));
533 for (exvector::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
534 s.push_back((*it).normal(level));
539 exvector exprseq::diffchildren(symbol const & y) const
542 RESERVE(s,seq.size());
543 for (exvector::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
544 s.push_back((*it).diff(y));
549 /* obsolete subschildren
550 exvector exprseq::subschildren(lst const & ls, lst const & lr) const
553 RESERVE(s,seq.size());
554 for (exvector::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
555 s.push_back((*it).subs(ls,lr));
561 exvector * exprseq::subschildren(lst const & ls, lst const & lr) const
563 // returns a NULL pointer if nothing had to be substituted
564 // returns a pointer to a newly created epvector otherwise
565 // (which has to be deleted somewhere else)
567 exvector::const_iterator last=seq.end();
568 exvector::const_iterator cit=seq.begin();
570 ex const & subsed_ex=(*cit).subs(ls,lr);
571 if (!are_ex_trivially_equal(*cit,subsed_ex)) {
573 // something changed, copy seq, subs and return it
574 exvector *s=new exvector;
575 RESERVE(*s,seq.size());
577 // copy parts of seq which are known not to have changed
578 exvector::const_iterator cit2=seq.begin();
583 // copy first changed element
584 s->push_back(subsed_ex);
588 s->push_back((*cit2).subs(ls,lr));
596 return 0; // nothing has changed
600 // static member variables
605 unsigned exprseq::precedence=10;
611 const exprseq some_exprseq;
612 type_info const & typeid_exprseq=typeid(some_exprseq);