simple-squiggle

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

exp.js (1442B)


      1 import { factory } from '../../utils/factory.js';
      2 import { deepMap } from '../../utils/collection.js';
      3 import { expNumber } from '../../plain/number/index.js';
      4 var name = 'exp';
      5 var dependencies = ['typed'];
      6 export var createExp = /* #__PURE__ */factory(name, dependencies, _ref => {
      7   var {
      8     typed
      9   } = _ref;
     10 
     11   /**
     12    * Calculate the exponent of a value.
     13    * For matrices, the function is evaluated element wise.
     14    *
     15    * Syntax:
     16    *
     17    *    math.exp(x)
     18    *
     19    * Examples:
     20    *
     21    *    math.exp(2)                  // returns number 7.3890560989306495
     22    *    math.pow(math.e, 2)          // returns number 7.3890560989306495
     23    *    math.log(math.exp(2))        // returns number 2
     24    *
     25    *    math.exp([1, 2, 3])
     26    *    // returns Array [
     27    *    //   2.718281828459045,
     28    *    //   7.3890560989306495,
     29    *    //   20.085536923187668
     30    *    // ]
     31    *
     32    * See also:
     33    *
     34    *    expm1, log, pow
     35    *
     36    * @param {number | BigNumber | Complex | Array | Matrix} x  A number or matrix to exponentiate
     37    * @return {number | BigNumber | Complex | Array | Matrix} Exponent of `x`
     38    */
     39   return typed(name, {
     40     number: expNumber,
     41     Complex: function Complex(x) {
     42       return x.exp();
     43     },
     44     BigNumber: function BigNumber(x) {
     45       return x.exp();
     46     },
     47     'Array | Matrix': function ArrayMatrix(x) {
     48       // TODO: exp(sparse) should return a dense matrix since exp(0)==1
     49       return deepMap(x, this);
     50     }
     51   });
     52 });