simple-squiggle

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

xor.js (4207B)


      1 "use strict";
      2 
      3 Object.defineProperty(exports, "__esModule", {
      4   value: true
      5 });
      6 exports.createXor = void 0;
      7 
      8 var _algorithm = require("../../type/matrix/utils/algorithm03.js");
      9 
     10 var _algorithm2 = require("../../type/matrix/utils/algorithm07.js");
     11 
     12 var _algorithm3 = require("../../type/matrix/utils/algorithm12.js");
     13 
     14 var _algorithm4 = require("../../type/matrix/utils/algorithm13.js");
     15 
     16 var _algorithm5 = require("../../type/matrix/utils/algorithm14.js");
     17 
     18 var _factory = require("../../utils/factory.js");
     19 
     20 var _index = require("../../plain/number/index.js");
     21 
     22 var name = 'xor';
     23 var dependencies = ['typed', 'matrix', 'DenseMatrix'];
     24 var createXor = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) {
     25   var typed = _ref.typed,
     26       matrix = _ref.matrix,
     27       DenseMatrix = _ref.DenseMatrix;
     28   var algorithm03 = (0, _algorithm.createAlgorithm03)({
     29     typed: typed
     30   });
     31   var algorithm07 = (0, _algorithm2.createAlgorithm07)({
     32     typed: typed,
     33     DenseMatrix: DenseMatrix
     34   });
     35   var algorithm12 = (0, _algorithm3.createAlgorithm12)({
     36     typed: typed,
     37     DenseMatrix: DenseMatrix
     38   });
     39   var algorithm13 = (0, _algorithm4.createAlgorithm13)({
     40     typed: typed
     41   });
     42   var algorithm14 = (0, _algorithm5.createAlgorithm14)({
     43     typed: typed
     44   });
     45   /**
     46    * Logical `xor`. Test whether one and only one value is defined with a nonzero/nonempty value.
     47    * For matrices, the function is evaluated element wise.
     48    *
     49    * Syntax:
     50    *
     51    *    math.xor(x, y)
     52    *
     53    * Examples:
     54    *
     55    *    math.xor(2, 4)   // returns false
     56    *
     57    *    a = [2, 0, 0]
     58    *    b = [2, 7, 0]
     59    *    c = 0
     60    *
     61    *    math.xor(a, b)   // returns [false, true, false]
     62    *    math.xor(a, c)   // returns [true, false, false]
     63    *
     64    * See also:
     65    *
     66    *    and, not, or
     67    *
     68    * @param  {number | BigNumber | Complex | Unit | Array | Matrix} x First value to check
     69    * @param  {number | BigNumber | Complex | Unit | Array | Matrix} y Second value to check
     70    * @return {boolean | Array | Matrix}
     71    *            Returns true when one and only one input is defined with a nonzero/nonempty value.
     72    */
     73 
     74   return typed(name, {
     75     'number, number': _index.xorNumber,
     76     'Complex, Complex': function ComplexComplex(x, y) {
     77       return (x.re !== 0 || x.im !== 0) !== (y.re !== 0 || y.im !== 0);
     78     },
     79     'BigNumber, BigNumber': function BigNumberBigNumber(x, y) {
     80       return (!x.isZero() && !x.isNaN()) !== (!y.isZero() && !y.isNaN());
     81     },
     82     'Unit, Unit': function UnitUnit(x, y) {
     83       return this(x.value || 0, y.value || 0);
     84     },
     85     'SparseMatrix, SparseMatrix': function SparseMatrixSparseMatrix(x, y) {
     86       return algorithm07(x, y, this);
     87     },
     88     'SparseMatrix, DenseMatrix': function SparseMatrixDenseMatrix(x, y) {
     89       return algorithm03(y, x, this, true);
     90     },
     91     'DenseMatrix, SparseMatrix': function DenseMatrixSparseMatrix(x, y) {
     92       return algorithm03(x, y, this, false);
     93     },
     94     'DenseMatrix, DenseMatrix': function DenseMatrixDenseMatrix(x, y) {
     95       return algorithm13(x, y, this);
     96     },
     97     'Array, Array': function ArrayArray(x, y) {
     98       // use matrix implementation
     99       return this(matrix(x), matrix(y)).valueOf();
    100     },
    101     'Array, Matrix': function ArrayMatrix(x, y) {
    102       // use matrix implementation
    103       return this(matrix(x), y);
    104     },
    105     'Matrix, Array': function MatrixArray(x, y) {
    106       // use matrix implementation
    107       return this(x, matrix(y));
    108     },
    109     'SparseMatrix, any': function SparseMatrixAny(x, y) {
    110       return algorithm12(x, y, this, false);
    111     },
    112     'DenseMatrix, any': function DenseMatrixAny(x, y) {
    113       return algorithm14(x, y, this, false);
    114     },
    115     'any, SparseMatrix': function anySparseMatrix(x, y) {
    116       return algorithm12(y, x, this, true);
    117     },
    118     'any, DenseMatrix': function anyDenseMatrix(x, y) {
    119       return algorithm14(y, x, this, true);
    120     },
    121     'Array, any': function ArrayAny(x, y) {
    122       // use matrix implementation
    123       return algorithm14(matrix(x), y, this, false).valueOf();
    124     },
    125     'any, Array': function anyArray(x, y) {
    126       // use matrix implementation
    127       return algorithm14(matrix(y), x, this, true).valueOf();
    128     }
    129   });
    130 });
    131 exports.createXor = createXor;