@mojir/lits 2.5.1 → 2.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/README.md +10 -11
  2. package/dist/cli/cli.js +2150 -1202
  3. package/dist/cli/reference/api.d.ts +15 -11
  4. package/dist/cli/reference/index.d.ts +133 -132
  5. package/dist/cli/src/builtin/bindingNode.d.ts +5 -0
  6. package/dist/cli/src/builtin/core/assertion.d.ts +2 -0
  7. package/dist/cli/src/builtin/index.d.ts +2 -2
  8. package/dist/cli/src/builtin/interface.d.ts +2 -1
  9. package/dist/cli/src/builtin/modules/convert/index.d.ts +2 -0
  10. package/dist/cli/src/builtin/specialExpressionTypes.d.ts +1 -1
  11. package/dist/cli/src/builtin/specialExpressions/match.d.ts +7 -0
  12. package/dist/cli/src/parser/subParsers/parseBindingTarget.d.ts +4 -2
  13. package/dist/cli/src/parser/subParsers/parseMatch.d.ts +4 -0
  14. package/dist/cli/src/parser/types.d.ts +5 -1
  15. package/dist/full.esm.js +1 -1
  16. package/dist/full.esm.js.map +1 -1
  17. package/dist/full.js +1 -1
  18. package/dist/full.js.map +1 -1
  19. package/dist/index.esm.js +1 -1
  20. package/dist/index.esm.js.map +1 -1
  21. package/dist/index.js +1 -1
  22. package/dist/index.js.map +1 -1
  23. package/dist/lits.iife.js +1 -1
  24. package/dist/lits.iife.js.map +1 -1
  25. package/dist/modules/assertion.esm.js +2 -0
  26. package/dist/modules/assertion.esm.js.map +1 -0
  27. package/dist/modules/assertion.js +2 -0
  28. package/dist/modules/assertion.js.map +1 -0
  29. package/dist/modules/collection.esm.js +1 -1
  30. package/dist/modules/collection.esm.js.map +1 -1
  31. package/dist/modules/collection.js +1 -1
  32. package/dist/modules/collection.js.map +1 -1
  33. package/dist/modules/convert.esm.js +2 -0
  34. package/dist/modules/convert.esm.js.map +1 -0
  35. package/dist/modules/convert.js +2 -0
  36. package/dist/modules/convert.js.map +1 -0
  37. package/dist/modules/grid.esm.js +1 -1
  38. package/dist/modules/grid.esm.js.map +1 -1
  39. package/dist/modules/grid.js +1 -1
  40. package/dist/modules/grid.js.map +1 -1
  41. package/dist/modules/linear-algebra.esm.js +1 -1
  42. package/dist/modules/linear-algebra.esm.js.map +1 -1
  43. package/dist/modules/linear-algebra.js +1 -1
  44. package/dist/modules/linear-algebra.js.map +1 -1
  45. package/dist/modules/math.esm.js +1 -1
  46. package/dist/modules/math.esm.js.map +1 -1
  47. package/dist/modules/math.js +1 -1
  48. package/dist/modules/math.js.map +1 -1
  49. package/dist/modules/matrix.esm.js +1 -1
  50. package/dist/modules/matrix.esm.js.map +1 -1
  51. package/dist/modules/matrix.js +1 -1
  52. package/dist/modules/matrix.js.map +1 -1
  53. package/dist/modules/random.esm.js +1 -1
  54. package/dist/modules/random.esm.js.map +1 -1
  55. package/dist/modules/random.js +1 -1
  56. package/dist/modules/random.js.map +1 -1
  57. package/dist/modules/reference/api.d.ts +15 -11
  58. package/dist/modules/reference/index.d.ts +133 -132
  59. package/dist/modules/sequence.esm.js +1 -1
  60. package/dist/modules/sequence.esm.js.map +1 -1
  61. package/dist/modules/sequence.js +1 -1
  62. package/dist/modules/sequence.js.map +1 -1
  63. package/dist/modules/src/builtin/bindingNode.d.ts +5 -0
  64. package/dist/modules/src/builtin/core/assertion.d.ts +2 -0
  65. package/dist/modules/src/builtin/index.d.ts +2 -2
  66. package/dist/modules/src/builtin/interface.d.ts +2 -1
  67. package/dist/modules/src/builtin/modules/convert/index.d.ts +2 -0
  68. package/dist/modules/src/builtin/specialExpressionTypes.d.ts +1 -1
  69. package/dist/modules/src/builtin/specialExpressions/match.d.ts +7 -0
  70. package/dist/modules/src/full.d.ts +1 -1
  71. package/dist/modules/src/modules/assertion.d.ts +2 -0
  72. package/dist/modules/src/modules/{assert.d.ts → convert.d.ts} +1 -1
  73. package/dist/modules/src/parser/subParsers/parseBindingTarget.d.ts +4 -2
  74. package/dist/modules/src/parser/subParsers/parseMatch.d.ts +4 -0
  75. package/dist/modules/src/parser/types.d.ts +5 -1
  76. package/dist/modules/string.esm.js +1 -1
  77. package/dist/modules/string.esm.js.map +1 -1
  78. package/dist/modules/string.js +1 -1
  79. package/dist/modules/string.js.map +1 -1
  80. package/dist/modules/vector.esm.js +1 -1
  81. package/dist/modules/vector.esm.js.map +1 -1
  82. package/dist/modules/vector.js +1 -1
  83. package/dist/modules/vector.js.map +1 -1
  84. package/dist/reference/api.d.ts +15 -11
  85. package/dist/reference/index.d.ts +133 -132
  86. package/dist/src/builtin/bindingNode.d.ts +5 -0
  87. package/dist/src/builtin/core/assertion.d.ts +2 -0
  88. package/dist/src/builtin/index.d.ts +2 -2
  89. package/dist/src/builtin/interface.d.ts +2 -1
  90. package/dist/src/builtin/modules/convert/index.d.ts +2 -0
  91. package/dist/src/builtin/specialExpressionTypes.d.ts +1 -1
  92. package/dist/src/builtin/specialExpressions/match.d.ts +7 -0
  93. package/dist/src/full.d.ts +1 -1
  94. package/dist/src/modules/assertion.d.ts +2 -0
  95. package/dist/src/modules/{assert.d.ts → convert.d.ts} +1 -1
  96. package/dist/src/parser/subParsers/parseBindingTarget.d.ts +4 -2
  97. package/dist/src/parser/subParsers/parseMatch.d.ts +4 -0
  98. package/dist/src/parser/types.d.ts +5 -1
  99. package/dist/testFramework.esm.js +1 -1
  100. package/dist/testFramework.esm.js.map +1 -1
  101. package/dist/testFramework.js +1 -1
  102. package/dist/testFramework.js.map +1 -1
  103. package/package.json +10 -5
  104. package/dist/cli/src/builtin/specialExpressions/switch.d.ts +0 -6
  105. package/dist/cli/src/parser/subParsers/parseSwitch.d.ts +0 -4
  106. package/dist/modules/assert.esm.js +0 -2
  107. package/dist/modules/assert.esm.js.map +0 -1
  108. package/dist/modules/assert.js +0 -2
  109. package/dist/modules/assert.js.map +0 -1
  110. package/dist/modules/src/builtin/specialExpressions/switch.d.ts +0 -6
  111. package/dist/modules/src/parser/subParsers/parseSwitch.d.ts +0 -4
  112. package/dist/src/builtin/specialExpressions/switch.d.ts +0 -6
  113. package/dist/src/parser/subParsers/parseSwitch.d.ts +0 -4
  114. /package/dist/cli/src/builtin/modules/{assert → assertion}/docs.d.ts +0 -0
  115. /package/dist/cli/src/builtin/modules/{assert → assertion}/index.d.ts +0 -0
  116. /package/dist/modules/src/builtin/modules/{assert → assertion}/docs.d.ts +0 -0
  117. /package/dist/modules/src/builtin/modules/{assert → assertion}/index.d.ts +0 -0
  118. /package/dist/src/builtin/modules/{assert → assertion}/docs.d.ts +0 -0
  119. /package/dist/src/builtin/modules/{assert → assertion}/index.d.ts +0 -0
