[GiNaC-list] let_op() and index

mdias at ift.unesp.br mdias at ift.unesp.br
Sat Feb 26 23:12:06 CET 2005

Thanks Chris,

 I would like that my class covdiff be inherited form indexed. I make this a
child class, remove new_index member, but I stupidly cant remove index and arg.
I dont have idea to define for example the method compare_same_type, without
using this. But the question is: It prints my covdiff ok:

D~gamma (A~beta.c)
but when a subs(gamma=nu):
and returns to be a indexed, not a covdiff object. there is a example to write a
subs code like this?

Thanks a lot,


class covdiff : public indexed{

  covdiff(ex arg, ex i1);
  ex &  let_op(size_t i);
   ex subs(const lst & ls, const lst & lr, unsigned options =0) const;
  size_t nops() const;
   ex op(size_t i) const;
ex index;
ex arg;
  void do_print(const print_context &c, unsigned level = 0) const;

covdiff::covdiff(ex arg_, ex i1_): indexed(arg_,i1_),arg(arg_),index(i1_){  
  tinfo_key = TINFO_covdiff;
int covdiff::compare_same_type(const basic &other) const
const covdiff &o = static_cast<const covdiff &>(other);
 if(arg != o.arg){
   //diferent  arg
   return arg < o.arg ? -1 : 1;
 return inherited::compare_same_type(other);

> Well, you made covdiff inherit from indexed. Indexed already has a .subs()
> method that comes from the type container that it is based on, so you are
> actually subsing in the underlying indexed object. You could, of course,
> add your own .subs()-method, but before you do so, you should ask yourself
> wheter inheriting from indexed is really what you want to do. If you want
> to inherit from indexed, why do you need to define your own member
> variables index and arg? Indexed already has the data structures to hold
> these. Also, making these public looks like a bad idea. Furthermore, why
> does this class have a member index and besides that a member new_index?
> If I were to write such a class, my first inclination would be to indeed
> try to make it a child class of indexed, but then to simply hold an
> integer that would hold, say 3, if the indexed object has 3 indices and
> further indices indicate differentiation. This would behave more or less
> as expected with respect to summations conventions and so on.
> Best wishes,
> Chris
> _______________________________________________
> GiNaC-list mailing list
> GiNaC-list at ginac.de
> http://thep.physik.uni-mainz.de/mailman/listinfo/ginac-list

This mail sent through IMP: http://horde.org/imp/

More information about the GiNaC-list mailing list