Hi, I'm extending GiNaC by some new classes and ran into a problem with subs and eval. My class, representing an integral, inherits from basic and is essentially a container class containing several ex's itself. The subs method, inherited from basic, works as expected for the substitution step, but does not re-evaluate the expression (i.e. the eval function of my class is not called after the substitution happened). The tutorial states "All GiNaC methods that transform expressions, like subs() or normal(), automatically re-evaluate their results." and, hence, I would expect that the default subs method of the basic class calls eval somewhere in the process. Is this a bug in basic::subs or am I supposed to take care of a re-evaluation of my custom classes myself (i.e. essentially overriding subs and calling eval explicitly in the process)? Looking into the source code (I'm on commit 9197695fc, ginac version 1.8.1-1) I'd expect a call to eval on line 628 of basic.cpp after all operands have been substituted, and before subs_one_level is called. Best, Gregor
Dear Gregor, Just a quick question: did you re-implement eval() method for your class? Best wishes, Vladimir -- Vladimir V. Kisil http://www.maths.leeds.ac.uk/~kisilv/ Book: Geometry of Mobius Maps https://doi.org/10.1142/p835 Soft: Geometry of cycles http://moebinv.sourceforge.net/ Jupyter notebooks: https://github.com/vvkisil/MoebInv-notebooks
On Wed, 10 Nov 2021 09:47:17 +0100, Gregor Kälin <kaelingre@gmail.com> said:
GK> Hi, GK> I'm extending GiNaC by some new classes and ran into a problem GK> with subs and eval. My class, representing an integral, inherits GK> from basic and is essentially a container class containing GK> several ex's itself. The subs method, inherited from basic, GK> works as expected for the substitution step, but does not GK> re-evaluate the expression (i.e. the eval function of my class GK> is not called after the substitution happened). The tutorial GK> states "All GiNaC methods that transform expressions, like GK> subs() or normal(), automatically re-evaluate their results." GK> and, hence, I would expect that the default subs method of the GK> basic class calls eval somewhere in the process. Is this a bug GK> in basic::subs or am I supposed to take care of a re-evaluation GK> of my custom classes myself (i.e. essentially overriding subs GK> and calling eval explicitly in the process)? Looking into the GK> source code (I'm on commit 9197695fc, ginac version 1.8.1-1) I'd GK> expect a call to eval on line 628 of basic.cpp after all GK> operands have been substituted, and before subs_one_level is GK> called. GK> Best, GK> Gregor GK> _______________________________________________ GiNaC-list GK> mailing list GiNaC-list@ginac.de GK> https://www.ginac.de/mailman/listinfo/ginac-list
Dear Vladimir, Yes, I did override the eval() method. It's called correctly on construction of an instance of the class. Best, Gregor On 11/10/21 11:30, Vladimir V. Kisil wrote:
Dear Gregor,
Just a quick question: did you re-implement eval() method for your class?
Best wishes, Vladimir
On Wed, 10 Nov 2021 11:33:59 +0100, Gregor Kälin <kaelingre@gmail.com> said: GK> Yes, I did override the eval() method. It's called correctly on GK> construction of an instance of the class.
For my derived classes I am using the following "quick and dirty" approach for subs: I made calls to ex:subs() for components of the derived class, and then call a constructor with these substituted components. [Disclaimer: the above approach is likely fundamentally wrong and resulting from my poor understanding of C++ class inheritance.] -- Vladimir V. Kisil http://www.maths.leeds.ac.uk/~kisilv/ Book: Geometry of Mobius Maps https://doi.org/10.1142/p835 Soft: Geometry of cycles http://moebinv.sourceforge.net/ Jupyter notebooks: https://github.com/vvkisil/MoebInv-notebooks
participants (2)
-
Gregor Kälin
-
Vladimir V. Kisil