Re: [math-fun] FactorInteger
Slight improvement: Mathematica's front end by default displays a centerdot for implicit multiplication. Strangely, this doesn't work in old the FI function below, which displays blanks. Blanks also (by default) separate digits in blocks of 3. So the display is sometimes ambiguous. But Wolfram CE Harry Calkins showed me this workaround: FI⨉[n : _Rational | _Integer] := Defer @@ {FactorInteger@n} /. {{a_Integer, 1} -> a, {a_Integer, b_} -> a^b} /. {a_} -> a /. List -> Times E.g. In[144]:= FI⨉@BernoulliB@50]@// tim During evaluation of In[144]:= 0.006522,1 (seconds) Out[144]= (5^2 417202699 47464429777438199)/(2 3 11) (The first Bernoulli number with a square factor!) Dirty trick. I used a tiny ⨉ symbol instead of x, so you need Front End completion to input FI⨉. You may want to edit the definition. Instead of little centerdots between the factors, there's a Preferences variable Appearances|Numbers|Multiplication|Automatically display multiplication symbol between multiplied numbers Use symbol: which you can bash to be a mini ⨉. Sorry, I don't know how to bash it under program control, as in an init file. Unfactor is way nicer than with FactorInteger: UnFI⨉@Defer[x_] := x In[153]:= UnFI⨉@%144 Out[153]= 495057205241079648212477525/66 —rwg On Wed, Jan 4, 2017 at 12:44 AM Bill Gosper <billgosper@gmail.com> wrote:
There are
In[14]:= 52! Out[14]= 80658175170943878571660636856403766975289505440883277824000000000000
ways to shuffle a deck. That's just a "little" over a googol ...
In[366]:= Log[10.^100, %] Out[366]= 0.679066483922048
to the 2/3 power. The square of the cube root. And vice versa. So if anybody asks how many ways to shuffle a deck, "Oh, about the cube root of a googol squared." But this is actually low by a fairly substantial factor of In[372]:= (10.^100)^(.679 - 2/3)
Out[372]= 17.1132830416181
The actual number of shufflings is enormously composite:
In[15]:= FactorInteger@%14 Out[15]= {{2,49},{3,23},{5,12},{7,8},{11,4},{13,4},{17,3},{19,2},{23,2},{29,1},{31,1},{37,1},{41,1},{43,1},{47,1}}
But this is ugly and hard to read. The doc suggests
In[16]:= CenterDot@@(Superscript@@@%) Out[16]= 2^49\[CenterDot]3^23\[CenterDot]5^12\[CenterDot]7^8\[CenterDot]11^4\[CenterDot]13^4\[CenterDot]17^3\[CenterDot]19^2\[CenterDot]23^2\[CenterDot]29^1\[CenterDot]31^1\[CenterDot]37^1\[CenterDot]41^1\[CenterDot]43^1\[CenterDot]47^1
This actually looks neat. Except for the ^1s. Try it. But it's unclear (actually, a nice little Mathematica exercise) how to get your original number back. So I wrote something called FI
In[364]:= FI[52!] Out[364]= 2^49 3^23 5^12 7^8 11^4 13^4 17^3 19^2 23^2 29 31 37 41 43 47
In[365]:= ReleaseHold@% Out[365]= 80658175170943878571660636856403766975289505440883277824000000000000
Here is the definition: FI[n : _Rational | _Integer] := Times @@ ((HoldForm @@ {#1[[1]]})^#1[[2]] &) /@ FactorInteger[n]
And here's a spoiler for how to invert FactorInteger:
In[367]:= Times @@ (Power @@@ FactorInteger[73 137]) Out[367]= 10001
which also works on that CenterDot expression:
In[368]:= Times @@ (Power @@@ %16)
Out[368]= 80658175170943878571660636856403766975289505440883277824000000000000
Finally, you might enjoy finding a fairly nice formula for how many 0s are on the end of n!, and, more generally, what are exponents of the various prime factors. --Bill
In the Doc for SequenceCases I just stumbled on another way to get legible factorizations: In[65]:= FR[n:_Rational|_Integer]:=Row[Superscript@@@FactorInteger@n] In[66]:= FR@QPochhammer[-2,1/5,3] Out[66]= 3^45^-37^1 Try it. It's very legible, due to not suppressing the ^1s, which serve as separators. However, you'll need to write your own unfactorer which replaces Superscript with Power and List by Times. The old way (defined way below): In[75]:= FI@QPochhammer[-2,1/5,3] Out[75]= (3^4 7)/5^3 Unfactor is just ReleaseHold. On Wed, Aug 7, 2019 at 4:47 PM Bill Gosper <billgosper@gmail.com> wrote:
Slight improvement: Mathematica's front end by default displays a centerdot for implicit multiplication.
Strangely, this doesn't work in old the FI function below, which displays blanks. Blanks also (by default) separate digits in blocks of 3. So the display is sometimes ambiguous. But Wolfram CE Harry Calkins showed me this workaround:
FI⨉[n : _Rational | _Integer] := Defer @@ {FactorInteger@n} /. {{a_Integer, 1} -> a, {a_Integer, b_} -> a^b} /. {a_} -> a /. List -> Times E.g. In[144]:= FI⨉@BernoulliB@50]@// tim
During evaluation of In[144]:= 0.006522,1 (seconds)
Out[144]= (5^2 417202699 47464429777438199)/(2 3 11)
(The first Bernoulli number with a square factor!) Dirty trick. I used a tiny ⨉ symbol instead of x, so you need Front End completion to input FI⨉. You may want to edit the definition.
Instead of little centerdots between the factors, there's a Preferences variable Appearances|Numbers|Multiplication|Automatically display multiplication symbol between multiplied numbers Use symbol: which you can bash to be a mini ⨉. Sorry, I don't know how to bash it under program control, as in an init file.
Unfactor is way nicer than with FactorInteger: UnFI⨉@Defer[x_] := x In[153]:= UnFI⨉@%144
Out[153]= 495057205241079648212477525/66 —rwg
On Wed, Jan 4, 2017 at 12:44 AM Bill Gosper <billgosper@gmail.com> wrote:
There are
In[14]:= 52! Out[14]= 80658175170943878571660636856403766975289505440883277824000000000000
ways to shuffle a deck. That's just a "little" over a googol ...
In[366]:= Log[10.^100, %] Out[366]= 0.679066483922048
to the 2/3 power. The square of the cube root. And vice versa. So if anybody asks how many ways to shuffle a deck, "Oh, about the cube root of a googol squared." But this is actually low by a fairly substantial factor of In[372]:= (10.^100)^(.679 - 2/3)
Out[372]= 17.1132830416181
The actual number of shufflings is enormously composite:
In[15]:= FactorInteger@%14 Out[15]= {{2,49},{3,23},{5,12},{7,8},{11,4},{13,4},{17,3},{19,2},{23,2},{29,1},{31,1},{37,1},{41,1},{43,1},{47,1}}
But this is ugly and hard to read. The doc suggests
In[16]:= CenterDot@@(Superscript@@@%) Out[16]= 2^49\[CenterDot]3^23\[CenterDot]5^12\[CenterDot]7^8\[CenterDot]11^4\[CenterDot]13^4\[CenterDot]17^3\[CenterDot]19^2\[CenterDot]23^2\[CenterDot]29^1\[CenterDot]31^1\[CenterDot]37^1\[CenterDot]41^1\[CenterDot]43^1\[CenterDot]47^1
This actually looks neat. Except for the ^1s. Try it. But it's unclear (actually, a nice little Mathematica exercise) how to get your original number back. So I wrote something called FI
In[364]:= FI[52!] Out[364]= 2^49 3^23 5^12 7^8 11^4 13^4 17^3 19^2 23^2 29 31 37 41 43 47
In[365]:= ReleaseHold@% Out[365]= 80658175170943878571660636856403766975289505440883277824000000000000
Here is the definition: FI[n : _Rational | _Integer] := Times @@ ((HoldForm @@ {#1[[1]]})^#1[[2]] &) /@ FactorInteger[n]
And here's a spoiler for how to invert FactorInteger:
In[367]:= Times @@ (Power @@@ FactorInteger[73 137]) Out[367]= 10001
which also works on that CenterDot expression:
In[368]:= Times @@ (Power @@@ %16)
Out[368]= 80658175170943878571660636856403766975289505440883277824000000000000
Finally, you might enjoy finding a fairly nice formula for how many 0s are on the end of n!, and, more generally, what are exponents of the various prime factors. --Bill
participants (1)
-
Bill Gosper