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
37 #define RESERVE(s,size) (s).reserve(size)
40 // default constructor, destructor, copy constructor assignment operator and helpers
45 exprseq::exprseq() : basic(TINFO_exprseq)
47 debugmsg("exprseq default constructor",LOGLEVEL_CONSTRUCT);
52 debugmsg("exprseq destructor",LOGLEVEL_DESTRUCT);
56 exprseq::exprseq(exprseq const & other)
58 debugmsg("exprseq copy constructor",LOGLEVEL_CONSTRUCT);
62 exprseq const & exprseq::operator=(exprseq const & other)
64 debugmsg("exprseq operator=",LOGLEVEL_ASSIGNMENT);
74 void exprseq::copy(exprseq const & other)
80 void exprseq::destroy(bool call_parent)
83 if (call_parent) basic::destroy(call_parent);
92 exprseq::exprseq(exvector const & s, bool discardable) : basic(TINFO_exprseq)
94 debugmsg("exprseq constructor from exvector",
97 seq.swap(const_cast<exvector &>(s));
103 exprseq::exprseq(exvector * vp) : basic(TINFO_exprseq)
105 debugmsg("exprseq constructor from exvector *",LOGLEVEL_CONSTRUCT);
111 exprseq::exprseq(ex const & e1) : basic(TINFO_exprseq)
113 debugmsg("exprseq constructor from 1 ex",
119 exprseq::exprseq(ex const & e1, ex const & e2) : basic(TINFO_exprseq)
121 debugmsg("exprseq constructor from 2 ex",
128 exprseq::exprseq(ex const & e1, ex const & e2, ex const & e3)
129 : basic(TINFO_exprseq)
131 debugmsg("exprseq constructor from 3 ex",
139 exprseq::exprseq(ex const & e1, ex const & e2, ex const & e3,
140 ex const & e4) : basic(TINFO_exprseq)
142 debugmsg("exprseq constructor from 4 ex",
151 exprseq::exprseq(ex const & e1, ex const & e2, ex const & e3,
152 ex const & e4, ex const & e5) : basic(TINFO_exprseq)
154 debugmsg("exprseq constructor from 5 ex",
164 exprseq::exprseq(ex const & e1, ex const & e2, ex const & e3,
165 ex const & e4, ex const & e5, ex const & e6)
166 : basic(TINFO_exprseq)
168 debugmsg("exprseq constructor from 6 ex",
179 exprseq::exprseq(ex const & e1, ex const & e2, ex const & e3,
180 ex const & e4, ex const & e5, ex const & e6,
181 ex const & e7) : basic(TINFO_exprseq)
183 debugmsg("exprseq constructor from 7 ex",
195 exprseq::exprseq(ex const & e1, ex const & e2, ex const & e3,
196 ex const & e4, ex const & e5, ex const & e6,
197 ex const & e7, ex const & e8) : basic(TINFO_exprseq)
199 debugmsg("exprseq constructor from 8 ex",
212 exprseq::exprseq(ex const & e1, ex const & e2, ex const & e3,
213 ex const & e4, ex const & e5, ex const & e6,
214 ex const & e7, ex const & e8, ex const & e9)
215 : basic(TINFO_exprseq)
217 debugmsg("exprseq constructor from 9 ex",
231 exprseq::exprseq(ex const & e1, ex const & e2, ex const & e3,
232 ex const & e4, ex const & e5, ex const & e6,
233 ex const & e7, ex const & e8, ex const & e9,
235 : basic(TINFO_exprseq)
237 debugmsg("exprseq constructor from 10 ex",
253 // functions overriding virtual functions from bases classes
258 basic * exprseq::duplicate() const
260 debugmsg("exprseq duplicate",LOGLEVEL_DUPLICATE);
261 return new exprseq(*this);
264 void exprseq::printraw(ostream & os) const
266 debugmsg("exprseq printraw",LOGLEVEL_PRINT);
269 for (exvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
270 (*cit).bp->printraw(os);
276 void exprseq::print(ostream & os, unsigned upper_precedence) const
278 debugmsg("exprseq print",LOGLEVEL_PRINT);
279 // always print brackets around seq, ignore upper_precedence
280 printseq(os,'(',',',')',precedence,precedence+1);
283 void exprseq::printtree(ostream & os, unsigned indent) const
285 debugmsg("exprseq printtree",LOGLEVEL_PRINT);
287 os << string(indent,' ') << "type=" << typeid(*this).name()
288 << ", hash=" << hashvalue << " (0x" << hex << hashvalue << dec << ")"
289 << ", flags=" << flags
290 << ", nops=" << nops() << endl;
291 for (exvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
292 (*cit).printtree(os,indent+delta_indent);
294 os << string(indent+delta_indent,' ') << "=====" << endl;
297 // exprseq::info() will be implemented by user elsewhere";
299 int exprseq::nops() const
304 // exprseq::let_op() will be implemented by user elsewhere
306 ex exprseq::expand(unsigned options) const
309 RESERVE(s,seq.size());
310 for (exvector::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
311 s.push_back((*it).expand(options));
314 return thisexprseq(s);
317 // a exprseq 'has' an expression if it is this expression itself or a child 'has' it
319 bool exprseq::has(ex const & other) const
322 if (is_equal(*other.bp)) return true;
323 for (exvector::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
324 if ((*it).has(other)) return true;
329 ex exprseq::eval(int level) const
334 return thisexprseq(evalchildren(level));
337 ex exprseq::evalf(int level) const
339 return thisexprseq(evalfchildren(level));
342 /** Implementation of ex::normal() for exprseqs. It normalizes the arguments
343 * and replaces the exprseq by a temporary symbol.
345 ex exprseq::normal(lst &sym_lst, lst &repl_lst, int level) const
347 ex n=thisexprseq(normalchildren(level));
348 return n.bp->basic::normal(sym_lst,repl_lst,level);
351 ex exprseq::diff(symbol const & s) const
353 return thisexprseq(diffchildren(s));
356 ex exprseq::subs(lst const & ls, lst const & lr) const
358 exvector * vp=subschildren(ls,lr);
362 return thisexprseq(vp);
367 int exprseq::compare_same_type(basic const & other) const
369 ASSERT(is_of_type(other,exprseq));
370 exprseq const & o=static_cast<exprseq const &>
371 (const_cast<basic &>(other));
373 exvector::const_iterator it1=seq.begin();
374 exvector::const_iterator it2=o.seq.begin();
376 for (; (it1!=seq.end())&&(it2!=o.seq.end()); ++it1, ++it2) {
377 cmpval=(*it1).compare(*it2);
378 if (cmpval!=0) return cmpval;
381 if (it1==seq.end()) {
382 return (it2==o.seq.end() ? 0 : -1);
388 bool exprseq::is_equal_same_type(basic const & other) const
390 ASSERT(is_of_type(other,exprseq));
391 exprseq const & o=static_cast<exprseq const &>
392 (const_cast<basic &>(other));
393 if (seq.size()!=o.seq.size()) return false;
395 exvector::const_iterator it1=seq.begin();
396 exvector::const_iterator it2=o.seq.begin();
398 for (; it1!=seq.end(); ++it1, ++it2) {
399 if (!(*it1).is_equal(*it2)) return false;
405 unsigned exprseq::return_type(void) const
407 return return_types::noncommutative_composite;
411 // new virtual functions which can be overridden by derived classes
416 exprseq & exprseq::append(ex const & b)
418 ensure_if_modifiable();
427 void exprseq::printseq(ostream & os, char openbracket, char delim,
428 char closebracket, unsigned this_precedence,
429 unsigned upper_precedence) const
431 if (this_precedence<=upper_precedence) os << openbracket;
433 exvector::const_iterator it,it_last;
437 for (; it!=it_last; ++it) {
438 (*it).bp->print(os,this_precedence);
441 (*it).bp->print(os,this_precedence);
443 if (this_precedence<=upper_precedence) os << closebracket;
446 ex exprseq::thisexprseq(exvector const & v) const
451 ex exprseq::thisexprseq(exvector * vp) const
457 // non-virtual functions in this class
466 bool exprseq::is_canonical() const
468 if (seq.size()<=1) { return 1; }
470 exvector::const_iterator it=seq.begin();
471 exvector::const_iterator it_last=it;
472 for (++it; it!=seq.end(); it_last=it, ++it) {
473 if ((*it_last).compare(*it)>0) {
474 if ((*it_last).compare(*it)>0) {
475 cout << *it_last << ">" << *it << "\n";
484 exvector exprseq::evalchildren(int level) const
487 RESERVE(s,seq.size());
492 if (level == -max_recursion_level) {
493 throw(std::runtime_error("max recursion level reached"));
496 for (exvector::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
497 s.push_back((*it).eval(level));
502 exvector exprseq::evalfchildren(int level) const
505 RESERVE(s,seq.size());
510 if (level == -max_recursion_level) {
511 throw(std::runtime_error("max recursion level reached"));
514 for (exvector::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
515 s.push_back((*it).evalf(level));
520 exvector exprseq::normalchildren(int level) const
523 RESERVE(s,seq.size());
528 if (level == -max_recursion_level) {
529 throw(std::runtime_error("max recursion level reached"));
532 for (exvector::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
533 s.push_back((*it).normal(level));
538 exvector exprseq::diffchildren(symbol const & y) const
541 RESERVE(s,seq.size());
542 for (exvector::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
543 s.push_back((*it).diff(y));
548 /* obsolete subschildren
549 exvector exprseq::subschildren(lst const & ls, lst const & lr) const
552 RESERVE(s,seq.size());
553 for (exvector::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
554 s.push_back((*it).subs(ls,lr));
560 exvector * exprseq::subschildren(lst const & ls, lst const & lr) const
562 // returns a NULL pointer if nothing had to be substituted
563 // returns a pointer to a newly created epvector otherwise
564 // (which has to be deleted somewhere else)
566 exvector::const_iterator last=seq.end();
567 exvector::const_iterator cit=seq.begin();
569 ex const & subsed_ex=(*cit).subs(ls,lr);
570 if (!are_ex_trivially_equal(*cit,subsed_ex)) {
572 // something changed, copy seq, subs and return it
573 exvector *s=new exvector;
574 RESERVE(*s,seq.size());
576 // copy parts of seq which are known not to have changed
577 exvector::const_iterator cit2=seq.begin();
582 // copy first changed element
583 s->push_back(subsed_ex);
587 s->push_back((*cit2).subs(ls,lr));
595 return 0; // nothing has changed
599 // static member variables
604 unsigned exprseq::precedence=10;
610 const exprseq some_exprseq;
611 type_info const & typeid_exprseq=typeid(some_exprseq);