1

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]
GambitSquared
  • 2,311
  • 15
  • 23
  • 1
    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... – kirma Jul 03 '16 at 08:24
  • 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. – Feyre Jul 03 '16 at 09:17
  • @Feyre Ok, but why would that matter in the calculation? – GambitSquared Jul 03 '16 at 09:18
  • Because when you don't use floating points the entire calculation is done in fixed points in fewer bits, up to apparentely 4^50 – Feyre Jul 03 '16 at 09:25
  • Can you change the expression within the Sin[] into a recurring function, afterall Sin[n]=Sin[n+2Pi]? – Feyre Jul 03 '16 at 09:27
  • @ImreVégh Probably you should reformulate your question in order to avoid it being closed as a duplicate: your question has nothing to do with plotting but is related to the precision of Sin supplied with a very large argument as showed by @mikado. I don't think this issue was discussed previously. – Alexey Popkov Jul 04 '16 at 13:08

1 Answers1

3

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.

mikado
  • 16,741
  • 2
  • 20
  • 54
  • 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. – Alexey Popkov Jul 04 '16 at 13:05
  • 1
    @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. – J. M.'s missing motivation Jul 04 '16 at 13:34
  • I do see this happen with guess as integer, but not with guess as floating point... Then the precision stays 30 until n=512 – GambitSquared Jul 04 '16 at 13:40