@mojir/lits 2.3.0 → 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.
- package/README.md +19 -23
- package/dist/bundler.esm.js +2 -0
- package/dist/bundler.esm.js.map +1 -0
- package/dist/bundler.js +2 -0
- package/dist/bundler.js.map +1 -0
- package/dist/cli/cli/src/js-interop/Cli/Fs/index.d.ts +2 -2
- package/dist/cli/cli/src/js-interop/Cli/Proc/index.d.ts +2 -2
- package/dist/cli/cli/src/js-interop/Cli/index.d.ts +2 -3
- package/dist/cli/cli.js +2861 -2542
- package/dist/cli/reference/api.d.ts +5 -5
- package/dist/cli/reference/examples.d.ts +2 -2
- package/dist/cli/reference/index.d.ts +8 -3
- package/dist/cli/src/Lits/Lits.d.ts +6 -7
- package/dist/cli/src/builtin/index.d.ts +1 -1
- package/dist/cli/src/builtin/specialExpressionTypes.d.ts +15 -15
- package/dist/cli/src/builtin/specialExpressions/import.d.ts +6 -0
- package/dist/cli/src/bundler/index.d.ts +9 -0
- package/dist/cli/src/bundler/interface.d.ts +15 -0
- package/dist/cli/src/bundler.d.ts +3 -0
- package/dist/cli/src/evaluator/ContextStack.d.ts +10 -4
- package/dist/cli/src/index.d.ts +2 -0
- package/dist/cli/src/js-interop/Cli/Fs/index.d.ts +2 -2
- package/dist/cli/src/js-interop/Cli/Proc/index.d.ts +2 -2
- package/dist/cli/src/js-interop/Cli/index.d.ts +2 -3
- package/dist/cli/src/parser/ParserContext.d.ts +1 -1
- package/dist/cli/src/parser/getPrecedence.d.ts +3 -0
- package/dist/cli/src/parser/index.d.ts +2 -0
- package/dist/cli/src/parser/subParsers/parseExpression.d.ts +5 -0
- package/dist/cli/src/parser/types.d.ts +0 -3
- package/dist/cli/src/tokenizer/operators.d.ts +2 -2
- package/dist/cli/src/tokenizer/reservedNames.d.ts +0 -1
- package/dist/full.esm.js +1 -1
- package/dist/full.esm.js.map +1 -1
- package/dist/full.js +1 -1
- package/dist/full.js.map +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lits.iife.js +1 -1
- package/dist/lits.iife.js.map +1 -1
- package/dist/modules/assert.esm.js +1 -1
- package/dist/modules/assert.esm.js.map +1 -1
- package/dist/modules/assert.js +1 -1
- package/dist/modules/assert.js.map +1 -1
- package/dist/modules/bitwise.esm.js +1 -1
- package/dist/modules/bitwise.esm.js.map +1 -1
- package/dist/modules/bitwise.js +1 -1
- package/dist/modules/bitwise.js.map +1 -1
- package/dist/modules/cli/src/js-interop/Cli/Fs/index.d.ts +2 -2
- package/dist/modules/cli/src/js-interop/Cli/Proc/index.d.ts +2 -2
- package/dist/modules/cli/src/js-interop/Cli/index.d.ts +2 -3
- package/dist/modules/collection.esm.js +1 -1
- package/dist/modules/collection.esm.js.map +1 -1
- package/dist/modules/collection.js +1 -1
- package/dist/modules/collection.js.map +1 -1
- package/dist/modules/functional.esm.js +1 -1
- package/dist/modules/functional.esm.js.map +1 -1
- package/dist/modules/functional.js +1 -1
- package/dist/modules/functional.js.map +1 -1
- package/dist/modules/grid.esm.js +1 -1
- package/dist/modules/grid.esm.js.map +1 -1
- package/dist/modules/grid.js +1 -1
- package/dist/modules/grid.js.map +1 -1
- package/dist/modules/linear-algebra.esm.js +1 -1
- package/dist/modules/linear-algebra.esm.js.map +1 -1
- package/dist/modules/linear-algebra.js +1 -1
- package/dist/modules/linear-algebra.js.map +1 -1
- package/dist/modules/math.esm.js +1 -1
- package/dist/modules/math.esm.js.map +1 -1
- package/dist/modules/math.js +1 -1
- package/dist/modules/math.js.map +1 -1
- package/dist/modules/matrix.esm.js +1 -1
- package/dist/modules/matrix.esm.js.map +1 -1
- package/dist/modules/matrix.js +1 -1
- package/dist/modules/matrix.js.map +1 -1
- package/dist/modules/number-theory.esm.js +1 -1
- package/dist/modules/number-theory.esm.js.map +1 -1
- package/dist/modules/number-theory.js +1 -1
- package/dist/modules/number-theory.js.map +1 -1
- package/dist/modules/random.esm.js +1 -1
- package/dist/modules/random.esm.js.map +1 -1
- package/dist/modules/random.js +1 -1
- package/dist/modules/random.js.map +1 -1
- package/dist/modules/reference/api.d.ts +5 -5
- package/dist/modules/reference/index.d.ts +8 -3
- package/dist/modules/sequence.esm.js +1 -1
- package/dist/modules/sequence.esm.js.map +1 -1
- package/dist/modules/sequence.js +1 -1
- package/dist/modules/sequence.js.map +1 -1
- package/dist/modules/src/Lits/Lits.d.ts +6 -7
- package/dist/modules/src/builtin/index.d.ts +1 -1
- package/dist/modules/src/builtin/specialExpressionTypes.d.ts +15 -15
- package/dist/modules/src/builtin/specialExpressions/import.d.ts +6 -0
- package/dist/modules/src/bundler/index.d.ts +9 -0
- package/dist/modules/src/bundler/interface.d.ts +15 -0
- package/dist/modules/src/bundler.d.ts +3 -0
- package/dist/modules/src/evaluator/ContextStack.d.ts +10 -4
- package/dist/modules/src/index.d.ts +2 -0
- package/dist/modules/src/parser/ParserContext.d.ts +1 -1
- package/dist/modules/src/parser/getPrecedence.d.ts +3 -0
- package/dist/modules/src/parser/index.d.ts +2 -0
- package/dist/modules/src/parser/subParsers/parseExpression.d.ts +5 -0
- package/dist/modules/src/parser/types.d.ts +0 -3
- package/dist/modules/src/tokenizer/operators.d.ts +2 -2
- package/dist/modules/src/tokenizer/reservedNames.d.ts +0 -1
- package/dist/modules/string.esm.js +1 -1
- package/dist/modules/string.esm.js.map +1 -1
- package/dist/modules/string.js +1 -1
- package/dist/modules/string.js.map +1 -1
- package/dist/modules/vector.esm.js +1 -1
- package/dist/modules/vector.esm.js.map +1 -1
- package/dist/modules/vector.js +1 -1
- package/dist/modules/vector.js.map +1 -1
- package/dist/reference/api.d.ts +5 -5
- package/dist/reference/index.d.ts +8 -3
- package/dist/src/Lits/Lits.d.ts +6 -7
- package/dist/src/builtin/index.d.ts +1 -1
- package/dist/src/builtin/specialExpressionTypes.d.ts +15 -15
- package/dist/src/builtin/specialExpressions/import.d.ts +6 -0
- package/dist/src/bundler/index.d.ts +9 -0
- package/dist/src/bundler/interface.d.ts +15 -0
- package/dist/src/bundler.d.ts +3 -0
- package/dist/src/evaluator/ContextStack.d.ts +10 -4
- package/dist/src/index.d.ts +2 -0
- package/dist/src/parser/ParserContext.d.ts +1 -1
- package/dist/src/parser/getPrecedence.d.ts +3 -0
- package/dist/src/parser/index.d.ts +2 -0
- package/dist/src/parser/subParsers/parseExpression.d.ts +5 -0
- package/dist/src/parser/types.d.ts +0 -3
- package/dist/src/tokenizer/operators.d.ts +2 -2
- package/dist/src/tokenizer/reservedNames.d.ts +0 -1
- package/dist/testFramework.esm.js +1 -1
- package/dist/testFramework.esm.js.map +1 -1
- package/dist/testFramework.js +1 -1
- package/dist/testFramework.js.map +1 -1
- package/package.json +6 -1
- package/dist/cli/cli/src/js-interop/utils.d.ts +0 -2
- package/dist/cli/src/builtin/specialExpressions/def.d.ts +0 -6
- package/dist/cli/src/js-interop/utils.d.ts +0 -2
- package/dist/cli/src/parser/subParsers/getPrecedence.d.ts +0 -3
- package/dist/modules/cli/src/js-interop/utils.d.ts +0 -2
- package/dist/modules/src/builtin/specialExpressions/def.d.ts +0 -6
- package/dist/modules/src/parser/subParsers/getPrecedence.d.ts +0 -3
- package/dist/src/builtin/specialExpressions/def.d.ts +0 -6
- package/dist/src/parser/subParsers/getPrecedence.d.ts +0 -3
package/dist/modules/math.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"math.js","sources":["../../src/utils/debug/getCodeMarker.ts","../../src/errors.ts","../../src/constants/constants.ts","../../src/typeGuards/number.ts","../../src/typeGuards/annotatedArrays.ts","../../src/utils/arity.ts","../../src/builtin/modules/math/index.ts"],"sourcesContent":["import type { SourceCodeInfo } from '../../tokenizer/token'\n\nexport function getCodeMarker(sourceCodeInfo: SourceCodeInfo): string {\n if (!sourceCodeInfo.position || !sourceCodeInfo.code)\n return ''\n\n const leftPadding = sourceCodeInfo.position.column - 1\n const rightPadding = sourceCodeInfo.code.length - leftPadding - 1\n return `${' '.repeat(Math.max(leftPadding, 0))}^${' '.repeat(Math.max(rightPadding, 0))}`\n}\n","import { getCodeMarker } from '../src/utils/debug/getCodeMarker'\nimport type { Arr } from './interface'\nimport type { SourceCodeInfo } from './tokenizer/token'\n\nfunction getLitsErrorMessage(message: string, sourceCodeInfo?: SourceCodeInfo) {\n if (!sourceCodeInfo) {\n return message\n }\n const location = `${sourceCodeInfo.position.line}:${sourceCodeInfo.position.column}`\n const filePathLine = sourceCodeInfo.filePath\n ? `\\n${sourceCodeInfo.filePath}:${location}`\n : `\\nLocation ${location}`\n const codeLine = `\\n${sourceCodeInfo.code}`\n const codeMarker = `\\n${getCodeMarker(sourceCodeInfo)}`\n return `${message}${filePathLine}${codeLine}${codeMarker}`\n}\n\nexport class RecurSignal extends Error {\n public params: Arr\n constructor(params: Arr) {\n super(`recur, params: ${params}`)\n Object.setPrototypeOf(this, RecurSignal.prototype)\n this.name = 'RecurSignal'\n this.params = params\n }\n}\n\nexport class LitsError extends Error {\n public readonly sourceCodeInfo?: SourceCodeInfo\n public readonly shortMessage: string\n constructor(err: unknown, sourceCodeInfo: SourceCodeInfo | undefined) {\n const message = err instanceof Error\n ? err.message\n : `${err}`\n\n super(getLitsErrorMessage(message, sourceCodeInfo))\n this.shortMessage = message\n this.sourceCodeInfo = sourceCodeInfo\n Object.setPrototypeOf(this, LitsError.prototype)\n this.name = 'LitsError'\n }\n\n public getCodeMarker(): string | undefined {\n return this.sourceCodeInfo && getCodeMarker(this.sourceCodeInfo)\n }\n}\n\nexport class UserDefinedError extends LitsError {\n public userMessage: string\n constructor(message: string, sourceCodeInfo?: SourceCodeInfo) {\n super(message, sourceCodeInfo)\n this.userMessage = message\n Object.setPrototypeOf(this, UserDefinedError.prototype)\n this.name = 'UserDefinedError'\n }\n}\n\nexport class AssertionError extends LitsError {\n constructor(message: string | Error, sourceCodeInfo?: SourceCodeInfo) {\n super(message, sourceCodeInfo)\n Object.setPrototypeOf(this, AssertionError.prototype)\n this.name = 'AssertionError'\n }\n}\n\nexport class UndefinedSymbolError extends LitsError {\n public symbol: string\n constructor(symbolName: string, sourceCodeInfo?: SourceCodeInfo) {\n const message = `Undefined symbol '${symbolName}'.`\n super(message, sourceCodeInfo)\n this.symbol = symbolName\n Object.setPrototypeOf(this, UndefinedSymbolError.prototype)\n this.name = 'UndefinedSymbolError'\n }\n}\n\nexport function isLitsError(error: unknown): error is LitsError {\n return error instanceof LitsError\n}\n","export const NodeTypes = {\n Number: 1,\n String: 2,\n NormalExpression: 3,\n SpecialExpression: 4,\n UserDefinedSymbol: 5,\n NormalBuiltinSymbol: 6,\n SpecialBuiltinSymbol: 7,\n ReservedSymbol: 8,\n Binding: 9,\n Spread: 10,\n} as const\n\nconst NodeTypesSet = new Set(Object.values(NodeTypes))\n\nexport type NodeType = typeof NodeTypes[keyof typeof NodeTypes]\n\nexport function getNodeTypeName(type: NodeType): keyof typeof NodeTypes {\n return Object.keys(NodeTypes).find(key => NodeTypes[key as keyof typeof NodeTypes] === type) as keyof typeof NodeTypes\n}\n\n// TODO, is this needed?\nexport function isNodeType(type: unknown): type is NodeType {\n return typeof type === 'number' && NodeTypesSet.has(type as NodeType)\n}\n\nconst functionTypes = [\n 'UserDefined',\n 'Partial',\n 'Comp',\n 'Constantly',\n 'Juxt',\n 'Complement',\n 'EveryPred',\n 'SomePred',\n 'Fnull',\n 'Builtin',\n 'SpecialBuiltin',\n 'NativeJsFunction',\n 'Module',\n] as const\n\nconst functionTypeSet = new Set(functionTypes)\n\nexport type FunctionType = typeof functionTypes[number]\n\nexport function isFunctionType(type: unknown): type is FunctionType {\n return typeof type === 'string' && functionTypeSet.has(type as FunctionType)\n}\n","import { LitsError } from '../errors'\nimport type { SourceCodeInfo } from '../tokenizer/token'\nimport { valueToString } from '../utils/debug/debugTools'\nimport { getSourceCodeInfo } from '../utils/debug/getSourceCodeInfo'\n\ntype SignOptions =\n | {\n positive?: true\n negative?: never\n nonPositive?: never\n nonNegative?: never\n zero?: never\n nonZero?: never\n }\n | {\n positive?: never\n negative?: true\n nonPositive?: never\n nonNegative?: never\n zero?: never\n nonZero?: never\n }\n | {\n positive?: never\n negative?: never\n nonPositive?: true\n nonNegative?: never\n zero?: never\n nonZero?: never\n }\n | {\n positive?: never\n negative?: never\n nonPositive?: never\n nonNegative?: true\n zero?: never\n nonZero?: never\n }\n | {\n positive?: never\n negative?: never\n nonPositive?: never\n nonNegative?: never\n zero?: true\n nonZero?: never\n }\n | {\n positive?: never\n negative?: never\n nonPositive?: never\n nonNegative?: never\n zero?: never\n nonZero?: true\n }\n\ntype GtOptions =\n | {\n gt?: number\n gte?: never\n }\n | {\n gt?: never\n gte?: number\n }\n\ntype LtOptions =\n | {\n lt?: number\n lte?: never\n }\n | {\n lt?: never\n lte?: number\n }\n\ntype NumberOptions = {\n integer?: true\n finite?: true\n} & SignOptions &\nGtOptions &\nLtOptions\n\nfunction getRangeString(options: NumberOptions): string {\n const hasUpperAndLowerBound\n = (typeof options.gt === 'number' || typeof options.gte === 'number')\n && (typeof options.lt === 'number' || typeof options.lte === 'number')\n if (hasUpperAndLowerBound) {\n return `${typeof options.gt === 'number' ? `${options.gt} < n ` : `${options.gte} <= n `}${\n typeof options.lt === 'number' ? `< ${options.lt}` : `<= ${options.lte}`\n }`\n }\n else if (typeof options.gt === 'number' || typeof options.gte === 'number') {\n return `${typeof options.gt === 'number' ? `n > ${options.gt}` : `n >= ${options.gte}`}`\n }\n else if (typeof options.lt === 'number' || typeof options.lte === 'number') {\n return `${typeof options.lt === 'number' ? `n < ${options.lt}` : `n <= ${options.lte}`}`\n }\n else { return '' }\n}\n\nfunction getSignString(options: NumberOptions): string {\n return options.positive\n ? 'positive'\n : options.negative\n ? 'negative'\n : options.nonNegative\n ? 'non negative'\n : options.nonPositive\n ? 'non positive'\n : options.nonZero\n ? 'non zero'\n : ''\n}\n\nfunction getNumberTypeName(options: NumberOptions): string {\n if (options.zero)\n return 'zero'\n\n const sign = getSignString(options)\n const numberType = options.integer ? 'integer' : 'number'\n const finite = options.finite ? 'finite' : ''\n const range = getRangeString(options)\n\n return [sign, finite, numberType, range].filter(x => !!x).join(' ')\n}\n\nexport function isNumber(value: unknown, options: NumberOptions = {}): value is number {\n if (typeof value !== 'number')\n return false\n\n if (Number.isNaN(value))\n return false\n\n if (options.integer && !Number.isInteger(value))\n return false\n\n if (options.finite && !Number.isFinite(value))\n return false\n\n if (options.zero && value !== 0)\n return false\n\n if (options.nonZero && value === 0)\n return false\n\n if (options.positive && value <= 0)\n return false\n\n if (options.negative && value >= 0)\n return false\n\n if (options.nonPositive && value > 0)\n return false\n\n if (options.nonNegative && value < 0)\n return false\n\n if (typeof options.gt === 'number' && value <= options.gt)\n return false\n\n if (typeof options.gte === 'number' && value < options.gte)\n return false\n\n if (typeof options.lt === 'number' && value >= options.lt)\n return false\n\n if (typeof options.lte === 'number' && value > options.lte)\n return false\n\n return true\n}\n\nexport function assertNumber(\n value: unknown,\n sourceCodeInfo?: SourceCodeInfo,\n options: NumberOptions = {},\n): asserts value is number {\n if (!isNumber(value, options)) {\n throw new LitsError(\n `Expected ${getNumberTypeName(options)}, got ${valueToString(value)}.`,\n getSourceCodeInfo(value, sourceCodeInfo),\n )\n }\n}\n\nexport function asNumber(\n value: unknown,\n sourceCodeInfo: SourceCodeInfo | undefined,\n options: NumberOptions = {},\n): number {\n assertNumber(value, sourceCodeInfo, options)\n return value\n}\n","import { LitsError } from '../errors'\nimport type { Any } from '../interface'\nimport type { SourceCodeInfo } from '../tokenizer/token'\nimport { isNumber } from './number'\n\nconst annotatedArrays = new WeakSet<unknown[]>()\nconst vectors = new WeakSet<unknown[]>()\nconst notVectors = new WeakSet<unknown[]>()\nconst matrices = new WeakSet<unknown[]>()\nconst notMatrices = new WeakSet<unknown[]>()\nconst grids = new WeakSet<unknown[]>()\nconst notGrids = new WeakSet<unknown[]>()\n\nexport function annotate<T>(value: T): T {\n if (!Array.isArray(value)) {\n return value\n }\n if (annotatedArrays.has(value)) {\n return value\n }\n isVector(value)\n if (!isMatrix(value)) {\n isGrid(value)\n }\n\n return value\n}\nexport function isVector(vector: unknown): vector is number[] {\n if (!Array.isArray(vector)) {\n return false\n }\n\n if (vectors.has(vector)) {\n return true\n }\n if (notVectors.has(vector)) {\n return false\n }\n\n if (vector.every(elem => isNumber(elem))) {\n annotatedArrays.add(vector)\n vectors.add(vector)\n return true\n }\n notVectors.add(vector)\n return false\n}\n\nexport function assertVector(vector: unknown, sourceCodeInfo: SourceCodeInfo | undefined): asserts vector is number[] {\n if (!isVector(vector)) {\n throw new LitsError(`Expected a vector, but got ${vector}`, sourceCodeInfo)\n }\n}\n\nexport function is2dVector(vector: unknown): vector is [number, number] {\n if (!isVector(vector)) {\n return false\n }\n return vector.length === 2\n}\nexport function assert2dVector(vector: unknown, sourceCodeInfo: SourceCodeInfo | undefined): asserts vector is [number, number] {\n if (!is2dVector(vector)) {\n throw new LitsError(`Expected a 2d vector, but got ${vector}`, sourceCodeInfo)\n }\n}\n\nexport function is3dVector(vector: unknown): vector is [number, number, number] {\n if (!isVector(vector)) {\n return false\n }\n return vector.length === 3\n}\nexport function assert3dVector(vector: unknown, sourceCodeInfo: SourceCodeInfo | undefined): asserts vector is [number, number, number] {\n if (!is3dVector(vector)) {\n throw new LitsError(`Expected a 3d vector, but got ${vector}`, sourceCodeInfo)\n }\n}\n\nexport function assertNonEmptyVector(vector: unknown, sourceCodeInfo: SourceCodeInfo | undefined): asserts vector is number[] {\n assertVector(vector, sourceCodeInfo)\n if (vector.length === 0) {\n throw new LitsError(`Expected a non empty vector, but got ${vector}`, sourceCodeInfo)\n }\n}\n\nexport function isGrid(grid: unknown): grid is unknown[][] {\n if (!Array.isArray(grid)) {\n return false\n }\n if (grids.has(grid)) {\n return true\n }\n if (notGrids.has(grid)) {\n return false\n }\n if (grid.length === 0) {\n notGrids.add(grid)\n return false\n }\n if (!Array.isArray(grid[0])) {\n notGrids.add(grid)\n return false\n }\n const nbrOfCols = grid[0].length\n for (const row of grid.slice(1)) {\n if (!Array.isArray(row)) {\n notGrids.add(grid)\n return false\n }\n if (row.length !== nbrOfCols) {\n notGrids.add(grid)\n return false\n }\n }\n annotatedArrays.add(grid)\n grids.add(grid)\n return true\n}\n\nexport function assertGrid(grid: unknown, sourceCodeInfo: SourceCodeInfo | undefined): asserts grid is Any[][] {\n if (!isGrid(grid)) {\n throw new LitsError(`Expected a grid, but got ${grid}`, sourceCodeInfo)\n }\n}\n\nexport function isMatrix(matrix: unknown): matrix is number[][] {\n if (!Array.isArray(matrix)) {\n return false\n }\n if (matrices.has(matrix)) {\n return true\n }\n if (notMatrices.has(matrix)) {\n return false\n }\n if (matrix.length === 0) {\n notMatrices.add(matrix)\n return false\n }\n if (!Array.isArray(matrix[0]) || matrix[0].length === 0) {\n notMatrices.add(matrix)\n return false\n }\n const nbrOfCols = matrix[0].length\n for (const row of matrix) {\n if (!Array.isArray(row) || row.length !== nbrOfCols || row.some(cell => !isNumber(cell))) {\n notMatrices.add(matrix)\n return false\n }\n }\n annotatedArrays.add(matrix)\n grids.add(matrix)\n matrices.add(matrix)\n return true\n}\n\nexport function assertMatrix(matrix: unknown, sourceCodeInfo: SourceCodeInfo | undefined): asserts matrix is number[][] {\n if (!isMatrix(matrix)) {\n throw new LitsError(`Expected a matrix, but got ${matrix}`, sourceCodeInfo)\n }\n}\n\nexport function assertSquareMatrix(matrix: unknown, sourceCodeInfo: SourceCodeInfo | undefined): asserts matrix is number[][] {\n if (!isMatrix(matrix)) {\n throw new LitsError(`Expected a matrix, but got ${matrix}`, sourceCodeInfo)\n }\n if (matrix.length !== matrix[0]!.length) {\n throw new LitsError(`Expected square matrix, but got ${matrix.length} and ${matrix[0]!.length}`, sourceCodeInfo)\n }\n}\n\nexport function isSquareMatrix(matrix: unknown): matrix is number[][] {\n if (!isMatrix(matrix)) {\n return false\n }\n if (matrix.length !== matrix[0]!.length) {\n return false\n }\n return true\n}\n","import type { Arity } from '../builtin/interface'\nimport { LitsError } from '../errors'\nimport type { FunctionLike } from '../parser/types'\nimport type { SourceCodeInfo } from '../tokenizer/token'\nimport { isColl } from '../typeGuards/lits'\nimport { valueToString } from './debug/debugTools'\n\nexport function arityAccepts(arity: Arity, nbrOfParams: number): boolean {\n const { min, max } = arity\n if (typeof min === 'number' && nbrOfParams < min) {\n return false\n }\n if (typeof max === 'number' && nbrOfParams > max) {\n return false\n }\n return true\n}\n\nexport function arityAcceptsMin(arity: Arity, nbrOfParams: number): boolean {\n const { min } = arity\n if (typeof min === 'number' && nbrOfParams < min) {\n return false\n }\n return true\n}\n\nexport function getCommonArityFromFunctions(params: FunctionLike[]): Arity | null {\n return params.reduce((acc: Arity | null, param): Arity | null => {\n if (acc === null) {\n return null\n }\n const arity: Arity = (typeof param === 'number' || isColl(param)) ? toFixedArity(1) : param.arity\n const { min: aMin, max: aMax } = arity\n const { min: bMin, max: bMax } = acc\n const min = typeof aMin === 'number' && typeof bMin === 'number'\n ? Math.max(aMin, bMin)\n : typeof aMin === 'number' ? aMin : typeof bMin === 'number' ? bMin : undefined\n const max = typeof aMax === 'number' && typeof bMax === 'number'\n ? Math.min(aMax, bMax)\n : typeof aMax === 'number' ? aMax : typeof bMax === 'number' ? bMax : undefined\n\n if (typeof min === 'number' && typeof max === 'number' && min > max) {\n return null\n }\n\n return { min, max }\n }, {})\n}\n\nexport function getArityFromFunction(param: FunctionLike): Arity {\n return (typeof param === 'number' || isColl(param)) ? toFixedArity(1) : param.arity\n}\n\nexport function assertNumberOfParams(arity: Arity, length: number, sourceCodeInfo: SourceCodeInfo | undefined): void {\n const { min, max } = arity\n if (typeof min === 'number' && length < min) {\n throw new LitsError(\n `Wrong number of arguments, expected at least ${min}, got ${valueToString(length)}.`,\n sourceCodeInfo,\n )\n }\n\n if (typeof max === 'number' && length > max) {\n throw new LitsError(\n `Wrong number of arguments, expected at most ${max}, got ${valueToString(length)}.`,\n sourceCodeInfo,\n )\n }\n}\n\nexport function canBeOperator(count: Arity): boolean {\n if (typeof count.max === 'number' && count.max < 2) {\n return false\n }\n\n if (typeof count.min === 'number' && count.min > 2) {\n return false\n }\n\n return true\n}\n\nexport function toFixedArity(arity: number): Arity {\n return { min: arity, max: arity }\n}\n","import type { SourceCodeInfo } from '../../../tokenizer/token'\nimport { isMatrix, isVector } from '../../../typeGuards/annotatedArrays'\nimport { isNumber } from '../../../typeGuards/number'\nimport { toFixedArity } from '../../../utils/arity'\nimport { LitsError } from '../../../errors'\nimport type { BuiltinNormalExpressions } from '../../interface'\nimport type { LitsModule } from '../interface'\n\ntype NumberVectorOrMatrix = number | number[] | number[][]\n\nfunction getNumberVectorOrMatrixOperation(\n param: unknown,\n sourceCodeInfo: SourceCodeInfo | undefined,\n):\n | ['number', number]\n | ['vector', number[]]\n | ['matrix', number[][]] {\n if (isVector(param)) {\n return ['vector', param]\n }\n if (isMatrix(param)) {\n return ['matrix', param]\n }\n if (!isNumber(param)) {\n throw new LitsError(`Invalid parameter type: ${typeof param}`, sourceCodeInfo)\n }\n return ['number', param]\n}\n\nfunction unaryMathOp(\n fn: (val: number) => number,\n): (params: unknown[], sourceCodeInfo: SourceCodeInfo | undefined) => NumberVectorOrMatrix {\n return ([param], sourceCodeInfo) => {\n const [operation, operand] = getNumberVectorOrMatrixOperation(param, sourceCodeInfo)\n if (operation === 'number') {\n return fn(operand)\n }\n else if (operation === 'vector') {\n return operand.map(val => fn(val))\n }\n else {\n return operand.map(row => row.map(val => fn(val)))\n }\n }\n}\n\nconst mathUtilsFunctions: BuiltinNormalExpressions = {\n 'sin': {\n evaluate: unaryMathOp(val => Math.sin(val)),\n arity: toFixedArity(1),\n docs: {\n category: 'math',\n returns: { type: ['number', 'vector', 'matrix'] },\n args: {\n x: { type: ['number', 'vector', 'matrix'] },\n },\n variants: [{ argumentNames: ['x'] }],\n description: 'The `sin` function computes the sine of an angle (in radians), working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the sine of each element while preserving the original structure.',\n seeAlso: ['math.asin', 'math.sinh', 'math.cos', 'math.tan', 'math.to-rad'],\n examples: [\n 'let { sin } = import(\"math\"); sin(0)',\n 'let { sin } = import(\"math\"); sin(1)',\n 'let { sin } = import(\"math\"); sin(PI)',\n 'let { sin } = import(\"math\"); sin(-0.5)',\n 'let { sin } = import(\"math\"); sin([1, 2, 3])',\n 'let { sin } = import(\"math\"); sin([[1, 2], [3, 4]])',\n ],\n },\n },\n 'asin': {\n evaluate: unaryMathOp(val => Math.asin(val)),\n arity: toFixedArity(1),\n docs: {\n category: 'math',\n returns: { type: ['number', 'vector', 'matrix'] },\n args: {\n x: { type: ['number', 'vector', 'matrix'] },\n },\n variants: [{ argumentNames: ['x'] }],\n description: 'The `asin` function computes the arcsine (inverse sine) of a `number` in radians, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the arcsine of each element while preserving the original structure.',\n seeAlso: ['math.sin', 'math.asinh', 'math.acos', 'math.atan'],\n examples: [\n 'let { asin } = import(\"math\"); asin(0)',\n 'let { asin } = import(\"math\"); asin(1)',\n 'let { asin } = import(\"math\"); asin(-0.5)',\n 'let { asin } = import(\"math\"); asin([1, 2, 3])',\n 'let { asin } = import(\"math\"); asin([[1, 2], [3, 4]])',\n ],\n },\n },\n 'sinh': {\n evaluate: unaryMathOp(val => Math.sinh(val)),\n arity: toFixedArity(1),\n docs: {\n category: 'math',\n returns: { type: ['number', 'vector', 'matrix'] },\n args: {\n x: { type: ['number', 'vector', 'matrix'] },\n },\n variants: [{ argumentNames: ['x'] }],\n description: 'The `sinh` function computes the hyperbolic sine of a `number`, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the hyperbolic sine of each element while preserving the original structure.',\n seeAlso: ['math.asinh', 'math.sin', 'math.cosh', 'math.tanh'],\n examples: [\n 'let { sinh } = import(\"math\"); sinh(0)',\n 'let { sinh } = import(\"math\"); sinh(1)',\n 'let { sinh } = import(\"math\"); sinh(-0.5)',\n 'let { sinh } = import(\"math\"); sinh([0.1, 0.2, 0.3])',\n 'let { sinh } = import(\"math\"); sinh([[0.1, 0.2], [0.3, 0.4]])',\n ],\n },\n },\n 'asinh': {\n evaluate: unaryMathOp(val => Math.asinh(val)),\n arity: toFixedArity(1),\n docs: {\n category: 'math',\n returns: { type: ['number', 'vector', 'matrix'] },\n args: {\n x: { type: ['number', 'vector', 'matrix'] },\n },\n variants: [{ argumentNames: ['x'] }],\n description: 'The `asinh` function computes the inverse hyperbolic sine of a `number`, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the inverse hyperbolic sine of each element while preserving the original structure.',\n seeAlso: ['math.sinh', 'math.asin', 'math.acosh', 'math.atanh'],\n examples: [\n 'let { asinh } = import(\"math\"); asinh(10)',\n 'let { asinh } = import(\"math\"); asinh(90)',\n 'let { asinh } = import(\"math\"); asinh(50)',\n 'let { asinh } = import(\"math\"); asinh([10, 20, 30])',\n 'let { asinh } = import(\"math\"); asinh([[10, 20], [30, 40]])',\n ],\n },\n },\n 'cos': {\n evaluate: unaryMathOp(val => Math.cos(val)),\n arity: toFixedArity(1),\n docs: {\n category: 'math',\n returns: { type: ['number', 'vector', 'matrix'] },\n args: {\n x: { type: ['number', 'vector', 'matrix'] },\n },\n variants: [{ argumentNames: ['x'] }],\n description: 'The `cos` function computes the cosine of an angle (in radians), working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the cosine of each element while preserving the original structure.',\n seeAlso: ['math.acos', 'math.cosh', 'math.sin', 'math.tan', 'math.to-rad'],\n examples: [\n 'let { cos } = import(\"math\"); cos(0)',\n 'let { cos } = import(\"math\"); cos(1)',\n 'let { cos } = import(\"math\"); cos(PI)',\n 'let { cos } = import(\"math\"); cos(-0.5)',\n 'let { cos } = import(\"math\"); cos([1, 2, 3])',\n 'let { cos } = import(\"math\"); cos([[1, 2], [3, 4]])',\n ],\n },\n },\n 'acos': {\n evaluate: unaryMathOp(val => Math.acos(val)),\n arity: toFixedArity(1),\n docs: {\n category: 'math',\n returns: { type: ['number', 'vector', 'matrix'] },\n args: {\n x: { type: ['number', 'vector', 'matrix'] },\n },\n variants: [{ argumentNames: ['x'] }],\n description: 'The `acos` function computes the arccosine (inverse cosine) of a `number` in radians, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the arccosine of each element while preserving the original structure.',\n seeAlso: ['math.cos', 'math.acosh', 'math.asin', 'math.atan'],\n examples: [\n 'let { acos } = import(\"math\"); acos(0)',\n 'let { acos } = import(\"math\"); acos(1)',\n 'let { acos } = import(\"math\"); acos(-0.5)',\n 'let { acos } = import(\"math\"); acos([0.1, 0.2, 0.3])',\n 'let { acos } = import(\"math\"); acos([[0.1, 0.2], [0.3, 0.4]])',\n ],\n },\n },\n 'cosh': {\n evaluate: unaryMathOp(val => Math.cosh(val)),\n arity: toFixedArity(1),\n docs: {\n category: 'math',\n returns: { type: ['number', 'vector', 'matrix'] },\n args: {\n x: { type: ['number', 'vector', 'matrix'] },\n },\n variants: [{ argumentNames: ['x'] }],\n description: 'The `cosh` function computes the hyperbolic cosine of a `number`, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the hyperbolic cosine of each element while preserving the original structure.',\n seeAlso: ['math.acosh', 'math.cos', 'math.sinh', 'math.tanh'],\n examples: [\n 'let { cosh } = import(\"math\"); cosh(0)',\n 'let { cosh } = import(\"math\"); cosh(1)',\n 'let { cosh } = import(\"math\"); cosh(-0.5)',\n 'let { cosh } = import(\"math\"); cosh([0.1, 0.2, 0.3])',\n 'let { cosh } = import(\"math\"); cosh([[0.1, 0.2], [0.3, 0.4]])',\n ],\n },\n },\n 'acosh': {\n evaluate: unaryMathOp(val => Math.acosh(val)),\n arity: toFixedArity(1),\n docs: {\n category: 'math',\n returns: { type: ['number', 'vector', 'matrix'] },\n args: {\n x: { type: ['number', 'vector', 'matrix'] },\n },\n variants: [{ argumentNames: ['x'] }],\n description: 'The `acosh` function computes the inverse hyperbolic cosine of a `number`, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the inverse hyperbolic cosine of each element while preserving the original structure.',\n seeAlso: ['math.cosh', 'math.acos', 'math.asinh', 'math.atanh'],\n examples: [\n 'let { acosh } = import(\"math\"); acosh(1)',\n 'let { acosh } = import(\"math\"); acosh(2)',\n 'let { acosh } = import(\"math\"); acosh(100)',\n 'let { acosh } = import(\"math\"); acosh(50)',\n 'let { acosh } = import(\"math\"); acosh([1, 2, 3])',\n 'let { acosh } = import(\"math\"); acosh([[1, 2], [3, 4]])',\n ],\n },\n },\n 'tan': {\n evaluate: unaryMathOp(val => Math.tan(val)),\n arity: toFixedArity(1),\n docs: {\n category: 'math',\n returns: { type: ['number', 'vector', 'matrix'] },\n args: {\n x: { type: ['number', 'vector', 'matrix'] },\n },\n variants: [{ argumentNames: ['x'] }],\n description: 'The `tan` function computes the tangent of an angle (in radians), working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the tangent of each element while preserving the original structure.',\n seeAlso: ['math.atan', 'math.tanh', 'math.sin', 'math.cos', 'math.to-rad'],\n examples: [\n 'let { tan } = import(\"math\"); tan(0)',\n 'let { tan } = import(\"math\"); tan(1)',\n 'let { tan } = import(\"math\"); tan(PI)',\n 'let { tan } = import(\"math\"); tan(-0.5)',\n 'let { tan } = import(\"math\"); tan([1, 2, 3])',\n 'let { tan } = import(\"math\"); tan([[1, 2], [3, 4]])',\n ],\n },\n },\n 'atan': {\n evaluate: unaryMathOp(val => Math.atan(val)),\n arity: toFixedArity(1),\n docs: {\n category: 'math',\n returns: { type: ['number', 'vector', 'matrix'] },\n args: {\n x: { type: ['number', 'vector', 'matrix'] },\n },\n variants: [{ argumentNames: ['x'] }],\n description: 'The `atan` function computes the arctangent (inverse tangent) of a `number` in radians, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the arctangent of each element while preserving the original structure.',\n seeAlso: ['math.tan', 'math.atanh', 'math.asin', 'math.acos'],\n examples: [\n 'let { atan } = import(\"math\"); atan(0)',\n 'let { atan } = import(\"math\"); atan(1)',\n 'let { atan } = import(\"math\"); atan(-0.5)',\n 'let { atan } = import(\"math\"); atan([0.1, 0.2, 0.3])',\n 'let { atan } = import(\"math\"); atan([[0.1, 0.2], [0.3, 0.4]])',\n ],\n },\n },\n 'tanh': {\n evaluate: unaryMathOp(val => Math.tanh(val)),\n arity: toFixedArity(1),\n docs: {\n category: 'math',\n returns: { type: ['number', 'vector', 'matrix'] },\n args: {\n x: { type: ['number', 'vector', 'matrix'] },\n },\n variants: [{ argumentNames: ['x'] }],\n description: 'The `tanh` function computes the hyperbolic tangent of a `number`, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the hyperbolic tangent of each element while preserving the original structure.',\n seeAlso: ['math.atanh', 'math.tan', 'math.sinh', 'math.cosh'],\n examples: [\n 'let { tanh } = import(\"math\"); tanh(0)',\n 'let { tanh } = import(\"math\"); tanh(1)',\n 'let { tanh } = import(\"math\"); tanh(-0.5)',\n 'let { tanh } = import(\"math\"); tanh(50)',\n ],\n },\n },\n 'atanh': {\n evaluate: unaryMathOp(val => Math.atanh(val)),\n arity: toFixedArity(1),\n docs: {\n category: 'math',\n returns: { type: ['number', 'vector', 'matrix'] },\n args: {\n x: { type: ['number', 'vector', 'matrix'] },\n },\n variants: [{ argumentNames: ['x'] }],\n description: 'The `atanh` function computes the inverse hyperbolic tangent of a `number`, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the inverse hyperbolic tangent of each element while preserving the original structure.',\n seeAlso: ['math.tanh', 'math.atan', 'math.asinh', 'math.acosh'],\n examples: [\n 'let { atanh } = import(\"math\"); atanh(0)',\n 'let { atanh } = import(\"math\"); atanh(0.9)',\n 'let { atanh } = import(\"math\"); atanh(-0.5)',\n 'let { atanh } = import(\"math\"); atanh([0.1, 0.2, 0.3])',\n 'let { atanh } = import(\"math\"); atanh([[0.1, 0.2], [0.3, 0.4]])',\n ],\n },\n },\n 'ln': {\n evaluate: unaryMathOp(val => Math.log(val)),\n arity: toFixedArity(1),\n docs: {\n category: 'math',\n returns: { type: ['number', 'vector', 'matrix'] },\n args: {\n x: { type: ['number', 'vector', 'matrix'] },\n },\n variants: [{ argumentNames: ['x'] }],\n description: 'The `ln` function computes the natural logarithm (base `e`) of a `number`, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the natural logarithm of each element while preserving the original structure.',\n seeAlso: ['math.log2', 'math.log10', '^'],\n examples: [\n 'let { ln } = import(\"math\"); ln(0.01)',\n 'let { ln } = import(\"math\"); ln(2.5)',\n 'let { ln } = import(\"math\"); ln(E)',\n 'let { ln } = import(\"math\"); ln([1, 2, 3])',\n 'let { ln } = import(\"math\"); ln([[1, 2], [3, 4]])',\n ],\n },\n },\n 'log2': {\n evaluate: unaryMathOp(val => Math.log2(val)),\n arity: toFixedArity(1),\n docs: {\n category: 'math',\n returns: { type: ['number', 'vector', 'matrix'] },\n args: {\n x: { type: ['number', 'vector', 'matrix'] },\n },\n variants: [{ argumentNames: ['x'] }],\n description: 'The `log2` function computes the base `2` logarithm of a `number`, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the base-2 logarithm of each element while preserving the original structure.',\n seeAlso: ['math.ln', 'math.log10'],\n examples: [\n 'let { log2 } = import(\"math\"); log2(0.01)',\n 'let { log2 } = import(\"math\"); log2(2 ^ 12)',\n 'let { log2 } = import(\"math\"); log2(2.5)',\n 'let { log2 } = import(\"math\"); log2([1, 2, 3])',\n 'let { log2 } = import(\"math\"); log2([[1, 2], [3, 4]])',\n ],\n },\n },\n 'log10': {\n evaluate: unaryMathOp(val => Math.log10(val)),\n arity: toFixedArity(1),\n docs: {\n category: 'math',\n returns: { type: ['number', 'vector', 'matrix'] },\n args: {\n x: { type: ['number', 'vector', 'matrix'] },\n },\n variants: [{ argumentNames: ['x'] }],\n description: 'The `log10` function computes the base `10` logarithm of a `number`, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the base-10 logarithm of each element while preserving the original structure.',\n seeAlso: ['math.ln', 'math.log2'],\n examples: [\n 'let { log10 } = import(\"math\"); log10(0.01)',\n 'let { log10 } = import(\"math\"); log10(10 ^ 12)',\n 'let { log10 } = import(\"math\"); log10(2.5)',\n 'let { log10 } = import(\"math\"); log10([1, 2, 3])',\n 'let { log10 } = import(\"math\"); log10([[1, 2], [3, 4]])',\n ],\n },\n },\n 'to-rad': {\n evaluate: unaryMathOp(val => (val * Math.PI) / 180),\n arity: toFixedArity(1),\n docs: {\n category: 'math',\n returns: { type: ['number', 'vector', 'matrix'] },\n args: {\n x: { type: ['number', 'vector', 'matrix'] },\n },\n variants: [{ argumentNames: ['x'] }],\n description: 'The `to-rad` function converts an angle from degrees to radians, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it converts each element while preserving the original structure.',\n seeAlso: ['math.to-deg', 'math.sin', 'math.cos', 'math.tan'],\n examples: [\n 'let { to-rad } = import(\"math\"); to-rad(0)',\n 'let { to-rad } = import(\"math\"); to-rad(90)',\n 'let { to-rad } = import(\"math\"); to-rad(180)',\n 'let { to-rad } = import(\"math\"); to-rad(360)',\n 'let { to-rad } = import(\"math\"); to-rad([0, 90, 180])',\n 'let { to-rad } = import(\"math\"); to-rad([[0, 90], [180, 360]])',\n ],\n },\n },\n 'to-deg': {\n evaluate: unaryMathOp(val => (val * 180) / Math.PI),\n arity: toFixedArity(1),\n docs: {\n category: 'math',\n returns: { type: ['number', 'vector', 'matrix'] },\n args: {\n x: { type: ['number', 'vector', 'matrix'] },\n },\n variants: [{ argumentNames: ['x'] }],\n description: 'The `to-deg` function converts an angle from radians to degrees, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it converts each element while preserving the original structure.',\n seeAlso: ['math.to-rad'],\n examples: [\n 'let { to-deg } = import(\"math\"); to-deg(0)',\n 'let { to-deg } = import(\"math\"); to-deg(PI)',\n 'let { to-deg } = import(\"math\"); to-deg(PI / 2)',\n 'let { to-deg } = import(\"math\"); to-deg(3 * PI / 2)',\n 'let { to-deg } = import(\"math\"); to-deg([0, PI, PI / 2])',\n 'let { to-deg } = import(\"math\"); to-deg([[0, PI], [PI / 2, 3 * PI / 2]])',\n ],\n },\n },\n}\n\nexport const mathUtilsModule: LitsModule = {\n name: 'math',\n functions: mathUtilsFunctions,\n}\n"],"names":["getCodeMarker","sourceCodeInfo","position","code","leftPadding","column","rightPadding","length","repeat","Math","max","LitsError","Error","shortMessage","constructor","err","message","super","location","line","filePath","getLitsErrorMessage","this","Object","setPrototypeOf","prototype","name","Set","values","Number","String","NormalExpression","SpecialExpression","UserDefinedSymbol","NormalBuiltinSymbol","SpecialBuiltinSymbol","ReservedSymbol","Binding","Spread","isNumber","value","options","isNaN","integer","isInteger","finite","isFinite","zero","nonZero","positive","negative","nonPositive","nonNegative","gt","gte","lt","lte","annotatedArrays","WeakSet","vectors","notVectors","matrices","notMatrices","grids","toFixedArity","arity","min","getNumberVectorOrMatrixOperation","param","vector","Array","isArray","has","every","elem","add","matrix","nbrOfCols","row","some","cell","isMatrix","unaryMathOp","fn","operation","operand","map","val","mathUtilsModule","functions","sin","evaluate","docs","category","returns","type","args","x","variants","argumentNames","description","seeAlso","examples","asin","sinh","asinh","cos","acos","cosh","acosh","tan","atan","tanh","atanh","ln","log","log2","log10","PI"],"mappings":"aAEM,SAAUA,EAAcC,GAC5B,IAAKA,EAAeC,WAAaD,EAAeE,KAC9C,MAAO,GAET,MAAMC,EAAcH,EAAeC,SAASG,OAAS,EAC/CC,EAAeL,EAAeE,KAAKI,OAASH,EAAc,EAChE,MAAO,GAAG,IAAII,OAAOC,KAAKC,IAAIN,EAAa,OAAO,IAAII,OAAOC,KAAKC,IAAIJ,EAAc,KACtF,CCkBM,MAAOK,UAAkBC,MACbX,eACAY,aAChB,WAAAC,CAAYC,EAAcd,GACxB,MAAMe,EAAUD,aAAeH,MAC3BG,EAAIC,QACJ,GAAGD,IAEPE,MA/BJ,SAA6BD,EAAiBf,GAC5C,IAAKA,EACH,OAAOe,EAET,MAAME,EAAW,GAAGjB,EAAeC,SAASiB,QAAQlB,EAAeC,SAASG,SAM5E,M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AAO9E,KAAK4G,MAAM9B,IACxCtB,MAAOD,EAAa,GACpB4B,KAAM,CACJC,SAAU,OACVC,QAAS,CAAEC,KAAM,CAAC,SAAU,SAAU,WACtCC,KAAM,CACJC,EAAG,CAAEF,KAAM,CAAC,SAAU,SAAU,YAElCG,SAAU,CAAC,CAAEC,cAAe,CAAC,OAC7BC,YAAa,iQACbC,QAAS,CAAC,UAAW,aACrBC,SAAU,CACR,8CACA,iDACA,6CACA,mDACA,6DAIN,SAAU,CACRX,SAAUT,EAAYK,GAAQA,EAAM9E,KAAK6G,GAAM,KAC/CrD,MAAOD,EAAa,GACpB4B,KAAM,CACJC,SAAU,OACVC,QAAS,CAAEC,KAAM,CAAC,SAAU,SAAU,WACtCC,KAAM,CACJC,EAAG,CAAEF,KAAM,CAAC,SAAU,SAAU,YAElCG,SAAU,CAAC,CAAEC,cAAe,CAAC,OAC7BC,YAAa,qOACbC,QAAS,CAAC,cAAe,WAAY,WAAY,YACjDC,SAAU,CACR,6CACA,8CACA,+CACA,+CACA,wDACA,oEAIN,SAAU,CACRX,SAAUT,EAAYK,GAAc,IAANA,EAAa9E,KAAK6G,IAChDrD,MAAOD,EAAa,GACpB4B,KAAM,CACJC,SAAU,OACVC,QAAS,CAAEC,KAAM,CAAC,SAAU,SAAU,WACtCC,KAAM,CACJC,EAAG,CAAEF,KAAM,CAAC,SAAU,SAAU,YAElCG,SAAU,CAAC,CAAEC,cAAe,CAAC,OAC7BC,YAAa,qOACbC,QAAS,CAAC,eACVC,SAAU,CACR,6CACA,8CACA,kDACA,sDACA,2DACA"}
|
|
1
|
+
{"version":3,"file":"math.js","sources":["../../src/utils/debug/getCodeMarker.ts","../../src/errors.ts","../../src/constants/constants.ts","../../src/typeGuards/number.ts","../../src/typeGuards/annotatedArrays.ts","../../src/utils/arity.ts","../../src/builtin/modules/math/index.ts"],"sourcesContent":["import type { SourceCodeInfo } from '../../tokenizer/token'\n\nexport function getCodeMarker(sourceCodeInfo: SourceCodeInfo): string {\n if (!sourceCodeInfo.position || !sourceCodeInfo.code)\n return ''\n\n const leftPadding = sourceCodeInfo.position.column - 1\n const rightPadding = sourceCodeInfo.code.length - leftPadding - 1\n return `${' '.repeat(Math.max(leftPadding, 0))}^${' '.repeat(Math.max(rightPadding, 0))}`\n}\n","import { getCodeMarker } from '../src/utils/debug/getCodeMarker'\nimport type { Arr } from './interface'\nimport type { SourceCodeInfo } from './tokenizer/token'\n\nfunction getLitsErrorMessage(message: string, sourceCodeInfo?: SourceCodeInfo) {\n if (!sourceCodeInfo) {\n return message\n }\n const location = `${sourceCodeInfo.position.line}:${sourceCodeInfo.position.column}`\n const filePathLine = sourceCodeInfo.filePath\n ? `\\n${sourceCodeInfo.filePath}:${location}`\n : `\\nLocation ${location}`\n const codeLine = `\\n${sourceCodeInfo.code}`\n const codeMarker = `\\n${getCodeMarker(sourceCodeInfo)}`\n return `${message}${filePathLine}${codeLine}${codeMarker}`\n}\n\nexport class RecurSignal extends Error {\n public params: Arr\n constructor(params: Arr) {\n super(`recur, params: ${params}`)\n Object.setPrototypeOf(this, RecurSignal.prototype)\n this.name = 'RecurSignal'\n this.params = params\n }\n}\n\nexport class LitsError extends Error {\n public readonly sourceCodeInfo?: SourceCodeInfo\n public readonly shortMessage: string\n constructor(err: unknown, sourceCodeInfo: SourceCodeInfo | undefined) {\n const message = err instanceof Error\n ? err.message\n : `${err}`\n\n super(getLitsErrorMessage(message, sourceCodeInfo))\n this.shortMessage = message\n this.sourceCodeInfo = sourceCodeInfo\n Object.setPrototypeOf(this, LitsError.prototype)\n this.name = 'LitsError'\n }\n\n public getCodeMarker(): string | undefined {\n return this.sourceCodeInfo && getCodeMarker(this.sourceCodeInfo)\n }\n}\n\nexport class UserDefinedError extends LitsError {\n public userMessage: string\n constructor(message: string, sourceCodeInfo?: SourceCodeInfo) {\n super(message, sourceCodeInfo)\n this.userMessage = message\n Object.setPrototypeOf(this, UserDefinedError.prototype)\n this.name = 'UserDefinedError'\n }\n}\n\nexport class AssertionError extends LitsError {\n constructor(message: string | Error, sourceCodeInfo?: SourceCodeInfo) {\n super(message, sourceCodeInfo)\n Object.setPrototypeOf(this, AssertionError.prototype)\n this.name = 'AssertionError'\n }\n}\n\nexport class UndefinedSymbolError extends LitsError {\n public symbol: string\n constructor(symbolName: string, sourceCodeInfo?: SourceCodeInfo) {\n const message = `Undefined symbol '${symbolName}'.`\n super(message, sourceCodeInfo)\n this.symbol = symbolName\n Object.setPrototypeOf(this, UndefinedSymbolError.prototype)\n this.name = 'UndefinedSymbolError'\n }\n}\n\nexport function isLitsError(error: unknown): error is LitsError {\n return error instanceof LitsError\n}\n","export const NodeTypes = {\n Number: 1,\n String: 2,\n NormalExpression: 3,\n SpecialExpression: 4,\n UserDefinedSymbol: 5,\n NormalBuiltinSymbol: 6,\n SpecialBuiltinSymbol: 7,\n ReservedSymbol: 8,\n Binding: 9,\n Spread: 10,\n} as const\n\nconst NodeTypesSet = new Set(Object.values(NodeTypes))\n\nexport type NodeType = typeof NodeTypes[keyof typeof NodeTypes]\n\nexport function getNodeTypeName(type: NodeType): keyof typeof NodeTypes {\n return Object.keys(NodeTypes).find(key => NodeTypes[key as keyof typeof NodeTypes] === type) as keyof typeof NodeTypes\n}\n\n// TODO, is this needed?\nexport function isNodeType(type: unknown): type is NodeType {\n return typeof type === 'number' && NodeTypesSet.has(type as NodeType)\n}\n\nconst functionTypes = [\n 'UserDefined',\n 'Partial',\n 'Comp',\n 'Constantly',\n 'Juxt',\n 'Complement',\n 'EveryPred',\n 'SomePred',\n 'Fnull',\n 'Builtin',\n 'SpecialBuiltin',\n 'NativeJsFunction',\n 'Module',\n] as const\n\nconst functionTypeSet = new Set(functionTypes)\n\nexport type FunctionType = typeof functionTypes[number]\n\nexport function isFunctionType(type: unknown): type is FunctionType {\n return typeof type === 'string' && functionTypeSet.has(type as FunctionType)\n}\n","import { LitsError } from '../errors'\nimport type { SourceCodeInfo } from '../tokenizer/token'\nimport { valueToString } from '../utils/debug/debugTools'\nimport { getSourceCodeInfo } from '../utils/debug/getSourceCodeInfo'\n\ntype SignOptions =\n | {\n positive?: true\n negative?: never\n nonPositive?: never\n nonNegative?: never\n zero?: never\n nonZero?: never\n }\n | {\n positive?: never\n negative?: true\n nonPositive?: never\n nonNegative?: never\n zero?: never\n nonZero?: never\n }\n | {\n positive?: never\n negative?: never\n nonPositive?: true\n nonNegative?: never\n zero?: never\n nonZero?: never\n }\n | {\n positive?: never\n negative?: never\n nonPositive?: never\n nonNegative?: true\n zero?: never\n nonZero?: never\n }\n | {\n positive?: never\n negative?: never\n nonPositive?: never\n nonNegative?: never\n zero?: true\n nonZero?: never\n }\n | {\n positive?: never\n negative?: never\n nonPositive?: never\n nonNegative?: never\n zero?: never\n nonZero?: true\n }\n\ntype GtOptions =\n | {\n gt?: number\n gte?: never\n }\n | {\n gt?: never\n gte?: number\n }\n\ntype LtOptions =\n | {\n lt?: number\n lte?: never\n }\n | {\n lt?: never\n lte?: number\n }\n\ntype NumberOptions = {\n integer?: true\n finite?: true\n} & SignOptions &\nGtOptions &\nLtOptions\n\nfunction getRangeString(options: NumberOptions): string {\n const hasUpperAndLowerBound\n = (typeof options.gt === 'number' || typeof options.gte === 'number')\n && (typeof options.lt === 'number' || typeof options.lte === 'number')\n if (hasUpperAndLowerBound) {\n return `${typeof options.gt === 'number' ? `${options.gt} < n ` : `${options.gte} <= n `}${\n typeof options.lt === 'number' ? `< ${options.lt}` : `<= ${options.lte}`\n }`\n }\n else if (typeof options.gt === 'number' || typeof options.gte === 'number') {\n return `${typeof options.gt === 'number' ? `n > ${options.gt}` : `n >= ${options.gte}`}`\n }\n else if (typeof options.lt === 'number' || typeof options.lte === 'number') {\n return `${typeof options.lt === 'number' ? `n < ${options.lt}` : `n <= ${options.lte}`}`\n }\n else { return '' }\n}\n\nfunction getSignString(options: NumberOptions): string {\n return options.positive\n ? 'positive'\n : options.negative\n ? 'negative'\n : options.nonNegative\n ? 'non negative'\n : options.nonPositive\n ? 'non positive'\n : options.nonZero\n ? 'non zero'\n : ''\n}\n\nfunction getNumberTypeName(options: NumberOptions): string {\n if (options.zero)\n return 'zero'\n\n const sign = getSignString(options)\n const numberType = options.integer ? 'integer' : 'number'\n const finite = options.finite ? 'finite' : ''\n const range = getRangeString(options)\n\n return [sign, finite, numberType, range].filter(x => !!x).join(' ')\n}\n\nexport function isNumber(value: unknown, options: NumberOptions = {}): value is number {\n if (typeof value !== 'number')\n return false\n\n if (Number.isNaN(value))\n return false\n\n if (options.integer && !Number.isInteger(value))\n return false\n\n if (options.finite && !Number.isFinite(value))\n return false\n\n if (options.zero && value !== 0)\n return false\n\n if (options.nonZero && value === 0)\n return false\n\n if (options.positive && value <= 0)\n return false\n\n if (options.negative && value >= 0)\n return false\n\n if (options.nonPositive && value > 0)\n return false\n\n if (options.nonNegative && value < 0)\n return false\n\n if (typeof options.gt === 'number' && value <= options.gt)\n return false\n\n if (typeof options.gte === 'number' && value < options.gte)\n return false\n\n if (typeof options.lt === 'number' && value >= options.lt)\n return false\n\n if (typeof options.lte === 'number' && value > options.lte)\n return false\n\n return true\n}\n\nexport function assertNumber(\n value: unknown,\n sourceCodeInfo?: SourceCodeInfo,\n options: NumberOptions = {},\n): asserts value is number {\n if (!isNumber(value, options)) {\n throw new LitsError(\n `Expected ${getNumberTypeName(options)}, got ${valueToString(value)}.`,\n getSourceCodeInfo(value, sourceCodeInfo),\n )\n }\n}\n\nexport function asNumber(\n value: unknown,\n sourceCodeInfo: SourceCodeInfo | undefined,\n options: NumberOptions = {},\n): number {\n assertNumber(value, sourceCodeInfo, options)\n return value\n}\n","import { LitsError } from '../errors'\nimport type { Any } from '../interface'\nimport type { SourceCodeInfo } from '../tokenizer/token'\nimport { isNumber } from './number'\n\nconst annotatedArrays = new WeakSet<unknown[]>()\nconst vectors = new WeakSet<unknown[]>()\nconst notVectors = new WeakSet<unknown[]>()\nconst matrices = new WeakSet<unknown[]>()\nconst notMatrices = new WeakSet<unknown[]>()\nconst grids = new WeakSet<unknown[]>()\nconst notGrids = new WeakSet<unknown[]>()\n\nexport function annotate<T>(value: T): T {\n if (!Array.isArray(value)) {\n return value\n }\n if (annotatedArrays.has(value)) {\n return value\n }\n isVector(value)\n if (!isMatrix(value)) {\n isGrid(value)\n }\n\n return value\n}\nexport function isVector(vector: unknown): vector is number[] {\n if (!Array.isArray(vector)) {\n return false\n }\n\n if (vectors.has(vector)) {\n return true\n }\n if (notVectors.has(vector)) {\n return false\n }\n\n if (vector.every(elem => isNumber(elem))) {\n annotatedArrays.add(vector)\n vectors.add(vector)\n return true\n }\n notVectors.add(vector)\n return false\n}\n\nexport function assertVector(vector: unknown, sourceCodeInfo: SourceCodeInfo | undefined): asserts vector is number[] {\n if (!isVector(vector)) {\n throw new LitsError(`Expected a vector, but got ${vector}`, sourceCodeInfo)\n }\n}\n\nexport function is2dVector(vector: unknown): vector is [number, number] {\n if (!isVector(vector)) {\n return false\n }\n return vector.length === 2\n}\nexport function assert2dVector(vector: unknown, sourceCodeInfo: SourceCodeInfo | undefined): asserts vector is [number, number] {\n if (!is2dVector(vector)) {\n throw new LitsError(`Expected a 2d vector, but got ${vector}`, sourceCodeInfo)\n }\n}\n\nexport function is3dVector(vector: unknown): vector is [number, number, number] {\n if (!isVector(vector)) {\n return false\n }\n return vector.length === 3\n}\nexport function assert3dVector(vector: unknown, sourceCodeInfo: SourceCodeInfo | undefined): asserts vector is [number, number, number] {\n if (!is3dVector(vector)) {\n throw new LitsError(`Expected a 3d vector, but got ${vector}`, sourceCodeInfo)\n }\n}\n\nexport function assertNonEmptyVector(vector: unknown, sourceCodeInfo: SourceCodeInfo | undefined): asserts vector is number[] {\n assertVector(vector, sourceCodeInfo)\n if (vector.length === 0) {\n throw new LitsError(`Expected a non empty vector, but got ${vector}`, sourceCodeInfo)\n }\n}\n\nexport function isGrid(grid: unknown): grid is unknown[][] {\n if (!Array.isArray(grid)) {\n return false\n }\n if (grids.has(grid)) {\n return true\n }\n if (notGrids.has(grid)) {\n return false\n }\n if (grid.length === 0) {\n notGrids.add(grid)\n return false\n }\n if (!Array.isArray(grid[0])) {\n notGrids.add(grid)\n return false\n }\n const nbrOfCols = grid[0].length\n for (const row of grid.slice(1)) {\n if (!Array.isArray(row)) {\n notGrids.add(grid)\n return false\n }\n if (row.length !== nbrOfCols) {\n notGrids.add(grid)\n return false\n }\n }\n annotatedArrays.add(grid)\n grids.add(grid)\n return true\n}\n\nexport function assertGrid(grid: unknown, sourceCodeInfo: SourceCodeInfo | undefined): asserts grid is Any[][] {\n if (!isGrid(grid)) {\n throw new LitsError(`Expected a grid, but got ${grid}`, sourceCodeInfo)\n }\n}\n\nexport function isMatrix(matrix: unknown): matrix is number[][] {\n if (!Array.isArray(matrix)) {\n return false\n }\n if (matrices.has(matrix)) {\n return true\n }\n if (notMatrices.has(matrix)) {\n return false\n }\n if (matrix.length === 0) {\n notMatrices.add(matrix)\n return false\n }\n if (!Array.isArray(matrix[0]) || matrix[0].length === 0) {\n notMatrices.add(matrix)\n return false\n }\n const nbrOfCols = matrix[0].length\n for (const row of matrix) {\n if (!Array.isArray(row) || row.length !== nbrOfCols || row.some(cell => !isNumber(cell))) {\n notMatrices.add(matrix)\n return false\n }\n }\n annotatedArrays.add(matrix)\n grids.add(matrix)\n matrices.add(matrix)\n return true\n}\n\nexport function assertMatrix(matrix: unknown, sourceCodeInfo: SourceCodeInfo | undefined): asserts matrix is number[][] {\n if (!isMatrix(matrix)) {\n throw new LitsError(`Expected a matrix, but got ${matrix}`, sourceCodeInfo)\n }\n}\n\nexport function assertSquareMatrix(matrix: unknown, sourceCodeInfo: SourceCodeInfo | undefined): asserts matrix is number[][] {\n if (!isMatrix(matrix)) {\n throw new LitsError(`Expected a matrix, but got ${matrix}`, sourceCodeInfo)\n }\n if (matrix.length !== matrix[0]!.length) {\n throw new LitsError(`Expected square matrix, but got ${matrix.length} and ${matrix[0]!.length}`, sourceCodeInfo)\n }\n}\n\nexport function isSquareMatrix(matrix: unknown): matrix is number[][] {\n if (!isMatrix(matrix)) {\n return false\n }\n if (matrix.length !== matrix[0]!.length) {\n return false\n }\n return true\n}\n","import type { Arity } from '../builtin/interface'\nimport { LitsError } from '../errors'\nimport type { FunctionLike } from '../parser/types'\nimport type { SourceCodeInfo } from '../tokenizer/token'\nimport { isColl } from '../typeGuards/lits'\nimport { valueToString } from './debug/debugTools'\n\nexport function arityAccepts(arity: Arity, nbrOfParams: number): boolean {\n const { min, max } = arity\n if (typeof min === 'number' && nbrOfParams < min) {\n return false\n }\n if (typeof max === 'number' && nbrOfParams > max) {\n return false\n }\n return true\n}\n\nexport function arityAcceptsMin(arity: Arity, nbrOfParams: number): boolean {\n const { min } = arity\n if (typeof min === 'number' && nbrOfParams < min) {\n return false\n }\n return true\n}\n\nexport function getCommonArityFromFunctions(params: FunctionLike[]): Arity | null {\n return params.reduce((acc: Arity | null, param): Arity | null => {\n if (acc === null) {\n return null\n }\n const arity: Arity = (typeof param === 'number' || isColl(param)) ? toFixedArity(1) : param.arity\n const { min: aMin, max: aMax } = arity\n const { min: bMin, max: bMax } = acc\n const min = typeof aMin === 'number' && typeof bMin === 'number'\n ? Math.max(aMin, bMin)\n : typeof aMin === 'number' ? aMin : typeof bMin === 'number' ? bMin : undefined\n const max = typeof aMax === 'number' && typeof bMax === 'number'\n ? Math.min(aMax, bMax)\n : typeof aMax === 'number' ? aMax : typeof bMax === 'number' ? bMax : undefined\n\n if (typeof min === 'number' && typeof max === 'number' && min > max) {\n return null\n }\n\n return { min, max }\n }, {})\n}\n\nexport function getArityFromFunction(param: FunctionLike): Arity {\n return (typeof param === 'number' || isColl(param)) ? toFixedArity(1) : param.arity\n}\n\nexport function assertNumberOfParams(arity: Arity, length: number, sourceCodeInfo: SourceCodeInfo | undefined): void {\n const { min, max } = arity\n if (typeof min === 'number' && length < min) {\n throw new LitsError(\n `Wrong number of arguments, expected at least ${min}, got ${valueToString(length)}.`,\n sourceCodeInfo,\n )\n }\n\n if (typeof max === 'number' && length > max) {\n throw new LitsError(\n `Wrong number of arguments, expected at most ${max}, got ${valueToString(length)}.`,\n sourceCodeInfo,\n )\n }\n}\n\nexport function canBeOperator(count: Arity): boolean {\n if (typeof count.max === 'number' && count.max < 2) {\n return false\n }\n\n if (typeof count.min === 'number' && count.min > 2) {\n return false\n }\n\n return true\n}\n\nexport function toFixedArity(arity: number): Arity {\n return { min: arity, max: arity }\n}\n","import type { SourceCodeInfo } from '../../../tokenizer/token'\nimport { isMatrix, isVector } from '../../../typeGuards/annotatedArrays'\nimport { isNumber } from '../../../typeGuards/number'\nimport { toFixedArity } from '../../../utils/arity'\nimport { LitsError } from '../../../errors'\nimport type { BuiltinNormalExpressions } from '../../interface'\nimport type { LitsModule } from '../interface'\n\ntype NumberVectorOrMatrix = number | number[] | number[][]\n\nfunction getNumberVectorOrMatrixOperation(\n param: unknown,\n sourceCodeInfo: SourceCodeInfo | undefined,\n):\n | ['number', number]\n | ['vector', number[]]\n | ['matrix', number[][]] {\n if (isVector(param)) {\n return ['vector', param]\n }\n if (isMatrix(param)) {\n return ['matrix', param]\n }\n if (!isNumber(param)) {\n throw new LitsError(`Invalid parameter type: ${typeof param}`, sourceCodeInfo)\n }\n return ['number', param]\n}\n\nfunction unaryMathOp(\n fn: (val: number) => number,\n): (params: unknown[], sourceCodeInfo: SourceCodeInfo | undefined) => NumberVectorOrMatrix {\n return ([param], sourceCodeInfo) => {\n const [operation, operand] = getNumberVectorOrMatrixOperation(param, sourceCodeInfo)\n if (operation === 'number') {\n return fn(operand)\n }\n else if (operation === 'vector') {\n return operand.map(val => fn(val))\n }\n else {\n return operand.map(row => row.map(val => fn(val)))\n }\n }\n}\n\nconst mathUtilsFunctions: BuiltinNormalExpressions = {\n 'sin': {\n evaluate: unaryMathOp(val => Math.sin(val)),\n arity: toFixedArity(1),\n docs: {\n category: 'math',\n returns: { type: ['number', 'vector', 'matrix'] },\n args: {\n x: { type: ['number', 'vector', 'matrix'] },\n },\n variants: [{ argumentNames: ['x'] }],\n description: 'The `sin` function computes the sine of an angle (in radians), working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the sine of each element while preserving the original structure.',\n seeAlso: ['math.asin', 'math.sinh', 'math.cos', 'math.tan', 'math.to-rad'],\n examples: [\n 'let { sin } = import(math); sin(0)',\n 'let { sin } = import(math); sin(1)',\n 'let { sin } = import(math); sin(PI)',\n 'let { sin } = import(math); sin(-0.5)',\n 'let { sin } = import(math); sin([1, 2, 3])',\n 'let { sin } = import(math); sin([[1, 2], [3, 4]])',\n ],\n },\n },\n 'asin': {\n evaluate: unaryMathOp(val => Math.asin(val)),\n arity: toFixedArity(1),\n docs: {\n category: 'math',\n returns: { type: ['number', 'vector', 'matrix'] },\n args: {\n x: { type: ['number', 'vector', 'matrix'] },\n },\n variants: [{ argumentNames: ['x'] }],\n description: 'The `asin` function computes the arcsine (inverse sine) of a `number` in radians, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the arcsine of each element while preserving the original structure.',\n seeAlso: ['math.sin', 'math.asinh', 'math.acos', 'math.atan'],\n examples: [\n 'let { asin } = import(math); asin(0)',\n 'let { asin } = import(math); asin(1)',\n 'let { asin } = import(math); asin(-0.5)',\n 'let { asin } = import(math); asin([1, 2, 3])',\n 'let { asin } = import(math); asin([[1, 2], [3, 4]])',\n ],\n },\n },\n 'sinh': {\n evaluate: unaryMathOp(val => Math.sinh(val)),\n arity: toFixedArity(1),\n docs: {\n category: 'math',\n returns: { type: ['number', 'vector', 'matrix'] },\n args: {\n x: { type: ['number', 'vector', 'matrix'] },\n },\n variants: [{ argumentNames: ['x'] }],\n description: 'The `sinh` function computes the hyperbolic sine of a `number`, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the hyperbolic sine of each element while preserving the original structure.',\n seeAlso: ['math.asinh', 'math.sin', 'math.cosh', 'math.tanh'],\n examples: [\n 'let { sinh } = import(math); sinh(0)',\n 'let { sinh } = import(math); sinh(1)',\n 'let { sinh } = import(math); sinh(-0.5)',\n 'let { sinh } = import(math); sinh([0.1, 0.2, 0.3])',\n 'let { sinh } = import(math); sinh([[0.1, 0.2], [0.3, 0.4]])',\n ],\n },\n },\n 'asinh': {\n evaluate: unaryMathOp(val => Math.asinh(val)),\n arity: toFixedArity(1),\n docs: {\n category: 'math',\n returns: { type: ['number', 'vector', 'matrix'] },\n args: {\n x: { type: ['number', 'vector', 'matrix'] },\n },\n variants: [{ argumentNames: ['x'] }],\n description: 'The `asinh` function computes the inverse hyperbolic sine of a `number`, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the inverse hyperbolic sine of each element while preserving the original structure.',\n seeAlso: ['math.sinh', 'math.asin', 'math.acosh', 'math.atanh'],\n examples: [\n 'let { asinh } = import(math); asinh(10)',\n 'let { asinh } = import(math); asinh(90)',\n 'let { asinh } = import(math); asinh(50)',\n 'let { asinh } = import(math); asinh([10, 20, 30])',\n 'let { asinh } = import(math); asinh([[10, 20], [30, 40]])',\n ],\n },\n },\n 'cos': {\n evaluate: unaryMathOp(val => Math.cos(val)),\n arity: toFixedArity(1),\n docs: {\n category: 'math',\n returns: { type: ['number', 'vector', 'matrix'] },\n args: {\n x: { type: ['number', 'vector', 'matrix'] },\n },\n variants: [{ argumentNames: ['x'] }],\n description: 'The `cos` function computes the cosine of an angle (in radians), working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the cosine of each element while preserving the original structure.',\n seeAlso: ['math.acos', 'math.cosh', 'math.sin', 'math.tan', 'math.to-rad'],\n examples: [\n 'let { cos } = import(math); cos(0)',\n 'let { cos } = import(math); cos(1)',\n 'let { cos } = import(math); cos(PI)',\n 'let { cos } = import(math); cos(-0.5)',\n 'let { cos } = import(math); cos([1, 2, 3])',\n 'let { cos } = import(math); cos([[1, 2], [3, 4]])',\n ],\n },\n },\n 'acos': {\n evaluate: unaryMathOp(val => Math.acos(val)),\n arity: toFixedArity(1),\n docs: {\n category: 'math',\n returns: { type: ['number', 'vector', 'matrix'] },\n args: {\n x: { type: ['number', 'vector', 'matrix'] },\n },\n variants: [{ argumentNames: ['x'] }],\n description: 'The `acos` function computes the arccosine (inverse cosine) of a `number` in radians, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the arccosine of each element while preserving the original structure.',\n seeAlso: ['math.cos', 'math.acosh', 'math.asin', 'math.atan'],\n examples: [\n 'let { acos } = import(math); acos(0)',\n 'let { acos } = import(math); acos(1)',\n 'let { acos } = import(math); acos(-0.5)',\n 'let { acos } = import(math); acos([0.1, 0.2, 0.3])',\n 'let { acos } = import(math); acos([[0.1, 0.2], [0.3, 0.4]])',\n ],\n },\n },\n 'cosh': {\n evaluate: unaryMathOp(val => Math.cosh(val)),\n arity: toFixedArity(1),\n docs: {\n category: 'math',\n returns: { type: ['number', 'vector', 'matrix'] },\n args: {\n x: { type: ['number', 'vector', 'matrix'] },\n },\n variants: [{ argumentNames: ['x'] }],\n description: 'The `cosh` function computes the hyperbolic cosine of a `number`, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the hyperbolic cosine of each element while preserving the original structure.',\n seeAlso: ['math.acosh', 'math.cos', 'math.sinh', 'math.tanh'],\n examples: [\n 'let { cosh } = import(math); cosh(0)',\n 'let { cosh } = import(math); cosh(1)',\n 'let { cosh } = import(math); cosh(-0.5)',\n 'let { cosh } = import(math); cosh([0.1, 0.2, 0.3])',\n 'let { cosh } = import(math); cosh([[0.1, 0.2], [0.3, 0.4]])',\n ],\n },\n },\n 'acosh': {\n evaluate: unaryMathOp(val => Math.acosh(val)),\n arity: toFixedArity(1),\n docs: {\n category: 'math',\n returns: { type: ['number', 'vector', 'matrix'] },\n args: {\n x: { type: ['number', 'vector', 'matrix'] },\n },\n variants: [{ argumentNames: ['x'] }],\n description: 'The `acosh` function computes the inverse hyperbolic cosine of a `number`, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the inverse hyperbolic cosine of each element while preserving the original structure.',\n seeAlso: ['math.cosh', 'math.acos', 'math.asinh', 'math.atanh'],\n examples: [\n 'let { acosh } = import(math); acosh(1)',\n 'let { acosh } = import(math); acosh(2)',\n 'let { acosh } = import(math); acosh(100)',\n 'let { acosh } = import(math); acosh(50)',\n 'let { acosh } = import(math); acosh([1, 2, 3])',\n 'let { acosh } = import(math); acosh([[1, 2], [3, 4]])',\n ],\n },\n },\n 'tan': {\n evaluate: unaryMathOp(val => Math.tan(val)),\n arity: toFixedArity(1),\n docs: {\n category: 'math',\n returns: { type: ['number', 'vector', 'matrix'] },\n args: {\n x: { type: ['number', 'vector', 'matrix'] },\n },\n variants: [{ argumentNames: ['x'] }],\n description: 'The `tan` function computes the tangent of an angle (in radians), working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the tangent of each element while preserving the original structure.',\n seeAlso: ['math.atan', 'math.tanh', 'math.sin', 'math.cos', 'math.to-rad'],\n examples: [\n 'let { tan } = import(math); tan(0)',\n 'let { tan } = import(math); tan(1)',\n 'let { tan } = import(math); tan(PI)',\n 'let { tan } = import(math); tan(-0.5)',\n 'let { tan } = import(math); tan([1, 2, 3])',\n 'let { tan } = import(math); tan([[1, 2], [3, 4]])',\n ],\n },\n },\n 'atan': {\n evaluate: unaryMathOp(val => Math.atan(val)),\n arity: toFixedArity(1),\n docs: {\n category: 'math',\n returns: { type: ['number', 'vector', 'matrix'] },\n args: {\n x: { type: ['number', 'vector', 'matrix'] },\n },\n variants: [{ argumentNames: ['x'] }],\n description: 'The `atan` function computes the arctangent (inverse tangent) of a `number` in radians, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the arctangent of each element while preserving the original structure.',\n seeAlso: ['math.tan', 'math.atanh', 'math.asin', 'math.acos'],\n examples: [\n 'let { atan } = import(math); atan(0)',\n 'let { atan } = import(math); atan(1)',\n 'let { atan } = import(math); atan(-0.5)',\n 'let { atan } = import(math); atan([0.1, 0.2, 0.3])',\n 'let { atan } = import(math); atan([[0.1, 0.2], [0.3, 0.4]])',\n ],\n },\n },\n 'tanh': {\n evaluate: unaryMathOp(val => Math.tanh(val)),\n arity: toFixedArity(1),\n docs: {\n category: 'math',\n returns: { type: ['number', 'vector', 'matrix'] },\n args: {\n x: { type: ['number', 'vector', 'matrix'] },\n },\n variants: [{ argumentNames: ['x'] }],\n description: 'The `tanh` function computes the hyperbolic tangent of a `number`, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the hyperbolic tangent of each element while preserving the original structure.',\n seeAlso: ['math.atanh', 'math.tan', 'math.sinh', 'math.cosh'],\n examples: [\n 'let { tanh } = import(math); tanh(0)',\n 'let { tanh } = import(math); tanh(1)',\n 'let { tanh } = import(math); tanh(-0.5)',\n 'let { tanh } = import(math); tanh(50)',\n ],\n },\n },\n 'atanh': {\n evaluate: unaryMathOp(val => Math.atanh(val)),\n arity: toFixedArity(1),\n docs: {\n category: 'math',\n returns: { type: ['number', 'vector', 'matrix'] },\n args: {\n x: { type: ['number', 'vector', 'matrix'] },\n },\n variants: [{ argumentNames: ['x'] }],\n description: 'The `atanh` function computes the inverse hyperbolic tangent of a `number`, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the inverse hyperbolic tangent of each element while preserving the original structure.',\n seeAlso: ['math.tanh', 'math.atan', 'math.asinh', 'math.acosh'],\n examples: [\n 'let { atanh } = import(math); atanh(0)',\n 'let { atanh } = import(math); atanh(0.9)',\n 'let { atanh } = import(math); atanh(-0.5)',\n 'let { atanh } = import(math); atanh([0.1, 0.2, 0.3])',\n 'let { atanh } = import(math); atanh([[0.1, 0.2], [0.3, 0.4]])',\n ],\n },\n },\n 'ln': {\n evaluate: unaryMathOp(val => Math.log(val)),\n arity: toFixedArity(1),\n docs: {\n category: 'math',\n returns: { type: ['number', 'vector', 'matrix'] },\n args: {\n x: { type: ['number', 'vector', 'matrix'] },\n },\n variants: [{ argumentNames: ['x'] }],\n description: 'The `ln` function computes the natural logarithm (base `e`) of a `number`, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the natural logarithm of each element while preserving the original structure.',\n seeAlso: ['math.log2', 'math.log10', '^'],\n examples: [\n 'let { ln } = import(math); ln(0.01)',\n 'let { ln } = import(math); ln(2.5)',\n 'let { ln } = import(math); ln(E)',\n 'let { ln } = import(math); ln([1, 2, 3])',\n 'let { ln } = import(math); ln([[1, 2], [3, 4]])',\n ],\n },\n },\n 'log2': {\n evaluate: unaryMathOp(val => Math.log2(val)),\n arity: toFixedArity(1),\n docs: {\n category: 'math',\n returns: { type: ['number', 'vector', 'matrix'] },\n args: {\n x: { type: ['number', 'vector', 'matrix'] },\n },\n variants: [{ argumentNames: ['x'] }],\n description: 'The `log2` function computes the base `2` logarithm of a `number`, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the base-2 logarithm of each element while preserving the original structure.',\n seeAlso: ['math.ln', 'math.log10'],\n examples: [\n 'let { log2 } = import(math); log2(0.01)',\n 'let { log2 } = import(math); log2(2 ^ 12)',\n 'let { log2 } = import(math); log2(2.5)',\n 'let { log2 } = import(math); log2([1, 2, 3])',\n 'let { log2 } = import(math); log2([[1, 2], [3, 4]])',\n ],\n },\n },\n 'log10': {\n evaluate: unaryMathOp(val => Math.log10(val)),\n arity: toFixedArity(1),\n docs: {\n category: 'math',\n returns: { type: ['number', 'vector', 'matrix'] },\n args: {\n x: { type: ['number', 'vector', 'matrix'] },\n },\n variants: [{ argumentNames: ['x'] }],\n description: 'The `log10` function computes the base `10` logarithm of a `number`, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it returns the base-10 logarithm of each element while preserving the original structure.',\n seeAlso: ['math.ln', 'math.log2'],\n examples: [\n 'let { log10 } = import(math); log10(0.01)',\n 'let { log10 } = import(math); log10(10 ^ 12)',\n 'let { log10 } = import(math); log10(2.5)',\n 'let { log10 } = import(math); log10([1, 2, 3])',\n 'let { log10 } = import(math); log10([[1, 2], [3, 4]])',\n ],\n },\n },\n 'to-rad': {\n evaluate: unaryMathOp(val => (val * Math.PI) / 180),\n arity: toFixedArity(1),\n docs: {\n category: 'math',\n returns: { type: ['number', 'vector', 'matrix'] },\n args: {\n x: { type: ['number', 'vector', 'matrix'] },\n },\n variants: [{ argumentNames: ['x'] }],\n description: 'The `to-rad` function converts an angle from degrees to radians, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it converts each element while preserving the original structure.',\n seeAlso: ['math.to-deg', 'math.sin', 'math.cos', 'math.tan'],\n examples: [\n 'let { to-rad } = import(math); to-rad(0)',\n 'let { to-rad } = import(math); to-rad(90)',\n 'let { to-rad } = import(math); to-rad(180)',\n 'let { to-rad } = import(math); to-rad(360)',\n 'let { to-rad } = import(math); to-rad([0, 90, 180])',\n 'let { to-rad } = import(math); to-rad([[0, 90], [180, 360]])',\n ],\n },\n },\n 'to-deg': {\n evaluate: unaryMathOp(val => (val * 180) / Math.PI),\n arity: toFixedArity(1),\n docs: {\n category: 'math',\n returns: { type: ['number', 'vector', 'matrix'] },\n args: {\n x: { type: ['number', 'vector', 'matrix'] },\n },\n variants: [{ argumentNames: ['x'] }],\n description: 'The `to-deg` function converts an angle from radians to degrees, working on `numbers` and element-wise on `vectors` and `matrices`. When applied to collections, it converts each element while preserving the original structure.',\n seeAlso: ['math.to-rad'],\n examples: [\n 'let { to-deg } = import(math); to-deg(0)',\n 'let { to-deg } = import(math); to-deg(PI)',\n 'let { to-deg } = import(math); to-deg(PI / 2)',\n 'let { to-deg } = import(math); to-deg(3 * PI / 2)',\n 'let { to-deg } = import(math); to-deg([0, PI, PI / 2])',\n 'let { to-deg } = import(math); to-deg([[0, PI], [PI / 2, 3 * PI / 2]])',\n ],\n },\n },\n}\n\nexport const mathUtilsModule: LitsModule = {\n name: 'math',\n functions: mathUtilsFunctions,\n}\n"],"names":["getCodeMarker","sourceCodeInfo","position","code","leftPadding","column","rightPadding","length","repeat","Math","max","LitsError","Error","shortMessage","constructor","err","message","super","location","line","filePath","getLitsErrorMessage","this","Object","setPrototypeOf","prototype","name","Set","values","Number","String","NormalExpression","SpecialExpression","UserDefinedSymbol","NormalBuiltinSymbol","SpecialBuiltinSymbol","ReservedSymbol","Binding","Spread","isNumber","value","options","isNaN","integer","isInteger","finite","isFinite","zero","nonZero","positive","negative","nonPositive","nonNegative","gt","gte","lt","lte","annotatedArrays","WeakSet","vectors","notVectors","matrices","notMatrices","grids","toFixedArity","arity","min","getNumberVectorOrMatrixOperation","param","vector","Array","isArray","has","every","elem","add","matrix","nbrOfCols","row","some","cell","isMatrix","unaryMathOp","fn","operation","operand","map","val","mathUtilsModule","functions","sin","evaluate","docs","category","returns","type","args","x","variants","argumentNames","description","seeAlso","examples","asin","sinh","asinh","cos","acos","cosh","acosh","tan","atan","tanh","atanh","ln","log","log2","log10","PI"],"mappings":"aAEM,SAAUA,EAAcC,GAC5B,IAAKA,EAAeC,WAAaD,EAAeE,KAC9C,MAAO,GAET,MAAMC,EAAcH,EAAeC,SAASG,OAAS,EAC/CC,EAAeL,EAAeE,KAAKI,OAASH,EAAc,EAChE,MAAO,GAAG,IAAII,OAAOC,KAAKC,IAAIN,EAAa,OAAO,IAAII,OAAOC,KAAKC,IAAIJ,EAAc,KACtF,CCkBM,MAAOK,UAAkBC,MACbX,eACAY,aAChB,WAAAC,CAAYC,EAAcd,GACxB,MAAMe,EAAUD,aAAeH,MAC3BG,EAAIC,QACJ,GAAGD,IAEPE,MA/BJ,SAA6BD,EAAiBf,GAC5C,IAAKA,EACH,OAAOe,EAET,MAAME,EAAW,GAAGjB,EAAeC,SAASiB,QAAQlB,EAAeC,SAASG,SAM5E,MAAO,GAAGW,IALWf,EAAemB,SAChC,KAAKnB,EAAemB,YAAYF,IAChC,cAAcA,QACIjB,EAAeE,SACbH,EAAcC,IAExC,CAoBUoB,CAAoBL,EAASf,IACnCqB,KAAKT,aAAeG,EACpBM,KAAKrB,eAAiBA,EACtBsB,OAAOC,eAAeF,KAAMX,EAAUc,WACtCH,KAAKI,KAAO,WACb,CAEM,aAAA1B,GACL,OAAOsB,KAAKrB,gBAAkBD,EAAcsB,KAAKrB,eAClD,EC/BkB,IAAI0B,IAAIJ,OAAOK,OAbX,CACvBC,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,GAAM,KAC/CrD,MAAOD,EAAa,GACpB4B,KAAM,CACJC,SAAU,OACVC,QAAS,CAAEC,KAAM,CAAC,SAAU,SAAU,WACtCC,KAAM,CACJC,EAAG,CAAEF,KAAM,CAAC,SAAU,SAAU,YAElCG,SAAU,CAAC,CAAEC,cAAe,CAAC,OAC7BC,YAAa,qOACbC,QAAS,CAAC,cAAe,WAAY,WAAY,YACjDC,SAAU,CACR,2CACA,4CACA,6CACA,6CACA,sDACA,kEAIN,SAAU,CACRX,SAAUT,EAAYK,GAAc,IAANA,EAAa9E,KAAK6G,IAChDrD,MAAOD,EAAa,GACpB4B,KAAM,CACJC,SAAU,OACVC,QAAS,CAAEC,KAAM,CAAC,SAAU,SAAU,WACtCC,KAAM,CACJC,EAAG,CAAEF,KAAM,CAAC,SAAU,SAAU,YAElCG,SAAU,CAAC,CAAEC,cAAe,CAAC,OAC7BC,YAAa,qOACbC,QAAS,CAAC,eACVC,SAAU,CACR,2CACA,4CACA,gDACA,oDACA,yDACA"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
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};export{S as matrixModule};
|
|
1
|
+
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};export{S as matrixModule};
|
|
2
2
|
//# sourceMappingURL=matrix.esm.js.map
|