@mojir/lits 2.3.1 → 2.4.0

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 (143) hide show
  1. package/README.md +18 -22
  2. package/dist/bundler.esm.js +2 -0
  3. package/dist/bundler.esm.js.map +1 -0
  4. package/dist/bundler.js +2 -0
  5. package/dist/bundler.js.map +1 -0
  6. package/dist/cli/cli/src/js-interop/Cli/Fs/index.d.ts +2 -2
  7. package/dist/cli/cli/src/js-interop/Cli/Proc/index.d.ts +2 -2
  8. package/dist/cli/cli/src/js-interop/Cli/index.d.ts +2 -3
  9. package/dist/cli/cli.js +2642 -2313
  10. package/dist/cli/reference/api.d.ts +3 -3
  11. package/dist/cli/reference/examples.d.ts +2 -2
  12. package/dist/cli/reference/index.d.ts +0 -1
  13. package/dist/cli/src/Lits/Lits.d.ts +6 -7
  14. package/dist/cli/src/builtin/index.d.ts +1 -1
  15. package/dist/cli/src/builtin/specialExpressionTypes.d.ts +15 -15
  16. package/dist/cli/src/builtin/specialExpressions/import.d.ts +6 -0
  17. package/dist/cli/src/bundler/index.d.ts +9 -0
  18. package/dist/cli/src/bundler/interface.d.ts +15 -0
  19. package/dist/cli/src/bundler.d.ts +3 -0
  20. package/dist/cli/src/evaluator/ContextStack.d.ts +10 -4
  21. package/dist/cli/src/index.d.ts +2 -0
  22. package/dist/cli/src/js-interop/Cli/Fs/index.d.ts +2 -2
  23. package/dist/cli/src/js-interop/Cli/Proc/index.d.ts +2 -2
  24. package/dist/cli/src/js-interop/Cli/index.d.ts +2 -3
  25. package/dist/cli/src/parser/ParserContext.d.ts +1 -1
  26. package/dist/cli/src/parser/getPrecedence.d.ts +3 -0
  27. package/dist/cli/src/parser/index.d.ts +2 -0
  28. package/dist/cli/src/parser/subParsers/parseExpression.d.ts +5 -0
  29. package/dist/cli/src/parser/types.d.ts +0 -3
  30. package/dist/cli/src/tokenizer/reservedNames.d.ts +0 -1
  31. package/dist/full.esm.js +1 -1
  32. package/dist/full.esm.js.map +1 -1
  33. package/dist/full.js +1 -1
  34. package/dist/full.js.map +1 -1
  35. package/dist/index.esm.js +1 -1
  36. package/dist/index.esm.js.map +1 -1
  37. package/dist/index.js +1 -1
  38. package/dist/index.js.map +1 -1
  39. package/dist/lits.iife.js +1 -1
  40. package/dist/lits.iife.js.map +1 -1
  41. package/dist/modules/assert.esm.js +1 -1
  42. package/dist/modules/assert.esm.js.map +1 -1
  43. package/dist/modules/assert.js +1 -1
  44. package/dist/modules/assert.js.map +1 -1
  45. package/dist/modules/bitwise.esm.js +1 -1
  46. package/dist/modules/bitwise.esm.js.map +1 -1
  47. package/dist/modules/bitwise.js +1 -1
  48. package/dist/modules/bitwise.js.map +1 -1
  49. package/dist/modules/cli/src/js-interop/Cli/Fs/index.d.ts +2 -2
  50. package/dist/modules/cli/src/js-interop/Cli/Proc/index.d.ts +2 -2
  51. package/dist/modules/cli/src/js-interop/Cli/index.d.ts +2 -3
  52. package/dist/modules/collection.esm.js +1 -1
  53. package/dist/modules/collection.esm.js.map +1 -1
  54. package/dist/modules/collection.js +1 -1
  55. package/dist/modules/collection.js.map +1 -1
  56. package/dist/modules/functional.esm.js +1 -1
  57. package/dist/modules/functional.esm.js.map +1 -1
  58. package/dist/modules/functional.js +1 -1
  59. package/dist/modules/functional.js.map +1 -1
  60. package/dist/modules/grid.esm.js +1 -1
  61. package/dist/modules/grid.esm.js.map +1 -1
  62. package/dist/modules/grid.js +1 -1
  63. package/dist/modules/grid.js.map +1 -1
  64. package/dist/modules/linear-algebra.esm.js +1 -1
  65. package/dist/modules/linear-algebra.esm.js.map +1 -1
  66. package/dist/modules/linear-algebra.js +1 -1
  67. package/dist/modules/linear-algebra.js.map +1 -1
  68. package/dist/modules/math.esm.js +1 -1
  69. package/dist/modules/math.esm.js.map +1 -1
  70. package/dist/modules/math.js +1 -1
  71. package/dist/modules/math.js.map +1 -1
  72. package/dist/modules/matrix.esm.js +1 -1
  73. package/dist/modules/matrix.esm.js.map +1 -1
  74. package/dist/modules/matrix.js +1 -1
  75. package/dist/modules/matrix.js.map +1 -1
  76. package/dist/modules/number-theory.esm.js +1 -1
  77. package/dist/modules/number-theory.esm.js.map +1 -1
  78. package/dist/modules/number-theory.js +1 -1
  79. package/dist/modules/number-theory.js.map +1 -1
  80. package/dist/modules/random.esm.js +1 -1
  81. package/dist/modules/random.esm.js.map +1 -1
  82. package/dist/modules/random.js +1 -1
  83. package/dist/modules/random.js.map +1 -1
  84. package/dist/modules/reference/api.d.ts +3 -3
  85. package/dist/modules/reference/index.d.ts +0 -1
  86. package/dist/modules/sequence.esm.js +1 -1
  87. package/dist/modules/sequence.esm.js.map +1 -1
  88. package/dist/modules/sequence.js +1 -1
  89. package/dist/modules/sequence.js.map +1 -1
  90. package/dist/modules/src/Lits/Lits.d.ts +6 -7
  91. package/dist/modules/src/builtin/index.d.ts +1 -1
  92. package/dist/modules/src/builtin/specialExpressionTypes.d.ts +15 -15
  93. package/dist/modules/src/builtin/specialExpressions/import.d.ts +6 -0
  94. package/dist/modules/src/bundler/index.d.ts +9 -0
  95. package/dist/modules/src/bundler/interface.d.ts +15 -0
  96. package/dist/modules/src/bundler.d.ts +3 -0
  97. package/dist/modules/src/evaluator/ContextStack.d.ts +10 -4
  98. package/dist/modules/src/index.d.ts +2 -0
  99. package/dist/modules/src/parser/ParserContext.d.ts +1 -1
  100. package/dist/modules/src/parser/getPrecedence.d.ts +3 -0
  101. package/dist/modules/src/parser/index.d.ts +2 -0
  102. package/dist/modules/src/parser/subParsers/parseExpression.d.ts +5 -0
  103. package/dist/modules/src/parser/types.d.ts +0 -3
  104. package/dist/modules/src/tokenizer/reservedNames.d.ts +0 -1
  105. package/dist/modules/string.esm.js +1 -1
  106. package/dist/modules/string.esm.js.map +1 -1
  107. package/dist/modules/string.js +1 -1
  108. package/dist/modules/string.js.map +1 -1
  109. package/dist/modules/vector.esm.js +1 -1
  110. package/dist/modules/vector.esm.js.map +1 -1
  111. package/dist/modules/vector.js +1 -1
  112. package/dist/modules/vector.js.map +1 -1
  113. package/dist/reference/api.d.ts +3 -3
  114. package/dist/reference/index.d.ts +0 -1
  115. package/dist/src/Lits/Lits.d.ts +6 -7
  116. package/dist/src/builtin/index.d.ts +1 -1
  117. package/dist/src/builtin/specialExpressionTypes.d.ts +15 -15
  118. package/dist/src/builtin/specialExpressions/import.d.ts +6 -0
  119. package/dist/src/bundler/index.d.ts +9 -0
  120. package/dist/src/bundler/interface.d.ts +15 -0
  121. package/dist/src/bundler.d.ts +3 -0
  122. package/dist/src/evaluator/ContextStack.d.ts +10 -4
  123. package/dist/src/index.d.ts +2 -0
  124. package/dist/src/parser/ParserContext.d.ts +1 -1
  125. package/dist/src/parser/getPrecedence.d.ts +3 -0
  126. package/dist/src/parser/index.d.ts +2 -0
  127. package/dist/src/parser/subParsers/parseExpression.d.ts +5 -0
  128. package/dist/src/parser/types.d.ts +0 -3
  129. package/dist/src/tokenizer/reservedNames.d.ts +0 -1
  130. package/dist/testFramework.esm.js +1 -1
  131. package/dist/testFramework.esm.js.map +1 -1
  132. package/dist/testFramework.js +1 -1
  133. package/dist/testFramework.js.map +1 -1
  134. package/package.json +6 -1
  135. package/dist/cli/cli/src/js-interop/utils.d.ts +0 -2
  136. package/dist/cli/src/builtin/specialExpressions/def.d.ts +0 -6
  137. package/dist/cli/src/js-interop/utils.d.ts +0 -2
  138. package/dist/cli/src/parser/subParsers/getPrecedence.d.ts +0 -3
  139. package/dist/modules/cli/src/js-interop/utils.d.ts +0 -2
  140. package/dist/modules/src/builtin/specialExpressions/def.d.ts +0 -6
  141. package/dist/modules/src/parser/subParsers/getPrecedence.d.ts +0 -3
  142. package/dist/src/builtin/specialExpressions/def.d.ts +0 -6
  143. package/dist/src/parser/subParsers/getPrecedence.d.ts +0 -3
