Hello,
I am using this package to do symbolic calculations with c++.
First of thank you to the developers for this very useful package!
Now my actual issue. I am using SymEngine::Expression to store symbolic expressions and in the actual calculation their are a lot of operations of the form x*y+z*w, where x,y,z,w are expressions. I am running into an issue where basic simplifications are not happening. Following is a very simple program showing this behaviour:
Program in file test_basic_prob.cpp:
#include <symengine/cwrapper.h>
#include <symengine/expression.h>
int main(){
// Declerations
SymEngine::Expression b("b");
SymEngine::Expression a("a");
SymEngine::Expression x, y, w, z;
SymEngine::Expression res;
// Set up expressions
x = SymEngine::Expression(-3);
y = (SymEngine::Expression(3)-a);
z = (-SymEngine::Expression(9)+b);
w = SymEngine::Expression(-1);
res = x*y + z*w;
// Print results;
std::cout << " x = " << x << std::endl;
std::cout << " y = " << y << std::endl;
std::cout << " z = " << z << std::endl;
std::cout << " w = " << w << std::endl;
std::cout << " x*y + z*w = " << res << std::endl;
return 0;
}
Compile and output:
icpc -std=c++14 -c -I/usr/local/include/symengine test_basic_prob.cpp -o test_basic_prob.o
icpc -std=c++14 -I/usr/local/include/symengine -o test.out test_basic_prob.o -L/usr/local/lib -lsymengine -lgmp
./test.out
x = -3
y = 3 - a
z = -9 + b
w = -1
x*y + z*w = -(-9 + b) - 3*(3 - a)
As you can see their is no problem compiling and running. The final result in res variable should have clearly been a - b or -b + a. However nothing is simplifying.
This issue is worst when a and b are the same variable, and the expression will not simplify to zero.
I tried going through the test programs to see if their is any instruction in the package to do this but I cannot seam to figure it out. Is their a way around this issue?