Simplification in GiNaC
Hello, I recently wrote a simple program to learn some calculations with GiNaC. This works, But I got some expression which automatically don't become simple. The question is: What is the simplest way to get the expected answer - Ax here? Best regards Petrov A.B. -------------------------------------------------------------------- Output for program: Starting: ./test2 sqrt(m*x^2*A)*sqrt(m^(-1)*A) *** Exited normally *** ------------------------------------------------------------------ Program: #include <iostream> using namespace std; #include<ginac/ginac.h> using namespace GiNaC; void calc_example(){ realsymbol A("A"),m("m"),x("x"); ex e = sqrt(A*m*pow(x,2))*sqrt(A/m); cout << e << endl; } int main(int argc, char** argv) { calc_example(); return 0; }
Hi, Avoiding discussion on correct transformations towards simpler expressions in general, here is an advise on your particular example. You can use susb method with wildcards to make manual transformation pow(X,1/2)*pow(Y,1/2) -> pow(X*Y,1/2) Also, with square roots it will be better to use possymbol instead of realsymbol whenever possible. This even can make the desired transformation automatically through the expand method. (the desired answer is not correct for arbitrary reals, indeed) Best wishes, Vladimir -- 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/
On Fri, 6 Jan 2017 21:52:32 +0500, abpetrov <abpetrov@ufacom.ru> said:
ABP> Hello, I recently wrote a simple program to learn some ABP> calculations with GiNaC. This works, But I got some expression ABP> which automatically don't become simple. The question is: What ABP> is the simplest way to get the expected answer - Ax here? ABP> Best regards Petrov A.B. ABP> -------------------------------------------------------------------- ABP> Output for program: ABP> Starting: ./test2 sqrt(m*x^2*A)*sqrt(m^(-1)*A) *** Exited ABP> normally *** ABP> ------------------------------------------------------------------ ABP> Program: ABP> #include <iostream> using namespace std; ABP> #include<ginac/ginac.h> using namespace GiNaC; ABP> void calc_example(){ realsymbol A("A"),m("m"),x("x"); ex e = ABP> sqrt(A*m*pow(x,2))*sqrt(A/m); cout << e << endl; } ABP> int main(int argc, char** argv) { calc_example(); return 0; } ABP> _______________________________________________ GiNaC-list ABP> mailing list GiNaC-list@ginac.de ABP> https://www.cebix.net/mailman/listinfo/ginac-list
That's works. Thank you for your answer Best regards Petrov A.B. On 01/07/2017 03:53 PM, Vladimir V. Kisil wrote:
Hi,
Avoiding discussion on correct transformations towards simpler expressions in general, here is an advise on your particular example.
You can use susb method with wildcards to make manual transformation
pow(X,1/2)*pow(Y,1/2) -> pow(X*Y,1/2)
Also, with square roots it will be better to use possymbol instead of realsymbol whenever possible. This even can make the desired transformation automatically through the expand method. (the desired answer is not correct for arbitrary reals, indeed)
Best wishes, Vladimir
participants (2)
-
abpetrov
-
Vladimir V. Kisil