7
$\begingroup$

I have code that takes an initial guess for a set of parameters to use in a function that I want to minimize, calculates the function, prints the value, recalculates new parameters via the gradient descent method, recalculates the function, prints it, and so on.

This is what my output looks like:

enter image description here

I don't mind it, I'm just curious as to when Mathematica decides it should use scientific notation and when it thinks regular notation is fine. At first sight, it seems random.

MWE not necessary because this is not a question related to code.

Edit: Sorry for the huge image. I've replaced it with a smaller one.

$\endgroup$
4
  • 2
    $\begingroup$ You can use NumberForm[] with its ScientificNotationThreshold setting if you want more control. $\endgroup$ Sep 27, 2018 at 13:06
  • 1
    $\begingroup$ I know I can. As I said, I don't mind which notation Mathematica uses for this; I'm just curious as to how it determines which one to use. $\endgroup$
    – Rain
    Sep 27, 2018 at 13:07
  • 1
    $\begingroup$ I don't have your numbers, so I can only hazard a guess that it's about precision differences. See e.g. {97170., 97170.`5, 97170.`4}. $\endgroup$ Sep 27, 2018 at 13:12
  • $\begingroup$ I suspect the message formatting is using the same thresholds as NumberForm. $\endgroup$ Sep 27, 2018 at 13:28

1 Answer 1

12
$\begingroup$

Mathematica uses 2 criteria to determine whether to show a number in scientific notation or not.

  1. For both arbitrary precision and machine precision numbers, use scientific notation if the exponent is not between 5 and -5 inclusive:

    123456.
    1234567.
    

    123456.

    1.23457*10^6

    and:

    1.23456*^-5
    1.23456*^-6
    

    0.0000123456

    1.23456*10^-6

  2. For arbitrary precision numbers, use scientific notation if the number of digits displayed is more than the precision:

    123400`4
    123400`5
    123400`6
    

    1.234*10^5

    1.2340*10^5

    123400.

    Basically, if Mathematica used decimal notation for all 3, then it would look like:

    123400.

    123400.

    123400.

    That is, the outputs would be indistinguishable. By using scientific notation, Mathematica is indicating the actual precision of the number.

$\endgroup$
1
  • 1
    $\begingroup$ Thank you. I think this explains it. I guess it has to do with whether the number has zeroes or not after the displayed digits (which are always five, I think). $\endgroup$
    – Rain
    Sep 27, 2018 at 22:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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