Mathematica setting double vs. float

  • Context: Mathematica 
  • Thread starter Thread starter tau1777
  • Start date Start date
  • Tags Tags
    Float Mathematica
Click For Summary

Discussion Overview

The discussion revolves around the use of Mathematica for solving partial differential equations (PDEs) numerically, specifically focusing on the precision of numerical calculations. Participants explore the implications of using double precision versus floating point numbers and seek ways to set a global precision for calculations within a notebook.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant expresses a desire to limit the precision of calculations in Mathematica to five digits after the decimal point for improved performance.
  • Another participant provides a link to a tutorial on machine precision numbers in Mathematica.
  • A participant clarifies that their interest lies not in how Mathematica stores numbers but in how to specify a particular format for number storage.
  • One participant suggests that achieving the desired precision may not be feasible, explaining the difference between hardware double precision and software simulated floating point, and how this affects calculation speed.
  • It is proposed that using options like AccuracyGoal and PrecisionGoal in NDSolve might help improve calculation speed, although there is no straightforward method to set a global precision mode in Mathematica.
  • A participant acknowledges the complexity of the issue and indicates a shift in focus towards optimizing the solution of a large sparse matrix instead.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the feasibility of setting a global precision in Mathematica, with some expressing skepticism about the ability to achieve the desired outcome efficiently.

Contextual Notes

Participants note limitations in Mathematica's handling of precision and the potential trade-offs between speed and accuracy in numerical computations.

tau1777
Messages
29
Reaction score
0
Hi,

I'm quite new to Mathematica, and I've been trying to use it to solve some PDE's numerically, and I eventually end up with a really large matrix I have to find the solution for. I was think the calculation would go by faster if I could take the precision of the numbers down. I think its using double and I want it to be floating pt numbers.

I guess by precision I mean the number of digits, after the decimal point. So maybe I mean to say accuracy. In any case, is there a way that I can tell mathematica to only use let's say 5 digits after the decimal point?

I've already read some of the documentation, about using $MaxPrecision, and WorkingPrecision, but it doesn't seem like there is a global way to set the precision. Is there? Can I just say "I want precision 5" somehow and set that for the whole notebook?

Thanks in advanced.
 
Physics news on Phys.org
Hey Bill,

Thanks for the link. I just had a chance to look at it, thanks to all of the end of semester crazy-ness.

I have to admit I'm still confused. I understand that mathematica will have a limit on the type of numbers it can store, and how large they can be etc. I think I should clarify my question, I'm not that interested in how it's storing the numbers, but rather how I can tell it to store the numbers in a specific format.

I've looked around various help guides and they mostly bring me back to tutorials similar to the one you showed me. However I still don't know how to tell mathematica that I only want it to keep the last 5 digits after the decimal point, for all of the calculations in a notebook.

Sorry to be a pain. Thanks again for the help, and Happy Holidays.
 
OK. An overly simplified but still not completely false summary.

You may not be able to get what you want using Mathematica.

For "most ordinary calculations" in Mathematica you can either use your fast CPU built-in hardware double precision floating point OR you can use substantially slower, often far slower, software simulated floating point. The latter is almost always when you want more than 16 digits, not less. When you tell Mathematica how many digits to use that is supposed to let it know to switch to the slow software math. And slow is exactly the opposite of what you say you want. In many cases telling it you want 16 or less digits will result in it switching to hardware floating point. And your hardware floating point has exactly the same speed for 1 digit precision as it does for 16 digit precision.

Now that is for "most ordinary calculations." You might be able, in some cases, to get a complicated solver, like the literally thousands of pages of code that are hidden behind NDSolve[] to realize that it can stop beating its head against the wall when it gets an answer that is close enough to only 5 digits, instead of pounding on it trying to get 16 digits, and you might get some speed out of that. But you will likely spend days or weeks trying to figure out how to coax Mathematica into doing what you want instead of the default of what it wants.

You can try giving NDSolve[theproblem,AccuracyGoal->5] or NDSolve[theproblem,PrecisionGoal->5] (and those are different) on a simplified problem and see if this gives you orders of magnitude increase in speed.

But there isn't a switch to put Mathematica into 5 digit mode.
 
Hi Bill,

Thanks for the quick response. I understand what you mean. I guess my main issue was that this was a suggestion given to me by my project leader, so to speak, and so I went on a hunt to try and figure out if this was possible. However it doesn't seem like an easy fix, for the moment I think I will spend more time trying to get a speed up by figuring out how to solve this large sparse matrix. From what I've read about sparse matrix solutions, going that route should definitely give me a speed up.

Thanks again for the quick reply.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
Replies
4
Views
2K
  • · Replies 0 ·
Replies
0
Views
1K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 12 ·
Replies
12
Views
2K