3 * Implementation of GiNaC's exprseq. */
6 * This file was generated automatically by container.pl.
7 * Please do not modify it directly, edit the perl script instead!
8 * container.pl options: $CONTAINER=exprseq
16 * GiNaC Copyright (C) 1999 Johannes Gutenberg University Mainz, Germany
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
42 #define RESERVE(s,size) (s).reserve(size)
45 // default constructor, destructor, copy constructor assignment operator and helpers
50 exprseq::exprseq() : basic(TINFO_exprseq)
52 debugmsg("exprseq default constructor",LOGLEVEL_CONSTRUCT);
57 debugmsg("exprseq destructor",LOGLEVEL_DESTRUCT);
61 exprseq::exprseq(exprseq const & other)
63 debugmsg("exprseq copy constructor",LOGLEVEL_CONSTRUCT);
67 exprseq const & exprseq::operator=(exprseq const & other)
69 debugmsg("exprseq operator=",LOGLEVEL_ASSIGNMENT);
79 void exprseq::copy(exprseq const & other)
85 void exprseq::destroy(bool call_parent)
88 if (call_parent) basic::destroy(call_parent);
97 exprseq::exprseq(exvector const & s, bool discardable) : basic(TINFO_exprseq)
99 debugmsg("exprseq constructor from exvector",
102 seq.swap(const_cast<exvector &>(s));
108 exprseq::exprseq(exvector * vp) : basic(TINFO_exprseq)
110 debugmsg("exprseq constructor from exvector *",LOGLEVEL_CONSTRUCT);
116 exprseq::exprseq(ex const & e1) : basic(TINFO_exprseq)
118 debugmsg("exprseq constructor from 1 ex",
124 exprseq::exprseq(ex const & e1, ex const & e2) : basic(TINFO_exprseq)
126 debugmsg("exprseq constructor from 2 ex",
133 exprseq::exprseq(ex const & e1, ex const & e2, ex const & e3)
134 : basic(TINFO_exprseq)
136 debugmsg("exprseq constructor from 3 ex",
144 exprseq::exprseq(ex const & e1, ex const & e2, ex const & e3,
145 ex const & e4) : basic(TINFO_exprseq)
147 debugmsg("exprseq constructor from 4 ex",
156 exprseq::exprseq(ex const & e1, ex const & e2, ex const & e3,
157 ex const & e4, ex const & e5) : basic(TINFO_exprseq)
159 debugmsg("exprseq constructor from 5 ex",
169 exprseq::exprseq(ex const & e1, ex const & e2, ex const & e3,
170 ex const & e4, ex const & e5, ex const & e6)
171 : basic(TINFO_exprseq)
173 debugmsg("exprseq constructor from 6 ex",
184 exprseq::exprseq(ex const & e1, ex const & e2, ex const & e3,
185 ex const & e4, ex const & e5, ex const & e6,
186 ex const & e7) : basic(TINFO_exprseq)
188 debugmsg("exprseq constructor from 7 ex",
200 exprseq::exprseq(ex const & e1, ex const & e2, ex const & e3,
201 ex const & e4, ex const & e5, ex const & e6,
202 ex const & e7, ex const & e8) : basic(TINFO_exprseq)
204 debugmsg("exprseq constructor from 8 ex",
217 exprseq::exprseq(ex const & e1, ex const & e2, ex const & e3,
218 ex const & e4, ex const & e5, ex const & e6,
219 ex const & e7, ex const & e8, ex const & e9)
220 : basic(TINFO_exprseq)
222 debugmsg("exprseq constructor from 9 ex",
236 exprseq::exprseq(ex const & e1, ex const & e2, ex const & e3,
237 ex const & e4, ex const & e5, ex const & e6,
238 ex const & e7, ex const & e8, ex const & e9,
240 : basic(TINFO_exprseq)
242 debugmsg("exprseq constructor from 10 ex",
258 // functions overriding virtual functions from bases classes
263 basic * exprseq::duplicate() const
265 debugmsg("exprseq duplicate",LOGLEVEL_DUPLICATE);
266 return new exprseq(*this);
269 void exprseq::printraw(ostream & os) const
271 debugmsg("exprseq printraw",LOGLEVEL_PRINT);
274 for (exvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
275 (*cit).bp->printraw(os);
281 void exprseq::print(ostream & os, unsigned upper_precedence) const
283 debugmsg("exprseq print",LOGLEVEL_PRINT);
284 // always print brackets around seq, ignore upper_precedence
285 printseq(os,'(',',',')',precedence,precedence+1);
288 void exprseq::printtree(ostream & os, unsigned indent) const
290 debugmsg("exprseq printtree",LOGLEVEL_PRINT);
292 os << string(indent,' ') << "type=" << typeid(*this).name()
293 << ", hash=" << hashvalue << " (0x" << hex << hashvalue << dec << ")"
294 << ", flags=" << flags
295 << ", nops=" << nops() << endl;
296 for (exvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
297 (*cit).printtree(os,indent+delta_indent);
299 os << string(indent+delta_indent,' ') << "=====" << endl;
302 // exprseq::info() will be implemented by user elsewhere";
304 int exprseq::nops() const
309 // exprseq::let_op() will be implemented by user elsewhere
311 ex exprseq::expand(unsigned options) const
314 RESERVE(s,seq.size());
315 for (exvector::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
316 s.push_back((*it).expand(options));
319 return thisexprseq(s);
322 // a exprseq 'has' an expression if it is this expression itself or a child 'has' it
324 bool exprseq::has(ex const & other) const
327 if (is_equal(*other.bp)) return true;
328 for (exvector::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
329 if ((*it).has(other)) return true;
334 ex exprseq::eval(int level) const
339 return thisexprseq(evalchildren(level));
342 ex exprseq::evalf(int level) const
344 return thisexprseq(evalfchildren(level));
347 /** Implementation of ex::normal() for exprseqs. It normalizes the arguments
348 * and replaces the exprseq by a temporary symbol.
350 ex exprseq::normal(lst &sym_lst, lst &repl_lst, int level) const
352 ex n=thisexprseq(normalchildren(level));
353 return n.bp->basic::normal(sym_lst,repl_lst,level);
356 ex exprseq::diff(symbol const & s) const
358 return thisexprseq(diffchildren(s));
361 ex exprseq::subs(lst const & ls, lst const & lr) const
363 exvector * vp=subschildren(ls,lr);
367 return thisexprseq(vp);
372 int exprseq::compare_same_type(basic const & other) const
374 ASSERT(is_of_type(other,exprseq));
375 exprseq const & o=static_cast<exprseq const &>
376 (const_cast<basic &>(other));
378 exvector::const_iterator it1=seq.begin();
379 exvector::const_iterator it2=o.seq.begin();
381 for (; (it1!=seq.end())&&(it2!=o.seq.end()); ++it1, ++it2) {
382 cmpval=(*it1).compare(*it2);
383 if (cmpval!=0) return cmpval;
386 if (it1==seq.end()) {
387 return (it2==o.seq.end() ? 0 : -1);
393 bool exprseq::is_equal_same_type(basic const & other) const
395 ASSERT(is_of_type(other,exprseq));
396 exprseq const & o=static_cast<exprseq const &>
397 (const_cast<basic &>(other));
398 if (seq.size()!=o.seq.size()) return false;
400 exvector::const_iterator it1=seq.begin();
401 exvector::const_iterator it2=o.seq.begin();
403 for (; it1!=seq.end(); ++it1, ++it2) {
404 if (!(*it1).is_equal(*it2)) return false;
410 unsigned exprseq::return_type(void) const
412 return return_types::noncommutative_composite;
416 // new virtual functions which can be overridden by derived classes
421 exprseq & exprseq::append(ex const & b)
423 ensure_if_modifiable();
432 void exprseq::printseq(ostream & os, char openbracket, char delim,
433 char closebracket, unsigned this_precedence,
434 unsigned upper_precedence) const
436 if (this_precedence<=upper_precedence) os << openbracket;
438 exvector::const_iterator it,it_last;
442 for (; it!=it_last; ++it) {
443 (*it).bp->print(os,this_precedence);
446 (*it).bp->print(os,this_precedence);
448 if (this_precedence<=upper_precedence) os << closebracket;
451 ex exprseq::thisexprseq(exvector const & v) const
456 ex exprseq::thisexprseq(exvector * vp) const
462 // non-virtual functions in this class
471 bool exprseq::is_canonical() const
473 if (seq.size()<=1) { return 1; }
475 exvector::const_iterator it=seq.begin();
476 exvector::const_iterator it_last=it;
477 for (++it; it!=seq.end(); it_last=it, ++it) {
478 if ((*it_last).compare(*it)>0) {
479 if ((*it_last).compare(*it)>0) {
480 cout << *it_last << ">" << *it << "\n";
489 exvector exprseq::evalchildren(int level) const
492 RESERVE(s,seq.size());
497 if (level == -max_recursion_level) {
498 throw(std::runtime_error("max recursion level reached"));
501 for (exvector::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
502 s.push_back((*it).eval(level));
507 exvector exprseq::evalfchildren(int level) const
510 RESERVE(s,seq.size());
515 if (level == -max_recursion_level) {
516 throw(std::runtime_error("max recursion level reached"));
519 for (exvector::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
520 s.push_back((*it).evalf(level));
525 exvector exprseq::normalchildren(int level) const
528 RESERVE(s,seq.size());
533 if (level == -max_recursion_level) {
534 throw(std::runtime_error("max recursion level reached"));
537 for (exvector::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
538 s.push_back((*it).normal(level));
543 exvector exprseq::diffchildren(symbol const & y) const
546 RESERVE(s,seq.size());
547 for (exvector::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
548 s.push_back((*it).diff(y));
553 /* obsolete subschildren
554 exvector exprseq::subschildren(lst const & ls, lst const & lr) const
557 RESERVE(s,seq.size());
558 for (exvector::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
559 s.push_back((*it).subs(ls,lr));
565 exvector * exprseq::subschildren(lst const & ls, lst const & lr) const
567 // returns a NULL pointer if nothing had to be substituted
568 // returns a pointer to a newly created epvector otherwise
569 // (which has to be deleted somewhere else)
571 exvector::const_iterator last=seq.end();
572 exvector::const_iterator cit=seq.begin();
574 ex const & subsed_ex=(*cit).subs(ls,lr);
575 if (!are_ex_trivially_equal(*cit,subsed_ex)) {
577 // something changed, copy seq, subs and return it
578 exvector *s=new exvector;
579 RESERVE(*s,seq.size());
581 // copy parts of seq which are known not to have changed
582 exvector::const_iterator cit2=seq.begin();
587 // copy first changed element
588 s->push_back(subsed_ex);
592 s->push_back((*cit2).subs(ls,lr));
600 return 0; // nothing has changed
604 // static member variables
609 unsigned exprseq::precedence=10;
615 const exprseq some_exprseq;
616 type_info const & typeid_exprseq=typeid(some_exprseq);