Efficient algorithm for calculating the tetration of two numbers mod n?

1.2k Views Asked by At

I'm trying to study the algebraic properties of the magma created by defining the binary operation $x*y$ to be:

$ x*y = (x \uparrow y) \bmod n $

where $ \uparrow $ is the symbol for tetration.

Doing so, the hardest commutation necessary for this kind of magma of order n is: $ (n-1) \uparrow (n-1) \bmod n $.

Using the standard algorithms for tetration and the modulus, this computation was instantaneous up to the magma of order 4. For the magma of order 5 however, with the computation $ 4 \uparrow 4 \bmod 5 $, I could not compute it after 2+ hours. Is this computation even tractable for a core i7 laptop? (I'm using a library that allows for arbitrarily large integers) Is there a better way to do this computation than with a standard (brute force) calculation?

1

There are 1 best solutions below

1
On

Yes, simply iteratively reduce the exponents mod $n$ from right to left. e.x. $4^{4^{4^4}} (mod \; 5) = 4^{4^{256}} \; (mod \; 5) = 4^{4^1} \; (mod \; 5) = 256 \; (mod \; 5) = 1 \; (mod \; 5) $. This should be workably efficient for small numbers.