I am looking to simplify arbitrary algebraic expressions by invoking the mathematica kernel from C using WSTP. My initial attempt was the following, which was based on the online documentation and the example "factor.c"
algebra = "(a + a + a + a - b)";
WSPutFunction(lp, "EvaluatePacket", 1L);
WSPutFunction(lp, "FullSimplify", 1L);
WSPutString(lp, algebra);
WSEndPacket(lp);
WSFlush(lp);
while( (pkt = WSNextPacket(lp), pkt) && pkt != RETURNPKT ) {
WSNewPacket(lp);
if (WSError(lp)) {
error(lp);
}
}
const char *output;
if(! WSGetString(lp, &output)) {
printf("Unable to read from link\n");
return -1;
} else {
printf("%s\n", output);
}
WSReleaseString(lp, symbol);
WSPutFunction(lp, "Exit", 0);
However, WSTP returns the still unsimplified expression from the WSGetString() call. I expected to see "4 a - b" as the result of "FullSimplify[(a + a + a + a - b)]".
I then attempted using EnterTextPacket and ReturnTextPacket but it isn't clear how these work.
My goal is to simplify algebraic expressions through WSTP. What is a working simple or common way to do this?