New answers tagged

3 votes

C, Julia, Python, Maxima, Mathematica, ChatGPT and numerical errors

bc can calculate this to an arbitrary number of decimal places, and is installed on most Linux systems: ...
Simon Branch's user avatar
2 votes

C, Julia, Python, Maxima, Mathematica, ChatGPT and numerical errors

I ran it in Python 3.12.1 and the result is -3.7701774498987155. Interestingly, it is now identical to Julia until the very final digits. Seems there was an update to the maths libraries? Seeing as ...
Caleb Fuller's user avatar
11 votes

C, Julia, Python, Maxima, Mathematica, ChatGPT and numerical errors

We could use exact arithmetic to compute the correct value. A range of exact numbers $e$ correspond to the same $a=5.0$ representation in float32 IEEE754, plot over this range: You can see that after ...
Yaroslav Bulatov's user avatar
16 votes

C, Julia, Python, Maxima, Mathematica, ChatGPT and numerical errors

Other answers have explained the results from Python, Julia, Maxima, C, and Mathematica. I'll explain the result you got from ChatGPT. Generally, the way that ChatGPT works is that you ask a question, ...
Tanner Swett's user avatar
30 votes

C, Julia, Python, Maxima, Mathematica, ChatGPT and numerical errors

I thought it would be interesting to see how the number of bits of precision affects the error. I wrote the following using arb, a library for interval arithmetic (and in particular a library that ...
davidlowryduda's user avatar
13 votes

C, Julia, Python, Maxima, Mathematica, ChatGPT and numerical errors

Perhaps the reason you are stunned is that you don't understand that what you are asking to calculate is impossible to ever calculate exactly. So if you want the answer to some precision, you need to ...
Secto Kia's user avatar
  • 239
7 votes

C, Julia, Python, Maxima, Mathematica, ChatGPT and numerical errors

Intrigued by the answer by Lutz Lehmann, I gave Fortran with the gfortran compiler (version 13.2.0) a spin because for one it wasn't considered by the OP. For two, since 2008 the intrinsic ...
Buttonwood's user avatar
32 votes

C, Julia, Python, Maxima, Mathematica, ChatGPT and numerical errors

This function, as any similar hill, tent or hat functions, implements the expansion-and-folding scheme. This means that in the most benign interpretation you lose in each iteration one bit from the ...
Lutz Lehmann's user avatar
  • 5,974
12 votes

C, Julia, Python, Maxima, Mathematica, ChatGPT and numerical errors

Unfortunately this comes down to the math library. IEEE754 does not mandate exactly how the cosine should be computed (technically one doesn't even need to include a function to compute the cosine to ...
Federico Poloni's user avatar
0 votes

How to design a sin and an arcsin function such that arcsin(sin(x))=x, where x is a finite precision floating point number

I think it is possible. You would need two ingredients: very accurate sin function and very accurate arcsin function. How accurate? Take this with grain of salt (I don't have the proof!), but if x is ...
Radivoje Vasiljević's user avatar

Top 50 recent answers are included