@@ -1,2 +1,2 @@
1
- function e(e){if(!e.position||!e.code)return"";const r=e.position.column-1,a=e.code.length-r-1;return`${" ".repeat(Math.max(r,0))}^${" ".repeat(Math.max(a,0))}`}class r extends Error{sourceCodeInfo;shortMessage;constructor(a,t){const n=a instanceof Error?a.message:`${a}`;super(function(r,a){if(!a)return r;const t=`${a.position.line}:${a.position.column}`;return`${r}${a.filePath?`\n${a.filePath}:${t}`:`\nLocation ${t}`}\n${a.code}\n${e(a)}`}(n,t)),this.shortMessage=n,this.sourceCodeInfo=t,Object.setPrototypeOf(this,r.prototype),this.name="LitsError"}getCodeMarker(){return this.sourceCodeInfo&&e(this.sourceCodeInfo)}}const a={Number:1,String:2,NormalExpression:3,SpecialExpression:4,UserDefinedSymbol:5,NormalBuiltinSymbol:6,SpecialBuiltinSymbol:7,ReservedSymbol:8,Binding:9,Spread:10},t=new Set(Object.values(a));const n=new Set(["UserDefined","Partial","Comp","Constantly","Juxt","Complement","EveryPred","SomePred","Fnull","Builtin","SpecialBuiltin","NativeJsFunction","Module"]);function l(e){return null!==e&&"object"==typeof e&&("^^fn^^"in e&&"functionType"in e&&("string"==typeof(r=e.functionType)&&n.has(r)));var r}function o(e){return!(!Array.isArray(e)||e.length<2)&&("number"==typeof(r=e[0])&&t.has(r));var r}function i(e){return l(e)?`<function ${e.name||"λ"}>`:o(e)?`${r=e[0],Object.keys(a).find(e=>a[e]===r)}-node`:null===e?"null":"object"==typeof e&&e instanceof RegExp?`${e}`:"object"==typeof e&&e instanceof Error?e.toString():JSON.stringify(e);var r}function s(e,r={}){return"number"==typeof e&&(!Number.isNaN(e)&&(!(r.integer&&!Number.isInteger(e))&&(!(r.finite&&!Number.isFinite(e))&&((!r.zero||0===e)&&((!r.nonZero||0!==e)&&(!(r.positive&&e<=0)&&(!(r.negative&&e>=0)&&(!(r.nonPositive&&e>0)&&(!(r.nonNegative&&e<0)&&(!("number"==typeof r.gt&&e<=r.gt)&&(!("number"==typeof r.gte&&e<r.gte)&&(!("number"==typeof r.lt&&e>=r.lt)&&!("number"==typeof r.lte&&e>r.lte)))))))))))))}function c(e,a,t={}){if(!s(e,t))throw new r(`Expected ${function(e){if(e.zero)return"zero";const r=function(e){return e.positive?"positive":e.negative?"negative":e.nonNegative?"non negative":e.nonPositive?"non positive":e.nonZero?"non zero":""}(e),a=e.integer?"integer":"number",t=e.finite?"finite":"",n=function(e){return"number"!=typeof e.gt&&"number"!=typeof e.gte||"number"!=typeof e.lt&&"number"!=typeof e.lte?"number"==typeof e.gt||"number"==typeof e.gte?"number"==typeof e.gt?`n > ${e.gt}`:`n >= ${e.gte}`:"number"==typeof e.lt||"number"==typeof e.lte?"number"==typeof e.lt?`n < ${e.lt}`:`n <= ${e.lte}`:"":`${"number"==typeof e.gt?`${e.gt} < n `:`${e.gte} <= n `}${"number"==typeof e.lt?`< ${e.lt}`:`<= ${e.lte}`}`}(e);return[r,t,a,n].filter(e=>!!e).join(" ")}(t)}, got ${i(e)}.`,function(e,r){return e?.sourceCodeInfo??r}(e,a))}const m=new WeakSet,g=new WeakSet,u=new WeakSet,b=new WeakSet,p=new WeakSet,h=new WeakSet;function v(e){return!!Array.isArray(e)&&(!!g.has(e)||!u.has(e)&&(e.every(e=>s(e))?(m.add(e),g.add(e),!0):(u.add(e),!1)))}function d(e,a){if(!v(e))throw new r(`Expected a vector, but got ${e}`,a)}function f(e,a){if(!function(e){return!!v(e)&&2===e.length}(e))throw new r(`Expected a 2d vector, but got ${e}`,a)}function y(e,a){if(!function(e){return!!v(e)&&3===e.length}(e))throw new r(`Expected a 3d vector, but got ${e}`,a)}function w(e,a){if(d(e,a),0===e.length)throw new r(`Expected a non empty vector, but got ${e}`,a)}function z(e){if(!Array.isArray(e))return!1;if(b.has(e))return!0;if(p.has(e))return!1;if(0===e.length)return p.add(e),!1;if(!Array.isArray(e[0])||0===e[0].length)return p.add(e),!1;const r=e[0].length;for(const a of e)if(!Array.isArray(a)||a.length!==r||a.some(e=>!s(e)))return p.add(e),!1;return m.add(e),h.add(e),b.add(e),!0}function x(e){if(0===e.length)return 0;return e.reduce((e,r)=>e+r,0)/e.length}function k(e){const r=[...e].sort((e,r)=>e-r),a=Math.floor(r.length/2);return r.length%2==0?(r[a-1]+r[a])/2:r[a]}function N(e,r){const a=function(e,r){const a=r??x(e);return e.reduce((e,r)=>e+(r-a)**2,0)/e.length}(e,r);return Math.sqrt(a)}function A(e){return{min:e,max:e}}const M={reflect:{category:"linear-algebra",description:"Reflects a vector across a given axis.",returns:{type:"vector"},args:{a:{type:"vector",description:"Vector to reflect."},b:{type:"vector",description:"Axis of reflection."}},variants:[{argumentNames:["a","b"]}],examples:["let { reflect } = import(linear-algebra);\nreflect([1, 2], [0, 1])","let { reflect } = import(linear-algebra);\nreflect([1, 2, 3], [0, 0, 1])"],seeAlso:["linear-algebra.refract","linear-algebra.projection"]},refract:{category:"linear-algebra",description:"Refracts a vector across a given axis.",returns:{type:"vector"},args:{vector:{type:"vector",description:"Vector to refract."},axis:{type:"vector",description:"Axis of refraction."},eta:{type:"number",description:"Refraction index."}},variants:[{argumentNames:["vector","axis","eta"]}],examples:["let { refract } = import(linear-algebra);\nrefract([1, 2], [0, 1], 1.5)","let { refract } = import(linear-algebra);\nrefract([1, 2, 3], [0, 0, 1], 1.5)"],seeAlso:["linear-algebra.reflect"]},lerp:{category:"linear-algebra",description:"Performs linear interpolation between two vectors.",returns:{type:"vector"},args:{a:{type:"vector",description:"Start vector."},b:{type:"vector",description:"End vector."},t:{type:"number",description:"Interpolation factor (0 to 1)."}},variants:[{argumentNames:["a","b","t"]}],examples:["let { lerp } = import(linear-algebra);\nlerp([1, 2], [3, 4], 0.5)","let { lerp } = import(linear-algebra);\nlerp([1, 2], [3, 4], 2)","let { lerp } = import(linear-algebra);\nlerp([1, 2], [3, 4], -1)","let { lerp } = import(linear-algebra);\nlerp([1, 2, 3], [4, 5, 6], 0.25)"],seeAlso:["linear-algebra.projection"]},rotate2d:{category:"linear-algebra",description:"Rotates a 2D vector by a given angle in radians.",returns:{type:"vector"},args:{a:{type:"vector",description:"Vector to rotate."},b:{type:"number",description:"Angle in b."}},variants:[{argumentNames:["a","b"]}],examples:["let { rotate2d } = import(linear-algebra);\nrotate2d([1, 0], PI / 2)","let { rotate2d } = import(linear-algebra);\nrotate2d([0, 1], PI)"],seeAlso:["linear-algebra.rotate3d","linear-algebra.angle"]},rotate3d:{category:"linear-algebra",description:"Rotates a 3D vector around a given axis by a given angle in radians.",returns:{type:"vector"},args:{v:{type:"vector",description:"Vector to rotate."},axis:{type:"vector",description:"Axis of rotation."},radians:{type:"number",description:"Angle in radians."}},variants:[{argumentNames:["v","axis","radians"]}],examples:["let { rotate3d } = import(linear-algebra);\nrotate3d([1, 0, 0], [0, 1, 0], PI / 2)","let { rotate3d } = import(linear-algebra);\nrotate3d([0, 1, 0], [1, 0, 0], PI)"],seeAlso:["linear-algebra.rotate2d","linear-algebra.angle"]},dot:{category:"linear-algebra",description:"Calculates the dot product of two vectors. The result is a scalar.",returns:{type:"number"},args:{a:{type:"vector",description:"First vector."},b:{type:"vector",description:"Second vector."}},variants:[{argumentNames:["a","b"]}],examples:["let { dot } = import(linear-algebra);\ndot([1, 2], [3, 4])","let { dot } = import(linear-algebra);\ndot([1, 2, 3], [4, 5, 6])"],seeAlso:["linear-algebra.cross","linear-algebra.cosine-similarity","linear-algebra.angle","linear-algebra.projection","linear-algebra.orthogonal?"]},cross:{category:"linear-algebra",description:"Calculates the cross product of two 3D vectors. The result is a vector perpendicular to both input vectors.",returns:{type:"vector"},args:{a:{type:"vector",description:"First vector (3D)."},b:{type:"vector",description:"Second vector (3D)."}},variants:[{argumentNames:["a","b"]}],examples:["let { cross } = import(linear-algebra);\ncross([1, 2, 3], [4, 5, 6])","let { cross } = import(linear-algebra);\ncross([1, 0, 0], [0, 1, 0])","let { cross } = import(linear-algebra);\ncross([0, 0, 1], [1, 0, 0])","let { cross } = import(linear-algebra);\ncross([1, 2, 3], [0, 0, 0])","let { cross } = import(linear-algebra);\ncross([0, 0, 0], [1, 2, 3])"],seeAlso:["linear-algebra.dot"]},"normalize-minmax":{category:"linear-algebra",description:"Normalizes the vector using min-max normalization. The result is a vector with values between 0 and 1.",returns:{type:"number"},args:{v:{type:"vector",description:"Vector to normalize."}},variants:[{argumentNames:["v"]}],examples:["let { normalize-minmax } = import(linear-algebra);\nnormalize-minmax([1, 2, 3])","let { normalize-minmax } = import(linear-algebra);\nnormalize-minmax([1, 2, -3])","let { normalize-minmax } = import(linear-algebra);\nnormalize-minmax([1, 2, 3, 4])","let { normalize-minmax } = import(linear-algebra);\nnormalize-minmax([1, 2, -3, 4])","let { normalize-minmax } = import(linear-algebra);\nnormalize-minmax([1, 2, 3, 40, 50])"],seeAlso:["linear-algebra.normalize-zscore","linear-algebra.normalize-robust","linear-algebra.normalize-l1","linear-algebra.normalize-l2","linear-algebra.normalize-log"]},"normalize-zscore":{category:"linear-algebra",description:"Normalizes the vector using z-score normalization. The result is a vector with mean 0 and standard deviation 1.",returns:{type:"number"},args:{v:{type:"vector",description:"Vector to normalize."}},variants:[{argumentNames:["v"]}],examples:["let { normalize-zscore } = import(linear-algebra);\nnormalize-zscore([1, 2, 3])","let { normalize-zscore } = import(linear-algebra);\nnormalize-zscore([1, 2, -3])","let { normalize-zscore } = import(linear-algebra);\nnormalize-zscore([1, 2, 3, 4])","let { normalize-zscore } = import(linear-algebra);\nnormalize-zscore([1, 2, -3, 4])","let { normalize-zscore } = import(linear-algebra);\nnormalize-zscore([1, 2, 3, 40, 50])"],seeAlso:["linear-algebra.normalize-minmax","linear-algebra.normalize-robust","linear-algebra.normalize-l1","linear-algebra.normalize-l2","linear-algebra.normalize-log"]},"normalize-robust":{category:"linear-algebra",description:"Normalizes the vector using robust normalization. The result is a vector with median 0 and median absolute deviation 1.",returns:{type:"number"},args:{v:{type:"vector",description:"Vector to normalize."}},variants:[{argumentNames:["v"]}],examples:["let { normalize-robust } = import(linear-algebra);\nnormalize-robust([1, 2, 3])","let { normalize-robust } = import(linear-algebra);\nnormalize-robust([1, 2, -3])","let { normalize-robust } = import(linear-algebra);\nnormalize-robust([1, 2, 3, 4])","let { normalize-robust } = import(linear-algebra);\nnormalize-robust([1, 2, -3, 4])","let { normalize-robust } = import(linear-algebra);\nnormalize-robust([1, 2, 3, 40, 50])"],seeAlso:["linear-algebra.normalize-minmax","linear-algebra.normalize-zscore"]},"normalize-l1":{category:"linear-algebra",description:"Normalizes the vector using L1 normalization. The result is a vector with L1 norm equal to 1.",returns:{type:"number"},args:{v:{type:"vector",description:"Vector to normalize."}},variants:[{argumentNames:["v"]}],examples:["let { normalize-l1 } = import(linear-algebra);\nnormalize-l1([1, 2, 3])","let { normalize-l1 } = import(linear-algebra);\nnormalize-l1([1, 2, -3])","let { normalize-l1 } = import(linear-algebra);\nnormalize-l1([1, 2, 3, 4])","let { normalize-l1 } = import(linear-algebra);\nnormalize-l1([1, 2, -3, 4])","let { normalize-l1 } = import(linear-algebra);\nnormalize-l1([1, 2, 3, 40, 50])"],seeAlso:["linear-algebra.normalize-l2","linear-algebra.normalize-minmax","linear-algebra.manhattan-norm","linear-algebra.normalize-zscore"]},"normalize-l2":{category:"linear-algebra",description:"Normalizes the vector using L2 normalization. The result is a vector with L2 norm equal to 1.",returns:{type:"number"},args:{v:{type:"vector",description:"Vector to normalize."}},variants:[{argumentNames:["v"]}],examples:["let { normalize-l2 } = import(linear-algebra);\nnormalize-l2([1, 2, 3])","let { normalize-l2 } = import(linear-algebra);\nnormalize-l2([1, 2, 3])","let { normalize-l2 } = import(linear-algebra);\nnormalize-l2([1, 2, -3])","let { normalize-l2 } = import(linear-algebra);\nnormalize-l2([1, 2, 3, 4])","let { normalize-l2 } = import(linear-algebra);\nnormalize-l2([1, 2, -3, 4])","let { normalize-l2 } = import(linear-algebra);\nnormalize-l2([1, 2, 3, 40, 50])"],seeAlso:["linear-algebra.normalize-l1","linear-algebra.normalize-minmax","linear-algebra.euclidean-norm","linear-algebra.normalize-zscore"]},"normalize-log":{category:"linear-algebra",description:"Normalizes the vector using natural log normalization. The result is a vector with log-transformed values.",returns:{type:"number"},args:{v:{type:"vector",description:"Vector to normalize."}},variants:[{argumentNames:["v"]}],examples:["let { normalize-log } = import(linear-algebra);\nnormalize-log([1, 2, 3])","let { normalize-log } = import(linear-algebra);\nnormalize-log([1, 2, 3, 4])","let { normalize-log } = import(linear-algebra);\nnormalize-log([1, 2, 3, 40, 50])"],seeAlso:["linear-algebra.normalize-minmax","linear-algebra.normalize-zscore"]},angle:{category:"linear-algebra",description:"Calculates the **angle** between two vectors in radians.",returns:{type:"number"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { angle } = import(linear-algebra);\nangle([1, 0], [0, 1])","let { angle } = import(linear-algebra);\nangle([1, 0, 1], [0, 1, 0])"],seeAlso:["linear-algebra.dot","linear-algebra.collinear?","linear-algebra.orthogonal?","linear-algebra.rotate2d","linear-algebra.rotate3d","linear-algebra.parallel?","linear-algebra.cosine-similarity","linear-algebra.to-polar"]},projection:{category:"linear-algebra",description:"Calculates the **projection** of vector `a` onto vector `b`.",returns:{type:"vector"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { projection } = import(linear-algebra);\nprojection([1, 2], [3, 4])","let { projection } = import(linear-algebra);\nprojection([1, 2, 3], [4, 5, 6])"],seeAlso:["linear-algebra.dot","linear-algebra.reflect","linear-algebra.lerp"]},"collinear?":{category:"linear-algebra",description:"Checks if two vectors are **collinear**.",returns:{type:"boolean"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { collinear? } = import(linear-algebra);\ncollinear?([1, 2], [2, 4])","let { collinear? } = import(linear-algebra);\ncollinear?([1, 2], [-2, -4])","let { collinear? } = import(linear-algebra);\ncollinear?([1, 2, 3], [2, 4, 6])"],seeAlso:["linear-algebra.parallel?","linear-algebra.orthogonal?","linear-algebra.angle"]},"parallel?":{category:"linear-algebra",description:"Checks if two vectors are **parallel**.",returns:{type:"boolean"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { parallel? } = import(linear-algebra);\nparallel?([1, 2], [2, 4])","let { parallel? } = import(linear-algebra);\nparallel?([1, 2], [-2, -4])","let { parallel? } = import(linear-algebra);\nparallel?([1, 2, 3], [2, 4, 6])","let { parallel? } = import(linear-algebra);\nparallel?([1, 2], [3, 4])"],seeAlso:["linear-algebra.collinear?","linear-algebra.orthogonal?","linear-algebra.angle"]},"orthogonal?":{category:"linear-algebra",description:"Checks if two vectors are **orthogonal**.",returns:{type:"boolean"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { orthogonal? } = import(linear-algebra);\northogonal?([1, 0], [0, 1])","let { orthogonal? } = import(linear-algebra);\northogonal?([1, 0, 1], [0, 1, 0])","let { orthogonal? } = import(linear-algebra);\northogonal?([1, 2], [2, -1])"],seeAlso:["linear-algebra.collinear?","linear-algebra.parallel?","linear-algebra.dot","matrix.orthogonal?","linear-algebra.angle"]},"cosine-similarity":{category:"linear-algebra",description:"Calculates the **cosine similarity** between two vectors. The result is a value between -1 and 1.",returns:{type:"number"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { cosine-similarity } = import(linear-algebra);\ncosine-similarity([1, 2], [3, 4])","let { cosine-similarity } = import(linear-algebra);\ncosine-similarity([1, 2, 3], [4, 5, 6])","let { cosine-similarity } = import(linear-algebra);\ncosine-similarity([1, 0], [0, 1])"],seeAlso:["linear-algebra.dot","linear-algebra.angle","linear-algebra.euclidean-distance"]},"euclidean-distance":{category:"linear-algebra",description:"Calculates the **Euclidean distance** between two vectors. The result is a non-negative number.",returns:{type:"number"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { euclidean-distance } = import(linear-algebra);\neuclidean-distance([1, 2], [3, 4])","let { euclidean-distance } = import(linear-algebra);\neuclidean-distance([1, 2, 3], [4, 5, 6])","let { euclidean-distance } = import(linear-algebra);\neuclidean-distance([1, 0], [0, 1])"],seeAlso:["linear-algebra.manhattan-distance","linear-algebra.chebyshev-distance","linear-algebra.minkowski-distance","linear-algebra.euclidean-norm","linear-algebra.cosine-similarity","linear-algebra.hamming-distance"]},"euclidean-norm":{category:"linear-algebra",description:"Calculates the **Euclidean norm** (L2 norm) of a vector. The result is a non-negative number.",returns:{type:"number"},args:{v:{type:"vector",description:"Vector to calculate the norm for."}},variants:[{argumentNames:["v"]}],examples:["let { euclidean-norm } = import(linear-algebra);\neuclidean-norm([1, 2])","let { euclidean-norm } = import(linear-algebra);\neuclidean-norm([3, 4])","let { euclidean-norm } = import(linear-algebra);\neuclidean-norm([1, 2, 3])"],seeAlso:["linear-algebra.manhattan-norm","linear-algebra.chebyshev-norm","linear-algebra.minkowski-norm","linear-algebra.euclidean-distance","linear-algebra.normalize-l2","linear-algebra.hamming-norm"]},"manhattan-distance":{category:"linear-algebra",description:"Calculates the **Manhattan distance** between two vectors. The result is a non-negative number.",returns:{type:"number"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { manhattan-distance } = import(linear-algebra);\nmanhattan-distance([1, 2], [3, 4])","let { manhattan-distance } = import(linear-algebra);\nmanhattan-distance([1, 2, 3], [4, 5, 6])","let { manhattan-distance } = import(linear-algebra);\nmanhattan-distance([1, 0], [0, 1])"],seeAlso:["linear-algebra.euclidean-distance","linear-algebra.chebyshev-distance","linear-algebra.minkowski-distance","linear-algebra.manhattan-norm","linear-algebra.hamming-distance"]},"manhattan-norm":{category:"linear-algebra",description:"Calculates the **Manhattan norm** (L1 norm) of a vector. The result is a non-negative number.",returns:{type:"number"},args:{v:{type:"vector",description:"Vector to calculate the norm for."}},variants:[{argumentNames:["v"]}],examples:["let { manhattan-norm } = import(linear-algebra);\nmanhattan-norm([1, 2])","let { manhattan-norm } = import(linear-algebra);\nmanhattan-norm([3, 4])","let { manhattan-norm } = import(linear-algebra);\nmanhattan-norm([1, 2, 3])"],seeAlso:["linear-algebra.euclidean-norm","linear-algebra.chebyshev-norm","linear-algebra.minkowski-norm","linear-algebra.manhattan-distance","linear-algebra.normalize-l1","linear-algebra.hamming-norm"]},"hamming-distance":{category:"linear-algebra",description:"Calculates the **Hamming distance** between two vectors. The result is a non-negative integer.",returns:{type:"integer"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { hamming-distance } = import(linear-algebra);\nhamming-distance([1, 2], [3, 4])","let { hamming-distance } = import(linear-algebra);\nhamming-distance([1, 2, 3], [4, 5, 6])","let { hamming-distance } = import(linear-algebra);\nhamming-distance([1, 0], [0, 1])"],seeAlso:["linear-algebra.euclidean-distance","linear-algebra.manhattan-distance","linear-algebra.hamming-norm"]},"hamming-norm":{category:"linear-algebra",description:"Calculates the **Hamming norm** of a vector. The result is a non-negative integer.",returns:{type:"integer"},args:{v:{type:"vector",description:"Vector to calculate the norm for."}},variants:[{argumentNames:["v"]}],examples:["let { hamming-norm } = import(linear-algebra);\nhamming-norm([1, 2])","let { hamming-norm } = import(linear-algebra);\nhamming-norm([3, 4])","let { hamming-norm } = import(linear-algebra);\nhamming-norm([1, 2, 3])"],seeAlso:["linear-algebra.euclidean-norm","linear-algebra.manhattan-norm","linear-algebra.hamming-distance"]},"chebyshev-distance":{category:"linear-algebra",description:"Calculates the **Chebyshev distance** between two vectors. The result is a non-negative number.",returns:{type:"number"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { chebyshev-distance } = import(linear-algebra);\nchebyshev-distance([1, 2], [3, 4])","let { chebyshev-distance } = import(linear-algebra);\nchebyshev-distance([1, 2, 3], [4, 5, 6])","let { chebyshev-distance } = import(linear-algebra);\nchebyshev-distance([1, 0], [0, 1])"],seeAlso:["linear-algebra.euclidean-distance","linear-algebra.manhattan-distance","linear-algebra.minkowski-distance","linear-algebra.chebyshev-norm"]},"chebyshev-norm":{category:"linear-algebra",description:"Calculates the **Chebyshev norm** of a vector. The result is a non-negative number.",returns:{type:"number"},args:{v:{type:"vector",description:"Vector to calculate the norm for."}},variants:[{argumentNames:["v"]}],examples:["let { chebyshev-norm } = import(linear-algebra);\nchebyshev-norm([1, 2])","let { chebyshev-norm } = import(linear-algebra);\nchebyshev-norm([3, 4])","let { chebyshev-norm } = import(linear-algebra);\nchebyshev-norm([1, 2, 3])"],seeAlso:["linear-algebra.euclidean-norm","linear-algebra.manhattan-norm","linear-algebra.minkowski-norm","linear-algebra.chebyshev-distance"]},"minkowski-distance":{category:"linear-algebra",description:"Calculates the **Minkowski distance** between two vectors. The result is a non-negative number.",returns:{type:"number"},args:{a:{type:"vector"},b:{type:"vector"},p:{type:"number",description:"Order of the norm (p)."}},variants:[{argumentNames:["a","b","p"]}],examples:["let { minkowski-distance } = import(linear-algebra);\nminkowski-distance([1, 2], [3, 4], 2)","let { minkowski-distance } = import(linear-algebra);\nminkowski-distance([1, 2, 3], [4, 5, 6], 3)","let { minkowski-distance } = import(linear-algebra);\nminkowski-distance([1, 0], [0, 1], 1)"],seeAlso:["linear-algebra.euclidean-distance","linear-algebra.manhattan-distance","linear-algebra.chebyshev-distance","linear-algebra.minkowski-norm"]},"minkowski-norm":{category:"linear-algebra",description:"Calculates the **Minkowski norm** of a vector. The result is a non-negative number.",returns:{type:"number"},args:{a:{type:"vector",description:"Vector to calculate the norm for."},b:{type:"number",description:"Order of the norm (p)."}},variants:[{argumentNames:["a","b"]}],examples:["let { minkowski-norm } = import(linear-algebra);\nminkowski-norm([1, 2], 2)","let { minkowski-norm } = import(linear-algebra);\nminkowski-norm([3, 4], 3)","let { minkowski-norm } = import(linear-algebra);\nminkowski-norm([1, 2, 3], 4)"],seeAlso:["linear-algebra.euclidean-norm","linear-algebra.manhattan-norm","linear-algebra.chebyshev-norm","linear-algebra.minkowski-distance"]},cov:{category:"linear-algebra",description:"Calculates the **covariance** between two vectors. The result is a number.",returns:{type:"number"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { cov } = import(linear-algebra);\ncov([1, 2], [3, 4])","let { cov } = import(linear-algebra);\ncov([1, 2, 3], [4, 5, 6])","let { cov } = import(linear-algebra);\ncov([1, 0], [0, 1])"],seeAlso:["linear-algebra.corr","linear-algebra.pearson-corr","vector.variance"]},corr:{category:"linear-algebra",description:"Calculates the **correlation** between two vectors. The result is a number between -1 and 1.",returns:{type:"number"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { corr } = import(linear-algebra);\ncorr([1, 2], [3, 4])","let { corr } = import(linear-algebra);\ncorr([1, 2, 3], [4, 5, 6])","let { corr } = import(linear-algebra);\ncorr([1, 0], [0, 1])"],seeAlso:["linear-algebra.cov","linear-algebra.pearson-corr","linear-algebra.spearman-corr","linear-algebra.kendall-tau","linear-algebra.autocorrelation","linear-algebra.cross-correlation"]},"spearman-corr":{category:"linear-algebra",description:"Calculates the **Spearman rank correlation** between two vectors. The result is a number between -1 and 1.",returns:{type:"number"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { spearman-corr } = import(linear-algebra);\nspearman-corr([1, 2], [3, 4])","let { spearman-corr } = import(linear-algebra);\nspearman-corr([1, 2, 3], [4, 5, 6])","let { spearman-corr } = import(linear-algebra);\nspearman-corr([1, 0], [0, 1])"],seeAlso:["linear-algebra.pearson-corr","linear-algebra.kendall-tau","linear-algebra.corr"]},"pearson-corr":{category:"linear-algebra",description:"Calculates the **Pearson correlation** between two vectors. The result is a number between -1 and 1.",returns:{type:"number"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { pearson-corr } = import(linear-algebra);\npearson-corr([1, 2], [3, 4])","let { pearson-corr } = import(linear-algebra);\npearson-corr([1, 2, 3], [4, 5, 6])","let { pearson-corr } = import(linear-algebra);\npearson-corr([1, 0], [0, 1])"],seeAlso:["linear-algebra.spearman-corr","linear-algebra.kendall-tau","linear-algebra.corr","linear-algebra.cov"]},"kendall-tau":{category:"linear-algebra",description:"Calculates the **Kendall Tau** rank correlation coefficient between two vectors. The result is a number between -1 and 1.",returns:{type:"number"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { kendall-tau } = import(linear-algebra);\nkendall-tau([1, 2], [3, 4])","let { kendall-tau } = import(linear-algebra);\nkendall-tau([1, 2, 3], [4, 5, 6])","let { kendall-tau } = import(linear-algebra);\nkendall-tau([1, 0], [0, 1])"],seeAlso:["linear-algebra.spearman-corr","linear-algebra.pearson-corr","linear-algebra.corr"]},autocorrelation:{category:"linear-algebra",description:"Calculates the **autocorrelation** of a vector. The result is a vector of autocorrelation coefficients.",returns:{type:"vector"},args:{a:{type:"vector",description:"Vector to calculate the autocorrelation for."},b:{type:"integer",description:"Lag value for the autocorrelation."}},variants:[{argumentNames:["a","b"]}],examples:["let { autocorrelation } = import(linear-algebra);\nautocorrelation([1, 2, 3], -2)","let { autocorrelation } = import(linear-algebra);\nautocorrelation([1, 2, 3], -1)","let { autocorrelation } = import(linear-algebra);\nautocorrelation([1, 2, 3], 0)","let { autocorrelation } = import(linear-algebra);\nautocorrelation([1, 2, 3], 1)","let { autocorrelation } = import(linear-algebra);\nautocorrelation([1, 2, 3], 2)"],seeAlso:["linear-algebra.cross-correlation","linear-algebra.corr"]},"cross-correlation":{category:"linear-algebra",description:"Calculates the **cross-correlation** between two vectors. The result is a vector of cross-correlation coefficients.",returns:{type:"vector"},args:{a:{type:"vector"},b:{type:"vector"},lag:{type:"integer",description:"Lag value for the cross-correlation."}},variants:[{argumentNames:["a","b","lag"]}],examples:["let { cross-correlation } = import(linear-algebra);\ncross-correlation([1, 2, 3], [4, 5, 6], -2)","let { cross-correlation } = import(linear-algebra);\ncross-correlation([1, 2, 3], [4, 5, 6], -1)","let { cross-correlation } = import(linear-algebra);\ncross-correlation([1, 2, 3], [4, 5, 6], 0)","let { cross-correlation } = import(linear-algebra);\ncross-correlation([1, 2, 3], [4, 5, 6], 1)","let { cross-correlation } = import(linear-algebra);\ncross-correlation([1, 2, 3], [4, 5, 6], 2)"],seeAlso:["linear-algebra.autocorrelation","linear-algebra.corr"]},rref:{category:"linear-algebra",description:"Calculates the **Reduced Row Echelon Form** (RREF) of a matrix.",returns:{type:"matrix"},args:{m:{type:"matrix",description:"Matrix to calculate the RREF for."}},variants:[{argumentNames:["m"]}],examples:["let { rref } = import(linear-algebra);\nrref([[1, 2], [3, 4]])","let { rref } = import(linear-algebra);\nrref([[1, 2, 3], [4, 5, 6], [7, 8, 9]])","let { rref } = import(linear-algebra);\nrref([[1, 2, 3], [7, 8, 9], [4, 5, 7]])"],seeAlso:["linear-algebra.solve","matrix.rank"]},solve:{category:"linear-algebra",description:"Solves a system of linear equations represented by a matrix and a vector.",returns:{type:"vector"},args:{a:{type:"matrix"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { solve } = import(linear-algebra);\nsolve([\n [2, 1, -1, 1], \n [4, 5, -3, 2], \n [6, -2, 5, -3], \n [8, 3, 2, 4]\n], [5, 10, 2, 17])","let { solve } = import(linear-algebra); solve([[2, 0, 0], [3, 1, 0], [4, 5, 6]], [4, 5, 38])","let { solve } = import(linear-algebra); solve([[2, 3], [1, -1]], [8, 2])"],seeAlso:["linear-algebra.rref","matrix.inv"]},"to-polar":{category:"linear-algebra",description:"Converts a 2D vector to polar coordinates.",returns:{type:"vector"},args:{vector:{type:"vector",description:"2D Vector to convert."}},variants:[{argumentNames:["vector"]}],examples:["let { to-polar } = import(linear-algebra);\nto-polar([1, 2])","let { to-polar } = import(linear-algebra);\nto-polar([3, 4])"],seeAlso:["linear-algebra.from-polar","linear-algebra.angle"]},"from-polar":{category:"linear-algebra",description:"Converts polar coordinates to a 2D vector.",returns:{type:"vector"},args:{polar:{type:"vector",description:"Polar coordinates to convert."}},variants:[{argumentNames:["polar"]}],examples:["let { from-polar } = import(linear-algebra);\nfrom-polar([1, PI / 4])","let { from-polar } = import(linear-algebra);\nfrom-polar([1, 0])","let { from-polar } = import(linear-algebra);\nfrom-polar([1, -PI / 2])"],seeAlso:["linear-algebra.to-polar"]}};function C(e,r,a=1e-10){if(e===r)return!0;const t=Math.abs(e-r);if(0===e||0===r||t<a)return t<a;return t/(Math.abs(e)+Math.abs(r))<a}function V(e){return Math.abs(e)<1e-10}function $(e){const r=e.map(e=>[...e]),a=r.length,t=r[0].length;let n=0,l=0;for(let e=0;e<t;e++){let o=-1;for(let t=l;t<a;t++)if(!V(r[t][e])){o=t;break}if(-1===o)continue;n+=1,o!==l&&([r[o],r[l]]=[r[l],r[o]]);const i=r[l][e];for(let a=e;a<t;a++)r[l][a]/=i;for(let n=0;n<a;n++)if(n!==l&&!V(r[n][e])){const a=r[n][e];for(let o=e;o<t;o++)r[n][o]-=a*r[l][o]}if(l++,l===a)break}return[r,n]}function T(e,r){const a=e=>e.every(e=>V(e));if(a(e)||a(r))return!0;let t=0;for(;t<e.length&&V(e[t]);)t++;const n=r[t]/e[t];for(let a=0;a<e.length;a++)if(!V(e[a])||!V(r[a])){if(V(e[a]))return!1;if(!C(r[a]/e[a],n))return!1}return!0}function S(e){return e.every(e=>V(e))}function E(e,r){const a=x(e),t=x(r);let n=0,l=0,o=0;for(let i=0;i<e.length;i++){const s=e[i]-a,c=r[i]-t;n+=s*c,l+=s*s,o+=c*c}if(0===l||0===o)throw new Error("Cannot calculate Pearson correlation coefficient: one of the vectors has zero variance.");return n/(Math.sqrt(l)*Math.sqrt(o))}function q(e){const r=[...e.keys()].sort((r,a)=>e[r]-e[a]),a=Array.from({length:e.length}).fill(0);let t=1,n=0;for(;n<r.length;){const l=e[r[n]];let o=n;for(;o<r.length&&e[r[o]]===l;)o++;const i=t+(o-n-1)/2;for(let e=n;e<o;e++)a[r[e]]=i;t+=o-n,n=o}return a}function j(e,r){const a=x(e),t=x(r);let n=0;for(let l=0;l<e.length;l++)n+=(e[l]-a)*(r[l]-t);return n/e.length}function P(e,a){if(0===e.length)return e;const t=Math.sqrt(e.reduce((e,r)=>e+r**2,0));if(V(t))throw new r("The vector must not be zero",a);return e.map(e=>e/t)}function R(e,r){return e.reduce((e,a,t)=>e+a*r[t],0)}function I(e,r){return e.map((e,a)=>e-r[a])}function D(e,r){return e.map(e=>e*r)}const L={rotate2d:{evaluate:([e,r],a)=>{if(f(e,a),S(e))return e;c(r,a,{finite:!0});const t=Math.cos(r),n=Math.sin(r);return[e[0]*t-e[1]*n,e[0]*n+e[1]*t]},arity:A(2)},rotate3d:{evaluate:([e,a,t],n)=>{if(y(e,n),S(e))return e;if(c(t,n,{finite:!0}),y(a,n),S(a))throw new r("Rotation axis must not be zero",n);const l=Math.cos(t),o=Math.sin(t),[i,s,m]=P(a,n),g=e[0]*i+e[1]*s+e[2]*m;return[g*i*(1-l)+e[0]*l+(-m*e[1]+s*e[2])*o,g*s*(1-l)+e[1]*l+(m*e[0]-i*e[2])*o,g*m*(1-l)+e[2]*l+(-s*e[0]+i*e[1])*o]},arity:A(3)},reflect:{evaluate:([e,a],t)=>{if(d(e,t),d(a,t),e.length!==a.length)throw new r("Vectors must be of the same length",t);if(S(a))throw new r("Reflection normal must not be zero",t);if(S(e))return e;const n=P(a,t);return I(e,D(n,2*R(e,n)))},arity:A(2)},refract:{evaluate:([e,a,t],n)=>{if(d(e,n),d(a,n),c(t,n,{finite:!0,positive:!0}),e.length!==a.length)throw new r("Vectors must be of the same length",n);if(S(a))throw new r("Refraction normal must not be zero",n);if(S(e))return e;const l=P(e,n),o=P(a,n),i=R(l,o),s=1-t*t*(1-i*i);if(s<0)return e;return I(D(l,t),D(o,t*i+Math.sqrt(s)))},arity:A(3)},lerp:{evaluate:([e,a,t],n)=>{if(d(e,n),d(a,n),c(t,n,{finite:!0}),e.length!==a.length)throw new r("Vectors must be of the same length",n);return e.map((e,r)=>e+(a[r]-e)*t)},arity:A(3)},dot:{evaluate:([e,a],t)=>{if(d(e,t),d(a,t),e.length!==a.length)throw new r("Vectors must be of the same length",t);return R(e,a)},arity:A(2)},cross:{evaluate:([e,a],t)=>{if(d(e,t),d(a,t),3!==e.length||3!==a.length)throw new r("Cross product is only defined for 3D vectors",t);return[e[1]*a[2]-e[2]*a[1],e[2]*a[0]-e[0]*a[2],e[0]*a[1]-e[1]*a[0]]},arity:A(2)},"normalize-minmax":{evaluate:([e],r)=>{if(d(e,r),0===e.length)return[];const a=e.reduce((e,r)=>r<e?r:e,e[0]),t=e.reduce((e,r)=>r>e?r:e,e[0]);return a===t?e.map(()=>0):e.map(e=>(e-a)/(t-a))},arity:A(1)},"normalize-robust":{evaluate:([e],r)=>{if(d(e,r),0===e.length)return[];const a=k(e),t=function(e){const r=k(e);return 1.4826*k(e.map(e=>Math.abs(e-r)))}(e);return 0===t?e.map(e=>e-a):e.map(e=>(e-a)/t)},arity:A(1)},"normalize-zscore":{evaluate:([e],r)=>{d(e,r);const a=x(e),t=N(e);return 0===t?e.map(()=>0):e.map(e=>(e-a)/t)},arity:A(1)},"normalize-l1":{evaluate:([e],r)=>{if(d(e,r),0===e.length)return[];const a=e.reduce((e,r)=>e+Math.abs(r),0);return 0===a?e.map(()=>0):e.map(e=>e/a)},arity:A(1)},"normalize-l2":{evaluate:([e],r)=>(d(e,r),P(e,r)),arity:A(1)},"normalize-log":{evaluate:([e],a)=>{if(d(e,a),0===e.length)return[];const t=Math.min(...e);if(t<=0)throw new r("Log normalization requires all values to be positive",a);return e.map(e=>Math.log(e/t))},arity:A(1)},angle:{evaluate:([e,a],t)=>{if(w(e,t),w(a,t),S(e)||S(a))throw new r("Cannot calculate angle with zero-length vector",t);if(e.length!==a.length)throw new r("Vectors must be of the same length",t);const n=e.reduce((e,r,t)=>e+r*a[t],0),l=Math.sqrt(e.reduce((e,r)=>e+r*r,0)),o=Math.sqrt(a.reduce((e,r)=>e+r*r,0));return Math.acos(n/(l*o))},arity:A(2)},projection:{evaluate:([e,a],t)=>{if(w(e,t),w(a,t),S(a))throw new r("Cannot project onto zero-length vector",t);if(e.length!==a.length)throw new r("Vectors must be of the same length",t);const n=e.reduce((e,r,t)=>e+r*a[t],0),l=Math.sqrt(a.reduce((e,r)=>e+r*r,0));return a.map(e=>n/l**2*e)},arity:A(2)},"orthogonal?":{evaluate:([e,a],t)=>{if(w(e,t),w(a,t),e.length!==a.length)throw new r("Vectors must be of the same length",t);return 0===e.reduce((e,r,t)=>e+r*a[t],0)},arity:A(2)},"parallel?":{evaluate:([e,a],t)=>{if(w(e,t),w(a,t),e.length!==a.length)throw new r("Vectors must be of the same length",t);return function(e,r){if(!T(e,r))return!1;for(let a=0;a<e.length;a++)if(!V(e[a])&&!V(r[a]))return Math.sign(e[a])===Math.sign(r[a]);return!0}(e,a)},arity:A(2)},"collinear?":{evaluate:([e,a],t)=>{if(w(e,t),w(a,t),e.length!==a.length)throw new r("Vectors must be of the same length",t);return T(e,a)},arity:A(2)},"cosine-similarity":{evaluate:([e,a],t)=>{if(w(e,t),w(a,t),S(e)||S(a))throw new r("Cannot calculate cosine similarity with zero-length vector",t);if(e.length!==a.length)throw new r("Vectors must be of the same length",t);return e.reduce((e,r,t)=>e+r*a[t],0)/(Math.sqrt(e.reduce((e,r)=>e+r*r,0))*Math.sqrt(a.reduce((e,r)=>e+r*r,0)))},arity:A(2)},"euclidean-distance":{evaluate:([e,a],t)=>{if(w(e,t),w(a,t),e.length!==a.length)throw new r("Vectors must be of the same length",t);return Math.sqrt(e.reduce((e,r,t)=>e+(r-a[t])**2,0))},arity:A(2)},"euclidean-norm":{evaluate:([e],r)=>(w(e,r),function(e){return Math.sqrt(e.reduce((e,r)=>e+r**2,0))}(e)),arity:A(1)},"manhattan-distance":{evaluate:([e,a],t)=>{if(w(e,t),w(a,t),e.length!==a.length)throw new r("Vectors must be of the same length",t);return e.reduce((e,r,t)=>e+Math.abs(r-a[t]),0)},arity:A(2)},"manhattan-norm":{evaluate:([e],r)=>(w(e,r),e.reduce((e,r)=>e+Math.abs(r),0)),arity:A(1)},"hamming-distance":{evaluate:([e,a],t)=>{if(w(e,t),w(a,t),e.length!==a.length)throw new r("Vectors must be of the same length",t);return e.reduce((e,r,t)=>e+(r!==a[t]?1:0),0)},arity:A(2)},"hamming-norm":{evaluate:([e],r)=>(w(e,r),e.reduce((e,r)=>e+(0!==r?1:0),0)),arity:A(1)},"chebyshev-distance":{evaluate:([e,a],t)=>{if(w(e,t),w(a,t),e.length!==a.length)throw new r("Vectors must be of the same length",t);return Math.max(...e.map((e,r)=>Math.abs(e-a[r])))},arity:A(2)},"chebyshev-norm":{evaluate:([e],r)=>(w(e,r),Math.max(...e.map(e=>Math.abs(e)))),arity:A(1)},"minkowski-distance":{evaluate:([e,a,t],n)=>{if(w(e,n),w(a,n),c(t,n,{finite:!0,positive:!0}),e.length!==a.length)throw new r("Vectors must be of the same length",n);return e.reduce((e,r,n)=>e+Math.abs(r-a[n])**t,0)**(1/t)},arity:A(3)},"minkowski-norm":{evaluate:([e,r],a)=>(w(e,a),c(r,a,{finite:!0,positive:!0}),e.reduce((e,a)=>e+Math.abs(a)**r,0)**(1/r)),arity:A(2)},cov:{evaluate:([e,a],t)=>{if(w(e,t),w(a,t),e.length!==a.length)throw new r("Vectors must be of the same length",t);return 1===e.length?0:j(e,a)},arity:A(2)},corr:{evaluate:([e,a],t)=>{if(d(e,t),d(a,t),e.length<=1)throw new r("Vectors must have at least 2 elements for corr",t);if(e.length!==a.length)throw new r("Vectors must be of the same length",t);const n=x(e),l=x(a);return e.reduce((e,r,t)=>e+(r-n)*(a[t]-l),0)/Math.sqrt(e.reduce((e,r)=>e+(r-n)**2,0)*a.reduce((e,r)=>e+(r-l)**2,0))},arity:A(2)},"spearman-corr":{evaluate:([e,a],t)=>{if(d(e,t),d(a,t),e.length<=1)throw new r("Vectors must have at least 2 elements for corr",t);if(e.length!==a.length)throw new r("Vectors must be of the same length",t);const n=q(e),l=q(a);try{return E(n,l)}catch(e){throw new r(e,t)}},arity:A(2)},"pearson-corr":{evaluate:([e,a],t)=>{if(d(e,t),d(a,t),e.length<=1)throw new r("Vectors must have at least 2 elements for pearson-corr",t);if(e.length!==a.length)throw new r("Vectors must be of the same length",t);try{return E(e,a)}catch(e){throw new r(e,t)}},arity:A(2)},"kendall-tau":{evaluate:([e,a],t)=>{if(d(e,t),d(a,t),e.length<2)throw new r("Vectors must have at least 2 elements for kendall-tau",t);if(e.length!==a.length)throw new r("Vectors must be of the same length",t);try{return function(e,r,a=1e-10){let t=0,n=0,l=0,o=0;for(let i=0;i<e.length;i++)for(let s=i+1;s<e.length;s++){const c=e[i]-e[s],m=r[i]-r[s],g=Math.abs(c)<a,u=Math.abs(m)<a;g&&u||(g?l+=1:u?o+=1:c*m>0?t+=1:n+=1)}const i=t+n+l,s=t+n+o;if(0===i||0===s)throw new Error("Not enough data to calculate Kendall's Tau");return(t-n)/Math.sqrt(i*s)}(e,a)}catch(e){throw new r(e,t)}},arity:A(2)},autocorrelation:{evaluate:([e,a],t)=>{if(d(e,t),e.length<2)throw new r("Vector must have at least 2 elements for autocorrelation",t);if(c(a,t,{integer:!0,lt:e.length,gt:-e.length}),0===a)return 1;const n=Math.abs(a),l=x(e);let o=0;const i=e.length;for(let r=0;r<i-n;r++){const t=a<0?r:r+n;o+=(e[a<0?r+n:r]-l)*(e[t]-l)}let s=0;for(let r=0;r<i;r++)s+=(e[r]-l)**2;return 0===s?0:o/s},arity:A(2)},"cross-correlation":{evaluate:([e,a,t],n)=>{if(d(e,n),d(a,n),e.length<2)throw new r("Vectors must have at least 2 elements",n);if(e.length!==a.length)throw new r("Vectors must be of the same length",n);if(c(t,n,{integer:!0,lt:e.length,gt:-e.length}),0===t&&e.length===a.length&&e.every((e,r)=>e===a[r]))return 1;const[l,o]=function(e,r,a){const t=Math.abs(a),n=e.length-t;let l=[],o=[];return a>=0?(l=e.slice(0,n),o=r.slice(a,a+n)):(l=e.slice(t),o=r.slice(0,n)),[l,o]}(e,a,t);return function(e,r){const a=x(e),t=x(r),n=N(e,a),l=N(r,t);return 0===n||0===l?0===n&&0===l&&a===t?1:0:j(e,r)/(n*l)}(l,o)},arity:A(3)},rref:{evaluate:([e],a)=>{!function(e,a){if(!z(e))throw new r(`Expected a matrix, but got ${e}`,a)}(e,a);const[t]=$(e);return t},arity:A(1)},solve:{evaluate:([e,a],t)=>{if(function(e,a){if(!z(e))throw new r(`Expected a matrix, but got ${e}`,a);if(e.length!==e[0].length)throw new r(`Expected square matrix, but got ${e.length} and ${e[0].length}`,a)}(e,t),d(a,t),e.length!==a.length)throw new r(`The number of rows in the matrix must be equal to the length of the vector, but got ${e.length} and ${a.length}`,t);return function(e,r){const a=e.length,t=e.map((e,a)=>[...e,r[a]]),[n]=$(t);for(let e=0;e<a;e+=1)if(V(n[e][e]))return null;const l=Array.from({length:a},()=>0);for(let e=a-1;e>=0;e--){let r=0;for(let t=e+1;t<a;t++)r+=n[e][t]*l[t];l[e]=(n[e][a]-r)/n[e][e]}return l}(e,a)},arity:A(2)},"to-polar":{evaluate:([e],r)=>{if(f(e,r),S(e))return[0,0];return[Math.sqrt(e[0]**2+e[1]**2),Math.atan2(e[1],e[0])]},arity:A(1)},"from-polar":{evaluate:([e],r)=>{f(e,r);const[a,t]=e;return 0===a?[0,0]:[a*Math.cos(t),a*Math.sin(t)]},arity:A(1)}};for(const[e,r]of Object.entries(M))L[e]&&(L[e].docs=r);const F={name:"linear-algebra",functions:L};export{F as linearAlgebraModule};
1
+ function e(e){if(!e.position||!e.code)return"";const r=e.position.column-1,a=e.code.length-r-1;return`${" ".repeat(Math.max(r,0))}^${" ".repeat(Math.max(a,0))}`}class r extends Error{sourceCodeInfo;shortMessage;constructor(a,t){const n=a instanceof Error?a.message:`${a}`;super(function(r,a){if(!a)return r;const t=`${a.position.line}:${a.position.column}`;return`${r}${a.filePath?`\n${a.filePath}:${t}`:`\nLocation ${t}`}\n${a.code}\n${e(a)}`}(n,t)),this.shortMessage=n,this.sourceCodeInfo=t,Object.setPrototypeOf(this,r.prototype),this.name="LitsError"}getCodeMarker(){return this.sourceCodeInfo&&e(this.sourceCodeInfo)}}const a={Number:1,String:2,NormalExpression:3,SpecialExpression:4,UserDefinedSymbol:5,NormalBuiltinSymbol:6,SpecialBuiltinSymbol:7,ReservedSymbol:8,Binding:9,Spread:10},t=new Set(Object.values(a));const n=new Set(["UserDefined","Partial","Comp","Constantly","Juxt","Complement","EveryPred","SomePred","Fnull","Builtin","SpecialBuiltin","NativeJsFunction","Module"]);function l(e){return null!==e&&"object"==typeof e&&("^^fn^^"in e&&"functionType"in e&&("string"==typeof(r=e.functionType)&&n.has(r)));var r}function o(e){return!(!Array.isArray(e)||e.length<2)&&("number"==typeof(r=e[0])&&t.has(r));var r}function i(e){return l(e)?`<function ${e.name||"λ"}>`:o(e)?`${r=e[0],Object.keys(a).find(e=>a[e]===r)}-node`:null===e?"null":"object"==typeof e&&e instanceof RegExp?`${e}`:"object"==typeof e&&e instanceof Error?e.toString():JSON.stringify(e);var r}function s(e,r={}){return"number"==typeof e&&(!Number.isNaN(e)&&(!(r.integer&&!Number.isInteger(e))&&(!(r.finite&&!Number.isFinite(e))&&((!r.zero||0===e)&&((!r.nonZero||0!==e)&&(!(r.positive&&e<=0)&&(!(r.negative&&e>=0)&&(!(r.nonPositive&&e>0)&&(!(r.nonNegative&&e<0)&&(!("number"==typeof r.gt&&e<=r.gt)&&(!("number"==typeof r.gte&&e<r.gte)&&(!("number"==typeof r.lt&&e>=r.lt)&&!("number"==typeof r.lte&&e>r.lte)))))))))))))}function c(e,a,t={}){if(!s(e,t))throw new r(`Expected ${function(e){if(e.zero)return"zero";const r=function(e){return e.positive?"positive":e.negative?"negative":e.nonNegative?"non negative":e.nonPositive?"non positive":e.nonZero?"non zero":""}(e),a=e.integer?"integer":"number",t=e.finite?"finite":"",n=function(e){return"number"!=typeof e.gt&&"number"!=typeof e.gte||"number"!=typeof e.lt&&"number"!=typeof e.lte?"number"==typeof e.gt||"number"==typeof e.gte?"number"==typeof e.gt?`n > ${e.gt}`:`n >= ${e.gte}`:"number"==typeof e.lt||"number"==typeof e.lte?"number"==typeof e.lt?`n < ${e.lt}`:`n <= ${e.lte}`:"":`${"number"==typeof e.gt?`${e.gt} < n `:`${e.gte} <= n `}${"number"==typeof e.lt?`< ${e.lt}`:`<= ${e.lte}`}`}(e);return[r,t,a,n].filter(e=>!!e).join(" ")}(t)}, got ${i(e)}.`,function(e,r){return e?.sourceCodeInfo??r}(e,a))}const m=new WeakSet,g=new WeakSet,u=new WeakSet,b=new WeakSet,p=new WeakSet,h=new WeakSet;function v(e){return!!Array.isArray(e)&&(!!g.has(e)||!u.has(e)&&(e.every(e=>s(e))?(m.add(e),g.add(e),!0):(u.add(e),!1)))}function d(e,a){if(!v(e))throw new r(`Expected a vector, but got ${e}`,a)}function f(e,a){if(!function(e){return!!v(e)&&2===e.length}(e))throw new r(`Expected a 2d vector, but got ${e}`,a)}function y(e,a){if(!function(e){return!!v(e)&&3===e.length}(e))throw new r(`Expected a 3d vector, but got ${e}`,a)}function w(e,a){if(d(e,a),0===e.length)throw new r(`Expected a non empty vector, but got ${e}`,a)}function z(e){if(!Array.isArray(e))return!1;if(b.has(e))return!0;if(p.has(e))return!1;if(0===e.length)return p.add(e),!1;if(!Array.isArray(e[0])||0===e[0].length)return p.add(e),!1;const r=e[0].length;for(const a of e)if(!Array.isArray(a)||a.length!==r||a.some(e=>!s(e)))return p.add(e),!1;return m.add(e),h.add(e),b.add(e),!0}function x(e){if(0===e.length)return 0;return e.reduce((e,r)=>e+r,0)/e.length}function k(e){const r=[...e].sort((e,r)=>e-r),a=Math.floor(r.length/2);return r.length%2==0?(r[a-1]+r[a])/2:r[a]}function N(e,r){const a=function(e,r){const a=r??x(e);return e.reduce((e,r)=>e+(r-a)**2,0)/e.length}(e,r);return Math.sqrt(a)}function A(e){return{min:e,max:e}}const M={reflect:{category:"linear-algebra",description:"Reflects a vector across a given axis.",returns:{type:"vector"},args:{a:{type:"vector",description:"Vector to reflect."},b:{type:"vector",description:"Axis of reflection."}},variants:[{argumentNames:["a","b"]}],examples:["let { reflect } = import(linear-algebra);\nreflect([1, 2], [0, 1])","let { reflect } = import(linear-algebra);\nreflect([1, 2, 3], [0, 0, 1])"],seeAlso:["linear-algebra.refract","linear-algebra.projection"]},refract:{category:"linear-algebra",description:"Refracts a vector across a given axis.",returns:{type:"vector"},args:{vector:{type:"vector",description:"Vector to refract."},axis:{type:"vector",description:"Axis of refraction."},eta:{type:"number",description:"Refraction index."}},variants:[{argumentNames:["vector","axis","eta"]}],examples:["let { refract } = import(linear-algebra);\nrefract([1, 2], [0, 1], 1.5)","let { refract } = import(linear-algebra);\nrefract([1, 2, 3], [0, 0, 1], 1.5)"],seeAlso:["linear-algebra.reflect"]},lerp:{category:"linear-algebra",description:"Performs linear interpolation between two vectors.",returns:{type:"vector"},args:{a:{type:"vector",description:"Start vector."},b:{type:"vector",description:"End vector."},t:{type:"number",description:"Interpolation factor (0 to 1)."}},variants:[{argumentNames:["a","b","t"]}],examples:["let { lerp } = import(linear-algebra);\nlerp([1, 2], [3, 4], 0.5)","let { lerp } = import(linear-algebra);\nlerp([1, 2], [3, 4], 2)","let { lerp } = import(linear-algebra);\nlerp([1, 2], [3, 4], -1)","let { lerp } = import(linear-algebra);\nlerp([1, 2, 3], [4, 5, 6], 0.25)"],seeAlso:["linear-algebra.projection"]},rotate2d:{category:"linear-algebra",description:"Rotates a 2D vector by a given angle in radians.",returns:{type:"vector"},args:{a:{type:"vector",description:"Vector to rotate."},b:{type:"number",description:"Angle in b."}},variants:[{argumentNames:["a","b"]}],examples:["let { rotate2d } = import(linear-algebra);\nrotate2d([1, 0], PI / 2)","let { rotate2d } = import(linear-algebra);\nrotate2d([0, 1], PI)"],seeAlso:["linear-algebra.rotate3d","linear-algebra.angle"]},rotate3d:{category:"linear-algebra",description:"Rotates a 3D vector around a given axis by a given angle in radians.",returns:{type:"vector"},args:{v:{type:"vector",description:"Vector to rotate."},axis:{type:"vector",description:"Axis of rotation."},radians:{type:"number",description:"Angle in radians."}},variants:[{argumentNames:["v","axis","radians"]}],examples:["let { rotate3d } = import(linear-algebra);\nrotate3d([1, 0, 0], [0, 1, 0], PI / 2)","let { rotate3d } = import(linear-algebra);\nrotate3d([0, 1, 0], [1, 0, 0], PI)"],seeAlso:["linear-algebra.rotate2d","linear-algebra.angle"]},dot:{category:"linear-algebra",description:"Calculates the dot product of two vectors. The result is a scalar.",returns:{type:"number"},args:{a:{type:"vector",description:"First vector."},b:{type:"vector",description:"Second vector."}},variants:[{argumentNames:["a","b"]}],examples:["let { dot } = import(linear-algebra);\ndot([1, 2], [3, 4])","let { dot } = import(linear-algebra);\ndot([1, 2, 3], [4, 5, 6])"],seeAlso:["linear-algebra.cross","linear-algebra.cosine-similarity","linear-algebra.angle","linear-algebra.projection","linear-algebra.orthogonal?"]},cross:{category:"linear-algebra",description:"Calculates the cross product of two 3D vectors. The result is a vector perpendicular to both input vectors.",returns:{type:"vector"},args:{a:{type:"vector",description:"First vector (3D)."},b:{type:"vector",description:"Second vector (3D)."}},variants:[{argumentNames:["a","b"]}],examples:["let { cross } = import(linear-algebra);\ncross([1, 2, 3], [4, 5, 6])","let { cross } = import(linear-algebra);\ncross([1, 0, 0], [0, 1, 0])","let { cross } = import(linear-algebra);\ncross([0, 0, 1], [1, 0, 0])","let { cross } = import(linear-algebra);\ncross([1, 2, 3], [0, 0, 0])","let { cross } = import(linear-algebra);\ncross([0, 0, 0], [1, 2, 3])"],seeAlso:["linear-algebra.dot"]},"normalize-minmax":{category:"linear-algebra",description:"Normalizes the vector using min-max normalization. The result is a vector with values between 0 and 1.",returns:{type:"number"},args:{v:{type:"vector",description:"Vector to normalize."}},variants:[{argumentNames:["v"]}],examples:["let { normalize-minmax } = import(linear-algebra);\nnormalize-minmax([1, 2, 3])","let { normalize-minmax } = import(linear-algebra);\nnormalize-minmax([1, 2, -3])","let { normalize-minmax } = import(linear-algebra);\nnormalize-minmax([1, 2, 3, 4])","let { normalize-minmax } = import(linear-algebra);\nnormalize-minmax([1, 2, -3, 4])","let { normalize-minmax } = import(linear-algebra);\nnormalize-minmax([1, 2, 3, 40, 50])"],seeAlso:["linear-algebra.normalize-zscore","linear-algebra.normalize-robust","linear-algebra.normalize-l1","linear-algebra.normalize-l2","linear-algebra.normalize-log"]},"normalize-zscore":{category:"linear-algebra",description:"Normalizes the vector using z-score normalization. The result is a vector with mean 0 and standard deviation 1.",returns:{type:"number"},args:{v:{type:"vector",description:"Vector to normalize."}},variants:[{argumentNames:["v"]}],examples:["let { normalize-zscore } = import(linear-algebra);\nnormalize-zscore([1, 2, 3])","let { normalize-zscore } = import(linear-algebra);\nnormalize-zscore([1, 2, -3])","let { normalize-zscore } = import(linear-algebra);\nnormalize-zscore([1, 2, 3, 4])","let { normalize-zscore } = import(linear-algebra);\nnormalize-zscore([1, 2, -3, 4])","let { normalize-zscore } = import(linear-algebra);\nnormalize-zscore([1, 2, 3, 40, 50])"],seeAlso:["linear-algebra.normalize-minmax","linear-algebra.normalize-robust","linear-algebra.normalize-l1","linear-algebra.normalize-l2","linear-algebra.normalize-log"]},"normalize-robust":{category:"linear-algebra",description:"Normalizes the vector using robust normalization. The result is a vector with median 0 and median absolute deviation 1.",returns:{type:"number"},args:{v:{type:"vector",description:"Vector to normalize."}},variants:[{argumentNames:["v"]}],examples:["let { normalize-robust } = import(linear-algebra);\nnormalize-robust([1, 2, 3])","let { normalize-robust } = import(linear-algebra);\nnormalize-robust([1, 2, -3])","let { normalize-robust } = import(linear-algebra);\nnormalize-robust([1, 2, 3, 4])","let { normalize-robust } = import(linear-algebra);\nnormalize-robust([1, 2, -3, 4])","let { normalize-robust } = import(linear-algebra);\nnormalize-robust([1, 2, 3, 40, 50])"],seeAlso:["linear-algebra.normalize-minmax","linear-algebra.normalize-zscore"]},"normalize-l1":{category:"linear-algebra",description:"Normalizes the vector using L1 normalization. The result is a vector with L1 norm equal to 1.",returns:{type:"number"},args:{v:{type:"vector",description:"Vector to normalize."}},variants:[{argumentNames:["v"]}],examples:["let { normalize-l1 } = import(linear-algebra);\nnormalize-l1([1, 2, 3])","let { normalize-l1 } = import(linear-algebra);\nnormalize-l1([1, 2, -3])","let { normalize-l1 } = import(linear-algebra);\nnormalize-l1([1, 2, 3, 4])","let { normalize-l1 } = import(linear-algebra);\nnormalize-l1([1, 2, -3, 4])","let { normalize-l1 } = import(linear-algebra);\nnormalize-l1([1, 2, 3, 40, 50])"],seeAlso:["linear-algebra.normalize-l2","linear-algebra.normalize-minmax","linear-algebra.manhattan-norm","linear-algebra.normalize-zscore"]},"normalize-l2":{category:"linear-algebra",description:"Normalizes the vector using L2 normalization. The result is a vector with L2 norm equal to 1.",returns:{type:"number"},args:{v:{type:"vector",description:"Vector to normalize."}},variants:[{argumentNames:["v"]}],examples:["let { normalize-l2 } = import(linear-algebra);\nnormalize-l2([1, 2, 3])","let { normalize-l2 } = import(linear-algebra);\nnormalize-l2([1, 2, 3])","let { normalize-l2 } = import(linear-algebra);\nnormalize-l2([1, 2, -3])","let { normalize-l2 } = import(linear-algebra);\nnormalize-l2([1, 2, 3, 4])","let { normalize-l2 } = import(linear-algebra);\nnormalize-l2([1, 2, -3, 4])","let { normalize-l2 } = import(linear-algebra);\nnormalize-l2([1, 2, 3, 40, 50])"],seeAlso:["linear-algebra.normalize-l1","linear-algebra.normalize-minmax","linear-algebra.euclidean-norm","linear-algebra.normalize-zscore"]},"normalize-log":{category:"linear-algebra",description:"Normalizes the vector using natural log normalization. The result is a vector with log-transformed values.",returns:{type:"number"},args:{v:{type:"vector",description:"Vector to normalize."}},variants:[{argumentNames:["v"]}],examples:["let { normalize-log } = import(linear-algebra);\nnormalize-log([1, 2, 3])","let { normalize-log } = import(linear-algebra);\nnormalize-log([1, 2, 3, 4])","let { normalize-log } = import(linear-algebra);\nnormalize-log([1, 2, 3, 40, 50])"],seeAlso:["linear-algebra.normalize-minmax","linear-algebra.normalize-zscore"]},angle:{category:"linear-algebra",description:"Calculates the **angle** between two vectors in radians.",returns:{type:"number"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { angle } = import(linear-algebra);\nangle([1, 0], [0, 1])","let { angle } = import(linear-algebra);\nangle([1, 0, 1], [0, 1, 0])"],seeAlso:["linear-algebra.dot","linear-algebra.collinear?","linear-algebra.orthogonal?","linear-algebra.rotate2d","linear-algebra.rotate3d","linear-algebra.parallel?","linear-algebra.cosine-similarity","linear-algebra.to-polar"]},projection:{category:"linear-algebra",description:"Calculates the **projection** of vector `a` onto vector `b`.",returns:{type:"vector"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { projection } = import(linear-algebra);\nprojection([1, 2], [3, 4])","let { projection } = import(linear-algebra);\nprojection([1, 2, 3], [4, 5, 6])"],seeAlso:["linear-algebra.dot","linear-algebra.reflect","linear-algebra.lerp"]},"collinear?":{category:"linear-algebra",description:"Checks if two vectors are **collinear**.",returns:{type:"boolean"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { collinear? } = import(linear-algebra);\ncollinear?([1, 2], [2, 4])","let { collinear? } = import(linear-algebra);\ncollinear?([1, 2], [-2, -4])","let { collinear? } = import(linear-algebra);\ncollinear?([1, 2, 3], [2, 4, 6])"],seeAlso:["linear-algebra.parallel?","linear-algebra.orthogonal?","linear-algebra.angle"]},"parallel?":{category:"linear-algebra",description:"Checks if two vectors are **parallel**.",returns:{type:"boolean"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { parallel? } = import(linear-algebra);\nparallel?([1, 2], [2, 4])","let { parallel? } = import(linear-algebra);\nparallel?([1, 2], [-2, -4])","let { parallel? } = import(linear-algebra);\nparallel?([1, 2, 3], [2, 4, 6])","let { parallel? } = import(linear-algebra);\nparallel?([1, 2], [3, 4])"],seeAlso:["linear-algebra.collinear?","linear-algebra.orthogonal?","linear-algebra.angle"]},"orthogonal?":{category:"linear-algebra",description:"Checks if two vectors are **orthogonal**.",returns:{type:"boolean"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { orthogonal? } = import(linear-algebra);\northogonal?([1, 0], [0, 1])","let { orthogonal? } = import(linear-algebra);\northogonal?([1, 0, 1], [0, 1, 0])","let { orthogonal? } = import(linear-algebra);\northogonal?([1, 2], [2, -1])"],seeAlso:["linear-algebra.collinear?","linear-algebra.parallel?","linear-algebra.dot","matrix.orthogonal-matrix?","linear-algebra.angle"]},"cosine-similarity":{category:"linear-algebra",description:"Calculates the **cosine similarity** between two vectors. The result is a value between -1 and 1.",returns:{type:"number"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { cosine-similarity } = import(linear-algebra);\ncosine-similarity([1, 2], [3, 4])","let { cosine-similarity } = import(linear-algebra);\ncosine-similarity([1, 2, 3], [4, 5, 6])","let { cosine-similarity } = import(linear-algebra);\ncosine-similarity([1, 0], [0, 1])"],seeAlso:["linear-algebra.dot","linear-algebra.angle","linear-algebra.euclidean-distance"]},"euclidean-distance":{category:"linear-algebra",description:"Calculates the **Euclidean distance** between two vectors. The result is a non-negative number.",returns:{type:"number"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { euclidean-distance } = import(linear-algebra);\neuclidean-distance([1, 2], [3, 4])","let { euclidean-distance } = import(linear-algebra);\neuclidean-distance([1, 2, 3], [4, 5, 6])","let { euclidean-distance } = import(linear-algebra);\neuclidean-distance([1, 0], [0, 1])"],seeAlso:["linear-algebra.manhattan-distance","linear-algebra.chebyshev-distance","linear-algebra.minkowski-distance","linear-algebra.euclidean-norm","linear-algebra.cosine-similarity","linear-algebra.hamming-distance"]},"euclidean-norm":{category:"linear-algebra",description:"Calculates the **Euclidean norm** (L2 norm) of a vector. The result is a non-negative number.",returns:{type:"number"},args:{v:{type:"vector",description:"Vector to calculate the norm for."}},variants:[{argumentNames:["v"]}],examples:["let { euclidean-norm } = import(linear-algebra);\neuclidean-norm([1, 2])","let { euclidean-norm } = import(linear-algebra);\neuclidean-norm([3, 4])","let { euclidean-norm } = import(linear-algebra);\neuclidean-norm([1, 2, 3])"],seeAlso:["linear-algebra.manhattan-norm","linear-algebra.chebyshev-norm","linear-algebra.minkowski-norm","linear-algebra.euclidean-distance","linear-algebra.normalize-l2","linear-algebra.hamming-norm"]},"manhattan-distance":{category:"linear-algebra",description:"Calculates the **Manhattan distance** between two vectors. The result is a non-negative number.",returns:{type:"number"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { manhattan-distance } = import(linear-algebra);\nmanhattan-distance([1, 2], [3, 4])","let { manhattan-distance } = import(linear-algebra);\nmanhattan-distance([1, 2, 3], [4, 5, 6])","let { manhattan-distance } = import(linear-algebra);\nmanhattan-distance([1, 0], [0, 1])"],seeAlso:["linear-algebra.euclidean-distance","linear-algebra.chebyshev-distance","linear-algebra.minkowski-distance","linear-algebra.manhattan-norm","linear-algebra.hamming-distance"]},"manhattan-norm":{category:"linear-algebra",description:"Calculates the **Manhattan norm** (L1 norm) of a vector. The result is a non-negative number.",returns:{type:"number"},args:{v:{type:"vector",description:"Vector to calculate the norm for."}},variants:[{argumentNames:["v"]}],examples:["let { manhattan-norm } = import(linear-algebra);\nmanhattan-norm([1, 2])","let { manhattan-norm } = import(linear-algebra);\nmanhattan-norm([3, 4])","let { manhattan-norm } = import(linear-algebra);\nmanhattan-norm([1, 2, 3])"],seeAlso:["linear-algebra.euclidean-norm","linear-algebra.chebyshev-norm","linear-algebra.minkowski-norm","linear-algebra.manhattan-distance","linear-algebra.normalize-l1","linear-algebra.hamming-norm"]},"hamming-distance":{category:"linear-algebra",description:"Calculates the **Hamming distance** between two vectors. The result is a non-negative integer.",returns:{type:"integer"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { hamming-distance } = import(linear-algebra);\nhamming-distance([1, 2], [3, 4])","let { hamming-distance } = import(linear-algebra);\nhamming-distance([1, 2, 3], [4, 5, 6])","let { hamming-distance } = import(linear-algebra);\nhamming-distance([1, 0], [0, 1])"],seeAlso:["linear-algebra.euclidean-distance","linear-algebra.manhattan-distance","linear-algebra.hamming-norm"]},"hamming-norm":{category:"linear-algebra",description:"Calculates the **Hamming norm** of a vector. The result is a non-negative integer.",returns:{type:"integer"},args:{v:{type:"vector",description:"Vector to calculate the norm for."}},variants:[{argumentNames:["v"]}],examples:["let { hamming-norm } = import(linear-algebra);\nhamming-norm([1, 2])","let { hamming-norm } = import(linear-algebra);\nhamming-norm([3, 4])","let { hamming-norm } = import(linear-algebra);\nhamming-norm([1, 2, 3])"],seeAlso:["linear-algebra.euclidean-norm","linear-algebra.manhattan-norm","linear-algebra.hamming-distance"]},"chebyshev-distance":{category:"linear-algebra",description:"Calculates the **Chebyshev distance** between two vectors. The result is a non-negative number.",returns:{type:"number"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { chebyshev-distance } = import(linear-algebra);\nchebyshev-distance([1, 2], [3, 4])","let { chebyshev-distance } = import(linear-algebra);\nchebyshev-distance([1, 2, 3], [4, 5, 6])","let { chebyshev-distance } = import(linear-algebra);\nchebyshev-distance([1, 0], [0, 1])"],seeAlso:["linear-algebra.euclidean-distance","linear-algebra.manhattan-distance","linear-algebra.minkowski-distance","linear-algebra.chebyshev-norm"]},"chebyshev-norm":{category:"linear-algebra",description:"Calculates the **Chebyshev norm** of a vector. The result is a non-negative number.",returns:{type:"number"},args:{v:{type:"vector",description:"Vector to calculate the norm for."}},variants:[{argumentNames:["v"]}],examples:["let { chebyshev-norm } = import(linear-algebra);\nchebyshev-norm([1, 2])","let { chebyshev-norm } = import(linear-algebra);\nchebyshev-norm([3, 4])","let { chebyshev-norm } = import(linear-algebra);\nchebyshev-norm([1, 2, 3])"],seeAlso:["linear-algebra.euclidean-norm","linear-algebra.manhattan-norm","linear-algebra.minkowski-norm","linear-algebra.chebyshev-distance"]},"minkowski-distance":{category:"linear-algebra",description:"Calculates the **Minkowski distance** between two vectors. The result is a non-negative number.",returns:{type:"number"},args:{a:{type:"vector"},b:{type:"vector"},p:{type:"number",description:"Order of the norm (p)."}},variants:[{argumentNames:["a","b","p"]}],examples:["let { minkowski-distance } = import(linear-algebra);\nminkowski-distance([1, 2], [3, 4], 2)","let { minkowski-distance } = import(linear-algebra);\nminkowski-distance([1, 2, 3], [4, 5, 6], 3)","let { minkowski-distance } = import(linear-algebra);\nminkowski-distance([1, 0], [0, 1], 1)"],seeAlso:["linear-algebra.euclidean-distance","linear-algebra.manhattan-distance","linear-algebra.chebyshev-distance","linear-algebra.minkowski-norm"]},"minkowski-norm":{category:"linear-algebra",description:"Calculates the **Minkowski norm** of a vector. The result is a non-negative number.",returns:{type:"number"},args:{a:{type:"vector",description:"Vector to calculate the norm for."},b:{type:"number",description:"Order of the norm (p)."}},variants:[{argumentNames:["a","b"]}],examples:["let { minkowski-norm } = import(linear-algebra);\nminkowski-norm([1, 2], 2)","let { minkowski-norm } = import(linear-algebra);\nminkowski-norm([3, 4], 3)","let { minkowski-norm } = import(linear-algebra);\nminkowski-norm([1, 2, 3], 4)"],seeAlso:["linear-algebra.euclidean-norm","linear-algebra.manhattan-norm","linear-algebra.chebyshev-norm","linear-algebra.minkowski-distance"]},cov:{category:"linear-algebra",description:"Calculates the **covariance** between two vectors. The result is a number.",returns:{type:"number"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { cov } = import(linear-algebra);\ncov([1, 2], [3, 4])","let { cov } = import(linear-algebra);\ncov([1, 2, 3], [4, 5, 6])","let { cov } = import(linear-algebra);\ncov([1, 0], [0, 1])"],seeAlso:["linear-algebra.corr","linear-algebra.pearson-corr","vector.variance"]},corr:{category:"linear-algebra",description:"Calculates the **correlation** between two vectors. The result is a number between -1 and 1.",returns:{type:"number"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { corr } = import(linear-algebra);\ncorr([1, 2], [3, 4])","let { corr } = import(linear-algebra);\ncorr([1, 2, 3], [4, 5, 6])","let { corr } = import(linear-algebra);\ncorr([1, 0], [0, 1])"],seeAlso:["linear-algebra.cov","linear-algebra.pearson-corr","linear-algebra.spearman-corr","linear-algebra.kendall-tau","linear-algebra.autocorrelation","linear-algebra.cross-correlation"]},"spearman-corr":{category:"linear-algebra",description:"Calculates the **Spearman rank correlation** between two vectors. The result is a number between -1 and 1.",returns:{type:"number"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { spearman-corr } = import(linear-algebra);\nspearman-corr([1, 2], [3, 4])","let { spearman-corr } = import(linear-algebra);\nspearman-corr([1, 2, 3], [4, 5, 6])","let { spearman-corr } = import(linear-algebra);\nspearman-corr([1, 0], [0, 1])"],seeAlso:["linear-algebra.pearson-corr","linear-algebra.kendall-tau","linear-algebra.corr"]},"pearson-corr":{category:"linear-algebra",description:"Calculates the **Pearson correlation** between two vectors. The result is a number between -1 and 1.",returns:{type:"number"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { pearson-corr } = import(linear-algebra);\npearson-corr([1, 2], [3, 4])","let { pearson-corr } = import(linear-algebra);\npearson-corr([1, 2, 3], [4, 5, 6])","let { pearson-corr } = import(linear-algebra);\npearson-corr([1, 0], [0, 1])"],seeAlso:["linear-algebra.spearman-corr","linear-algebra.kendall-tau","linear-algebra.corr","linear-algebra.cov"]},"kendall-tau":{category:"linear-algebra",description:"Calculates the **Kendall Tau** rank correlation coefficient between two vectors. The result is a number between -1 and 1.",returns:{type:"number"},args:{a:{type:"vector"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { kendall-tau } = import(linear-algebra);\nkendall-tau([1, 2], [3, 4])","let { kendall-tau } = import(linear-algebra);\nkendall-tau([1, 2, 3], [4, 5, 6])","let { kendall-tau } = import(linear-algebra);\nkendall-tau([1, 0], [0, 1])"],seeAlso:["linear-algebra.spearman-corr","linear-algebra.pearson-corr","linear-algebra.corr"]},autocorrelation:{category:"linear-algebra",description:"Calculates the **autocorrelation** of a vector. The result is a vector of autocorrelation coefficients.",returns:{type:"vector"},args:{a:{type:"vector",description:"Vector to calculate the autocorrelation for."},b:{type:"integer",description:"Lag value for the autocorrelation."}},variants:[{argumentNames:["a","b"]}],examples:["let { autocorrelation } = import(linear-algebra);\nautocorrelation([1, 2, 3], -2)","let { autocorrelation } = import(linear-algebra);\nautocorrelation([1, 2, 3], -1)","let { autocorrelation } = import(linear-algebra);\nautocorrelation([1, 2, 3], 0)","let { autocorrelation } = import(linear-algebra);\nautocorrelation([1, 2, 3], 1)","let { autocorrelation } = import(linear-algebra);\nautocorrelation([1, 2, 3], 2)"],seeAlso:["linear-algebra.cross-correlation","linear-algebra.corr"]},"cross-correlation":{category:"linear-algebra",description:"Calculates the **cross-correlation** between two vectors. The result is a vector of cross-correlation coefficients.",returns:{type:"vector"},args:{a:{type:"vector"},b:{type:"vector"},lag:{type:"integer",description:"Lag value for the cross-correlation."}},variants:[{argumentNames:["a","b","lag"]}],examples:["let { cross-correlation } = import(linear-algebra);\ncross-correlation([1, 2, 3], [4, 5, 6], -2)","let { cross-correlation } = import(linear-algebra);\ncross-correlation([1, 2, 3], [4, 5, 6], -1)","let { cross-correlation } = import(linear-algebra);\ncross-correlation([1, 2, 3], [4, 5, 6], 0)","let { cross-correlation } = import(linear-algebra);\ncross-correlation([1, 2, 3], [4, 5, 6], 1)","let { cross-correlation } = import(linear-algebra);\ncross-correlation([1, 2, 3], [4, 5, 6], 2)"],seeAlso:["linear-algebra.autocorrelation","linear-algebra.corr"]},rref:{category:"linear-algebra",description:"Calculates the **Reduced Row Echelon Form** (RREF) of a matrix.",returns:{type:"matrix"},args:{m:{type:"matrix",description:"Matrix to calculate the RREF for."}},variants:[{argumentNames:["m"]}],examples:["let { rref } = import(linear-algebra);\nrref([[1, 2], [3, 4]])","let { rref } = import(linear-algebra);\nrref([[1, 2, 3], [4, 5, 6], [7, 8, 9]])","let { rref } = import(linear-algebra);\nrref([[1, 2, 3], [7, 8, 9], [4, 5, 7]])"],seeAlso:["linear-algebra.solve","matrix.rank"]},solve:{category:"linear-algebra",description:"Solves a system of linear equations represented by a matrix and a vector.",returns:{type:"vector"},args:{a:{type:"matrix"},b:{type:"vector"}},variants:[{argumentNames:["a","b"]}],examples:["let { solve } = import(linear-algebra);\nsolve([\n [2, 1, -1, 1], \n [4, 5, -3, 2], \n [6, -2, 5, -3], \n [8, 3, 2, 4]\n], [5, 10, 2, 17])","let { solve } = import(linear-algebra);\nsolve([[2, 0, 0], [3, 1, 0], [4, 5, 6]], [4, 5, 38])","let { solve } = import(linear-algebra);\nsolve([[2, 3], [1, -1]], [8, 2])"],seeAlso:["linear-algebra.rref","matrix.inv"]},"to-polar":{category:"linear-algebra",description:"Converts a 2D vector to polar coordinates.",returns:{type:"vector"},args:{vector:{type:"vector",description:"2D Vector to convert."}},variants:[{argumentNames:["vector"]}],examples:["let { to-polar } = import(linear-algebra);\nto-polar([1, 2])","let { to-polar } = import(linear-algebra);\nto-polar([3, 4])"],seeAlso:["linear-algebra.from-polar","linear-algebra.angle"]},"from-polar":{category:"linear-algebra",description:"Converts polar coordinates to a 2D vector.",returns:{type:"vector"},args:{polar:{type:"vector",description:"Polar coordinates to convert."}},variants:[{argumentNames:["polar"]}],examples:["let { from-polar } = import(linear-algebra);\nfrom-polar([1, PI / 4])","let { from-polar } = import(linear-algebra);\nfrom-polar([1, 0])","let { from-polar } = import(linear-algebra);\nfrom-polar([1, -PI / 2])"],seeAlso:["linear-algebra.to-polar"]}};function C(e,r,a=1e-10){if(e===r)return!0;const t=Math.abs(e-r);if(0===e||0===r||t<a)return t<a;return t/(Math.abs(e)+Math.abs(r))<a}function V(e){return Math.abs(e)<1e-10}function $(e){const r=e.map(e=>[...e]),a=r.length,t=r[0].length;let n=0,l=0;for(let e=0;e<t;e++){let o=-1;for(let t=l;t<a;t++)if(!V(r[t][e])){o=t;break}if(-1===o)continue;n+=1,o!==l&&([r[o],r[l]]=[r[l],r[o]]);const i=r[l][e];for(let a=e;a<t;a++)r[l][a]/=i;for(let n=0;n<a;n++)if(n!==l&&!V(r[n][e])){const a=r[n][e];for(let o=e;o<t;o++)r[n][o]-=a*r[l][o]}if(l++,l===a)break}return[r,n]}function T(e,r){const a=e=>e.every(e=>V(e));if(a(e)||a(r))return!0;let t=0;for(;t<e.length&&V(e[t]);)t++;const n=r[t]/e[t];for(let a=0;a<e.length;a++)if(!V(e[a])||!V(r[a])){if(V(e[a]))return!1;if(!C(r[a]/e[a],n))return!1}return!0}function S(e){return e.every(e=>V(e))}function E(e,r){const a=x(e),t=x(r);let n=0,l=0,o=0;for(let i=0;i<e.length;i++){const s=e[i]-a,c=r[i]-t;n+=s*c,l+=s*s,o+=c*c}if(0===l||0===o)throw new Error("Cannot calculate Pearson correlation coefficient: one of the vectors has zero variance.");return n/(Math.sqrt(l)*Math.sqrt(o))}function q(e){const r=[...e.keys()].sort((r,a)=>e[r]-e[a]),a=Array.from({length:e.length}).fill(0);let t=1,n=0;for(;n<r.length;){const l=e[r[n]];let o=n;for(;o<r.length&&e[r[o]]===l;)o++;const i=t+(o-n-1)/2;for(let e=n;e<o;e++)a[r[e]]=i;t+=o-n,n=o}return a}function j(e,r){const a=x(e),t=x(r);let n=0;for(let l=0;l<e.length;l++)n+=(e[l]-a)*(r[l]-t);return n/e.length}function P(e,a){if(0===e.length)return e;const t=Math.sqrt(e.reduce((e,r)=>e+r**2,0));if(V(t))throw new r("The vector must not be zero",a);return e.map(e=>e/t)}function R(e,r){return e.reduce((e,a,t)=>e+a*r[t],0)}function I(e,r){return e.map((e,a)=>e-r[a])}function D(e,r){return e.map(e=>e*r)}const L={rotate2d:{evaluate:([e,r],a)=>{if(f(e,a),S(e))return e;c(r,a,{finite:!0});const t=Math.cos(r),n=Math.sin(r);return[e[0]*t-e[1]*n,e[0]*n+e[1]*t]},arity:A(2)},rotate3d:{evaluate:([e,a,t],n)=>{if(y(e,n),S(e))return e;if(c(t,n,{finite:!0}),y(a,n),S(a))throw new r("Rotation axis must not be zero",n);const l=Math.cos(t),o=Math.sin(t),[i,s,m]=P(a,n),g=e[0]*i+e[1]*s+e[2]*m;return[g*i*(1-l)+e[0]*l+(-m*e[1]+s*e[2])*o,g*s*(1-l)+e[1]*l+(m*e[0]-i*e[2])*o,g*m*(1-l)+e[2]*l+(-s*e[0]+i*e[1])*o]},arity:A(3)},reflect:{evaluate:([e,a],t)=>{if(d(e,t),d(a,t),e.length!==a.length)throw new r("Vectors must be of the same length",t);if(S(a))throw new r("Reflection normal must not be zero",t);if(S(e))return e;const n=P(a,t);return I(e,D(n,2*R(e,n)))},arity:A(2)},refract:{evaluate:([e,a,t],n)=>{if(d(e,n),d(a,n),c(t,n,{finite:!0,positive:!0}),e.length!==a.length)throw new r("Vectors must be of the same length",n);if(S(a))throw new r("Refraction normal must not be zero",n);if(S(e))return e;const l=P(e,n),o=P(a,n),i=R(l,o),s=1-t*t*(1-i*i);if(s<0)return e;return I(D(l,t),D(o,t*i+Math.sqrt(s)))},arity:A(3)},lerp:{evaluate:([e,a,t],n)=>{if(d(e,n),d(a,n),c(t,n,{finite:!0}),e.length!==a.length)throw new r("Vectors must be of the same length",n);return e.map((e,r)=>e+(a[r]-e)*t)},arity:A(3)},dot:{evaluate:([e,a],t)=>{if(d(e,t),d(a,t),e.length!==a.length)throw new r("Vectors must be of the same length",t);return R(e,a)},arity:A(2)},cross:{evaluate:([e,a],t)=>{if(d(e,t),d(a,t),3!==e.length||3!==a.length)throw new r("Cross product is only defined for 3D vectors",t);return[e[1]*a[2]-e[2]*a[1],e[2]*a[0]-e[0]*a[2],e[0]*a[1]-e[1]*a[0]]},arity:A(2)},"normalize-minmax":{evaluate:([e],r)=>{if(d(e,r),0===e.length)return[];const a=e.reduce((e,r)=>r<e?r:e,e[0]),t=e.reduce((e,r)=>r>e?r:e,e[0]);return a===t?e.map(()=>0):e.map(e=>(e-a)/(t-a))},arity:A(1)},"normalize-robust":{evaluate:([e],r)=>{if(d(e,r),0===e.length)return[];const a=k(e),t=function(e){const r=k(e);return 1.4826*k(e.map(e=>Math.abs(e-r)))}(e);return 0===t?e.map(e=>e-a):e.map(e=>(e-a)/t)},arity:A(1)},"normalize-zscore":{evaluate:([e],r)=>{d(e,r);const a=x(e),t=N(e);return 0===t?e.map(()=>0):e.map(e=>(e-a)/t)},arity:A(1)},"normalize-l1":{evaluate:([e],r)=>{if(d(e,r),0===e.length)return[];const a=e.reduce((e,r)=>e+Math.abs(r),0);return 0===a?e.map(()=>0):e.map(e=>e/a)},arity:A(1)},"normalize-l2":{evaluate:([e],r)=>(d(e,r),P(e,r)),arity:A(1)},"normalize-log":{evaluate:([e],a)=>{if(d(e,a),0===e.length)return[];const t=Math.min(...e);if(t<=0)throw new r("Log normalization requires all values to be positive",a);return e.map(e=>Math.log(e/t))},arity:A(1)},angle:{evaluate:([e,a],t)=>{if(w(e,t),w(a,t),S(e)||S(a))throw new r("Cannot calculate angle with zero-length vector",t);if(e.length!==a.length)throw new r("Vectors must be of the same length",t);const n=e.reduce((e,r,t)=>e+r*a[t],0),l=Math.sqrt(e.reduce((e,r)=>e+r*r,0)),o=Math.sqrt(a.reduce((e,r)=>e+r*r,0));return Math.acos(n/(l*o))},arity:A(2)},projection:{evaluate:([e,a],t)=>{if(w(e,t),w(a,t),S(a))throw new r("Cannot project onto zero-length vector",t);if(e.length!==a.length)throw new r("Vectors must be of the same length",t);const n=e.reduce((e,r,t)=>e+r*a[t],0),l=Math.sqrt(a.reduce((e,r)=>e+r*r,0));return a.map(e=>n/l**2*e)},arity:A(2)},"orthogonal?":{evaluate:([e,a],t)=>{if(w(e,t),w(a,t),e.length!==a.length)throw new r("Vectors must be of the same length",t);return 0===e.reduce((e,r,t)=>e+r*a[t],0)},arity:A(2)},"parallel?":{evaluate:([e,a],t)=>{if(w(e,t),w(a,t),e.length!==a.length)throw new r("Vectors must be of the same length",t);return function(e,r){if(!T(e,r))return!1;for(let a=0;a<e.length;a++)if(!V(e[a])&&!V(r[a]))return Math.sign(e[a])===Math.sign(r[a]);return!0}(e,a)},arity:A(2)},"collinear?":{evaluate:([e,a],t)=>{if(w(e,t),w(a,t),e.length!==a.length)throw new r("Vectors must be of the same length",t);return T(e,a)},arity:A(2)},"cosine-similarity":{evaluate:([e,a],t)=>{if(w(e,t),w(a,t),S(e)||S(a))throw new r("Cannot calculate cosine similarity with zero-length vector",t);if(e.length!==a.length)throw new r("Vectors must be of the same length",t);return e.reduce((e,r,t)=>e+r*a[t],0)/(Math.sqrt(e.reduce((e,r)=>e+r*r,0))*Math.sqrt(a.reduce((e,r)=>e+r*r,0)))},arity:A(2)},"euclidean-distance":{evaluate:([e,a],t)=>{if(w(e,t),w(a,t),e.length!==a.length)throw new r("Vectors must be of the same length",t);return Math.sqrt(e.reduce((e,r,t)=>e+(r-a[t])**2,0))},arity:A(2)},"euclidean-norm":{evaluate:([e],r)=>(w(e,r),function(e){return Math.sqrt(e.reduce((e,r)=>e+r**2,0))}(e)),arity:A(1)},"manhattan-distance":{evaluate:([e,a],t)=>{if(w(e,t),w(a,t),e.length!==a.length)throw new r("Vectors must be of the same length",t);return e.reduce((e,r,t)=>e+Math.abs(r-a[t]),0)},arity:A(2)},"manhattan-norm":{evaluate:([e],r)=>(w(e,r),e.reduce((e,r)=>e+Math.abs(r),0)),arity:A(1)},"hamming-distance":{evaluate:([e,a],t)=>{if(w(e,t),w(a,t),e.length!==a.length)throw new r("Vectors must be of the same length",t);return e.reduce((e,r,t)=>e+(r!==a[t]?1:0),0)},arity:A(2)},"hamming-norm":{evaluate:([e],r)=>(w(e,r),e.reduce((e,r)=>e+(0!==r?1:0),0)),arity:A(1)},"chebyshev-distance":{evaluate:([e,a],t)=>{if(w(e,t),w(a,t),e.length!==a.length)throw new r("Vectors must be of the same length",t);return Math.max(...e.map((e,r)=>Math.abs(e-a[r])))},arity:A(2)},"chebyshev-norm":{evaluate:([e],r)=>(w(e,r),Math.max(...e.map(e=>Math.abs(e)))),arity:A(1)},"minkowski-distance":{evaluate:([e,a,t],n)=>{if(w(e,n),w(a,n),c(t,n,{finite:!0,positive:!0}),e.length!==a.length)throw new r("Vectors must be of the same length",n);return e.reduce((e,r,n)=>e+Math.abs(r-a[n])**t,0)**(1/t)},arity:A(3)},"minkowski-norm":{evaluate:([e,r],a)=>(w(e,a),c(r,a,{finite:!0,positive:!0}),e.reduce((e,a)=>e+Math.abs(a)**r,0)**(1/r)),arity:A(2)},cov:{evaluate:([e,a],t)=>{if(w(e,t),w(a,t),e.length!==a.length)throw new r("Vectors must be of the same length",t);return 1===e.length?0:j(e,a)},arity:A(2)},corr:{evaluate:([e,a],t)=>{if(d(e,t),d(a,t),e.length<=1)throw new r("Vectors must have at least 2 elements for corr",t);if(e.length!==a.length)throw new r("Vectors must be of the same length",t);const n=x(e),l=x(a);return e.reduce((e,r,t)=>e+(r-n)*(a[t]-l),0)/Math.sqrt(e.reduce((e,r)=>e+(r-n)**2,0)*a.reduce((e,r)=>e+(r-l)**2,0))},arity:A(2)},"spearman-corr":{evaluate:([e,a],t)=>{if(d(e,t),d(a,t),e.length<=1)throw new r("Vectors must have at least 2 elements for corr",t);if(e.length!==a.length)throw new r("Vectors must be of the same length",t);const n=q(e),l=q(a);try{return E(n,l)}catch(e){throw new r(e,t)}},arity:A(2)},"pearson-corr":{evaluate:([e,a],t)=>{if(d(e,t),d(a,t),e.length<=1)throw new r("Vectors must have at least 2 elements for pearson-corr",t);if(e.length!==a.length)throw new r("Vectors must be of the same length",t);try{return E(e,a)}catch(e){throw new r(e,t)}},arity:A(2)},"kendall-tau":{evaluate:([e,a],t)=>{if(d(e,t),d(a,t),e.length<2)throw new r("Vectors must have at least 2 elements for kendall-tau",t);if(e.length!==a.length)throw new r("Vectors must be of the same length",t);try{return function(e,r,a=1e-10){let t=0,n=0,l=0,o=0;for(let i=0;i<e.length;i++)for(let s=i+1;s<e.length;s++){const c=e[i]-e[s],m=r[i]-r[s],g=Math.abs(c)<a,u=Math.abs(m)<a;g&&u||(g?l+=1:u?o+=1:c*m>0?t+=1:n+=1)}const i=t+n+l,s=t+n+o;if(0===i||0===s)throw new Error("Not enough data to calculate Kendall's Tau");return(t-n)/Math.sqrt(i*s)}(e,a)}catch(e){throw new r(e,t)}},arity:A(2)},autocorrelation:{evaluate:([e,a],t)=>{if(d(e,t),e.length<2)throw new r("Vector must have at least 2 elements for autocorrelation",t);if(c(a,t,{integer:!0,lt:e.length,gt:-e.length}),0===a)return 1;const n=Math.abs(a),l=x(e);let o=0;const i=e.length;for(let r=0;r<i-n;r++){const t=a<0?r:r+n;o+=(e[a<0?r+n:r]-l)*(e[t]-l)}let s=0;for(let r=0;r<i;r++)s+=(e[r]-l)**2;return 0===s?0:o/s},arity:A(2)},"cross-correlation":{evaluate:([e,a,t],n)=>{if(d(e,n),d(a,n),e.length<2)throw new r("Vectors must have at least 2 elements",n);if(e.length!==a.length)throw new r("Vectors must be of the same length",n);if(c(t,n,{integer:!0,lt:e.length,gt:-e.length}),0===t&&e.length===a.length&&e.every((e,r)=>e===a[r]))return 1;const[l,o]=function(e,r,a){const t=Math.abs(a),n=e.length-t;let l=[],o=[];return a>=0?(l=e.slice(0,n),o=r.slice(a,a+n)):(l=e.slice(t),o=r.slice(0,n)),[l,o]}(e,a,t);return function(e,r){const a=x(e),t=x(r),n=N(e,a),l=N(r,t);return 0===n||0===l?0===n&&0===l&&a===t?1:0:j(e,r)/(n*l)}(l,o)},arity:A(3)},rref:{evaluate:([e],a)=>{!function(e,a){if(!z(e))throw new r(`Expected a matrix, but got ${e}`,a)}(e,a);const[t]=$(e);return t},arity:A(1)},solve:{evaluate:([e,a],t)=>{if(function(e,a){if(!z(e))throw new r(`Expected a matrix, but got ${e}`,a);if(e.length!==e[0].length)throw new r(`Expected square matrix, but got ${e.length} and ${e[0].length}`,a)}(e,t),d(a,t),e.length!==a.length)throw new r(`The number of rows in the matrix must be equal to the length of the vector, but got ${e.length} and ${a.length}`,t);return function(e,r){const a=e.length,t=e.map((e,a)=>[...e,r[a]]),[n]=$(t);for(let e=0;e<a;e+=1)if(V(n[e][e]))return null;const l=Array.from({length:a},()=>0);for(let e=a-1;e>=0;e--){let r=0;for(let t=e+1;t<a;t++)r+=n[e][t]*l[t];l[e]=(n[e][a]-r)/n[e][e]}return l}(e,a)},arity:A(2)},"to-polar":{evaluate:([e],r)=>{if(f(e,r),S(e))return[0,0];return[Math.sqrt(e[0]**2+e[1]**2),Math.atan2(e[1],e[0])]},arity:A(1)},"from-polar":{evaluate:([e],r)=>{f(e,r);const[a,t]=e;return 0===a?[0,0]:[a*Math.cos(t),a*Math.sin(t)]},arity:A(1)}};for(const[e,r]of Object.entries(M))L[e]&&(L[e].docs=r);const F={name:"linear-algebra",functions:L};export{F as linearAlgebraModule};
2
2
  //# sourceMappingURL=linear-algebra.esm.js.map