5
$\begingroup$

Mysterious behavior of Precision:

{{1.0+I*0.0},{0.0+I*0.0}} // SetPrecision[#,30]& // Precision // Print;
0.
{{1.0},{0.0}} // SetPrecision[#,30]& // Precision // Print;
30.

Why is the precision zero in the first instance, but not the second?

This led to some tough-to-diagnose program behaviors!

$\endgroup$
  • 1
    $\begingroup$ This seems to be closely related: How to eliminate the zero real part of a purely imaginary number?. $\endgroup$ – Artes Feb 11 '14 at 0:12
  • 1
    $\begingroup$ It seems like the 0.0+I*0.0 is the culprit. Try I // SetPrecision[#, 30] & // Precision, 1 // SetPrecision[#, 30] & // Precision, 0 // SetPrecision[#, 30] & // Precision, 0.0 // SetPrecision[#, 30] & // Precision, 0.0 I // SetPrecision[#, 30] & // Precision and especially pay attention to the last two. I assume that Precision when applied to an array takes the minimum of the precisions of the elements of the array; the first element of {{1.0+I*0.0},{0.0+I*0.0}} has precision 30, whereas the second has precision 0, so the result is 0, but I'm not sure why 0.0I has precision 0. $\endgroup$ – DumpsterDoofus Feb 11 '14 at 0:35
  • $\begingroup$ And there's also precision Infinity: f[x_] := x // SetPrecision[#, 30] & // Precision; {f[0], f[0.0], f[0.0 + 0.0 I], f[1.0], f[1.0 I]} gives {[Infinity], [Infinity], 0., 30., 30.} $\endgroup$ – bill s Feb 11 '14 at 1:43
1
$\begingroup$

Not receiving an answer, the following "workaround" returns Precision as a rounded-up integer multiple of MachinePrecision:

Precision$TNS[arg_] := arg//
  Precision//
    Which[
        NumberQ[#] && (#>0.0),
        {#},
        True,
        {arg}//Flatten//
          Map[Precision,#]&//
            Select[#,(NumberQ[#] && (#>0.0))&]&
    ]&//Max[#,MachinePrecision]&//
      (#-1)/MachinePrecision&//Ceiling//
        #*MachinePrecision&;
This workaround suffices (seemingly) for my main purpose, which is to assess and if necessary adaptively increase the precision of large-condition Real and Complex array arguments that are supplied to SingularValueDecomposition[_].

$\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.