Timeline for My version of PowerMod breaks down around 10^308
Current License: CC BY-SA 4.0
15 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Mar 8, 2019 at 5:37 | history | edited | J. M.'s missing motivation♦ |
edited tags
|
|
Mar 8, 2019 at 5:19 | history | edited | Shinaolord | CC BY-SA 4.0 |
added 136 characters in body
|
Mar 8, 2019 at 5:02 | answer | added | Shinaolord | timeline score: 3 | |
Mar 8, 2019 at 4:57 | comment | added | J. M.'s missing motivation♦ |
Yes, you answering your own question would be good, if you got it. If you want a further diagnostic, insert the line Echo[Length[DownValues[z]]]; after your call to z[l]; , and look what happens to your original call with the default $RecursionLimit setting of 1024 , and when you increase the limit. (Yes, I'm doing these things from a smartphone.)
|
|
Mar 8, 2019 at 4:52 | comment | added | Shinaolord | @J.M.iscomputer-less That was the problem. I can either post an answer to my own question, or allow you to point out via your own answer that I was just exceeding $RecursionLimit by having a number that when expressed in binary, had >= 1024 digits. Either way, thanks, I probably could have figured this out eventually, though who knows how long. (if you are computer less, do you just remember all this stuff? I know, bad joke.) | |
Mar 8, 2019 at 4:51 | history | edited | m_goldberg | CC BY-SA 4.0 |
Improved formatting
|
Mar 8, 2019 at 4:50 | comment | added | Shinaolord | That is where My original thought at the error came from, considering 10^308 may have been (i believe, with the inclusion of 2^0=1 in binary, it is the cause of the error), and hence the list binarylist was greater than or equal to 1024, exceeding the recursion limit. I'll try modifying that limit now, as you suggested. | |
Mar 8, 2019 at 4:48 | history | edited | m_goldberg | CC BY-SA 4.0 |
deleted 3 characters in body; edited title
|
Mar 8, 2019 at 4:48 | comment | added | J. M.'s missing motivation♦ |
The warning message is pretty informative; your implementation has a recursive computation of z that is hitting the current limit. If you want to do an experiment, try Block[{$RecursionLimit = 2048}, pmod[3, 10^308, 353]] .
|
|
Mar 8, 2019 at 4:46 | history | edited | Shinaolord | CC BY-SA 4.0 |
added 239 characters in body
|
Mar 8, 2019 at 4:46 | comment | added | Shinaolord | I know this isn't the best way, I was just curious why it was breaking down. I added some bits at the end explaining what my first thought on the issue may have been. I will implement your suggestions, and see if it stills breaks. Thanks :) | |
Mar 8, 2019 at 4:45 | history | edited | m_goldberg | CC BY-SA 4.0 |
deleted 527 characters in body; edited tags; edited title
|
Mar 8, 2019 at 4:44 | comment | added | J. M.'s missing motivation♦ |
There are better ways to implement the Russian peasant algorithm, but as a starting point: z = Reverse[NestList[Mod[#^2, mod] &, a, l - 1]]; and then do val *= z[[j]] within your loop.
|
|
Mar 8, 2019 at 4:44 | history | edited | Shinaolord | CC BY-SA 4.0 |
added 231 characters in body
|
Mar 8, 2019 at 4:21 | history | asked | Shinaolord | CC BY-SA 4.0 |