3 * Implementation of GiNaC's lst. */
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=lst
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) // no reserve needed for list
45 // default constructor, destructor, copy constructor assignment operator and helpers
50 lst::lst() : basic(TINFO_lst)
52 debugmsg("lst default constructor",LOGLEVEL_CONSTRUCT);
57 debugmsg("lst destructor",LOGLEVEL_DESTRUCT);
61 lst::lst(lst const & other)
63 debugmsg("lst copy constructor",LOGLEVEL_CONSTRUCT);
67 lst const & lst::operator=(lst const & other)
69 debugmsg("lst operator=",LOGLEVEL_ASSIGNMENT);
79 void lst::copy(lst const & other)
85 void lst::destroy(bool call_parent)
88 if (call_parent) basic::destroy(call_parent);
97 lst::lst(exlist const & s, bool discardable) : basic(TINFO_lst)
99 debugmsg("lst constructor from exlist",
102 seq.swap(const_cast<exlist &>(s));
108 lst::lst(exlist * vp) : basic(TINFO_lst)
110 debugmsg("lst constructor from exlist *",LOGLEVEL_CONSTRUCT);
116 lst::lst(ex const & e1) : basic(TINFO_lst)
118 debugmsg("lst constructor from 1 ex",
124 lst::lst(ex const & e1, ex const & e2) : basic(TINFO_lst)
126 debugmsg("lst constructor from 2 ex",
133 lst::lst(ex const & e1, ex const & e2, ex const & e3)
136 debugmsg("lst constructor from 3 ex",
144 lst::lst(ex const & e1, ex const & e2, ex const & e3,
145 ex const & e4) : basic(TINFO_lst)
147 debugmsg("lst constructor from 4 ex",
156 lst::lst(ex const & e1, ex const & e2, ex const & e3,
157 ex const & e4, ex const & e5) : basic(TINFO_lst)
159 debugmsg("lst constructor from 5 ex",
169 lst::lst(ex const & e1, ex const & e2, ex const & e3,
170 ex const & e4, ex const & e5, ex const & e6)
173 debugmsg("lst constructor from 6 ex",
184 lst::lst(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_lst)
188 debugmsg("lst constructor from 7 ex",
200 lst::lst(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_lst)
204 debugmsg("lst constructor from 8 ex",
217 lst::lst(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)
222 debugmsg("lst constructor from 9 ex",
236 lst::lst(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,
242 debugmsg("lst constructor from 10 ex",
258 // functions overriding virtual functions from bases classes
263 basic * lst::duplicate() const
265 debugmsg("lst duplicate",LOGLEVEL_DUPLICATE);
266 return new lst(*this);
269 void lst::printraw(ostream & os) const
271 debugmsg("lst printraw",LOGLEVEL_PRINT);
274 for (exlist::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
275 (*cit).bp->printraw(os);
281 void lst::print(ostream & os, unsigned upper_precedence) const
283 debugmsg("lst print",LOGLEVEL_PRINT);
284 // always print brackets around seq, ignore upper_precedence
285 printseq(os,'[',',',']',precedence,precedence+1);
288 void lst::printtree(ostream & os, unsigned indent) const
290 debugmsg("lst 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 (exlist::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
297 (*cit).printtree(os,indent+delta_indent);
299 os << string(indent+delta_indent,' ') << "=====" << endl;
302 // lst::info() will be implemented by user elsewhere";
304 int lst::nops() const
309 ex & lst::let_op(int const i)
312 GINAC_ASSERT(i<nops());
314 exlist::iterator it=seq.begin();
315 for (int j=0; j<i; j++) {
322 ex lst::expand(unsigned options) const
325 RESERVE(s,seq.size());
326 for (exlist::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
327 s.push_back((*it).expand(options));
333 // a lst 'has' an expression if it is this expression itself or a child 'has' it
335 bool lst::has(ex const & other) const
337 GINAC_ASSERT(other.bp!=0);
338 if (is_equal(*other.bp)) return true;
339 for (exlist::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
340 if ((*it).has(other)) return true;
345 ex lst::eval(int level) const
350 return thislst(evalchildren(level));
353 ex lst::evalf(int level) const
355 return thislst(evalfchildren(level));
358 /** Implementation of ex::normal() for lsts. It normalizes the arguments
359 * and replaces the lst by a temporary symbol.
361 ex lst::normal(lst &sym_lst, lst &repl_lst, int level) const
363 ex n=thislst(normalchildren(level));
364 return n.bp->basic::normal(sym_lst,repl_lst,level);
367 ex lst::diff(symbol const & s) const
369 return thislst(diffchildren(s));
372 ex lst::subs(lst const & ls, lst const & lr) const
374 exlist * vp=subschildren(ls,lr);
383 int lst::compare_same_type(basic const & other) const
385 GINAC_ASSERT(is_of_type(other,lst));
386 lst const & o=static_cast<lst const &>
387 (const_cast<basic &>(other));
389 exlist::const_iterator it1=seq.begin();
390 exlist::const_iterator it2=o.seq.begin();
392 for (; (it1!=seq.end())&&(it2!=o.seq.end()); ++it1, ++it2) {
393 cmpval=(*it1).compare(*it2);
394 if (cmpval!=0) return cmpval;
397 if (it1==seq.end()) {
398 return (it2==o.seq.end() ? 0 : -1);
404 bool lst::is_equal_same_type(basic const & other) const
406 GINAC_ASSERT(is_of_type(other,lst));
407 lst const & o=static_cast<lst const &>
408 (const_cast<basic &>(other));
409 if (seq.size()!=o.seq.size()) return false;
411 exlist::const_iterator it1=seq.begin();
412 exlist::const_iterator it2=o.seq.begin();
414 for (; it1!=seq.end(); ++it1, ++it2) {
415 if (!(*it1).is_equal(*it2)) return false;
421 unsigned lst::return_type(void) const
423 return return_types::noncommutative_composite;
427 // new virtual functions which can be overridden by derived classes
432 lst & lst::append(ex const & b)
434 ensure_if_modifiable();
439 lst & lst::prepend(ex const & b)
441 ensure_if_modifiable();
449 void lst::printseq(ostream & os, char openbracket, char delim,
450 char closebracket, unsigned this_precedence,
451 unsigned upper_precedence) const
453 if (this_precedence<=upper_precedence) os << openbracket;
455 exlist::const_iterator it,it_last;
459 for (; it!=it_last; ++it) {
460 (*it).bp->print(os,this_precedence);
463 (*it).bp->print(os,this_precedence);
465 if (this_precedence<=upper_precedence) os << closebracket;
468 ex lst::thislst(exlist const & v) const
473 ex lst::thislst(exlist * vp) const
479 // non-virtual functions in this class
488 bool lst::is_canonical() const
490 if (seq.size()<=1) { return 1; }
492 exlist::const_iterator it=seq.begin();
493 exlist::const_iterator it_last=it;
494 for (++it; it!=seq.end(); it_last=it, ++it) {
495 if ((*it_last).compare(*it)>0) {
496 if ((*it_last).compare(*it)>0) {
497 cout << *it_last << ">" << *it << "\n";
506 exlist lst::evalchildren(int level) const
509 RESERVE(s,seq.size());
514 if (level == -max_recursion_level) {
515 throw(std::runtime_error("max recursion level reached"));
518 for (exlist::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
519 s.push_back((*it).eval(level));
524 exlist lst::evalfchildren(int level) const
527 RESERVE(s,seq.size());
532 if (level == -max_recursion_level) {
533 throw(std::runtime_error("max recursion level reached"));
536 for (exlist::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
537 s.push_back((*it).evalf(level));
542 exlist lst::normalchildren(int level) const
545 RESERVE(s,seq.size());
550 if (level == -max_recursion_level) {
551 throw(std::runtime_error("max recursion level reached"));
554 for (exlist::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
555 s.push_back((*it).normal(level));
560 exlist lst::diffchildren(symbol const & y) const
563 RESERVE(s,seq.size());
564 for (exlist::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
565 s.push_back((*it).diff(y));
570 /* obsolete subschildren
571 exlist lst::subschildren(lst const & ls, lst const & lr) const
574 RESERVE(s,seq.size());
575 for (exlist::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
576 s.push_back((*it).subs(ls,lr));
582 exlist * lst::subschildren(lst const & ls, lst const & lr) const
584 // returns a NULL pointer if nothing had to be substituted
585 // returns a pointer to a newly created epvector otherwise
586 // (which has to be deleted somewhere else)
588 exlist::const_iterator last=seq.end();
589 exlist::const_iterator cit=seq.begin();
591 ex const & subsed_ex=(*cit).subs(ls,lr);
592 if (!are_ex_trivially_equal(*cit,subsed_ex)) {
594 // something changed, copy seq, subs and return it
595 exlist *s=new exlist;
596 RESERVE(*s,seq.size());
598 // copy parts of seq which are known not to have changed
599 exlist::const_iterator cit2=seq.begin();
604 // copy first changed element
605 s->push_back(subsed_ex);
609 s->push_back((*cit2).subs(ls,lr));
617 return 0; // nothing has changed
621 // static member variables
626 unsigned lst::precedence=10;
633 type_info const & typeid_lst=typeid(some_lst);