# numerical evaluation of symbolic expressions

401 views

### dirkd

Jul 4, 2010, 8:36:50 AM7/4/10
to sage-support
Why is evaluating this expression problematical?

y1(x)=x^2;y2(x)=5-x;
a0=1;an=3;Delta=(an-a0)/n;p(k)=a0+(k-1/2)*Delta;
I(n)=sum(abs(y2(p(k))-y1(p(k)))*Delta,k,1,n);
N(I(10))

SAGE respons:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "_sage_input_109.py", line 9, in <module>
open("___code___.py","w").write("# -*- coding: utf-8 -*-\n" +
_support_.preparse_worksheet_cell(base64.b64decode("eTEoeCk9eF4yO3kyKHgpPTUteDsKYTA9MTthbj0zO0RlbHRhPShhbi1hMCkvbjtwKGspPWEwKyhrLTEvMikqRGVsdGE7Ckkobik9c3VtKGFicyh5MihwKGspKS15MShwKGspKSkqRGVsdGEsaywxLG4pOwpOKEkoMTApKQ=="),globals())
+"\n"); execfile(os.path.abspath("___code___.py"))
File "", line 1, in <module>

File "/tmp/tmpk0DnhJ/___code___.py", line 6, in <module>
N(I(_sage_const_10 ))
File "", line 1, in <module>

File "/home/sage/sage/local/lib/python2.6/site-packages/sage/misc/
functional.py", line 1165, in numerical_approx
return x.numerical_approx(prec)
File "expression.pyx", line 3797, in
sage.symbolic.expression.Expression.n (sage/symbolic/expression.cpp:
17022)
TypeError: cannot evaluate symbolic expression numerically

If I leave out the N( )-operator on the last line the block evaluates
to

1/500*sum(abs(-4*k^2 - 56*k + 329), k, 1, 10)

which can be evaluated in a new inputbox. Why not in one step?

### Burcin Erocal

Jul 4, 2010, 9:17:07 AM7/4/10
Hi,

On Sun, 4 Jul 2010 05:36:50 -0700 (PDT)
dirkd <dirk.da...@gmail.com> wrote:

> Why is evaluating this expression problematical?
>
> y1(x)=x^2;y2(x)=5-x;
> a0=1;an=3;Delta=(an-a0)/n;p(k)=a0+(k-1/2)*Delta;
> I(n)=sum(abs(y2(p(k))-y1(p(k)))*Delta,k,1,n);
> N(I(10))
>
> SAGE respons:

<snip>

> File "expression.pyx", line 3797, in
> sage.symbolic.expression.Expression.n (sage/symbolic/expression.cpp:
> 17022)
> TypeError: cannot evaluate symbolic expression numerically
>
>
> If I leave out the N( )-operator on the last line the block evaluates
> to
>
>
> 1/500*sum(abs(-4*k^2 - 56*k + 329), k, 1, 10)
>
> which can be evaluated in a new inputbox. Why not in one step?

The result returned from maxima uses a symbolic function object created
on the fly. This is quite different from the sum() function
available on the command line, and unfortunately, it doesn't define a
numerical evaluation function, _evalf_().

If no one beats me to it, I will provide a symbolic sum function in the
next few days. I opened a ticket for this problem:

http://trac.sagemath.org/sage_trac/ticket/9424

Thanks for the report.

Burcin