hi, i am having trouble turning a string with function "pow" into an expression. an example of the code is given below along with the output. i cannot figure out what i am doing wrong. thanks for your help in advance. -------- #include <iostream> #include <string> #include <ginac/ginac.h> #include <ginac/power.h> using namespace std; using namespace GiNaC; int main() { lst all; all.append(symbol("x")); // no pow string str2 = "x*x"; ex e2(str2, all); cout << "nopow : " << e2 << endl; // with pow string str = "pow(x, 2)"; ex e(str, all); cout << "withpow: " << e << endl; return 0; } the output is: nopow : x^2 terminate called after throwing an instance of 'std::runtime_error' what(): no function 'pow' with 2 parameters defined Aborted -------------------- -- saurav
I am resending this mail. This is a very critical issue for me. I absolutely must be able to change a string into an expression. And if I am doing it wrong, please show it to me. Thanks, Saurav Saurav Pathak [Mon, Jan 30, 2006 at 07:31:20PM -0500]: + hi, + + i am having trouble turning a string with function "pow" into an + expression. an example of the code is given below along with the + output. i cannot figure out what i am doing wrong. + + thanks for your help in advance. + -------- + #include <iostream> + #include <string> + #include <ginac/ginac.h> + #include <ginac/power.h> + using namespace std; + using namespace GiNaC; + + int main() + { + lst all; + all.append(symbol("x")); + + // no pow + string str2 = "x*x"; + ex e2(str2, all); + cout << "nopow : " << e2 << endl; + + // with pow + string str = "pow(x, 2)"; + ex e(str, all); + cout << "withpow: " << e << endl; + + return 0; + } + + the output is: + nopow : x^2 + terminate called after throwing an instance of 'std::runtime_error' + what(): no function 'pow' with 2 parameters defined + Aborted + -------------------- + -- + saurav
Chris Dams wrote:
Dear Saurav,
On Tue, 2006-02-07 at 16:13 -0500, Saurav Pathak wrote:
+ string str = "pow(x, 2)";
Change this into string str = "x^2"; and you're fine.
Hi Chris, In real life, I get such strings from an external parser that converts MathML. Some functions are complicated and have other functions embedded---for instance exponentials. I don't want to further parse such a string. Thanks, Saurav
Dear Saurav, On Wed, 2006-02-08 at 07:28 -0500, Saurav Pathak wrote:
In real life, I get such strings from an external parser that converts MathML. Some functions are complicated and have other functions embedded---for instance exponentials. I don't want to further parse such a string.
What about defining your own function then. For instance, DECLARE_FUNCTION_2P(my_pow); REGISTER_FUNCTION(my_pow,dummy()); In that case you would only need to change the word "pow" in the output of your parser into "my_pow". After that you could use the constructor that makes an ex from a string and then you could get a real power object again by doing .subs(my_pow(wild(0),wild(1))==power(wild(0),wild(1)). Best, Chris
participants (2)
-
Chris Dams
-
Saurav Pathak