UNPKG

1.22 kBJavaScriptView Raw
1import { factory } from '../../utils/factory.js';
2var name = 'catalan';
3var dependencies = ['typed', 'addScalar', 'divideScalar', 'multiplyScalar', 'combinations', 'isNegative', 'isInteger'];
4export var createCatalan = /* #__PURE__ */factory(name, dependencies, _ref => {
5 var {
6 typed,
7 addScalar,
8 divideScalar,
9 multiplyScalar,
10 combinations,
11 isNegative,
12 isInteger
13 } = _ref;
14
15 /**
16 * The Catalan Numbers enumerate combinatorial structures of many different types.
17 * catalan only takes integer arguments.
18 * The following condition must be enforced: n >= 0
19 *
20 * Syntax:
21 *
22 * math.catalan(n)
23 *
24 * Examples:
25 *
26 * math.catalan(3) // returns 5
27 * math.catalan(8) // returns 1430
28 *
29 * See also:
30 *
31 * bellNumbers
32 *
33 * @param {Number | BigNumber} n nth Catalan number
34 * @return {Number | BigNumber} Cn(n)
35 */
36 return typed(name, {
37 'number | BigNumber': function numberBigNumber(n) {
38 if (!isInteger(n) || isNegative(n)) {
39 throw new TypeError('Non-negative integer value expected in function catalan');
40 }
41
42 return divideScalar(combinations(multiplyScalar(n, 2), n), addScalar(n, 1));
43 }
44 });
45});
\No newline at end of file