admin管理员组

文章数量:1312844

The tetration is an operation defined as an iterated exponentiation (e.g 2^^4 = 2^(2^(2^2)) = 65536)

I'm learning the J programming language and want to experiment with the ^: (power of verb) function . Specifically, I want to use it to tacitly compute the tetration of two numbers. I want to do this tacitly in order to better understand modifier trains in J.

So far, I've only been able to write this code: ^/@# . It creates a list of x copies of y and inserts ^ between the items, effectively producing y^^x. However, I don't want that solution, because it doesn't let x be infinite, and it also doesn't use the ^: function. I haven't been able to make any further progress. Can anyone help me?

The tetration is an operation defined as an iterated exponentiation (e.g 2^^4 = 2^(2^(2^2)) = 65536)

I'm learning the J programming language and want to experiment with the ^: (power of verb) function . Specifically, I want to use it to tacitly compute the tetration of two numbers. I want to do this tacitly in order to better understand modifier trains in J.

So far, I've only been able to write this code: ^/@# . It creates a list of x copies of y and inserts ^ between the items, effectively producing y^^x. However, I don't want that solution, because it doesn't let x be infinite, and it also doesn't use the ^: function. I haven't been able to make any further progress. Can anyone help me?

Share Improve this question asked Feb 1 at 3:27 Lol ilolLol ilol 531 silver badge4 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

First of all, in my opinion, your solution is the idiomatic way to go for this. It is the natural way to express a right fold.

Then, there is the new-ish Fold (F:) which you could use like 1 ] F:: (2&^) 4 == init ] F:: operator times.

To use only the Power of verb (and assuming you mean general iterated exponential, not just the hyper-4) you simply repeat your operator n times:

(2&^)>:4 ] 1
65536
NB. or simply
2 ^^:4 ] 1 

The problem here is that you "waste" your input y to the standard initial value of 1. This makes a tacit formulation a bit cumbersome. However, because the initial value and the operator use the same constant, we can compress the expression to:

(^^:3 ])~ 2 

To make repetition-count tacit, you need to make it dynamic, so you need all your inputs (base and count) into x or y and verbs that will feed them appropriately to ^:. For example you could:

(u^:h)~ 2 4

where u and h providing (y u y == 2&^) and (y h y == 4) with whatever tacit forms you prefer:

u =: (0{[) ^ (0{])
h =: <:@(1 {  ])
(u^:h)~ 2 4
65536
(u^:h)~ 1.5 3
2.1062

本文标签: How to write a tacit tetration verb in JStack Overflow