Let’s take a look at the AOPS post on its Facebook page today. The animation shows a general solution for any integer can be put on the right hand side of equation just like the lucky number 7.
The algorithm and the implementation contains solutions for both positive and negative ’s.
r
Use Fold to create such tower for arbitrary length. The number 5 in the code to control the levels of the tower. In general, generate levels.
n
n+1
In[]:=
Style[Fold[#2*Ceiling[#1]&,r,ConstantArray[r,5]]//TraditionalForm,16]
Out[]=
r⌈r⌈r⌈r⌈r⌈r⌉⌉⌉⌉⌉
In particular, I am only interested in the case from the original problem:
In[]:=
f[r_]:=rCeiling[rCeiling[rCeiling[rCeiling[rCeiling[r]]]]]
And later you see the algorithm, this specification really does not matter the code, only the numeric result.
Analysis
Analysis
◼
The first step is to think about simplest cases when is an positive integer
r
I can simply remove all ceiling function and partition the integers with these end points. Say I choose
In[]:=
Array[f,5]
Out[]=
{1,64,729,4096,15625}
Candidates of the RHS of the equation, M, can be partition using following intervals. That is (the left side is inclusive and the right hand side is strict). Also we notice that this function is non-decreasing.
(n-1)≤M<
4
n
In[]:=
LogPlot[f[r],{r,1.,5},GridLines{None,{1,64,729,4096,15625}}]
Out[]=
We usually need to choose a proper interval to analyze the solution for a jumpy cut-off function. For Floor and Ceiling functions, it is always convenient to assume the solution is of the form , , , and so on with (left inclusive and right strict). We know returns an integer , thus the origin equation can be convert to two simultaneous inequality for . Once the range of is determined, we test finitely many ’s to see if the original equation is satisfied.
1+ϵ
2+ϵ
3+ϵ
0<=ϵ<1
⌈r⌈r⌈r⌈r⌈r⌉⌉⌉⌉⌉
K
K
K
K
For instance ,there are some integers less than 64 can have valid solution for r , other than 7.
1<=r<2
In[]:=
Plot[f[r],{r,1.,1.5},GridLines{None,Range[1,20]},Ticks{Automatic,Range[7,20]},AxesLabel{"r",f[r]},LabelStyle14]
Out[]=
Let’s say this valid integer is (number on the Y axis in the diagram above and have grid line intersecting with the curve ). The original tower is then .
Solve for ϵ we have which is between 0 (inclusive) and 1 (exclusive). Say , the range for integer is to
M
f[r]
(1+ϵ)*r⌈r⌈r⌈r⌈r⌈r⌉⌉⌉⌉⌉=(1+ϵ)*K=M
Solve for ϵ we have
ϵ=-1+M/K
M=7
K
Ceiling[M/2]=Ceiling[3.5]=4
Floor[M/1]=7
In[]:=
Reduce[0<=-1+7/k<1,{k},PositiveIntegers]
Out[]=
k4||k5||k6||k7
The denominator of the expression in the ceiling and floor functions are from the integer part of the solution . In general, the two denominators are and respectively.
r=x+ϵ
x+1
x
Convert the argument above into WL code and cache the result for convenience and quick reuse:
In[]:=
CeilingTowerSolutionP[m_]:=CeilingTowerSolutionP[m]=Module[{expr,intPart=Floor[Surd[m,6]]},expr=(f[m/Table[n,{n,Ceiling[m/(intPart+1)],Floor[m/intPart]}]]-m);If[Times@@expr==0,m/(Position[expr,0][[1,1]]+Ceiling[m/(intPart+1)]-1),False]]
Let’s exam how many no larger than 730 can be expressed as ceiling tower:
n
In[]:=
sol=Cases[CeilingTowerSolutionP/@Range[730],_?NumericQ];Short[sol]
Out[]//Short=
1,,,,,,,142,,,,,,,3
7
6
7
5
17
12
3
2
26
17
14
9
717
241
721
242
361
121
723
242
727
243
728
243
So these integers have valid solution in terms of :
n==r⌈r⌈r⌈r⌈r⌈r⌉⌉⌉⌉⌉
r
In[]:=
f@sol
Out[]=
{1,7,14,17,18,26,28,30,32,33,36,40,48,51,52,59,60,63,64,127,128,131,132,139,140,143,144,147,152,163,164,165,168,173,176,177,181,182,190,193,194,206,214,215,216,219,248,249,253,261,274,275,278,284,287,288,289,292,293,302,306,307,311,312,333,337,338,346,347,351,352,356,357,366,370,371,375,376,377,402,403,412,416,417,421,478,481,482,491,492,496,497,501,502,503,512,515,516,517,521,522,523,526,527,536,537,541,564,568,569,570,573,574,575,588,589,590,594,595,599,600,610,614,615,616,620,621,622,625,635,662,663,667,668,669,673,674,675,688,689,690,694,695,696,700,701,702,715,716,717,721,722,723,727,728,729}
Plot these values with their index:
In[]:=
Plot[f[r],{r,1,1.8},GridLines{sol,f[sol]},AxesLabel{"r",f[r]},LabelStyle14]
Out[]=
For possible negative solutions, I just use the similar argument but a different range for . Extreme caution is required to handle floor and ceiling function with negative numbers because the direction of cutoff is different in terms of their absolute value. Also you should notice it only works with even number of ’s. Otherwise the value of ceiling tower is also negative.
K
r
In[]:=
CeilingTowerSolutionN[m_]:=CeilingTowerSolutionN[m]=Module[{expr,intPart=Floor[Surd[m,6]]},expr=(f[m/Table[n,{n,Ceiling[-m/intPart],Floor[-m/(intPart+1)]}]]-m);If[Times@@expr==0,m/(Position[expr,0][[1,1]]+Ceiling[-m/intPart]-1),False]]
Use the function for negative solutions:
In[]:=
sol2=Cases[CeilingTowerSolutionN/@Range[730],_?NumericQ];Short[sol2]
Out[]//Short=
-1,-,-,-,-,-,84,-,-,-,-,-,-3
11
7
13
8
17
10
9
5
21
11
448
151
449
151
450
151
227
76
455
152
Exam the results
In[]:=
f@sol2
Mark the solution points on the diagram:
Generate Animation
Generate Animation