Precision Issue in Mathematica

In summary, the person is trying to speed up an equation and the results are slow. They say that the equation is slow because it has many derivatives and summations. They also say that it is slow because it is expensive to use machine-precision numbers. They suggest parallelism as a way to speed up the process.
  • #1
EngWiPy
1,368
61
Hello,

I have an equation that when I wrote using Mathematica to get results, the results were wrong in some places. This has nothing to do with the code, which is a 100% correct code. It is a presicion issue. But when I increased the precision, say up to 20, even to 10, the code takes a lot (I mean a huge amount) of running time, and I got no results. The question is: how can I increase the precision to get accurate results in an efficient way in time?

Thanks in advance
 
Physics news on Phys.org
  • #2
Arbitrary-precision numbers are inherently slower to compute than machine-precision numbers. It is an unavoidable trade-off, so there is only going to be so much that you can do since you need the precision.

However, in general, when trying to speed up an algorithm the most important thing to do is to measure the different parts of your algorithm and actually find out where the bottleneck is. NEVER simply assume that you know which part is the slowest. Test it and find out for sure. Once you have identified the slowest part you can try to code it in an algebraically equivalent but more efficient manner or you can parallelize it etc. depending on the details.
 
  • #3
DaleSpam said:
Arbitrary-precision numbers are inherently slower to compute than machine-precision numbers. It is an unavoidable trade-off, so there is only going to be so much that you can do since you need the precision.

However, in general, when trying to speed up an algorithm the most important thing to do is to measure the different parts of your algorithm and actually find out where the bottleneck is. NEVER simply assume that you know which part is the slowest. Test it and find out for sure. Once you have identified the slowest part you can try to code it in an algebraically equivalent but more efficient manner or you can parallelize it etc. depending on the details.

I am affraid that, I have nothing to do with the equations. But, I will try.

Furthermore, my equation consists of more than 10 summations, and has many derivatives in each iteration. So, I think it is natural to be slow. But it is affordable for the case of machine-precision numbers.

Regards
 
  • #4
FYI, my final project for my dissertation involved a calculation that took 27 PC-days of computation. I parallelized the function and ran it over one weekend using all of my lab's computers as a jury-rigged cluster. Many universities now offer this kind of thing on a more "official" basis. If it is really a problem you might look into the resources available.
 
  • #5
DaleSpam said:
FYI, my final project for my dissertation involved a calculation that took 27 PC-days of computation. I parallelized the function and ran it over one weekend using all of my lab's computers as a jury-rigged cluster. Many universities now offer this kind of thing on a more "official" basis. If it is really a problem you might look into the resources available.

Wow. Parallelism is a smart idea. I don't know, but I think the inter-dependence of the code may make this process difficult. Anyway, it is not that necessary for my thesis, whereas I believe that your project was worthy (27 PC-days).

But I felt that when I increased the precesion, the running time was largely incraesed relative to the corresponding machine-precision numbers.

Best regards
 

What is precision issue in Mathematica?

Precision issue in Mathematica refers to the limited number of digits that can be represented and manipulated in a numerical calculation. This can lead to rounding errors and loss of accuracy in calculations.

How can I improve precision in my Mathematica calculations?

There are several ways to improve precision in Mathematica. One option is to use the SetPrecision function to set a higher precision for specific numbers or variables. Another option is to use the N function to convert exact numbers to approximate numbers with a specified precision. Additionally, using high-precision numbers such as MachinePrecision or DoublePrecision can also improve precision.

Why do precision issues occur in Mathematica?

Precision issues occur in Mathematica because of the way numbers are represented and stored in the computer's memory. The computer can only store a limited number of digits, so when performing calculations with numbers that have more digits than the computer can handle, rounding errors and loss of precision can occur.

How does Mathematica handle precision in different types of calculations?

Mathematica uses different precision tracking methods for different types of calculations. For algebraic and symbolic calculations, exact precision is maintained. For numerical calculations, Mathematica uses a precision tracking system that can automatically increase precision when needed. However, this can also lead to slower performance.

Are there any precautions I can take to avoid precision issues in Mathematica?

Yes, there are several precautions you can take to avoid precision issues in Mathematica. One is to use high-precision numbers whenever possible. Another is to avoid using approximate numbers in calculations, as this can lead to compounding rounding errors. You can also use the Chop function to remove small values that may be the result of precision errors.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
415
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
262
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
18
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
21
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
Back
Top