simple-squiggle

A restricted subset of Squiggle
Log | Files | Refs | README

catalan.js (1216B)


      1 import { factory } from '../../utils/factory.js';
      2 var name = 'catalan';
      3 var dependencies = ['typed', 'addScalar', 'divideScalar', 'multiplyScalar', 'combinations', 'isNegative', 'isInteger'];
      4 export 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 });