1
$\begingroup$

Question 1: If I change guess to a integer, for example guess = 1 then ListPlot already stops at $n=50$. This seems strange to me, any ideas on why this happens? Update, if I change guess to guess = 1.0 then this doesn't occur. Maybe this has something to do with the loss of precision with Sin?

Question 2: Why does the ListPlot stop at $n=512$? Is there something special about the number $4^{512}$?

For reference; to see what is going on I also included the Grid.

Clear["Global`*"]
guess = 1.5;
iter = 1000;
n = Table[j, {j, 0, iter}];
y = SetPrecision[Sin[4^n guess]^2, 30];
Grid[Transpose[{n, y}], Frame -> All];
ListPlot[y]
$\endgroup$
6
  • 1
    $\begingroup$ 2^1024, or 4^512 is the maximum machine number (essentially IEEE 64-bit floating point number), and plotting functions use machine numbers in their operation... $\endgroup$
    – kirma
    Commented Jul 3, 2016 at 8:24
  • $\begingroup$ If you use guess=1, you aren't even using a floating point, setting it to 1. makes it use floating point, if you use some other software like Python you'll get used to always adding a . after an integer. $\endgroup$
    – Feyre
    Commented Jul 3, 2016 at 9:17
  • $\begingroup$ @Feyre Ok, but why would that matter in the calculation? $\endgroup$ Commented Jul 3, 2016 at 9:18
  • $\begingroup$ Because when you don't use floating points the entire calculation is done in fixed points in fewer bits, up to apparentely 4^50 $\endgroup$
    – Feyre
    Commented Jul 3, 2016 at 9:25
  • $\begingroup$ Can you change the expression within the Sin[] into a recurring function, afterall Sin[n]=Sin[n+2Pi]? $\endgroup$
    – Feyre
    Commented Jul 3, 2016 at 9:27

1 Answer 1

3
$\begingroup$

I offer the following slightly modified version as a better illustration of the problem:

Clear["Global`*"]
guess = N[3/2, 300];
iter = 1000;
n = Table[j, {j, 0, iter}];
y = Sin[4^n guess]^2;
Grid[Transpose[{n, y}], Frame -> All]
ListPlot[y]

What see from the Grid is that at each iteration the number of residual digits of precision decreases - we have 2 less bits available after reduction mod 2 Pi each time. Eventually there is no precision left and we have a result indistinguishable from zero.

This is slightly hidden in the original version, since the SetPrecision function is applied after precision has been lost - we neither force Mathematica to work to higher precision nor track it accurately.

$\endgroup$
3
  • $\begingroup$ Good catch (+1)! There is a catastrophic loss of precision when Sin is supplied with a very large argument. I don't think it was discussed previously. $\endgroup$ Commented Jul 4, 2016 at 13:05
  • 1
    $\begingroup$ @Alexey, trig functions usually do range reduction by adding/subtracting appropriate multiples of the period; for a large enough argument then, you are subtracting two large numbers just to get something within the fundamental domain. $\endgroup$ Commented Jul 4, 2016 at 13:34
  • $\begingroup$ I do see this happen with guess as integer, but not with guess as floating point... Then the precision stays 30 until n=512 $\endgroup$ Commented Jul 4, 2016 at 13:40

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