Hi Cristóvão!

On 24 Okt., 00:50, Cristóvão Sousa <cris...@gmail.com> wrote:
> But, is there any way of round reals even if they are inside a symbolic
> expression?

I guess it would be needed to define a recursive function for that
purpose, using operator and operands of a symbolic expression. Such
as:

sage: def symround(x, ndigits=0):
....:     if hasattr(x,'operator') and x.operator():
....:         return x.operator()(*map(lambda
y:symround(y,ndigits=ndigits), x.operands()))
....:     try:
....:         return round(x,ndigits=ndigits)
....:     except TypeError:
....:         return x
....:
sage: sr = (1.01*x^2+(0.1*0.1-0.01)*x)*2.0001*sin(3.01*x)
sage: sr
(2.02010100000000*x^2 +
(3.46962042430121e-18)*x)*sin(3.01000000000000*x)
sage: symround(sr)
2.0*x^2.0*sin(3.0*x)
sage: symround(sr,ndigits=10)
2.020101*x^2.0*sin(3.01*x)

There might be ways to do it more efficient, though. I don't know.

Cheers,
Simon

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to