<html><head></head><body><div style="font-family: Verdana;font-size: 12.0px;"><div>Awesome ! That works ! Do you have an idea on how to convert the ex returned by diff back to a std::string ?
<div> 
<div name="quote" style="margin:10px 5px 5px 10px; padding: 10px 0 10px 10px; border-left:2px solid #C3D9E5; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">
<div style="margin:0 0 10px 0;"><b>Gesendet:</b> Dienstag, 28. März 2017 um 22:49 Uhr<br/>
<b>Von:</b> "Richard B. Kreckel" <kreckel@in.terlu.de><br/>
<b>An:</b> ginac-list@ginac.de<br/>
<b>Betreff:</b> Re: [GiNaC-list] Converting an expression to std::string and back again</div>

<div name="quoted-content">On 03/28/2017 09:57 AM, Robert Hai wrote:<br/>
> for a project I need to convert a std::string to an ex, diff it and then convert it back to a std::string. For the conversion from std::string to ex I found this constructor :<br/>
><br/>
> /** Construct example from string and a list of symbols. The input grammar is * similar to the GiNaC<br/>
> output format. All symbols and indices to be used * in the expression must be specified in a lst in the<br/>
> second argument. * Undefined symbols and other parser errors will throw an exception. */<br/>
> ex(const std::string &s, const ex &l);<br/>
><br/>
> at <a href="http://www.ginac.de/reference/classGiNaC_1_1ex.html#ace68037326c1a2b8c93a56716599ec7a" target="_blank">http://www.ginac.de/reference/classGiNaC_1_1ex.html#ace68037326c1a2b8c93a56716599ec7a</a><br/>
><br/>
> So I tried doing the following :<br/>
><br/>
> symbol x("x");<br/>
> ex expression;<br/>
> ex e("x^2",expression);<br/>
> std::cout << diff(e,x) << std::endl;<br/>
><br/>
> But this leads me to this exception :<br/>
><br/>
> std::invalid_argument: find_or_insert_symbol: symbol "x" not found<br/>
><br/>
> Note that I tried using expression and e in diff(e,x). Unfortunately I could not find any documentation on how to convert the expression diff returns to a std::string.<br/>
<br/>
The second argument should be a GiNaC::lst with all symbols that occur<br/>
in the string. Try this:<br/>
<br/>
symbol x("x");<br/>
lst syms = {x};<br/>
ex e("x^2", syms);<br/>
std::cout << diff(e, x) << std::endl;<br/>
// -> 2*x<br/>
<br/>
All my best,<br/>
-richy.<br/>
--<br/>
Richard B. Kreckel<br/>
<<a href="http://in.terlu.de/~kreckel/" target="_blank">http://in.terlu.de/~kreckel/</a>><br/>
_______________________________________________<br/>
GiNaC-list mailing list<br/>
GiNaC-list@ginac.de<br/>
<a href="https://www.cebix.net/mailman/listinfo/ginac-list" target="_blank">https://www.cebix.net/mailman/listinfo/ginac-list</a></div>
</div>
</div>
</div></div></body></html>