解决电力塔

发布于 2024-10-11 19:29:28 字数 297 浏览 1 评论 0原文

a=2^Power[10^6, 10^9] 3^Power[4^9, 7^5]
TwoTower[n_] := Nest[2^# &, 1, n]

满足 TwoTower[n]>a 的最小 n 是多少?这个问题有笔和纸在Quora上回答,这里有没有办法使用Mathematica?

a=2^Power[10^6, 10^9] 3^Power[4^9, 7^5]
TwoTower[n_] := Nest[2^# &, 1, n]

What's the smallest n such that TwoTower[n]>a? This question had a pen-and-paper answer on Quora, is there a way to use Mathematica here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蛮可爱 2024-10-18 19:29:28

只是一些想法(没有仔细检查)。如果我们遵循该链接中的建议并开始记录日志(基数为 2),那么显而易见的第一件事就是我们可以安全地忘记前因子(3 的幂),因为

Log[Log[a*b]] = Log[Log[a]+Log[b]] = Log[Log[a]]+Log[1+Log[b]/Log[a]] = 
= Log[Log[a]] + Log[b]/Log[a] + O((Log[b]/Log[a])^2), Log[b]<<Log[a]

其中 a 是一个幂2 和 b 是 3 的幂。然后,我们可以只关注 2 的幂。如果我们定义 logpower:

Clear[log2,power];
log2[2] = 1;
log2[1] = 0;
log2[a_*b_] := log2[a] + log2[b];
log2[a_^b_] := b*log2[a];
log2[power[a_, b_]] := b*log2[a]; 

那么下面似乎给出了答案:

In[62]:= 
    Length[NestWhileList[N[Log[2, #]] &,log2[log2[log2[ 2^power[10^6, 10^9]]]] /. 
           log2 -> (N[Log[2, #]]&), # > 1 &]] - 1 + 3

Out[62]= 7

由于 NestWhile 的工作方式(最后一个元素已经违反了条件),我们减去 1,并添加 3,因为在进入 NestWhileList 之前我们已经应用了 log2 3 次。如果没有在网站上注册,我无法阅读该链接中的所有评论,因此我不知道他们的答案或正确答案是什么。

编辑:

我发现上面的解决方案可以表达得更优雅一些,这样就根本不需要人工交互:

ClearAll[log2, power];
log2[2] = 1;
log2[1] = 0;
log2[a_*b_] := log2[a] + log2[b];
log2[(power | Power)[a_, b_]] := b*log2[a];
log2[x : (_Integer | _Real)] := N[Log[2, x]];
power[a_, b_] :=
   With[{eval = Quiet[Check[Power[a, b], $Failed]]},
     eval /; (eval =!= $Failed)]

然后,解决方案本身看起来更容易一些:

In[8]:=Length[NestWhileList[log2,2^power[10^6, 10^9], ! FreeQ[#, power] || # > 1 &]] - 1

Out[8] = 7

Just some thoughts (did not carefully check). If we follow the suggestion in that link and start taking logs (base 2), first thing which seems obvious is that we can safely forget the prefactor (the power of 3), since

Log[Log[a*b]] = Log[Log[a]+Log[b]] = Log[Log[a]]+Log[1+Log[b]/Log[a]] = 
= Log[Log[a]] + Log[b]/Log[a] + O((Log[b]/Log[a])^2), Log[b]<<Log[a]

where a is a power of 2 and b is a power of 3. Then, we can focus on just the power of 2. If we define our version of log and power:

Clear[log2,power];
log2[2] = 1;
log2[1] = 0;
log2[a_*b_] := log2[a] + log2[b];
log2[a_^b_] := b*log2[a];
log2[power[a_, b_]] := b*log2[a]; 

Then the following seems to give the answer:

In[62]:= 
    Length[NestWhileList[N[Log[2, #]] &,log2[log2[log2[ 2^power[10^6, 10^9]]]] /. 
           log2 -> (N[Log[2, #]]&), # > 1 &]] - 1 + 3

Out[62]= 7

We subtract 1 due to the way NestWhile works (the last element already violates the condition), and add 3 because we applied log2 3 times already, before entering NestWhileList. I was not able to read all the comments in that link without registering on the site, so I don't know their answer or what is the correct answer.

Edit:

It occured to me that the above solution can be expressed a little more elegantly so that no human interaction is at all needed:

ClearAll[log2, power];
log2[2] = 1;
log2[1] = 0;
log2[a_*b_] := log2[a] + log2[b];
log2[(power | Power)[a_, b_]] := b*log2[a];
log2[x : (_Integer | _Real)] := N[Log[2, x]];
power[a_, b_] :=
   With[{eval = Quiet[Check[Power[a, b], $Failed]]},
     eval /; (eval =!= $Failed)]

Then, the solution itself looks a bit easier:

In[8]:=Length[NestWhileList[log2,2^power[10^6, 10^9], ! FreeQ[#, power] || # > 1 &]] - 1

Out[8] = 7
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文