converting expressions to double
Hello, Thank you for GiNaC and your support - I have almost completed my PhD with it :) But I have a little problem still... I have a symbolic expression F(x, y, z, u) and I need to 1) substitute x, y, z, u with values (given as double), 2) calculate F, 3) export F as double. My code looks like this: double my_method(GiNaC::ex & ex, double x1, double y1, double z1, double u1) { numeric _x(x1), _y(y1), _z(z1), _u(u1); ex = ex.subs(lst(x == _x, y == _y, z == _z, u == _u)); ex = ex.evalf(); numeric tmp = ex_to<numeric>(ex); return tmp.to_double(); } Unfortunately, the last instruction (to_double() ) fails and throws the exception: terminate called after throwing an instance of 'cln::notreached_exception' what(): Internal error: statement in file real/conv/cl_R_to_double.cc, line 55 has been reached!! Please send the authors of the program a description how you produced this error! I read the response cited below, but still I can't fix it. Could you please help me? Thank you very much, Tomasz. Warsaw University of Technology ========================= Hi! On 11/02/2010 08:12 AM, Sebastian Luther wrote:
below you'll find a small test program that crashes for me.
-------------------------------------------- #include<ginac/ginac.h> #include<iostream>
int main(int argc, char* argv[]) { GiNaC::parser p; GiNaC::ex e = p("941480149401/1250000000000000*2^(5/91)"); GiNaC::numeric n = GiNaC::ex_to<GiNaC::numeric>(e); double x = n.to_double(); //throws the exception below return 0; }
Since e is a product (of a rational number and a power of two) it must be converted to a number using evalf() before trying to assign it to a simple numeric object.
Looks like the real problem lays in cln, but I'm not sure how to reproduce it there.
It has nothing to do with CLN. Best wishes -richy. -- Richard B. Kreckel <http://www.ginac.de/~kreckel/>
Hi, Tomasz, One of the common reasons for such problem is that your expression still contains some variables. Make a debug print of it and check if it is the case. Good luck! Vladimir -- Vladimir V. Kisil email: kisilv@maths.leeds.ac.uk www: http://www.maths.leeds.ac.uk/~kisilv/ Book: Geometry of Mobius Transformations http://www.icpress.co.uk/mathematics/p835.html
Hi, Thanks for quick reply. I am afraid this is not the case. My dbgprint() of my expression looks like this (many iterations given here): 4.760311310558623545 -0.4959608476010454472 0.83221034995653497086 1.5383241757249394564 -0.31180539644482394346 3.5366695187408772796 0.6577950130788717955 1.776523528073554051 2.3553448973345405323 -1.4278829682706838499 -3.1344162711667552658 -8.88682924942704566 Any suggestions? Kind Regards, Tomasz W dniu 02.03.2012 12:07, Vladimir V. Kisil pisze:
Hi, Tomasz,
One of the common reasons for such problem is that your expression still contains some variables. Make a debug print of it and check if it is the case.
Good luck! Vladimir
Hi, could you run your code with an added extra line like the following: ... ex = ex.subs(lst(x == _x, y == _y, z == _z, u == _u)); ex = ex.evalf(); std::cout << tree << ex << std::endl; /* NEW NEW NEW */ numeric tmp = ex_to<numeric>(ex); ... and report about the result? That would help pin down the problem. Regards, Jens On 02.03.2012 15:41, Tomasz I. Rudny wrote:
Hi,
Thanks for quick reply. I am afraid this is not the case. My dbgprint() of my expression looks like this (many iterations given here):
4.760311310558623545 -0.4959608476010454472 0.83221034995653497086 1.5383241757249394564 -0.31180539644482394346 3.5366695187408772796 0.6577950130788717955 1.776523528073554051 2.3553448973345405323 -1.4278829682706838499 -3.1344162711667552658 -8.88682924942704566
Any suggestions?
Kind Regards, Tomasz
W dniu 02.03.2012 12:07, Vladimir V. Kisil pisze:
Hi, Tomasz,
One of the common reasons for such problem is that your expression still contains some variables. Make a debug print of it and check if it is the case.
Good luck! Vladimir
_______________________________________________ GiNaC-list mailing list GiNaC-list@ginac.de https://www.cebix.net/mailman/listinfo/ginac-list
Hi. I have found the source of the problem. Some of the numbers had values like 1E-20 or lower. Attempt to convert them to double produced the exception. It was difficult to track it because the exception text appeared randomly interwoven with the regular program output. Thank you all for help and advice. Kind Regards, Tomasz. PS. Is there any nice tutorial on GiNaC usage for polynomials? It seems to be quite powerful in this respect... W dniu 02.03.2012 21:11, Jens Vollinga pisze:
Hi,
could you run your code with an added extra line like the following:
... ex = ex.subs(lst(x == _x, y == _y, z == _z, u == _u)); ex = ex.evalf(); std::cout << tree << ex << std::endl; /* NEW NEW NEW */ numeric tmp = ex_to<numeric>(ex); ...
and report about the result? That would help pin down the problem.
Regards, Jens
On 02.03.2012 15:41, Tomasz I. Rudny wrote:
Hi,
Thanks for quick reply. I am afraid this is not the case. My dbgprint() of my expression looks like this (many iterations given here):
4.760311310558623545 -0.4959608476010454472 0.83221034995653497086 1.5383241757249394564 -0.31180539644482394346 3.5366695187408772796 0.6577950130788717955 1.776523528073554051 2.3553448973345405323 -1.4278829682706838499 -3.1344162711667552658 -8.88682924942704566
Any suggestions?
Kind Regards, Tomasz
W dniu 02.03.2012 12:07, Vladimir V. Kisil pisze:
Hi, Tomasz,
One of the common reasons for such problem is that your expression still contains some variables. Make a debug print of it and check if it is the case.
Good luck! Vladimir
_______________________________________________ GiNaC-list mailing list GiNaC-list@ginac.de https://www.cebix.net/mailman/listinfo/ginac-list
_______________________________________________ GiNaC-list mailing list GiNaC-list@ginac.de https://www.cebix.net/mailman/listinfo/ginac-list
Hi! On 03/02/2012 10:34 PM, Tomasz I. Rudny wrote:
I have found the source of the problem. Some of the numbers had values like 1E-20 or lower. Attempt to convert them to double produced the exception.
Well, this shouldn't happen. Can you send a simple example program where this happens and tell us on what platform this is? Bye! -richy. -- Richard B. Kreckel <http://www.ginac.de/~kreckel/>
participants (4)
-
Jens Vollinga
-
Richard B. Kreckel
-
Tomasz I. Rudny
-
Vladimir V. Kisil