-1

I have a third-party library, and I want to use one of the supplied constructors.

ex.h:

/** Construct example from string and a list of symbols. The input grammar is
 *  similar to the GiNaC output format. All symbols and indices to be used
 *  in the expression must be specified in a lst in the second argument.
 *  Undefined symbols and other parser errors will throw an exception.        */
ex(const std::string &s, const ex &l);

I tried the following:

symbol x("x");

ex e("x^2",x);

Unfortunately the usage of this constructor is incorrect. I get the following error message:

libc++abi.dylib: terminating with uncaught exception of type std::invalid_argument: find_or_insert_symbol: symbol "x" not found

All documentation that is provided is the comment above the declaration. I am a C++ novice, so I have no idea what is wrong.

I tried the suggestion in the first answer like the following:

symbol x("x");

ex expression;
ex e("x^2",expression);

std::cout << diff(e,x) << std::end

This results in the following error message:

libc++abi.dylib: terminating with uncaught exception of type std::invalid_argument: find_or_insert_symbol: symbol "x" not found (lldb)

Note: I tried using e and expression in diff().

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Jony
  • 53
  • 10

2 Answers2

1

You need to provide an ex reference, not a symbol reference; Try this:

ex MyEx1; //This will call to the ex default constructor for MyEx1, if it exist.
ex e("x^2",MyEx1); //This will call to the ex constructor that you want to use for e.
Rama
  • 3,222
  • 2
  • 11
  • 26
0

The second argument should be a list of symbols occuring in the string (more precisely, a GiNaC::ex handling a GiNaC::lst). This works:

    symbol x("x");
    ex e("x^2", lst{x});

The idea is that it should work with more than just one symbol:

    symbol x("x"), y("y");
    ex e("x^2-2*x*y+y^2", lst{x,y});
    cout << diff(e, x) << endl;  // prints "2*x-2*y" or similar
RichyBK
  • 73
  • 7