@@ -1,2 +1,2 @@
1
- "use strict";function t(t){if(!t.position||!t.code)return"";const e=t.position.column-1,r=t.code.length-e-1;return`${" ".repeat(Math.max(e,0))}^${" ".repeat(Math.max(r,0))}`}class e extends Error{sourceCodeInfo;shortMessage;constructor(r,a){const n=r instanceof Error?r.message:`${r}`;super(function(e,r){if(!r)return e;const a=`${r.position.line}:${r.position.column}`;return`${e}${r.filePath?`\n${r.filePath}:${a}`:`\nLocation ${a}`}\n${r.code}\n${t(r)}`}(n,a)),this.shortMessage=n,this.sourceCodeInfo=a,Object.setPrototypeOf(this,e.prototype),this.name="LitsError"}getCodeMarker(){return this.sourceCodeInfo&&t(this.sourceCodeInfo)}}const r={Number:1,String:2,NormalExpression:3,SpecialExpression:4,UserDefinedSymbol:5,NormalBuiltinSymbol:6,SpecialBuiltinSymbol:7,ReservedSymbol:8,Binding:9,Spread:10},a=new Set(Object.values(r));const n=new Set(["UserDefined","Partial","Comp","Constantly","Juxt","Complement","EveryPred","SomePred","Fnull","Builtin","SpecialBuiltin","NativeJsFunction","Module"]);function i(t){return null!==t&&"object"==typeof t&&("^^fn^^"in t&&"functionType"in t&&("string"==typeof(e=t.functionType)&&n.has(e)));var e}function o(t){return!(!Array.isArray(t)||t.length<2)&&("number"==typeof(e=t[0])&&a.has(e));var e}function m(t){return i(t)?`<function ${t.name||"λ"}>`:o(t)?`${e=t[0],Object.keys(r).find(t=>r[t]===e)}-node`:null===t?"null":"object"==typeof t&&t instanceof RegExp?`${t}`:"object"==typeof t&&t instanceof Error?t.toString():JSON.stringify(t);var e}function l(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)))))))))))))}function s(t,r,a={}){if(!l(t,a))throw new e(`Expected ${function(t){if(t.zero)return"zero";const e=function(t){return t.positive?"positive":t.negative?"negative":t.nonNegative?"non negative":t.nonPositive?"non positive":t.nonZero?"non zero":""}(t),r=t.integer?"integer":"number",a=t.finite?"finite":"",n=function(t){return"number"!=typeof t.gt&&"number"!=typeof t.gte||"number"!=typeof t.lt&&"number"!=typeof t.lte?"number"==typeof t.gt||"number"==typeof t.gte?"number"==typeof t.gt?`n > ${t.gt}`:`n >= ${t.gte}`:"number"==typeof t.lt||"number"==typeof t.lte?"number"==typeof t.lt?`n < ${t.lt}`:`n <= ${t.lte}`:"":`${"number"==typeof t.gt?`${t.gt} < n `:`${t.gte} <= n `}${"number"==typeof t.lt?`< ${t.lt}`:`<= ${t.lte}`}`}(t);return[e,a,r,n].filter(t=>!!t).join(" ")}(a)}, got ${m(t)}.`,function(t,e){return t?.sourceCodeInfo??e}(t,r))}const u=new WeakSet,c=new WeakSet,x=new WeakSet,p=new WeakSet,f=new WeakSet,d=new WeakSet;function g(t,r){if(!function(t){return!(!Array.isArray(t)||!c.has(t)&&(x.has(t)||(t.every(t=>l(t))?(u.add(t),c.add(t),0):(x.add(t),1))))}(t))throw new e(`Expected a vector, but got ${t}`,r)}function h(t){if(!Array.isArray(t))return!1;if(p.has(t))return!0;if(f.has(t))return!1;if(0===t.length)return f.add(t),!1;if(!Array.isArray(t[0])||0===t[0].length)return f.add(t),!1;const e=t[0].length;for(const r of t)if(!Array.isArray(r)||r.length!==e||r.some(t=>!l(t)))return f.add(t),!1;return u.add(t),d.add(t),p.add(t),!0}function y(t,r){if(!h(t))throw new e(`Expected a matrix, but got ${t}`,r)}function b(t,r){if(!h(t))throw new e(`Expected a matrix, but got ${t}`,r);if(t.length!==t[0].length)throw new e(`Expected square matrix, but got ${t.length} and ${t[0].length}`,r)}function v(t,e,r=1e-10){if(t===e)return!0;const a=Math.abs(t-e);if(0===t||0===e||a<r)return a<r;return a/(Math.abs(t)+Math.abs(e))<r}function w(t){return Math.abs(t)<1e-10}function N(t){return{min:t,max:t}}const k={mul:{category:"matrix",description:"Multiplies two `matrices` using standard `matrix` multiplication based on **dot products** of rows and columns.",returns:{type:"matrix"},args:{a:{type:"matrix"},b:{type:"matrix"}},variants:[{argumentNames:["a","b"]}],examples:['let { mul } = import("matrix");\nmul([[1, 2], [3, 4]], [[5, 6], [7, 8]])','let { mul } = import("matrix");\nmul([[1, 2, 3], [4, 5, 6]], [[7, 8], [9, 10], [11, 12]])'],seeAlso:["matrix.det","matrix.inv"]},det:{category:"matrix",description:"Calculates the **determinant** of a square matrix.",returns:{type:"number"},args:{m:{type:"matrix",description:"The `matrix` to calculate the determinant of."}},variants:[{argumentNames:["m"]}],examples:['let { det } = import("matrix");\ndet([[1, 2], [3, 4]])','let { det } = import("matrix");\ndet([[1, 2, 3], [4, 5, 6], [7, 8, 9]])'],seeAlso:["matrix.inv","matrix.cofactor","matrix.adj","matrix.trace","matrix.rank","matrix.invertible?","matrix.mul","matrix.minor"]},inv:{category:"matrix",description:"Calculates the **inverse** of a square matrix.",returns:{type:"matrix"},args:{m:{type:"matrix",description:"The `matrix` to calculate the inverse of."}},variants:[{argumentNames:["m"]}],examples:['let { inv } = import("matrix");\ninv([[1, 2], [3, 4]])','let { inv } = import("matrix");\ninv([[1, 2, 3], [4, 5, 7], [7, 8, 10]])'],seeAlso:["matrix.det","matrix.adj","matrix.invertible?","linear-algebra.solve","matrix.mul","matrix.orthogonal?"]},adj:{category:"matrix",description:"Calculates the **adjugate** of a square matrix.",returns:{type:"matrix"},args:{m:{type:"matrix",description:"The `matrix` to calculate the adjugate of."}},variants:[{argumentNames:["m"]}],examples:['let { adj } = import("matrix");\nadj([[1, 2], [3, 4]])','let { adj } = import("matrix");\nadj([[1, 2, 3], [4, 5, 6], [7, 8, 9]])','let { adj } = import("matrix");\nadj([[1, 2, 3], [7, 8, 9], [4, 5, 6]])'],seeAlso:["matrix.cofactor","matrix.det","matrix.inv"]},cofactor:{category:"matrix",description:"Calculates the **cofactor** of a square matrix.",returns:{type:"matrix"},args:{m:{type:"matrix",description:"The `matrix` to calculate the cofactor of."}},variants:[{argumentNames:["m"]}],examples:['let { cofactor } = import("matrix");\ncofactor([[1, 2], [3, 4]])','let { cofactor } = import("matrix");\ncofactor([[1, 2, 3], [4, 5, 6], [7, 8, 9]])','let { cofactor } = import("matrix");\ncofactor([[1, 2, 3], [7, 8, 9], [4, 5, 6]])'],seeAlso:["matrix.adj","matrix.minor","matrix.det"]},minor:{category:"matrix",description:"Calculates the **minor** of a square matrix.",returns:{type:"matrix"},args:{m:{type:"matrix",description:"The `matrix` to calculate the minor of."},row:{type:"integer",description:"The row index of the element to calculate the minor for."},col:{type:"integer",description:"The column index of the element to calculate the minor for."}},variants:[{argumentNames:["m","row","col"]}],examples:['let { minor } = import("matrix");\nminor([[1, 2], [3, 4]], 0, 1)','let { minor } = import("matrix");\nminor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], 1, 1)'],seeAlso:["matrix.cofactor","matrix.det"]},trace:{category:"matrix",description:"Calculates the **trace** of a square matrix.",returns:{type:"number"},args:{m:{type:"matrix",description:"The `matrix` to calculate the trace of."}},variants:[{argumentNames:["m"]}],examples:['let { trace } = import("matrix");\ntrace([[1, 2], [3, 4]])','let { trace } = import("matrix");\ntrace([[1, 2, 3], [4, 5, 6], [7, 8, 9]])'],seeAlso:["matrix.det","matrix.diagonal?"]},"symmetric?":{category:"matrix",description:"Checks if a `matrix` is **symmetric**.",returns:{type:"boolean"},args:{m:{type:"matrix",description:"The `matrix` to check for symmetry."}},variants:[{argumentNames:["m"]}],examples:['let { symmetric? } = import("matrix");\nsymmetric?([[1, 2], [2, 1]])','let { symmetric? } = import("matrix");\nsymmetric?([[1, 2, 3], [2, 1, 4], [3, 4, 1]])'],seeAlso:["matrix.orthogonal?","matrix.diagonal?","matrix.square?","matrix.hilbert"]},"triangular?":{category:"matrix",description:"Checks if a `matrix` is **triangular**.",returns:{type:"boolean"},args:{m:{type:"matrix",description:"The `matrix` to check for triangularity."}},variants:[{argumentNames:["m"]}],examples:['let { triangular? } = import("matrix");\ntriangular?([[2, 0], [0, 1]])','let { triangular? } = import("matrix");\ntriangular?([[1, 2, 3], [0, 4, 5], [0, 0, 6]])'],seeAlso:["matrix.upper-triangular?","matrix.lower-triangular?","matrix.diagonal?","matrix.banded?"]},"upper-triangular?":{category:"matrix",description:"Checks if a `matrix` is **upper triangular**.",returns:{type:"boolean"},args:{m:{type:"matrix",description:"The `matrix` to check for upper triangularity."}},variants:[{argumentNames:["m"]}],examples:['let { upper-triangular? } = import("matrix");\nupper-triangular?([[1, 2], [0, 3]])','let { upper-triangular? } = import("matrix");\nupper-triangular?([[1, 2, 3], [0, 4, 5], [0, 0, 6]])'],seeAlso:["matrix.lower-triangular?","matrix.triangular?","matrix.diagonal?"]},"lower-triangular?":{category:"matrix",description:"Checks if a `matrix` is **lower triangular**.",returns:{type:"boolean"},args:{m:{type:"matrix",description:"The `matrix` to check for lower triangularity."}},variants:[{argumentNames:["m"]}],examples:['let { lower-triangular? } = import("matrix");\nlower-triangular?([[1, 0], [2, 3]])','let { lower-triangular? } = import("matrix");\nlower-triangular?([[1, 0, 0], [2, 3, 0], [4, 5, 6]])'],seeAlso:["matrix.upper-triangular?","matrix.triangular?","matrix.diagonal?"]},"diagonal?":{category:"matrix",description:"Checks if a `matrix` is **diagonal**.",returns:{type:"boolean"},args:{m:{type:"matrix",description:"The `matrix` to check for diagonal property."}},variants:[{argumentNames:["m"]}],examples:['let { diagonal? } = import("matrix");\ndiagonal?([[1, 0], [0, 2]])','let { diagonal? } = import("matrix");\ndiagonal?([[1, 0, 0], [0, 2, 0], [0, 0, 3]])','let { diagonal? } = import("matrix");\ndiagonal?([[1, 0, 0], [2, 2, 2], [0, 0, 3]])'],seeAlso:["matrix.identity?","matrix.symmetric?","matrix.triangular?","matrix.trace","matrix.upper-triangular?","matrix.lower-triangular?","matrix.band","matrix.banded?"]},"square?":{category:"matrix",description:"Checks if a `matrix` is **square**.",returns:{type:"boolean"},args:{m:{type:"matrix",description:"The `matrix` to check for square property."}},variants:[{argumentNames:["m"]}],examples:['let { square? } = import("matrix");\nsquare?([[1, 2], [3, 4]])','let { square? } = import("matrix");\nsquare?([[1, 2, 3], [4, 5, 6], [7, 8, 9]])','let { square? } = import("matrix");\nsquare?([[1, 2, 3], [4, 5, 6]])'],seeAlso:["matrix.symmetric?","matrix.identity?","matrix.invertible?"]},"orthogonal?":{category:"matrix",description:"Checks if a `matrix` is **orthogonal**.",returns:{type:"boolean"},args:{m:{type:"matrix",description:"The `matrix` to check for **orthogonality**."}},variants:[{argumentNames:["m"]}],examples:['let { orthogonal? } = import("matrix");\northogonal?([[1, 0], [0, 1]])','let { orthogonal? } = import("matrix");\northogonal?([[1, 0], [0, -1]])','let { orthogonal? } = import("matrix");\northogonal?([[1, 2], [3, 4]])'],seeAlso:["matrix.symmetric?","matrix.inv","matrix.identity?","linear-algebra.orthogonal?"]},"identity?":{category:"matrix",description:"Checks if a `matrix` is an **identity matrix**.",returns:{type:"boolean"},args:{m:{type:"matrix",description:"The `matrix` to check for identity property."}},variants:[{argumentNames:["m"]}],examples:['let { identity? } = import("matrix");\nidentity?([[1, 0], [0, 1]])','let { identity? } = import("matrix");\nidentity?([[1, 0, 0], [0, 1, 0], [0, 0, 1]])','let { identity? } = import("matrix");\nidentity?([[1, 0, 0], [0, 1, 0], [0, 0, 0]])'],seeAlso:["matrix.diagonal?","matrix.square?","matrix.orthogonal?"]},"invertible?":{category:"matrix",description:"Checks if a `matrix` is **invertible**.",returns:{type:"boolean"},args:{m:{type:"matrix",description:"The `matrix` to check for invertibility."}},variants:[{argumentNames:["m"]}],examples:['let { invertible? } = import("matrix");\ninvertible?([[1, 2], [3, 4]])','let { invertible? } = import("matrix");\ninvertible?([[1, 2, 3], [4, 5, 6], [7, 8, 9]])','let { invertible? } = import("matrix");\ninvertible?([[1, 2], [2, 4]])'],seeAlso:["matrix.det","matrix.inv","matrix.rank","matrix.square?"]},hilbert:{category:"matrix",description:"Generates a **Hilbert matrix** of size `n`.",returns:{type:"matrix"},args:{n:{type:"integer",description:"The size of the Hilbert matrix."}},variants:[{argumentNames:["n"]}],examples:['let { hilbert } = import("matrix");\nhilbert(3)','let { hilbert } = import("matrix");\nhilbert(4)'],seeAlso:["matrix.vandermonde","matrix.symmetric?"]},vandermonde:{category:"matrix",description:"Generates a **Vandermonde matrix** from a vector.",returns:{type:"matrix"},args:{v:{type:"vector",description:"The vector to generate the Vandermonde matrix from."}},variants:[{argumentNames:["v"]}],examples:['let { vandermonde } = import("matrix");\nvandermonde([1, 2, 3])','let { vandermonde } = import("matrix");\nvandermonde([1, 0, 1])'],seeAlso:["matrix.hilbert","matrix.band"]},band:{category:"matrix",description:"Generates a **banded matrix** of size `n` with lower band index `lband` and upper band index `uband`.",returns:{type:"matrix"},args:{n:{type:"integer",description:"The size of the banded matrix."},lband:{type:"integer",description:"The lower band index."},uband:{type:"integer",description:"The upper band index."}},variants:[{argumentNames:["n","lband","uband"]}],examples:['let { band } = import("matrix");\nband(3, 1, 1)','let { band } = import("matrix");\nband(4, 1, 2)'],seeAlso:["matrix.banded?","matrix.diagonal?","matrix.vandermonde"]},"banded?":{category:"matrix",description:"Checks if a `matrix` is **banded** with lower band index `lband` and upper band index `uband`.",returns:{type:"boolean"},args:{m:{type:"matrix",description:"The `matrix` to check for **banded** property."},lband:{type:"integer",description:"The lower band index."},uband:{type:"integer",description:"The upper band index."}},variants:[{argumentNames:["m","lband","uband"]}],examples:['let { banded? } = import("matrix");\nbanded?([\n [1, 1, 1, 0],\n [1, 1, 1, 1],\n [1, 1, 1, 1],\n [0, 1, 1, 1],\n], 2, 2)','let { banded? } = import("matrix");\nbanded?([\n [1, 1, 1, 0],\n [1, 1, 1, 1],\n [1, 1, 1, 1],\n [0, 1, 1, 1],\n], 1, 1)'],seeAlso:["matrix.band","matrix.triangular?","matrix.diagonal?"]},rank:{category:"matrix",description:"Calculates the **rank** of a matrix using **Gaussian elimination**.",returns:{type:"number"},args:{m:{type:"matrix",description:"The `matrix` to calculate the rank of."}},variants:[{argumentNames:["m"]}],examples:['let { rank } = import("matrix");\nrank([[1, 0, 0], [0, 1, 0], [0, 0, 1]])','let { rank } = import("matrix");\nrank([[1, 2, 3], [4, 5, 6], [7, 8, 9]])','let { rank } = import("matrix");\nrank([[2, 4, 6], [3, 6, 9], [4, 8, 12]])'],seeAlso:["matrix.det","matrix.invertible?","linear-algebra.rref"]},"frobenius-norm":{category:"matrix",description:"Calculates the **Frobenius norm** of a matrix.",returns:{type:"number"},args:{m:{type:"matrix",description:"The `matrix` to calculate the Frobenius norm of."}},variants:[{argumentNames:["m"]}],examples:['let { frobenius-norm } = import("matrix");\nfrobenius-norm([[1, 2], [3, 4]])','let { frobenius-norm } = import("matrix");\nfrobenius-norm([[1, 2, 3], [4, 5, 6], [7, 8, 9]])'],seeAlso:["matrix.one-norm","matrix.inf-norm","matrix.max-norm"]},"one-norm":{category:"matrix",description:"Calculates the **one-norm** (column norm) of a matrix.",returns:{type:"number"},args:{m:{type:"matrix",description:"The `matrix` to calculate the one-norm of."}},variants:[{argumentNames:["m"]}],examples:['let { one-norm } = import("matrix");\none-norm([[1, 2], [3, 4]])','let { one-norm } = import("matrix");\none-norm([[1, 2, 3], [4, 5, 6], [7, 8, 9]])'],seeAlso:["matrix.frobenius-norm","matrix.inf-norm","matrix.max-norm"]},"inf-norm":{category:"matrix",description:"Calculates the **infinity norm** of a matrix.",returns:{type:"number"},args:{m:{type:"matrix",description:"The `matrix` to calculate the infinity norm of."}},variants:[{argumentNames:["m"]}],examples:['let { inf-norm } = import("matrix");\ninf-norm([[1, 2], [3, 4]])','let { inf-norm } = import("matrix");\ninf-norm([[1, 2, 3], [4, 5, 6], [7, 8, 9]])'],seeAlso:["matrix.frobenius-norm","matrix.one-norm","matrix.max-norm"]},"max-norm":{category:"matrix",description:"Calculates the **max norm** of a matrix.",returns:{type:"number"},args:{m:{type:"matrix",description:"The `matrix` to calculate the max norm of."}},variants:[{argumentNames:["m"]}],examples:['let { max-norm } = import("matrix");\nmax-norm([[1, 2], [3, 4]])','let { max-norm } = import("matrix");\nmax-norm([[1, 2, 3], [4, 5, 6], [7, 8, 9]])'],seeAlso:["matrix.frobenius-norm","matrix.one-norm","matrix.inf-norm"]}};function A(t){const e=t.length,r=[];for(let a=0;a<e;a++)r[a]=[...t[a]];if(1===e)return r[0][0];if(2===e)return r[0][0]*r[1][1]-r[0][1]*r[1][0];let a=1;for(let t=0;t<e-1;t+=1){let n=t;for(let a=t+1;a<e;a+=1)Math.abs(r[a][t])>Math.abs(r[n][t])&&(n=a);if(w(r[n][t]))return 0;n!==t&&([r[t],r[n]]=[r[n],r[t]],a=-a);for(let a=t+1;a<e;a+=1){const n=r[a][t]/r[t][t];for(let i=t;i<e;i++)r[a][i]-=n*r[t][i]}}let n=a;for(let t=0;t<e;t++)n*=r[t][t];return n}function T(t,e,r){const a=t.length,n=[];for(let i=0;i<a;i++)if(i!==e){const e=[];for(let n=0;n<a;n++)n!==r&&e.push(t[i][n]);n.push(e)}return n}function $(t){const e=t.length,r=[];for(let a=0;a<e;a++){r[a]=[];for(let n=0;n<e;n++){const e=(-1)**(a+n)*A(T(t,n,a));r[a][n]=e}}return r}function C(t){return t.length===t[0].length}function M(t){if(!C(t))return!1;const e=t.length;for(let r=0;r<e;r++)for(let a=0;a<e;a++)if(r===a){if(!v(t[r][a],1))return!1}else if(!w(t[r][a]))return!1;return!0}function q(t,e){if(0===t.length||0===e.length||t[0].length!==e.length)throw new Error("Matrix dimensions do not match for multiplication");const r=t.length,a=t[0].length,n=e[0].length,i=Array(r).fill(0).map(()=>Array(n).fill(0));for(let o=0;o<r;o++)for(let r=0;r<a;r++){const a=t[o][r];for(let t=0;t<n;t++)i[o][t]+=a*e[r][t]}return i}const j={mul:{evaluate:([t,r],a)=>{y(t,a),y(r,a);try{return q(t,r)}catch(n){throw new e(`The number of columns in the first matrix must be equal to the number of rows in the second matrix, but got ${t[0].length} and ${r.length}`,a)}},arity:N(2)},det:{evaluate:([t],e)=>(b(t,e),A(t)),arity:N(1)},inv:{evaluate:([t],r)=>{b(t,r);const a=function(t){const e=t.length;if(1===e){const e=t[0][0];return w(e)?null:[[1/e]]}const r=A(t);if(w(r))return null;const a=$(t),n=[];for(let t=0;t<e;t++){n[t]=[];for(let i=0;i<e;i++)n[t][i]=a[t][i]/r}return n}(t);if(null===a)throw new e("The matrix must be invertible",r);return a},arity:N(1)},adj:{evaluate:([t],e)=>(b(t,e),$(t)),arity:N(1)},cofactor:{evaluate:([t],e)=>(b(t,e),function(t){const e=t.length,r=[];for(let a=0;a<e;a++){r[a]=[];for(let n=0;n<e;n++){const e=T(t,a,n),i=(-1)**(a+n);r[a][n]=i*A(e)}}return r}(t)),arity:N(1)},minor:{evaluate:([t,e,r],a)=>(y(t,a),s(e,a,{integer:!0,nonNegative:!0,lte:t.length}),s(r,a,{integer:!0,nonNegative:!0,lte:t[0].length}),T(t,e,r)),arity:N(3)},trace:{evaluate:([t],e)=>(b(t,e),function(t){return t.reduce((t,e,r)=>t+e[r],0)}(t)),arity:N(1)},"symmetric?":{evaluate:([t],e)=>(y(t,e),function(t){const e=t.length;if(!C(t))return!1;for(let r=0;r<e;r+=1)for(let e=0;e<r;e+=1)if(t[r][e]!==t[e][r])return!1;return!0}(t)),arity:N(1)},"triangular?":{evaluate:([t],e)=>(y(t,e),function(t){if(!C(t))return!1;const e=t.length;let r=!0,a=!0;for(let n=0;n<e;n++)for(let i=0;i<e;i++){if(n>i&&0!==t[n][i]&&(r=!1,!a))return!1;n<i&&0!==t[n][i]&&(a=!1)}return r||a}(t)),arity:N(1)},"upper-triangular?":{evaluate:([t],e)=>(y(t,e),function(t){if(!C(t))return!1;const e=t.length;for(let r=0;r<e;r++)for(let e=0;e<r;e++)if(0!==t[r][e])return!1;return!0}(t)),arity:N(1)},"lower-triangular?":{evaluate:([t],e)=>(y(t,e),function(t){if(!C(t))return!1;const e=t.length;if(!t.every(t=>t.length===e))return!1;for(let r=0;r<e;r++)for(let a=r+1;a<e;a++)if(0!==t[r][a])return!1;return!0}(t)),arity:N(1)},"diagonal?":{evaluate:([t],e)=>(y(t,e),function(t){if(!C(t))return!1;const e=t.length;for(let r=0;r<e;r+=1)for(let a=0;a<e;a+=1)if(r!==a&&0!==t[r][a])return!1;return!0}(t)),arity:N(1)},"square?":{evaluate:([t],e)=>(y(t,e),C(t)),arity:N(1)},"orthogonal?":{evaluate:([t],e)=>(y(t,e),function(t){return!!C(t)&&M(q(t,function(t){const e=[];for(let r=0;r<t[0].length;r+=1){const a=[];for(let e=0;e<t.length;e+=1)a.push(t[e][r]);e.push(a)}return e}(t)))}(t)),arity:N(1)},"identity?":{evaluate:([t],e)=>(y(t,e),M(t)),arity:N(1)},"invertible?":{evaluate:([t],e)=>(y(t,e),!!function(t){return!!h(t)&&t.length===t[0].length}(t)&&!w(A(t))),arity:N(1)},hilbert:{evaluate:([t],e)=>{s(t,e,{integer:!0,positive:!0});const r=[];for(let e=0;e<t;e+=1){const a=[];for(let r=0;r<t;r+=1)a.push(1/(e+r+1));r.push(a)}return r},arity:N(1)},vandermonde:{evaluate:([t],e)=>{g(t,e);const r=[];for(let e=0;e<t.length;e+=1){const a=[];for(let r=0;r<t.length;r+=1)a.push(t[e]**r);r.push(a)}return r},arity:N(1)},band:{evaluate:([t,e,r],a)=>(s(t,a,{integer:!0,positive:!0}),s(e,a,{integer:!0,nonNegative:!0,lt:t}),s(r,a,{integer:!0,nonNegative:!0,lte:t}),function(t,e,r){const a=Array.from({length:t},()=>Array.from({length:t},()=>0));for(let n=0;n<t;n++)for(let i=Math.max(0,n-e);i<=Math.min(t-1,n+r);i++)a[n][i]=1;return a}(t,e,r)),arity:N(3)},"banded?":{evaluate:([t,e,r],a)=>{y(t,a);const n=Math.max(t.length,t[0].length);return s(e,a,{integer:!0,nonNegative:!0,lt:n}),s(r,a,{integer:!0,nonNegative:!0,lt:n}),function(t,e,r){const a=t.length,n=t[0].length;for(let i=0;i<a;i++)for(let a=0;a<n;a++)if(0!==t[i][a]&&(i-a>e||a-i>r))return!1;return!0}(t,e,r)},arity:N(3)},rank:{evaluate:([t],e)=>{y(t,e);const[,r]=function(t){const e=t.map(t=>[...t]),r=e.length,a=e[0].length;let n=0,i=0;for(let t=0;t<a;t++){let o=-1;for(let a=i;a<r;a++)if(!w(e[a][t])){o=a;break}if(-1===o)continue;n+=1,o!==i&&([e[o],e[i]]=[e[i],e[o]]);const m=e[i][t];for(let r=t;r<a;r++)e[i][r]/=m;for(let n=0;n<r;n++)if(n!==i&&!w(e[n][t])){const r=e[n][t];for(let o=t;o<a;o++)e[n][o]-=r*e[i][o]}if(i++,i===r)break}return[e,n]}(t);return r},arity:N(1)},"frobenius-norm":{evaluate:([t],e)=>(y(t,e),Math.sqrt(t.reduce((t,e)=>t+e.reduce((t,e)=>t+e*e,0),0))),arity:N(1)},"one-norm":{evaluate:([t],e)=>(y(t,e),function(t){const e=t.length,r=t[0].length;let a=0;for(let n=0;n<r;n+=1){let r=0;for(let a=0;a<e;a+=1)r+=Math.abs(t[a][n]);a=Math.max(a,r)}return a}(t)),arity:N(1)},"inf-norm":{evaluate:([t],e)=>(y(t,e),t.reduce((t,e)=>Math.max(t,e.reduce((t,e)=>t+Math.abs(e),0)),0)),arity:N(1)},"max-norm":{evaluate:([t],e)=>(y(t,e),t.reduce((t,e)=>{const r=e.reduce((t,e)=>Math.max(t,Math.abs(e)),0);return Math.max(t,r)},0)),arity:N(1)}};for(const[t,e]of Object.entries(k))j[t]&&(j[t].docs=e);const S={name:"matrix",functions:j};exports.matrixModule=S;
1
+ "use strict";function t(t){if(!t.position||!t.code)return"";const e=t.position.column-1,r=t.code.length-e-1;return`${" ".repeat(Math.max(e,0))}^${" ".repeat(Math.max(r,0))}`}class e extends Error{sourceCodeInfo;shortMessage;constructor(r,a){const n=r instanceof Error?r.message:`${r}`;super(function(e,r){if(!r)return e;const a=`${r.position.line}:${r.position.column}`;return`${e}${r.filePath?`\n${r.filePath}:${a}`:`\nLocation ${a}`}\n${r.code}\n${t(r)}`}(n,a)),this.shortMessage=n,this.sourceCodeInfo=a,Object.setPrototypeOf(this,e.prototype),this.name="LitsError"}getCodeMarker(){return this.sourceCodeInfo&&t(this.sourceCodeInfo)}}const r={Number:1,String:2,NormalExpression:3,SpecialExpression:4,UserDefinedSymbol:5,NormalBuiltinSymbol:6,SpecialBuiltinSymbol:7,ReservedSymbol:8,Binding:9,Spread:10},a=new Set(Object.values(r));const n=new Set(["UserDefined","Partial","Comp","Constantly","Juxt","Complement","EveryPred","SomePred","Fnull","Builtin","SpecialBuiltin","NativeJsFunction","Module"]);function i(t){return null!==t&&"object"==typeof t&&("^^fn^^"in t&&"functionType"in t&&("string"==typeof(e=t.functionType)&&n.has(e)));var e}function o(t){return!(!Array.isArray(t)||t.length<2)&&("number"==typeof(e=t[0])&&a.has(e));var e}function m(t){return i(t)?`<function ${t.name||"λ"}>`:o(t)?`${e=t[0],Object.keys(r).find(t=>r[t]===e)}-node`:null===t?"null":"object"==typeof t&&t instanceof RegExp?`${t}`:"object"==typeof t&&t instanceof Error?t.toString():JSON.stringify(t);var e}function l(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)))))))))))))}function s(t,r,a={}){if(!l(t,a))throw new e(`Expected ${function(t){if(t.zero)return"zero";const e=function(t){return t.positive?"positive":t.negative?"negative":t.nonNegative?"non negative":t.nonPositive?"non positive":t.nonZero?"non zero":""}(t),r=t.integer?"integer":"number",a=t.finite?"finite":"",n=function(t){return"number"!=typeof t.gt&&"number"!=typeof t.gte||"number"!=typeof t.lt&&"number"!=typeof t.lte?"number"==typeof t.gt||"number"==typeof t.gte?"number"==typeof t.gt?`n > ${t.gt}`:`n >= ${t.gte}`:"number"==typeof t.lt||"number"==typeof t.lte?"number"==typeof t.lt?`n < ${t.lt}`:`n <= ${t.lte}`:"":`${"number"==typeof t.gt?`${t.gt} < n `:`${t.gte} <= n `}${"number"==typeof t.lt?`< ${t.lt}`:`<= ${t.lte}`}`}(t);return[e,a,r,n].filter(t=>!!t).join(" ")}(a)}, got ${m(t)}.`,function(t,e){return t?.sourceCodeInfo??e}(t,r))}const u=new WeakSet,c=new WeakSet,x=new WeakSet,p=new WeakSet,f=new WeakSet,d=new WeakSet;function g(t,r){if(!function(t){return!(!Array.isArray(t)||!c.has(t)&&(x.has(t)||(t.every(t=>l(t))?(u.add(t),c.add(t),0):(x.add(t),1))))}(t))throw new e(`Expected a vector, but got ${t}`,r)}function h(t){if(!Array.isArray(t))return!1;if(p.has(t))return!0;if(f.has(t))return!1;if(0===t.length)return f.add(t),!1;if(!Array.isArray(t[0])||0===t[0].length)return f.add(t),!1;const e=t[0].length;for(const r of t)if(!Array.isArray(r)||r.length!==e||r.some(t=>!l(t)))return f.add(t),!1;return u.add(t),d.add(t),p.add(t),!0}function y(t,r){if(!h(t))throw new e(`Expected a matrix, but got ${t}`,r)}function b(t,r){if(!h(t))throw new e(`Expected a matrix, but got ${t}`,r);if(t.length!==t[0].length)throw new e(`Expected square matrix, but got ${t.length} and ${t[0].length}`,r)}function v(t,e,r=1e-10){if(t===e)return!0;const a=Math.abs(t-e);if(0===t||0===e||a<r)return a<r;return a/(Math.abs(t)+Math.abs(e))<r}function w(t){return Math.abs(t)<1e-10}function N(t){return{min:t,max:t}}const k={mul:{category:"matrix",description:"Multiplies two `matrices` using standard `matrix` multiplication based on **dot products** of rows and columns.",returns:{type:"matrix"},args:{a:{type:"matrix"},b:{type:"matrix"}},variants:[{argumentNames:["a","b"]}],examples:["let { mul } = import(matrix);\nmul([[1, 2], [3, 4]], [[5, 6], [7, 8]])","let { mul } = import(matrix);\nmul([[1, 2, 3], [4, 5, 6]], [[7, 8], [9, 10], [11, 12]])"],seeAlso:["matrix.det","matrix.inv"]},det:{category:"matrix",description:"Calculates the **determinant** of a square matrix.",returns:{type:"number"},args:{m:{type:"matrix",description:"The `matrix` to calculate the determinant of."}},variants:[{argumentNames:["m"]}],examples:["let { det } = import(matrix);\ndet([[1, 2], [3, 4]])","let { det } = import(matrix);\ndet([[1, 2, 3], [4, 5, 6], [7, 8, 9]])"],seeAlso:["matrix.inv","matrix.cofactor","matrix.adj","matrix.trace","matrix.rank","matrix.invertible?","matrix.mul","matrix.minor"]},inv:{category:"matrix",description:"Calculates the **inverse** of a square matrix.",returns:{type:"matrix"},args:{m:{type:"matrix",description:"The `matrix` to calculate the inverse of."}},variants:[{argumentNames:["m"]}],examples:["let { inv } = import(matrix);\ninv([[1, 2], [3, 4]])","let { inv } = import(matrix);\ninv([[1, 2, 3], [4, 5, 7], [7, 8, 10]])"],seeAlso:["matrix.det","matrix.adj","matrix.invertible?","linear-algebra.solve","matrix.mul","matrix.orthogonal?"]},adj:{category:"matrix",description:"Calculates the **adjugate** of a square matrix.",returns:{type:"matrix"},args:{m:{type:"matrix",description:"The `matrix` to calculate the adjugate of."}},variants:[{argumentNames:["m"]}],examples:["let { adj } = import(matrix);\nadj([[1, 2], [3, 4]])","let { adj } = import(matrix);\nadj([[1, 2, 3], [4, 5, 6], [7, 8, 9]])","let { adj } = import(matrix);\nadj([[1, 2, 3], [7, 8, 9], [4, 5, 6]])"],seeAlso:["matrix.cofactor","matrix.det","matrix.inv"]},cofactor:{category:"matrix",description:"Calculates the **cofactor** of a square matrix.",returns:{type:"matrix"},args:{m:{type:"matrix",description:"The `matrix` to calculate the cofactor of."}},variants:[{argumentNames:["m"]}],examples:["let { cofactor } = import(matrix);\ncofactor([[1, 2], [3, 4]])","let { cofactor } = import(matrix);\ncofactor([[1, 2, 3], [4, 5, 6], [7, 8, 9]])","let { cofactor } = import(matrix);\ncofactor([[1, 2, 3], [7, 8, 9], [4, 5, 6]])"],seeAlso:["matrix.adj","matrix.minor","matrix.det"]},minor:{category:"matrix",description:"Calculates the **minor** of a square matrix.",returns:{type:"matrix"},args:{m:{type:"matrix",description:"The `matrix` to calculate the minor of."},row:{type:"integer",description:"The row index of the element to calculate the minor for."},col:{type:"integer",description:"The column index of the element to calculate the minor for."}},variants:[{argumentNames:["m","row","col"]}],examples:["let { minor } = import(matrix);\nminor([[1, 2], [3, 4]], 0, 1)","let { minor } = import(matrix);\nminor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], 1, 1)"],seeAlso:["matrix.cofactor","matrix.det"]},trace:{category:"matrix",description:"Calculates the **trace** of a square matrix.",returns:{type:"number"},args:{m:{type:"matrix",description:"The `matrix` to calculate the trace of."}},variants:[{argumentNames:["m"]}],examples:["let { trace } = import(matrix);\ntrace([[1, 2], [3, 4]])","let { trace } = import(matrix);\ntrace([[1, 2, 3], [4, 5, 6], [7, 8, 9]])"],seeAlso:["matrix.det","matrix.diagonal?"]},"symmetric?":{category:"matrix",description:"Checks if a `matrix` is **symmetric**.",returns:{type:"boolean"},args:{m:{type:"matrix",description:"The `matrix` to check for symmetry."}},variants:[{argumentNames:["m"]}],examples:["let { symmetric? } = import(matrix);\nsymmetric?([[1, 2], [2, 1]])","let { symmetric? } = import(matrix);\nsymmetric?([[1, 2, 3], [2, 1, 4], [3, 4, 1]])"],seeAlso:["matrix.orthogonal?","matrix.diagonal?","matrix.square?","matrix.hilbert"]},"triangular?":{category:"matrix",description:"Checks if a `matrix` is **triangular**.",returns:{type:"boolean"},args:{m:{type:"matrix",description:"The `matrix` to check for triangularity."}},variants:[{argumentNames:["m"]}],examples:["let { triangular? } = import(matrix);\ntriangular?([[2, 0], [0, 1]])","let { triangular? } = import(matrix);\ntriangular?([[1, 2, 3], [0, 4, 5], [0, 0, 6]])"],seeAlso:["matrix.upper-triangular?","matrix.lower-triangular?","matrix.diagonal?","matrix.banded?"]},"upper-triangular?":{category:"matrix",description:"Checks if a `matrix` is **upper triangular**.",returns:{type:"boolean"},args:{m:{type:"matrix",description:"The `matrix` to check for upper triangularity."}},variants:[{argumentNames:["m"]}],examples:["let { upper-triangular? } = import(matrix);\nupper-triangular?([[1, 2], [0, 3]])","let { upper-triangular? } = import(matrix);\nupper-triangular?([[1, 2, 3], [0, 4, 5], [0, 0, 6]])"],seeAlso:["matrix.lower-triangular?","matrix.triangular?","matrix.diagonal?"]},"lower-triangular?":{category:"matrix",description:"Checks if a `matrix` is **lower triangular**.",returns:{type:"boolean"},args:{m:{type:"matrix",description:"The `matrix` to check for lower triangularity."}},variants:[{argumentNames:["m"]}],examples:["let { lower-triangular? } = import(matrix);\nlower-triangular?([[1, 0], [2, 3]])","let { lower-triangular? } = import(matrix);\nlower-triangular?([[1, 0, 0], [2, 3, 0], [4, 5, 6]])"],seeAlso:["matrix.upper-triangular?","matrix.triangular?","matrix.diagonal?"]},"diagonal?":{category:"matrix",description:"Checks if a `matrix` is **diagonal**.",returns:{type:"boolean"},args:{m:{type:"matrix",description:"The `matrix` to check for diagonal property."}},variants:[{argumentNames:["m"]}],examples:["let { diagonal? } = import(matrix);\ndiagonal?([[1, 0], [0, 2]])","let { diagonal? } = import(matrix);\ndiagonal?([[1, 0, 0], [0, 2, 0], [0, 0, 3]])","let { diagonal? } = import(matrix);\ndiagonal?([[1, 0, 0], [2, 2, 2], [0, 0, 3]])"],seeAlso:["matrix.identity?","matrix.symmetric?","matrix.triangular?","matrix.trace","matrix.upper-triangular?","matrix.lower-triangular?","matrix.band","matrix.banded?"]},"square?":{category:"matrix",description:"Checks if a `matrix` is **square**.",returns:{type:"boolean"},args:{m:{type:"matrix",description:"The `matrix` to check for square property."}},variants:[{argumentNames:["m"]}],examples:["let { square? } = import(matrix);\nsquare?([[1, 2], [3, 4]])","let { square? } = import(matrix);\nsquare?([[1, 2, 3], [4, 5, 6], [7, 8, 9]])","let { square? } = import(matrix);\nsquare?([[1, 2, 3], [4, 5, 6]])"],seeAlso:["matrix.symmetric?","matrix.identity?","matrix.invertible?"]},"orthogonal?":{category:"matrix",description:"Checks if a `matrix` is **orthogonal**.",returns:{type:"boolean"},args:{m:{type:"matrix",description:"The `matrix` to check for **orthogonality**."}},variants:[{argumentNames:["m"]}],examples:["let { orthogonal? } = import(matrix);\northogonal?([[1, 0], [0, 1]])","let { orthogonal? } = import(matrix);\northogonal?([[1, 0], [0, -1]])","let { orthogonal? } = import(matrix);\northogonal?([[1, 2], [3, 4]])"],seeAlso:["matrix.symmetric?","matrix.inv","matrix.identity?","linear-algebra.orthogonal?"]},"identity?":{category:"matrix",description:"Checks if a `matrix` is an **identity matrix**.",returns:{type:"boolean"},args:{m:{type:"matrix",description:"The `matrix` to check for identity property."}},variants:[{argumentNames:["m"]}],examples:["let { identity? } = import(matrix);\nidentity?([[1, 0], [0, 1]])","let { identity? } = import(matrix);\nidentity?([[1, 0, 0], [0, 1, 0], [0, 0, 1]])","let { identity? } = import(matrix);\nidentity?([[1, 0, 0], [0, 1, 0], [0, 0, 0]])"],seeAlso:["matrix.diagonal?","matrix.square?","matrix.orthogonal?"]},"invertible?":{category:"matrix",description:"Checks if a `matrix` is **invertible**.",returns:{type:"boolean"},args:{m:{type:"matrix",description:"The `matrix` to check for invertibility."}},variants:[{argumentNames:["m"]}],examples:["let { invertible? } = import(matrix);\ninvertible?([[1, 2], [3, 4]])","let { invertible? } = import(matrix);\ninvertible?([[1, 2, 3], [4, 5, 6], [7, 8, 9]])","let { invertible? } = import(matrix);\ninvertible?([[1, 2], [2, 4]])"],seeAlso:["matrix.det","matrix.inv","matrix.rank","matrix.square?"]},hilbert:{category:"matrix",description:"Generates a **Hilbert matrix** of size `n`.",returns:{type:"matrix"},args:{n:{type:"integer",description:"The size of the Hilbert matrix."}},variants:[{argumentNames:["n"]}],examples:["let { hilbert } = import(matrix);\nhilbert(3)","let { hilbert } = import(matrix);\nhilbert(4)"],seeAlso:["matrix.vandermonde","matrix.symmetric?"]},vandermonde:{category:"matrix",description:"Generates a **Vandermonde matrix** from a vector.",returns:{type:"matrix"},args:{v:{type:"vector",description:"The vector to generate the Vandermonde matrix from."}},variants:[{argumentNames:["v"]}],examples:["let { vandermonde } = import(matrix);\nvandermonde([1, 2, 3])","let { vandermonde } = import(matrix);\nvandermonde([1, 0, 1])"],seeAlso:["matrix.hilbert","matrix.band"]},band:{category:"matrix",description:"Generates a **banded matrix** of size `n` with lower band index `lband` and upper band index `uband`.",returns:{type:"matrix"},args:{n:{type:"integer",description:"The size of the banded matrix."},lband:{type:"integer",description:"The lower band index."},uband:{type:"integer",description:"The upper band index."}},variants:[{argumentNames:["n","lband","uband"]}],examples:["let { band } = import(matrix);\nband(3, 1, 1)","let { band } = import(matrix);\nband(4, 1, 2)"],seeAlso:["matrix.banded?","matrix.diagonal?","matrix.vandermonde"]},"banded?":{category:"matrix",description:"Checks if a `matrix` is **banded** with lower band index `lband` and upper band index `uband`.",returns:{type:"boolean"},args:{m:{type:"matrix",description:"The `matrix` to check for **banded** property."},lband:{type:"integer",description:"The lower band index."},uband:{type:"integer",description:"The upper band index."}},variants:[{argumentNames:["m","lband","uband"]}],examples:["let { banded? } = import(matrix);\nbanded?([\n [1, 1, 1, 0],\n [1, 1, 1, 1],\n [1, 1, 1, 1],\n [0, 1, 1, 1],\n], 2, 2)","let { banded? } = import(matrix);\nbanded?([\n [1, 1, 1, 0],\n [1, 1, 1, 1],\n [1, 1, 1, 1],\n [0, 1, 1, 1],\n], 1, 1)"],seeAlso:["matrix.band","matrix.triangular?","matrix.diagonal?"]},rank:{category:"matrix",description:"Calculates the **rank** of a matrix using **Gaussian elimination**.",returns:{type:"number"},args:{m:{type:"matrix",description:"The `matrix` to calculate the rank of."}},variants:[{argumentNames:["m"]}],examples:["let { rank } = import(matrix);\nrank([[1, 0, 0], [0, 1, 0], [0, 0, 1]])","let { rank } = import(matrix);\nrank([[1, 2, 3], [4, 5, 6], [7, 8, 9]])","let { rank } = import(matrix);\nrank([[2, 4, 6], [3, 6, 9], [4, 8, 12]])"],seeAlso:["matrix.det","matrix.invertible?","linear-algebra.rref"]},"frobenius-norm":{category:"matrix",description:"Calculates the **Frobenius norm** of a matrix.",returns:{type:"number"},args:{m:{type:"matrix",description:"The `matrix` to calculate the Frobenius norm of."}},variants:[{argumentNames:["m"]}],examples:["let { frobenius-norm } = import(matrix);\nfrobenius-norm([[1, 2], [3, 4]])","let { frobenius-norm } = import(matrix);\nfrobenius-norm([[1, 2, 3], [4, 5, 6], [7, 8, 9]])"],seeAlso:["matrix.one-norm","matrix.inf-norm","matrix.max-norm"]},"one-norm":{category:"matrix",description:"Calculates the **one-norm** (column norm) of a matrix.",returns:{type:"number"},args:{m:{type:"matrix",description:"The `matrix` to calculate the one-norm of."}},variants:[{argumentNames:["m"]}],examples:["let { one-norm } = import(matrix);\none-norm([[1, 2], [3, 4]])","let { one-norm } = import(matrix);\none-norm([[1, 2, 3], [4, 5, 6], [7, 8, 9]])"],seeAlso:["matrix.frobenius-norm","matrix.inf-norm","matrix.max-norm"]},"inf-norm":{category:"matrix",description:"Calculates the **infinity norm** of a matrix.",returns:{type:"number"},args:{m:{type:"matrix",description:"The `matrix` to calculate the infinity norm of."}},variants:[{argumentNames:["m"]}],examples:["let { inf-norm } = import(matrix);\ninf-norm([[1, 2], [3, 4]])","let { inf-norm } = import(matrix);\ninf-norm([[1, 2, 3], [4, 5, 6], [7, 8, 9]])"],seeAlso:["matrix.frobenius-norm","matrix.one-norm","matrix.max-norm"]},"max-norm":{category:"matrix",description:"Calculates the **max norm** of a matrix.",returns:{type:"number"},args:{m:{type:"matrix",description:"The `matrix` to calculate the max norm of."}},variants:[{argumentNames:["m"]}],examples:["let { max-norm } = import(matrix);\nmax-norm([[1, 2], [3, 4]])","let { max-norm } = import(matrix);\nmax-norm([[1, 2, 3], [4, 5, 6], [7, 8, 9]])"],seeAlso:["matrix.frobenius-norm","matrix.one-norm","matrix.inf-norm"]}};function A(t){const e=t.length,r=[];for(let a=0;a<e;a++)r[a]=[...t[a]];if(1===e)return r[0][0];if(2===e)return r[0][0]*r[1][1]-r[0][1]*r[1][0];let a=1;for(let t=0;t<e-1;t+=1){let n=t;for(let a=t+1;a<e;a+=1)Math.abs(r[a][t])>Math.abs(r[n][t])&&(n=a);if(w(r[n][t]))return 0;n!==t&&([r[t],r[n]]=[r[n],r[t]],a=-a);for(let a=t+1;a<e;a+=1){const n=r[a][t]/r[t][t];for(let i=t;i<e;i++)r[a][i]-=n*r[t][i]}}let n=a;for(let t=0;t<e;t++)n*=r[t][t];return n}function T(t,e,r){const a=t.length,n=[];for(let i=0;i<a;i++)if(i!==e){const e=[];for(let n=0;n<a;n++)n!==r&&e.push(t[i][n]);n.push(e)}return n}function $(t){const e=t.length,r=[];for(let a=0;a<e;a++){r[a]=[];for(let n=0;n<e;n++){const e=(-1)**(a+n)*A(T(t,n,a));r[a][n]=e}}return r}function C(t){return t.length===t[0].length}function M(t){if(!C(t))return!1;const e=t.length;for(let r=0;r<e;r++)for(let a=0;a<e;a++)if(r===a){if(!v(t[r][a],1))return!1}else if(!w(t[r][a]))return!1;return!0}function q(t,e){if(0===t.length||0===e.length||t[0].length!==e.length)throw new Error("Matrix dimensions do not match for multiplication");const r=t.length,a=t[0].length,n=e[0].length,i=Array(r).fill(0).map(()=>Array(n).fill(0));for(let o=0;o<r;o++)for(let r=0;r<a;r++){const a=t[o][r];for(let t=0;t<n;t++)i[o][t]+=a*e[r][t]}return i}const j={mul:{evaluate:([t,r],a)=>{y(t,a),y(r,a);try{return q(t,r)}catch(n){throw new e(`The number of columns in the first matrix must be equal to the number of rows in the second matrix, but got ${t[0].length} and ${r.length}`,a)}},arity:N(2)},det:{evaluate:([t],e)=>(b(t,e),A(t)),arity:N(1)},inv:{evaluate:([t],r)=>{b(t,r);const a=function(t){const e=t.length;if(1===e){const e=t[0][0];return w(e)?null:[[1/e]]}const r=A(t);if(w(r))return null;const a=$(t),n=[];for(let t=0;t<e;t++){n[t]=[];for(let i=0;i<e;i++)n[t][i]=a[t][i]/r}return n}(t);if(null===a)throw new e("The matrix must be invertible",r);return a},arity:N(1)},adj:{evaluate:([t],e)=>(b(t,e),$(t)),arity:N(1)},cofactor:{evaluate:([t],e)=>(b(t,e),function(t){const e=t.length,r=[];for(let a=0;a<e;a++){r[a]=[];for(let n=0;n<e;n++){const e=T(t,a,n),i=(-1)**(a+n);r[a][n]=i*A(e)}}return r}(t)),arity:N(1)},minor:{evaluate:([t,e,r],a)=>(y(t,a),s(e,a,{integer:!0,nonNegative:!0,lte:t.length}),s(r,a,{integer:!0,nonNegative:!0,lte:t[0].length}),T(t,e,r)),arity:N(3)},trace:{evaluate:([t],e)=>(b(t,e),function(t){return t.reduce((t,e,r)=>t+e[r],0)}(t)),arity:N(1)},"symmetric?":{evaluate:([t],e)=>(y(t,e),function(t){const e=t.length;if(!C(t))return!1;for(let r=0;r<e;r+=1)for(let e=0;e<r;e+=1)if(t[r][e]!==t[e][r])return!1;return!0}(t)),arity:N(1)},"triangular?":{evaluate:([t],e)=>(y(t,e),function(t){if(!C(t))return!1;const e=t.length;let r=!0,a=!0;for(let n=0;n<e;n++)for(let i=0;i<e;i++){if(n>i&&0!==t[n][i]&&(r=!1,!a))return!1;n<i&&0!==t[n][i]&&(a=!1)}return r||a}(t)),arity:N(1)},"upper-triangular?":{evaluate:([t],e)=>(y(t,e),function(t){if(!C(t))return!1;const e=t.length;for(let r=0;r<e;r++)for(let e=0;e<r;e++)if(0!==t[r][e])return!1;return!0}(t)),arity:N(1)},"lower-triangular?":{evaluate:([t],e)=>(y(t,e),function(t){if(!C(t))return!1;const e=t.length;if(!t.every(t=>t.length===e))return!1;for(let r=0;r<e;r++)for(let a=r+1;a<e;a++)if(0!==t[r][a])return!1;return!0}(t)),arity:N(1)},"diagonal?":{evaluate:([t],e)=>(y(t,e),function(t){if(!C(t))return!1;const e=t.length;for(let r=0;r<e;r+=1)for(let a=0;a<e;a+=1)if(r!==a&&0!==t[r][a])return!1;return!0}(t)),arity:N(1)},"square?":{evaluate:([t],e)=>(y(t,e),C(t)),arity:N(1)},"orthogonal?":{evaluate:([t],e)=>(y(t,e),function(t){return!!C(t)&&M(q(t,function(t){const e=[];for(let r=0;r<t[0].length;r+=1){const a=[];for(let e=0;e<t.length;e+=1)a.push(t[e][r]);e.push(a)}return e}(t)))}(t)),arity:N(1)},"identity?":{evaluate:([t],e)=>(y(t,e),M(t)),arity:N(1)},"invertible?":{evaluate:([t],e)=>(y(t,e),!!function(t){return!!h(t)&&t.length===t[0].length}(t)&&!w(A(t))),arity:N(1)},hilbert:{evaluate:([t],e)=>{s(t,e,{integer:!0,positive:!0});const r=[];for(let e=0;e<t;e+=1){const a=[];for(let r=0;r<t;r+=1)a.push(1/(e+r+1));r.push(a)}return r},arity:N(1)},vandermonde:{evaluate:([t],e)=>{g(t,e);const r=[];for(let e=0;e<t.length;e+=1){const a=[];for(let r=0;r<t.length;r+=1)a.push(t[e]**r);r.push(a)}return r},arity:N(1)},band:{evaluate:([t,e,r],a)=>(s(t,a,{integer:!0,positive:!0}),s(e,a,{integer:!0,nonNegative:!0,lt:t}),s(r,a,{integer:!0,nonNegative:!0,lte:t}),function(t,e,r){const a=Array.from({length:t},()=>Array.from({length:t},()=>0));for(let n=0;n<t;n++)for(let i=Math.max(0,n-e);i<=Math.min(t-1,n+r);i++)a[n][i]=1;return a}(t,e,r)),arity:N(3)},"banded?":{evaluate:([t,e,r],a)=>{y(t,a);const n=Math.max(t.length,t[0].length);return s(e,a,{integer:!0,nonNegative:!0,lt:n}),s(r,a,{integer:!0,nonNegative:!0,lt:n}),function(t,e,r){const a=t.length,n=t[0].length;for(let i=0;i<a;i++)for(let a=0;a<n;a++)if(0!==t[i][a]&&(i-a>e||a-i>r))return!1;return!0}(t,e,r)},arity:N(3)},rank:{evaluate:([t],e)=>{y(t,e);const[,r]=function(t){const e=t.map(t=>[...t]),r=e.length,a=e[0].length;let n=0,i=0;for(let t=0;t<a;t++){let o=-1;for(let a=i;a<r;a++)if(!w(e[a][t])){o=a;break}if(-1===o)continue;n+=1,o!==i&&([e[o],e[i]]=[e[i],e[o]]);const m=e[i][t];for(let r=t;r<a;r++)e[i][r]/=m;for(let n=0;n<r;n++)if(n!==i&&!w(e[n][t])){const r=e[n][t];for(let o=t;o<a;o++)e[n][o]-=r*e[i][o]}if(i++,i===r)break}return[e,n]}(t);return r},arity:N(1)},"frobenius-norm":{evaluate:([t],e)=>(y(t,e),Math.sqrt(t.reduce((t,e)=>t+e.reduce((t,e)=>t+e*e,0),0))),arity:N(1)},"one-norm":{evaluate:([t],e)=>(y(t,e),function(t){const e=t.length,r=t[0].length;let a=0;for(let n=0;n<r;n+=1){let r=0;for(let a=0;a<e;a+=1)r+=Math.abs(t[a][n]);a=Math.max(a,r)}return a}(t)),arity:N(1)},"inf-norm":{evaluate:([t],e)=>(y(t,e),t.reduce((t,e)=>Math.max(t,e.reduce((t,e)=>t+Math.abs(e),0)),0)),arity:N(1)},"max-norm":{evaluate:([t],e)=>(y(t,e),t.reduce((t,e)=>{const r=e.reduce((t,e)=>Math.max(t,Math.abs(e)),0);return Math.max(t,r)},0)),arity:N(1)}};for(const[t,e]of Object.entries(k))j[t]&&(j[t].docs=e);const S={name:"matrix",functions:j};exports.matrixModule=S;
2
2
  //# sourceMappingURL=matrix.js.map