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
37 #define RESERVE(s,size) // no reserve needed for list
40 // default constructor, destructor, copy constructor assignment operator and helpers
45 lst::lst() : basic(TINFO_lst)
47 debugmsg("lst default constructor",LOGLEVEL_CONSTRUCT);
52 debugmsg("lst destructor",LOGLEVEL_DESTRUCT);
56 lst::lst(lst const & other)
58 debugmsg("lst copy constructor",LOGLEVEL_CONSTRUCT);
62 lst const & lst::operator=(lst const & other)
64 debugmsg("lst operator=",LOGLEVEL_ASSIGNMENT);
74 void lst::copy(lst const & other)
80 void lst::destroy(bool call_parent)
83 if (call_parent) basic::destroy(call_parent);
92 lst::lst(exlist const & s, bool discardable) : basic(TINFO_lst)
94 debugmsg("lst constructor from exlist",
97 seq.swap(const_cast<exlist &>(s));
103 lst::lst(exlist * vp) : basic(TINFO_lst)
105 debugmsg("lst constructor from exlist *",LOGLEVEL_CONSTRUCT);
111 lst::lst(ex const & e1) : basic(TINFO_lst)
113 debugmsg("lst constructor from 1 ex",
119 lst::lst(ex const & e1, ex const & e2) : basic(TINFO_lst)
121 debugmsg("lst constructor from 2 ex",
128 lst::lst(ex const & e1, ex const & e2, ex const & e3)
131 debugmsg("lst constructor from 3 ex",
139 lst::lst(ex const & e1, ex const & e2, ex const & e3,
140 ex const & e4) : basic(TINFO_lst)
142 debugmsg("lst constructor from 4 ex",
151 lst::lst(ex const & e1, ex const & e2, ex const & e3,
152 ex const & e4, ex const & e5) : basic(TINFO_lst)
154 debugmsg("lst constructor from 5 ex",
164 lst::lst(ex const & e1, ex const & e2, ex const & e3,
165 ex const & e4, ex const & e5, ex const & e6)
168 debugmsg("lst constructor from 6 ex",
179 lst::lst(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_lst)
183 debugmsg("lst constructor from 7 ex",
195 lst::lst(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_lst)
199 debugmsg("lst constructor from 8 ex",
212 lst::lst(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)
217 debugmsg("lst constructor from 9 ex",
231 lst::lst(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,
237 debugmsg("lst constructor from 10 ex",
253 // functions overriding virtual functions from bases classes
258 basic * lst::duplicate() const
260 debugmsg("lst duplicate",LOGLEVEL_DUPLICATE);
261 return new lst(*this);
264 void lst::printraw(ostream & os) const
266 debugmsg("lst printraw",LOGLEVEL_PRINT);
269 for (exlist::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
270 (*cit).bp->printraw(os);
276 void lst::print(ostream & os, unsigned upper_precedence) const
278 debugmsg("lst print",LOGLEVEL_PRINT);
279 // always print brackets around seq, ignore upper_precedence
280 printseq(os,'[',',',']',precedence,precedence+1);
283 void lst::printtree(ostream & os, unsigned indent) const
285 debugmsg("lst 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 (exlist::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
292 (*cit).printtree(os,indent+delta_indent);
294 os << string(indent+delta_indent,' ') << "=====" << endl;
297 // lst::info() will be implemented by user elsewhere";
299 int lst::nops() const
304 ex & lst::let_op(int const i)
309 exlist::iterator it=seq.begin();
310 for (int j=0; j<i; j++) {
317 ex lst::expand(unsigned options) const
320 RESERVE(s,seq.size());
321 for (exlist::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
322 s.push_back((*it).expand(options));
328 // a lst 'has' an expression if it is this expression itself or a child 'has' it
330 bool lst::has(ex const & other) const
333 if (is_equal(*other.bp)) return true;
334 for (exlist::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
335 if ((*it).has(other)) return true;
340 ex lst::eval(int level) const
345 return thislst(evalchildren(level));
348 ex lst::evalf(int level) const
350 return thislst(evalfchildren(level));
353 /** Implementation of ex::normal() for lsts. It normalizes the arguments
354 * and replaces the lst by a temporary symbol.
356 ex lst::normal(lst &sym_lst, lst &repl_lst, int level) const
358 ex n=thislst(normalchildren(level));
359 return n.bp->basic::normal(sym_lst,repl_lst,level);
362 ex lst::diff(symbol const & s) const
364 return thislst(diffchildren(s));
367 ex lst::subs(lst const & ls, lst const & lr) const
369 exlist * vp=subschildren(ls,lr);
378 int lst::compare_same_type(basic const & other) const
380 ASSERT(is_of_type(other,lst));
381 lst const & o=static_cast<lst const &>
382 (const_cast<basic &>(other));
384 exlist::const_iterator it1=seq.begin();
385 exlist::const_iterator it2=o.seq.begin();
387 for (; (it1!=seq.end())&&(it2!=o.seq.end()); ++it1, ++it2) {
388 cmpval=(*it1).compare(*it2);
389 if (cmpval!=0) return cmpval;
392 if (it1==seq.end()) {
393 return (it2==o.seq.end() ? 0 : -1);
399 bool lst::is_equal_same_type(basic const & other) const
401 ASSERT(is_of_type(other,lst));
402 lst const & o=static_cast<lst const &>
403 (const_cast<basic &>(other));
404 if (seq.size()!=o.seq.size()) return false;
406 exlist::const_iterator it1=seq.begin();
407 exlist::const_iterator it2=o.seq.begin();
409 for (; it1!=seq.end(); ++it1, ++it2) {
410 if (!(*it1).is_equal(*it2)) return false;
416 unsigned lst::return_type(void) const
418 return return_types::noncommutative_composite;
422 // new virtual functions which can be overridden by derived classes
427 lst & lst::append(ex const & b)
429 ensure_if_modifiable();
434 lst & lst::prepend(ex const & b)
436 ensure_if_modifiable();
444 void lst::printseq(ostream & os, char openbracket, char delim,
445 char closebracket, unsigned this_precedence,
446 unsigned upper_precedence) const
448 if (this_precedence<=upper_precedence) os << openbracket;
450 exlist::const_iterator it,it_last;
454 for (; it!=it_last; ++it) {
455 (*it).bp->print(os,this_precedence);
458 (*it).bp->print(os,this_precedence);
460 if (this_precedence<=upper_precedence) os << closebracket;
463 ex lst::thislst(exlist const & v) const
468 ex lst::thislst(exlist * vp) const
474 // non-virtual functions in this class
483 bool lst::is_canonical() const
485 if (seq.size()<=1) { return 1; }
487 exlist::const_iterator it=seq.begin();
488 exlist::const_iterator it_last=it;
489 for (++it; it!=seq.end(); it_last=it, ++it) {
490 if ((*it_last).compare(*it)>0) {
491 if ((*it_last).compare(*it)>0) {
492 cout << *it_last << ">" << *it << "\n";
501 exlist lst::evalchildren(int level) const
504 RESERVE(s,seq.size());
509 if (level == -max_recursion_level) {
510 throw(std::runtime_error("max recursion level reached"));
513 for (exlist::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
514 s.push_back((*it).eval(level));
519 exlist lst::evalfchildren(int level) const
522 RESERVE(s,seq.size());
527 if (level == -max_recursion_level) {
528 throw(std::runtime_error("max recursion level reached"));
531 for (exlist::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
532 s.push_back((*it).evalf(level));
537 exlist lst::normalchildren(int level) const
540 RESERVE(s,seq.size());
545 if (level == -max_recursion_level) {
546 throw(std::runtime_error("max recursion level reached"));
549 for (exlist::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
550 s.push_back((*it).normal(level));
555 exlist lst::diffchildren(symbol const & y) const
558 RESERVE(s,seq.size());
559 for (exlist::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
560 s.push_back((*it).diff(y));
565 /* obsolete subschildren
566 exlist lst::subschildren(lst const & ls, lst const & lr) const
569 RESERVE(s,seq.size());
570 for (exlist::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
571 s.push_back((*it).subs(ls,lr));
577 exlist * lst::subschildren(lst const & ls, lst const & lr) const
579 // returns a NULL pointer if nothing had to be substituted
580 // returns a pointer to a newly created epvector otherwise
581 // (which has to be deleted somewhere else)
583 exlist::const_iterator last=seq.end();
584 exlist::const_iterator cit=seq.begin();
586 ex const & subsed_ex=(*cit).subs(ls,lr);
587 if (!are_ex_trivially_equal(*cit,subsed_ex)) {
589 // something changed, copy seq, subs and return it
590 exlist *s=new exlist;
591 RESERVE(*s,seq.size());
593 // copy parts of seq which are known not to have changed
594 exlist::const_iterator cit2=seq.begin();
599 // copy first changed element
600 s->push_back(subsed_ex);
604 s->push_back((*cit2).subs(ls,lr));
612 return 0; // nothing has changed
616 // static member variables
621 unsigned lst::precedence=10;
628 type_info const & typeid_lst=typeid(some_lst);