Hi guys, I have a simple question. I would like to construct a derived class of indexed type, folowing the final part of tutorial. How can I inherit simplify_indexed()? For example: class Myclass : public indexed{ .... } Myclass(ex b, idx a), indexed(b,a) { ... } Myclass::simplify_indexed() { I don't know!!! } Thanks in advance, Marco ------------------------------------------------- This mail sent through IMP: http://horde.org/imp/
Hi! On Tue, Mar 15, 2005 at 06:54:01PM -0300, mdias@ift.unesp.br wrote:
I have a simple question. I would like to construct a derived class of indexed type, folowing the final part of tutorial. How can I inherit simplify_indexed()?
You can't, as there is no member function simplify_indexed(). What you can override is eval_indexed() (for automatic evaluation) and contract_with()/add_indexed()/scalar_mul_indexed() (for manual evaluation, AKA simplify_indexed()). However, these are not methods of the 'indexed' class but of the base objects that are being indexed. You probably don't need to subclass 'indexed' at all. The library is designed in a way that allows putting nearly all relevant properties of indexed expressions into their base objects. If you still want to do it: take a look at GiNaC's 'color' class (color.h/color.cpp) which is pretty minimal, except for its eval_ncmul() (the main purpose of the color class is to implement the proper noncommutative behavior of indexed color objects). Bye, Christian -- / Physics is an algorithm \/ http://www.uni-mainz.de/~bauec002/
Hi guys, First of all thanks for the answer. But a diferent question arise: I make a struct that look at a ex e=color_f($0,$1,$2) and return zero. But I tried: is_a<su3f>(e) is_exactly_a<su3f>(e) is_a<su3f>(e.op(0)) is_a<color>(e) but all returns zero? I think my archive is corrupted. Somebody tried it before? Thanks, Marco Citando Christian Bauer <Christian.Bauer@uni-mainz.de>:
Hi!
On Tue, Mar 15, 2005 at 06:54:01PM -0300, mdias@ift.unesp.br wrote:
I have a simple question. I would like to construct a derived class of indexed type, folowing the final part of tutorial. How can I inherit simplify_indexed()?
You can't, as there is no member function simplify_indexed().
What you can override is eval_indexed() (for automatic evaluation) and contract_with()/add_indexed()/scalar_mul_indexed() (for manual evaluation, AKA simplify_indexed()). However, these are not methods of the 'indexed' class but of the base objects that are being indexed.
You probably don't need to subclass 'indexed' at all. The library is designed in a way that allows putting nearly all relevant properties of indexed expressions into their base objects. If you still want to do it: take a look at GiNaC's 'color' class (color.h/color.cpp) which is pretty minimal, except for its eval_ncmul() (the main purpose of the color class is to implement the proper noncommutative behavior of indexed color objects).
Bye, Christian
-- / Physics is an algorithm \/ http://www.uni-mainz.de/~bauec002/
_______________________________________________ GiNaC-list mailing list GiNaC-list@ginac.de http://thep.physik.uni-mainz.de/mailman/listinfo/ginac-list
------------------------------------------------- This mail sent through IMP: http://horde.org/imp/
On Thu, Mar 17, 2005 at 09:03:10PM -0300, mdias at ift dot unesp dot br wrote:
I make a struct that look at a ex e=color_f($0,$1,$2) and return zero. But I tried:
is_a<su3f>(e) is_exactly_a<su3f>(e) is_a<su3f>(e.op(0)) is_a<color>(e)
but all returns zero?
color_f(const ex&, const ex&, const ex&) returns an indexed object, so all those results are correct. You might try something like this: // This hack works for me (TM) class su3f_visitor_t : public visitor, public indexed::visitor { lst res; public: su3f_visitor_t() { } inline lst get_result() const { return res; } inline void visit(const indexed &i) { if (is_a<su3f>(i.op(0))) res.append(i); } }; // look for color_f in expression e su3f_visitor_t su3f_v; e.traverse(su3f_v); lst color_lst = su3f_v.get_result(); // do whatever you need Best regards, Alexei
Hi! On Thu, Mar 17, 2005 at 09:03:10PM -0300, mdias@ift.unesp.br wrote:
But a diferent question arise: I make a struct that look at a ex e=color_f($0,$1,$2) and return zero.
Uhm, what exactly are you trying to do? Indices of color_f() need to be of type idx, so if you want to use wildcards, it needs to look like this: ex e = color_f(idx(wild(0), 8), idx(wild(1), 8), idx(wild(2), 8)); cout << e << endl; // -> "f.($0).($1).($2)"
is_a<su3f>(e) is_exactly_a<su3f>(e) is_a<su3f>(e.op(0)) is_a<color>(e)
The third one is the correct test. cout << is_a<su3f>(e.op(0)) << endl; // -> "1" (The fourth test returns 0 because an f_abc is not a color object; only the noncommutative t_a are.) Bye, Christian -- / Physics is an algorithm \/ http://www.uni-mainz.de/~bauec002/
participants (3)
-
Christian Bauer
-
mdias@ift.unesp.br
-
varg@theor.jinr.ru