#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;
    }
  }
}
