From jrheinlaender at gmx.de Wed May 11 21:10:29 2016 From: jrheinlaender at gmx.de (=?UTF-8?Q?Jan_Rheinl=c3=a4nder?=) Date: Wed, 11 May 2016 21:10:29 +0200 Subject: [GiNaC-devel] Subclassing symbol Message-ID: <573383A5.9050107@gmx.de> Hi, something must be wrong with my subclass, but I don't understand it. I subclassed symbol to get a non-commutative version: ---------- HEADER -------------- #include namespace GiNaC { class ncsymbol: public symbol { public: ncsymbol(const symbol& s); explicit ncsymbol(const std::string & initname); ncsymbol(const std::string & initname, const std::string & texname); unsigned return_type() const { return return_types::noncommutative_composite; } }; GINAC_DECLARE_UNARCHIVER(ncsymbol); } ---------- IMPLEMENTATION ------------- #include namespace GiNaC { // non-commutative symbol ncsymbol::ncsymbol() : symbol() { } ncsymbol::ncsymbol(const symbol& s) : symbol(s) { } ncsymbol::ncsymbol(const std::string & initname) : symbol(initname) { } ncsymbol::ncsymbol(const std::string & initname, const std::string & texname) : symbol(initname, texname) { } GINAC_BIND_UNARCHIVER(ncsymbol); -------------------------------------- But when I execute the following code the program crashes when printing x: symbol x("x"); x = ncsymbol("y"); std::cout << x << std::endl; It does not crash if I print ncsymbol("y") directly (without assigning it to x first). Can anybody explain why? Did I forget to implement an essential method? Thanks! Jan From kisilv at maths.leeds.ac.uk Wed May 11 21:45:19 2016 From: kisilv at maths.leeds.ac.uk (Vladimir V. Kisil) Date: Wed, 11 May 2016 20:45:19 +0100 Subject: [GiNaC-devel] Subclassing symbol In-Reply-To: <573383A5.9050107@gmx.de> References: <573383A5.9050107@gmx.de> Message-ID: <23619.1462995919@math-pc2069.leeds.ac.uk> >>>>> On Wed, 11 May 2016 21:10:29 +0200, Jan Rheinl?nder said: JR> Hi, something must be wrong with my subclass, but I don't JR> understand it. Did you look into section "6.5.1 Hierarchy of algebraic classes" of the tutorial? I think you need to use several macros described there. -- Vladimir V. Kisil http://www.maths.leeds.ac.uk/~kisilv/ Book: Geometry of Mobius Transformations http://goo.gl/EaG2Vu Software: Geometry of cycles http://moebinv.sourceforge.net/ From jrheinlaender at gmx.de Wed May 11 21:56:50 2016 From: jrheinlaender at gmx.de (=?UTF-8?Q?Jan_Rheinl=c3=a4nder?=) Date: Wed, 11 May 2016 21:56:50 +0200 Subject: [GiNaC-devel] Subclassing symbol In-Reply-To: <23619.1462995919@math-pc2069.leeds.ac.uk> References: <573383A5.9050107@gmx.de> <23619.1462995919@math-pc2069.leeds.ac.uk> Message-ID: <57338E82.1070508@gmx.de> Hi, the code is practically the same as in GiNaC symbol.h and symbol.cpp (for symbol subclasses realsymbol / possymbol). I did try using GINAC_DECLARE_REGISTERED_CLASS(ncsymbol, symbol) etc. as well but it makes no difference. And I just tried: If I use GiNaC::realsymbol class instead of my own ncsymbol class the code also crashes. So maybe its a GinaC bug? Am 11.05.2016 um 21:45 schrieb Vladimir V. Kisil: >>>>>> On Wed, 11 May 2016 21:10:29 +0200, Jan Rheinl?nder said: > JR> Hi, something must be wrong with my subclass, but I don't > JR> understand it. > > Did you look into section "6.5.1 Hierarchy of algebraic classes" of > the tutorial? I think you need to use several macros described there. From kisilv at maths.leeds.ac.uk Wed May 11 22:11:23 2016 From: kisilv at maths.leeds.ac.uk (Vladimir V. Kisil) Date: Wed, 11 May 2016 21:11:23 +0100 Subject: [GiNaC-devel] Subclassing symbol In-Reply-To: <57338E82.1070508@gmx.de> References: <573383A5.9050107@gmx.de> <23619.1462995919@math-pc2069.leeds.ac.uk> <57338E82.1070508@gmx.de> Message-ID: <24516.1462997483@math-pc2069.leeds.ac.uk> >>>>> On Wed, 11 May 2016 21:56:50 +0200, Jan Rheinl?nder said: JR> Hi, the code is practically the same as in GiNaC symbol.h and JR> symbol.cpp (for symbol subclasses realsymbol / possymbol). I JR> did try using GINAC_DECLARE_REGISTERED_CLASS(ncsymbol, symbol) JR> etc. as well but it makes no difference. I think you have to send the full example written in accordance to GiNaC tutorial which crashes, then other people may look into it. -- Vladimir V. Kisil http://www.maths.leeds.ac.uk/~kisilv/ Book: Geometry of Mobius Transformations http://goo.gl/EaG2Vu Software: Geometry of cycles http://moebinv.sourceforge.net/ From jrheinlaender at gmx.de Fri May 13 19:16:29 2016 From: jrheinlaender at gmx.de (=?UTF-8?Q?Jan_Rheinl=c3=a4nder?=) Date: Fri, 13 May 2016 19:16:29 +0200 Subject: [GiNaC-devel] Why does this program crash? Message-ID: <57360BED.209@gmx.de> Hi, I condensed my previous post on subclassing symbol into this little program, which crashes at the last line. Any idea why? Is it a bug or do I just not understand C++ inheritance? #include #include using namespace std; using namespace GiNaC; int main() { symbol x("x"); x = realsymbol("y"); cout << x << endl; } Jan From kisilv at maths.leeds.ac.uk Fri May 13 23:32:44 2016 From: kisilv at maths.leeds.ac.uk (Vladimir V. Kisil) Date: Fri, 13 May 2016 22:32:44 +0100 Subject: [GiNaC-devel] Why does this program crash? In-Reply-To: <57360BED.209@gmx.de> References: <57360BED.209@gmx.de> Message-ID: <17687.1463175164@math-pc2069.leeds.ac.uk> Dear Jan, I think it is crucial that you would provide the full definition of your derived class. Otherwise it is not possible to track the issue. Best wishes, Vladimir -- Vladimir V. Kisil http://www.maths.leeds.ac.uk/~kisilv/ Book: Geometry of Mobius Transformations http://goo.gl/EaG2Vu Software: Geometry of cycles http://moebinv.sourceforge.net/ >>>>> On Fri, 13 May 2016 19:16:29 +0200, Jan Rheinl?nder said: JR> Hi, I condensed my previous post on subclassing symbol into this JR> little program, which crashes at the last line. Any idea why? Is JR> it a bug or do I just not understand C++ inheritance? JR> #include #include using JR> namespace std; using namespace GiNaC; JR> int main() { symbol x("x"); x = realsymbol("y"); cout << x JR> << endl; } JR> Jan JR> _______________________________________________ GiNaC-devel JR> mailing list GiNaC-devel at ginac.de JR> https://www.cebix.net/mailman/listinfo/ginac-devel From jrheinlaender at gmx.de Sat May 14 04:53:54 2016 From: jrheinlaender at gmx.de (=?UTF-8?Q?Jan_Rheinl=c3=a4nder?=) Date: Sat, 14 May 2016 04:53:54 +0200 Subject: [GiNaC-devel] Why does this program crash? In-Reply-To: <17687.1463175164@math-pc2069.leeds.ac.uk> References: <57360BED.209@gmx.de> <17687.1463175164@math-pc2069.leeds.ac.uk> Message-ID: <57369342.5010902@gmx.de> Dear Vladimir, realsymbol is not my derived class. See ginac/symbol.h ! Am 13.05.2016 um 23:32 schrieb Vladimir V. Kisil: > Dear Jan, > > I think it is crucial that you would provide the full definition of your > derived class. Otherwise it is not possible to track the issue. > > Best wishes, > Vladimir From kisilv at maths.leeds.ac.uk Sat May 14 10:21:23 2016 From: kisilv at maths.leeds.ac.uk (Vladimir V. Kisil) Date: Sat, 14 May 2016 09:21:23 +0100 Subject: [GiNaC-devel] Why does this program crash? In-Reply-To: <57369342.5010902@gmx.de> References: <57360BED.209@gmx.de> <17687.1463175164@math-pc2069.leeds.ac.uk> <57369342.5010902@gmx.de> Message-ID: <23859.1463214083@math-pc2069.leeds.ac.uk> >>>>> On Sat, 14 May 2016 04:53:54 +0200, Jan Rheinl?nder said: JR> Dear Vladimir, realsymbol is not my derived class. See JR> ginac/symbol.h ! Yes, and as far as I am aware there is no problem with realsymbol in GiNaC. Furthermore, in my own project (see the end of the email) I have successfully derived several new classes following the advise from the GiNaC tutorial. If you are looking for an assistance you need to provide a complete piece of software, including the full description of your derived class, which causes the issue. Best wishes, Vladimir -- Vladimir V. Kisil http://www.maths.leeds.ac.uk/~kisilv/ Book: Geometry of Mobius Transformations http://goo.gl/EaG2Vu Software: Geometry of cycles http://moebinv.sourceforge.net/ From kisilv at maths.leeds.ac.uk Sat May 14 11:03:26 2016 From: kisilv at maths.leeds.ac.uk (Vladimir V. Kisil) Date: Sat, 14 May 2016 10:03:26 +0100 Subject: [GiNaC-devel] Why does this program crash? In-Reply-To: <23859.1463214083@math-pc2069.leeds.ac.uk> References: <57360BED.209@gmx.de> <17687.1463175164@math-pc2069.leeds.ac.uk> <57369342.5010902@gmx.de> <23859.1463214083@math-pc2069.leeds.ac.uk> Message-ID: <24741.1463216606@math-pc2069.leeds.ac.uk> Dear Jan, Please accept my apology, you did send a complete example and I have overseen that. In my opinion, the issue is not with the inheritance as such. Symbol x is not assumed to be a left value. There are GiNaC::ex for this. Best wishes, Vladimir -- Vladimir V. Kisil http://www.maths.leeds.ac.uk/~kisilv/ Book: Geometry of Mobius Transformations http://goo.gl/EaG2Vu Software: Geometry of cycles http://moebinv.sourceforge.net/ >>>>> On Sat, 14 May 2016 09:21:23 +0100, "Vladimir V. Kisil" said: >>>>> On Sat, 14 May 2016 04:53:54 +0200, Jan Rheinl?nder said: JR> Dear Vladimir, realsymbol is not my derived class. See JR> ginac/symbol.h ! VVK> Yes, and as far as I am aware there is no problem with VVK> realsymbol in GiNaC. Furthermore, in my own project (see the VVK> end of the email) I have successfully derived several new VVK> classes following the advise from the GiNaC tutorial. VVK> If you are looking for an assistance you need to provide a VVK> complete piece of software, including the full description of VVK> your derived class, which causes the issue. VVK> Best wishes, Vladimir -- Vladimir V. Kisil VVK> http://www.maths.leeds.ac.uk/~kisilv/ Book: Geometry of Mobius VVK> Transformations http://goo.gl/EaG2Vu Software: Geometry of VVK> cycles http://moebinv.sourceforge.net/ VVK> _______________________________________________ GiNaC-devel VVK> mailing list GiNaC-devel at ginac.de VVK> https://www.cebix.net/mailman/listinfo/ginac-devel From kisilv at maths.leeds.ac.uk Sat May 14 23:03:24 2016 From: kisilv at maths.leeds.ac.uk (Vladimir V. Kisil) Date: Sat, 14 May 2016 22:03:24 +0100 Subject: [GiNaC-devel] Why does this program crash? In-Reply-To: <24741.1463216606@math-pc2069.leeds.ac.uk> References: <57360BED.209@gmx.de> <17687.1463175164@math-pc2069.leeds.ac.uk> <57369342.5010902@gmx.de> <23859.1463214083@math-pc2069.leeds.ac.uk> <24741.1463216606@math-pc2069.leeds.ac.uk> Message-ID: <29368.1463259804@math-pc2069.leeds.ac.uk> Dear All, I investigated the crash. It is caused by an infinite loop of calls in GiNaC::ex::ex at /usr/include/ginac/ex.h:265 in GiNaC::symbol::eval at /usr/include/ginac/symbol.h:49 in GiNaC::ex::construct_from_basic(GiNaC::basic const&) from /usr/lib/libginac.so.5 This happens because the assignment symbol x("x"); x = realsymbol("y"); is done through the inherited operator const basic & basic::operator=() which resets the status_flags::evaluated (for different classes) and this flag is never set again for symbols. Now the first question is: do we really want a symbol to be assigned through operator=? If the answer is "yes" then there is the second question is: to repair the situation either * an adjusted symbol::operator=() shall be provided, which sets the flag evaluated; or * at ex:eval() we shall set status_flags::evaluated for GiNaC::symbol and its children? Another option is: basic::operator= shall reset status_flags::evaluated only if another object is not of a child class. My understanding of GiNaC is not sufficient to take decision on this matter. Best wishes, Vladimir -- Vladimir V. Kisil http://www.maths.leeds.ac.uk/~kisilv/ Book: Geometry of Mobius Transformations http://goo.gl/EaG2Vu Software: Geometry of cycles http://moebinv.sourceforge.net/ >>>>> On Sat, 14 May 2016 10:03:26 +0100, "Vladimir V. Kisil" said: VVK> Dear Jan, VVK> Please accept my apology, you did send a complete VVK> example and I have overseen that. In my opinion, the issue is VVK> not with the inheritance as such. Symbol x is not assumed to be VVK> a left value. There are GiNaC::ex for this. VVK> Best wishes, Vladimir -- Vladimir V. Kisil VVK> http://www.maths.leeds.ac.uk/~kisilv/ Book: Geometry of Mobius VVK> Transformations http://goo.gl/EaG2Vu Software: Geometry of VVK> cycles http://moebinv.sourceforge.net/ >>>>> On Sat, 14 May 2016 09:21:23 +0100, "Vladimir V. Kisil" VVK> said: >>>>> On Sat, 14 May 2016 04:53:54 +0200, Jan Rheinl?nder said: JR> Dear Vladimir, realsymbol is not my derived class. See JR> ginac/symbol.h ! VVK> Yes, and as far as I am aware there is no problem with VVK> realsymbol in GiNaC. Furthermore, in my own project (see the VVK> end of the email) I have successfully derived several new VVK> classes following the advise from the GiNaC tutorial. VVK> If you are looking for an assistance you need to provide a VVK> complete piece of software, including the full description of VVK> your derived class, which causes the issue. VVK> Best wishes, Vladimir -- Vladimir V. Kisil VVK> http://www.maths.leeds.ac.uk/~kisilv/ Book: Geometry of Mobius VVK> Transformations http://goo.gl/EaG2Vu Software: Geometry of VVK> cycles http://moebinv.sourceforge.net/ VVK> _______________________________________________ GiNaC-devel VVK> mailing list GiNaC-devel at ginac.de VVK> https://www.cebix.net/mailman/listinfo/ginac-devel VVK> _______________________________________________ GiNaC-devel VVK> mailing list GiNaC-devel at ginac.de VVK> https://www.cebix.net/mailman/listinfo/ginac-devel From asheplyakov at yandex.ru Sun May 15 20:21:35 2016 From: asheplyakov at yandex.ru (Alexey Sheplyakov) Date: Sun, 15 May 2016 21:21:35 +0300 Subject: [GiNaC-devel] Why does this program crash? In-Reply-To: <57360BED.209@gmx.de> References: <57360BED.209@gmx.de> Message-ID: <1643551463336495@web17j.yandex.ru> Hello, > I condensed my previous post on subclassing symbol into this little > program, which crashes at the last line. Any idea why? Is it a bug or do > > ?????#include > ?????#include > ?????using namespace std; > ?????using namespace GiNaC; > > ?????int main() > ?????{ > ????????symbol x("x"); > ????????x = realsymbol("y"); Assigning an instance of a subclass is in general a bad idea, see https://en.wikipedia.org/wiki/Object_slicing In this particular case GiNaC::basic assignment operator resets status_flags::evaluated Thus when an ex gets constructed from the symbol here > ????????cout << x << endl; ex::construct_from_basic enters an infinite recursion in const ex tmpex & = other.eval(); since symbol::eval() is essentially a nop. Sooner or later the program exhausts the stack and segfaults. So this is sort of GiNaC bug, but it's certainly useful for it lets you know that your code is wrong. #include #include using namespace std; using namespace GiNaC; int main() { symbol x("x"); x.dbgprinttree(); x = realsymbol("y"); x.dbgprinttree(); return 0; } x (symbol) @0x7ffc08327bc0, serial=1, hash=0x1, flags=0x6, domain=0 y (symbol) @0x7ffc08327bc0, serial=2, hash=0x1, flags=0x0, domain=0 So x remains complex (domain == 0) after assigning y. This is natural from C++ point of the view, however this is most likely not what you mean. Without the bug which triggers an infinite recursion the original problem (assigning an instance of a subclass) will be more difficult to find. Hope this helps, Alexey From jrheinlaender at gmx.de Sat May 28 21:19:49 2016 From: jrheinlaender at gmx.de (=?UTF-8?Q?Jan_Rheinl=c3=a4nder?=) Date: Sat, 28 May 2016 21:19:49 +0200 Subject: [GiNaC-devel] Why does this program crash? In-Reply-To: <1643551463336495@web17j.yandex.ru> References: <57360BED.209@gmx.de> <1643551463336495@web17j.yandex.ru> Message-ID: <5749EF55.4000805@gmx.de> Hello, thank you for your comments and explanations on C++ inheritance issues. I was away for two weeks and apologize for the delay in answering. I have a need to change the domain and the commutativity of a symbol after creation. From what I gather, this is not possible with the existing symbol class. So what I would try next is to define a new symbol subclass which stores domain and return_type in a member and has ::set operators to change them. Jan Am 15.05.2016 um 20:21 schrieb Alexey Sheplyakov: > Hello, > >> I condensed my previous post on subclassing symbol into this little >> program, which crashes at the last line. Any idea why? Is it a bug or do >> #include >> #include >> using namespace std; >> using namespace GiNaC; >> >> int main() >> { >> symbol x("x"); >> x = realsymbol("y"); > Assigning an instance of a subclass is in general a bad idea, see https://en.wikipedia.org/wiki/Object_slicing > In this particular case GiNaC::basic assignment operator resets status_flags::evaluated > > Thus when an ex gets constructed from the symbol here > >> cout << x << endl; > ex::construct_from_basic enters an infinite recursion in > > const ex tmpex & = other.eval(); > > since symbol::eval() is essentially a nop. Sooner or later the program exhausts the stack and segfaults. > So this is sort of GiNaC bug, but it's certainly useful for it lets you know that your code is wrong. > > #include > #include > using namespace std; > using namespace GiNaC; > > int main() { > symbol x("x"); > x.dbgprinttree(); > x = realsymbol("y"); > x.dbgprinttree(); > return 0; > } > > x (symbol) @0x7ffc08327bc0, serial=1, hash=0x1, flags=0x6, domain=0 > y (symbol) @0x7ffc08327bc0, serial=2, hash=0x1, flags=0x0, domain=0 > > So x remains complex (domain == 0) after assigning y. This is natural from C++ point of the view, > however this is most likely not what you mean. Without the bug which triggers an infinite recursion > the original problem (assigning an instance of a subclass) will be more difficult to find. > > > Hope this helps, > Alexey > _______________________________________________ > GiNaC-devel mailing list > GiNaC-devel at ginac.de > https://www.cebix.net/mailman/listinfo/ginac-devel