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
14 * GiNaC Copyright (C) 1999 Johannes Gutenberg University Mainz, Germany
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
36 #define RESERVE(s,size) (s).reserve(size)
39 // default constructor, destructor, copy constructor assignment operator and helpers
44 exprseq::exprseq() : basic(TINFO_EXPRSEQ)
46 debugmsg("exprseq default constructor",LOGLEVEL_CONSTRUCT);
51 debugmsg("exprseq destructor",LOGLEVEL_DESTRUCT);
55 exprseq::exprseq(exprseq const & other)
57 debugmsg("exprseq copy constructor",LOGLEVEL_CONSTRUCT);
61 exprseq const & exprseq::operator=(exprseq const & other)
63 debugmsg("exprseq operator=",LOGLEVEL_ASSIGNMENT);
73 void exprseq::copy(exprseq const & other)
79 void exprseq::destroy(bool call_parent)
82 if (call_parent) basic::destroy(call_parent);
91 exprseq::exprseq(exvector const & s, bool discardable) : basic(TINFO_EXPRSEQ)
93 debugmsg("exprseq constructor from exvector",
96 seq.swap(const_cast<exvector &>(s));
102 exprseq::exprseq(exvector * vp) : basic(TINFO_EXPRSEQ)
104 debugmsg("exprseq constructor from exvector *",LOGLEVEL_CONSTRUCT);
110 exprseq::exprseq(ex const & e1) : basic(TINFO_EXPRSEQ)
112 debugmsg("exprseq constructor from 1 ex",
118 exprseq::exprseq(ex const & e1, ex const & e2) : basic(TINFO_EXPRSEQ)
120 debugmsg("exprseq constructor from 2 ex",
127 exprseq::exprseq(ex const & e1, ex const & e2, ex const & e3)
128 : basic(TINFO_EXPRSEQ)
130 debugmsg("exprseq constructor from 3 ex",
138 exprseq::exprseq(ex const & e1, ex const & e2, ex const & e3,
139 ex const & e4) : basic(TINFO_EXPRSEQ)
141 debugmsg("exprseq constructor from 4 ex",
150 exprseq::exprseq(ex const & e1, ex const & e2, ex const & e3,
151 ex const & e4, ex const & e5) : basic(TINFO_EXPRSEQ)
153 debugmsg("exprseq constructor from 5 ex",
163 exprseq::exprseq(ex const & e1, ex const & e2, ex const & e3,
164 ex const & e4, ex const & e5, ex const & e6)
165 : basic(TINFO_EXPRSEQ)
167 debugmsg("exprseq constructor from 6 ex",
178 exprseq::exprseq(ex const & e1, ex const & e2, ex const & e3,
179 ex const & e4, ex const & e5, ex const & e6,
180 ex const & e7) : basic(TINFO_EXPRSEQ)
182 debugmsg("exprseq constructor from 7 ex",
194 exprseq::exprseq(ex const & e1, ex const & e2, ex const & e3,
195 ex const & e4, ex const & e5, ex const & e6,
196 ex const & e7, ex const & e8) : basic(TINFO_EXPRSEQ)
198 debugmsg("exprseq constructor from 8 ex",
211 exprseq::exprseq(ex const & e1, ex const & e2, ex const & e3,
212 ex const & e4, ex const & e5, ex const & e6,
213 ex const & e7, ex const & e8, ex const & e9)
214 : basic(TINFO_EXPRSEQ)
216 debugmsg("exprseq constructor from 9 ex",
230 exprseq::exprseq(ex const & e1, ex const & e2, ex const & e3,
231 ex const & e4, ex const & e5, ex const & e6,
232 ex const & e7, ex const & e8, ex const & e9,
234 : basic(TINFO_EXPRSEQ)
236 debugmsg("exprseq constructor from 10 ex",
252 // functions overriding virtual functions from bases classes
257 basic * exprseq::duplicate() const
259 debugmsg("exprseq duplicate",LOGLEVEL_DUPLICATE);
260 return new exprseq(*this);
263 void exprseq::printraw(ostream & os) const
265 debugmsg("exprseq printraw",LOGLEVEL_PRINT);
268 for (exvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
269 (*cit).bp->printraw(os);
275 void exprseq::print(ostream & os, unsigned upper_precedence) const
277 debugmsg("exprseq print",LOGLEVEL_PRINT);
278 // always print brackets around seq, ignore upper_precedence
279 printseq(os,'(',',',')',precedence,precedence+1);
282 void exprseq::printtree(ostream & os, unsigned indent) const
284 debugmsg("exprseq printtree",LOGLEVEL_PRINT);
286 os << string(indent,' ') << "type=" << typeid(*this).name()
287 << ", hash=" << hashvalue << " (0x" << hex << hashvalue << dec << ")"
288 << ", flags=" << flags
289 << ", nops=" << nops() << endl;
290 for (exvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
291 (*cit).printtree(os,indent+delta_indent);
293 os << string(indent+delta_indent,' ') << "=====" << endl;
296 // exprseq::info() will be implemented by user elsewhere";
298 int exprseq::nops() const
303 // exprseq::let_op() will be implemented by user elsewhere
305 ex exprseq::expand(unsigned options) const
308 RESERVE(s,seq.size());
309 for (exvector::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
310 s.push_back((*it).expand(options));
313 return thisexprseq(s);
316 // a exprseq 'has' an expression if it is this expression itself or a child 'has' it
318 bool exprseq::has(ex const & other) const
321 if (is_equal(*other.bp)) return true;
322 for (exvector::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
323 if ((*it).has(other)) return true;
328 ex exprseq::eval(int level) const
333 return thisexprseq(evalchildren(level));
336 ex exprseq::evalf(int level) const
338 return thisexprseq(evalfchildren(level));
341 /** Implementation of ex::normal() for exprseqs. It normalizes the arguments
342 * and replaces the exprseq by a temporary symbol.
344 ex exprseq::normal(lst &sym_lst, lst &repl_lst, int level) const
346 ex n=thisexprseq(normalchildren(level));
347 return n.bp->basic::normal(sym_lst,repl_lst,level);
350 ex exprseq::diff(symbol const & s) const
352 return thisexprseq(diffchildren(s));
355 ex exprseq::subs(lst const & ls, lst const & lr) const
357 exvector * vp=subschildren(ls,lr);
361 return thisexprseq(vp);
366 int exprseq::compare_same_type(basic const & other) const
368 ASSERT(is_of_type(other,exprseq));
369 exprseq const & o=static_cast<exprseq const &>
370 (const_cast<basic &>(other));
372 exvector::const_iterator it1=seq.begin();
373 exvector::const_iterator it2=o.seq.begin();
375 for (; (it1!=seq.end())&&(it2!=o.seq.end()); ++it1, ++it2) {
376 cmpval=(*it1).compare(*it2);
377 if (cmpval!=0) return cmpval;
380 if (it1==seq.end()) {
381 return (it2==o.seq.end() ? 0 : -1);
387 bool exprseq::is_equal_same_type(basic const & other) const
389 ASSERT(is_of_type(other,exprseq));
390 exprseq const & o=static_cast<exprseq const &>
391 (const_cast<basic &>(other));
392 if (seq.size()!=o.seq.size()) return false;
394 exvector::const_iterator it1=seq.begin();
395 exvector::const_iterator it2=o.seq.begin();
397 for (; it1!=seq.end(); ++it1, ++it2) {
398 if (!(*it1).is_equal(*it2)) return false;
404 unsigned exprseq::return_type(void) const
406 return return_types::noncommutative_composite;
410 // new virtual functions which can be overridden by derived classes
415 exprseq & exprseq::append(ex const & b)
417 ensure_if_modifiable();
426 void exprseq::printseq(ostream & os, char openbracket, char delim,
427 char closebracket, unsigned this_precedence,
428 unsigned upper_precedence) const
430 if (this_precedence<=upper_precedence) os << openbracket;
432 exvector::const_iterator it,it_last;
436 for (; it!=it_last; ++it) {
437 (*it).bp->print(os,this_precedence);
440 (*it).bp->print(os,this_precedence);
442 if (this_precedence<=upper_precedence) os << closebracket;
445 ex exprseq::thisexprseq(exvector const & v) const
450 ex exprseq::thisexprseq(exvector * vp) const
456 // non-virtual functions in this class
465 bool exprseq::is_canonical() const
467 if (seq.size()<=1) { return 1; }
469 exvector::const_iterator it=seq.begin();
470 exvector::const_iterator it_last=it;
471 for (++it; it!=seq.end(); it_last=it, ++it) {
472 if ((*it_last).compare(*it)>0) {
473 if ((*it_last).compare(*it)>0) {
474 cout << *it_last << ">" << *it << "\n";
483 exvector exprseq::evalchildren(int level) const
486 RESERVE(s,seq.size());
491 if (level == -max_recursion_level) {
492 throw(std::runtime_error("max recursion level reached"));
495 for (exvector::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
496 s.push_back((*it).eval(level));
501 exvector exprseq::evalfchildren(int level) const
504 RESERVE(s,seq.size());
509 if (level == -max_recursion_level) {
510 throw(std::runtime_error("max recursion level reached"));
513 for (exvector::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
514 s.push_back((*it).evalf(level));
519 exvector exprseq::normalchildren(int level) const
522 RESERVE(s,seq.size());
527 if (level == -max_recursion_level) {
528 throw(std::runtime_error("max recursion level reached"));
531 for (exvector::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
532 s.push_back((*it).normal(level));
537 exvector exprseq::diffchildren(symbol const & y) const
540 RESERVE(s,seq.size());
541 for (exvector::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
542 s.push_back((*it).diff(y));
547 /* obsolete subschildren
548 exvector exprseq::subschildren(lst const & ls, lst const & lr) const
551 RESERVE(s,seq.size());
552 for (exvector::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
553 s.push_back((*it).subs(ls,lr));
559 exvector * exprseq::subschildren(lst const & ls, lst const & lr) const
561 // returns a NULL pointer if nothing had to be substituted
562 // returns a pointer to a newly created epvector otherwise
563 // (which has to be deleted somewhere else)
565 exvector::const_iterator last=seq.end();
566 exvector::const_iterator cit=seq.begin();
568 ex const & subsed_ex=(*cit).subs(ls,lr);
569 if (!are_ex_trivially_equal(*cit,subsed_ex)) {
571 // something changed, copy seq, subs and return it
572 exvector *s=new exvector;
573 RESERVE(*s,seq.size());
575 // copy parts of seq which are known not to have changed
576 exvector::const_iterator cit2=seq.begin();
581 // copy first changed element
582 s->push_back(subsed_ex);
586 s->push_back((*cit2).subs(ls,lr));
594 return 0; // nothing has changed
598 // static member variables
603 unsigned exprseq::precedence=10;
609 const exprseq some_exprseq;
610 type_info const & typeid_exprseq=typeid(some_exprseq);