@mojir/lits
Version:
Lits is a pure functional programming language implemented in TypeScript
3 lines (2 loc) • 15.4 kB
JavaScript
function t(t){if(!t.position||!t.code)return"";const e=t.position.column-1,a=t.code.length-e-1;return`${" ".repeat(Math.max(e,0))}^${" ".repeat(Math.max(a,0))}`}class e extends Error{sourceCodeInfo;shortMessage;constructor(a,n){const r=a instanceof Error?a.message:`${a}`;super(function(e,a){if(!a)return e;const n=`${a.position.line}:${a.position.column}`;return`${e}${a.filePath?`\n${a.filePath}:${n}`:`\nLocation ${n}`}\n${a.code}\n${t(a)}`}(r,n)),this.shortMessage=r,this.sourceCodeInfo=n,Object.setPrototypeOf(this,e.prototype),this.name="LitsError"}getCodeMarker(){return this.sourceCodeInfo&&t(this.sourceCodeInfo)}}new Set(Object.values({Number:1,String:2,NormalExpression:3,SpecialExpression:4,UserDefinedSymbol:5,NormalBuiltinSymbol:6,SpecialBuiltinSymbol:7,ReservedSymbol:8,Binding:9,Spread:10}));function a(t,e={}){return"number"==typeof t&&(!Number.isNaN(t)&&(!(e.integer&&!Number.isInteger(t))&&(!(e.finite&&!Number.isFinite(t))&&((!e.zero||0===t)&&((!e.nonZero||0!==t)&&(!(e.positive&&t<=0)&&(!(e.negative&&t>=0)&&(!(e.nonPositive&&t>0)&&(!(e.nonNegative&&t<0)&&(!("number"==typeof e.gt&&t<=e.gt)&&(!("number"==typeof e.gte&&t<e.gte)&&(!("number"==typeof e.lt&&t>=e.lt)&&!("number"==typeof e.lte&&t>e.lte)))))))))))))}new Set(["UserDefined","Partial","Comp","Constantly","Juxt","Complement","EveryPred","SomePred","Fnull","Builtin","SpecialBuiltin","NativeJsFunction","Module"]);const n=new WeakSet,r=new WeakSet,o=new WeakSet,i=new WeakSet,s=new WeakSet,m=new WeakSet;function h(t){return{min:t,max:t}}function l(t,h){if(l=t,Array.isArray(l)&&(r.has(l)||!o.has(l)&&!(l.every(t=>a(t))?(n.add(l),r.add(l),0):(o.add(l),1))))return["vector",t];var l;if(function(t){if(!Array.isArray(t))return!1;if(i.has(t))return!0;if(s.has(t))return!1;if(0===t.length)return s.add(t),!1;if(!Array.isArray(t[0])||0===t[0].length)return s.add(t),!1;const e=t[0].length;for(const n of t)if(!Array.isArray(n)||n.length!==e||n.some(t=>!a(t)))return s.add(t),!1;return n.add(t),m.add(t),i.add(t),!0}(t))return["matrix",t];if(!a(t))throw new e("Invalid parameter type: "+typeof t,h);return["number",t]}function c(t){return([e],a)=>{const[n,r]=l(e,a);return"number"===n?t(r):"vector"===n?r.map(e=>t(e)):r.map(e=>e.map(e=>t(e)))}}const p={name:"math",functions:{sin:{evaluate:c(t=>Math.sin(t)),arity:h(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `sin` function computes the sine of an angle (in radians), working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the sine of each element while preserving the original structure.",seeAlso:["math.asin","math.sinh","math.cos","math.tan","math.to-rad"],examples:["let { sin } = import(math);\nsin(0)","let { sin } = import(math);\nsin(1)","let { sin } = import(math);\nsin(PI)","let { sin } = import(math);\nsin(-0.5)","let { sin } = import(math);\nsin([1, 2, 3])","let { sin } = import(math);\nsin([[1, 2], [3, 4]])"]}},asin:{evaluate:c(t=>Math.asin(t)),arity:h(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `asin` function computes the arcsine (inverse sine) of a `number` in radians, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the arcsine of each element while preserving the original structure.",seeAlso:["math.sin","math.asinh","math.acos","math.atan"],examples:["let { asin } = import(math);\nasin(0)","let { asin } = import(math);\nasin(1)","let { asin } = import(math);\nasin(-0.5)","let { asin } = import(math);\nasin([1, 2, 3])","let { asin } = import(math);\nasin([[1, 2], [3, 4]])"]}},sinh:{evaluate:c(t=>Math.sinh(t)),arity:h(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `sinh` function computes the hyperbolic sine of a `number`, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the hyperbolic sine of each element while preserving the original structure.",seeAlso:["math.asinh","math.sin","math.cosh","math.tanh"],examples:["let { sinh } = import(math);\nsinh(0)","let { sinh } = import(math);\nsinh(1)","let { sinh } = import(math);\nsinh(-0.5)","let { sinh } = import(math);\nsinh([0.1, 0.2, 0.3])","let { sinh } = import(math);\nsinh([[0.1, 0.2], [0.3, 0.4]])"]}},asinh:{evaluate:c(t=>Math.asinh(t)),arity:h(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `asinh` function computes the inverse hyperbolic sine of a `number`, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the inverse hyperbolic sine of each element while preserving the original structure.",seeAlso:["math.sinh","math.asin","math.acosh","math.atanh"],examples:["let { asinh } = import(math);\nasinh(10)","let { asinh } = import(math);\nasinh(90)","let { asinh } = import(math);\nasinh(50)","let { asinh } = import(math);\nasinh([10, 20, 30])","let { asinh } = import(math);\nasinh([[10, 20], [30, 40]])"]}},cos:{evaluate:c(t=>Math.cos(t)),arity:h(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `cos` function computes the cosine of an angle (in radians), working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the cosine of each element while preserving the original structure.",seeAlso:["math.acos","math.cosh","math.sin","math.tan","math.to-rad"],examples:["let { cos } = import(math);\ncos(0)","let { cos } = import(math);\ncos(1)","let { cos } = import(math);\ncos(PI)","let { cos } = import(math);\ncos(-0.5)","let { cos } = import(math);\ncos([1, 2, 3])","let { cos } = import(math);\ncos([[1, 2], [3, 4]])"]}},acos:{evaluate:c(t=>Math.acos(t)),arity:h(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `acos` function computes the arccosine (inverse cosine) of a `number` in radians, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the arccosine of each element while preserving the original structure.",seeAlso:["math.cos","math.acosh","math.asin","math.atan"],examples:["let { acos } = import(math);\nacos(0)","let { acos } = import(math);\nacos(1)","let { acos } = import(math);\nacos(-0.5)","let { acos } = import(math);\nacos([0.1, 0.2, 0.3])","let { acos } = import(math);\nacos([[0.1, 0.2], [0.3, 0.4]])"]}},cosh:{evaluate:c(t=>Math.cosh(t)),arity:h(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `cosh` function computes the hyperbolic cosine of a `number`, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the hyperbolic cosine of each element while preserving the original structure.",seeAlso:["math.acosh","math.cos","math.sinh","math.tanh"],examples:["let { cosh } = import(math);\ncosh(0)","let { cosh } = import(math);\ncosh(1)","let { cosh } = import(math);\ncosh(-0.5)","let { cosh } = import(math);\ncosh([0.1, 0.2, 0.3])","let { cosh } = import(math);\ncosh([[0.1, 0.2], [0.3, 0.4]])"]}},acosh:{evaluate:c(t=>Math.acosh(t)),arity:h(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `acosh` function computes the inverse hyperbolic cosine of a `number`, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the inverse hyperbolic cosine of each element while preserving the original structure.",seeAlso:["math.cosh","math.acos","math.asinh","math.atanh"],examples:["let { acosh } = import(math);\nacosh(1)","let { acosh } = import(math);\nacosh(2)","let { acosh } = import(math);\nacosh(100)","let { acosh } = import(math);\nacosh(50)","let { acosh } = import(math);\nacosh([1, 2, 3])","let { acosh } = import(math);\nacosh([[1, 2], [3, 4]])"]}},tan:{evaluate:c(t=>Math.tan(t)),arity:h(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `tan` function computes the tangent of an angle (in radians), working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the tangent of each element while preserving the original structure.",seeAlso:["math.atan","math.tanh","math.sin","math.cos","math.to-rad"],examples:["let { tan } = import(math);\ntan(0)","let { tan } = import(math);\ntan(1)","let { tan } = import(math);\ntan(PI)","let { tan } = import(math);\ntan(-0.5)","let { tan } = import(math);\ntan([1, 2, 3])","let { tan } = import(math);\ntan([[1, 2], [3, 4]])"]}},atan:{evaluate:c(t=>Math.atan(t)),arity:h(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `atan` function computes the arctangent (inverse tangent) of a `number` in radians, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the arctangent of each element while preserving the original structure.",seeAlso:["math.tan","math.atanh","math.asin","math.acos"],examples:["let { atan } = import(math);\natan(0)","let { atan } = import(math);\natan(1)","let { atan } = import(math);\natan(-0.5)","let { atan } = import(math);\natan([0.1, 0.2, 0.3])","let { atan } = import(math);\natan([[0.1, 0.2], [0.3, 0.4]])"]}},tanh:{evaluate:c(t=>Math.tanh(t)),arity:h(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `tanh` function computes the hyperbolic tangent of a `number`, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the hyperbolic tangent of each element while preserving the original structure.",seeAlso:["math.atanh","math.tan","math.sinh","math.cosh"],examples:["let { tanh } = import(math);\ntanh(0)","let { tanh } = import(math);\ntanh(1)","let { tanh } = import(math);\ntanh(-0.5)","let { tanh } = import(math);\ntanh(50)"]}},atanh:{evaluate:c(t=>Math.atanh(t)),arity:h(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `atanh` function computes the inverse hyperbolic tangent of a `number`, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the inverse hyperbolic tangent of each element while preserving the original structure.",seeAlso:["math.tanh","math.atan","math.asinh","math.acosh"],examples:["let { atanh } = import(math);\natanh(0)","let { atanh } = import(math);\natanh(0.9)","let { atanh } = import(math);\natanh(-0.5)","let { atanh } = import(math);\natanh([0.1, 0.2, 0.3])","let { atanh } = import(math);\natanh([[0.1, 0.2], [0.3, 0.4]])"]}},ln:{evaluate:c(t=>Math.log(t)),arity:h(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `ln` function computes the natural logarithm (base `e`) of a `number`, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the natural logarithm of each element while preserving the original structure.",seeAlso:["math.log2","math.log10","^"],examples:["let { ln } = import(math);\nln(0.01)","let { ln } = import(math);\nln(2.5)","let { ln } = import(math);\nln(E)","let { ln } = import(math);\nln([1, 2, 3])","let { ln } = import(math);\nln([[1, 2], [3, 4]])"]}},log2:{evaluate:c(t=>Math.log2(t)),arity:h(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `log2` function computes the base `2` logarithm of a `number`, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the base-2 logarithm of each element while preserving the original structure.",seeAlso:["math.ln","math.log10"],examples:["let { log2 } = import(math);\nlog2(0.01)","let { log2 } = import(math);\nlog2(2 ^ 12)","let { log2 } = import(math);\nlog2(2.5)","let { log2 } = import(math);\nlog2([1, 2, 3])","let { log2 } = import(math);\nlog2([[1, 2], [3, 4]])"]}},log10:{evaluate:c(t=>Math.log10(t)),arity:h(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `log10` function computes the base `10` logarithm of a `number`, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the base-10 logarithm of each element while preserving the original structure.",seeAlso:["math.ln","math.log2"],examples:["let { log10 } = import(math);\nlog10(0.01)","let { log10 } = import(math);\nlog10(10 ^ 12)","let { log10 } = import(math);\nlog10(2.5)","let { log10 } = import(math);\nlog10([1, 2, 3])","let { log10 } = import(math);\nlog10([[1, 2], [3, 4]])"]}},"to-rad":{evaluate:c(t=>t*Math.PI/180),arity:h(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `to-rad` function converts an angle from degrees to radians, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it converts each element while preserving the original structure.",seeAlso:["math.to-deg","math.sin","math.cos","math.tan"],examples:["let { to-rad } = import(math);\nto-rad(0)","let { to-rad } = import(math);\nto-rad(90)","let { to-rad } = import(math);\nto-rad(180)","let { to-rad } = import(math);\nto-rad(360)","let { to-rad } = import(math);\nto-rad([0, 90, 180])","let { to-rad } = import(math);\nto-rad([[0, 90], [180, 360]])"]}},"to-deg":{evaluate:c(t=>180*t/Math.PI),arity:h(1),docs:{category:"math",returns:{type:["number","vector","matrix"]},args:{x:{type:["number","vector","matrix"]}},variants:[{argumentNames:["x"]}],description:"The `to-deg` function converts an angle from radians to degrees, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it converts each element while preserving the original structure.",seeAlso:["math.to-rad"],examples:["let { to-deg } = import(math);\nto-deg(0)","let { to-deg } = import(math);\nto-deg(PI)","let { to-deg } = import(math);\nto-deg(PI / 2)","let { to-deg } = import(math);\nto-deg(3 * PI / 2)","let { to-deg } = import(math);\nto-deg([0, PI, PI / 2])","let { to-deg } = import(math);\nto-deg([[0, PI], [PI / 2, 3 * PI / 2]])"]}}}};export{p as mathUtilsModule};
//# sourceMappingURL=math.esm.js.map