CVSROOT: /cvs/purrs
Module name: purrs
Changes by: zolo(a)cs.unipr.it 2002-10-20 18:35:23
Modified files:
src : rr_solver.cc
Log message:
Modified the structure of `solve()' so that characteristic equation and
roots are computed only in the case of recurrences with constant
coefficients.
Other little changes.
Patches:
http://www.cs.unipr.it/cgi-bin/cvsweb.cgi/purrs/src/rr_solver.cc.diff?cvsro…
Hi there,
implementing interactive GiNaC programs is made extremely painful
by the fact that GiNaC's parser accepts too much.
This claim can be checked with the attached program derived from an
example in the tutorial. Basically, stuff at the end of the string
sometimes is accepted even if nonsensical. Moreover, once a well-formed
string has been parsed, things tend to be accepted anyway.
$ a.out
Enter an expression containing 'x': x.13 put what you want here
The derivative of x with respect to x is 1.
$ a.out
Enter an expression containing 'x': x.
The derivative of 0 with respect to x is 0.
Enter an expression containing 'x': x.13 put what you want here
The derivative of x with respect to x is 1.
Again:
$ a.out
Enter an expression containing 'x': 0
The derivative of 0 with respect to x is 0.
Enter an expression containing 'x': log(|x|)
The derivative of 0 with respect to x is 0.
Enter an expression containing 'x': log(|x|+put anything here)
The derivative of 0 with respect to x is 0.
All the best
Roberto
--
Prof. Roberto Bagnara
Computer Science Group
Department of Mathematics, University of Parma, Italy
http://www.cs.unipr.it/~bagnara/
mailto:bagnara@cs.unipr.it
#include <iostream>
#include <string>
#include <stdexcept>
#include <ginac/ginac.h>
using namespace std;
using namespace GiNaC;
int main()
{
while (true) {
symbol x("x");
string s;
cout << "Enter an expression containing 'x': ";
getline(cin, s);
if (!cin)
return 0;
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;
}
}
}