[GiNaC-list] Re: ginac parsing from string issue

Richard B. Kreckel kreckel at ginac.de
Sun Jul 9 21:30:33 CEST 2006


Francesco Biscani wrote:

>I'm using ginac 1.3.4 and trying to transform from std::string to ex. I'm 
>using the small test program present in the FAQ:
>
>---------------------------------------------------------
>     #include <iostream>
>     #include <string>
>     #include <stdexcept>
>     #include <ginac/ginac.h>
>     using namespace std;
>     using namespace GiNaC;
>     
>     int main()
>     {
>         symbol x("x");
>         string s;
>     
>         cout << "Enter an expression containing 'x': ";
>         getline(cin, s);
>     
>         try {
>             ex e(s, lst(x));
>             cout << "The derivative of " << e << " with respect to x is ";
>             cout << e.diff(x) << ".\n";
>         } catch (exception &p) {
>             cerr << p.what() << endl;
>         }
>     }
>---------------------------------------------------------
>
>The problem is that it does not work at all. Example output:
>
>Enter an expression containing 'x': 5+x
>The derivative of x with respect to x is 1
>
>I.e., "5+x" is parsed simply as x. With different expressions I get other 
>wierd errors, like:
>
>Enter an expression containing 'x': 5+3*x^2
>The derivative of 2 with respect to x is 0.
>
>syntax error, unexpected T_EOF, expecting ']' or ',' at
>
>As strange as it sounds, ginsh seems not to have these problems
>
>Type ?? for a list of help topics.
>  
>
>>diff(x^2+sin(x),x);
>>    
>>
>2*x+cos(x)
>  
>
>>     
>>    
>>
>
>I'm using gcc 4.1.1 on Gentoo. ginac was compiled with "-O2" c(xx)flag.
>
>Thanks very much for ginac! I'm writing an algebraic manipulator software for 
>Poisson series (celestial mechanics), and ginac would really help me 
>manipulate the series' coefficients (instead of writing some ad-hoc 
>representation for them). I hope this issue can be resolved.
>  
>

I'm unable to reproduce your problem using either Debian/testing (gcc 
4.1.2-prerelease) or Debian/stable (gcc 3.3.5). Over here, it works as 
expected. I'm CCing ginac-list, maybe someone there has a similar system 
and can reproduce your problem?

The behavior you describe sounds too weird to be true. I recommend first 
using another system or compiler version in order to get a clue where it 
is coming from.

Luck
  -richy.

-- 
Richard B. Kreckel
<http://www.ginac.de/~kreckel/>



More information about the GiNaC-list mailing list