3 * Implementation of GiNaC's lst.
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=lst
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) // no reserve needed for list
39 // default constructor, destructor, copy constructor assignment operator and helpers
44 lst::lst() : basic(TINFO_LST)
46 debugmsg("lst default constructor",LOGLEVEL_CONSTRUCT);
51 debugmsg("lst destructor",LOGLEVEL_DESTRUCT);
55 lst::lst(lst const & other)
57 debugmsg("lst copy constructor",LOGLEVEL_CONSTRUCT);
61 lst const & lst::operator=(lst const & other)
63 debugmsg("lst operator=",LOGLEVEL_ASSIGNMENT);
73 void lst::copy(lst const & other)
79 void lst::destroy(bool call_parent)
82 if (call_parent) basic::destroy(call_parent);
91 lst::lst(exlist const & s, bool discardable) : basic(TINFO_LST)
93 debugmsg("lst constructor from exlist",
96 seq.swap(const_cast<exlist &>(s));
102 lst::lst(exlist * vp) : basic(TINFO_LST)
104 debugmsg("lst constructor from exlist *",LOGLEVEL_CONSTRUCT);
110 lst::lst(ex const & e1) : basic(TINFO_LST)
112 debugmsg("lst constructor from 1 ex",
118 lst::lst(ex const & e1, ex const & e2) : basic(TINFO_LST)
120 debugmsg("lst constructor from 2 ex",
127 lst::lst(ex const & e1, ex const & e2, ex const & e3)
130 debugmsg("lst constructor from 3 ex",
138 lst::lst(ex const & e1, ex const & e2, ex const & e3,
139 ex const & e4) : basic(TINFO_LST)
141 debugmsg("lst constructor from 4 ex",
150 lst::lst(ex const & e1, ex const & e2, ex const & e3,
151 ex const & e4, ex const & e5) : basic(TINFO_LST)
153 debugmsg("lst constructor from 5 ex",
163 lst::lst(ex const & e1, ex const & e2, ex const & e3,
164 ex const & e4, ex const & e5, ex const & e6)
167 debugmsg("lst constructor from 6 ex",
178 lst::lst(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_LST)
182 debugmsg("lst constructor from 7 ex",
194 lst::lst(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_LST)
198 debugmsg("lst constructor from 8 ex",
211 lst::lst(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)
216 debugmsg("lst constructor from 9 ex",
230 lst::lst(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,
236 debugmsg("lst constructor from 10 ex",
252 // functions overriding virtual functions from bases classes
257 basic * lst::duplicate() const
259 debugmsg("lst duplicate",LOGLEVEL_DUPLICATE);
260 return new lst(*this);
263 void lst::printraw(ostream & os) const
265 debugmsg("lst printraw",LOGLEVEL_PRINT);
268 for (exlist::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
269 (*cit).bp->printraw(os);
275 void lst::print(ostream & os, unsigned upper_precedence) const
277 debugmsg("lst print",LOGLEVEL_PRINT);
278 // always print brackets around seq, ignore upper_precedence
279 printseq(os,'[',',',']',precedence,precedence+1);
282 void lst::printtree(ostream & os, unsigned indent) const
284 debugmsg("lst 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 (exlist::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
291 (*cit).printtree(os,indent+delta_indent);
293 os << string(indent+delta_indent,' ') << "=====" << endl;
296 // lst::info() will be implemented by user elsewhere";
298 int lst::nops() const
303 ex & lst::let_op(int const i)
308 exlist::iterator it=seq.begin();
309 for (int j=0; j<i; j++) {
316 ex lst::expand(unsigned options) const
319 RESERVE(s,seq.size());
320 for (exlist::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
321 s.push_back((*it).expand(options));
327 // a lst 'has' an expression if it is this expression itself or a child 'has' it
329 bool lst::has(ex const & other) const
332 if (is_equal(*other.bp)) return true;
333 for (exlist::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
334 if ((*it).has(other)) return true;
339 ex lst::eval(int level) const
344 return thislst(evalchildren(level));
347 ex lst::evalf(int level) const
349 return thislst(evalfchildren(level));
352 /** Implementation of ex::normal() for lsts. It normalizes the arguments
353 * and replaces the lst by a temporary symbol.
355 ex lst::normal(lst &sym_lst, lst &repl_lst, int level) const
357 ex n=thislst(normalchildren(level));
358 return n.bp->basic::normal(sym_lst,repl_lst,level);
361 ex lst::diff(symbol const & s) const
363 return thislst(diffchildren(s));
366 ex lst::subs(lst const & ls, lst const & lr) const
368 exlist * vp=subschildren(ls,lr);
377 int lst::compare_same_type(basic const & other) const
379 ASSERT(is_of_type(other,lst));
380 lst const & o=static_cast<lst const &>
381 (const_cast<basic &>(other));
383 exlist::const_iterator it1=seq.begin();
384 exlist::const_iterator it2=o.seq.begin();
386 for (; (it1!=seq.end())&&(it2!=o.seq.end()); ++it1, ++it2) {
387 cmpval=(*it1).compare(*it2);
388 if (cmpval!=0) return cmpval;
391 if (it1==seq.end()) {
392 return (it2==o.seq.end() ? 0 : -1);
398 bool lst::is_equal_same_type(basic const & other) const
400 ASSERT(is_of_type(other,lst));
401 lst const & o=static_cast<lst const &>
402 (const_cast<basic &>(other));
403 if (seq.size()!=o.seq.size()) return false;
405 exlist::const_iterator it1=seq.begin();
406 exlist::const_iterator it2=o.seq.begin();
408 for (; it1!=seq.end(); ++it1, ++it2) {
409 if (!(*it1).is_equal(*it2)) return false;
415 unsigned lst::return_type(void) const
417 return return_types::noncommutative_composite;
421 // new virtual functions which can be overridden by derived classes
426 lst & lst::append(ex const & b)
428 ensure_if_modifiable();
433 lst & lst::prepend(ex const & b)
435 ensure_if_modifiable();
443 void lst::printseq(ostream & os, char openbracket, char delim,
444 char closebracket, unsigned this_precedence,
445 unsigned upper_precedence) const
447 if (this_precedence<=upper_precedence) os << openbracket;
449 exlist::const_iterator it,it_last;
453 for (; it!=it_last; ++it) {
454 (*it).bp->print(os,this_precedence);
457 (*it).bp->print(os,this_precedence);
459 if (this_precedence<=upper_precedence) os << closebracket;
462 ex lst::thislst(exlist const & v) const
467 ex lst::thislst(exlist * vp) const
473 // non-virtual functions in this class
482 bool lst::is_canonical() const
484 if (seq.size()<=1) { return 1; }
486 exlist::const_iterator it=seq.begin();
487 exlist::const_iterator it_last=it;
488 for (++it; it!=seq.end(); it_last=it, ++it) {
489 if ((*it_last).compare(*it)>0) {
490 if ((*it_last).compare(*it)>0) {
491 cout << *it_last << ">" << *it << "\n";
500 exlist lst::evalchildren(int level) const
503 RESERVE(s,seq.size());
508 if (level == -max_recursion_level) {
509 throw(std::runtime_error("max recursion level reached"));
512 for (exlist::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
513 s.push_back((*it).eval(level));
518 exlist lst::evalfchildren(int level) const
521 RESERVE(s,seq.size());
526 if (level == -max_recursion_level) {
527 throw(std::runtime_error("max recursion level reached"));
530 for (exlist::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
531 s.push_back((*it).evalf(level));
536 exlist lst::normalchildren(int level) const
539 RESERVE(s,seq.size());
544 if (level == -max_recursion_level) {
545 throw(std::runtime_error("max recursion level reached"));
548 for (exlist::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
549 s.push_back((*it).normal(level));
554 exlist lst::diffchildren(symbol const & y) const
557 RESERVE(s,seq.size());
558 for (exlist::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
559 s.push_back((*it).diff(y));
564 /* obsolete subschildren
565 exlist lst::subschildren(lst const & ls, lst const & lr) const
568 RESERVE(s,seq.size());
569 for (exlist::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
570 s.push_back((*it).subs(ls,lr));
576 exlist * lst::subschildren(lst const & ls, lst const & lr) const
578 // returns a NULL pointer if nothing had to be substituted
579 // returns a pointer to a newly created epvector otherwise
580 // (which has to be deleted somewhere else)
582 exlist::const_iterator last=seq.end();
583 exlist::const_iterator cit=seq.begin();
585 ex const & subsed_ex=(*cit).subs(ls,lr);
586 if (!are_ex_trivially_equal(*cit,subsed_ex)) {
588 // something changed, copy seq, subs and return it
589 exlist *s=new exlist;
590 RESERVE(*s,seq.size());
592 // copy parts of seq which are known not to have changed
593 exlist::const_iterator cit2=seq.begin();
598 // copy first changed element
599 s->push_back(subsed_ex);
603 s->push_back((*cit2).subs(ls,lr));
611 return 0; // nothing has changed
615 // static member variables
620 unsigned lst::precedence=10;
627 type_info const & typeid_lst=typeid(some_lst);