mirror of
https://github.com/josdejong/mathjs.git
synced 2025-12-08 19:46:04 +00:00
Many functions in place in mainAll
This commit is contained in:
parent
95703df862
commit
0d93f45dfd
@ -327,5 +327,8 @@ export function createTyped (type) {
|
||||
}
|
||||
]
|
||||
|
||||
// TODO: this is a temporary test
|
||||
typed.type = type
|
||||
|
||||
return typed
|
||||
}
|
||||
|
||||
@ -14,11 +14,10 @@ const name = 'bitAnd'
|
||||
const dependencies = [
|
||||
'typed',
|
||||
'matrix',
|
||||
'equalScalar',
|
||||
'type.DenseMatrix'
|
||||
'equalScalar'
|
||||
]
|
||||
|
||||
export const createBitAnd = factory(name, dependencies, ({ typed, matrix, equalScalar, type: { DenseMatrix } }) => {
|
||||
export const createBitAnd = factory(name, dependencies, ({ typed, matrix, equalScalar }) => {
|
||||
const algorithm02 = createAlgorithm02({ typed, equalScalar })
|
||||
const algorithm06 = createAlgorithm06({ typed, equalScalar })
|
||||
const algorithm11 = createAlgorithm11({ typed, equalScalar })
|
||||
|
||||
500
src/mainAll.js
500
src/mainAll.js
@ -1,6 +1,4 @@
|
||||
import { create as _create } from './core/core'
|
||||
|
||||
// type
|
||||
import { createNumber } from './type/number'
|
||||
import { createBigNumberClass } from './type/bignumber/BigNumber'
|
||||
import { createBignumber } from './type/bignumber/function/bignumber'
|
||||
@ -12,8 +10,6 @@ import { createMatrix } from './type/matrix/function/matrix'
|
||||
import { createMatrixClass } from './type/matrix/Matrix'
|
||||
import { createDenseMatrixClass } from './type/matrix/DenseMatrix'
|
||||
import { createSparseMatrixClass } from './type/matrix/SparseMatrix'
|
||||
|
||||
// arithmetic
|
||||
import { createAbs } from './function/arithmetic/abs'
|
||||
import { createAdd } from './function/arithmetic/add'
|
||||
import { createAddScalar } from './function/arithmetic/addScalar'
|
||||
@ -51,13 +47,9 @@ import { createSubtract } from './function/arithmetic/subtract'
|
||||
import { createUnaryMinus } from './function/arithmetic/unaryMinus'
|
||||
import { createUnaryPlus } from './function/arithmetic/unaryPlus'
|
||||
import { createXgcd } from './function/arithmetic/xgcd'
|
||||
|
||||
// relational
|
||||
import { createEqualScalar } from './function/relational/equalScalar'
|
||||
import { createSmaller } from './function/relational/smaller'
|
||||
import { createLarger } from './function/relational/larger'
|
||||
|
||||
// utils
|
||||
import { createClone } from './function/utils/clone'
|
||||
import { createIsInteger } from './function/utils/isInteger'
|
||||
import { createIsNegative } from './function/utils/isNegative'
|
||||
@ -69,6 +61,119 @@ import { createIsNaN } from './function/utils/isNaN'
|
||||
import { createNumeric } from './function/utils/numeric'
|
||||
import { createTypeOf } from './function/utils/typeOf'
|
||||
import { createEmbeddedDocs } from './expression/embeddedDocs'
|
||||
import { createUnitClass } from './type/unit/Unit'
|
||||
import { createUnit } from './type/unit/function/unit'
|
||||
import { createArg } from './function/complex/arg'
|
||||
import { createConj } from './function/complex/conj'
|
||||
import { createIm } from './function/complex/im'
|
||||
import { createRe } from './function/complex/re'
|
||||
import { createLeftShift } from './function/bitwise/leftShift'
|
||||
import { createRightArithShift } from './function/bitwise/rightArithShift'
|
||||
import { createRightLogShift } from './function/bitwise/rightLogShift'
|
||||
import { createBitXor } from './function/bitwise/bitXor'
|
||||
import { createBitOr } from './function/bitwise/bitOr'
|
||||
import { createBitNot } from './function/bitwise/bitNot'
|
||||
import { createBitAnd } from './function/bitwise/bitAnd'
|
||||
import { createCompare } from './function/relational/compare'
|
||||
import { createCompareNatural } from './function/relational/compareNatural'
|
||||
import { createDeepEqual } from './function/relational/deepEqual'
|
||||
import { createCompareText } from './function/relational/compareText'
|
||||
import { createEqual } from './function/relational/equal'
|
||||
import { createEqualText } from './function/relational/equalText'
|
||||
import { createLargerEq } from './function/relational/largerEq'
|
||||
import { createSmallerEq } from './function/relational/smallerEq'
|
||||
import { createUnequal } from './function/relational/unequal'
|
||||
import { createPrint } from './function/string/print'
|
||||
import { createFormat } from './function/string/format'
|
||||
import { createAnd } from './function/logical/and'
|
||||
import { createXor } from './function/logical/xor'
|
||||
import { createOr } from './function/logical/or'
|
||||
import { createNot } from './function/logical/not'
|
||||
import { createParseExpression } from './expression/parse'
|
||||
import { createEval } from './expression/function/eval'
|
||||
import { createCompile } from './expression/function/compile'
|
||||
import { createParse } from './expression/function/parse'
|
||||
import { createSymbolNode } from './expression/node/SymbolNode'
|
||||
import { createRelationalNode } from './expression/node/RelationalNode'
|
||||
import { createRangeNode } from './expression/node/RangeNode'
|
||||
import { createParenthesisNode } from './expression/node/ParenthesisNode'
|
||||
import { createOperatorNode } from './expression/node/OperatorNode'
|
||||
import { createObjectNode } from './expression/node/ObjectNode'
|
||||
import { createIndexNode } from './expression/node/IndexNode'
|
||||
import { createFunctionNode } from './expression/node/FunctionNode'
|
||||
import { createFunctionAssignmentNode } from './expression/node/FunctionAssignmentNode'
|
||||
import { createConstantNode } from './expression/node/ConstantNode'
|
||||
import { createConditionalNode } from './expression/node/ConditionalNode'
|
||||
import { createBlockNode } from './expression/node/BlockNode'
|
||||
import { createAssignmentNode } from './expression/node/AssignmentNode'
|
||||
import { createArrayNode } from './expression/node/ArrayNode'
|
||||
import { createAccessorNode } from './expression/node/AccessorNode'
|
||||
import { createNode } from './expression/node/Node'
|
||||
import { createParserClass } from './expression/Parser'
|
||||
import { createImmutableDenseMatrixClass } from './type/matrix/ImmutableDenseMatrix'
|
||||
import { createIndexClass } from './type/matrix/MatrixIndex'
|
||||
import { createRangeClass } from './type/matrix/Range'
|
||||
import { createResultSet } from './type/resultset/ResultSet'
|
||||
import { createChainClass } from './type/chain/Chain'
|
||||
import { createChain } from './type/chain/function/chain'
|
||||
import { createSpaClass } from './type/matrix/Spa'
|
||||
import { createFibonacciHeapClass } from './type/matrix/FibonacciHeap'
|
||||
import { createSparse } from './type/matrix/function/sparse'
|
||||
import { createBoolean } from './type/boolean'
|
||||
import { createString } from './type/string'
|
||||
import { createIdentity } from './function/matrix/identity'
|
||||
import { createGetMatrixDataType } from './function/matrix/getMatrixDataType'
|
||||
import { createPartitionSelect } from './function/matrix/partitionSelect'
|
||||
import { createReshape } from './function/matrix/reshape'
|
||||
import { createResize } from './function/matrix/resize'
|
||||
import { createSize } from './function/matrix/size'
|
||||
import { createSqueeze } from './function/matrix/squeeze'
|
||||
import { createZeros } from './function/matrix/zeros'
|
||||
import { createTranspose } from './function/matrix/transpose'
|
||||
import { createTrace } from './function/matrix/trace'
|
||||
import { createSubset } from './function/matrix/subset'
|
||||
import { createSqrtm } from './function/matrix/sqrtm'
|
||||
import { createSort } from './function/matrix/sort'
|
||||
import { createRange } from './function/matrix/range'
|
||||
import { createOnes } from './function/matrix/ones'
|
||||
import { createMap } from './function/matrix/map'
|
||||
import { createKron } from './function/matrix/kron'
|
||||
import { createInv } from './function/matrix/inv'
|
||||
import { createIndex } from './type/matrix/function'
|
||||
import { createForEach } from './function/matrix/forEach'
|
||||
import { createFlatten } from './function/matrix/flatten'
|
||||
import { createFilter } from './function/matrix/filter'
|
||||
import { createEye } from './function/matrix/eye'
|
||||
import { createExpm } from './function/matrix/expm'
|
||||
import { createDot } from './function/matrix/dot'
|
||||
import { createDiag } from './function/matrix/diag'
|
||||
import { createDet } from './function/matrix/det'
|
||||
import { createCtranspose } from './function/matrix/ctranspose'
|
||||
import { createCross } from './function/matrix/cross'
|
||||
import { createConcat } from './function/matrix/concat'
|
||||
import { createMax } from './function/statistics/max'
|
||||
import { createMean } from './function/statistics/mean'
|
||||
import { createQuantileSeq } from './function/statistics/quantileSeq'
|
||||
import { createVariance } from './function/statistics/variance'
|
||||
import { createMedian } from './function/statistics/median'
|
||||
import { createSum } from './function/statistics/sum'
|
||||
import { createStd } from './function/statistics/std'
|
||||
import { createProd } from './function/statistics/prod'
|
||||
import { createMode } from './function/statistics/mode'
|
||||
import { createMin } from './function/statistics/min'
|
||||
import { createMad } from './function/statistics/mad'
|
||||
import { createLsolve } from './function/algebra/solver/lsolve'
|
||||
import { createRationalize } from './function/algebra/rationalize'
|
||||
import { createLusolve } from './function/algebra/solver/lusolve'
|
||||
import { createUsolve } from './function/algebra/solver/usolve'
|
||||
import { createDerivative } from './function/algebra/derivative'
|
||||
import { createSimplify } from './function/algebra/simplify'
|
||||
import { createSlu } from './function/algebra/decomposition/slu'
|
||||
import { createQr } from './function/algebra/decomposition/qr'
|
||||
import { createLup } from './function/algebra/decomposition/lup'
|
||||
import { createResolve } from './function/algebra/simplify/resolve'
|
||||
import { createSimplifyConstant } from './function/algebra/simplify/simplifyConstant'
|
||||
import { createSimplifyCore } from './function/algebra/simplify/simplifyCore'
|
||||
|
||||
const math = _create()
|
||||
|
||||
@ -91,49 +196,27 @@ export const typeOf = createTypeOf({ typed })
|
||||
// relational (1)
|
||||
export const equalScalar = createEqualScalar({ typed, config })
|
||||
|
||||
export const Matrix = createMatrixClass()
|
||||
// class (1)
|
||||
export const ResultSet = createResultSet()
|
||||
export const BigNumber = createBigNumberClass({ config, on })
|
||||
export const Complex = createComplexClass({ config, on })
|
||||
export const Complex = createComplexClass({ typed, config, on })
|
||||
export const Fraction = createFractionClass()
|
||||
export const Range = createRangeClass()
|
||||
export const Matrix = createMatrixClass()
|
||||
export const DenseMatrix = createDenseMatrixClass({ typed, type: { Matrix } })
|
||||
export const SparseMatrix = createSparseMatrixClass({ typed, equalScalar, type: { Matrix } })
|
||||
|
||||
// for backward compatibility
|
||||
export const type = {
|
||||
BigNumber,
|
||||
Complex,
|
||||
Matrix,
|
||||
DenseMatrix,
|
||||
SparseMatrix
|
||||
}
|
||||
|
||||
// type
|
||||
// create (1)
|
||||
export const number = createNumber({ typed })
|
||||
export const string = createString({ typed })
|
||||
export const boolean = createBoolean({ typed })
|
||||
export const bignumber = createBignumber({ typed, type: { BigNumber } })
|
||||
export const complex = createComplex({ typed, type: { Complex } })
|
||||
export const fraction = createFraction({ typed, type: { Fraction } })
|
||||
export const matrix = createMatrix({ typed, type: { Matrix } })
|
||||
|
||||
// utils (2)
|
||||
export const isPrime = createIsPrime({ typed, type: { BigNumber } })
|
||||
export const numeric = createNumeric({ typed, number, bignumber, fraction })
|
||||
export const sparse = createSparse({ typed, type: { SparseMatrix } })
|
||||
|
||||
// arithmetic (1)
|
||||
export const divideScalar = createDivideScalar({ typed, numeric })
|
||||
|
||||
// complex (1)
|
||||
export const conj = () => { throw new Error('Sorry conj is not yet implemented') } // FIXME: load conj
|
||||
|
||||
// matrix (1)
|
||||
export const identity = () => { throw new Error('Sorry identity is not yet implemented') } // FIXME: load identity
|
||||
export const inv = () => { throw new Error('Sorry inv is not yet implemented') } // FIXME: load inv
|
||||
export const zeros = () => { throw new Error('Sorry zeros is not yet implemented') } // FIXME: load zeros
|
||||
|
||||
// relational (2)
|
||||
export const smaller = createSmaller({ typed, config, matrix, equalScalar, divideScalar, type: { DenseMatrix } })
|
||||
export const larger = createLarger({ typed, config, matrix, type: { DenseMatrix } })
|
||||
|
||||
// arithmetic (2)
|
||||
export const unaryMinus = createUnaryMinus({ typed })
|
||||
export const unaryPlus = createUnaryPlus({ typed, config, type: { BigNumber } })
|
||||
export const abs = createAbs({ typed })
|
||||
@ -148,32 +231,355 @@ export const fix = createFix({ typed, type: { Complex } })
|
||||
export const floor = createFloor({ typed })
|
||||
export const gcd = createGcd({ typed, matrix, equalScalar, type: { BigNumber, DenseMatrix } })
|
||||
export const lcm = createLcm({ typed, matrix, equalScalar })
|
||||
export const log = createLog({ typed, config, divideScalar, type: { Complex } })
|
||||
export const log10 = createLog10({ typed, config, type: { Complex } })
|
||||
export const log1p = createLog1p({ typed, config, divideScalar, log, type: { Complex } })
|
||||
export const log2 = createLog2({ typed, config, type: { Complex } })
|
||||
export const mod = createMod({ typed, matrix, equalScalar, type: { DenseMatrix } })
|
||||
export const multiplyScalar = createMultiplyScalar({ typed })
|
||||
export const multiply = createMultiply({ typed, matrix, addScalar, multiplyScalar, equalScalar })
|
||||
export const nthRoot = createNthRoot({ typed, matrix, equalScalar, type: { BigNumber } })
|
||||
export const nthRoots = createNthRoots({ typed, config, divideScalar, type: { Complex } })
|
||||
export const pow = createPow({ typed, config, identity, multiply, matrix, number, fraction, type: { Complex } })
|
||||
export const round = createRound({ typed, matrix, equalScalar, zeros, type: { BigNumber, DenseMatrix } })
|
||||
export const sign = createSign({ typed, type: { BigNumber, Fraction } })
|
||||
export const sqrt = createSqrt({ config, typed, type: { Complex } })
|
||||
export const square = createSquare({ typed })
|
||||
export const subtract = createSubtract({ typed, matrix, equalScalar, addScalar, unaryMinus, type: { DenseMatrix } })
|
||||
export const xgcd = createXgcd({ typed, config, matrix, type: { BigNumber } })
|
||||
export const divide = createDivide({ typed, matrix, multiply, equalScalar, divideScalar, inv })
|
||||
export const hypot = createHypot({ typed, abs, addScalar, divideScalar, multiplyScalar, sqrt, smaller, isPositive })
|
||||
export const norm = createNorm({ typed, abs, add, pow, conj, sqrt, multiply, equalScalar, larger, smaller, matrix })
|
||||
export const dotMultiply = createDotMultiply({ typed, matrix, equalScalar, multiplyScalar })
|
||||
|
||||
// bitwise (1)
|
||||
export const bitAnd = createBitAnd({ typed, matrix, equalScalar })
|
||||
export const bitNot = createBitNot({ typed })
|
||||
export const bitOr = createBitOr({ typed, matrix, equalScalar, type: { DenseMatrix } })
|
||||
export const bitXor = createBitXor({ typed, matrix, type: { DenseMatrix } })
|
||||
|
||||
// complex (1)
|
||||
export const arg = createArg({ typed, type: { BigNumber } })
|
||||
export const conj = createConj({ typed })
|
||||
export const im = createIm({ typed })
|
||||
export const re = createRe({ typed })
|
||||
|
||||
// logical (1)
|
||||
export const not = createNot({ typed })
|
||||
export const or = createOr({ typed, matrix, equalScalar, type: { DenseMatrix } })
|
||||
export const xor = createXor({ typed, matrix, type: { DenseMatrix } })
|
||||
|
||||
// matrix (1)
|
||||
export const concat = createConcat({ typed, matrix, isInteger })
|
||||
export const cross = createCross({ typed, matrix, subtract, multiply })
|
||||
export const diag = createDiag({ typed, matrix, type: { Matrix } })
|
||||
export const dot = createDot({ typed, add, multiply })
|
||||
export const eye = createEye({ typed, matrix })
|
||||
export const filter = createFilter({ typed, matrix })
|
||||
export const flatten = createFlatten({ typed, matrix })
|
||||
export const forEach = createForEach({ typed })
|
||||
export const getMatrixDataType = createGetMatrixDataType({ typed })
|
||||
export const identity = createIdentity({ typed, config, matrix, type: { BigNumber, Matrix } })
|
||||
export const kron = createKron({ typed, matrix, multiplyScalar })
|
||||
export const map = createMap({ typed })
|
||||
export const ones = createOnes({ typed, config, matrix, type: { BigNumber } })
|
||||
export const range = createRange({ typed, config, matrix, type: { BigNumber } })
|
||||
export const reshape = createReshape({ typed, isInteger, matrix })
|
||||
export const resize = createResize({ config, matrix })
|
||||
export const size = createSize({ typed, config, matrix })
|
||||
export const squeeze = createSqueeze({ typed, matrix })
|
||||
export const subset = createSubset({ typed, matrix })
|
||||
export const trace = createTrace({ typed, matrix, add })
|
||||
export const transpose = createTranspose({ typed, matrix })
|
||||
export const ctranspose = createCtranspose({ typed, transpose, conj })
|
||||
export const zeros = createZeros({ typed, config, matrix, type: { BigNumber } })
|
||||
|
||||
// statistics (1)
|
||||
export const mode = createMode({ typed, isNaN, isNumeric })
|
||||
export const prod = createProd({ typed, multiply })
|
||||
export const sum = createSum({ typed, config, add, type: { BigNumber, Fraction } })
|
||||
|
||||
// string (1)
|
||||
export const format = createFormat({ typed })
|
||||
export const print = createPrint({ typed })
|
||||
|
||||
// utils (2)
|
||||
export const isPrime = createIsPrime({ typed, type: { BigNumber } })
|
||||
export const numeric = createNumeric({ typed, number, bignumber, fraction })
|
||||
|
||||
// arithmetic (2)
|
||||
export const divideScalar = createDivideScalar({ typed, numeric })
|
||||
export const pow = createPow({ typed, config, identity, multiply, matrix, number, fraction, type: { Complex } })
|
||||
export const round = createRound({ typed, matrix, equalScalar, zeros, type: { BigNumber, DenseMatrix } })
|
||||
export const log = createLog({ typed, config, divideScalar, type: { Complex } })
|
||||
export const log1p = createLog1p({ typed, config, divideScalar, log, type: { Complex } })
|
||||
export const nthRoots = createNthRoots({ typed, config, divideScalar, type: { Complex } })
|
||||
export const dotPow = createDotPow({ typed, equalScalar, matrix, pow, type: { DenseMatrix } })
|
||||
export const dotDivide = createDotDivide({ typed, matrix, equalScalar, divideScalar, type: { DenseMatrix } })
|
||||
|
||||
// algebra (2)
|
||||
export const lsolve = createLsolve({ typed, matrix, divideScalar, multiplyScalar, subtract, equalScalar, type: { DenseMatrix } })
|
||||
export const usolve = createUsolve({ typed, matrix, divideScalar, multiplyScalar, subtract, equalScalar, type: { DenseMatrix } })
|
||||
|
||||
// bitwise (2)
|
||||
export const leftShift = createLeftShift({ typed, matrix, equalScalar, zeros, type: { DenseMatrix } })
|
||||
export const rightArithShift = createRightArithShift({ typed, matrix, equalScalar, zeros, type: { DenseMatrix } })
|
||||
export const rightLogShift = createRightLogShift({ typed, matrix, equalScalar, zeros, type: { DenseMatrix } })
|
||||
|
||||
// logical (2)
|
||||
export const and = createAnd({ typed, matrix, equalScalar, zeros, not })
|
||||
|
||||
// relational (2)
|
||||
export const compare = createCompare({ typed, config, equalScalar, matrix, type: { BigNumber, Fraction, DenseMatrix } })
|
||||
export const compareNatural = createCompareNatural({ typed, compare })
|
||||
export const compareText = createCompareText({ typed, config, matrix })
|
||||
export const equal = createEqual({ typed, matrix, equalScalar, type: { DenseMatrix } })
|
||||
export const equalText = createEqualText({ typed, compareText, isZero })
|
||||
export const smaller = createSmaller({ typed, config, matrix, equalScalar, divideScalar, type: { DenseMatrix } })
|
||||
export const smallerEq = createSmallerEq({ typed, config, matrix, type: { DenseMatrix } })
|
||||
export const larger = createLarger({ typed, config, matrix, type: { DenseMatrix } })
|
||||
export const largerEq = createLargerEq({ typed, config, matrix, type: { DenseMatrix } })
|
||||
export const deepEqual = createDeepEqual({ typed, equal })
|
||||
export const unequal = createUnequal({ typed, config, matrix, type: { DenseMatrix } })
|
||||
|
||||
// matrix (2)
|
||||
export const partitionSelect = createPartitionSelect({ typed, isNumeric, isNaN, compare })
|
||||
export const sort = createSort({ typed, matrix, compare, compareNatural })
|
||||
|
||||
// statistics (2)
|
||||
export const max = createMax({ typed, larger })
|
||||
export const min = createMin({ typed, smaller })
|
||||
export const quantileSeq = createQuantileSeq({ typed, add, multiply, partitionSelect, compare, type: { BigNumber } })
|
||||
|
||||
// class (2)
|
||||
export const ImmutableDenseMatrix = createImmutableDenseMatrixClass({ smaller, type: { DenseMatrix } })
|
||||
export const Index = createIndexClass({ type: { ImmutableDenseMatrix } })
|
||||
export const FibonacciHeap = createFibonacciHeapClass({ smaller, larger })
|
||||
export const Spa = createSpaClass({ addScalar, equalScalar, type: { FibonacciHeap } })
|
||||
export const Unit = createUnitClass({
|
||||
config,
|
||||
on,
|
||||
addScalar,
|
||||
subtract,
|
||||
multiplyScalar,
|
||||
divideScalar,
|
||||
pow,
|
||||
abs,
|
||||
fix,
|
||||
round,
|
||||
equal,
|
||||
isNumeric,
|
||||
format,
|
||||
number,
|
||||
type: { Complex, BigNumber, Fraction }
|
||||
})
|
||||
|
||||
// type (2)
|
||||
export const unit = createUnit({ typed, type: { Unit } })
|
||||
|
||||
// arithmetic (3)
|
||||
export const hypot = createHypot({ typed, abs, addScalar, divideScalar, multiplyScalar, sqrt, smaller, isPositive })
|
||||
export const norm = createNorm({ typed, abs, add, pow, conj, sqrt, multiply, equalScalar, larger, smaller, matrix })
|
||||
|
||||
// matrix (3)
|
||||
export const index = createIndex({ typed, type: { Index } })
|
||||
|
||||
// FIXME: import all functions in math2
|
||||
const math2 = {
|
||||
abs
|
||||
}
|
||||
const math2WithTransform = Object.assign({}, math2)
|
||||
|
||||
// expression (3)
|
||||
export const Node = createNode({ expression: { mathWithTransform: math2WithTransform } })
|
||||
export const AccessorNode = createAccessorNode({ subset, expression: { node: { Node } } })
|
||||
export const ArrayNode = createArrayNode({ expression: { node: { Node } } })
|
||||
export const AssignmentNode = createAssignmentNode({ subset, matrix, expression: { node: { Node } } })
|
||||
export const BlockNode = createBlockNode({ type: { ResultSet }, expression: { node: { Node } } })
|
||||
export const ConditionalNode = createConditionalNode({ expression: { node: { Node } } })
|
||||
export const ConstantNode = createConstantNode({ expression: { node: { Node } } })
|
||||
export const FunctionAssignmentNode = createFunctionAssignmentNode({ typed, expression: { node: { Node } } })
|
||||
export const IndexNode = createIndexNode({ type: { Range }, expression: { node: { Node } } })
|
||||
export const ObjectNode = createObjectNode({ expression: { node: { Node } } })
|
||||
export const OperatorNode = createOperatorNode({ expression: { node: { Node } } })
|
||||
export const ParenthesisNode = createParenthesisNode({ expression: { node: { Node } } })
|
||||
export const RangeNode = createRangeNode({ expression: { node: { Node } } })
|
||||
export const RelationalNode = createRelationalNode({ expression: { node: { Node } } })
|
||||
export const SymbolNode = createSymbolNode({ math: math2, type: { Unit }, expression: { node: { Node } } })
|
||||
export const FunctionNode = createFunctionNode({ math: math2, expression: { node: { Node, SymbolNode } } })
|
||||
const parseExpression = createParseExpression({
|
||||
numeric,
|
||||
config,
|
||||
expression: {
|
||||
node: {
|
||||
AccessorNode,
|
||||
ArrayNode,
|
||||
AssignmentNode,
|
||||
BlockNode,
|
||||
ConditionalNode,
|
||||
ConstantNode,
|
||||
FunctionAssignmentNode,
|
||||
FunctionNode,
|
||||
IndexNode,
|
||||
ObjectNode,
|
||||
OperatorNode,
|
||||
ParenthesisNode,
|
||||
RangeNode,
|
||||
RelationalNode,
|
||||
SymbolNode
|
||||
}
|
||||
}
|
||||
})
|
||||
export const parse = createParse({ typed, expression: { parse: parseExpression } })
|
||||
export const compile = createCompile({ typed, expression: { parse: parseExpression } })
|
||||
export const evaluate = createEval({ typed, expression: { parse: parseExpression } })
|
||||
export const Parser = createParserClass({ expression: { parse: parseExpression } })
|
||||
|
||||
// algebra (3)
|
||||
export const lup = createLup({
|
||||
typed,
|
||||
matrix,
|
||||
abs,
|
||||
addScalar,
|
||||
divideScalar,
|
||||
multiplyScalar,
|
||||
subtract,
|
||||
larger,
|
||||
equalScalar,
|
||||
unaryMinus,
|
||||
type: { DenseMatrix, SparseMatrix, Spa }
|
||||
})
|
||||
export const qr = createQr({
|
||||
typed,
|
||||
matrix,
|
||||
zeros,
|
||||
identity,
|
||||
isZero,
|
||||
unequal,
|
||||
sign,
|
||||
sqrt,
|
||||
conj,
|
||||
unaryMinus,
|
||||
addScalar,
|
||||
divideScalar,
|
||||
multiplyScalar,
|
||||
subtract
|
||||
})
|
||||
export const slu = createSlu({ typed, abs, add, multiply, transpose, divideScalar, subtract, larger, largerEq, type: { SparseMatrix } })
|
||||
export const lusolve = createLusolve({ typed, matrix, lup, slu, usolve, lsolve, type: { DenseMatrix } })
|
||||
|
||||
// class (3)
|
||||
export const Chain = createChainClass({ on, math: math2 })
|
||||
|
||||
// type (3)
|
||||
export const chain = createChain({ typed, type: { Chain } })
|
||||
|
||||
// matrix (4)
|
||||
export const det = createDet({ typed, matrix, subtract, multiply, unaryMinus, lup })
|
||||
export const inv = createInv({ typed, matrix, divideScalar, addScalar, multiply, unaryMinus, det, identity, abs })
|
||||
export const expm = createExpm({ typed, abs, add, identity, inv, multiply })
|
||||
export const sqrtm = createSqrtm({ typed, abs, add, multiply, sqrt, subtract, inv, size, max, identity })
|
||||
|
||||
// arithmetic (4)
|
||||
export const divide = createDivide({ typed, matrix, multiply, equalScalar, divideScalar, inv })
|
||||
|
||||
// statistics (4)
|
||||
export const mean = createMean({ typed, add, divide })
|
||||
export const median = createMedian({ typed, add, divide, compare, partitionSelect })
|
||||
export const mad = createMad({ typed, abs, map, median, subtract })
|
||||
export const variance = createVariance({ typed, add, subtract, multiply, divide, isNaN })
|
||||
export const std = createStd({ typed, sqrt, variance })
|
||||
|
||||
// algebra (4)
|
||||
const simplifyCore = createSimplifyCore({
|
||||
equal,
|
||||
isZero,
|
||||
add,
|
||||
subtract,
|
||||
multiply,
|
||||
divide,
|
||||
pow,
|
||||
expression: {
|
||||
node: {
|
||||
ConstantNode,
|
||||
OperatorNode,
|
||||
FunctionNode,
|
||||
ParenthesisNode
|
||||
}
|
||||
}
|
||||
})
|
||||
const simplifyConstant = createSimplifyConstant({
|
||||
typed,
|
||||
config,
|
||||
math: math2,
|
||||
fraction,
|
||||
bignumber,
|
||||
expression: {
|
||||
node: {
|
||||
ConstantNode,
|
||||
OperatorNode,
|
||||
FunctionNode,
|
||||
SymbolNode
|
||||
}
|
||||
}
|
||||
})
|
||||
const resolve = createResolve({ expression: { parse, node: { Node, FunctionNode, OperatorNode, ParenthesisNode } } })
|
||||
export const simplify = createSimplify({
|
||||
typed,
|
||||
math: math2,
|
||||
parse,
|
||||
equal,
|
||||
algebra: {
|
||||
simplify: {
|
||||
simplifyConstant,
|
||||
simplifyCore,
|
||||
resolve
|
||||
}
|
||||
},
|
||||
expression: {
|
||||
node: {
|
||||
ConstantNode,
|
||||
FunctionNode,
|
||||
OperatorNode,
|
||||
ParenthesisNode,
|
||||
SymbolNode
|
||||
}
|
||||
}
|
||||
})
|
||||
export const derivative = createDerivative({
|
||||
typed,
|
||||
config,
|
||||
parse,
|
||||
simplify,
|
||||
equal,
|
||||
isZero,
|
||||
numeric,
|
||||
expression: {
|
||||
node: {
|
||||
ConstantNode,
|
||||
FunctionNode,
|
||||
OperatorNode,
|
||||
ParenthesisNode,
|
||||
SymbolNode
|
||||
}
|
||||
}
|
||||
})
|
||||
export const rationalize = createRationalize({
|
||||
typed,
|
||||
parse,
|
||||
simplify,
|
||||
algebra: {
|
||||
simplify: {
|
||||
simplifyConstant,
|
||||
simplifyCore
|
||||
}
|
||||
},
|
||||
expression: {
|
||||
node: {
|
||||
ConstantNode,
|
||||
OperatorNode,
|
||||
SymbolNode
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// TODO: export constants
|
||||
// TODO: export physical constants
|
||||
|
||||
export const expression = {
|
||||
docs: createEmbeddedDocs()
|
||||
}
|
||||
|
||||
// TODO: create an export default for backward compatibility, with the whole old structure
|
||||
|
||||
@ -6,9 +6,9 @@ import { isUnit, isNumber } from '../../utils/is'
|
||||
import { factory } from '../../utils/factory'
|
||||
|
||||
const name = 'type.Complex'
|
||||
const dependencies = ['config', 'on']
|
||||
const dependencies = ['typed', 'config', 'on']
|
||||
|
||||
export const createComplexClass = factory(name, dependencies, ({ config, on }) => {
|
||||
export const createComplexClass = factory(name, dependencies, ({ typed, config, on }) => {
|
||||
/**
|
||||
* Attach type information
|
||||
*/
|
||||
@ -191,5 +191,11 @@ export const createComplexClass = factory(name, dependencies, ({ config, on }) =
|
||||
return 0
|
||||
}
|
||||
|
||||
// register with typed
|
||||
typed.type.Complex = Complex
|
||||
|
||||
return Complex
|
||||
})
|
||||
|
||||
// no lazy loading, we need to register with typed.type
|
||||
createComplexClass.lazy = false
|
||||
|
||||
@ -1,109 +1,109 @@
|
||||
// test abs
|
||||
import assert from 'assert'
|
||||
|
||||
import math from '../../../src/main'
|
||||
import { abs, bignumber, complex, fraction, matrix, Matrix, unit, parse } from '../../../src/mainAll'
|
||||
|
||||
describe('abs', function () {
|
||||
it('should return the abs value of a boolean', function () {
|
||||
assert.strictEqual(math.abs(true), 1)
|
||||
assert.strictEqual(math.abs(false), 0)
|
||||
assert.strictEqual(abs(true), 1)
|
||||
assert.strictEqual(abs(false), 0)
|
||||
})
|
||||
|
||||
it('should not support null', function () {
|
||||
assert.throws(function () { math.abs(null) }, /Unexpected type of argument/)
|
||||
assert.throws(function () { abs(null) }, /Unexpected type of argument/)
|
||||
})
|
||||
|
||||
it('should return the abs value of a number', function () {
|
||||
assert.strictEqual(math.abs(-4.2), 4.2)
|
||||
assert.strictEqual(math.abs(-3.5), 3.5)
|
||||
assert.strictEqual(math.abs(100), 100)
|
||||
assert.strictEqual(math.abs(0), 0)
|
||||
assert.strictEqual(abs(-4.2), 4.2)
|
||||
assert.strictEqual(abs(-3.5), 3.5)
|
||||
assert.strictEqual(abs(100), 100)
|
||||
assert.strictEqual(abs(0), 0)
|
||||
})
|
||||
|
||||
it('should return the absolute value of a big number', function () {
|
||||
assert.deepStrictEqual(math.abs(math.bignumber(-2.3)), math.bignumber(2.3))
|
||||
assert.deepStrictEqual(math.abs(math.bignumber('5e500')), math.bignumber('5e500'))
|
||||
assert.deepStrictEqual(math.abs(math.bignumber('-5e500')), math.bignumber('5e500'))
|
||||
assert.deepStrictEqual(abs(bignumber(-2.3)), bignumber(2.3))
|
||||
assert.deepStrictEqual(abs(bignumber('5e500')), bignumber('5e500'))
|
||||
assert.deepStrictEqual(abs(bignumber('-5e500')), bignumber('5e500'))
|
||||
})
|
||||
|
||||
it('should return the absolute value of a complex number', function () {
|
||||
assert.strictEqual(math.abs(math.complex(3, -4)), 5)
|
||||
assert.strictEqual(math.abs(math.complex(1e200, -4e200)), 4.12310562561766e+200)
|
||||
assert.strictEqual(abs(complex(3, -4)), 5)
|
||||
assert.strictEqual(abs(complex(1e200, -4e200)), 4.12310562561766e+200)
|
||||
})
|
||||
|
||||
it('should return the absolute value of a fraction', function () {
|
||||
const a = math.fraction('-1/3')
|
||||
assert.strictEqual(math.abs(a).toString(), '0.(3)')
|
||||
const a = fraction('-1/3')
|
||||
assert.strictEqual(abs(a).toString(), '0.(3)')
|
||||
assert.strictEqual(a.toString(), '-0.(3)')
|
||||
assert.strictEqual(math.abs(math.fraction('1/3')).toString(), '0.(3)')
|
||||
assert.strictEqual(abs(fraction('1/3')).toString(), '0.(3)')
|
||||
})
|
||||
|
||||
it('should convert a string to a number', function () {
|
||||
assert.strictEqual(math.abs('-2'), 2)
|
||||
assert.strictEqual(abs('-2'), 2)
|
||||
})
|
||||
|
||||
it('should return the absolute value of all elements in an Array', function () {
|
||||
let a1 = math.abs([1, -2, 3])
|
||||
let a1 = abs([1, -2, 3])
|
||||
assert.ok(Array.isArray(a1))
|
||||
assert.deepStrictEqual(a1, [1, 2, 3])
|
||||
a1 = math.abs([-2, -1, 0, 1, 2])
|
||||
a1 = abs([-2, -1, 0, 1, 2])
|
||||
assert.ok(Array.isArray(a1))
|
||||
assert.deepStrictEqual(a1, [2, 1, 0, 1, 2])
|
||||
})
|
||||
|
||||
it('should return the absolute number of a complex number with zero', function () {
|
||||
assert.strictEqual(math.abs(math.complex(1, 0)), 1)
|
||||
assert.strictEqual(math.abs(math.complex(0, 1)), 1)
|
||||
assert.strictEqual(math.abs(math.complex(0, 0)), 0)
|
||||
assert.strictEqual(math.abs(math.complex(-1, 0)), 1)
|
||||
assert.strictEqual(math.abs(math.complex(0, -1)), 1)
|
||||
assert.strictEqual(abs(complex(1, 0)), 1)
|
||||
assert.strictEqual(abs(complex(0, 1)), 1)
|
||||
assert.strictEqual(abs(complex(0, 0)), 0)
|
||||
assert.strictEqual(abs(complex(-1, 0)), 1)
|
||||
assert.strictEqual(abs(complex(0, -1)), 1)
|
||||
})
|
||||
|
||||
it('should return the absolute value of all elements in a matrix', function () {
|
||||
let a1 = math.abs(math.matrix([1, -2, 3]))
|
||||
assert.ok(a1 instanceof math.type.Matrix)
|
||||
let a1 = abs(matrix([1, -2, 3]))
|
||||
assert.ok(a1 instanceof Matrix)
|
||||
assert.deepStrictEqual(a1.size(), [3])
|
||||
assert.deepStrictEqual(a1.valueOf(), [1, 2, 3])
|
||||
a1 = math.abs(math.matrix([-2, -1, 0, 1, 2]))
|
||||
assert.ok(a1 instanceof math.type.Matrix)
|
||||
a1 = abs(matrix([-2, -1, 0, 1, 2]))
|
||||
assert.ok(a1 instanceof Matrix)
|
||||
assert.deepStrictEqual(a1.size(), [5])
|
||||
assert.deepStrictEqual(a1.valueOf(), [2, 1, 0, 1, 2])
|
||||
})
|
||||
|
||||
it('should return the absolute value of a unit', function () {
|
||||
let u = math.abs(math.unit('5 m'))
|
||||
let u = abs(unit('5 m'))
|
||||
assert.strictEqual(u.toString(), '5 m')
|
||||
|
||||
u = math.abs(math.unit('-5 m'))
|
||||
u = abs(unit('-5 m'))
|
||||
assert.strictEqual(u.toString(), '5 m')
|
||||
|
||||
u = math.abs(math.unit('-283.15 degC'))
|
||||
u = abs(unit('-283.15 degC'))
|
||||
assert.strictEqual(u.toString(), '-263.15 degC')
|
||||
|
||||
u = math.abs(math.unit(math.fraction(2, 3), 'm'))
|
||||
u = abs(unit(fraction(2, 3), 'm'))
|
||||
assert.strictEqual(u.toString(), '2/3 m')
|
||||
|
||||
u = math.abs(math.unit(math.complex(-4, 3), 'in'))
|
||||
u = abs(unit(complex(-4, 3), 'in'))
|
||||
assert.strictEqual(u.toString(), '5 in')
|
||||
})
|
||||
|
||||
it('should throw an error in case of invalid number of arguments', function () {
|
||||
assert.throws(function () { math.abs() }, /TypeError: Too few arguments/)
|
||||
assert.throws(function () { math.abs(1, 2) }, /TypeError: Too many arguments/)
|
||||
assert.throws(function () { abs() }, /TypeError: Too few arguments/)
|
||||
assert.throws(function () { abs(1, 2) }, /TypeError: Too many arguments/)
|
||||
})
|
||||
|
||||
it('should throw an in case of wrong type of arguments', function () {
|
||||
assert.throws(function () { math.abs(null) }, /TypeError: Unexpected type of argument/)
|
||||
assert.throws(function () { abs(null) }, /TypeError: Unexpected type of argument/)
|
||||
})
|
||||
|
||||
it('should throw an error in case of unsupported types', function () {
|
||||
assert.throws(function () { math.abs(new Date()) }, /TypeError: Unexpected type of argument/)
|
||||
assert.throws(function () { math.abs(null) }, /TypeError: Unexpected type of argument/)
|
||||
assert.throws(function () { math.abs(undefined) }, /TypeError: Unexpected type of argument/)
|
||||
assert.throws(function () { abs(new Date()) }, /TypeError: Unexpected type of argument/)
|
||||
assert.throws(function () { abs(null) }, /TypeError: Unexpected type of argument/)
|
||||
assert.throws(function () { abs(undefined) }, /TypeError: Unexpected type of argument/)
|
||||
})
|
||||
|
||||
it('should LaTeX abs', function () {
|
||||
const expression = math.parse('abs(-1)')
|
||||
const expression = parse('abs(-1)')
|
||||
assert.strictEqual(expression.toTex(), '\\left|-1\\right|')
|
||||
})
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user