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
19 #define RESERVE(s,size) (s).reserve(size)
22 // default constructor, destructor, copy constructor assignment operator and helpers
27 exprseq::exprseq() : basic(TINFO_EXPRSEQ)
29 debugmsg("exprseq default constructor",LOGLEVEL_CONSTRUCT);
34 debugmsg("exprseq destructor",LOGLEVEL_DESTRUCT);
38 exprseq::exprseq(exprseq const & other)
40 debugmsg("exprseq copy constructor",LOGLEVEL_CONSTRUCT);
44 exprseq const & exprseq::operator=(exprseq const & other)
46 debugmsg("exprseq operator=",LOGLEVEL_ASSIGNMENT);
56 void exprseq::copy(exprseq const & other)
62 void exprseq::destroy(bool call_parent)
65 if (call_parent) basic::destroy(call_parent);
74 exprseq::exprseq(exvector const & s, bool discardable) : basic(TINFO_EXPRSEQ)
76 debugmsg("exprseq constructor from exvector",
79 seq.swap(const_cast<exvector &>(s));
85 exprseq::exprseq(exvector * vp) : basic(TINFO_EXPRSEQ)
87 debugmsg("exprseq constructor from exvector *",LOGLEVEL_CONSTRUCT);
93 exprseq::exprseq(ex const & e1) : basic(TINFO_EXPRSEQ)
95 debugmsg("exprseq constructor from 1 ex",
101 exprseq::exprseq(ex const & e1, ex const & e2) : basic(TINFO_EXPRSEQ)
103 debugmsg("exprseq constructor from 2 ex",
110 exprseq::exprseq(ex const & e1, ex const & e2, ex const & e3)
111 : basic(TINFO_EXPRSEQ)
113 debugmsg("exprseq constructor from 3 ex",
121 exprseq::exprseq(ex const & e1, ex const & e2, ex const & e3,
122 ex const & e4) : basic(TINFO_EXPRSEQ)
124 debugmsg("exprseq constructor from 4 ex",
133 exprseq::exprseq(ex const & e1, ex const & e2, ex const & e3,
134 ex const & e4, ex const & e5) : basic(TINFO_EXPRSEQ)
136 debugmsg("exprseq constructor from 5 ex",
146 exprseq::exprseq(ex const & e1, ex const & e2, ex const & e3,
147 ex const & e4, ex const & e5, ex const & e6)
148 : basic(TINFO_EXPRSEQ)
150 debugmsg("exprseq constructor from 6 ex",
161 exprseq::exprseq(ex const & e1, ex const & e2, ex const & e3,
162 ex const & e4, ex const & e5, ex const & e6,
163 ex const & e7) : basic(TINFO_EXPRSEQ)
165 debugmsg("exprseq constructor from 7 ex",
177 exprseq::exprseq(ex const & e1, ex const & e2, ex const & e3,
178 ex const & e4, ex const & e5, ex const & e6,
179 ex const & e7, ex const & e8) : basic(TINFO_EXPRSEQ)
181 debugmsg("exprseq constructor from 8 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, ex const & e9)
197 : basic(TINFO_EXPRSEQ)
199 debugmsg("exprseq constructor from 9 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,
217 : basic(TINFO_EXPRSEQ)
219 debugmsg("exprseq constructor from 10 ex",
235 // functions overriding virtual functions from bases classes
240 basic * exprseq::duplicate() const
242 debugmsg("exprseq duplicate",LOGLEVEL_DUPLICATE);
243 return new exprseq(*this);
246 void exprseq::printraw(ostream & os) const
248 debugmsg("exprseq printraw",LOGLEVEL_PRINT);
251 for (exvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
252 (*cit).bp->printraw(os);
258 void exprseq::print(ostream & os, unsigned upper_precedence) const
260 debugmsg("exprseq print",LOGLEVEL_PRINT);
261 // always print brackets around seq, ignore upper_precedence
262 printseq(os,'(',',',')',precedence,precedence+1);
265 void exprseq::printtree(ostream & os, unsigned indent) const
267 debugmsg("exprseq printtree",LOGLEVEL_PRINT);
269 os << string(indent,' ') << "type=" << typeid(*this).name()
270 << ", hash=" << hashvalue << " (0x" << hex << hashvalue << dec << ")"
271 << ", flags=" << flags
272 << ", nops=" << nops() << endl;
273 for (exvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
274 (*cit).printtree(os,indent+delta_indent);
276 os << string(indent+delta_indent,' ') << "=====" << endl;
279 // exprseq::info() will be implemented by user elsewhere";
281 int exprseq::nops() const
286 // exprseq::let_op() will be implemented by user elsewhere
288 ex exprseq::expand(unsigned options) const
291 RESERVE(s,seq.size());
292 for (exvector::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
293 s.push_back((*it).expand(options));
296 return thisexprseq(s);
299 // a exprseq 'has' an expression if it is this expression itself or a child 'has' it
301 bool exprseq::has(ex const & other) const
304 if (is_equal(*other.bp)) return true;
305 for (exvector::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
306 if ((*it).has(other)) return true;
311 ex exprseq::eval(int level) const
316 return thisexprseq(evalchildren(level));
319 ex exprseq::evalf(int level) const
321 return thisexprseq(evalfchildren(level));
324 /** Implementation of ex::normal() for exprseqs. It normalizes the arguments
325 * and replaces the exprseq by a temporary symbol.
327 ex exprseq::normal(lst &sym_lst, lst &repl_lst, int level) const
329 ex n=thisexprseq(normalchildren(level));
330 return n.bp->basic::normal(sym_lst,repl_lst,level);
333 ex exprseq::diff(symbol const & s) const
335 return thisexprseq(diffchildren(s));
338 ex exprseq::subs(lst const & ls, lst const & lr) const
340 exvector * vp=subschildren(ls,lr);
344 return thisexprseq(vp);
349 int exprseq::compare_same_type(basic const & other) const
351 ASSERT(is_of_type(other,exprseq));
352 exprseq const & o=static_cast<exprseq const &>
353 (const_cast<basic &>(other));
355 exvector::const_iterator it1=seq.begin();
356 exvector::const_iterator it2=o.seq.begin();
358 for (; (it1!=seq.end())&&(it2!=o.seq.end()); ++it1, ++it2) {
359 cmpval=(*it1).compare(*it2);
360 if (cmpval!=0) return cmpval;
363 if (it1==seq.end()) {
364 return (it2==o.seq.end() ? 0 : -1);
370 bool exprseq::is_equal_same_type(basic const & other) const
372 ASSERT(is_of_type(other,exprseq));
373 exprseq const & o=static_cast<exprseq const &>
374 (const_cast<basic &>(other));
375 if (seq.size()!=o.seq.size()) return false;
377 exvector::const_iterator it1=seq.begin();
378 exvector::const_iterator it2=o.seq.begin();
380 for (; it1!=seq.end(); ++it1, ++it2) {
381 if (!(*it1).is_equal(*it2)) return false;
387 unsigned exprseq::return_type(void) const
389 return return_types::noncommutative_composite;
393 // new virtual functions which can be overridden by derived classes
398 exprseq & exprseq::append(ex const & b)
400 ensure_if_modifiable();
409 void exprseq::printseq(ostream & os, char openbracket, char delim,
410 char closebracket, unsigned this_precedence,
411 unsigned upper_precedence) const
413 if (this_precedence<=upper_precedence) os << openbracket;
415 exvector::const_iterator it,it_last;
419 for (; it!=it_last; ++it) {
420 (*it).bp->print(os,this_precedence);
423 (*it).bp->print(os,this_precedence);
425 if (this_precedence<=upper_precedence) os << closebracket;
428 ex exprseq::thisexprseq(exvector const & v) const
433 ex exprseq::thisexprseq(exvector * vp) const
439 // non-virtual functions in this class
448 bool exprseq::is_canonical() const
450 if (seq.size()<=1) { return 1; }
452 exvector::const_iterator it=seq.begin();
453 exvector::const_iterator it_last=it;
454 for (++it; it!=seq.end(); it_last=it, ++it) {
455 if ((*it_last).compare(*it)>0) {
456 if ((*it_last).compare(*it)>0) {
457 cout << *it_last << ">" << *it << "\n";
466 exvector exprseq::evalchildren(int level) const
469 RESERVE(s,seq.size());
474 if (level == -max_recursion_level) {
475 throw(std::runtime_error("max recursion level reached"));
478 for (exvector::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
479 s.push_back((*it).eval(level));
484 exvector exprseq::evalfchildren(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).evalf(level));
502 exvector exprseq::normalchildren(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).normal(level));
520 exvector exprseq::diffchildren(symbol const & y) const
523 RESERVE(s,seq.size());
524 for (exvector::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
525 s.push_back((*it).diff(y));
530 /* obsolete subschildren
531 exvector exprseq::subschildren(lst const & ls, lst const & lr) const
534 RESERVE(s,seq.size());
535 for (exvector::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
536 s.push_back((*it).subs(ls,lr));
542 exvector * exprseq::subschildren(lst const & ls, lst const & lr) const
544 // returns a NULL pointer if nothing had to be substituted
545 // returns a pointer to a newly created epvector otherwise
546 // (which has to be deleted somewhere else)
548 exvector::const_iterator last=seq.end();
549 exvector::const_iterator cit=seq.begin();
551 ex const & subsed_ex=(*cit).subs(ls,lr);
552 if (!are_ex_trivially_equal(*cit,subsed_ex)) {
554 // something changed, copy seq, subs and return it
555 exvector *s=new exvector;
556 RESERVE(*s,seq.size());
558 // copy parts of seq which are known not to have changed
559 exvector::const_iterator cit2=seq.begin();
564 // copy first changed element
565 s->push_back(subsed_ex);
569 s->push_back((*cit2).subs(ls,lr));
577 return 0; // nothing has changed
581 // static member variables
586 unsigned exprseq::precedence=10;
592 const exprseq some_exprseq;
593 type_info const & typeid_exprseq=typeid(some_exprseq);