Concatenative topics
Concatenative meta
Other languages
Meta
The Tak function, was invented by Ikuo Takeuchi of the Electrical Communication Laboratory of Nippon Telephone and Telegraph Co., for the purpose of comparing the speeds of LISP systems.
This is one of those nonsensical algorithms that can be used to profile efficiency of a system or language. It was used as a means of testing stack instructions, data moving, and arithmetic.
def tak(x, y, z): if y < x: return tak( tak(x-1, y, z), tak(y-1, z, x), tak(z-1, x, y) ) else: return z
@on-reset ( -> ) #08 #04 #07 tak #010e DEO BRK @tak ( z y x -- res ) LTHk ?{ POP2 JMP2r } ROT ROTk ROTk #01 SUB tak STH #01 SUB tak STH #01 SUB tak STHr STHr !tak
USING: combinators.extras kernel math ; IN: scratchpad : tak ( z y x -- res ) 2dup >= [ 2drop ] [ rot 3dup rot 3dup rot [ 1 - tak ] 3tri@ tak ] if ; 8 4 7 tak .
: 3dup dup 2over rot ; : tak ( z y x -- n ) 2dup >= if 2drop exit then 3dup 1- recurse >r 3dup -rot 1- recurse >r rot 1- recurse r> r> recurse ; 7 4 8 tak . cr bye
module(main) import(prelude) import(platform.posix) def(tak, Int Int Int -- Int, dup2 < if( dup3 1- tak dip(dup3 rotr 1- tak) dip2(rotl 1- tak) tak, drop2 ) ) 7 4 8 tak print-ln!
using std.manip using std.smanip using std.quote using std.cond using std.out ⋮ Z Y X -> S tak == [ 3 ⊑ >s [ :s ∘ ⍉ 1 - tak :s ∘ ⟷ 1 - ⍉ ⟷ tak <s ∘ 1 - tak tak ] [<s ∘ /2] :s ∘ ⍉ / < ? ] 8 4 7 tak .nl
include "cores/select.cal" include "std/io.cal" func tak cell x cell y cell z begin if y x < then x 1 - y z tak y 1 - z x tak z 1 - x y tak tak return else z return end end 7 4 8 tak printdec 10 printch
This revision created on Tue, 17 Sep 2024 22:41:00 by soxfox42 (Update Callisto with latest syntax changes (copied from Callisto page))