[math-fun] How can I accurately calculate (p/q)^n mod 1, for large n
*From: * At 05:20 PM 4/23/2011, Dan Asimov wrote:
Maybe I should be more specific.
Mathematica can do a loop of length 10000, say calculating
100*Floor[Mod[(3/2)^k,1]]
for 10001 <= k < 20000,
but when I try to do something like that for a loop of size 100,000 or 1,000,000, it seems to take forever (or hang, I'm not sure which).
--Dan
It's computing the numerators and denominators, e.g., 2^100000, exactly. In[622]:= Timing[Do[If[10^16*Floor[Mod[(3/2)^k, 1]] != 10^16*Floor[Mod[1.5^k, 1]],Print[k]], {k, 99999}]] Out[622]= {59.0911, Null} About 50 times faster: In[623]:= Timing[Do[10^16*Floor[Mod[1.5^k, 1]], {k, 99999}]] Out[623]= {1.21972, Null} Or 60 this way: In[625]:= Block[{t = 10^16},Timing[Do[t*Floor[Mod[1.5^k, 1]], {k, 99999}]]] Out[625]= {0.997455, Null} At some point, the two methods will probably differ by 1 (in 10^16). --rwg (Boy, Neil must be busy, not to have beaten me to this one.)
participants (1)
-
Bill Gosper