Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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!

share|improve this question
1  
This seems to be closely related: How to eliminate the zero real part of a purely imaginary number?. –  Artes Feb 11 at 0:12
1  
+1 for minimal example of behavior. –  DumpsterDoofus Feb 11 at 0:30
1  
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. –  DumpsterDoofus Feb 11 at 0:35
    
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.} –  bill s Feb 11 at 1:43

1 Answer 1

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[_].

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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