Tak (function)
In computer science, the Tak function is a recursive function, named after . It is defined as follows: \tau (x,y,z) = \begin{cases} \tau (\tau (x-1,y,z) ,\tau (y-1,z,x) ,\tau (z-1,x,y) ) & \text{if } y def tak(x: int, y: int, z: int) -> int: if y This function is often used as a benchmark for languages with optimization for recursion.
In computer science, the Tak function is a recursive function, named after . It is defined as follows: \tau (x,y,z) = \begin{cases} \tau (\tau (x-1,y,z) ,\tau (y-1,z,x) ,\tau (z-1,x,y) ) & \text{if } y def tak(x: int, y: int, z: int) -> int: if y This function is often used as a benchmark for languages with optimization for recursion. ==tak() vs. tarai()== The original definition by Takeuchi was as follows: def tarai(x: int, y: int, z: int) -> int: if y tarai is short for in Japanese. John McCarthy named this function tak() after Takeuchi. However, in certain later references, the y somehow got turned into the z. This is a small, but significant difference because the original version benefits significantly from lazy evaluation. Though written in exactly the same manner as others, the Haskell code below runs much faster. tarai :: Int -> Int -> Int -> Int tarai x y z | x One can easily accelerate this function via memoization yet lazy evaluation still wins. The best known way to optimize tarai is to use a mutually recursive helper function as follows. def laziest_tarai(x: int, y: int, zx: int, zy: int, zz: int) -> int: if not y int: if not y Here is an efficient implementation of tarai() in C: int tarai(int x, int y, int z) { while (x > y) { int oldx = x, oldy = y; x = tarai(x - 1, y, z); y = tarai(y - 1, z, oldx); if (x Note the additional check for ( x ) before z (the third argument) is evaluated, avoiding unnecessary recursive evaluation. ==References== ==External links== TAK Function
References
- ^ Peter Coffee (1996). "Tak test stands the test of time". PC Week . 13 (39). Wikipedia revision 1301932557, retrieved 2026-11-18 · 1794956400.0
- ^ "Recursive Methods" by Elliotte Rusty Harold Wikipedia revision 1301932557, retrieved 2026-11-18 · 1794956400.0
- ^ John McCarthy (December 1979). "An Interesting LISP Function". ACM Lisp Bulletin (3): 6– 8. doi : 10.1145/1411829.1411833 . S2CID 31639459 . Wikipedia revision 1301932557, retrieved 2026-11-18 · 1794956400.0
- ^ Johnson-Davies, David (June 1986). "Six of the Best Against the Clock" . Acorn User . pp. 179, 181– 182 . Retrieved 28 October 2020 . Wikipedia revision 1301932557, retrieved 2026-11-18 · 1794956400.0
- ^ Johnson-Davies, David (November 1986). "Testing the Tak" . Acorn User . pp. 197, 199 . Retrieved 28 October 2020 . Wikipedia revision 1301932557, retrieved 2026-11-18 · 1794956400.0
Cite this
"Tak (function)". 1753181901. e01 Encyclopedia. CC BY-SA 4.0. https://en.wikipedia.org/w/index.php?oldid=1301932557