[GiNaC-list] arithmetic error on concat two expressions
Alexei Sheplyakov
alexei.sheplyakov at gmail.com
Fri Aug 6 12:48:54 CEST 2010
Hello,
On Fri, Aug 06, 2010 at 12:03:11PM +0200, Kraus Philipp wrote:
> I'm new at GiNaC and I use the lib for create a gradient descent
> algorithm (symbolic calculating).
> I have a formula "a*x^3+b*y^4" and I subsitute the formula in the
> error function "0.5*(t - <formula>)^2".
> After the substitution GiNaC returns the expression
> "(0.5)*(a*x^3+b*y^4-t)^2".
>
> I use this code:
> GiNaC::ex m_expression;
> GiNaC::symtab m_exprtable;
>
> try {
> m_expression = l_parser( "a*x^3+b*y^4" );
> m_exprtable = l_parser.get_syms();
> } catch (...) {}
>
>
> GiNaC::ex l_full;
> GiNaC::symtab l_table(m_exprtable);
>
> l_table["formula"] = m_expression;
> GiNaC::parser l_parser(l_table);
>
> try {
> l_full = l_parser( "0.5*(t - formula)^2" ); // (*)
> } catch (...) {}
>
> std::cout << l_full << std::endl;
The code below does the same thing and is a bit simpler:
symbol a("a"), b("b"), x("x"), y("y"), t("t");
ex e = a*pow(x, 3) + b*pow(y, 4);
ex d = pow(t - e, 2)/2;
Also, "0.5" is inexact number, I guess this is not what you want for
a symbolic calculation.
Best regards,
Alexei
More information about the GiNaC-list
mailing list