6
$\begingroup$

When I do something a little bit more complicated than standard documentation examples, I often hit precision problem.

Or I accidentally disprove Riemann hypothesis Like this

enter image description here

Abs[Zeta[0.989999999999999999 + 1000000000072486.88*I]]//AccountingForm
0.0000000377472

But precise value is around 0.7 if I put 0.989999999999999999`30. Or something happened with interpolation function like described here.

Often I have issues with NDSolve I got bad precision and it is difficult to find proper parameters or I got something like this “The precision of the differential equation ... is less than WorkingPrecision”. Even when I got a precise solution, plot function use low machine precision by default, etc, etc.

In every particular case I can find a solution, but work process looks like this:

  1. I spent 1 hour to write program to solve my task.
  2. I spent 4 hours to fight with precision issues.

What I would like to do is avoid step2, which is kind of expected from professional math software. I want to be a scientist, but not a programmer.

Ideally, I would like to solve my scientific problem first with high precision and with slow execution time and when I solved my problem and if time is not acceptable for me, than I would like to be a programmer and start optimization process. But how it works now, it is opposite.

My question: is there generic way to tell Mathematica to use high precision for everything? I have found some solutions like always use N[xxx, 50] and then use M`50 for every number, but then programs will look really ugly. Of course I understand, that for some specific cases it is necessary to set precision manually and precision control is implemented very good, but for generic case people should not bother about it.

If someone here has connection with Mathematica developers, is there any plans to improve it in future? Because how it is implemented now is really bad and for any serious problem it takes 80% of time to fight with different precision problems.

$\endgroup$
8
$\begingroup$

WRI Support solved my precision issue by using $Pre to SetPrecision on all MachineNumberQ values in the input.

Precision[2.1]
MachinePrecision

Now set $Pre to do the conversion.

$Pre =
  Function[{in},
   Unevaluated[in] /. 
    r_Real?MachineNumberQ :> RuleCondition@SetPrecision[r, 50],
   HoldAllComplete];

Then all Reals have Precision 50.

Precision[2.1]
50.

Unset $Pre when you are done.

$Pre =.

Precision[2.1]
MachinePrecision

You can also use Infinity for infinite precision if you dare.

Hope this helps.

$\endgroup$
  • $\begingroup$ It looks like perfect solution. Thanks a lot. I will be able to test it only in a few days. And is there something for complex numbers? $\endgroup$ – Zlelik Feb 21 '18 at 22:50
  • $\begingroup$ I got an error "Symbol $Pre is protected". I tried in cloud. Maybe it will work with desktop version, I will try later. $\endgroup$ – Zlelik Feb 21 '18 at 22:58
  • $\begingroup$ I have tested and it works for simple example like Precision[2.1], it works for Interpolation problem mentioned in the question, but it does not work for NDSolve at all and does not work for complex numbers Abs[Zeta[0.989999999999999999 + 1000000000072486.88*I]]//AccountingForm.it is only partial solution. $\endgroup$ – Zlelik Feb 28 '18 at 22:21

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.