[Jprogramming] Crash calculating large hyper operations
Dan Bron
j at bron.us
Thu Nov 19 20:51:44 UTC 2015
The notion of “hyper operation” extends the intuition that multiplication is repeated addition, exponentiation is repeated multiplication, tetration is repeated exponentiation, and so on.
Hyperoperation can be defined piecewise (per Wikipedia) as:
/ b+1 if n = 0
| a if n = 1, b = 0
H_n(a,b) = | 0 if n = 2, b = 0
| 1 if n >= 3, b = 0
\ H_n-1( a, H_n(a, b-1) ) otherwise
Or, in J:
H =: adverb define
:
if. 0=m do.
1+y
elseif. (m > 0) *. (0=y) do.
(<:3<.m) { x,0,1
elseif. do.
x (<:m) H x m H <:y
end.
)
Now, while J likes 2 (0 H) 3, 2 (1 H) 3, 2 (2 H) 3, and 2 (3 H) 3 just fine, producing the expected results [1], it silently crashes (i.e. the IDE simply disappears) on 2 (4 H) 3 .
Now, I’m sure 2 tetration 3 is some absurdly large number and I wouldn’t expect a result, but I’d prefer a stack error (or whatever) to a crash.
-Dan
[1] Representing successor, addition, multiplication, and exponentiation respectively.
More information about the Programming
mailing list