[GiNaC-list] Algebraic sqrt()
Timo Schlüßler
timo at schluessler.org
Mon Jun 16 20:09:46 CEST 2008
I always just tried sqrt(numeric(...)) and not sqrt(ex(...)). So thank
you very much for that hint.
regards
Alexei Sheplyakov wrote:
> 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
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> GiNaC-list mailing list
> GiNaC-list at ginac.de
> https://www.cebix.net/mailman/listinfo/ginac-list
>
More information about the GiNaC-list
mailing list