Function Repository Resource:

PowerTowerMod

Source Notebook

Give the remainder on division of a power tower expression

Contributed by: Carl Woll, Ilan Vardi

ResourceFunction["PowerTowerMod"][expr, n]

gives Mod[expr,n] without evaluating the power tower expression expr.

Details and Options

ResourceFunction["PowerTowerMod"] has the HoldFirst attribute.
The modulus must be a positive integer.
ResourceFunction["PowerTowerMod"] returns unevaluated if the expression is not a power tower or nested power tower.

Examples

Basic Examples (2) 

Find the last 20 digits of a power tower:

In[1]:=
ResourceFunction["PowerTowerMod"][2^2^2^2^2, 10^20]
Out[1]=

Check:

In[2]:=
Mod[2^2^2^2^2, 10^20]
Out[2]=

Scope (2) 

Nested power towers:

In[3]:=
ResourceFunction["PowerTowerMod"][2^2^(3^2^3)^3^(2^3)^3, 10^10]
Out[3]=

PoweTowerMod does not evaluate the power tower expression, and so can work with expressions that are much larger than the maximum number:

In[4]:=
Mod[2^2^2^2^2^2, 10^10]
Out[4]=
In[5]:=
ResourceFunction["PowerTowerMod"][2^2^2^2^2^2, 10^10]
Out[5]=

Properties and Relations (2) 

For expressions small enough for Mod, PowerTowerMod returns the same result:

In[6]:=
Mod[2^2^2^2, 137]
Out[6]=

Using PowerTowerMod:

In[7]:=
ResourceFunction["PowerTowerMod"][2^2^2^2, 137]
Out[7]=

Publisher

Carl Woll

Version History

  • 1.0.0 – 18 October 2019

Related Resources

Author Notes

The algorithm used is due to Ilan Vardi.
This is a modification of the version used by WolframAlpha.

License Information