Dear All, Consider the code: #include <iostream> #include <ginac/ginac.h> using namespace std; using namespace GiNaC; int main() { for (int i=0; i < 2; ++i) (i==0? realsymbol("r") : symbol("s")).dbgprinttree(); return 0; } My expectation would be that it first creates a realsymbol r and then a symbol s. However, the actual output of the programme is: r (symbol) @0x7fff6e472700, serial=1, hash=0x1689b718, flags=0x6, domain=0 s (symbol) @0x7fff6e472700, serial=2, hash=0x1689b718, flags=0x6, domain=0 That is, in both cases the domain is 0 (complex) and r is not recognised as a real symbol. Shall this be corrected or did I misunderstand the concept of (A? B : C) construct? Best wishes, Vladimir PS Another (less important and more disputable) question: do we want the debug output for realsymbol/possymbol look like r (realsymbol) @0x7fff6e472700, serial=1, hash=0x1689b718, flags=0x6, domain=1 p (possymbol) @0x7fff6e472700, serial=1, hash=0x1689b718, flags=0x6, domain=2 to make the class more visible? -- 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/ Jupyter (Colab): https://github.com/vvkisil/MoebInv-notebooks Jupyter (CodeOcean): https://codeocean.com/capsule/7952650/tree
PPS And yes, using the line (i==0? ex(realsymbol("r")) : ex(symbol("s"))).dbgprinttree(); in the code produces the expected output. -- 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/ Jupyter (Colab): https://github.com/vvkisil/MoebInv-notebooks Jupyter (CodeOcean): https://codeocean.com/capsule/7952650/tree
On Fri, 08 Nov 2019 20:57:52 +0000, "Vladimir V. Kisil" <kisilv@maths.leeds.ac.uk> said:
Dear All,
Consider the code:
#include <iostream> #include <ginac/ginac.h> using namespace std; using namespace GiNaC; int main() { for (int i=0; i < 2; ++i) (i==0? realsymbol("r") : symbol("s")).dbgprinttree();
return 0; }
My expectation would be that it first creates a realsymbol r and then a symbol s. However, the actual output of the programme is:
r (symbol) @0x7fff6e472700, serial=1, hash=0x1689b718, flags=0x6, domain=0 s (symbol) @0x7fff6e472700, serial=2, hash=0x1689b718, flags=0x6, domain=0
That is, in both cases the domain is 0 (complex) and r is not recognised as a real symbol.
Shall this be corrected or did I misunderstand the concept of (A? B : C) construct?
Best wishes, Vladimir
PS Another (less important and more disputable) question: do we want the debug output for realsymbol/possymbol look like
r (realsymbol) @0x7fff6e472700, serial=1, hash=0x1689b718, flags=0x6, domain=1 p (possymbol) @0x7fff6e472700, serial=1, hash=0x1689b718, flags=0x6, domain=2
to make the class more visible?
Dear Vladimir, Thanks for sharing with us an effect of the language's darker side! On 08.11.19 21:57, Vladimir V. Kisil wrote:
#include <iostream> #include <ginac/ginac.h> using namespace std; using namespace GiNaC; int main() { for (int i=0; i < 2; ++i) (i==0? realsymbol("r") : symbol("s")).dbgprinttree();
return 0; }
My expectation would be that it first creates a realsymbol r and then a symbol s. However, the actual output of the programme is:
r (symbol) @0x7fff6e472700, serial=1, hash=0x1689b718, flags=0x6, domain=0 s (symbol) @0x7fff6e472700, serial=2, hash=0x1689b718, flags=0x6, domain=0
That is, in both cases the domain is 0 (complex) and r is not recognised as a real symbol.
Shall this be corrected or did I misunderstand the concept of (A? B : C) construct?
We can't correct this. The first and second expression and aren't of the same type. The compiler has to find the conditional operator's type in order to call dbgprinttree(). The standard (section 8.16.4 in [IEC14882:2017]) specifies that the compiler must try to find the common type by trying to convert the one into each other. Since realsymbol is derived from symbol, this works only one way and this determines the type of the conditional operator. Note that the code isn't doing a dynamic call. This changes when you wrap the symbols into an ex. Many people recommend avoiding the conditional operator for a variety of reasons. -richy. -- Richard B. Kreckel <https://in.terlu.de/~kreckel/>
participants (2)
-
Richard B. Kreckel
-
Vladimir V. Kisil