simple-squiggle

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

composition.js (1750B)


      1 "use strict";
      2 
      3 Object.defineProperty(exports, "__esModule", {
      4   value: true
      5 });
      6 exports.createComposition = void 0;
      7 
      8 var _factory = require("../../utils/factory.js");
      9 
     10 var name = 'composition';
     11 var dependencies = ['typed', 'addScalar', 'combinations', 'isNegative', 'isPositive', 'isInteger', 'larger'];
     12 var createComposition = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) {
     13   var typed = _ref.typed,
     14       addScalar = _ref.addScalar,
     15       combinations = _ref.combinations,
     16       isPositive = _ref.isPositive,
     17       isNegative = _ref.isNegative,
     18       isInteger = _ref.isInteger,
     19       larger = _ref.larger;
     20 
     21   /**
     22    * The composition counts of n into k parts.
     23    *
     24    * composition only takes integer arguments.
     25    * The following condition must be enforced: k <= n.
     26    *
     27    * Syntax:
     28    *
     29    *   math.composition(n, k)
     30    *
     31    * Examples:
     32    *
     33    *    math.composition(5, 3) // returns 6
     34    *
     35    * See also:
     36    *
     37    *    combinations
     38    *
     39    * @param {Number | BigNumber} n    Total number of objects in the set
     40    * @param {Number | BigNumber} k    Number of objects in the subset
     41    * @return {Number | BigNumber}     Returns the composition counts of n into k parts.
     42    */
     43   return typed(name, {
     44     'number | BigNumber, number | BigNumber': function numberBigNumberNumberBigNumber(n, k) {
     45       if (!isInteger(n) || !isPositive(n) || !isInteger(k) || !isPositive(k)) {
     46         throw new TypeError('Positive integer value expected in function composition');
     47       } else if (larger(k, n)) {
     48         throw new TypeError('k must be less than or equal to n in function composition');
     49       }
     50 
     51       return combinations(addScalar(n, -1), addScalar(k, -1));
     52     }
     53   });
     54 });
     55 exports.createComposition = createComposition;