Compare commits

..

4 Commits

Author SHA1 Message Date
Peter Norvig
2e8234232d Update explanation of modular exponentiation 2026-03-29 19:44:23 -07:00
Peter Norvig
be1195dfa6 Fix formatting in TruncatablePrimes.ipynb 2026-03-29 18:50:31 -07:00
Peter Norvig
6712e8f626 Fix wording in TruncatablePrimes.ipynb 2026-03-29 18:50:08 -07:00
Peter Norvig
9ec6d0565e Add files via upload 2026-03-29 18:32:37 -07:00
4 changed files with 969 additions and 998 deletions

File diff suppressed because one or more lines are too long

View File

@@ -13,11 +13,11 @@
"\n",
"[![](https://community.wolfram.com//c/portal/getImageAttachment?filename=IMG_20181212_120939.jpg&userId=143131)](https://community.wolfram.com/groups/-/m/t/1569707)\n",
"\n",
"The 24-digit number printed on it is a prime, and as you sharpen the pencil and remove digits one at a time from the left, the resulting numbers are all primes:\n",
"The 24-digit number printed on this pencil is a prime, and as you sharpen the pencil and remove digits one at a time from the left, the resulting numbers are all primes:\n",
"\n",
" 357686312646216567629137 is prime\n",
" 57686312646216567629137 is prime\n",
" 7686312646216567629137 is prime|\n",
" 7686312646216567629137 is prime\n",
" ...\n",
" 137 is prime\n",
" 37 is prime\n",
@@ -1127,7 +1127,7 @@
"\n",
"# Note on Modular Exponentiation\n",
"\n",
"Just one more thing: none of this would work unless we can efficiently compute *a*<sup>(*n* - 1)</sup> (mod *n*). How does the `pow` builtin function do it? When *a* and *n* are 24-digit numbers, if we naively tried to compute `a ** (n - 1)`, we'd have two problems: we'd need nearly a billion petabytes to store the result, and we'd need centuries to compute it. The way around these problems is to use [modular exponentiation](https://en.wikipedia.org/wiki/Modular_exponentiation) where we apply the modulus to each intermediate result, and cut the exponent in half each iteration, so we need only do *O*(log *n*) multiplications, not *O*(*n*). That's a big difference: 10<sup>24</sup> is a trillion trillion, and log<sub>2</sub>(10<sup>24</sup>) is only 80. \n",
"Just one more thing: none of this would work unless we can efficiently compute *a*<sup>(*n* - 1)</sup> (mod *n*). How does the `pow` builtin function do it? When *a* and *n* are 24-digit numbers, if we naively tried to compute `a ** (n - 1)` and then apply (mod *n*), we'd have two problems: we'd need nearly a billion petabytes to store the result, and we'd need centuries to compute it. The way around these problems is to use [modular exponentiation](https://en.wikipedia.org/wiki/Modular_exponentiation) where we apply the modulus to each intermediate result, and cut the exponent in half each iteration, so we need only do *O*(log *n*) multiplications, not *O*(*n*). That's a big difference: 10<sup>24</sup> is a trillion trillion, and log<sub>2</sub>(10<sup>24</sup>) is only 80. \n",
"\n",
"There are two key ides that make this work:\n",
"1) *b*<sup>2*e*</sup> = (*b* × *b*)<sup>*e*</sup>\n",

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long