5
$\begingroup$

I developed a big package that does quite a bit of numerics. Is there a way to enforce that all numerical computations are done with a pre-defined accuracy? For example, can one use something like SetAccuracy[...] in the beginning of the package and then all functions automatically use that accuracy. Of course, one can wrap all functions with N[], but I wonder if that can be avoided.

EDIT: As an example, I tried changing

BeginPackage["packageName`"];
...

into

BeginPackage["packageName`"];
$MaxPrecision=10;
...

but I noticed that the computations are still done with unlimited precision (unless N[] is used to wrap expressions).

$\endgroup$
  • $\begingroup$ Well, maybe. But this is not how Mathematica is meant to work and I would question whether it is a good idea to have a package that relies on a non-standard use of numerics. Can you give an example that shows your use case more clearly? $\endgroup$ – Oleksandr R. Mar 26 '14 at 11:18
  • $\begingroup$ (Also, your $MaxPrecision is by no means localized to the package, so this will be problematic for the user.) $\endgroup$ – Oleksandr R. Mar 26 '14 at 11:23
  • $\begingroup$ I understanding your point. I know that Mathematica is meant to work as it does. However, the question is not about that. In fact, one should be able to use it to solve heavy numerical problems, and I am doing that frequently. The example you seek is way too big to be listed here, but I can simplify. Imagine a piece of code that evolves a network of electronic elements. Basically an ODE system that needs to be solved numerically. Of course, I am doing it in a very specific way so I cannot really use built in ODE solver. The point is, well, as the question states. $\endgroup$ – zorank Mar 26 '14 at 11:52
  • $\begingroup$ Okay. And you need to do it in fixed precision why exactly? Is it for performance or algorithmic reasons? $\endgroup$ – Oleksandr R. Mar 26 '14 at 14:57
  • 1
    $\begingroup$ I understood that you've already written the package. But to say it bluntly, what you're asking for (restriction to fixed precision numerical arithmetic only, localized to a specific package) is simply impossible in the abstract, because Mathematica does not support that, even at a conceptual level. To give people a chance of suggesting an implementation that works for you, it would be necessary for you to give at least some concrete detail about the structure of your package and the numerical requirements of your calculations. I understand this must be getting frustrating for you, but I ... $\endgroup$ – Oleksandr R. Mar 28 '14 at 11:22
0
$\begingroup$

By Oleksandr R: "...what you're asking for (restriction to fixed precision numerical arithmetic only, localized to a specific package) is simply impossible in the abstract, because Mathematica does not support that, even at a conceptual level."

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.