UNPKG

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