simple-squiggle

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

asech.js (1793B)


      1 "use strict";
      2 
      3 Object.defineProperty(exports, "__esModule", {
      4   value: true
      5 });
      6 exports.createAsech = void 0;
      7 
      8 var _factory = require("../../utils/factory.js");
      9 
     10 var _collection = require("../../utils/collection.js");
     11 
     12 var _index = require("../../plain/number/index.js");
     13 
     14 var name = 'asech';
     15 var dependencies = ['typed', 'config', 'Complex', 'BigNumber'];
     16 var createAsech = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) {
     17   var typed = _ref.typed,
     18       config = _ref.config,
     19       Complex = _ref.Complex,
     20       _BigNumber = _ref.BigNumber;
     21 
     22   /**
     23    * Calculate the hyperbolic arcsecant of a value,
     24    * defined as `asech(x) = acosh(1/x) = ln(sqrt(1/x^2 - 1) + 1/x)`.
     25    *
     26    * For matrices, the function is evaluated element wise.
     27    *
     28    * Syntax:
     29    *
     30    *    math.asech(x)
     31    *
     32    * Examples:
     33    *
     34    *    math.asech(0.5)       // returns 1.3169578969248166
     35    *
     36    * See also:
     37    *
     38    *    acsch, acoth
     39    *
     40    * @param {number | Complex | Array | Matrix} x  Function input
     41    * @return {number | Complex | Array | Matrix} Hyperbolic arcsecant of x
     42    */
     43   return typed(name, {
     44     number: function number(x) {
     45       if (x <= 1 && x >= -1 || config.predictable) {
     46         var xInv = 1 / x;
     47 
     48         if (xInv > 0 || config.predictable) {
     49           return (0, _index.asechNumber)(x);
     50         }
     51 
     52         var ret = Math.sqrt(xInv * xInv - 1);
     53         return new Complex(Math.log(ret - xInv), Math.PI);
     54       }
     55 
     56       return new Complex(x, 0).asech();
     57     },
     58     Complex: function Complex(x) {
     59       return x.asech();
     60     },
     61     BigNumber: function BigNumber(x) {
     62       return new _BigNumber(1).div(x).acosh();
     63     },
     64     'Array | Matrix': function ArrayMatrix(x) {
     65       return (0, _collection.deepMap)(x, this);
     66     }
     67   });
     68 });
     69 exports.createAsech = createAsech;