gpt4 book ai didi

kdb - q - 递归/

转载 作者:行者123 更新时间:2023-12-05 01:24:01 26 4
gpt4 key购买 nike

在 q 中,over 的常见插图运算符(operator) /implementation of fibonacci sequence

10 {x,sum -2#x}/ 1 1

这确实打印了前 10 个斐波那契数,但对于 over 的定义没有意义。运算符在此 whitepaper (第 8 页)

With two arguments, the second one being a list, the function is called with the left argument as its first parameter and the first element of the right argument as the second parameter. Next, the function is called with the result of the previous iteration as the first parameter and the third element as the second parameter. The process continues in this way for the remaining elements of the list.



所以在上面的斐波那契例子中,在第一次迭代时,函数将被调用 [10;1] (“第一个参数和第二个参数的第一项”)这已经给出了错误的结果。

我的实现符合定义(并且有效)
1 1 {[l;c] l,sum -2#l}/til 10

但我不喜欢它,因为参数 c从不使用。

第一个例子如何与定义相协调?

谢谢您的帮助

最佳答案

/有多种形式,描述如下:https://code.kx.com/q/ref/adverbs

这里使用的具体形式是“重复” - https://code.kx.com/q/ref/adverbs/#converge-repeat

这里的斐波那契函数是一元的,即接受一个参数 (x)

在这种形式中,/将使用提供的参数(即 1 1 的列表)运行函数,然后使用该调用的结果,然后再次使用该调用的结果,依此类推,直到迭代次数达到 10 (/的左参数)

如果函数是二元函数(即采用两个参数),则您提供的定义为真

希望这可以帮助

乔纳森

AquaQ 分析

关于kdb - q - 递归/,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46806165/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com