2

Tetration is the level above exponentiation (e.g: 2^^4 = 2^(2^(2^2)) = 65536.

So far, I've figured out an algorithm for tetration that works.

However, although the variable a can be floating or integer, unfortunately, the variable b must be an integer number.

How can I modify the pseudo-code algorithm so that both a and b can be floating point numbers and the correct answer will be produced?

// Hyperoperation type 4:
public float tetrate(float a, float b)
{
    float total = a;
    for (i = 1; i < b; i++) total = pow(a, total);
    return total;
}

In an attempt to solve this, I've created my own custom power() function (trying to avoid roots, and log functions), and then successfully generalized it to multiplication. Unfortunately, when I then try to generalize to tetration, numbers go pear shaped.

I would like an algorithm to be precise up to x amount of decimal places, and not an approximation as Wikipedia talks about. To clarify, preferably, it would need to satisfy at least the first three requirements, and the fourth requirement can be up to the answerer.

Dan W
  • 3,520
  • 7
  • 42
  • 69
  • 3
    So how exactly `2^^1.7` is calculated? – Eugene Sh. May 14 '15 at 17:15
  • With logs and exp functions of course. :) – Michael Dorgan May 14 '15 at 17:32
  • 1
    And with numbers, I guess.. – Eugene Sh. May 14 '15 at 17:33
  • 2
    @Eugene Sh. Hmm Wiki says [no commonly accepted solution to the general problem of extending tetration to the real or complex values of _n_](http://en.wikipedia.org/wiki/Tetration#Extension_to_real_heights), So OP, suggest posting on http://math.stackexchange.com to get the algorithm – chux - Reinstate Monica May 14 '15 at 17:38
  • 2
    So the algorithm can't be "precise to n decimal places", because there is no definition of what is the correct result of the operation itself for real heights. – Kolmar May 14 '15 at 17:44
  • 2
    To solidify the point that I think Eugene and Kolmar are trying to make, you need to first define the operation you want to do (or adopt some one else's definition), _then_ worry about clever algorithms for computing it efficiently. – Nicu Stiurca May 14 '15 at 21:05
  • To clarify, preferably, it would need to satisfy at least the first [three requirements](https://en.wikipedia.org/wiki/Tetration#Extension_to_real_heights), and the fourth requirement can be up to the answerer. – Dan W May 15 '15 at 08:13

1 Answers1

1

base_num ^^ tetration_num =

e^( base_num * ln (e^(tetration_num * ln base_num)))

Natural log can be calculated with a Taylor series to a whatever accuracy you need.

e^x can also be calcuated to whatever accuracy you need with a Taylor series.

With some care about over/underflow, you should be able to work with whatever values you need using the above.

Just in case you need to series, This page lists the ones you would need. Having coded something similiar to this in fixed point math (ints, no floats) I can say that it isn't all that hard to get up and running, but you need to be careful about the order in which you do things or you will overflow numbers quickly.


Update

It turns out my above only works for some tetrations as I did not fully understand how tetrations work. Silly rabbit.

Michael Dorgan
  • 12,453
  • 3
  • 31
  • 61
  • 1
    Tetration `a^^x` is not `(a^x)^a` as your answer seems to imply. It's `a^(...^(a^(a^a)))` with `a` repeated `x` times. – Kolmar May 14 '15 at 17:53
  • Then, by all means, I can change my answer, but the concept I show is still valid - e^x - ln x can be used to handle variable precision. – Michael Dorgan May 14 '15 at 18:48
  • That's if you have well defined exponentiations. But you can't express tetration with a real height as a combination of exponentiations. (That definition a^(...^(a^(a^a))) is for natural heights) – Kolmar May 14 '15 at 18:53
  • Ahh. I see now. Interesting. Then my above answer won't work then. I will update my answer as thus. – Michael Dorgan May 14 '15 at 20:52