The following example from the tutorial
GiNaC::symbol x, y;
GiNaC::symtab table;
table["x"] = x+log(y)+1;
GiNaC::parser reader(table);
GiNaC::ex e = reader("5*x3 - x2");
fails with the following exception:
terminate called after throwing an instance of 'std::invalid_argument'
what(): find_or_insert_symbol: name "x" does not correspond to a symbol
Remove silly checks from find_or_insert_symbol, and fix its return value
(should be ex, not symbol).
namespace GiNaC {
-symbol
+ex
find_or_insert_symbol(const std::string& name, symtab& syms, const bool strict)
{
symtab::const_iterator p = syms.find(name);
- if (p != syms.end()) {
- if (is_a<symbol>(p->second))
- return ex_to<symbol>(p->second);
- else
- throw std::invalid_argument(
- std::string("find_or_insert_symbol: name \"")
- + name + "\" does not correspond to a symbol");
- }
-
+ if (p != syms.end())
+ return p->second;
if (strict)
throw std::invalid_argument(
typedef std::map<std::string, ex> symtab;
/**
- * Find the symbol with the @a name in the symbol table @a syms.
+ * Find the symbol (or abbreviation) with the @a name in the symbol table @a syms.
*
* If symbol is missing and @a strict = false, insert it, otherwise
* throw an exception.
*/
-extern symbol
+extern ex
find_or_insert_symbol(const std::string& name, symtab& syms,
const bool strict);