prd, prds¶
Products
prd¶
Product
prd x prd[x]
Where x is a numeric list, returns its product.
The product of an atom is itself.
prd treats nulls as 1s. For a nested list, prd preserves nulls.
q)prd 7 / product of atom (returned unchanged)
7
q)prd 2 3 5 7 / product of list
210
q)prd 2 3 0N 7 / 0N is treated as 1
42
q)prd (1 2 3 4;2 3 5 7) / product of list of lists
2 6 15 28
q)prd (1 2;0N 4) / nested: nulls are preserved
0N 8
q)prd 101b
0i
q)prd "abc"
'type
[0] prd "abc"
^
prd is an aggregate function, equivalent to */.
prds¶
Running products
prds x prds[x]
Where x is a numeric list, returns the cumulative products of its items. prds treats nulls as 1s.
q)prds 7 / atom is returned unchanged
7
q)prds 2 3 5 7 / cumulative products of list
2 6 30 210
q)prds 2 3 0N 7 / 0N is treated as 1
2 6 6 42
q)/ cumulative products of list of lists: same as (1 2 3;1 2 3 * 2 3 5)
q)prds (1 2 3;2 3 5)
1 2 3
2 6 15
q)prds "abc" / type error if list is not numeric
'type
[0] prds "abc" / type error if list is not numeric
^
prds is a uniform function, equivalent to *\.
Implicit iteration¶
prd and prds apply to dictionaries and tables.
q)kt:`k xkey update k:`abc`def`ghi from t:flip d:`a`b!(10 21 3;4 5 6)
q)d
a| 10 21 3
b| 4 5 6
q)t
a b
----
10 4
21 5
3 6
q)kt
k | a b
---| ----
abc| 10 4
def| 21 5
ghi| 3 6
q)prd d
40 105 18
q)prds d
a| 10 21 3
b| 40 105 18
q)prd t
a| 630
b| 120
q)prds t
a b
-------
10 4
210 20
630 120
q)prd kt
a| 630
b| 120
q)prds kt
k | a b
---| -------
abc| 10 4
def| 210 20
ghi| 630 120
Domain and range¶
prd
domain: B G X H I J E F C S P M D Z N U V T
range: i . i i i j e f . . . . . . . . . .
prds
domain: B G X H I J E F C S P M D Z N U V T
range: I . I I I J E F . . . . . . . . . .