[GiNaC-list] Algebraic sqrt()
Alexei Sheplyakov
varg at theor.jinr.ru
Mon Jun 16 15:24:20 CEST 2008
Hello!
On Wed, Jun 11, 2008 at 04:32:22PM +0200, Timo Schlüßler wrote:
> is there a way to compute a sqrt() algebraic?
> E.g. that sqrt(2) * sqrt(2) gives exact 2 and not 2.0000001 or whatever
> else.
sqrt(2) is a bit ambigous. I.e. there are GiNaC::sqrt(const GiNaC::numeric&),
GiNaC::sqrt(const GiNaC::ex&), and also std::sqrt(double) std::sqrt(float).
So, you need to specify the type of the argument expicitly:
ex e = sqrt(ex(2));
cout << e << endl; // prints sqrt(2)
e = e*e;
cout << e << endl; // prints 2
ex a = sqrt(ex(45))*sqrt(ex(3));
cout << a << endl; // prints sqrt(3)*sqrt(45)
> Or that sqrt(45) * sqrt(3) gives sqrt(135) and not the rounded value.
You'll need to do the transformation yourself. It's not quite clear what
is the canonical form of the expression sqrt(45)*sqrt(3) (and in
general, any non-rational expression), so GiNaC won't bother to rewrite it.
Best regards,
Alexei
--
All science is either physics or stamp collecting.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 827 bytes
Desc: Digital signature
Url : http://www.cebix.net/pipermail/ginac-list/attachments/20080616/0762653f/attachment.sig
More information about the GiNaC-list
mailing list