simple-squiggle

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

unequal.js (5395B)


      1 import { factory } from '../../utils/factory.js';
      2 import { createAlgorithm03 } from '../../type/matrix/utils/algorithm03.js';
      3 import { createAlgorithm07 } from '../../type/matrix/utils/algorithm07.js';
      4 import { createAlgorithm12 } from '../../type/matrix/utils/algorithm12.js';
      5 import { createAlgorithm14 } from '../../type/matrix/utils/algorithm14.js';
      6 import { createAlgorithm13 } from '../../type/matrix/utils/algorithm13.js';
      7 var name = 'unequal';
      8 var dependencies = ['typed', 'config', 'equalScalar', 'matrix', 'DenseMatrix'];
      9 export var createUnequal = /* #__PURE__ */factory(name, dependencies, _ref => {
     10   var {
     11     typed,
     12     config,
     13     equalScalar,
     14     matrix,
     15     DenseMatrix
     16   } = _ref;
     17   var algorithm03 = createAlgorithm03({
     18     typed
     19   });
     20   var algorithm07 = createAlgorithm07({
     21     typed,
     22     DenseMatrix
     23   });
     24   var algorithm12 = createAlgorithm12({
     25     typed,
     26     DenseMatrix
     27   });
     28   var algorithm13 = createAlgorithm13({
     29     typed
     30   });
     31   var algorithm14 = createAlgorithm14({
     32     typed
     33   });
     34   /**
     35    * Test whether two values are unequal.
     36    *
     37    * The function tests whether the relative difference between x and y is
     38    * larger than the configured epsilon. The function cannot be used to compare
     39    * values smaller than approximately 2.22e-16.
     40    *
     41    * For matrices, the function is evaluated element wise.
     42    * In case of complex numbers, x.re must unequal y.re, or x.im must unequal y.im.
     43    * Strings are compared by their numerical value.
     44    *
     45    * Values `null` and `undefined` are compared strictly, thus `null` is unequal
     46    * with everything except `null`, and `undefined` is unequal with everything
     47    * except `undefined`.
     48    *
     49    * Syntax:
     50    *
     51    *    math.unequal(x, y)
     52    *
     53    * Examples:
     54    *
     55    *    math.unequal(2 + 2, 3)       // returns true
     56    *    math.unequal(2 + 2, 4)       // returns false
     57    *
     58    *    const a = math.unit('50 cm')
     59    *    const b = math.unit('5 m')
     60    *    math.unequal(a, b)           // returns false
     61    *
     62    *    const c = [2, 5, 1]
     63    *    const d = [2, 7, 1]
     64    *
     65    *    math.unequal(c, d)           // returns [false, true, false]
     66    *    math.deepEqual(c, d)         // returns false
     67    *
     68    *    math.unequal(0, null)        // returns true
     69    * See also:
     70    *
     71    *    equal, deepEqual, smaller, smallerEq, larger, largerEq, compare
     72    *
     73    * @param  {number | BigNumber | Fraction | boolean | Complex | Unit | string | Array | Matrix | undefined} x First value to compare
     74    * @param  {number | BigNumber | Fraction | boolean | Complex | Unit | string | Array | Matrix | undefined} y Second value to compare
     75    * @return {boolean | Array | Matrix} Returns true when the compared values are unequal, else returns false
     76    */
     77 
     78   return typed('unequal', {
     79     'any, any': function anyAny(x, y) {
     80       // strict equality for null and undefined?
     81       if (x === null) {
     82         return y !== null;
     83       }
     84 
     85       if (y === null) {
     86         return x !== null;
     87       }
     88 
     89       if (x === undefined) {
     90         return y !== undefined;
     91       }
     92 
     93       if (y === undefined) {
     94         return x !== undefined;
     95       }
     96 
     97       return _unequal(x, y);
     98     },
     99     'SparseMatrix, SparseMatrix': function SparseMatrixSparseMatrix(x, y) {
    100       return algorithm07(x, y, _unequal);
    101     },
    102     'SparseMatrix, DenseMatrix': function SparseMatrixDenseMatrix(x, y) {
    103       return algorithm03(y, x, _unequal, true);
    104     },
    105     'DenseMatrix, SparseMatrix': function DenseMatrixSparseMatrix(x, y) {
    106       return algorithm03(x, y, _unequal, false);
    107     },
    108     'DenseMatrix, DenseMatrix': function DenseMatrixDenseMatrix(x, y) {
    109       return algorithm13(x, y, _unequal);
    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, _unequal, false);
    125     },
    126     'DenseMatrix, any': function DenseMatrixAny(x, y) {
    127       return algorithm14(x, y, _unequal, false);
    128     },
    129     'any, SparseMatrix': function anySparseMatrix(x, y) {
    130       return algorithm12(y, x, _unequal, true);
    131     },
    132     'any, DenseMatrix': function anyDenseMatrix(x, y) {
    133       return algorithm14(y, x, _unequal, true);
    134     },
    135     'Array, any': function ArrayAny(x, y) {
    136       // use matrix implementation
    137       return algorithm14(matrix(x), y, _unequal, false).valueOf();
    138     },
    139     'any, Array': function anyArray(x, y) {
    140       // use matrix implementation
    141       return algorithm14(matrix(y), x, _unequal, true).valueOf();
    142     }
    143   });
    144 
    145   function _unequal(x, y) {
    146     return !equalScalar(x, y);
    147   }
    148 });
    149 export var createUnequalNumber = factory(name, ['typed', 'equalScalar'], _ref2 => {
    150   var {
    151     typed,
    152     equalScalar
    153   } = _ref2;
    154   return typed(name, {
    155     'any, any': function anyAny(x, y) {
    156       // strict equality for null and undefined?
    157       if (x === null) {
    158         return y !== null;
    159       }
    160 
    161       if (y === null) {
    162         return x !== null;
    163       }
    164 
    165       if (x === undefined) {
    166         return y !== undefined;
    167       }
    168 
    169       if (y === undefined) {
    170         return x !== undefined;
    171       }
    172 
    173       return !equalScalar(x, y);
    174     }
    175   });
    176 });