[英]what is a good tacit form of sum(1/(1+x)^y) in J
作为一个初学练习,我试着用J计算下面的和, sum(1/(1+0.03)^n for n = 1 to 30
使用+/%(1 + 0.03)^ >:i.30
。我怎么能把它写成一个简单的默认形式?我尝试过的所有内容都比上面的显式形式更加丑陋>:@[ (+/&:%)@:^ >:&i.@]
You could start with 你可以先开始吧
+/@:%@((1 + 0.03) ^ >:@i.) 30
You can make the 0.03 a left argument using a fork, but using a hook can be cleaner 您可以使用fork使0.03成为左参数,但使用钩子可以更清晰
(1 + 0.03) +/@:%@([ ^ >:@i.@]) 30 NB. use fork
(1 + 0.03) +/@:%@(^ >:@i.) 30 NB. use hook
The same operation (increment) is being performed on both the left and right arguments to ^
. 对
^
左右参数执行相同的操作(增量)。 That is a hint that &
( Compose ) may be useful. 这是
&
( 撰写 )可能有用的暗示。
0.03 +/@:%@(^&>: i.) 30 NB. apply increment to both left & right arg
When I want a tacit function I often let 13 :
bang it out for me. 当我想要一个隐性功能时,我常常让
13 :
为我敲打它。 In this case, some variations: 在这种情况下,一些变化:
13 : '+/ %((1+0.03)^1+i.y)'
[: +/ [: % 1.03 ^ 1 + i.
13 : '+/ %((1+0.03)^>:i.y)'
[: +/ [: % 1.03 ^ [: >: i.
And with 1+0.03
or whatever as a leftargument: 使用
1+0.03
或其他任何左参数:
13 : '+/ %(x^1+i.y)'
[: +/ [: % [ ^ 1 + [: i. ]
13 : '+/ %(x^>:i.y)'
[: +/ [: % [ ^ [: >: [: i. ]
There are way too many caps ( [:
) to call it less ugly, though, but that's a start. 有太多的上限(
[:
]称它不那么丑陋,但这是一个开始。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.