This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 29356 - Add fn:product
Summary: Add fn:product
Status: NEW
Alias: None
Product: XPath / XQuery / XSLT
Classification: Unclassified
Component: Requirements for Future Versions (show other bugs)
Version: Working drafts
Hardware: PC Linux
: P2 normal
Target Milestone: ---
Assignee: Jim Melton
QA Contact: Mailing list for public feedback on specs from XSL and XML Query WGs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-01-03 21:30 UTC by Benito van der Zander
Modified: 2016-01-03 23:35 UTC (History)
1 user (show)

See Also:


Attachments

Description Benito van der Zander 2016-01-03 21:30:29 UTC
There is a fn:sum, but no fn:product

That does not seem intuitive. Both are the basic commutative arithmetic operations, there should either be both or neither.

It is also very useful to calculate the factorial: product(1 to $something)

From that you can define the binomial (which could also be useful in the math: module):

declare function binomial($n, $k) { product(($k + 1) to $n) div product(1 to (n - k)) } 

and work with combinatorics and stuff
Comment 1 Michael Kay 2016-01-03 23:24:59 UTC
It's very easy to define it yourself:

let $product := 
  fold-left(?, 1, function($x, $y){$x * $y})
Comment 2 Benito van der Zander 2016-01-03 23:35:46 UTC
But so is fn:sum and that is there

And utility functions seem to have become popular again, like fn:contains-token