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 badges1 Answer
Reset to default 1First 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
版权声明:本文标题:How to write a tacit tetration verb in J? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741888514a2403167.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论