Set Precision or Decimal places in symbolic expression

asked 2021-05-27 16:34:00 +0200

yorgos_sot gravatar image

Hello. I am currently working with some cumbersome symbolic expressions containing lots of variables. The issue I have is that I cannot view my symbolic expressions with as few decimal places as I would like. Here is a simplified example:

sage: var('x','y','z')
(x, y, z)
sage: expr = 0.1*x+0.2*y+0.3333*z
sage: show(expr)
0.100000000000000*x + 0.200000000000000*y + 0.333300000000000*z

Ideally I would like sth like:

sage: show(expr(precision=1))
0.1*x + 0.2*y + 0.3*z

or

sage: show(expr(decimals=2))
0.10*x + 0.20*y + 0.33*z
edit retag flag offensive close merge delete

Comments

1

See the answer to this question.

mwageringel gravatar imagemwageringel ( 2021-05-27 20:03:12 +0200 )edit

In the long term, I think Sage should make this easier by implementing the IPython %precision magic, but currently it is not yet implemented. There is an open ticket (#30755) which would be a first step for this.

mwageringel gravatar imagemwageringel ( 2021-05-27 20:03:34 +0200 )edit

Thank you! Worked like a charm!

yorgos_sot gravatar imageyorgos_sot ( 2021-05-27 23:34:05 +0200 )edit