simple-squiggle

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

smallerEq.js (5320B)


      1 "use strict";
      2 
      3 Object.defineProperty(exports, "__esModule", {
      4   value: true
      5 });
      6 exports.createSmallerEqNumber = exports.createSmallerEq = void 0;
      7 
      8 var _nearlyEqual = require("../../utils/bignumber/nearlyEqual.js");
      9 
     10 var _number = require("../../utils/number.js");
     11 
     12 var _factory = require("../../utils/factory.js");
     13 
     14 var _algorithm = require("../../type/matrix/utils/algorithm03.js");
     15 
     16 var _algorithm2 = require("../../type/matrix/utils/algorithm07.js");
     17 
     18 var _algorithm3 = require("../../type/matrix/utils/algorithm12.js");
     19 
     20 var _algorithm4 = require("../../type/matrix/utils/algorithm14.js");
     21 
     22 var _algorithm5 = require("../../type/matrix/utils/algorithm13.js");
     23 
     24 var name = 'smallerEq';
     25 var dependencies = ['typed', 'config', 'matrix', 'DenseMatrix'];
     26 var createSmallerEq = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) {
     27   var typed = _ref.typed,
     28       config = _ref.config,
     29       matrix = _ref.matrix,
     30       DenseMatrix = _ref.DenseMatrix;
     31   var algorithm03 = (0, _algorithm.createAlgorithm03)({
     32     typed: typed
     33   });
     34   var algorithm07 = (0, _algorithm2.createAlgorithm07)({
     35     typed: typed,
     36     DenseMatrix: DenseMatrix
     37   });
     38   var algorithm12 = (0, _algorithm3.createAlgorithm12)({
     39     typed: typed,
     40     DenseMatrix: DenseMatrix
     41   });
     42   var algorithm13 = (0, _algorithm5.createAlgorithm13)({
     43     typed: typed
     44   });
     45   var algorithm14 = (0, _algorithm4.createAlgorithm14)({
     46     typed: typed
     47   });
     48   /**
     49    * Test whether value x is smaller or equal to y.
     50    *
     51    * The function returns true when x is smaller than y or the relative
     52    * difference between x and y is smaller than the configured epsilon. The
     53    * function cannot be used to compare values smaller than approximately 2.22e-16.
     54    *
     55    * For matrices, the function is evaluated element wise.
     56    * Strings are compared by their numerical value.
     57    *
     58    * Syntax:
     59    *
     60    *    math.smallerEq(x, y)
     61    *
     62    * Examples:
     63    *
     64    *    math.smaller(1 + 2, 3)        // returns false
     65    *    math.smallerEq(1 + 2, 3)      // returns true
     66    *
     67    * See also:
     68    *
     69    *    equal, unequal, smaller, larger, largerEq, compare
     70    *
     71    * @param  {number | BigNumber | Fraction | boolean | Unit | string | Array | Matrix} x First value to compare
     72    * @param  {number | BigNumber | Fraction | boolean | Unit | string | Array | Matrix} y Second value to compare
     73    * @return {boolean | Array | Matrix} Returns true when the x is smaller than y, else returns false
     74    */
     75 
     76   return typed(name, {
     77     'boolean, boolean': function booleanBoolean(x, y) {
     78       return x <= y;
     79     },
     80     'number, number': function numberNumber(x, y) {
     81       return x <= y || (0, _number.nearlyEqual)(x, y, config.epsilon);
     82     },
     83     'BigNumber, BigNumber': function BigNumberBigNumber(x, y) {
     84       return x.lte(y) || (0, _nearlyEqual.nearlyEqual)(x, y, config.epsilon);
     85     },
     86     'Fraction, Fraction': function FractionFraction(x, y) {
     87       return x.compare(y) !== 1;
     88     },
     89     'Complex, Complex': function ComplexComplex() {
     90       throw new TypeError('No ordering relation is defined for complex numbers');
     91     },
     92     'Unit, Unit': function UnitUnit(x, y) {
     93       if (!x.equalBase(y)) {
     94         throw new Error('Cannot compare units with different base');
     95       }
     96 
     97       return this(x.value, y.value);
     98     },
     99     'SparseMatrix, SparseMatrix': function SparseMatrixSparseMatrix(x, y) {
    100       return algorithm07(x, y, this);
    101     },
    102     'SparseMatrix, DenseMatrix': function SparseMatrixDenseMatrix(x, y) {
    103       return algorithm03(y, x, this, true);
    104     },
    105     'DenseMatrix, SparseMatrix': function DenseMatrixSparseMatrix(x, y) {
    106       return algorithm03(x, y, this, false);
    107     },
    108     'DenseMatrix, DenseMatrix': function DenseMatrixDenseMatrix(x, y) {
    109       return algorithm13(x, y, this);
    110     },
    111     'Array, Array': function ArrayArray(x, y) {
    112       // use matrix implementation
    113       return this(matrix(x), matrix(y)).valueOf();
    114     },
    115     'Array, Matrix': function ArrayMatrix(x, y) {
    116       // use matrix implementation
    117       return this(matrix(x), y);
    118     },
    119     'Matrix, Array': function MatrixArray(x, y) {
    120       // use matrix implementation
    121       return this(x, matrix(y));
    122     },
    123     'SparseMatrix, any': function SparseMatrixAny(x, y) {
    124       return algorithm12(x, y, this, false);
    125     },
    126     'DenseMatrix, any': function DenseMatrixAny(x, y) {
    127       return algorithm14(x, y, this, false);
    128     },
    129     'any, SparseMatrix': function anySparseMatrix(x, y) {
    130       return algorithm12(y, x, this, true);
    131     },
    132     'any, DenseMatrix': function anyDenseMatrix(x, y) {
    133       return algorithm14(y, x, this, true);
    134     },
    135     'Array, any': function ArrayAny(x, y) {
    136       // use matrix implementation
    137       return algorithm14(matrix(x), y, this, false).valueOf();
    138     },
    139     'any, Array': function anyArray(x, y) {
    140       // use matrix implementation
    141       return algorithm14(matrix(y), x, this, true).valueOf();
    142     }
    143   });
    144 });
    145 exports.createSmallerEq = createSmallerEq;
    146 var createSmallerEqNumber = /* #__PURE__ */(0, _factory.factory)(name, ['typed', 'config'], function (_ref2) {
    147   var typed = _ref2.typed,
    148       config = _ref2.config;
    149   return typed(name, {
    150     'number, number': function numberNumber(x, y) {
    151       return x <= y || (0, _number.nearlyEqual)(x, y, config.epsilon);
    152     }
    153   });
    154 });
    155 exports.createSmallerEqNumber = createSmallerEqNumber;