Message Boards Message Boards

Large time difference when >= is used compared to ==?

Posted 9 years ago
POSTED BY: Paul Cleary
3 Replies
Posted 9 years ago

Thanks David and llian, I now see where the difference comes from, regarding the N[n] that certainly speeded it up, the timings went down to 8.61 and 51.76 respectively.

POSTED BY: Paul Cleary

Note that And uses short-circuit evaluation, and count for how many numbers computing the GeometricMean will be necessary:

  Length[Select[
    Range[100, 
     1000000], (a = IntegerDigits[#]; b = RotateLeft[a]; 
      c = RotateLeft[b]; 
      IntegerLength[FromDigits[b]] == IntegerLength[FromDigits[c]] == 
        IntegerLength[#] && Length[Union[b]] >= 3) &]]

(* Out[17]= 805752 *)

but if the last condition used ==, there would only be 67896 -- much less work.

Also, the timings should improve if you use GeometricMean[{N[n], FromDigits[b]}], since machine precision computation is faster.

POSTED BY: Ilian Gachevski
Posted 9 years ago

On my Core i5 laptop it goes from 33s to 268s. About the same ratio.

POSTED BY: David Keith
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract