Dimensional Analysis

59 views
Skip to first unread message

XR-7 RKE

unread,
Nov 17, 2022, 4:18:32 AM11/17/22
to sympy
Hey guys,

Does sympy support round a number to significant figures?

SCR-20221117-m64.png

Peter Stahlecker

unread,
Nov 17, 2022, 4:46:42 AM11/17/22
to sy...@googlegroups.com
you might want to check floating point numbers in the sympy documentation.

--
You received this message because you are subscribed to the Google Groups "sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/4f5ae36a-60fb-429b-8f7a-e00e5637853fn%40googlegroups.com.

Oscar Benjamin

unread,
Nov 17, 2022, 5:04:20 AM11/17/22
to sy...@googlegroups.com

gu...@uwosh.edu

unread,
Nov 17, 2022, 8:30:51 AM11/17/22
to sympy
An alternative interpretation of your question is that you are asking if sympy is aware of the rules for propagating significant digits through calculations? The answer is no. You have to apply the rules yourself to decide appropriate rounding.

Additional alternatives:  1) set up interval arithmetic to get a more precise version of the significant figures rules; 2) do full error propagation to determine uncertainties in your computations.

Jonathan

Roberto Colistete Jr.

unread,
Nov 17, 2022, 10:06:54 AM11/17/22
to sy...@googlegroups.com
    Not SymPy, but the Uncertainties (Python module) does what you want if you use "print(x)", where x is a ufloat number (with uncertainties).
https://pythonhosted.org/uncertainties/user_guide.html#printing



Em 17/11/2022 10:30, gu...@uwosh.edu escreveu:

XR-7 RKE

unread,
Nov 17, 2022, 4:16:51 PM11/17/22
to sympy
Yes. This exactly. Oh. sadly sympy doesn't support :'(

Peter Stahlecker

unread,
Nov 17, 2022, 9:28:03 PM11/17/22
to sy...@googlegroups.com
My limited understanding of sympy is, that it is used for symbolic calculations.
If you then want numerical calculations, is it not better to convert your sympy results to, say, numpy results ( using e.g. lambdify(..) )? Then you have the full power of numpy, scipy, etc. There is even a special library to handle calculations with floats having uncertainties. (This was mentioned earlier in this dialogue) 

--
Best regards,

Peter Stahlecker

Jeremy Monat

unread,
Nov 17, 2022, 11:03:30 PM11/17/22
to sy...@googlegroups.com
Here's an example of using SymPy's lambdify() to convert a SymPy function to a numerical function that e.g. SciPy can use: Numerically Solve an ODE in SciPy

Best,
Jeremy Monat

S.Y. Lee

unread,
Nov 21, 2022, 9:41:24 PM11/21/22
to sympy
If you expect correct decimal arithmetic and rounding, it could be better look at the alternatives like decimal library.
I don't think that there is any good unified library of combining arbitrary precision arithmetic with different rounding option yet,
but it would not be more difficult to program straightforwardly from integers, if you want to experiment with customized decimal, rounding option,
unless someone provides some encyclopedia.

XR-7 RKE

unread,
Nov 24, 2022, 5:19:23 PM11/24/22
to sympy
Thank you. Will check it out!
Reply all
Reply to author
Forward
0 new messages