public:
basic()
#ifdef INLINE_BASIC_CONSTRUCTORS
- : tinfo_key(TINFO_basic), flags(0), refcount(0)
+ : tinfo_key(TINFO_basic), flags(0), refcount(0)
{
}
#else
// other constructors
basic(unsigned ti)
#ifdef INLINE_BASIC_CONSTRUCTORS
- : tinfo_key(ti), flags(0), refcount(0)
+ : tinfo_key(ti), flags(0), refcount(0)
{
}
#else
friend color color_delta8(const ex & a, const ex & b);
friend unsigned subs_index_in_exvector(exvector & v, const ex & is, const ex & ir);
friend void split_color_string_in_parts(const exvector & v, exvector & delta8vec,
- exvector & fvec, exvector & dvec,
- exvectorvector & Tvecs,
- exvectorvector & ONEvecs,
- exvector & unknownvec);
+ exvector & fvec, exvector & dvec,
+ exvectorvector & Tvecs,
+ exvectorvector & ONEvecs,
+ exvector & unknownvec);
friend exvector recombine_color_string(exvector & delta8vec, exvector & fvec,
- exvector & dvec, exvectorvector & Tvecs,
- exvectorvector & ONEvecs, exvector & unknownvec);
+ exvector & dvec, exvectorvector & Tvecs,
+ exvectorvector & ONEvecs, exvector & unknownvec);
friend ex color_trace_of_one_representation_label(const exvector & v);
friend ex color_trace(const exvector & v, unsigned rl);
friend ex simplify_pure_color_string(const ex & e);
// types
public:
- typedef enum { invalid, // not properly constructed by one of the friend functions
- color_T,
- color_f,
- color_d,
- color_delta8,
- color_ONE
+ typedef enum {
+ invalid, // not properly constructed by one of the friend functions
+ color_T,
+ color_f,
+ color_d,
+ color_delta8,
+ color_ONE
} color_types;
// member functions
color(color_types const t, const ex & i1, unsigned rl=0);
color(color_types const t, const ex & i1, const ex & i2, unsigned rl=0);
color(color_types const t, const ex & i1, const ex & i2, const ex & i3,
- unsigned rl=0);
+ unsigned rl=0);
color(color_types const t, const exvector & iv, unsigned rl=0);
color(color_types const t, exvector * ivp, unsigned rl=0);
ex color_h(const ex & a, const ex & b, const ex & c);
color color_delta8(const ex & a, const ex & b);
void split_color_string_in_parts(const exvector & v, exvector & delta8vec,
- exvector & fvec, exvector & dvec,
- exvectorvector & Tvecs,
- exvectorvector & ONEvecs,
- exvector & unknownvec);
+ exvector & fvec, exvector & dvec,
+ exvectorvector & Tvecs,
+ exvectorvector & ONEvecs,
+ exvector & unknownvec);
exvector recombine_color_string(exvector & delta8vec, exvector & fvec,
- exvector & dvec, exvectorvector & Tvecs,
- exvectorvector & ONEvecs, exvector & unknownvec);
+ exvector & dvec, exvectorvector & Tvecs,
+ exvectorvector & ONEvecs, exvector & unknownvec);
ex color_trace_of_one_representation_label(const exvector & v);
ex color_trace(const exvector & v, unsigned rl=0);
ex simplify_pure_color_string(const ex & e);
if (($#ARGV!=0) and ($#ARGV!=1)) {
- die 'usage: container.pl type [maxargs] (type=lst or exprseq)';
+ die 'usage: container.pl type [maxargs] (type=lst or exprseq)';
}
if ($ARGV[0] eq 'lst') {
- $type='lst';
+ $type='lst';
} elsif ($ARGV[0] eq 'exprseq') {
- $type='exprseq';
+ $type='exprseq';
} else {
- die 'only lst and exprseq supported';
+ die 'only lst and exprseq supported';
}
if ($#ARGV==1) {
- $maxargs=$ARGV[1];
+ $maxargs=$ARGV[1];
} else {
- $maxargs=15; # must be greater or equal than the value used in function.pl
+ $maxargs=15; # must be greater or equal than the value used in function.pl
}
if ($type eq 'exprseq') {
- # settings for exprseq
- $CONTAINER="exprseq";
- $STLHEADER="vector";
- $reserve=1;
- $prepend=0;
- $let_op=0;
- $open_bracket='(';
- $close_bracket=')';
-
+ # settings for exprseq
+ $CONTAINER="exprseq";
+ $STLHEADER="vector";
+ $reserve=1;
+ $prepend=0;
+ $let_op=0;
+ $open_bracket='(';
+ $close_bracket=')';
+
} elsif ($type eq 'lst') {
- # settings for lst
- $CONTAINER="lst";
- $STLHEADER="list";
- $reserve=0;
- $prepend=1;
- $let_op=1;
- $open_bracket='[';
- $close_bracket=']';
+ # settings for lst
+ $CONTAINER="lst";
+ $STLHEADER="list";
+ $reserve=0;
+ $prepend=1;
+ $let_op=1;
+ $open_bracket='[';
+ $close_bracket=']';
} else {
- die "invalid type $type";
+ die "invalid type $type";
}
$CONTAINER_UC=uc(${CONTAINER});
$STLT="ex".$STLHEADER;
if ($reserve) {
- $RESERVE_IMPLEMENTATION="#define RESERVE(s,size) (s).reserve(size)";
+ $RESERVE_IMPLEMENTATION="#define RESERVE(s,size) (s).reserve(size)";
} else {
- $RESERVE_IMPLEMENTATION="#define RESERVE(s,size) // no reserve needed for ${STLHEADER}";
+ $RESERVE_IMPLEMENTATION="#define RESERVE(s,size) // no reserve needed for ${STLHEADER}";
}
if ($prepend) {
- $PREPEND_INTERFACE=<<END_OF_PREPEND_INTERFACE;
- virtual ${CONTAINER} & prepend(const ex & b);
+ $PREPEND_INTERFACE=<<END_OF_PREPEND_INTERFACE;
+ virtual ${CONTAINER} & prepend(const ex & b);
END_OF_PREPEND_INTERFACE
- $PREPEND_IMPLEMENTATION=<<END_OF_PREPEND_IMPLEMENTATION;
+ $PREPEND_IMPLEMENTATION=<<END_OF_PREPEND_IMPLEMENTATION;
${CONTAINER} & ${CONTAINER}::prepend(const ex & b)
{
- ensure_if_modifiable();
- seq.push_front(b);
- return *this;
+ ensure_if_modifiable();
+ seq.push_front(b);
+ return *this;
}
END_OF_PREPEND_IMPLEMENTATION
} else {
- $PREPEND_INTERFACE=" // no prepend possible for ${CONTAINER}";
- $PREPEND_IMPLEMENTATION="";
+ $PREPEND_INTERFACE=" // no prepend possible for ${CONTAINER}";
+ $PREPEND_IMPLEMENTATION="";
}
if ($let_op) {
- $LET_OP_IMPLEMENTATION=<<END_OF_LET_OP_IMPLEMENTATION
+ $LET_OP_IMPLEMENTATION=<<END_OF_LET_OP_IMPLEMENTATION
ex & ${CONTAINER}::let_op(int i)
{
- GINAC_ASSERT(i>=0);
- GINAC_ASSERT(i<nops());
+ GINAC_ASSERT(i>=0);
+ GINAC_ASSERT(i<nops());
- ${STLT}::iterator it=seq.begin();
- for (int j=0; j<i; j++) {
- ++it;
- }
- return *it;
+ ${STLT}::iterator it=seq.begin();
+ for (int j=0; j<i; j++) {
+ ++it;
+ }
+ return *it;
}
END_OF_LET_OP_IMPLEMENTATION
} else {
- $LET_OP_IMPLEMENTATION="// ${CONTAINER}::let_op() will be implemented by user elsewhere";
+ $LET_OP_IMPLEMENTATION="// ${CONTAINER}::let_op() will be implemented by user elsewhere";
}
sub generate_seq {
- my ($seq_template,$n,$separator)=@_;
- my ($res,$N);
-
- $res='';
- for ($N=1; $N<=$n; $N++) {
- $res .= eval('"' . $seq_template . '"');
- if ($N!=$n) {
- $res .= $separator;
- }
- }
- return $res;
+ my ($seq_template,$n,$separator)=@_;
+ my ($res,$N);
+
+ $res='';
+ for ($N=1; $N<=$n; $N++) {
+ $res .= eval('"' . $seq_template . '"');
+ if ($N!=$n) {
+ $res .= $separator;
+ }
+ }
+ return $res;
}
sub generate_from_to {
- my ($template,$seq_template1,$seq_separator1,$seq_template2,
- $seq_separator2,$from,$to)=@_;
- my ($res,$N,$SEQ);
+ my ($template,$seq_template1,$seq_separator1,$seq_template2,
+ $seq_separator2,$from,$to)=@_;
+ my ($res,$N,$SEQ);
- $res='';
- for ($N=$from; $N<=$to; $N++) {
- $SEQ1=generate_seq($seq_template1,$N,$seq_separator1);
- $SEQ2=generate_seq($seq_template2,$N,$seq_separator2);
- $res .= eval('"' . $template . '"');
- $SEQ1=''; # to avoid main::SEQ1 used only once warning
- $SEQ2=''; # same as above
- }
- return $res;
+ $res='';
+ for ($N=$from; $N<=$to; $N++) {
+ $SEQ1=generate_seq($seq_template1,$N,$seq_separator1);
+ $SEQ2=generate_seq($seq_template2,$N,$seq_separator2);
+ $res .= eval('"' . $template . '"');
+ $SEQ1=''; # to avoid main::SEQ1 used only once warning
+ $SEQ2=''; # same as above
+ }
+ return $res;
}
sub generate {
- my ($template,$seq_template1,$seq_separator1,$seq_template2,
- $seq_separator2)=@_;
- return generate_from_to($template,$seq_template1,$seq_separator1,
- $seq_template2,$seq_separator2,1,$maxargs);
+ my ($template,$seq_template1,$seq_separator1,$seq_template2,
+ $seq_separator2)=@_;
+ return generate_from_to($template,$seq_template1,$seq_separator1,
+ $seq_template2,$seq_separator2,1,$maxargs);
}
$constructors_interface=generate(
'const ex & param${N}',', ','','');
$constructors_implementation=generate(
- <<'END_OF_CONSTRUCTORS_IMPLEMENTATION','const ex & param${N}',', ',' seq.push_back(param${N});',"\n");
+ <<'END_OF_CONSTRUCTORS_IMPLEMENTATION','const ex & param${N}',', ',' seq.push_back(param${N});',"\n");
${CONTAINER}::${CONTAINER}(${SEQ1}) : basic(TINFO_${CONTAINER})
{
- debugmsg(\"${CONTAINER} constructor from ${N}*ex\",LOGLEVEL_CONSTRUCT);
- RESERVE(seq,${N});
+ debugmsg(\"${CONTAINER} constructor from ${N}*ex\",LOGLEVEL_CONSTRUCT);
+ RESERVE(seq,${N});
${SEQ2}
}
END_OF_CONSTRUCTORS_IMPLEMENTATION
class ${CONTAINER} : public basic
{
- GINAC_DECLARE_REGISTERED_CLASS(${CONTAINER}, basic)
+ GINAC_DECLARE_REGISTERED_CLASS(${CONTAINER}, basic)
public:
- ${CONTAINER}();
- ~${CONTAINER}();
- ${CONTAINER}(${CONTAINER} const & other);
- ${CONTAINER} const & operator=(${CONTAINER} const & other);
+ ${CONTAINER}();
+ ~${CONTAINER}();
+ ${CONTAINER}(${CONTAINER} const & other);
+ ${CONTAINER} const & operator=(${CONTAINER} const & other);
protected:
- void copy(${CONTAINER} const & other);
- void destroy(bool call_parent);
+ void copy(${CONTAINER} const & other);
+ void destroy(bool call_parent);
public:
- ${CONTAINER}(${STLT} const & s, bool discardable=0);
- ${CONTAINER}(${STLT} * vp); // vp will be deleted
+ ${CONTAINER}(${STLT} const & s, bool discardable=0);
+ ${CONTAINER}(${STLT} * vp); // vp will be deleted
${constructors_interface}
public:
- basic * duplicate() const;
- void printraw(std::ostream & os) const;
- void print(std::ostream & os, unsigned upper_precedence=0) const;
- void printtree(std::ostream & os, unsigned indent) const;
- bool info(unsigned inf) const;
- unsigned nops() const;
- ex & let_op(int i);
- ex expand(unsigned options=0) const;
- bool has(const ex & other) const;
- ex eval(int level=0) const;
- ex evalf(int level=0) const;
- ex normal(lst &sym_lst, lst &repl_lst, int level=0) const;
- ex derivative(const symbol & s) const;
- ex subs(const lst & ls, const lst & lr) const;
+ basic * duplicate() const;
+ void printraw(std::ostream & os) const;
+ void print(std::ostream & os, unsigned upper_precedence=0) const;
+ void printtree(std::ostream & os, unsigned indent) const;
+ bool info(unsigned inf) const;
+ unsigned nops() const;
+ ex & let_op(int i);
+ ex expand(unsigned options=0) const;
+ bool has(const ex & other) const;
+ ex eval(int level=0) const;
+ ex evalf(int level=0) const;
+ ex normal(lst &sym_lst, lst &repl_lst, int level=0) const;
+ ex derivative(const symbol & s) const;
+ ex subs(const lst & ls, const lst & lr) const;
protected:
- int compare_same_type(const basic & other) const;
- bool is_equal_same_type(const basic & other) const;
- unsigned return_type(void) const;
+ int compare_same_type(const basic & other) const;
+ bool is_equal_same_type(const basic & other) const;
+ unsigned return_type(void) const;
- // new virtual functions which can be overridden by derived classes
+ // new virtual functions which can be overridden by derived classes
public:
- virtual ${CONTAINER} & append(const ex & b);
+ virtual ${CONTAINER} & append(const ex & b);
${PREPEND_INTERFACE}
protected:
- virtual void printseq(std::ostream & os, char openbracket, char delim,
- char closebracket, unsigned this_precedence,
- unsigned upper_precedence=0) const;
- virtual ex this${CONTAINER}(${STLT} const & v) const;
- virtual ex this${CONTAINER}(${STLT} * vp) const;
+ virtual void printseq(std::ostream & os, char openbracket, char delim,
+ char closebracket, unsigned this_precedence,
+ unsigned upper_precedence=0) const;
+ virtual ex this${CONTAINER}(${STLT} const & v) const;
+ virtual ex this${CONTAINER}(${STLT} * vp) const;
protected:
- bool is_canonical() const;
- ${STLT} evalchildren(int level) const;
- ${STLT} evalfchildren(int level) const;
- ${STLT} normalchildren(int level) const;
- ${STLT} diffchildren(const symbol & s) const;
- ${STLT} * subschildren(const lst & ls, const lst & lr) const;
+ bool is_canonical() const;
+ ${STLT} evalchildren(int level) const;
+ ${STLT} evalfchildren(int level) const;
+ ${STLT} normalchildren(int level) const;
+ ${STLT} diffchildren(const symbol & s) const;
+ ${STLT} * subschildren(const lst & ls, const lst & lr) const;
protected:
- ${STLT} seq;
- static unsigned precedence;
+ ${STLT} seq;
+ static unsigned precedence;
};
// global constants
// utility functions
inline const ${CONTAINER} &ex_to_${CONTAINER}(const ex &e)
{
- return static_cast<const ${CONTAINER} &>(*e.bp);
+ return static_cast<const ${CONTAINER} &>(*e.bp);
}
inline ${CONTAINER} &ex_to_nonconst_${CONTAINER}(const ex &e)
{
- return static_cast<${CONTAINER} &>(*e.bp);
+ return static_cast<${CONTAINER} &>(*e.bp);
}
#ifndef NO_NAMESPACE_GINAC
${CONTAINER}::${CONTAINER}() : basic(TINFO_${CONTAINER})
{
- debugmsg("${CONTAINER} default constructor",LOGLEVEL_CONSTRUCT);
+ debugmsg("${CONTAINER} default constructor",LOGLEVEL_CONSTRUCT);
}
${CONTAINER}::~${CONTAINER}()
{
- debugmsg("${CONTAINER} destructor",LOGLEVEL_DESTRUCT);
- destroy(0);
+ debugmsg("${CONTAINER} destructor",LOGLEVEL_DESTRUCT);
+ destroy(0);
}
${CONTAINER}::${CONTAINER}(${CONTAINER} const & other)
{
- debugmsg("${CONTAINER} copy constructor",LOGLEVEL_CONSTRUCT);
- copy(other);
+ debugmsg("${CONTAINER} copy constructor",LOGLEVEL_CONSTRUCT);
+ copy(other);
}
${CONTAINER} const & ${CONTAINER}::operator=(${CONTAINER} const & other)
{
- debugmsg("${CONTAINER} operator=",LOGLEVEL_ASSIGNMENT);
- if (this != &other) {
- destroy(1);
- copy(other);
- }
- return *this;
+ debugmsg("${CONTAINER} operator=",LOGLEVEL_ASSIGNMENT);
+ if (this != &other) {
+ destroy(1);
+ copy(other);
+ }
+ return *this;
}
// protected
void ${CONTAINER}::copy(${CONTAINER} const & other)
{
- inherited::copy(other);
- seq=other.seq;
+ inherited::copy(other);
+ seq=other.seq;
}
void ${CONTAINER}::destroy(bool call_parent)
{
- seq.clear();
- if (call_parent) inherited::destroy(call_parent);
+ seq.clear();
+ if (call_parent) inherited::destroy(call_parent);
}
//////////
${CONTAINER}::${CONTAINER}(${STLT} const & s, bool discardable) : basic(TINFO_${CONTAINER})
{
- debugmsg("${CONTAINER} constructor from ${STLT}",
- LOGLEVEL_CONSTRUCT);
- if (discardable) {
- seq.swap(const_cast<${STLT} &>(s));
- } else {
- seq=s;
- }
+ debugmsg("${CONTAINER} constructor from ${STLT}", LOGLEVEL_CONSTRUCT);
+ if (discardable) {
+ seq.swap(const_cast<${STLT} &>(s));
+ } else {
+ seq=s;
+ }
}
${CONTAINER}::${CONTAINER}(${STLT} * vp) : basic(TINFO_${CONTAINER})
{
- debugmsg("${CONTAINER} constructor from ${STLT} *",LOGLEVEL_CONSTRUCT);
- GINAC_ASSERT(vp!=0);
- seq.swap(*vp);
- delete vp;
+ debugmsg("${CONTAINER} constructor from ${STLT} *",LOGLEVEL_CONSTRUCT);
+ GINAC_ASSERT(vp!=0);
+ seq.swap(*vp);
+ delete vp;
}
${constructors_implementation}
/** Construct object from archive_node. */
${CONTAINER}::${CONTAINER}(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst)
{
- debugmsg("${CONTAINER} constructor from archive_node", LOGLEVEL_CONSTRUCT);
- for (unsigned int i=0; true; i++) {
- ex e;
- if (n.find_ex("seq", e, sym_lst, i))
- seq.push_back(e);
- else
- break;
- }
+ debugmsg("${CONTAINER} constructor from archive_node", LOGLEVEL_CONSTRUCT);
+ for (unsigned int i=0; true; i++) {
+ ex e;
+ if (n.find_ex("seq", e, sym_lst, i))
+ seq.push_back(e);
+ else
+ break;
+ }
}
/** Unarchive the object. */
ex ${CONTAINER}::unarchive(const archive_node &n, const lst &sym_lst)
{
- return (new ${CONTAINER}(n, sym_lst))->setflag(status_flags::dynallocated);
+ return (new ${CONTAINER}(n, sym_lst))->setflag(status_flags::dynallocated);
}
/** Archive the object. */
void ${CONTAINER}::archive(archive_node &n) const
{
- inherited::archive(n);
- ${STLT}::const_iterator i = seq.begin(), iend = seq.end();
- while (i != iend) {
- n.add_ex("seq", *i);
- i++;
- }
+ inherited::archive(n);
+ ${STLT}::const_iterator i = seq.begin(), iend = seq.end();
+ while (i != iend) {
+ n.add_ex("seq", *i);
+ i++;
+ }
}
//////////
basic * ${CONTAINER}::duplicate() const
{
- debugmsg("${CONTAINER} duplicate",LOGLEVEL_DUPLICATE);
- return new ${CONTAINER}(*this);
+ debugmsg("${CONTAINER} duplicate",LOGLEVEL_DUPLICATE);
+ return new ${CONTAINER}(*this);
}
void ${CONTAINER}::printraw(std::ostream & os) const
{
- debugmsg("${CONTAINER} printraw",LOGLEVEL_PRINT);
+ debugmsg("${CONTAINER} printraw",LOGLEVEL_PRINT);
- os << "${CONTAINER}(";
- for (${STLT}::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
- (*cit).bp->printraw(os);
- os << ",";
- }
- os << ")";
+ os << "${CONTAINER}(";
+ for (${STLT}::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
+ (*cit).bp->printraw(os);
+ os << ",";
+ }
+ os << ")";
}
void ${CONTAINER}::print(std::ostream & os, unsigned upper_precedence) const
{
- debugmsg("${CONTAINER} print",LOGLEVEL_PRINT);
- // always print brackets around seq, ignore upper_precedence
- printseq(os,'${open_bracket}',',','${close_bracket}',precedence,precedence+1);
+ debugmsg("${CONTAINER} print",LOGLEVEL_PRINT);
+ // always print brackets around seq, ignore upper_precedence
+ printseq(os,'${open_bracket}',',','${close_bracket}',precedence,precedence+1);
}
void ${CONTAINER}::printtree(std::ostream & os, unsigned indent) const
{
- debugmsg("${CONTAINER} printtree",LOGLEVEL_PRINT);
+ debugmsg("${CONTAINER} printtree",LOGLEVEL_PRINT);
- os << std::string(indent,' ') << "type=" << typeid(*this).name()
- << ", hash=" << hashvalue
- << " (0x" << std::hex << hashvalue << std::dec << ")"
- << ", flags=" << flags
- << ", nops=" << nops() << std::endl;
- for (${STLT}::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
- (*cit).printtree(os,indent+delta_indent);
- }
- os << std::string(indent+delta_indent,' ') << "=====" << std::endl;
+ os << std::string(indent,' ') << "type=" << class_name()
+ << ", hash=" << hashvalue
+ << " (0x" << std::hex << hashvalue << std::dec << ")"
+ << ", flags=" << flags
+ << ", nops=" << nops() << std::endl;
+ for (${STLT}::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
+ (*cit).printtree(os,indent+delta_indent);
+ }
+ os << std::string(indent+delta_indent,' ') << "=====" << std::endl;
}
// ${CONTAINER}::info() will be implemented by user elsewhere";
unsigned ${CONTAINER}::nops() const
{
- return seq.size();
+ return seq.size();
}
${LET_OP_IMPLEMENTATION}
ex ${CONTAINER}::expand(unsigned options) const
{
- ${STLT} s;
- RESERVE(s,seq.size());
- for (${STLT}::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
- s.push_back((*it).expand(options));
- }
+ ${STLT} s;
+ RESERVE(s,seq.size());
+ for (${STLT}::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
+ s.push_back((*it).expand(options));
+ }
- return this${CONTAINER}(s);
+ return this${CONTAINER}(s);
}
// a ${CONTAINER} 'has' an expression if it is this expression itself or a child 'has' it
bool ${CONTAINER}::has(const ex & other) const
{
- GINAC_ASSERT(other.bp!=0);
- if (is_equal(*other.bp)) return true;
- for (${STLT}::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
- if ((*it).has(other)) return true;
- }
- return false;
+ GINAC_ASSERT(other.bp!=0);
+ if (is_equal(*other.bp)) return true;
+ for (${STLT}::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
+ if ((*it).has(other)) return true;
+ }
+ return false;
}
ex ${CONTAINER}::eval(int level) const
{
- if (level==1) {
- return this->hold();
- }
- return this${CONTAINER}(evalchildren(level));
+ if (level==1) {
+ return this->hold();
+ }
+ return this${CONTAINER}(evalchildren(level));
}
ex ${CONTAINER}::evalf(int level) const
{
- return this${CONTAINER}(evalfchildren(level));
+ return this${CONTAINER}(evalfchildren(level));
}
/** Implementation of ex::normal() for ${CONTAINER}s. It normalizes the arguments
* \@see ex::normal */
ex ${CONTAINER}::normal(lst &sym_lst, lst &repl_lst, int level) const
{
- ex n=this${CONTAINER}(normalchildren(level));
- return n.bp->basic::normal(sym_lst,repl_lst,level);
+ ex n=this${CONTAINER}(normalchildren(level));
+ return n.bp->basic::normal(sym_lst,repl_lst,level);
}
ex ${CONTAINER}::derivative(const symbol & s) const
{
- return this${CONTAINER}(diffchildren(s));
+ return this${CONTAINER}(diffchildren(s));
}
ex ${CONTAINER}::subs(const lst & ls, const lst & lr) const
{
- ${STLT} * vp=subschildren(ls,lr);
- if (vp==0) {
- return *this;
- }
- return this${CONTAINER}(vp);
+ ${STLT} * vp=subschildren(ls,lr);
+ if (vp==0) {
+ return *this;
+ }
+ return this${CONTAINER}(vp);
}
// protected
int ${CONTAINER}::compare_same_type(const basic & other) const
{
- GINAC_ASSERT(is_of_type(other,${CONTAINER}));
- ${CONTAINER} const & o=static_cast<${CONTAINER} const &>
- (const_cast<basic &>(other));
- int cmpval;
- ${STLT}::const_iterator it1=seq.begin();
- ${STLT}::const_iterator it2=o.seq.begin();
+ GINAC_ASSERT(is_of_type(other,${CONTAINER}));
+ ${CONTAINER} const & o=static_cast<${CONTAINER} const &>
+ (const_cast<basic &>(other));
+ int cmpval;
+ ${STLT}::const_iterator it1=seq.begin();
+ ${STLT}::const_iterator it2=o.seq.begin();
- for (; (it1!=seq.end())&&(it2!=o.seq.end()); ++it1, ++it2) {
- cmpval=(*it1).compare(*it2);
- if (cmpval!=0) return cmpval;
- }
+ for (; (it1!=seq.end())&&(it2!=o.seq.end()); ++it1, ++it2) {
+ cmpval=(*it1).compare(*it2);
+ if (cmpval!=0) return cmpval;
+ }
- if (it1==seq.end()) {
- return (it2==o.seq.end() ? 0 : -1);
- }
+ if (it1==seq.end()) {
+ return (it2==o.seq.end() ? 0 : -1);
+ }
- return 1;
+ return 1;
}
bool ${CONTAINER}::is_equal_same_type(const basic & other) const
{
- GINAC_ASSERT(is_of_type(other,${CONTAINER}));
- ${CONTAINER} const & o=static_cast<${CONTAINER} const &>
- (const_cast<basic &>(other));
- if (seq.size()!=o.seq.size()) return false;
+ GINAC_ASSERT(is_of_type(other,${CONTAINER}));
+ ${CONTAINER} const & o=static_cast<${CONTAINER} const &>
+ (const_cast<basic &>(other));
+ if (seq.size()!=o.seq.size()) return false;
- ${STLT}::const_iterator it1=seq.begin();
- ${STLT}::const_iterator it2=o.seq.begin();
+ ${STLT}::const_iterator it1=seq.begin();
+ ${STLT}::const_iterator it2=o.seq.begin();
- for (; it1!=seq.end(); ++it1, ++it2) {
- if (!(*it1).is_equal(*it2)) return false;
- }
+ for (; it1!=seq.end(); ++it1, ++it2) {
+ if (!(*it1).is_equal(*it2)) return false;
+ }
- return true;
+ return true;
}
unsigned ${CONTAINER}::return_type(void) const
{
- return return_types::noncommutative_composite;
+ return return_types::noncommutative_composite;
}
//////////
${CONTAINER} & ${CONTAINER}::append(const ex & b)
{
- ensure_if_modifiable();
- seq.push_back(b);
- return *this;
+ ensure_if_modifiable();
+ seq.push_back(b);
+ return *this;
}
${PREPEND_IMPLEMENTATION}
// protected
void ${CONTAINER}::printseq(std::ostream & os, char openbracket, char delim,
- char closebracket, unsigned this_precedence,
- unsigned upper_precedence) const
-{
- if (this_precedence<=upper_precedence) os << openbracket;
- if (seq.size()!=0) {
- ${STLT}::const_iterator it,it_last;
- it=seq.begin();
- it_last=seq.end();
- --it_last;
- for (; it!=it_last; ++it) {
- (*it).bp->print(os,this_precedence);
- os << delim;
- }
- (*it).bp->print(os,this_precedence);
- }
- if (this_precedence<=upper_precedence) os << closebracket;
+ char closebracket, unsigned this_precedence,
+ unsigned upper_precedence) const
+{
+ if (this_precedence<=upper_precedence) os << openbracket;
+ if (seq.size()!=0) {
+ ${STLT}::const_iterator it,it_last;
+ it=seq.begin();
+ it_last=seq.end();
+ --it_last;
+ for (; it!=it_last; ++it) {
+ (*it).bp->print(os,this_precedence);
+ os << delim;
+ }
+ (*it).bp->print(os,this_precedence);
+ }
+ if (this_precedence<=upper_precedence) os << closebracket;
}
ex ${CONTAINER}::this${CONTAINER}(${STLT} const & v) const
{
- return ${CONTAINER}(v);
+ return ${CONTAINER}(v);
}
ex ${CONTAINER}::this${CONTAINER}(${STLT} * vp) const
{
- return ${CONTAINER}(vp);
+ return ${CONTAINER}(vp);
}
//////////
bool ${CONTAINER}::is_canonical() const
{
- if (seq.size()<=1) { return 1; }
+ if (seq.size()<=1) { return 1; }
- ${STLT}::const_iterator it=seq.begin();
- ${STLT}::const_iterator it_last=it;
- for (++it; it!=seq.end(); it_last=it, ++it) {
- if ((*it_last).compare(*it)>0) {
- if ((*it_last).compare(*it)>0) {
- std::cout << *it_last << ">" << *it << "\\n";
- return 0;
- }
- }
- }
- return 1;
+ ${STLT}::const_iterator it=seq.begin();
+ ${STLT}::const_iterator it_last=it;
+ for (++it; it!=seq.end(); it_last=it, ++it) {
+ if ((*it_last).compare(*it)>0) {
+ if ((*it_last).compare(*it)>0) {
+ std::cout << *it_last << ">" << *it << "\\n";
+ return 0;
+ }
+ }
+ }
+ return 1;
}
${STLT} ${CONTAINER}::evalchildren(int level) const
{
- ${STLT} s;
- RESERVE(s,seq.size());
+ ${STLT} s;
+ RESERVE(s,seq.size());
- if (level==1) {
- return seq;
- }
- if (level == -max_recursion_level) {
- throw(std::runtime_error("max recursion level reached"));
- }
- --level;
- for (${STLT}::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
- s.push_back((*it).eval(level));
- }
- return s;
+ if (level==1) {
+ return seq;
+ }
+ if (level == -max_recursion_level) {
+ throw(std::runtime_error("max recursion level reached"));
+ }
+ --level;
+ for (${STLT}::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
+ s.push_back((*it).eval(level));
+ }
+ return s;
}
${STLT} ${CONTAINER}::evalfchildren(int level) const
{
- ${STLT} s;
- RESERVE(s,seq.size());
+ ${STLT} s;
+ RESERVE(s,seq.size());
- if (level==1) {
- return seq;
- }
- if (level == -max_recursion_level) {
- throw(std::runtime_error("max recursion level reached"));
- }
- --level;
- for (${STLT}::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
- s.push_back((*it).evalf(level));
- }
- return s;
+ if (level==1) {
+ return seq;
+ }
+ if (level == -max_recursion_level) {
+ throw(std::runtime_error("max recursion level reached"));
+ }
+ --level;
+ for (${STLT}::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
+ s.push_back((*it).evalf(level));
+ }
+ return s;
}
${STLT} ${CONTAINER}::normalchildren(int level) const
{
- ${STLT} s;
- RESERVE(s,seq.size());
+ ${STLT} s;
+ RESERVE(s,seq.size());
- if (level==1) {
- return seq;
- }
- if (level == -max_recursion_level) {
- throw(std::runtime_error("max recursion level reached"));
- }
- --level;
- for (${STLT}::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
- s.push_back((*it).normal(level));
- }
- return s;
+ if (level==1) {
+ return seq;
+ }
+ if (level == -max_recursion_level) {
+ throw(std::runtime_error("max recursion level reached"));
+ }
+ --level;
+ for (${STLT}::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
+ s.push_back((*it).normal(level));
+ }
+ return s;
}
${STLT} ${CONTAINER}::diffchildren(const symbol & y) const
{
- ${STLT} s;
- RESERVE(s,seq.size());
- for (${STLT}::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
- s.push_back((*it).diff(y));
- }
- return s;
+ ${STLT} s;
+ RESERVE(s,seq.size());
+ for (${STLT}::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
+ s.push_back((*it).diff(y));
+ }
+ return s;
}
/* obsolete subschildren
${STLT} ${CONTAINER}::subschildren(const lst & ls, const lst & lr) const
{
- ${STLT} s;
- RESERVE(s,seq.size());
- for (${STLT}::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
- s.push_back((*it).subs(ls,lr));
- }
- return s;
+ ${STLT} s;
+ RESERVE(s,seq.size());
+ for (${STLT}::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
+ s.push_back((*it).subs(ls,lr));
+ }
+ return s;
}
*/
${STLT} * ${CONTAINER}::subschildren(const lst & ls, const lst & lr) const
{
- // returns a NULL pointer if nothing had to be substituted
- // returns a pointer to a newly created epvector otherwise
- // (which has to be deleted somewhere else)
-
- ${STLT}::const_iterator last=seq.end();
- ${STLT}::const_iterator cit=seq.begin();
- while (cit!=last) {
- const ex & subsed_ex=(*cit).subs(ls,lr);
- if (!are_ex_trivially_equal(*cit,subsed_ex)) {
-
- // something changed, copy seq, subs and return it
- ${STLT} *s=new ${STLT};
- RESERVE(*s,seq.size());
-
- // copy parts of seq which are known not to have changed
- ${STLT}::const_iterator cit2=seq.begin();
- while (cit2!=cit) {
- s->push_back(*cit2);
- ++cit2;
- }
- // copy first changed element
- s->push_back(subsed_ex);
- ++cit2;
- // copy rest
- while (cit2!=last) {
- s->push_back((*cit2).subs(ls,lr));
- ++cit2;
- }
- return s;
- }
- ++cit;
- }
-
- return 0; // nothing has changed
+ // returns a NULL pointer if nothing had to be substituted
+ // returns a pointer to a newly created epvector otherwise
+ // (which has to be deleted somewhere else)
+
+ ${STLT}::const_iterator last=seq.end();
+ ${STLT}::const_iterator cit=seq.begin();
+ while (cit!=last) {
+ const ex & subsed_ex=(*cit).subs(ls,lr);
+ if (!are_ex_trivially_equal(*cit,subsed_ex)) {
+
+ // something changed, copy seq, subs and return it
+ ${STLT} *s=new ${STLT};
+ RESERVE(*s,seq.size());
+
+ // copy parts of seq which are known not to have changed
+ ${STLT}::const_iterator cit2=seq.begin();
+ while (cit2!=cit) {
+ s->push_back(*cit2);
+ ++cit2;
+ }
+ // copy first changed element
+ s->push_back(subsed_ex);
+ ++cit2;
+ // copy rest
+ while (cit2!=last) {
+ s->push_back((*cit2).subs(ls,lr));
+ ++cit2;
+ }
+ return s;
+ }
+ ++cit;
+ }
+
+ return 0; // nothing has changed
}
//////////
public:
ex()
#ifdef INLINE_EX_CONSTRUCTORS
- : bp(_ex0().bp)
- {
- GINAC_ASSERT(_ex0().bp!=0);
- GINAC_ASSERT(_ex0().bp->flags & status_flags::dynallocated);
- GINAC_ASSERT(bp!=0);
- ++bp->refcount;
+ : bp(_ex0().bp)
+ {
+ GINAC_ASSERT(_ex0().bp!=0);
+ GINAC_ASSERT(_ex0().bp->flags & status_flags::dynallocated);
+ GINAC_ASSERT(bp!=0);
+ ++bp->refcount;
#ifdef OBSCURE_CINT_HACK
- update_last_created_or_assigned_bp();
+ update_last_created_or_assigned_bp();
#endif // def OBSCURE_CINT_HACK
- }
+ }
#else
;
#endif // def INLINE_EX_CONSTRUCTORS
~ex()
#ifdef INLINE_EX_CONSTRUCTORS
- {
- GINAC_ASSERT(bp!=0);
- GINAC_ASSERT(bp->flags & status_flags::dynallocated);
- if (--bp->refcount == 0) {
- delete bp;
- }
+ {
+ GINAC_ASSERT(bp!=0);
+ GINAC_ASSERT(bp->flags & status_flags::dynallocated);
+ if (--bp->refcount == 0) {
+ delete bp;
}
+ }
#else
;
#endif // def INLINE_EX_CONSTRUCTORS
ex(const ex & other)
#ifdef INLINE_EX_CONSTRUCTORS
- : bp(other.bp)
- {
- GINAC_ASSERT(bp!=0);
- GINAC_ASSERT((bp->flags) & status_flags::dynallocated);
- ++bp->refcount;
+ : bp(other.bp)
+ {
+ GINAC_ASSERT(bp!=0);
+ GINAC_ASSERT((bp->flags) & status_flags::dynallocated);
+ ++bp->refcount;
#ifdef OBSCURE_CINT_HACK
- update_last_created_or_assigned_bp();
+ update_last_created_or_assigned_bp();
#endif // def OBSCURE_CINT_HACK
- }
+ }
#else
;
#endif // def INLINE_EX_CONSTRUCTORS
const ex & operator=(const ex & other)
#ifdef INLINE_EX_CONSTRUCTORS
- {
- GINAC_ASSERT(bp!=0);
- GINAC_ASSERT(bp->flags & status_flags::dynallocated);
- GINAC_ASSERT(other.bp!=0);
- GINAC_ASSERT(other.bp->flags & status_flags::dynallocated);
- ++other.bp->refcount;
- basic * tmpbp=other.bp;
- if (--bp->refcount==0) {
- delete bp;
- }
- bp=tmpbp;
+ {
+ GINAC_ASSERT(bp!=0);
+ GINAC_ASSERT(bp->flags & status_flags::dynallocated);
+ GINAC_ASSERT(other.bp!=0);
+ GINAC_ASSERT(other.bp->flags & status_flags::dynallocated);
+ ++other.bp->refcount;
+ basic * tmpbp=other.bp;
+ if (--bp->refcount==0) {
+ delete bp;
+ }
+ bp=tmpbp;
#ifdef OBSCURE_CINT_HACK
- update_last_created_or_assigned_bp();
+ update_last_created_or_assigned_bp();
#endif // def OBSCURE_CINT_HACK
- return *this;
- }
+ return *this;
+ }
#else
;
#endif // def INLINE_EX_CONSTRUCTORS
public:
ex(const basic & other)
#ifdef INLINE_EX_CONSTRUCTORS
- {
- construct_from_basic(other);
+ {
+ construct_from_basic(other);
#ifdef OBSCURE_CINT_HACK
- update_last_created_or_assigned_bp();
+ update_last_created_or_assigned_bp();
#endif // def OBSCURE_CINT_HACK
- }
+ }
#else
;
#endif // def INLINE_EX_CONSTRUCTORS
ex(int i)
#ifdef INLINE_EX_CONSTRUCTORS
- {
- construct_from_int(i);
+ {
+ construct_from_int(i);
#ifdef OBSCURE_CINT_HACK
- update_last_created_or_assigned_bp();
+ update_last_created_or_assigned_bp();
#endif // def OBSCURE_CINT_HACK
- }
+ }
#else
;
#endif // def INLINE_EX_CONSTRUCTORS
ex(unsigned int i)
#ifdef INLINE_EX_CONSTRUCTORS
- {
- construct_from_uint(i);
+ {
+ construct_from_uint(i);
#ifdef OBSCURE_CINT_HACK
- update_last_created_or_assigned_bp();
+ update_last_created_or_assigned_bp();
#endif // def OBSCURE_CINT_HACK
- }
+ }
#else
;
#endif // def INLINE_EX_CONSTRUCTORS
ex(long i)
#ifdef INLINE_EX_CONSTRUCTORS
- {
- construct_from_long(i);
+ {
+ construct_from_long(i);
#ifdef OBSCURE_CINT_HACK
- update_last_created_or_assigned_bp();
+ update_last_created_or_assigned_bp();
#endif // def OBSCURE_CINT_HACK
- }
+ }
#else
;
#endif // def INLINE_EX_CONSTRUCTORS
ex(unsigned long i)
#ifdef INLINE_EX_CONSTRUCTORS
- {
- construct_from_ulong(i);
+ {
+ construct_from_ulong(i);
#ifdef OBSCURE_CINT_HACK
- update_last_created_or_assigned_bp();
+ update_last_created_or_assigned_bp();
#endif // def OBSCURE_CINT_HACK
- }
+ }
#else
;
#endif // def INLINE_EX_CONSTRUCTORS
ex(double const d)
#ifdef INLINE_EX_CONSTRUCTORS
- {
- construct_from_double(d);
+ {
+ construct_from_double(d);
#ifdef OBSCURE_CINT_HACK
- update_last_created_or_assigned_bp();
+ update_last_created_or_assigned_bp();
#endif // def OBSCURE_CINT_HACK
- }
+ }
#else
;
#endif // def INLINE_EX_CONSTRUCTORS
* symbols and other parser errors will throw an exception. */
ex(const std::string &s, const ex &l)
#ifdef INLINE_EX_CONSTRUCTORS
- {
- construct_from_string_and_lst(s, l);
+ {
+ construct_from_string_and_lst(s, l);
#ifdef OBSCURE_CINT_HACK
- update_last_created_or_assigned_bp();
+ update_last_created_or_assigned_bp();
#endif // def OBSCURE_CINT_HACK
- }
+ }
#else
;
#endif // def INLINE_EX_CONSTRUCTORS
ex rhs(void) const;
int compare(const ex & other) const
#ifdef INLINE_EX_CONSTRUCTORS
- {
- GINAC_ASSERT(bp!=0);
- GINAC_ASSERT(other.bp!=0);
- if (bp==other.bp) {
- // special case: both expression point to same basic, trivially equal
- return 0;
- }
- return bp->compare(*other.bp);
+ {
+ GINAC_ASSERT(bp!=0);
+ GINAC_ASSERT(other.bp!=0);
+ if (bp==other.bp) {
+ // special case: both expression point to same basic, trivially equal
+ return 0;
}
+ return bp->compare(*other.bp);
+ }
#else
;
#endif // def INLINE_EX_CONSTRUCTORS
bool is_equal(const ex & other) const
#ifdef INLINE_EX_CONSTRUCTORS
- {
- GINAC_ASSERT(bp!=0);
- GINAC_ASSERT(other.bp!=0);
- if (bp==other.bp) {
- // special case: both expression point to same basic, trivially equal
- return true;
- }
- return bp->is_equal(*other.bp);
+ {
+ GINAC_ASSERT(bp!=0);
+ GINAC_ASSERT(other.bp!=0);
+ if (bp==other.bp) {
+ // special case: both expression point to same basic, trivially equal
+ return true;
}
+ return bp->is_equal(*other.bp);
+ }
#else
;
#endif // def INLINE_EX_CONSTRUCTORS
#ifdef OBSCURE_CINT_HACK
public:
static bool last_created_or_assigned_bp_can_be_converted_to_ex(void)
- {
- if (last_created_or_assigned_bp==0) return false;
- if ((last_created_or_assigned_bp->flags &
- status_flags::dynallocated)==0) return false;
- if ((last_created_or_assigned_bp->flags &
- status_flags::evaluated)==0) return false;
- return true;
- }
+ {
+ if (last_created_or_assigned_bp==0) return false;
+ if ((last_created_or_assigned_bp->flags &
+ status_flags::dynallocated)==0) return false;
+ if ((last_created_or_assigned_bp->flags &
+ status_flags::evaluated)==0) return false;
+ return true;
+ }
protected:
void update_last_created_or_assigned_bp(void)
- {
- if (last_created_or_assigned_bp!=0) {
- if (--last_created_or_assigned_bp->refcount == 0) {
- delete last_created_or_assigned_bp;
- }
+ {
+ if (last_created_or_assigned_bp!=0) {
+ if (--last_created_or_assigned_bp->refcount == 0) {
+ delete last_created_or_assigned_bp;
}
- last_created_or_assigned_bp=bp;
- ++last_created_or_assigned_bp->refcount;
- last_created_or_assigned_exp=(long)(void *)(this);
}
+ last_created_or_assigned_bp=bp;
+ ++last_created_or_assigned_bp->refcount;
+ last_created_or_assigned_exp=(long)(void *)(this);
+ }
#endif // def OBSCURE_CINT_HACK
// member variables
public:
expair() {}
~expair() {}
+
expair(const expair & other) : rest(other.rest), coeff(other.coeff)
{
GINAC_ASSERT(is_ex_exactly_of_type(coeff,numeric));
}
+
const expair & operator=(const expair & other)
{
if (this != &other) {
}
return *this;
}
+
expair(const ex & r, const ex & c) : rest(r), coeff(c)
{
GINAC_ASSERT(is_ex_exactly_of_type(coeff,numeric));
bool is_numeric_with_coeff_1(void) const
{
GINAC_ASSERT(is_ex_exactly_of_type(coeff,numeric));
- return is_ex_exactly_of_type(rest,numeric) &&
- (coeff.is_equal(ex(1)));
+ return is_ex_exactly_of_type(rest,numeric)
+ && (coeff.is_equal(ex(1)));
}
bool is_equal(const expair & other) const
{
return (rest.is_equal(other.rest) && coeff.is_equal(other.coeff));
}
+
bool is_less(const expair & other) const
{
- return (rest.compare(other.rest)<0) ||
- (!(other.rest.compare(rest)<0) && (coeff.compare(other.coeff)<0));
+ return (rest.compare(other.rest)<0)
+ || (!(other.rest.compare(rest)<0) && (coeff.compare(other.coeff)<0));
}
+
int compare(const expair & other) const
{
int cmpval=rest.compare(other.rest);
// only other has coeff 1: <
return true;
}
- return (rest.compare(other.rest)<0) ||
- (!(other.rest.compare(rest)<0) &&
- (coeff.compare(other.coeff)<0));
+ return (rest.compare(other.rest)<0)
+ || (!(other.rest.compare(rest)<0) && (coeff.compare(other.coeff)<0));
*/
if (is_ex_exactly_of_type(rest,numeric) &&
is_ex_exactly_of_type(other.rest,numeric)) {
}
// neither has coeff 1: usual compare
}
- return (rest.compare(other.rest)<0) ||
- (!(other.rest.compare(rest)<0) &&
- (coeff.compare(other.coeff)<0));
+ return (rest.compare(other.rest)<0)
+ || (!(other.rest.compare(rest)<0) && (coeff.compare(other.coeff)<0));
}
+
int compare_old2(const expair & other) const
{
if (is_ex_exactly_of_type(rest,numeric) &&
if (cmpval!=0) return cmpval;
return coeff.compare(other.coeff);
}
+
bool is_less_old(const expair & other) const
{
- return (rest.compare(other.rest)<0) ||
- (!(other.rest.compare(rest)<0) && (coeff.compare(other.coeff)<0));
+ return (rest.compare(other.rest)<0)
+ || (!(other.rest.compare(rest)<0) && (coeff.compare(other.coeff)<0));
}
int compare_old(const expair & other) const
{
public:
expairseq() : basic(TINFO_expairseq)
#ifdef EXPAIRSEQ_USE_HASHTAB
- , hashtabsize(0)
+ , hashtabsize(0)
#endif // def EXPAIRSEQ_USE_HASHTAB
- {
- }
+ {
+ }
~expairseq()
- {
- destroy(0);
- }
+ {
+ destroy(0);
+ }
expairseq(const expairseq & other);
const expairseq & operator=(const expairseq & other);
protected:
void copy(const expairseq & other);
void destroy(bool call_parent)
- {
- if (call_parent) basic::destroy(call_parent);
- };
+ {
+ if (call_parent) basic::destroy(call_parent);
+ };
// other constructors
public:
virtual ex thisexpairseq(const epvector & v, const ex & oc) const;
virtual ex thisexpairseq(epvector * vp, const ex & oc) const;
virtual void printseq(std::ostream & os, char delim,
- unsigned this_precedence,
- unsigned upper_precedence) const;
+ unsigned this_precedence,
+ unsigned upper_precedence) const;
virtual void printpair(std::ostream & os, const expair & p,
- unsigned upper_precedence) const;
+ unsigned upper_precedence) const;
virtual expair split_ex_to_pair(const ex & e) const;
virtual expair combine_ex_with_coeff_to_pair(const ex & e,
const ex & c) const;
void construct_from_2_ex_via_exvector(const ex & lh, const ex & rh);
void construct_from_2_ex(const ex & lh, const ex & rh);
void construct_from_2_expairseq(const expairseq & s1,
- const expairseq & s2);
+ const expairseq & s2);
void construct_from_expairseq_ex(const expairseq & s,
- const ex & e);
+ const ex & e);
void construct_from_exvector(const exvector & v);
void construct_from_epvector(const epvector & v);
void make_flat(const exvector & v);
void shrink_hashtab(void);
void remove_hashtab_entry(epvector::const_iterator element);
void move_hashtab_entry(epvector::const_iterator oldpos,
- epvector::iterator newpos);
+ epvector::iterator newpos);
void sorted_insert(epplist & eppl, epp elem);
void build_hashtab_and_combine(epvector::iterator & first_numeric,
- epvector::iterator & last_non_zero,
- vector<bool> & touched,
- unsigned & number_of_zeroes);
+ epvector::iterator & last_non_zero,
+ vector<bool> & touched,
+ unsigned & number_of_zeroes);
void drop_coeff_0_terms(epvector::iterator & first_numeric,
- epvector::iterator & last_non_zero,
- vector<bool> & touched,
- unsigned & number_of_zeroes);
+ epvector::iterator & last_non_zero,
+ vector<bool> & touched,
+ unsigned & number_of_zeroes);
bool has_coeff_0(void) const;
void add_numerics_to_hashtab(epvector::iterator first_numeric,
- epvector::const_iterator last_non_zero);
+ epvector::const_iterator last_non_zero);
#endif // def EXPAIRSEQ_USE_HASHTAB
bool is_canonical() const;
epvector * expandchildren(unsigned options) const;
class expand_options {
public:
- enum { expand_trigonometric = 0x0001
- };
+ enum {
+ expand_trigonometric = 0x0001
+ };
};
class series_options {
public:
- enum { suppress_branchcut = 0x0001
- };
+ enum {
+ suppress_branchcut = 0x0001
+ };
};
class determinant_algo {
public:
- enum { automatic,
- gauss,
- divfree,
- laplace,
- bareiss
- };
+ enum {
+ automatic,
+ gauss,
+ divfree,
+ laplace,
+ bareiss
+ };
};
class solve_algo {
public:
- enum { automatic,
- gauss,
- divfree,
- bareiss
- };
+ enum {
+ automatic,
+ gauss,
+ divfree,
+ bareiss
+ };
};
class status_flags {
public:
- enum { dynallocated = 0x0001,
- evaluated = 0x0002,
- expanded = 0x0004,
- hash_calculated = 0x0008
- };
+ enum {
+ dynallocated = 0x0001,
+ evaluated = 0x0002,
+ expanded = 0x0004,
+ hash_calculated = 0x0008
+ };
};
/** Possible attributes an object can have. */
class info_flags {
public:
enum {
- // answered by class numeric
- numeric,
- real,
- rational,
- integer,
- crational,
- cinteger,
- positive,
- negative,
- nonnegative,
- posint,
- negint,
- nonnegint,
- even,
- odd,
- prime,
-
- // answered by class relation
- relation,
- relation_equal,
- relation_not_equal,
- relation_less,
- relation_less_or_equal,
- relation_greater,
- relation_greater_or_equal,
-
- // answered by class symbol
- symbol,
-
- // answered by class lst
- list,
-
- // answered by class exprseq
- exprseq,
-
- // answered by classes numeric, symbol, add, mul, power
- polynomial,
- integer_polynomial,
- cinteger_polynomial,
- rational_polynomial,
- crational_polynomial,
- rational_function,
- algebraic,
-
- // answered by class indexed
- indexed, // class can carry indices
- has_indices, // object has at least one index
-
- // answered by class idx
- idx,
-
- // answered by class coloridx
- coloridx,
-
- // answered by class lorentzidx
- lorentzidx
+ // answered by class numeric
+ numeric,
+ real,
+ rational,
+ integer,
+ crational,
+ cinteger,
+ positive,
+ negative,
+ nonnegative,
+ posint,
+ negint,
+ nonnegint,
+ even,
+ odd,
+ prime,
+
+ // answered by class relation
+ relation,
+ relation_equal,
+ relation_not_equal,
+ relation_less,
+ relation_less_or_equal,
+ relation_greater,
+ relation_greater_or_equal,
+
+ // answered by class symbol
+ symbol,
+
+ // answered by class lst
+ list,
+
+ // answered by class exprseq
+ exprseq,
+
+ // answered by classes numeric, symbol, add, mul, power
+ polynomial,
+ integer_polynomial,
+ cinteger_polynomial,
+ rational_polynomial,
+ crational_polynomial,
+ rational_function,
+ algebraic,
+
+ // answered by class indexed
+ indexed, // class can carry indices
+ has_indices, // object has at least one index
+
+ // answered by class idx
+ idx,
+
+ // answered by class coloridx
+ coloridx,
+
+ // answered by class lorentzidx
+ lorentzidx
};
};
class return_types {
public:
- enum { commutative, noncommutative, noncommutative_composite};
+ enum {
+ commutative,
+ noncommutative,
+ noncommutative_composite
+ };
};
class csrc_types {
class remember_strategies {
public:
- enum { delete_never, // let table grow undefinitely, not recommmended, but currently default
- delete_lru, // least recently used
- delete_lfu, // least frequently used
- delete_cyclic // first (oldest) one in list
+ enum {
+ delete_never, // let table grow undefinitely, not recommmended, but currently default
+ delete_lru, // least recently used
+ delete_lfu, // least frequently used
+ delete_cyclic // first (oldest) one in list
};
};
$maxargs=13;
sub generate_seq {
- my ($seq_template,$n)=@_;
- my ($res,$N);
-
- $res='';
- for ($N=1; $N<=$n; $N++) {
- $res .= eval('"' . $seq_template . '"');
- if ($N!=$n) {
- $res .= ', ';
- }
- }
- return $res;
+ my ($seq_template,$n)=@_;
+ my ($res,$N);
+
+ $res='';
+ for ($N=1; $N<=$n; $N++) {
+ $res .= eval('"' . $seq_template . '"');
+ if ($N!=$n) {
+ $res .= ', ';
+ }
+ }
+ return $res;
}
sub generate_from_to {
- my ($template,$seq_template1,$seq_template2,$from,$to)=@_;
- my ($res,$N,$SEQ);
-
- $res='';
- for ($N=$from; $N<=$to; $N++) {
- $SEQ1=generate_seq($seq_template1,$N);
- $SEQ2=generate_seq($seq_template2,$N);
- $res .= eval('"' . $template . '"');
- $SEQ1=''; # to avoid main::SEQ1 used only once warning
- $SEQ2=''; # same as above
- }
- return $res;
+ my ($template,$seq_template1,$seq_template2,$from,$to)=@_;
+ my ($res,$N,$SEQ);
+
+ $res='';
+ for ($N=$from; $N<=$to; $N++) {
+ $SEQ1=generate_seq($seq_template1,$N);
+ $SEQ2=generate_seq($seq_template2,$N);
+ $res .= eval('"' . $template . '"');
+ $SEQ1=''; # to avoid main::SEQ1 used only once warning
+ $SEQ2=''; # same as above
+ }
+ return $res;
}
sub generate {
- my ($template,$seq_template1,$seq_template2)=@_;
- return generate_from_to($template,$seq_template1,$seq_template2,1,$maxargs);
+ my ($template,$seq_template1,$seq_template2)=@_;
+ return generate_from_to($template,$seq_template1,$seq_template2,1,$maxargs);
}
$declare_function_macro_namespace = <<'END_OF_DECLARE_FUNCTION_1_AND_2P_MACRO_NAMESPACE';
#define DECLARE_FUNCTION_1P(NAME) \
extern const unsigned function_index_##NAME; \
inline GiNaC::function NAME(const GiNaC::ex & p1) { \
- return GiNaC::function(function_index_##NAME, p1); \
+ return GiNaC::function(function_index_##NAME, p1); \
}
#define DECLARE_FUNCTION_2P(NAME) \
extern const unsigned function_index_##NAME; \
inline GiNaC::function NAME(const GiNaC::ex & p1, const GiNaC::ex & p2) { \
- return GiNaC::function(function_index_##NAME, p1, p2); \
+ return GiNaC::function(function_index_##NAME, p1, p2); \
}
END_OF_DECLARE_FUNCTION_1_AND_2P_MACRO_NAMESPACE
$declare_function_macro_namespace .= generate_from_to(
- <<'END_OF_DECLARE_FUNCTION_MACRO_NAMESPACE','const GiNaC::ex & p${N}','p${N}',3,$maxargs);
+ <<'END_OF_DECLARE_FUNCTION_MACRO_NAMESPACE','const GiNaC::ex & p${N}','p${N}',3,$maxargs);
#define DECLARE_FUNCTION_${N}P(NAME) \\
extern const unsigned function_index_##NAME; \\
inline GiNaC::function NAME(${SEQ1}) { \\
- return GiNaC::function(function_index_##NAME, ${SEQ2}); \\
+ return GiNaC::function(function_index_##NAME, ${SEQ2}); \\
}
END_OF_DECLARE_FUNCTION_MACRO_NAMESPACE
#define DECLARE_FUNCTION_1P(NAME) \
extern const unsigned function_index_##NAME; \
inline function NAME(const ex & p1) { \
- return function(function_index_##NAME, p1); \
+ return function(function_index_##NAME, p1); \
}
#define DECLARE_FUNCTION_2P(NAME) \
extern const unsigned function_index_##NAME; \
inline function NAME(const ex & p1, const ex & p2) { \
- return function(function_index_##NAME, p1, p2); \
+ return function(function_index_##NAME, p1, p2); \
}
END_OF_DECLARE_FUNCTION_1_AND_2P_MACRO_NO_NAMESPACE
$declare_function_macro_no_namespace .= generate_from_to(
- <<'END_OF_DECLARE_FUNCTION_MACRO_NO_NAMESPACE','const ex & p${N}','p${N}',3,$maxargs);
+ <<'END_OF_DECLARE_FUNCTION_MACRO_NO_NAMESPACE','const ex & p${N}','p${N}',3,$maxargs);
#define DECLARE_FUNCTION_${N}P(NAME) \\
extern const unsigned function_index_##NAME; \\
inline function NAME(${SEQ1}) { \\
- return function(function_index_##NAME, ${SEQ2}); \\
+ return function(function_index_##NAME, ${SEQ2}); \\
}
END_OF_DECLARE_FUNCTION_MACRO_NO_NAMESPACE
'const ex & param${N}','');
$constructors_implementation=generate(
- <<'END_OF_CONSTRUCTORS_IMPLEMENTATION','const ex & param${N}','param${N}');
+ <<'END_OF_CONSTRUCTORS_IMPLEMENTATION','const ex & param${N}','param${N}');
function::function(unsigned ser, ${SEQ1})
- : exprseq(${SEQ2}), serial(ser)
+ : exprseq(${SEQ2}), serial(ser)
{
- debugmsg(\"function constructor from unsigned,${N}*ex\",LOGLEVEL_CONSTRUCT);
- tinfo_key = TINFO_function;
+ debugmsg(\"function constructor from unsigned,${N}*ex\",LOGLEVEL_CONSTRUCT);
+ tinfo_key = TINFO_function;
}
END_OF_CONSTRUCTORS_IMPLEMENTATION
$eval_switch_statement=generate(
- <<'END_OF_EVAL_SWITCH_STATEMENT','seq[${N}-1]','');
- case ${N}:
- eval_result=((eval_funcp_${N})(registered_functions()[serial].eval_f))(${SEQ1});
- break;
+ <<'END_OF_EVAL_SWITCH_STATEMENT','seq[${N}-1]','');
+ case ${N}:
+ eval_result=((eval_funcp_${N})(registered_functions()[serial].eval_f))(${SEQ1});
+ break;
END_OF_EVAL_SWITCH_STATEMENT
$evalf_switch_statement=generate(
- <<'END_OF_EVALF_SWITCH_STATEMENT','eseq[${N}-1]','');
- case ${N}:
- return ((evalf_funcp_${N})(registered_functions()[serial].evalf_f))(${SEQ1});
- break;
+ <<'END_OF_EVALF_SWITCH_STATEMENT','eseq[${N}-1]','');
+ case ${N}:
+ return ((evalf_funcp_${N})(registered_functions()[serial].evalf_f))(${SEQ1});
+ break;
END_OF_EVALF_SWITCH_STATEMENT
$diff_switch_statement=generate(
- <<'END_OF_DIFF_SWITCH_STATEMENT','seq[${N}-1]','');
- case ${N}:
- return ((derivative_funcp_${N})(registered_functions()[serial].derivative_f))(${SEQ1},diff_param);
- break;
+ <<'END_OF_DIFF_SWITCH_STATEMENT','seq[${N}-1]','');
+ case ${N}:
+ return ((derivative_funcp_${N})(registered_functions()[serial].derivative_f))(${SEQ1},diff_param);
+ break;
END_OF_DIFF_SWITCH_STATEMENT
$series_switch_statement=generate(
- <<'END_OF_SERIES_SWITCH_STATEMENT','seq[${N}-1]','');
- case ${N}:
- try {
- res = ((series_funcp_${N})(registered_functions()[serial].series_f))(${SEQ1},r,order,options);
- } catch (do_taylor) {
- res = basic::series(r, order, options);
- }
- return res;
- break;
+ <<'END_OF_SERIES_SWITCH_STATEMENT','seq[${N}-1]','');
+ case ${N}:
+ try {
+ res = ((series_funcp_${N})(registered_functions()[serial].series_f))(${SEQ1},r,order,options);
+ } catch (do_taylor) {
+ res = basic::series(r, order, options);
+ }
+ return res;
+ break;
END_OF_SERIES_SWITCH_STATEMENT
$eval_func_implementation=generate(
- <<'END_OF_EVAL_FUNC_IMPLEMENTATION','','');
+ <<'END_OF_EVAL_FUNC_IMPLEMENTATION','','');
function_options & function_options::eval_func(eval_funcp_${N} e)
{
- test_and_set_nparams(${N});
- eval_f=eval_funcp(e);
- return *this;
+ test_and_set_nparams(${N});
+ eval_f=eval_funcp(e);
+ return *this;
}
END_OF_EVAL_FUNC_IMPLEMENTATION
$evalf_func_implementation=generate(
- <<'END_OF_EVALF_FUNC_IMPLEMENTATION','','');
+ <<'END_OF_EVALF_FUNC_IMPLEMENTATION','','');
function_options & function_options::evalf_func(evalf_funcp_${N} ef)
{
- test_and_set_nparams(${N});
- evalf_f=evalf_funcp(ef);
- return *this;
+ test_and_set_nparams(${N});
+ evalf_f=evalf_funcp(ef);
+ return *this;
}
END_OF_EVALF_FUNC_IMPLEMENTATION
$derivative_func_implementation=generate(
- <<'END_OF_DERIVATIVE_FUNC_IMPLEMENTATION','','');
+ <<'END_OF_DERIVATIVE_FUNC_IMPLEMENTATION','','');
function_options & function_options::derivative_func(derivative_funcp_${N} d)
{
- test_and_set_nparams(${N});
- derivative_f=derivative_funcp(d);
- return *this;
+ test_and_set_nparams(${N});
+ derivative_f=derivative_funcp(d);
+ return *this;
}
END_OF_DERIVATIVE_FUNC_IMPLEMENTATION
$series_func_implementation=generate(
- <<'END_OF_SERIES_FUNC_IMPLEMENTATION','','');
+ <<'END_OF_SERIES_FUNC_IMPLEMENTATION','','');
function_options & function_options::series_func(series_funcp_${N} s)
{
- test_and_set_nparams(${N});
- series_f=series_funcp(s);
- return *this;
+ test_and_set_nparams(${N});
+ series_f=series_funcp(s);
+ return *this;
}
END_OF_SERIES_FUNC_IMPLEMENTATION
#define REGISTER_FUNCTION(NAME,OPT) \\
const unsigned function_index_##NAME= \\
- GiNaC::function::register_new(GiNaC::function_options(#NAME).OPT);
+ GiNaC::function::register_new(GiNaC::function_options(#NAME).OPT);
#define REGISTER_FUNCTION_OLD(NAME,E,EF,D,S) \\
const unsigned function_index_##NAME= \\
- GiNaC::function::register_new(GiNaC::function_options(#NAME). \\
- eval_func(E). \\
- evalf_func(EF). \\
- derivative_func(D). \\
- series_func(S));
+ GiNaC::function::register_new(GiNaC::function_options(#NAME). \\
+ eval_func(E). \\
+ evalf_func(EF). \\
+ derivative_func(D). \\
+ series_func(S));
#else // ndef NO_NAMESPACE_GINAC
#define REGISTER_FUNCTION(NAME,OPT) \\
const unsigned function_index_##NAME= \\
- function::register_new(function_options(#NAME).OPT);
+ function::register_new(function_options(#NAME).OPT);
#define REGISTER_FUNCTION_OLD(NAME,E,EF,D,S) \\
const unsigned function_index_##NAME= \\
- function::register_new(function_options(#NAME). \\
- eval_func(E). \\
- evalf_func(EF). \\
- derivative_func(D). \\
- series_func(S));
+ function::register_new(function_options(#NAME). \\
+ eval_func(E). \\
+ evalf_func(EF). \\
+ derivative_func(D). \\
+ series_func(S));
#endif // ndef NO_NAMESPACE_GINAC
#define TYPECHECK(VAR,TYPE) \\
if (!is_ex_exactly_of_type(VAR,TYPE)) { \\
- automatic_typecheck=false; \\
+ automatic_typecheck=false; \\
} else
#ifndef NO_NAMESPACE_GINAC
#define TYPECHECK_INTEGER(VAR) \\
if (!(VAR).info(GiNaC::info_flags::integer)) { \\
- automatic_typecheck=false; \\
+ automatic_typecheck=false; \\
} else
#else // ndef NO_NAMESPACE_GINAC
#define TYPECHECK_INTEGER(VAR) \\
if (!(VAR).info(info_flags::integer)) { \\
- automatic_typecheck=false; \\
+ automatic_typecheck=false; \\
} else
#endif // ndef NO_NAMESPACE_GINAC
#define END_TYPECHECK(RV) \\
{} \\
if (!automatic_typecheck) { \\
- return RV.hold(); \\
+ return RV.hold(); \\
}
#ifndef NO_NAMESPACE_GINAC
class function_options
{
- friend class function;
+ friend class function;
public:
- function_options();
- function_options(std::string const & n, std::string const & tn=std::string());
- ~function_options();
- void initialize(void);
- function_options & set_name(std::string const & n, std::string const & tn=std::string());
+ function_options();
+ function_options(std::string const & n, std::string const & tn=std::string());
+ ~function_options();
+ void initialize(void);
+ function_options & set_name(std::string const & n, std::string const & tn=std::string());
// the following lines have been generated for max. ${maxargs} parameters
$eval_func_interface
$evalf_func_interface
$derivative_func_interface
$series_func_interface
// end of generated lines
- function_options & set_return_type(unsigned rt, unsigned rtt=0);
- function_options & do_not_evalf_params(void);
- function_options & remember(unsigned size, unsigned assoc_size=0,
- unsigned strategy=remember_strategies::delete_never);
- function_options & overloaded(unsigned o);
- void test_and_set_nparams(unsigned n);
- std::string get_name(void) const { return name; }
- unsigned get_nparams(void) const { return nparams; }
+ function_options & set_return_type(unsigned rt, unsigned rtt=0);
+ function_options & do_not_evalf_params(void);
+ function_options & remember(unsigned size, unsigned assoc_size=0,
+ unsigned strategy=remember_strategies::delete_never);
+ function_options & overloaded(unsigned o);
+ void test_and_set_nparams(unsigned n);
+ std::string get_name(void) const { return name; }
+ unsigned get_nparams(void) const { return nparams; }
protected:
- std::string name;
- std::string TeX_name;
+ std::string name;
+ std::string TeX_name;
- unsigned nparams;
+ unsigned nparams;
- eval_funcp eval_f;
- evalf_funcp evalf_f;
- derivative_funcp derivative_f;
- series_funcp series_f;
+ eval_funcp eval_f;
+ evalf_funcp evalf_f;
+ derivative_funcp derivative_f;
+ series_funcp series_f;
- bool evalf_params_first;
+ bool evalf_params_first;
- bool use_return_type;
- unsigned return_type;
- unsigned return_type_tinfo;
+ bool use_return_type;
+ unsigned return_type;
+ unsigned return_type_tinfo;
- bool use_remember;
- unsigned remember_size;
- unsigned remember_assoc_size;
- unsigned remember_strategy;
+ bool use_remember;
+ unsigned remember_size;
+ unsigned remember_assoc_size;
+ unsigned remember_strategy;
- unsigned functions_with_same_name;
+ unsigned functions_with_same_name;
};
/** The class function is used to implement builtin functions like sin, cos...
- and user defined functions */
+ and user defined functions */
class function : public exprseq
{
- GINAC_DECLARE_REGISTERED_CLASS(function, exprseq)
+ GINAC_DECLARE_REGISTERED_CLASS(function, exprseq)
- // CINT has a linking problem
+ // CINT has a linking problem
#ifndef __MAKECINT__
- friend void ginsh_get_ginac_functions(void);
+ friend void ginsh_get_ginac_functions(void);
#endif // def __MAKECINT__
- friend class remember_table_entry;
- // friend class remember_table_list;
- // friend class remember_table;
+ friend class remember_table_entry;
+ // friend class remember_table_list;
+ // friend class remember_table;
// member functions
- // default constructor, destructor, copy constructor assignment operator and helpers
+ // default constructor, destructor, copy constructor assignment operator and helpers
public:
- function();
- ~function();
- function(const function & other);
- const function & operator=(const function & other);
+ function();
+ ~function();
+ function(const function & other);
+ const function & operator=(const function & other);
protected:
- void copy(const function & other);
- void destroy(bool call_parent);
+ void copy(const function & other);
+ void destroy(bool call_parent);
- // other constructors
+ // other constructors
public:
- function(unsigned ser);
- // the following lines have been generated for max. ${maxargs} parameters
+ function(unsigned ser);
+ // the following lines have been generated for max. ${maxargs} parameters
$constructors_interface
- // end of generated lines
- function(unsigned ser, const exprseq & es);
- function(unsigned ser, const exvector & v, bool discardable=0);
- function(unsigned ser, exvector * vp); // vp will be deleted
+ // end of generated lines
+ function(unsigned ser, const exprseq & es);
+ function(unsigned ser, const exvector & v, bool discardable=0);
+ function(unsigned ser, exvector * vp); // vp will be deleted
- // functions overriding virtual functions from bases classes
+ // functions overriding virtual functions from bases classes
public:
- basic * duplicate() const;
- void printraw(std::ostream & os) const;
- void print(std::ostream & os, unsigned upper_precedence=0) const;
- void printtree(std::ostream & os, unsigned indent) const;
- void printcsrc(std::ostream & os, unsigned type, unsigned upper_precedence=0) const;
- ex expand(unsigned options=0) const;
- ex eval(int level=0) const;
- ex evalf(int level=0) const;
- ex series(const relational & r, int order, unsigned options = 0) const;
- ex thisexprseq(const exvector & v) const;
- ex thisexprseq(exvector * vp) const;
+ basic * duplicate() const;
+ void printraw(std::ostream & os) const;
+ void print(std::ostream & os, unsigned upper_precedence=0) const;
+ void printtree(std::ostream & os, unsigned indent) const;
+ void printcsrc(std::ostream & os, unsigned type, unsigned upper_precedence=0) const;
+ ex expand(unsigned options=0) const;
+ ex eval(int level=0) const;
+ ex evalf(int level=0) const;
+ ex series(const relational & r, int order, unsigned options = 0) const;
+ ex thisexprseq(const exvector & v) const;
+ ex thisexprseq(exvector * vp) const;
protected:
- ex derivative(const symbol & s) const;
- int compare_same_type(const basic & other) const;
- bool is_equal_same_type(const basic & other) const;
- unsigned return_type(void) const;
- unsigned return_type_tinfo(void) const;
-
- // new virtual functions which can be overridden by derived classes
- // none
-
- // non-virtual functions in this class
+ ex derivative(const symbol & s) const;
+ int compare_same_type(const basic & other) const;
+ bool is_equal_same_type(const basic & other) const;
+ unsigned return_type(void) const;
+ unsigned return_type_tinfo(void) const;
+
+ // new virtual functions which can be overridden by derived classes
+ // none
+
+ // non-virtual functions in this class
protected:
- ex pderivative(unsigned diff_param) const; // partial differentiation
- static std::vector<function_options> & registered_functions(void);
- bool lookup_remember_table(ex & result) const;
- void store_remember_table(ex const & result) const;
+ ex pderivative(unsigned diff_param) const; // partial differentiation
+ static std::vector<function_options> & registered_functions(void);
+ bool lookup_remember_table(ex & result) const;
+ void store_remember_table(ex const & result) const;
public:
- static unsigned register_new(function_options const & opt);
- static unsigned find_function(const std::string &name, unsigned nparams);
- unsigned getserial(void) const {return serial;}
-
+ static unsigned register_new(function_options const & opt);
+ static unsigned find_function(const std::string &name, unsigned nparams);
+ unsigned getserial(void) const {return serial;}
+
// member variables
protected:
- unsigned serial;
+ unsigned serial;
};
// utility functions/macros
inline const function &ex_to_function(const ex &e)
{
- return static_cast<const function &>(*e.bp);
+ return static_cast<const function &>(*e.bp);
}
#ifndef NO_NAMESPACE_GINAC
#define is_ex_the_function(OBJ, FUNCNAME) \\
- (is_ex_exactly_of_type(OBJ, function) && static_cast<GiNaC::function *>(OBJ.bp)->getserial() == function_index_##FUNCNAME)
+ (is_ex_exactly_of_type(OBJ, function) && static_cast<GiNaC::function *>(OBJ.bp)->getserial() == function_index_##FUNCNAME)
#else // ndef NO_NAMESPACE_GINAC
#define is_ex_the_function(OBJ, FUNCNAME) \\
- (is_ex_exactly_of_type(OBJ, function) && static_cast<function *>(OBJ.bp)->getserial() == function_index_##FUNCNAME)
+ (is_ex_exactly_of_type(OBJ, function) && static_cast<function *>(OBJ.bp)->getserial() == function_index_##FUNCNAME)
#endif // ndef NO_NAMESPACE_GINAC
function_options::function_options()
{
- initialize();
+ initialize();
}
function_options::function_options(std::string const & n, std::string const & tn)
{
- initialize();
- set_name(n,tn);
+ initialize();
+ set_name(n,tn);
}
function_options::~function_options()
{
- // nothing to clean up at the moment
+ // nothing to clean up at the moment
}
void function_options::initialize(void)
{
- set_name("unnamed_function","\\\\operatorname{unnamed}");
- nparams=0;
- eval_f=evalf_f=derivative_f=series_f=0;
- evalf_params_first=true;
- use_return_type=false;
- use_remember=false;
- functions_with_same_name=1;
+ set_name("unnamed_function","\\\\operatorname{unnamed}");
+ nparams=0;
+ eval_f=evalf_f=derivative_f=series_f=0;
+ evalf_params_first=true;
+ use_return_type=false;
+ use_remember=false;
+ functions_with_same_name=1;
}
function_options & function_options::set_name(std::string const & n,
std::string const & tn)
{
- name=n;
- if (tn==std::string()) {
- TeX_name="\\\\operatorname{"+name+"}";
- } else {
- TeX_name=tn;
- }
- return *this;
+ name=n;
+ if (tn==std::string()) {
+ TeX_name="\\\\operatorname{"+name+"}";
+ } else {
+ TeX_name=tn;
+ }
+ return *this;
}
// the following lines have been generated for max. ${maxargs} parameters
function_options & function_options::set_return_type(unsigned rt, unsigned rtt)
{
- use_return_type=true;
- return_type=rt;
- return_type_tinfo=rtt;
- return *this;
+ use_return_type=true;
+ return_type=rt;
+ return_type_tinfo=rtt;
+ return *this;
}
function_options & function_options::do_not_evalf_params(void)
{
- evalf_params_first=false;
- return *this;
+ evalf_params_first=false;
+ return *this;
}
function_options & function_options::remember(unsigned size,
unsigned assoc_size,
unsigned strategy)
{
- use_remember=true;
- remember_size=size;
- remember_assoc_size=assoc_size;
- remember_strategy=strategy;
- return *this;
+ use_remember=true;
+ remember_size=size;
+ remember_assoc_size=assoc_size;
+ remember_strategy=strategy;
+ return *this;
}
function_options & function_options::overloaded(unsigned o)
{
- functions_with_same_name=o;
- return *this;
+ functions_with_same_name=o;
+ return *this;
}
-
+
void function_options::test_and_set_nparams(unsigned n)
{
- if (nparams==0) {
- nparams=n;
- } else if (nparams!=n) {
- // we do not throw an exception here because this code is
- // usually executed before main(), so the exception could not
- // caught anyhow
- std::cerr << "WARNING: number of parameters ("
- << n << ") differs from number set before ("
- << nparams << ")" << std::endl;
- }
+ if (nparams==0) {
+ nparams=n;
+ } else if (nparams!=n) {
+ // we do not throw an exception here because this code is
+ // usually executed before main(), so the exception could not
+ // caught anyhow
+ std::cerr << "WARNING: number of parameters ("
+ << n << ") differs from number set before ("
+ << nparams << ")" << std::endl;
+ }
}
GINAC_IMPLEMENT_REGISTERED_CLASS(function, exprseq)
function::function() : serial(0)
{
- debugmsg("function default constructor",LOGLEVEL_CONSTRUCT);
- tinfo_key = TINFO_function;
+ debugmsg("function default constructor",LOGLEVEL_CONSTRUCT);
+ tinfo_key = TINFO_function;
}
function::~function()
{
- debugmsg("function destructor",LOGLEVEL_DESTRUCT);
- destroy(0);
+ debugmsg("function destructor",LOGLEVEL_DESTRUCT);
+ destroy(0);
}
function::function(const function & other)
{
- debugmsg("function copy constructor",LOGLEVEL_CONSTRUCT);
- copy(other);
+ debugmsg("function copy constructor",LOGLEVEL_CONSTRUCT);
+ copy(other);
}
const function & function::operator=(const function & other)
{
- debugmsg("function operator=",LOGLEVEL_ASSIGNMENT);
- if (this != &other) {
- destroy(1);
- copy(other);
- }
- return *this;
+ debugmsg("function operator=",LOGLEVEL_ASSIGNMENT);
+ if (this != &other) {
+ destroy(1);
+ copy(other);
+ }
+ return *this;
}
// protected
void function::copy(const function & other)
{
- exprseq::copy(other);
- serial=other.serial;
+ exprseq::copy(other);
+ serial=other.serial;
}
void function::destroy(bool call_parent)
{
- if (call_parent) exprseq::destroy(call_parent);
+ if (call_parent) exprseq::destroy(call_parent);
}
//////////
function::function(unsigned ser) : serial(ser)
{
- debugmsg("function constructor from unsigned",LOGLEVEL_CONSTRUCT);
- tinfo_key = TINFO_function;
+ debugmsg("function constructor from unsigned",LOGLEVEL_CONSTRUCT);
+ tinfo_key = TINFO_function;
}
// the following lines have been generated for max. ${maxargs} parameters
function::function(unsigned ser, const exprseq & es) : exprseq(es), serial(ser)
{
- debugmsg("function constructor from unsigned,exprseq",LOGLEVEL_CONSTRUCT);
- tinfo_key = TINFO_function;
+ debugmsg("function constructor from unsigned,exprseq",LOGLEVEL_CONSTRUCT);
+ tinfo_key = TINFO_function;
}
function::function(unsigned ser, const exvector & v, bool discardable)
- : exprseq(v,discardable), serial(ser)
+ : exprseq(v,discardable), serial(ser)
{
- debugmsg("function constructor from string,exvector,bool",LOGLEVEL_CONSTRUCT);
- tinfo_key = TINFO_function;
+ debugmsg("function constructor from string,exvector,bool",LOGLEVEL_CONSTRUCT);
+ tinfo_key = TINFO_function;
}
function::function(unsigned ser, exvector * vp)
- : exprseq(vp), serial(ser)
+ : exprseq(vp), serial(ser)
{
- debugmsg("function constructor from unsigned,exvector *",LOGLEVEL_CONSTRUCT);
- tinfo_key = TINFO_function;
+ debugmsg("function constructor from unsigned,exvector *",LOGLEVEL_CONSTRUCT);
+ tinfo_key = TINFO_function;
}
//////////
/** Construct object from archive_node. */
function::function(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst)
{
- debugmsg("function constructor from archive_node", LOGLEVEL_CONSTRUCT);
-
- // Find serial number by function name
- std::string s;
- if (n.find_string("name", s)) {
- unsigned int ser = 0;
- std::vector<function_options>::const_iterator i = registered_functions().begin(), iend = registered_functions().end();
- while (i != iend) {
- if (s == i->name) {
- serial = ser;
- return;
- }
- i++; ser++;
- }
- throw (std::runtime_error("unknown function '" + s + "' in archive"));
- } else
- throw (std::runtime_error("unnamed function in archive"));
+ debugmsg("function constructor from archive_node", LOGLEVEL_CONSTRUCT);
+
+ // Find serial number by function name
+ std::string s;
+ if (n.find_string("name", s)) {
+ unsigned int ser = 0;
+ std::vector<function_options>::const_iterator i = registered_functions().begin(), iend = registered_functions().end();
+ while (i != iend) {
+ if (s == i->name) {
+ serial = ser;
+ return;
+ }
+ i++; ser++;
+ }
+ throw (std::runtime_error("unknown function '" + s + "' in archive"));
+ } else
+ throw (std::runtime_error("unnamed function in archive"));
}
/** Unarchive the object. */
ex function::unarchive(const archive_node &n, const lst &sym_lst)
{
- return (new function(n, sym_lst))->setflag(status_flags::dynallocated);
+ return (new function(n, sym_lst))->setflag(status_flags::dynallocated);
}
/** Archive the object. */
void function::archive(archive_node &n) const
{
- inherited::archive(n);
- GINAC_ASSERT(serial < registered_functions().size());
- n.add_string("name", registered_functions()[serial].name);
+ inherited::archive(n);
+ GINAC_ASSERT(serial < registered_functions().size());
+ n.add_string("name", registered_functions()[serial].name);
}
//////////
basic * function::duplicate() const
{
- debugmsg("function duplicate",LOGLEVEL_DUPLICATE);
- return new function(*this);
+ debugmsg("function duplicate",LOGLEVEL_DUPLICATE);
+ return new function(*this);
}
void function::printraw(std::ostream & os) const
{
- debugmsg("function printraw",LOGLEVEL_PRINT);
+ debugmsg("function printraw",LOGLEVEL_PRINT);
- GINAC_ASSERT(serial<registered_functions().size());
+ GINAC_ASSERT(serial<registered_functions().size());
- os << "function(name=" << registered_functions()[serial].name;
- for (exvector::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
- os << ",";
- (*it).bp->print(os);
- }
- os << ")";
+ os << "function(name=" << registered_functions()[serial].name;
+ for (exvector::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
+ os << ",";
+ (*it).bp->print(os);
+ }
+ os << ")";
}
void function::print(std::ostream & os, unsigned upper_precedence) const
{
- debugmsg("function print",LOGLEVEL_PRINT);
+ debugmsg("function print",LOGLEVEL_PRINT);
- GINAC_ASSERT(serial<registered_functions().size());
+ GINAC_ASSERT(serial<registered_functions().size());
- os << registered_functions()[serial].name;
- printseq(os,'(',',',')',exprseq::precedence,function::precedence);
+ os << registered_functions()[serial].name;
+ printseq(os,'(',',',')',exprseq::precedence,function::precedence);
}
void function::printtree(std::ostream & os, unsigned indent) const
{
- debugmsg("function printtree",LOGLEVEL_PRINT);
-
- GINAC_ASSERT(serial<registered_functions().size());
-
- os << std::string(indent,' ') << "function "
- << registered_functions()[serial].name
- << ", hash=" << hashvalue
- << " (0x" << std::hex << hashvalue << std::dec << ")"
- << ", flags=" << flags
- << ", nops=" << nops() << std::endl;
- for (unsigned i=0; i<nops(); ++i) {
- seq[i].printtree(os,indent+delta_indent);
- }
- os << std::string(indent+delta_indent,' ') << "=====" << std::endl;
+ debugmsg("function printtree",LOGLEVEL_PRINT);
+
+ GINAC_ASSERT(serial<registered_functions().size());
+
+ os << std::string(indent,' ') << "function "
+ << registered_functions()[serial].name
+ << ", hash=" << hashvalue
+ << " (0x" << std::hex << hashvalue << std::dec << ")"
+ << ", flags=" << flags
+ << ", nops=" << nops() << std::endl;
+ for (unsigned i=0; i<nops(); ++i) {
+ seq[i].printtree(os,indent+delta_indent);
+ }
+ os << std::string(indent+delta_indent,' ') << "=====" << std::endl;
}
void function::printcsrc(std::ostream & os, unsigned type, unsigned upper_precedence) const
{
- debugmsg("function print csrc",LOGLEVEL_PRINT);
+ debugmsg("function print csrc",LOGLEVEL_PRINT);
- GINAC_ASSERT(serial<registered_functions().size());
+ GINAC_ASSERT(serial<registered_functions().size());
// Print function name in lowercase
- std::string lname;
- lname=registered_functions()[serial].name;
- for (unsigned i=0; i<lname.size(); i++)
- lname[i] = tolower(lname[i]);
- os << lname << "(";
+ std::string lname;
+ lname=registered_functions()[serial].name;
+ for (unsigned i=0; i<lname.size(); i++)
+ lname[i] = tolower(lname[i]);
+ os << lname << "(";
// Print arguments, separated by commas
- exvector::const_iterator it = seq.begin();
- exvector::const_iterator itend = seq.end();
- while (it != itend) {
- it->bp->printcsrc(os, type, 0);
- it++;
- if (it != itend)
- os << ",";
- }
- os << ")";
+ exvector::const_iterator it = seq.begin();
+ exvector::const_iterator itend = seq.end();
+ while (it != itend) {
+ it->bp->printcsrc(os, type, 0);
+ it++;
+ if (it != itend)
+ os << ",";
+ }
+ os << ")";
}
ex function::expand(unsigned options) const
{
- return this->setflag(status_flags::expanded);
+ return this->setflag(status_flags::expanded);
}
ex function::eval(int level) const
{
- GINAC_ASSERT(serial<registered_functions().size());
+ GINAC_ASSERT(serial<registered_functions().size());
- if (level>1) {
- // first evaluate children, then we will end up here again
- return function(serial,evalchildren(level));
- }
+ if (level>1) {
+ // first evaluate children, then we will end up here again
+ return function(serial,evalchildren(level));
+ }
- if (registered_functions()[serial].eval_f==0) {
- return this->hold();
- }
+ if (registered_functions()[serial].eval_f==0) {
+ return this->hold();
+ }
- bool use_remember=registered_functions()[serial].use_remember;
- ex eval_result;
- if (use_remember && lookup_remember_table(eval_result)) {
- return eval_result;
- }
+ bool use_remember=registered_functions()[serial].use_remember;
+ ex eval_result;
+ if (use_remember && lookup_remember_table(eval_result)) {
+ return eval_result;
+ }
- switch (registered_functions()[serial].nparams) {
- // the following lines have been generated for max. ${maxargs} parameters
+ switch (registered_functions()[serial].nparams) {
+ // the following lines have been generated for max. ${maxargs} parameters
${eval_switch_statement}
- // end of generated lines
- default:
- throw(std::logic_error("function::eval(): invalid nparams"));
- }
- if (use_remember) {
- store_remember_table(eval_result);
- }
- return eval_result;
+ // end of generated lines
+ default:
+ throw(std::logic_error("function::eval(): invalid nparams"));
+ }
+ if (use_remember) {
+ store_remember_table(eval_result);
+ }
+ return eval_result;
}
ex function::evalf(int level) const
{
- GINAC_ASSERT(serial<registered_functions().size());
-
- exvector eseq=evalfchildren(level);
-
- if (registered_functions()[serial].evalf_f==0) {
- return function(serial,eseq).hold();
- }
- switch (registered_functions()[serial].nparams) {
- // the following lines have been generated for max. ${maxargs} parameters
+ GINAC_ASSERT(serial<registered_functions().size());
+
+ exvector eseq=evalfchildren(level);
+
+ if (registered_functions()[serial].evalf_f==0) {
+ return function(serial,eseq).hold();
+ }
+ switch (registered_functions()[serial].nparams) {
+ // the following lines have been generated for max. ${maxargs} parameters
${evalf_switch_statement}
- // end of generated lines
- }
- throw(std::logic_error("function::evalf(): invalid nparams"));
+ // end of generated lines
+ }
+ throw(std::logic_error("function::evalf(): invalid nparams"));
}
ex function::thisexprseq(const exvector & v) const
{
- return function(serial,v);
+ return function(serial,v);
}
ex function::thisexprseq(exvector * vp) const
{
- return function(serial,vp);
+ return function(serial,vp);
}
/** Implementation of ex::series for functions.
* \@see ex::series */
ex function::series(const relational & r, int order, unsigned options = 0) const
{
- GINAC_ASSERT(serial<registered_functions().size());
-
- if (registered_functions()[serial].series_f==0) {
- return basic::series(r, order);
- }
- ex res;
- switch (registered_functions()[serial].nparams) {
- // the following lines have been generated for max. ${maxargs} parameters
+ GINAC_ASSERT(serial<registered_functions().size());
+
+ if (registered_functions()[serial].series_f==0) {
+ return basic::series(r, order);
+ }
+ ex res;
+ switch (registered_functions()[serial].nparams) {
+ // the following lines have been generated for max. ${maxargs} parameters
${series_switch_statement}
- // end of generated lines
- }
- throw(std::logic_error("function::series(): invalid nparams"));
+ // end of generated lines
+ }
+ throw(std::logic_error("function::series(): invalid nparams"));
}
// protected
* \@see ex::diff */
ex function::derivative(const symbol & s) const
{
- ex result;
-
- if (serial == function_index_Order) {
- // Order Term function only differentiates the argument
- return Order(seq[0].diff(s));
- } else if (serial == function_index_Derivative) {
- // Inert derivative performs chain rule on the first argument only, and
- // adds differentiation parameter to list (second argument)
- GINAC_ASSERT(is_ex_exactly_of_type(seq[0], function));
- GINAC_ASSERT(is_ex_exactly_of_type(seq[1], function));
- ex fcn = seq[0];
- ex arg_diff;
- for (unsigned i=0; i!=fcn.nops(); i++) {
- arg_diff = fcn.op(i).diff(s);
- if (!arg_diff.is_zero()) {
- lst new_lst = ex_to_lst(seq[1]);
- new_lst.append(i);
- result += arg_diff * Derivative(fcn, new_lst);
- }
- }
- } else {
- // Chain rule
- ex arg_diff;
- for (unsigned i=0; i!=seq.size(); i++) {
- arg_diff = seq[i].diff(s);
- // We apply the chain rule only when it makes sense. This is not
- // just for performance reasons but also to allow functions to
- // throw when differentiated with respect to one of its arguments
- // without running into trouble with our automatic full
- // differentiation:
- if (!arg_diff.is_zero())
- result += pderivative(i)*arg_diff;
- }
- }
- return result;
+ ex result;
+
+ if (serial == function_index_Order) {
+ // Order Term function only differentiates the argument
+ return Order(seq[0].diff(s));
+ } else if (serial == function_index_Derivative) {
+ // Inert derivative performs chain rule on the first argument only, and
+ // adds differentiation parameter to list (second argument)
+ GINAC_ASSERT(is_ex_exactly_of_type(seq[0], function));
+ GINAC_ASSERT(is_ex_exactly_of_type(seq[1], function));
+ ex fcn = seq[0];
+ ex arg_diff;
+ for (unsigned i=0; i!=fcn.nops(); i++) {
+ arg_diff = fcn.op(i).diff(s);
+ if (!arg_diff.is_zero()) {
+ lst new_lst = ex_to_lst(seq[1]);
+ new_lst.append(i);
+ result += arg_diff * Derivative(fcn, new_lst);
+ }
+ }
+ } else {
+ // Chain rule
+ ex arg_diff;
+ for (unsigned i=0; i!=seq.size(); i++) {
+ arg_diff = seq[i].diff(s);
+ // We apply the chain rule only when it makes sense. This is not
+ // just for performance reasons but also to allow functions to
+ // throw when differentiated with respect to one of its arguments
+ // without running into trouble with our automatic full
+ // differentiation:
+ if (!arg_diff.is_zero())
+ result += pderivative(i)*arg_diff;
+ }
+ }
+ return result;
}
int function::compare_same_type(const basic & other) const
{
- GINAC_ASSERT(is_of_type(other, function));
- const function & o=static_cast<function &>(const_cast<basic &>(other));
+ GINAC_ASSERT(is_of_type(other, function));
+ const function & o=static_cast<function &>(const_cast<basic &>(other));
- if (serial!=o.serial) {
- return serial < o.serial ? -1 : 1;
- }
- return exprseq::compare_same_type(o);
+ if (serial!=o.serial) {
+ return serial < o.serial ? -1 : 1;
+ }
+ return exprseq::compare_same_type(o);
}
bool function::is_equal_same_type(const basic & other) const
{
- GINAC_ASSERT(is_of_type(other, function));
- const function & o=static_cast<function &>(const_cast<basic &>(other));
+ GINAC_ASSERT(is_of_type(other, function));
+ const function & o=static_cast<function &>(const_cast<basic &>(other));
- if (serial!=o.serial) return false;
- return exprseq::is_equal_same_type(o);
+ if (serial!=o.serial) return false;
+ return exprseq::is_equal_same_type(o);
}
unsigned function::return_type(void) const
{
- if (seq.size()==0) {
- return return_types::commutative;
- }
- return (*seq.begin()).return_type();
+ if (seq.size()==0) {
+ return return_types::commutative;
+ }
+ return (*seq.begin()).return_type();
}
unsigned function::return_type_tinfo(void) const
{
- if (seq.size()==0) {
- return tinfo_key;
- }
- return (*seq.begin()).return_type_tinfo();
+ if (seq.size()==0) {
+ return tinfo_key;
+ }
+ return (*seq.begin()).return_type_tinfo();
}
//////////
ex function::pderivative(unsigned diff_param) const // partial differentiation
{
- GINAC_ASSERT(serial<registered_functions().size());
-
- if (registered_functions()[serial].derivative_f==0) {
- return Derivative(*this, lst(diff_param));
- }
- switch (registered_functions()[serial].nparams) {
- // the following lines have been generated for max. ${maxargs} parameters
+ GINAC_ASSERT(serial<registered_functions().size());
+
+ if (registered_functions()[serial].derivative_f==0) {
+ return Derivative(*this, lst(diff_param));
+ }
+ switch (registered_functions()[serial].nparams) {
+ // the following lines have been generated for max. ${maxargs} parameters
${diff_switch_statement}
- // end of generated lines
- }
- throw(std::logic_error("function::pderivative(): no diff function defined"));
+ // end of generated lines
+ }
+ throw(std::logic_error("function::pderivative(): no diff function defined"));
}
std::vector<function_options> & function::registered_functions(void)
{
- static std::vector<function_options> * rf = new std::vector<function_options>;
- return *rf;
+ static std::vector<function_options> * rf = new std::vector<function_options>;
+ return *rf;
}
bool function::lookup_remember_table(ex & result) const
{
- return remember_table::remember_tables()[serial].lookup_entry(*this,result);
+ return remember_table::remember_tables()[serial].lookup_entry(*this,result);
}
void function::store_remember_table(ex const & result) const
{
- remember_table::remember_tables()[serial].add_entry(*this,result);
+ remember_table::remember_tables()[serial].add_entry(*this,result);
}
// public
unsigned function::register_new(function_options const & opt)
{
- unsigned same_name=0;
- for (unsigned i=0; i<registered_functions().size(); ++i) {
- if (registered_functions()[i].name==opt.name) {
- same_name++;
- }
- }
- if (same_name>=opt.functions_with_same_name) {
- // we do not throw an exception here because this code is
- // usually executed before main(), so the exception could not
- // caught anyhow
- std::cerr << "WARNING: function name " << opt.name
- << " already in use!" << std::endl;
- }
- registered_functions().push_back(opt);
- if (opt.use_remember) {
- remember_table::remember_tables().
- push_back(remember_table(opt.remember_size,
- opt.remember_assoc_size,
- opt.remember_strategy));
- } else {
- remember_table::remember_tables().push_back(remember_table());
- }
- return registered_functions().size()-1;
+ unsigned same_name=0;
+ for (unsigned i=0; i<registered_functions().size(); ++i) {
+ if (registered_functions()[i].name==opt.name) {
+ same_name++;
+ }
+ }
+ if (same_name>=opt.functions_with_same_name) {
+ // we do not throw an exception here because this code is
+ // usually executed before main(), so the exception could not
+ // caught anyhow
+ std::cerr << "WARNING: function name " << opt.name
+ << " already in use!" << std::endl;
+ }
+ registered_functions().push_back(opt);
+ if (opt.use_remember) {
+ remember_table::remember_tables().
+ push_back(remember_table(opt.remember_size,
+ opt.remember_assoc_size,
+ opt.remember_strategy));
+ } else {
+ remember_table::remember_tables().push_back(remember_table());
+ }
+ return registered_functions().size()-1;
}
/** Find serial number of function by name and number of parameters.
* Throws exception if function was not found. */
unsigned function::find_function(const std::string &name, unsigned nparams)
{
- std::vector<function_options>::const_iterator i = function::registered_functions().begin(), end = function::registered_functions().end();
- unsigned serial = 0;
- while (i != end) {
- if (i->get_name() == name && i->get_nparams() == nparams)
- return serial;
- i++;
- serial++;
- }
- throw (std::runtime_error("no function '" + name + "' with " + ToString(nparams) + " parameters defined"));
+ std::vector<function_options>::const_iterator i = function::registered_functions().begin(), end = function::registered_functions().end();
+ unsigned serial = 0;
+ while (i != end) {
+ if (i->get_name() == name && i->get_nparams() == nparams)
+ return serial;
+ i++;
+ serial++;
+ }
+ throw (std::runtime_error("no function '" + name + "' with " + ToString(nparams) + " parameters defined"));
}
//////////
int canonicalize_indices(exvector & iv, bool antisymmetric=false);
exvector idx_intersect(const exvector & iv1, const exvector & iv2);
ex permute_free_index_to_front(const exvector & iv3, const exvector & iv2,
- bool antisymmetric, int * sig);
+ bool antisymmetric, int * sig);
unsigned subs_index_in_exvector(exvector & v, const ex & is, const ex & ir);
ex subs_indices(const ex & e, const exvector & idxv_contra,
- const exvector & idxv_co);
+ const exvector & idxv_co);
unsigned count_index(const ex & e, const ex & i);
#ifndef NO_NAMESPACE_GINAC
public:
explicit lorentzidx(bool cov, bool oonly=false, unsigned dimp=0);
explicit lorentzidx(const std::string & n, bool cov=false,
- bool oonly=false, unsigned dimp=0);
+ bool oonly=false, unsigned dimp=0);
explicit lorentzidx(const char * n, bool cov=false,
- bool oonly=false, unsigned dimp=0);
+ bool oonly=false, unsigned dimp=0);
explicit lorentzidx(unsigned v, bool cov=false);
// functions overriding virtual functions from bases classes
/** Base class for lortensor object */
class lortensor : public indexed
{
- // friends
friend lortensor lortensor_g(const ex & mu, const ex & nu);
// friend lortensor lortensor_delta(const ex & mu, const ex & nu);
friend lortensor lortensor_epsilon(const ex & mu, const ex & nu,
friend ex simplify_lortensor(const ex & e);
// types
-
public:
- typedef enum { invalid,
- lortensor_g,
- lortensor_rankn,
- lortensor_rank1,
- lortensor_rank2,
- // lortensor_delta,
- lortensor_epsilon
+ typedef enum {
+ invalid,
+ lortensor_g,
+ lortensor_rankn,
+ lortensor_rank1,
+ lortensor_rank2,
+ // lortensor_delta,
+ lortensor_epsilon
} lortensor_types;
// member functions
lortensor(lortensor_types const lt, const std::string & n);
lortensor(lortensor_types const lt, const std::string & n, const ex & mu);
lortensor(lortensor_types const lt, const std::string & n, const ex & mu, const ex & nu);
- lortensor(lortensor_types const lt, const std::string & n, const ex & mu, const ex & nu,
- const ex & rho);
+ lortensor(lortensor_types const lt, const std::string & n, const ex & mu, const ex & nu, const ex & rho);
lortensor(lortensor_types const lt, const std::string & n, const ex & mu, const ex & nu, const ex & rho, const ex & sigma);
lortensor(lortensor_types const lt, const std::string & n, const exvector & iv);
lortensor(lortensor_types const lt, const std::string & n, unsigned s, const exvector & iv);
ex charpoly(const symbol & lambda) const;
matrix inverse(void) const;
matrix solve(const matrix & vars, const matrix & rhs,
- unsigned algo = solve_algo::automatic) const;
+ unsigned algo = solve_algo::automatic) const;
protected:
ex determinant_minor(void) const;
int gauss_elimination(const bool det = false);
ncmul(const ex & lh, const ex & rh);
ncmul(const ex & f1, const ex & f2, const ex & f3);
ncmul(const ex & f1, const ex & f2, const ex & f3,
- const ex & f4);
+ const ex & f4);
ncmul(const ex & f1, const ex & f2, const ex & f3,
- const ex & f4, const ex & f5);
+ const ex & f4, const ex & f5);
ncmul(const ex & f1, const ex & f2, const ex & f3,
- const ex & f4, const ex & f5, const ex & f6);
+ const ex & f4, const ex & f5, const ex & f6);
ncmul(const exvector & v, bool discardable=false);
ncmul(exvector * vp); // vp will be deleted
#include "basic.h"
#include "ex.h"
-class cl_N; // We want to include cln.h only in numeric.cpp in order to
- // avoid namespace pollution and keep compile-time low.
+class cl_N; // We want to include cln.h only in numeric.cpp in order to
+ // avoid namespace pollution and keep compile-time low.
#ifndef NO_NAMESPACE_GINAC
namespace GiNaC {
ex expand_add_2(const add & a) const;
ex expand_mul(const mul & m, const numeric & n) const;
//ex expand_commutative_3(const ex & basis, const numeric & exponent,
- // unsigned options) const;
- // ex expand_noncommutative(const ex & basis, const numeric & exponent, unsigned options) const;
+ // unsigned options) const;
+ //ex expand_noncommutative(const ex & basis, const numeric & exponent, unsigned options) const;
// member variables
first_registered_class = this;
}
- registered_class_info *next; /**< Pointer to next registered_class_info in list. */
- const char *name; /**< Class name. */
- const char *super; /**< Name of superclass. */
- unsigned int tinfo_key; /**< TINFO_* key. */
- unarch_func unarchive; /**< Pointer to unarchiving function. */
+ registered_class_info *next; /**< Pointer to next registered_class_info in list. */
+ const char *name; /**< Class name. */
+ const char *super; /**< Name of superclass. */
+ unsigned int tinfo_key; /**< TINFO_* key. */
+ unarch_func unarchive; /**< Pointer to unarchiving function. */
};
// types
public:
- enum operators { equal,
- not_equal,
- less,
- less_or_equal,
- greater,
- greater_or_equal
+ enum operators {
+ equal,
+ not_equal,
+ less,
+ less_or_equal,
+ greater,
+ greater_or_equal
};
// member functions
class ex;
/** A single entry in the remember table of a function.
- Needs to be a friend of class function to access 'seq'.
- 'last_access' and 'successful_hits' are updated at each successful
- 'is_equal'. */
+ * Needs to be a friend of class function to access 'seq'.
+ * 'last_access' and 'successful_hits' are updated at each successful
+ * 'is_equal'. */
class remember_table_entry {
public:
remember_table_entry(function const & f, ex const & r);
};
/** A list of entries in the remember table having some least
- significant bits of the hashvalue in common. */
+ * significant bits of the hashvalue in common. */
class remember_table_list : public std::list<remember_table_entry> {
public:
remember_table_list(unsigned as, unsigned strat);
};
/** The remember table is organized like an n-fold associative cache
- in a microprocessor. The table has a width of 's' (which is rounded
- to table_size, some power of 2 near 's', internally) and a depth of 'as'
- (unless you choose that entries are never discarded). The place where
- an entry is stored depends on the hashvalue of the parameters of the
- function (this corresponds to the address of byte to be cached).
- The 'log_2(table_size)' least significant bits of this hashvalue
- give the slot in which the entry will be stored or looked up.
- Each slot can take up to 'as' entries. If a slot is full, an older
- entry is removed by one of the following strategies:
- - oldest entry (the first one in the list)
- - least recently used (the one with the lowest 'last_access')
- - least frequently used (the one with the lowest 'successful_hits')
- or all entries are kept which means that the table grows indefinitely. */
+ * in a microprocessor. The table has a width of 's' (which is rounded
+ * to table_size, some power of 2 near 's', internally) and a depth of 'as'
+ * (unless you choose that entries are never discarded). The place where
+ * an entry is stored depends on the hashvalue of the parameters of the
+ * function (this corresponds to the address of byte to be cached).
+ * The 'log_2(table_size)' least significant bits of this hashvalue
+ * give the slot in which the entry will be stored or looked up.
+ * Each slot can take up to 'as' entries. If a slot is full, an older
+ * entry is removed by one of the following strategies:
+ * - oldest entry (the first one in the list)
+ * - least recently used (the one with the lowest 'last_access')
+ * - least frequently used (the one with the lowest 'successful_hits')
+ * or all entries are kept which means that the table grows indefinitely. */
class remember_table : public std::vector<remember_table_list> {
public:
remember_table();
rh.second.printraw(cerr);
cerr << ")" << endl;
*/
- bool res=lh.first<rh.first ||
- (!(rh.first<lh.first) && lh.second.compare(rh.second)<0 );
+ bool res = lh.first<rh.first
+ || (!(rh.first<lh.first) && lh.second.compare(rh.second)<0);
// cout << "result=" << res << endl;
return res;
}
// types
public:
- typedef enum { invalid, // not properly constructed by one of the friend functions
- simp_lor_g,
- simp_lor_vec
+ typedef enum {
+ invalid, // not properly constructed by one of the friend functions
+ simp_lor_g,
+ simp_lor_vec
} simp_lor_types;
// member functions
$input_structure='';
$original_input_structure='';
while (<>) {
- $input_structure .= '// '.$_;
- $original_input_structure .= $_;
+ $input_structure .= '// '.$_;
+ $original_input_structure .= $_;
}
$original_input_structure =~ tr/ \t\n\r\f/ /;
$original_input_structure =~ tr/ //s;
if ($original_input_structure =~ /^struct (\w+) ?\{ ?(.*)\}\;? ?$/) {
- $STRUCTURE=$1;
- $decl=$2;
+ $STRUCTURE=$1;
+ $decl=$2;
} else {
- die "illegal struct, must match 'struct name { type var; /*comment*/ ...};': $original_input_structure";
+ die "illegal struct, must match 'struct name { type var; /*comment*/ ...};': $original_input_structure";
}
# split off a part 'type var[,var...];' with a possible C-comment '/* ... */'
while ($decl =~ /^ ?(\w+) ([\w \,]+)\; ?((\/\*.*?\*\/)?)(.*)$/) {
- $type=$1;
- $member=$2;
- $comment=$3;
- $decl=$5;
- while ($member =~ /^(\w+) ?\, ?(.*)$/) {
- push @TYPES,$type;
- push @MEMBERS,$1;
- push @COMMENTS,$comment;
- if ($comment ne '') {
- $comment='/* see above */';
- }
- $member=$2;
- }
- if ($member !~ /^\w+$/) {
- die "illegal struct, must match 'struct name { type var; /*comment*/ ...};': $input_structure";
- }
- push @TYPES,$type;
- push @MEMBERS,$member;
- push @COMMENTS,$comment;
+ $type=$1;
+ $member=$2;
+ $comment=$3;
+ $decl=$5;
+ while ($member =~ /^(\w+) ?\, ?(.*)$/) {
+ push @TYPES,$type;
+ push @MEMBERS,$1;
+ push @COMMENTS,$comment;
+ if ($comment ne '') {
+ $comment='/* see above */';
+ }
+ $member=$2;
+ }
+ if ($member !~ /^\w+$/) {
+ die "illegal struct, must match 'struct name { type var; /*comment*/ ...};': $input_structure";
+ }
+ push @TYPES,$type;
+ push @MEMBERS,$member;
+ push @COMMENTS,$comment;
}
if ($decl !~ /^ ?$/) {
- die "illegal struct, must match 'struct name { type var; /*comment*/ ...};': $input_structure";
+ die "illegal struct, must match 'struct name { type var; /*comment*/ ...};': $input_structure";
}
#$STRUCTURE='teststruct';
#@MEMBERS=('q10','q20','q21');
sub generate {
- my ($template,$conj)=@_;
- my ($res,$N);
-
- $res='';
- for ($N=1; $N<=$#MEMBERS+1; $N++) {
- $TYPE=$TYPES[$N-1];
- $MEMBER=$MEMBERS[$N-1];
- $COMMENT=$COMMENTS[$N-1];
- $res .= eval('"' . $template . '"');
- $TYPE=''; # to avoid main::TYPE used only once warning
- $MEMBER=''; # same as above
- $COMMENT=''; # same as above
- if ($N!=$#MEMBERS+1) {
- $res .= $conj;
- }
- }
- return $res;
+ my ($template,$conj)=@_;
+ my ($res,$N);
+
+ $res='';
+ for ($N=1; $N<=$#MEMBERS+1; $N++) {
+ $TYPE=$TYPES[$N-1];
+ $MEMBER=$MEMBERS[$N-1];
+ $COMMENT=$COMMENTS[$N-1];
+ $res .= eval('"' . $template . '"');
+ $TYPE=''; # to avoid main::TYPE used only once warning
+ $MEMBER=''; # same as above
+ $COMMENT=''; # same as above
+ if ($N!=$#MEMBERS+1) {
+ $res .= $conj;
+ }
+ }
+ return $res;
}
$number_of_members=$#MEMBERS+1;
{
// member functions
- // default constructor, destructor, copy constructor assignment operator and helpers
+ // default constructor, destructor, copy constructor assignment operator and helpers
public:
- ${STRUCTURE}();
- ~${STRUCTURE}();
- ${STRUCTURE}(${STRUCTURE} const & other);
- ${STRUCTURE} const & operator=(${STRUCTURE} const & other);
+ ${STRUCTURE}();
+ ~${STRUCTURE}();
+ ${STRUCTURE}(${STRUCTURE} const & other);
+ ${STRUCTURE} const & operator=(${STRUCTURE} const & other);
protected:
- void copy(${STRUCTURE} const & other);
- void destroy(bool call_parent);
+ void copy(${STRUCTURE} const & other);
+ void destroy(bool call_parent);
- // other constructors
+ // other constructors
public:
- ${STRUCTURE}(${constructor_arglist});
+ ${STRUCTURE}(${constructor_arglist});
- // functions overriding virtual functions from bases classes
+ // functions overriding virtual functions from bases classes
public:
- basic * duplicate() const;
- void printraw(ostream & os) const;
- void print(ostream & os, unsigned upper_precedence=0) const;
- void printtree(ostream & os, unsigned indent) const;
- int nops() const;
- ex & let_op(int i);
- ex expand(unsigned options=0) const;
- bool has(const ex & other) const;
- ex eval(int level=0) const;
- ex evalf(int level=0) const;
- ex normal(lst &sym_lst, lst &repl_lst, int level=0) const;
- ex diff(const symbol & s) const;
- ex subs(const lst & ls, const lst & lr) const;
+ basic * duplicate() const;
+ void printraw(ostream & os) const;
+ void print(ostream & os, unsigned upper_precedence=0) const;
+ void printtree(ostream & os, unsigned indent) const;
+ int nops() const;
+ ex & let_op(int i);
+ ex expand(unsigned options=0) const;
+ bool has(const ex & other) const;
+ ex eval(int level=0) const;
+ ex evalf(int level=0) const;
+ ex normal(lst &sym_lst, lst &repl_lst, int level=0) const;
+ ex diff(const symbol & s) const;
+ ex subs(const lst & ls, const lst & lr) const;
protected:
- int compare_same_type(const basic & other) const;
- bool is_equal_same_type(const basic & other) const;
- unsigned return_type(void) const;
+ int compare_same_type(const basic & other) const;
+ bool is_equal_same_type(const basic & other) const;
+ unsigned return_type(void) const;
- // new virtual functions which can be overridden by derived classes
- // none
+ // new virtual functions which can be overridden by derived classes
+ // none
- // non-virtual functions in this class
+ // non-virtual functions in this class
public:
${member_access_functions}
- bool types_ok(void) const;
-
+ bool types_ok(void) const;
+
// member variables
protected:
${members}
${STRUCTURE}::${STRUCTURE}()
{
- debugmsg("${STRUCTURE} default constructor",LOGLEVEL_CONSTRUCT);
- tinfo_key=tinfo_${STRUCTURE};
+ debugmsg("${STRUCTURE} default constructor",LOGLEVEL_CONSTRUCT);
+ tinfo_key=tinfo_${STRUCTURE};
}
${STRUCTURE}::~${STRUCTURE}()
{
- debugmsg("${STRUCTURE} destructor",LOGLEVEL_DESTRUCT);
- destroy(0);
+ debugmsg("${STRUCTURE} destructor",LOGLEVEL_DESTRUCT);
+ destroy(0);
}
${STRUCTURE}::${STRUCTURE}(${STRUCTURE} const & other)
{
- debugmsg("${STRUCTURE} copy constructor",LOGLEVEL_CONSTRUCT);
- copy(other);
+ debugmsg("${STRUCTURE} copy constructor",LOGLEVEL_CONSTRUCT);
+ copy(other);
}
${STRUCTURE} const & ${STRUCTURE}::operator=(${STRUCTURE} const & other)
{
- debugmsg("${STRUCTURE} operator=",LOGLEVEL_ASSIGNMENT);
- if (this != &other) {
- destroy(1);
- copy(other);
- }
- return *this;
+ debugmsg("${STRUCTURE} operator=",LOGLEVEL_ASSIGNMENT);
+ if (this != &other) {
+ destroy(1);
+ copy(other);
+ }
+ return *this;
}
// protected
void ${STRUCTURE}::copy(${STRUCTURE} const & other)
{
- structure::copy(other);
+ structure::copy(other);
${copy_statements}
}
void ${STRUCTURE}::destroy(bool call_parent)
{
- if (call_parent) structure::destroy(call_parent);
+ if (call_parent) structure::destroy(call_parent);
}
//////////
// public
${STRUCTURE}::${STRUCTURE}(${constructor_arglist})
- : ${constructor_statements}
+ : ${constructor_statements}
{
- debugmsg("${STRUCTURE} constructor from children",
- LOGLEVEL_CONSTRUCT);
- tinfo_key=tinfo_${STRUCTURE};
+ debugmsg("${STRUCTURE} constructor from children", LOGLEVEL_CONSTRUCT);
+ tinfo_key=tinfo_${STRUCTURE};
}
//////////
basic * ${STRUCTURE}::duplicate() const
{
- debugmsg("${STRUCTURE} duplicate",LOGLEVEL_DUPLICATE);
- return new ${STRUCTURE}(*this);
+ debugmsg("${STRUCTURE} duplicate",LOGLEVEL_DUPLICATE);
+ return new ${STRUCTURE}(*this);
}
void ${STRUCTURE}::printraw(ostream & os) const
{
- debugmsg("${STRUCTURE} printraw",LOGLEVEL_PRINT);
- os << "${STRUCTURE}()";
+ debugmsg("${STRUCTURE} printraw",LOGLEVEL_PRINT);
+ os << "${STRUCTURE}()";
}
void ${STRUCTURE}::print(ostream & os, unsigned upper_precedence) const
{
- debugmsg("${STRUCTURE} print",LOGLEVEL_PRINT);
- os << "${STRUCTURE}()";
+ debugmsg("${STRUCTURE} print",LOGLEVEL_PRINT);
+ os << "${STRUCTURE}()";
}
void ${STRUCTURE}::printtree(ostream & os, unsigned indent) const
{
- debugmsg("${STRUCTURE} printtree",LOGLEVEL_PRINT);
- os << "${STRUCTURE}()";
+ debugmsg("${STRUCTURE} printtree",LOGLEVEL_PRINT);
+ os << "${STRUCTURE}()";
}
int ${STRUCTURE}::nops() const
{
- return ${number_of_members};
+ return ${number_of_members};
}
ex & ${STRUCTURE}::let_op(int i)
{
- GINAC_ASSERT(i>=0);
- GINAC_ASSERT(i<nops());
+ GINAC_ASSERT(i>=0);
+ GINAC_ASSERT(i<nops());
- switch (i) {
+ switch (i) {
${let_op_statements}
- }
- errormsg("${STRUCTURE}::let_op(): should not reach this point");
- return *new ex(fail());
+ }
+ errormsg("${STRUCTURE}::let_op(): should not reach this point");
+ return *new ex(fail());
}
ex ${STRUCTURE}::expand(unsigned options) const
{
- bool all_are_trivially_equal=true;
+ bool all_are_trivially_equal=true;
${expand_statements}
- if (all_are_trivially_equal) {
- return *this;
- }
- return ${STRUCTURE}(${temporary_arglist});
+ if (all_are_trivially_equal) {
+ return *this;
+ }
+ return ${STRUCTURE}(${temporary_arglist});
}
// a ${STRUCTURE} 'has' an expression if it is this expression itself or a child 'has' it
bool ${STRUCTURE}::has(const ex & other) const
{
- GINAC_ASSERT(other.bp!=0);
- if (is_equal(*other.bp)) return true;
+ GINAC_ASSERT(other.bp!=0);
+ if (is_equal(*other.bp)) return true;
${has_statements}
- return false;
+ return false;
}
ex ${STRUCTURE}::eval(int level) const
{
- if (level==1) {
- return this->hold();
- }
- bool all_are_trivially_equal=true;
+ if (level==1) {
+ return this->hold();
+ }
+ bool all_are_trivially_equal=true;
${eval_statements}
- if (all_are_trivially_equal) {
- return this->hold();
- }
- return ${STRUCTURE}(${temporary_arglist});
+ if (all_are_trivially_equal) {
+ return this->hold();
+ }
+ return ${STRUCTURE}(${temporary_arglist});
}
ex ${STRUCTURE}::evalf(int level) const
{
- if (level==1) {
- return *this;
- }
- bool all_are_trivially_equal=true;
+ if (level==1) {
+ return *this;
+ }
+ bool all_are_trivially_equal=true;
${evalf_statements}
- if (all_are_trivially_equal) {
- return *this;
- }
- return ${STRUCTURE}(${temporary_arglist});
+ if (all_are_trivially_equal) {
+ return *this;
+ }
+ return ${STRUCTURE}(${temporary_arglist});
}
/** Implementation of ex::normal() for ${STRUCTURE}s. It normalizes the arguments
* \@see ex::normal */
ex ${STRUCTURE}::normal(lst &sym_lst, lst &repl_lst, int level) const
{
- if (level==1) {
- return basic::normal(sym_lst,repl_lst,level);
- }
- bool all_are_trivially_equal=true;
+ if (level==1) {
+ return basic::normal(sym_lst,repl_lst,level);
+ }
+ bool all_are_trivially_equal=true;
${normal_statements}
- if (all_are_trivially_equal) {
- return basic::normal(sym_lst,repl_lst,level);
- }
- ex n=${STRUCTURE}(${temporary_arglist});
- return n.bp->basic::normal(sym_lst,repl_lst,level);
+ if (all_are_trivially_equal) {
+ return basic::normal(sym_lst,repl_lst,level);
+ }
+ ex n=${STRUCTURE}(${temporary_arglist});
+ return n.bp->basic::normal(sym_lst,repl_lst,level);
}
/** ${STRUCTURE}::diff() differentiates the children.
- there is no need to check for triavially equal, since diff usually
- does not return itself unevaluated. */
+ there is no need to check for triavially equal, since diff usually
+ does not return itself unevaluated. */
ex ${STRUCTURE}::diff(const symbol & s) const
{
${diff_statements}
- return ${STRUCTURE}(${temporary_arglist});
+ return ${STRUCTURE}(${temporary_arglist});
}
ex ${STRUCTURE}::subs(const lst & ls, const lst & lr) const
{
- bool all_are_trivially_equal=true;
+ bool all_are_trivially_equal=true;
${subs_statements}
- if (all_are_trivially_equal) {
- return *this;
- }
- return ${STRUCTURE}(${temporary_arglist});
+ if (all_are_trivially_equal) {
+ return *this;
+ }
+ return ${STRUCTURE}(${temporary_arglist});
}
// protected
int ${STRUCTURE}::compare_same_type(const basic & other) const
{
- GINAC_ASSERT(is_of_type(other,${STRUCTURE}));
- ${STRUCTURE} const & o=static_cast<${STRUCTURE} const &>
- (const_cast<basic &>(other));
- int cmpval;
+ GINAC_ASSERT(is_of_type(other,${STRUCTURE}));
+ ${STRUCTURE} const & o=static_cast<${STRUCTURE} const &>
+ (const_cast<basic &>(other));
+ int cmpval;
${compare_statements}
- return 0;
+ return 0;
}
bool ${STRUCTURE}::is_equal_same_type(const basic & other) const
{
- GINAC_ASSERT(is_of_type(other,${STRUCTURE}));
- ${STRUCTURE} const & o=static_cast<${STRUCTURE} const &>
- (const_cast<basic &>(other));
+ GINAC_ASSERT(is_of_type(other,${STRUCTURE}));
+ ${STRUCTURE} const & o=static_cast<${STRUCTURE} const &>
+ (const_cast<basic &>(other));
${is_equal_statements}
- return true;
+ return true;
}
unsigned ${STRUCTURE}::return_type(void) const
{
- return return_types::noncommutative_composite;
+ return return_types::noncommutative_composite;
}
//////////
bool ${STRUCTURE}::types_ok(void) const
{
${types_ok_statements}
- return true;
+ return true;
}
//////////
}
// modified from stl_algo.h: always do com(*first1,*first2) instead of comp(*first2,*first1)
-template <class InputIterator1, class InputIterator2, class OutputIterator,
- class Compare>
+template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
OutputIterator mymerge(InputIterator1 first1, InputIterator1 last1,
- InputIterator2 first2, InputIterator2 last2,
- OutputIterator result, Compare comp) {
+ InputIterator2 first2, InputIterator2 last2,
+ OutputIterator result, Compare comp) {
while (first1 != last1 && first2 != last2) {
if (comp(*first1, *first2)) {
*result = *first1;
// like merge(), but three lists with *last2<*first3
template <class InputIterator1, class InputIterator2, class InputIterator3,
- class OutputIterator, class Compare>
+ class OutputIterator, class Compare>
OutputIterator mymerge3(InputIterator1 first1, InputIterator1 last1,
- InputIterator2 first2, InputIterator2 last2,
- InputIterator3 first3, InputIterator3 last3,
- OutputIterator result, Compare comp) {
+ InputIterator2 first2, InputIterator2 last2,
+ InputIterator3 first3, InputIterator3 last3,
+ OutputIterator result, Compare comp) {
while (first1 != last1 && first2 != last2) {
if (comp(*first1, *first2)) {
*result = *first1;