Is it possible to make evalf() let integer constants stay integers? I looked in flags.h, but couldn't find anything. (3*x).evalf() gives (3.0)*x -- Martin
On Wed, Nov 14, 2007 at 04:41:03PM +0100, Martin Sandve Alnæs wrote:
Is it possible to make evalf() let integer constants stay integers?
evalf() turns exact numbers into inexact _by definition_. Keeping the coefficient exact (for instance, integer) does not make sense anyway, since they are multiplied by inexact number. If you still insist on it, you could roll down your own evalf-alike function, e.g. struct weird_evalf() : public map_function { ex operator()(const ex& e) { if (is_a<add>(e) || is_a<mul>(e)) return e.map(*this); if (is_a<power>(e)) return power(e.op(0).map(*this), e.op(1)); if (is_a<numeric>(e)) return e; else return e.evalf(); } Best regards, Alexei -- All science is either physics or stamp collecting.
As today everybody "googles" to find quick answer, I think this example will be usefull to somebody like me, starting making clases with GiNaC. This is a modified versions of Alexei's reply: "Re: Defining a new symbol class (mysymbol.cpp)" The new mysymbol class provides total time derivative. The numbering corresponds to the steps of the mystring Tutorial at Ginacs Tutorial. It works with GiNaC 1.3.6 & 1.4 Enjoy, and thanks again Javier
Excuse me, I've attached a incorrect file Javier El mié, 14-11-2007 a las 20:35 +0100, jros escribió:
As today everybody "googles" to find quick answer, I think this example will be usefull to somebody like me, starting making clases with GiNaC.
This is a modified versions of Alexei's reply: "Re: Defining a new symbol class (mysymbol.cpp)"
The new mysymbol class provides total time derivative.
The numbering corresponds to the steps of the mystring Tutorial at Ginacs Tutorial.
It works with GiNaC 1.3.6 & 1.4
Enjoy, and thanks again
Javier
_______________________________________________ GiNaC-list mailing list GiNaC-list@ginac.de https://www.cebix.net/mailman/listinfo/ginac-list
2007/11/14, Alexei Sheplyakov <varg@theor.jinr.ru>:
On Wed, Nov 14, 2007 at 04:41:03PM +0100, Martin Sandve Alnæs wrote:
Is it possible to make evalf() let integer constants stay integers?
evalf() turns exact numbers into inexact _by definition_. Keeping the coefficient exact (for instance, integer) does not make sense anyway, since they are multiplied by inexact number. If you still insist on it, you could roll down your own evalf-alike function, e.g.
struct weird_evalf() : public map_function { ex operator()(const ex& e) { if (is_a<add>(e) || is_a<mul>(e)) return e.map(*this); if (is_a<power>(e)) return power(e.op(0).map(*this), e.op(1)); if (is_a<numeric>(e)) return e; else return e.evalf(); }
Ok, thanks. The reason I asked was that I encountered a situation I can't reproduce right now, where terms like "x^3" were converted to "x^3.0" and collect wouldn't work on them afterwards since the exponents were non-integers. Thinking about it now, it's probably a bug in my own code, I might call evalf on "3" in "x^3" someplace. Because (x^3).evalf() returns (x^3), so it doesn't seem to be ginacs behaviour. -- Martin
Martin Sandve Alnæs wrote:
Ok, thanks. The reason I asked was that I encountered a situation I can't reproduce right now, where terms like "x^3" were converted to "x^3.0" and collect wouldn't work on them afterwards since the exponents were non-integers.
That must have been an ancient version. It was fixed in March 2000: <http://www.ginac.de/viewcvs/GiNaC/ginac/power.cpp?r1=1.17&r2=1.18> -richy. -- Richard B. Kreckel <http://www.ginac.de/~kreckel/>
participants (4)
-
Alexei Sheplyakov
-
jros
-
Martin Sandve Alnæs
-
Richard B. Kreckel