├── .babelrc ├── .browserslistrc ├── .eslintrc.cjs ├── .github ├── FUNDING.yml ├── ISSUE_TEMPLATE │ └── new_issue.md └── workflows │ ├── build.yaml │ ├── lambdatest.yaml │ └── local-browser.yaml ├── .gitignore ├── .mailmap ├── .mocharc.json ├── .prettierrc.cjs ├── AUTHORS ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── HISTORY.md ├── LICENSE ├── NOTICE ├── README.md ├── SECURITY.md ├── bin ├── cli.js ├── package.json └── repl.js ├── docs ├── command_line_interface.md ├── core │ ├── chaining.md │ ├── configuration.md │ ├── extension.md │ ├── index.md │ └── serialization.md ├── custom_bundling.md ├── datatypes │ ├── bigints.md │ ├── bignumbers.md │ ├── complex_numbers.md │ ├── fractions.md │ ├── index.md │ ├── matrices.md │ ├── numbers.md │ └── units.md ├── expressions │ ├── algebra.md │ ├── customization.md │ ├── expression_trees.md │ ├── html_classes.md │ ├── index.md │ ├── parsing.md │ ├── security.md │ └── syntax.md ├── getting_started.md ├── index.md └── reference │ ├── .gitignore │ ├── .npmignore │ ├── classes.md │ ├── classes │ ├── densematrix.md │ ├── fibonacciheap.md │ ├── matrixindex.md │ ├── matrixrange.md │ ├── resultset.md │ ├── sparsematrix.md │ └── unit.md │ ├── constants.md │ ├── functions │ ├── .gitignore │ └── .npmignore │ └── index.md ├── examples ├── advanced │ ├── convert_fraction_to_bignumber.js │ ├── custom_argument_parsing.js │ ├── custom_datatype.js │ ├── custom_evaluate_using_factories.js │ ├── custom_evaluate_using_import.js │ ├── custom_loading.js │ ├── custom_relational_functions.js │ ├── custom_scope_objects.js │ ├── expression_trees.js │ ├── function_transform.js │ ├── more_secure_eval.js │ └── web_server │ │ ├── math_worker.js │ │ └── server.js ├── algebra.js ├── basic_usage.js ├── bignumbers.js ├── browser │ ├── angle_configuration.html │ ├── basic_usage.html │ ├── currency_conversion.html │ ├── custom_separators.html │ ├── lorenz.html │ ├── lorenz_interactive.html │ ├── plot.html │ ├── pretty_printing_with_mathjax.html │ ├── printing_html.html │ ├── requirejs_loading.html │ ├── rocket_trajectory_optimization.html │ └── webworkers │ │ ├── webworkers.html │ │ └── worker.js ├── chaining.js ├── code editor │ ├── .gitignore │ ├── README.md │ ├── getExpressions.js │ ├── index.html │ ├── main.js │ ├── mathjs-lang.js │ ├── package-lock.json │ ├── package.json │ └── style.css ├── complex_numbers.js ├── expressions.js ├── fractions.js ├── import.js ├── matrices.js ├── objects.js ├── serialization.js ├── sparse_matrices.js └── units.js ├── gulpfile.js ├── hyperexecute.yaml ├── misc ├── how_to_publish.md ├── img │ ├── favicon.ico │ ├── favicon.png │ ├── favicon_16x16.png │ ├── favicon_256x256.png │ ├── favicon_75x75.png │ ├── mathjs.png │ ├── mathjs.svg │ ├── mathjs.txt │ ├── mathjs_100x30.png │ ├── mathjs_165x50.png │ ├── mathjs_330x100.png │ ├── mathjs_favicon.svg │ └── mathjs_source.svg └── lambdatest.svg ├── package-lock.json ├── package.json ├── src ├── constants.js ├── core │ ├── config.js │ ├── create.js │ └── function │ │ ├── config.js │ │ ├── import.js │ │ └── typed.js ├── defaultInstance.js ├── entry │ ├── allFactoriesAny.js │ ├── allFactoriesNumber.js │ ├── configReadonly.js │ ├── mainAny.js │ ├── mainNumber.js │ └── typeChecks.js ├── error │ ├── ArgumentsError.js │ ├── DimensionError.js │ └── IndexError.js ├── expression │ ├── Help.js │ ├── Parser.js │ ├── embeddedDocs │ │ ├── constants │ │ │ ├── Infinity.js │ │ │ ├── LN10.js │ │ │ ├── LN2.js │ │ │ ├── LOG10E.js │ │ │ ├── LOG2E.js │ │ │ ├── NaN.js │ │ │ ├── SQRT1_2.js │ │ │ ├── SQRT2.js │ │ │ ├── e.js │ │ │ ├── false.js │ │ │ ├── i.js │ │ │ ├── null.js │ │ │ ├── phi.js │ │ │ ├── pi.js │ │ │ ├── tau.js │ │ │ ├── true.js │ │ │ └── version.js │ │ ├── construction │ │ │ ├── bigint.js │ │ │ ├── bignumber.js │ │ │ ├── boolean.js │ │ │ ├── complex.js │ │ │ ├── createUnit.js │ │ │ ├── fraction.js │ │ │ ├── index.js │ │ │ ├── matrix.js │ │ │ ├── number.js │ │ │ ├── sparse.js │ │ │ ├── splitUnit.js │ │ │ ├── string.js │ │ │ └── unit.js │ │ ├── core │ │ │ ├── config.js │ │ │ ├── import.js │ │ │ └── typed.js │ │ ├── embeddedDocs.js │ │ └── function │ │ │ ├── algebra │ │ │ ├── derivative.js │ │ │ ├── leafCount.js │ │ │ ├── lsolve.js │ │ │ ├── lsolveAll.js │ │ │ ├── lup.js │ │ │ ├── lusolve.js │ │ │ ├── lyap.js │ │ │ ├── polynomialRoot.js │ │ │ ├── qr.js │ │ │ ├── rationalize.js │ │ │ ├── resolve.js │ │ │ ├── schur.js │ │ │ ├── simplify.js │ │ │ ├── simplifyConstant.js │ │ │ ├── simplifyCore.js │ │ │ ├── slu.js │ │ │ ├── sylvester.js │ │ │ ├── symbolicEqual.js │ │ │ ├── usolve.js │ │ │ └── usolveAll.js │ │ │ ├── arithmetic │ │ │ ├── abs.js │ │ │ ├── add.js │ │ │ ├── cbrt.js │ │ │ ├── ceil.js │ │ │ ├── cube.js │ │ │ ├── divide.js │ │ │ ├── dotDivide.js │ │ │ ├── dotMultiply.js │ │ │ ├── dotPow.js │ │ │ ├── exp.js │ │ │ ├── expm.js │ │ │ ├── expm1.js │ │ │ ├── fix.js │ │ │ ├── floor.js │ │ │ ├── gcd.js │ │ │ ├── hypot.js │ │ │ ├── invmod.js │ │ │ ├── lcm.js │ │ │ ├── log.js │ │ │ ├── log10.js │ │ │ ├── log1p.js │ │ │ ├── log2.js │ │ │ ├── mod.js │ │ │ ├── multiply.js │ │ │ ├── norm.js │ │ │ ├── nthRoot.js │ │ │ ├── nthRoots.js │ │ │ ├── pow.js │ │ │ ├── round.js │ │ │ ├── sign.js │ │ │ ├── sqrt.js │ │ │ ├── sqrtm.js │ │ │ ├── square.js │ │ │ ├── subtract.js │ │ │ ├── unaryMinus.js │ │ │ ├── unaryPlus.js │ │ │ └── xgcd.js │ │ │ ├── bitwise │ │ │ ├── bitAnd.js │ │ │ ├── bitNot.js │ │ │ ├── bitOr.js │ │ │ ├── bitXor.js │ │ │ ├── leftShift.js │ │ │ ├── rightArithShift.js │ │ │ └── rightLogShift.js │ │ │ ├── combinatorics │ │ │ ├── bellNumbers.js │ │ │ ├── catalan.js │ │ │ ├── composition.js │ │ │ └── stirlingS2.js │ │ │ ├── complex │ │ │ ├── arg.js │ │ │ ├── conj.js │ │ │ ├── im.js │ │ │ └── re.js │ │ │ ├── expression │ │ │ ├── compile.js │ │ │ ├── evaluate.js │ │ │ ├── help.js │ │ │ ├── parse.js │ │ │ └── parser.js │ │ │ ├── geometry │ │ │ ├── distance.js │ │ │ └── intersect.js │ │ │ ├── logical │ │ │ ├── and.js │ │ │ ├── not.js │ │ │ ├── or.js │ │ │ └── xor.js │ │ │ ├── matrix │ │ │ ├── column.js │ │ │ ├── concat.js │ │ │ ├── count.js │ │ │ ├── cross.js │ │ │ ├── ctranspose.js │ │ │ ├── det.js │ │ │ ├── diag.js │ │ │ ├── diff.js │ │ │ ├── dot.js │ │ │ ├── eigs.js │ │ │ ├── fft.js │ │ │ ├── filter.js │ │ │ ├── flatten.js │ │ │ ├── forEach.js │ │ │ ├── getMatrixDataType.js │ │ │ ├── identity.js │ │ │ ├── ifft.js │ │ │ ├── inv.js │ │ │ ├── kron.js │ │ │ ├── map.js │ │ │ ├── mapSlices.js │ │ │ ├── matrixFromColumns.js │ │ │ ├── matrixFromFunction.js │ │ │ ├── matrixFromRows.js │ │ │ ├── ones.js │ │ │ ├── partitionSelect.js │ │ │ ├── pinv.js │ │ │ ├── range.js │ │ │ ├── reshape.js │ │ │ ├── resize.js │ │ │ ├── rotate.js │ │ │ ├── rotationMatrix.js │ │ │ ├── row.js │ │ │ ├── size.js │ │ │ ├── sort.js │ │ │ ├── squeeze.js │ │ │ ├── subset.js │ │ │ ├── trace.js │ │ │ ├── transpose.js │ │ │ └── zeros.js │ │ │ ├── numeric │ │ │ └── solveODE.js │ │ │ ├── probability │ │ │ ├── combinations.js │ │ │ ├── combinationsWithRep.js │ │ │ ├── distribution.js │ │ │ ├── factorial.js │ │ │ ├── gamma.js │ │ │ ├── kldivergence.js │ │ │ ├── lgamma.js │ │ │ ├── multinomial.js │ │ │ ├── permutations.js │ │ │ ├── pickRandom.js │ │ │ ├── random.js │ │ │ └── randomInt.js │ │ │ ├── relational │ │ │ ├── compare.js │ │ │ ├── compareNatural.js │ │ │ ├── compareText.js │ │ │ ├── deepEqual.js │ │ │ ├── equal.js │ │ │ ├── equalText.js │ │ │ ├── larger.js │ │ │ ├── largerEq.js │ │ │ ├── smaller.js │ │ │ ├── smallerEq.js │ │ │ └── unequal.js │ │ │ ├── set │ │ │ ├── setCartesian.js │ │ │ ├── setDifference.js │ │ │ ├── setDistinct.js │ │ │ ├── setIntersect.js │ │ │ ├── setIsSubset.js │ │ │ ├── setMultiplicity.js │ │ │ ├── setPowerset.js │ │ │ ├── setSize.js │ │ │ ├── setSymDifference.js │ │ │ └── setUnion.js │ │ │ ├── signal │ │ │ ├── freqz.js │ │ │ └── zpk2tf.js │ │ │ ├── special │ │ │ ├── erf.js │ │ │ └── zeta.js │ │ │ ├── statistics │ │ │ ├── corr.js │ │ │ ├── cumsum.js │ │ │ ├── mad.js │ │ │ ├── max.js │ │ │ ├── mean.js │ │ │ ├── median.js │ │ │ ├── min.js │ │ │ ├── mode.js │ │ │ ├── prod.js │ │ │ ├── quantileSeq.js │ │ │ ├── std.js │ │ │ ├── sum.js │ │ │ └── variance.js │ │ │ ├── trigonometry │ │ │ ├── acos.js │ │ │ ├── acosh.js │ │ │ ├── acot.js │ │ │ ├── acoth.js │ │ │ ├── acsc.js │ │ │ ├── acsch.js │ │ │ ├── asec.js │ │ │ ├── asech.js │ │ │ ├── asin.js │ │ │ ├── asinh.js │ │ │ ├── atan.js │ │ │ ├── atan2.js │ │ │ ├── atanh.js │ │ │ ├── cos.js │ │ │ ├── cosh.js │ │ │ ├── cot.js │ │ │ ├── coth.js │ │ │ ├── csc.js │ │ │ ├── csch.js │ │ │ ├── sec.js │ │ │ ├── sech.js │ │ │ ├── sin.js │ │ │ ├── sinh.js │ │ │ ├── tan.js │ │ │ └── tanh.js │ │ │ ├── units │ │ │ └── to.js │ │ │ └── utils │ │ │ ├── bin.js │ │ │ ├── clone.js │ │ │ ├── format.js │ │ │ ├── hasNumericValue.js │ │ │ ├── hex.js │ │ │ ├── isInteger.js │ │ │ ├── isNaN.js │ │ │ ├── isNegative.js │ │ │ ├── isNumeric.js │ │ │ ├── isPositive.js │ │ │ ├── isPrime.js │ │ │ ├── isZero.js │ │ │ ├── numeric.js │ │ │ ├── oct.js │ │ │ ├── print.js │ │ │ └── typeOf.js │ ├── function │ │ ├── compile.js │ │ ├── evaluate.js │ │ ├── help.js │ │ └── parser.js │ ├── keywords.js │ ├── node │ │ ├── AccessorNode.js │ │ ├── ArrayNode.js │ │ ├── AssignmentNode.js │ │ ├── BlockNode.js │ │ ├── ConditionalNode.js │ │ ├── ConstantNode.js │ │ ├── FunctionAssignmentNode.js │ │ ├── FunctionNode.js │ │ ├── IndexNode.js │ │ ├── Node.js │ │ ├── ObjectNode.js │ │ ├── OperatorNode.js │ │ ├── ParenthesisNode.js │ │ ├── RangeNode.js │ │ ├── RelationalNode.js │ │ ├── SymbolNode.js │ │ └── utils │ │ │ ├── access.js │ │ │ └── assign.js │ ├── operators.js │ ├── parse.js │ └── transform │ │ ├── and.transform.js │ │ ├── bitAnd.transform.js │ │ ├── bitOr.transform.js │ │ ├── column.transform.js │ │ ├── concat.transform.js │ │ ├── cumsum.transform.js │ │ ├── diff.transform.js │ │ ├── filter.transform.js │ │ ├── forEach.transform.js │ │ ├── index.transform.js │ │ ├── map.transform.js │ │ ├── mapSlices.transform.js │ │ ├── max.transform.js │ │ ├── mean.transform.js │ │ ├── min.transform.js │ │ ├── or.transform.js │ │ ├── print.transform.js │ │ ├── quantileSeq.transform.js │ │ ├── range.transform.js │ │ ├── row.transform.js │ │ ├── std.transform.js │ │ ├── subset.transform.js │ │ ├── sum.transform.js │ │ ├── utils │ │ ├── compileInlineExpression.js │ │ ├── dimToZeroBase.js │ │ ├── errorTransform.js │ │ ├── lastDimToZeroBase.js │ │ └── transformCallback.js │ │ └── variance.transform.js ├── factoriesAny.js ├── factoriesNumber.js ├── function │ ├── algebra │ │ ├── decomposition │ │ │ ├── lup.js │ │ │ ├── qr.js │ │ │ ├── schur.js │ │ │ └── slu.js │ │ ├── derivative.js │ │ ├── leafCount.js │ │ ├── lyap.js │ │ ├── polynomialRoot.js │ │ ├── rationalize.js │ │ ├── resolve.js │ │ ├── simplify.js │ │ ├── simplify │ │ │ ├── util.js │ │ │ └── wildcards.js │ │ ├── simplifyConstant.js │ │ ├── simplifyCore.js │ │ ├── solver │ │ │ ├── lsolve.js │ │ │ ├── lsolveAll.js │ │ │ ├── lusolve.js │ │ │ ├── usolve.js │ │ │ ├── usolveAll.js │ │ │ └── utils │ │ │ │ └── solveValidation.js │ │ ├── sparse │ │ │ ├── README.md │ │ │ ├── csAmd.js │ │ │ ├── csChol.js │ │ │ ├── csCounts.js │ │ │ ├── csCumsum.js │ │ │ ├── csDfs.js │ │ │ ├── csEreach.js │ │ │ ├── csEtree.js │ │ │ ├── csFkeep.js │ │ │ ├── csFlip.js │ │ │ ├── csIpvec.js │ │ │ ├── csLeaf.js │ │ │ ├── csLu.js │ │ │ ├── csMark.js │ │ │ ├── csMarked.js │ │ │ ├── csPermute.js │ │ │ ├── csPost.js │ │ │ ├── csReach.js │ │ │ ├── csSpsolve.js │ │ │ ├── csSqr.js │ │ │ ├── csSymperm.js │ │ │ ├── csTdfs.js │ │ │ └── csUnflip.js │ │ ├── sylvester.js │ │ └── symbolicEqual.js │ ├── arithmetic │ │ ├── abs.js │ │ ├── add.js │ │ ├── addScalar.js │ │ ├── cbrt.js │ │ ├── ceil.js │ │ ├── cube.js │ │ ├── divide.js │ │ ├── divideScalar.js │ │ ├── dotDivide.js │ │ ├── dotMultiply.js │ │ ├── dotPow.js │ │ ├── exp.js │ │ ├── expm1.js │ │ ├── fix.js │ │ ├── floor.js │ │ ├── gcd.js │ │ ├── hypot.js │ │ ├── invmod.js │ │ ├── lcm.js │ │ ├── log.js │ │ ├── log10.js │ │ ├── log1p.js │ │ ├── log2.js │ │ ├── mod.js │ │ ├── multiply.js │ │ ├── multiplyScalar.js │ │ ├── norm.js │ │ ├── nthRoot.js │ │ ├── nthRoots.js │ │ ├── pow.js │ │ ├── round.js │ │ ├── sign.js │ │ ├── sqrt.js │ │ ├── square.js │ │ ├── subtract.js │ │ ├── subtractScalar.js │ │ ├── unaryMinus.js │ │ ├── unaryPlus.js │ │ └── xgcd.js │ ├── bitwise │ │ ├── bitAnd.js │ │ ├── bitNot.js │ │ ├── bitOr.js │ │ ├── bitXor.js │ │ ├── leftShift.js │ │ ├── rightArithShift.js │ │ ├── rightLogShift.js │ │ └── useMatrixForArrayScalar.js │ ├── combinatorics │ │ ├── bellNumbers.js │ │ ├── catalan.js │ │ ├── composition.js │ │ └── stirlingS2.js │ ├── complex │ │ ├── arg.js │ │ ├── conj.js │ │ ├── im.js │ │ └── re.js │ ├── geometry │ │ ├── distance.js │ │ └── intersect.js │ ├── logical │ │ ├── and.js │ │ ├── not.js │ │ ├── or.js │ │ └── xor.js │ ├── matrix │ │ ├── column.js │ │ ├── concat.js │ │ ├── count.js │ │ ├── cross.js │ │ ├── ctranspose.js │ │ ├── det.js │ │ ├── diag.js │ │ ├── diff.js │ │ ├── dot.js │ │ ├── eigs.js │ │ ├── eigs │ │ │ ├── complexEigs.js │ │ │ └── realSymmetric.js │ │ ├── expm.js │ │ ├── fft.js │ │ ├── filter.js │ │ ├── flatten.js │ │ ├── forEach.js │ │ ├── getMatrixDataType.js │ │ ├── identity.js │ │ ├── ifft.js │ │ ├── inv.js │ │ ├── kron.js │ │ ├── map.js │ │ ├── mapSlices.js │ │ ├── matrixFromColumns.js │ │ ├── matrixFromFunction.js │ │ ├── matrixFromRows.js │ │ ├── ones.js │ │ ├── partitionSelect.js │ │ ├── pinv.js │ │ ├── range.js │ │ ├── reshape.js │ │ ├── resize.js │ │ ├── rotate.js │ │ ├── rotationMatrix.js │ │ ├── row.js │ │ ├── size.js │ │ ├── sort.js │ │ ├── sqrtm.js │ │ ├── squeeze.js │ │ ├── subset.js │ │ ├── trace.js │ │ ├── transpose.js │ │ └── zeros.js │ ├── numeric │ │ └── solveODE.js │ ├── probability │ │ ├── combinations.js │ │ ├── combinationsWithRep.js │ │ ├── factorial.js │ │ ├── gamma.js │ │ ├── kldivergence.js │ │ ├── lgamma.js │ │ ├── multinomial.js │ │ ├── permutations.js │ │ ├── pickRandom.js │ │ ├── random.js │ │ ├── randomInt.js │ │ └── util │ │ │ ├── randomMatrix.js │ │ │ └── seededRNG.js │ ├── relational │ │ ├── compare.js │ │ ├── compareNatural.js │ │ ├── compareText.js │ │ ├── compareUnits.js │ │ ├── deepEqual.js │ │ ├── equal.js │ │ ├── equalScalar.js │ │ ├── equalText.js │ │ ├── larger.js │ │ ├── largerEq.js │ │ ├── smaller.js │ │ ├── smallerEq.js │ │ └── unequal.js │ ├── set │ │ ├── setCartesian.js │ │ ├── setDifference.js │ │ ├── setDistinct.js │ │ ├── setIntersect.js │ │ ├── setIsSubset.js │ │ ├── setMultiplicity.js │ │ ├── setPowerset.js │ │ ├── setSize.js │ │ ├── setSymDifference.js │ │ └── setUnion.js │ ├── signal │ │ ├── freqz.js │ │ └── zpk2tf.js │ ├── special │ │ ├── erf.js │ │ └── zeta.js │ ├── statistics │ │ ├── corr.js │ │ ├── cumsum.js │ │ ├── mad.js │ │ ├── max.js │ │ ├── mean.js │ │ ├── median.js │ │ ├── min.js │ │ ├── mode.js │ │ ├── prod.js │ │ ├── quantileSeq.js │ │ ├── std.js │ │ ├── sum.js │ │ ├── utils │ │ │ └── improveErrorMessage.js │ │ └── variance.js │ ├── string │ │ ├── bin.js │ │ ├── format.js │ │ ├── hex.js │ │ ├── oct.js │ │ └── print.js │ ├── trigonometry │ │ ├── acos.js │ │ ├── acosh.js │ │ ├── acot.js │ │ ├── acoth.js │ │ ├── acsc.js │ │ ├── acsch.js │ │ ├── asec.js │ │ ├── asech.js │ │ ├── asin.js │ │ ├── asinh.js │ │ ├── atan.js │ │ ├── atan2.js │ │ ├── atanh.js │ │ ├── cos.js │ │ ├── cosh.js │ │ ├── cot.js │ │ ├── coth.js │ │ ├── csc.js │ │ ├── csch.js │ │ ├── sec.js │ │ ├── sech.js │ │ ├── sin.js │ │ ├── sinh.js │ │ ├── tan.js │ │ ├── tanh.js │ │ └── trigUnit.js │ ├── unit │ │ └── to.js │ └── utils │ │ ├── clone.js │ │ ├── hasNumericValue.js │ │ ├── isInteger.js │ │ ├── isNaN.js │ │ ├── isNegative.js │ │ ├── isNumeric.js │ │ ├── isPositive.js │ │ ├── isPrime.js │ │ ├── isZero.js │ │ ├── numeric.js │ │ └── typeOf.js ├── header.js ├── index.js ├── json │ ├── replacer.js │ └── reviver.js ├── number.js ├── plain │ ├── bignumber │ │ ├── arithmetic.js │ │ └── index.js │ └── number │ │ ├── arithmetic.js │ │ ├── bitwise.js │ │ ├── combinations.js │ │ ├── constants.js │ │ ├── index.js │ │ ├── logical.js │ │ ├── probability.js │ │ ├── relational.js │ │ ├── trigonometry.js │ │ └── utils.js ├── type │ ├── bigint.js │ ├── bignumber │ │ ├── BigNumber.js │ │ └── function │ │ │ └── bignumber.js │ ├── boolean.js │ ├── chain │ │ ├── Chain.js │ │ └── function │ │ │ └── chain.js │ ├── complex │ │ ├── Complex.js │ │ └── function │ │ │ └── complex.js │ ├── fraction │ │ ├── Fraction.js │ │ └── function │ │ │ └── fraction.js │ ├── matrix │ │ ├── DenseMatrix.js │ │ ├── FibonacciHeap.js │ │ ├── ImmutableDenseMatrix.js │ │ ├── Matrix.js │ │ ├── MatrixIndex.js │ │ ├── Range.js │ │ ├── Spa.js │ │ ├── SparseMatrix.js │ │ ├── function │ │ │ ├── index.js │ │ │ ├── matrix.js │ │ │ └── sparse.js │ │ └── utils │ │ │ ├── README.md │ │ │ ├── broadcast.js │ │ │ ├── matAlgo01xDSid.js │ │ │ ├── matAlgo02xDS0.js │ │ │ ├── matAlgo03xDSf.js │ │ │ ├── matAlgo04xSidSid.js │ │ │ ├── matAlgo05xSfSf.js │ │ │ ├── matAlgo06xS0S0.js │ │ │ ├── matAlgo07xSSf.js │ │ │ ├── matAlgo08xS0Sid.js │ │ │ ├── matAlgo09xS0Sf.js │ │ │ ├── matAlgo10xSids.js │ │ │ ├── matAlgo11xS0s.js │ │ │ ├── matAlgo12xSfs.js │ │ │ ├── matAlgo13xDD.js │ │ │ ├── matAlgo14xDs.js │ │ │ └── matrixAlgorithmSuite.js │ ├── number.js │ ├── resultset │ │ └── ResultSet.js │ ├── string.js │ └── unit │ │ ├── Unit.js │ │ ├── function │ │ ├── createUnit.js │ │ ├── splitUnit.js │ │ └── unit.js │ │ └── physicalConstants.js ├── utils │ ├── array.js │ ├── bigint.js │ ├── bignumber │ │ ├── bitwise.js │ │ ├── constants.js │ │ ├── formatter.js │ │ └── nearlyEqual.js │ ├── collection.js │ ├── complex.js │ ├── customs.js │ ├── emitter.js │ ├── factory.js │ ├── function.js │ ├── is.js │ ├── latex.js │ ├── log.js │ ├── lruQueue.js │ ├── map.js │ ├── noop.js │ ├── number.js │ ├── object.js │ ├── optimizeCallback.js │ ├── print.js │ ├── product.js │ ├── scope.js │ ├── snapshot.js │ ├── string.js │ └── switch.js └── version.js ├── tea.yaml ├── test ├── benchmark │ ├── README.md │ ├── algebra.js │ ├── derivative.js │ ├── expression_parser.js │ ├── factorial.js │ ├── flatten.js │ ├── forEach.js │ ├── index.js │ ├── load.js │ ├── map.js │ ├── matrix_operations.js │ ├── matrix_operations_octave.m │ ├── matrix_operations_python.py │ ├── matrix_operations_results.txt │ ├── prime.js │ ├── roots.js │ ├── scope_variables.js │ ├── subset.js │ ├── unit_parser.js │ └── utils │ │ └── formatTaskResult.js ├── browser-test-config │ ├── base-karma.js │ ├── browser-tests.test.js │ ├── lambdatest-karma.js │ ├── local-karma.js │ └── package.json ├── generated-code-tests │ ├── dependencies.test.js │ └── entry │ │ ├── mainAny.test.js │ │ └── mainNumber.test.js ├── node-tests │ ├── browser.test.cjs │ ├── cli │ │ ├── cli.test.cjs │ │ ├── script1 │ │ └── script2 │ ├── commonjs.test.cjs │ ├── commonjsApp.cjs │ ├── commonjsAppNumberOnly.cjs │ ├── defaultInstance.test.cjs │ ├── doc.test.js │ ├── esm.test.js │ ├── esmApp.js │ ├── esmAppNumberOnly.js │ ├── function │ │ ├── alegbra │ │ │ ├── decomposition │ │ │ │ └── slu.test.js │ │ │ └── sparse │ │ │ │ ├── csAmd.test.js │ │ │ │ └── csLu.test.js │ │ └── arithmetic │ │ │ └── multiply.test.js │ ├── pollutedObjectPrototype.js │ └── treeShaking │ │ ├── .gitignore │ │ ├── treeShaking.test.js │ │ └── treeShakingApp.js ├── typescript-tests │ └── testTypes.ts └── unit-tests │ ├── approx.test.js │ ├── constants.test.js │ ├── core │ ├── config.test.js │ ├── import.test.js │ ├── index.test.js │ └── typed.test.js │ ├── error │ ├── ArgumentsError.test.js │ ├── DimensionError.test.js │ └── IndexError.test.js │ ├── expression │ ├── Help.test.js │ ├── Parser.test.js │ ├── function │ │ ├── compile.test.js │ │ ├── evaluate.test.js │ │ ├── help.test.js │ │ ├── parse.test.js │ │ └── parser.test.js │ ├── keywords.test.js │ ├── node │ │ ├── AccessorNode.test.js │ │ ├── ArrayNode.test.js │ │ ├── AssignmentNode.test.js │ │ ├── BlockNode.test.js │ │ ├── ConditionalNode.test.js │ │ ├── ConstantNode.test.js │ │ ├── FunctionAssignmentNode.test.js │ │ ├── FunctionNode.test.js │ │ ├── IndexNode.test.js │ │ ├── Node.test.js │ │ ├── ObjectNode.test.js │ │ ├── OperatorNode.test.js │ │ ├── ParenthesisNode.test.js │ │ ├── RangeNode.test.js │ │ ├── RelationalNode.test.js │ │ └── SymbolNode.test.js │ ├── operators.test.js │ ├── parse.test.js │ ├── security.test.js │ ├── transform │ │ ├── cumsum.transform.test.js │ │ ├── diff.transform.test.js │ │ ├── mapSlices.transform.test.js │ │ ├── std.transform.test.js │ │ ├── utils │ │ │ └── lastDimToZeroBase.test.js │ │ └── variance.transform.test.js │ └── transforms.test.js │ ├── function │ ├── algebra │ │ ├── decomposition │ │ │ ├── lup.test.js │ │ │ ├── qr.test.js │ │ │ ├── schur.test.js │ │ │ └── slu.test.js │ │ ├── derivative.test.js │ │ ├── leafCount.test.js │ │ ├── lyap.test.js │ │ ├── polynomialRoot.test.js │ │ ├── rationalize.test.js │ │ ├── resolve.test.js │ │ ├── simplify.test.js │ │ ├── simplifyConstant.test.js │ │ ├── simplifyCore.test.js │ │ ├── solver │ │ │ ├── lsolve.test.js │ │ │ ├── lsolveAll.test.js │ │ │ ├── lusolve.test.js │ │ │ ├── usolve.test.js │ │ │ └── usolveAll.test.js │ │ ├── sparse │ │ │ └── csLu.test.js │ │ ├── sylvester.test.js │ │ └── symbolicEqual.test.js │ ├── arithmetic │ │ ├── abs.test.js │ │ ├── add.test.js │ │ ├── addScalar.test.js │ │ ├── cbrt.test.js │ │ ├── ceil.test.js │ │ ├── createHypot.test.js │ │ ├── cube.test.js │ │ ├── divide.test.js │ │ ├── dotDivide.test.js │ │ ├── dotMultiply.test.js │ │ ├── dotPow.test.js │ │ ├── exp.test.js │ │ ├── expm1.test.js │ │ ├── fix.test.js │ │ ├── floor.test.js │ │ ├── gcd.test.js │ │ ├── invmod.test.js │ │ ├── lcm.test.js │ │ ├── log.test.js │ │ ├── log10.test.js │ │ ├── log1p.test.js │ │ ├── log2.test.js │ │ ├── mod.test.js │ │ ├── multiply.test.js │ │ ├── norm.test.js │ │ ├── nthRoot.test.js │ │ ├── nthRoots.test.js │ │ ├── pow.test.js │ │ ├── round.test.js │ │ ├── sign.test.js │ │ ├── sqrt.test.js │ │ ├── square.test.js │ │ ├── subtract.test.js │ │ ├── subtractScalar.test.js │ │ ├── unaryMinus.test.js │ │ ├── unaryPlus.test.js │ │ └── xgcd.test.js │ ├── bitwise │ │ ├── bitAnd.test.js │ │ ├── bitNot.test.js │ │ ├── bitOr.test.js │ │ ├── bitXor.test.js │ │ ├── leftShift.test.js │ │ ├── rightArithShift.test.js │ │ └── rightLogShift.test.js │ ├── combinatorics │ │ ├── bellNumbers.test.js │ │ ├── catalan.test.js │ │ ├── composition.test.js │ │ └── stirlingS2.test.js │ ├── complex │ │ ├── arg.test.js │ │ ├── conj.test.js │ │ ├── im.test.js │ │ └── re.test.js │ ├── geometry │ │ ├── distance.test.js │ │ └── intersect.test.js │ ├── logical │ │ ├── and.test.js │ │ ├── not.test.js │ │ ├── or.test.js │ │ └── xor.test.js │ ├── matrix │ │ ├── column.test.js │ │ ├── concat.test.js │ │ ├── count.test.js │ │ ├── cross.test.js │ │ ├── ctranspose.test.js │ │ ├── det.test.js │ │ ├── diag.test.js │ │ ├── diff.test.js │ │ ├── dot.test.js │ │ ├── eigs.test.js │ │ ├── expm.test.js │ │ ├── fft.test.js │ │ ├── filter.test.js │ │ ├── flatten.test.js │ │ ├── forEach.test.js │ │ ├── identity.test.js │ │ ├── ifft.test.js │ │ ├── inv.test.js │ │ ├── kron.test.js │ │ ├── map.test.js │ │ ├── mapSlices.test.js │ │ ├── matrixFrom.test.js │ │ ├── ones.test.js │ │ ├── partitionSelect.test.js │ │ ├── pinv.test.js │ │ ├── range.test.js │ │ ├── reshape.test.js │ │ ├── resize.test.js │ │ ├── rotate.test.js │ │ ├── rotationMatrix.test.js │ │ ├── row.test.js │ │ ├── size.test.js │ │ ├── sort.test.js │ │ ├── sqrtm.test.js │ │ ├── squeeze.test.js │ │ ├── subset.test.js │ │ ├── trace.test.js │ │ ├── transpose.test.js │ │ └── zeros.test.js │ ├── numeric │ │ └── solveODE.test.js │ ├── probability │ │ ├── combinations.test.js │ │ ├── combinationsWithRep.test.js │ │ ├── factorial.test.js │ │ ├── gamma.test.js │ │ ├── kldivergence.test.js │ │ ├── lgamma.test.js │ │ ├── multinomial.test.js │ │ ├── permutations.test.js │ │ ├── pickRandom.test.js │ │ ├── random.test.js │ │ ├── randomInt.test.js │ │ └── seededrandom.test.js │ ├── relational │ │ ├── compare.test.js │ │ ├── compareNatural.test.js │ │ ├── compareText.test.js │ │ ├── deepEqual.test.js │ │ ├── equal.test.js │ │ ├── equalText.test.js │ │ ├── larger.test.js │ │ ├── largerEq.test.js │ │ ├── smaller.test.js │ │ ├── smallerEq.test.js │ │ └── unequal.test.js │ ├── set │ │ ├── setCartesian.test.js │ │ ├── setDifference.test.js │ │ ├── setDistinct.test.js │ │ ├── setIntersect.test.js │ │ ├── setIsSubset.test.js │ │ ├── setMultiplicity.test.js │ │ ├── setPowerset.test.js │ │ ├── setSize.test.js │ │ ├── setSymDifference.test.js │ │ └── setUnion.test.js │ ├── signal │ │ ├── freqz.test.js │ │ └── zpk2tf.test.js │ ├── special │ │ ├── erf.test.js │ │ └── zeta.test.js │ ├── statistics │ │ ├── corr.test.js │ │ ├── cumsum.test.js │ │ ├── mad.test.js │ │ ├── max.test.js │ │ ├── mean.test.js │ │ ├── median.test.js │ │ ├── min.test.js │ │ ├── mode.test.js │ │ ├── prod.test.js │ │ ├── quantileSeq.test.js │ │ ├── std.test.js │ │ ├── sum.test.js │ │ └── variance.test.js │ ├── string │ │ ├── format.test.js │ │ └── print.test.js │ ├── trigonometry │ │ ├── acos.test.js │ │ ├── acosh.test.js │ │ ├── acot.test.js │ │ ├── acoth.test.js │ │ ├── acsc.test.js │ │ ├── acsch.test.js │ │ ├── asec.test.js │ │ ├── asech.test.js │ │ ├── asin.test.js │ │ ├── asinh.test.js │ │ ├── atan.test.js │ │ ├── atan2.test.js │ │ ├── atanh.test.js │ │ ├── cos.test.js │ │ ├── cosh.test.js │ │ ├── cot.test.js │ │ ├── coth.test.js │ │ ├── csc.test.js │ │ ├── csch.test.js │ │ ├── sec.test.js │ │ ├── sech.test.js │ │ ├── sin.test.js │ │ ├── sinh.test.js │ │ ├── tan.test.js │ │ └── tanh.test.js │ ├── unit │ │ └── to.test.js │ └── utils │ │ ├── clone.test.js │ │ ├── hasNumericValue.test.js │ │ ├── isInteger.test.js │ │ ├── isNaN.test.js │ │ ├── isNegative.test.js │ │ ├── isNumeric.test.js │ │ ├── isPositive.test.js │ │ ├── isPrime.test.js │ │ ├── isZero.test.js │ │ └── typeof.test.js │ ├── json │ ├── replacer.test.js │ └── reviver.test.js │ ├── plain │ └── number │ │ └── arithmetic.test.js │ ├── test.html │ ├── type │ ├── bigint.test.js │ ├── bignumber │ │ ├── BigNumber.test.js │ │ └── function │ │ │ └── bignumber.test.js │ ├── boolean.test.js │ ├── chain │ │ ├── Chain.test.js │ │ └── function │ │ │ └── chain.test.js │ ├── complex │ │ ├── Complex.test.js │ │ └── function │ │ │ └── complex.test.js │ ├── fraction │ │ ├── Fraction.test.js │ │ └── function │ │ │ └── fraction.test.js │ ├── matrix │ │ ├── DenseMatrix.test.js │ │ ├── FibonacciHeap.test.js │ │ ├── ImmutableDenseMatrix.test.js │ │ ├── Index.test.js │ │ ├── Matrix.test.js │ │ ├── Range.test.js │ │ ├── Spa.test.js │ │ ├── SparseMatrix.test.js │ │ ├── collection.test.js │ │ ├── function │ │ │ ├── index.test.js │ │ │ ├── matrix.test.js │ │ │ └── sparse.test.js │ │ └── utils │ │ │ ├── broadcast.test.js │ │ │ ├── deepForEach.test.js │ │ │ ├── deepMap.test.js │ │ │ ├── getMatrixDataType.test.js │ │ │ ├── isCollection.test.js │ │ │ └── reduce.test.js │ ├── number.test.js │ ├── numeric.test.js │ ├── resultset │ │ └── ResultSet.test.js │ ├── string.test.js │ └── unit │ │ ├── Unit.test.js │ │ ├── function │ │ ├── createUnit.test.js │ │ ├── splitUnit.test.js │ │ └── unit.test.js │ │ └── physicalConstants.test.js │ └── utils │ ├── array.test.js │ ├── bignumber │ ├── constants.test.js │ ├── formatter.test.js │ └── nearlyEqual.test.js │ ├── customs.test.js │ ├── factory.test.js │ ├── function.test.js │ ├── is.test.js │ ├── latex.test.js │ ├── map.test.js │ ├── number.test.js │ ├── object.test.js │ └── string.test.js ├── tools ├── approx.js ├── docgenerator.js ├── entryGenerator.js ├── matrices │ ├── arc130.mtx │ ├── bcsstk01.mtx │ ├── bfwb62.mtx │ ├── can_24.mtx │ ├── fpga_dcop_01.mtx │ └── fpga_dcop_01_b.mtx ├── matrixmarket.js ├── update-authors.js ├── utils.js ├── validateAsciiChars.js └── whitelistgenerator.js ├── tsconfig.json └── types ├── EXPLANATION.md ├── index.d.ts └── tslint.json /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["@babel/preset-env"] 4 | ], 5 | "plugins": [ 6 | "@babel/plugin-transform-object-assign", 7 | "@babel/plugin-transform-optional-catch-binding", 8 | "@babel/plugin-transform-runtime" 9 | ], 10 | "ignore": [ 11 | "lib/**/*.js" 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /.browserslistrc: -------------------------------------------------------------------------------- 1 | # Test out at: https://browsersl.ist/ 2 | 3 | fully supports es6 and fully supports bigint 4 | not dead 5 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: josdejong 2 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/new_issue.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: New issue 3 | about: Create an issue to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | The issues section is used only for bug reports. Please use the [Discussions](https://github.com/josdejong/mathjs/discussions) section to ask questions and share ideas and suggestions. 11 | 12 | **Describe the bug** 13 | A clear and concise description of what the bug is. 14 | 15 | **To Reproduce** 16 | Steps to reproduce the behavior. 17 | -------------------------------------------------------------------------------- /.github/workflows/lambdatest.yaml: -------------------------------------------------------------------------------- 1 | name: Browser testing on Lambdatest 2 | 3 | on: 4 | push: 5 | branches: 6 | - '*' 7 | 8 | jobs: 9 | test-tunnel: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: Start Tunnel 13 | uses: LambdaTest/LambdaTest-tunnel-action@v2 14 | id: tunnel 15 | with: 16 | user: ${{ secrets.LT_USERNAME }} 17 | accessKey: ${{ secrets.LT_ACCESS_KEY }} 18 | - uses: actions/checkout@v4 19 | - uses: actions/setup-node@v4 20 | with: 21 | node-version: 22.x 22 | - run: npm ci 23 | - run: npm run test:lambdatest 24 | env: 25 | LT_USERNAME: ${{ secrets.LT_USERNAME }} 26 | LT_ACCESS_KEY: ${{ secrets.LT_ACCESS_KEY }} 27 | -------------------------------------------------------------------------------- /.github/workflows/local-browser.yaml: -------------------------------------------------------------------------------- 1 | name: Browser testing locally 2 | 3 | on: pull_request 4 | 5 | jobs: 6 | browser-tests: 7 | 8 | runs-on: ubuntu-latest 9 | 10 | steps: 11 | - uses: actions/checkout@v4 12 | - uses: actions/setup-node@v4 13 | with: 14 | node-version: 20.x 15 | - run: npm ci 16 | - run: npm run test:browser 17 | env: 18 | CI: true 19 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | .vscode 3 | .c9 4 | _site 5 | *swp 6 | *.log 7 | *.bak 8 | 9 | node_modules 10 | .nyc_output 11 | /coverage 12 | .eslintcache 13 | 14 | lib 15 | test-results 16 | *.generated.js 17 | -------------------------------------------------------------------------------- /.mocharc.json: -------------------------------------------------------------------------------- 1 | { 2 | "reporter": "dot", 3 | "timeout": 60000, 4 | "forbid-only": true, 5 | "recursive": true 6 | } 7 | -------------------------------------------------------------------------------- /.prettierrc.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | semi: false, 3 | singleQuote: true, 4 | trailingComma: 'none' 5 | } 6 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | math.js 2 | https://github.com/josdejong/mathjs 3 | 4 | Copyright (C) 2013-2025 Jos de Jong 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | https://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Usage risks 4 | 5 | The mathjs library comes with some risks, since it contains an expression parser which allows arbitrary user input, which may result in CPU or memory heavy operations. Read more in the docs: https://mathjs.org/docs/expressions/security.html 6 | 7 | 8 | ## Reporting a Vulnerability 9 | 10 | Please report (suspected) security vulnerabilities privately to one of the maintainers of the library, for example to Jos de Jong: https://github.com/josdejong. 11 | -------------------------------------------------------------------------------- /bin/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "commonjs" 3 | } 4 | -------------------------------------------------------------------------------- /bin/repl.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /* 4 | * This simply preloads mathjs and drops you into a REPL to 5 | * help interactive debugging. 6 | **/ 7 | global.math = require('../lib/browser/math.js') 8 | const repl = require('repl') 9 | 10 | repl.start({ useGlobal: true }) 11 | -------------------------------------------------------------------------------- /docs/core/index.md: -------------------------------------------------------------------------------- 1 | # Core 2 | 3 | ## Usage 4 | 5 | The core of math.js is the `math` namespace containing all functions and constants. There are three ways to do calculations in math.js: 6 | 7 | - Doing regular function calls like `math.add(math.sqrt(4), 2)`. 8 | - Evaluating expressions like `math.evaluate('sqrt(4) + 2')` 9 | - Chaining operations like `math.chain(4).sqrt().add(2)`. 10 | 11 | ## Configuration 12 | 13 | math.js can be configured using the `math.config()`, see page [Configuration](configuration.md). 14 | 15 | ## Extension 16 | 17 | math.js can be extended with new functions and constants using the function `math.import()`, see page [Extension](extension.md). 18 | 19 | ## Serialization 20 | 21 | To persist or exchange data structures like matrices and units, the data types of math.js can be stringified as JSON. This is explained on the page [Serialization](serialization.md). 22 | -------------------------------------------------------------------------------- /docs/reference/.gitignore: -------------------------------------------------------------------------------- 1 | functions.md 2 | -------------------------------------------------------------------------------- /docs/reference/.npmignore: -------------------------------------------------------------------------------- 1 | # empty .npmignore to prevent ignoring generated docs in npm -------------------------------------------------------------------------------- /docs/reference/functions/.gitignore: -------------------------------------------------------------------------------- 1 | *.md 2 | -------------------------------------------------------------------------------- /docs/reference/functions/.npmignore: -------------------------------------------------------------------------------- 1 | # empty .npmignore to prevent ignoring generated docs in npm -------------------------------------------------------------------------------- /docs/reference/index.md: -------------------------------------------------------------------------------- 1 | # Reference 2 | 3 | - [Classes](classes.md) 4 | - [Constants](constants.md) 5 | - [Functions](functions.md) 6 | -------------------------------------------------------------------------------- /examples/advanced/custom_evaluate_using_import.js: -------------------------------------------------------------------------------- 1 | // we use the number only implementation in order to not pull in 2 | // the `Unit` class for example. when using as library, 3 | // use require('mathjs/number') 4 | import { create, evaluateDependencies } from '../../lib/esm/number.js' 5 | 6 | // custom implementations of all functions you want to support 7 | const add = (a, b) => a + b 8 | const subtract = (a, b) => a - b 9 | const multiply = (a, b) => a * b 10 | const divide = (a, b) => a / b 11 | 12 | // create a mathjs instance with hardly any functions 13 | // there are some functions created which are used internally by evaluate though, 14 | // for example by the Unit class which has dependencies on addScalar, subtractScalar, 15 | // multiplyScalar, etc. 16 | const math = create(evaluateDependencies) 17 | 18 | // import your own functions 19 | math.import({ add, subtract, multiply, divide }, { override: true }) 20 | 21 | console.log(math.evaluate('2 + 3 * 4')) // 14 22 | -------------------------------------------------------------------------------- /examples/advanced/web_server/math_worker.js: -------------------------------------------------------------------------------- 1 | const { create, all } = require('../../..') 2 | const workerpool = require('workerpool') 3 | const math = create(all) 4 | 5 | // disable the import function so the math.js instance cannot be changed 6 | function noImport () { 7 | throw new Error('function import is disabled.') 8 | } 9 | math.import({ import: noImport }, { override: true }) 10 | 11 | /** 12 | * Evaluate an expression 13 | * @param {string} expr 14 | * @return {string} result 15 | */ 16 | function evaluate (expr) { 17 | const ans = math.evaluate(expr) 18 | return math.format(ans) 19 | } 20 | 21 | // create a worker and register public functions 22 | workerpool.worker({ 23 | evaluate: evaluate 24 | }) 25 | -------------------------------------------------------------------------------- /examples/browser/requirejs_loading.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | math.js | require.js loading 6 | 7 | 8 | 9 | 10 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /examples/browser/webworkers/worker.js: -------------------------------------------------------------------------------- 1 | importScripts('../../../lib/browser/math.js') 2 | 3 | // create a parser 4 | const parser = self.math.parser() 5 | 6 | self.addEventListener('message', function (event) { 7 | const request = JSON.parse(event.data) 8 | let result = null 9 | let err = null 10 | 11 | try { 12 | // evaluate the expression 13 | result = parser.evaluate(request.expr) 14 | } catch (e) { 15 | // return the error 16 | err = e 17 | } 18 | 19 | // build a response 20 | const response = { 21 | id: request.id, 22 | result: self.math.format(result), 23 | err: err 24 | } 25 | 26 | // send the response back 27 | self.postMessage(JSON.stringify(response)) 28 | }, false) 29 | -------------------------------------------------------------------------------- /examples/code editor/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | pnpm-debug.log* 8 | lerna-debug.log* 9 | 10 | node_modules 11 | dist 12 | dist-ssr 13 | *.local 14 | 15 | # Editor directories and files 16 | .vscode/* 17 | !.vscode/extensions.json 18 | .idea 19 | .DS_Store 20 | *.suo 21 | *.ntvs* 22 | *.njsproj 23 | *.sln 24 | *.sw? 25 | -------------------------------------------------------------------------------- /examples/code editor/README.md: -------------------------------------------------------------------------------- 1 | # Code Editor Example 2 | 3 | This is an example for using [mathjs](https://mathjs.org) with a code editor. 4 | 5 | To run your own you need to install the dependancies with. 6 | ``` 7 | npm install 8 | ``` 9 | 10 | You can start development mode with: 11 | ``` 12 | npm run dev 13 | ``` 14 | 15 | Or build the project with: 16 | ``` 17 | npm run build 18 | ``` -------------------------------------------------------------------------------- /examples/code editor/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | math.js | code editor 8 | 9 | 10 | 11 |
12 |
13 |
14 |
15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /examples/code editor/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "code-editor", 3 | "private": true, 4 | "version": "1.0.0", 5 | "type": "module", 6 | "scripts": { 7 | "dev": "vite", 8 | "build": "vite build", 9 | "preview": "vite preview" 10 | }, 11 | "devDependencies": { 12 | "vite": "5.3.3" 13 | }, 14 | "dependencies": { 15 | "@codemirror/language": "6.10.2", 16 | "@codemirror/state": "6.4.1", 17 | "codemirror": "6.0.1", 18 | "github-markdown-css": "5.6.1", 19 | "katex": "0.16.11", 20 | "mathjs": "13.0.2" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/serialization.js: -------------------------------------------------------------------------------- 1 | // serialization 2 | import { complex, replacer, reviver, typeOf } from '../lib/esm/index.js' 3 | 4 | // serialize a math.js data type into a JSON string 5 | // the replacer function is needed to correctly stringify a value like Infinity 6 | const x = complex('2+3i') 7 | const str1 = JSON.stringify(x, replacer) 8 | console.log(str1) 9 | // outputs {"mathjs":"Complex","re":2,"im":3} 10 | 11 | // deserialize a JSON string into a math.js data type 12 | // note that the reviver of math.js is needed for this: 13 | const str2 = '{"mathjs":"Unit","value":5,"unit":"cm"}' 14 | const y = JSON.parse(str2, reviver) 15 | console.log(typeOf(y)) // 'Unit' 16 | console.log(y.toString()) // 5 cm 17 | -------------------------------------------------------------------------------- /examples/sparse_matrices.js: -------------------------------------------------------------------------------- 1 | // Sparse matrices 2 | import { identity, multiply, transpose, complex } from '../lib/esm/index.js' 3 | 4 | // create a sparse matrix 5 | console.log('creating a 1000x1000 sparse matrix...') 6 | const a = identity(1000, 1000, 'sparse') 7 | 8 | // do operations with a sparse matrix 9 | console.log('doing some operations on the sparse matrix...') 10 | const b = multiply(a, a) 11 | const c = multiply(b, complex(2, 2)) 12 | const d = transpose(c) 13 | const e = multiply(d, a) 14 | console.log('size(e)=', e.size()) 15 | 16 | // we will not print the output, but doing the same operations 17 | // with a dense matrix are very slow, try it for yourself. 18 | console.log('already done') 19 | console.log('now try this with a dense matrix :)') 20 | -------------------------------------------------------------------------------- /misc/img/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josdejong/mathjs/7933089bd49df092cc5016c46554c4f32fab6bc2/misc/img/favicon.ico -------------------------------------------------------------------------------- /misc/img/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josdejong/mathjs/7933089bd49df092cc5016c46554c4f32fab6bc2/misc/img/favicon.png -------------------------------------------------------------------------------- /misc/img/favicon_16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josdejong/mathjs/7933089bd49df092cc5016c46554c4f32fab6bc2/misc/img/favicon_16x16.png -------------------------------------------------------------------------------- /misc/img/favicon_256x256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josdejong/mathjs/7933089bd49df092cc5016c46554c4f32fab6bc2/misc/img/favicon_256x256.png -------------------------------------------------------------------------------- /misc/img/favicon_75x75.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josdejong/mathjs/7933089bd49df092cc5016c46554c4f32fab6bc2/misc/img/favicon_75x75.png -------------------------------------------------------------------------------- /misc/img/mathjs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josdejong/mathjs/7933089bd49df092cc5016c46554c4f32fab6bc2/misc/img/mathjs.png -------------------------------------------------------------------------------- /misc/img/mathjs.txt: -------------------------------------------------------------------------------- 1 | Description of the logo: 2 | 3 | size: 330x100px 4 | font: Source Sans 3, 96px 5 | 6 | math: 7 | size: 243x100px 8 | color: ffffffff 9 | bgcolor: dc3912ff 10 | 11 | js: 12 | size: 87x100px 13 | color: 202020ff 14 | bgcolor: ffffffff 15 | 16 | To update the logo: 17 | - install Source Sans 3 18 | - open mathjs_source.svg in inkscape 19 | - use use Path menu > Object to Path on the text and export to mathjs.svg -------------------------------------------------------------------------------- /misc/img/mathjs_100x30.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josdejong/mathjs/7933089bd49df092cc5016c46554c4f32fab6bc2/misc/img/mathjs_100x30.png -------------------------------------------------------------------------------- /misc/img/mathjs_165x50.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josdejong/mathjs/7933089bd49df092cc5016c46554c4f32fab6bc2/misc/img/mathjs_165x50.png -------------------------------------------------------------------------------- /misc/img/mathjs_330x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josdejong/mathjs/7933089bd49df092cc5016c46554c4f32fab6bc2/misc/img/mathjs_330x100.png -------------------------------------------------------------------------------- /src/defaultInstance.js: -------------------------------------------------------------------------------- 1 | import * as all from './factoriesAny.js' 2 | import { create } from './core/create.js' 3 | 4 | export default create(all) 5 | -------------------------------------------------------------------------------- /src/entry/allFactoriesAny.js: -------------------------------------------------------------------------------- 1 | // creating all factories here in a separate file is needed to get tree-shaking working 2 | import * as allFactories from '../factoriesAny.js' 3 | 4 | export const all = allFactories 5 | -------------------------------------------------------------------------------- /src/entry/allFactoriesNumber.js: -------------------------------------------------------------------------------- 1 | // creating all factories here in a separate file is needed to get tree-shaking working 2 | import * as allFactories from '../factoriesNumber.js' 3 | 4 | export const all = allFactories 5 | -------------------------------------------------------------------------------- /src/entry/configReadonly.js: -------------------------------------------------------------------------------- 1 | import { DEFAULT_CONFIG } from '../core/config.js' 2 | import { MATRIX_OPTIONS, NUMBER_OPTIONS } from '../core/function/config.js' 3 | 4 | // create a read-only version of config 5 | export const config = function (options) { 6 | if (options) { 7 | throw new Error('The global config is readonly. \n' + 8 | 'Please create a mathjs instance if you want to change the default configuration. \n' + 9 | 'Example:\n' + 10 | '\n' + 11 | ' import { create, all } from \'mathjs\';\n' + 12 | ' const mathjs = create(all);\n' + 13 | ' mathjs.config({ number: \'BigNumber\' });\n') 14 | } 15 | 16 | return Object.freeze(DEFAULT_CONFIG) 17 | } 18 | Object.assign(config, DEFAULT_CONFIG, { MATRIX_OPTIONS, NUMBER_OPTIONS }) 19 | -------------------------------------------------------------------------------- /src/entry/mainAny.js: -------------------------------------------------------------------------------- 1 | // configuration 2 | export { config } from './configReadonly.js' 3 | 4 | // functions and constants 5 | export * from './pureFunctionsAny.generated.js' 6 | export * from './impureFunctionsAny.generated.js' 7 | export * from './typeChecks.js' 8 | 9 | // error classes 10 | export { IndexError } from '../error/IndexError.js' 11 | export { DimensionError } from '../error/DimensionError.js' 12 | export { ArgumentsError } from '../error/ArgumentsError.js' 13 | 14 | // dependency groups 15 | export * from './dependenciesAny.generated.js' 16 | 17 | // factory functions 18 | export * from '../factoriesAny.js' 19 | 20 | // core 21 | export { create } from '../core/create.js' 22 | export { factory } from '../utils/factory.js' 23 | -------------------------------------------------------------------------------- /src/entry/mainNumber.js: -------------------------------------------------------------------------------- 1 | // configuration 2 | export { config } from './configReadonly.js' 3 | 4 | // functions and constants 5 | export * from './pureFunctionsNumber.generated.js' 6 | export * from './impureFunctionsNumber.generated.js' 7 | export * from './typeChecks.js' 8 | 9 | // error classes 10 | export { IndexError } from '../error/IndexError.js' 11 | export { DimensionError } from '../error/DimensionError.js' 12 | export { ArgumentsError } from '../error/ArgumentsError.js' 13 | 14 | // dependency groups 15 | export * from './dependenciesNumber.generated.js' 16 | 17 | // factory functions 18 | export * from '../factoriesNumber.js' 19 | 20 | // core 21 | export { create } from '../core/create.js' 22 | export { factory } from '../utils/factory.js' 23 | -------------------------------------------------------------------------------- /src/entry/typeChecks.js: -------------------------------------------------------------------------------- 1 | // util functions 2 | export { 3 | isAccessorNode, 4 | isArray, 5 | isArrayNode, 6 | isAssignmentNode, 7 | isBigNumber, 8 | isBigInt, 9 | isBlockNode, 10 | isBoolean, 11 | isChain, 12 | isCollection, 13 | isComplex, 14 | isConditionalNode, 15 | isConstantNode, 16 | isDate, 17 | isDenseMatrix, 18 | isFraction, 19 | isFunction, 20 | isFunctionAssignmentNode, 21 | isFunctionNode, 22 | isHelp, 23 | isIndex, 24 | isIndexNode, 25 | isMatrix, 26 | isNode, 27 | isNull, 28 | isNumber, 29 | isString, 30 | isUndefined, 31 | isObject, 32 | isMap, 33 | isPartitionedMap, 34 | isObjectWrappingMap, 35 | isObjectNode, 36 | isOperatorNode, 37 | isParenthesisNode, 38 | isRange, 39 | isRangeNode, 40 | isRelationalNode, 41 | isRegExp, 42 | isResultSet, 43 | isSparseMatrix, 44 | isSymbolNode, 45 | isUnit 46 | } from '../utils/is.js' 47 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/constants/Infinity.js: -------------------------------------------------------------------------------- 1 | export const InfinityDocs = { 2 | name: 'Infinity', 3 | category: 'Constants', 4 | syntax: [ 5 | 'Infinity' 6 | ], 7 | description: 'Infinity, a number which is larger than the maximum number that can be handled by a floating point number.', 8 | examples: [ 9 | 'Infinity', 10 | '1 / 0' 11 | ], 12 | seealso: [] 13 | } 14 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/constants/LN10.js: -------------------------------------------------------------------------------- 1 | export const LN10Docs = { 2 | name: 'LN10', 3 | category: 'Constants', 4 | syntax: [ 5 | 'LN10' 6 | ], 7 | description: 'Returns the natural logarithm of 10, approximately equal to 2.302', 8 | examples: [ 9 | 'LN10', 10 | 'log(10)' 11 | ], 12 | seealso: [] 13 | } 14 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/constants/LN2.js: -------------------------------------------------------------------------------- 1 | export const LN2Docs = { 2 | name: 'LN2', 3 | category: 'Constants', 4 | syntax: [ 5 | 'LN2' 6 | ], 7 | description: 'Returns the natural logarithm of 2, approximately equal to 0.693', 8 | examples: [ 9 | 'LN2', 10 | 'log(2)' 11 | ], 12 | seealso: [] 13 | } 14 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/constants/LOG10E.js: -------------------------------------------------------------------------------- 1 | export const LOG10EDocs = { 2 | name: 'LOG10E', 3 | category: 'Constants', 4 | syntax: [ 5 | 'LOG10E' 6 | ], 7 | description: 'Returns the base-10 logarithm of E, approximately equal to 0.434', 8 | examples: [ 9 | 'LOG10E', 10 | 'log(e, 10)' 11 | ], 12 | seealso: [] 13 | } 14 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/constants/LOG2E.js: -------------------------------------------------------------------------------- 1 | export const LOG2EDocs = { 2 | name: 'LOG2E', 3 | category: 'Constants', 4 | syntax: [ 5 | 'LOG2E' 6 | ], 7 | description: 'Returns the base-2 logarithm of E, approximately equal to 1.442', 8 | examples: [ 9 | 'LOG2E', 10 | 'log(e, 2)' 11 | ], 12 | seealso: [] 13 | } 14 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/constants/NaN.js: -------------------------------------------------------------------------------- 1 | export const NaNDocs = { 2 | name: 'NaN', 3 | category: 'Constants', 4 | syntax: [ 5 | 'NaN' 6 | ], 7 | description: 'Not a number', 8 | examples: [ 9 | 'NaN', 10 | '0 / 0' 11 | ], 12 | seealso: [] 13 | } 14 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/constants/SQRT1_2.js: -------------------------------------------------------------------------------- 1 | export const SQRT12Docs = { 2 | name: 'SQRT1_2', 3 | category: 'Constants', 4 | syntax: [ 5 | 'SQRT1_2' 6 | ], 7 | description: 'Returns the square root of 1/2, approximately equal to 0.707', 8 | examples: [ 9 | 'SQRT1_2', 10 | 'sqrt(1/2)' 11 | ], 12 | seealso: [] 13 | } 14 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/constants/SQRT2.js: -------------------------------------------------------------------------------- 1 | export const SQRT2Docs = { 2 | name: 'SQRT2', 3 | category: 'Constants', 4 | syntax: [ 5 | 'SQRT2' 6 | ], 7 | description: 'Returns the square root of 2, approximately equal to 1.414', 8 | examples: [ 9 | 'SQRT2', 10 | 'sqrt(2)' 11 | ], 12 | seealso: [] 13 | } 14 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/constants/e.js: -------------------------------------------------------------------------------- 1 | export const eDocs = { 2 | name: 'e', 3 | category: 'Constants', 4 | syntax: [ 5 | 'e' 6 | ], 7 | description: 'Euler\'s number, the base of the natural logarithm. Approximately equal to 2.71828', 8 | examples: [ 9 | 'e', 10 | 'e ^ 2', 11 | 'exp(2)', 12 | 'log(e)' 13 | ], 14 | seealso: ['exp'] 15 | } 16 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/constants/false.js: -------------------------------------------------------------------------------- 1 | export const falseDocs = { 2 | name: 'false', 3 | category: 'Constants', 4 | syntax: [ 5 | 'false' 6 | ], 7 | description: 'Boolean value false', 8 | examples: [ 9 | 'false' 10 | ], 11 | seealso: ['true'] 12 | } 13 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/constants/i.js: -------------------------------------------------------------------------------- 1 | export const iDocs = { 2 | name: 'i', 3 | category: 'Constants', 4 | syntax: [ 5 | 'i' 6 | ], 7 | description: 'Imaginary unit, defined as i*i=-1. A complex number is described as a + b*i, where a is the real part, and b is the imaginary part.', 8 | examples: [ 9 | 'i', 10 | 'i * i', 11 | 'sqrt(-1)' 12 | ], 13 | seealso: [] 14 | } 15 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/constants/null.js: -------------------------------------------------------------------------------- 1 | export const nullDocs = { 2 | name: 'null', 3 | category: 'Constants', 4 | syntax: [ 5 | 'null' 6 | ], 7 | description: 'Value null', 8 | examples: [ 9 | 'null' 10 | ], 11 | seealso: ['true', 'false'] 12 | } 13 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/constants/phi.js: -------------------------------------------------------------------------------- 1 | export const phiDocs = { 2 | name: 'phi', 3 | category: 'Constants', 4 | syntax: [ 5 | 'phi' 6 | ], 7 | description: 'Phi is the golden ratio. Two quantities are in the golden ratio if their ratio is the same as the ratio of their sum to the larger of the two quantities. Phi is defined as `(1 + sqrt(5)) / 2` and is approximately 1.618034...', 8 | examples: [ 9 | 'phi' 10 | ], 11 | seealso: [] 12 | } 13 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/constants/pi.js: -------------------------------------------------------------------------------- 1 | export const piDocs = { 2 | name: 'pi', 3 | category: 'Constants', 4 | syntax: [ 5 | 'pi' 6 | ], 7 | description: 'The number pi is a mathematical constant that is the ratio of a circle\'s circumference to its diameter, and is approximately equal to 3.14159', 8 | examples: [ 9 | 'pi', 10 | 'sin(pi/2)' 11 | ], 12 | seealso: ['tau'] 13 | } 14 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/constants/tau.js: -------------------------------------------------------------------------------- 1 | export const tauDocs = { 2 | name: 'tau', 3 | category: 'Constants', 4 | syntax: [ 5 | 'tau' 6 | ], 7 | description: 'Tau is the ratio constant of a circle\'s circumference to radius, equal to 2 * pi, approximately 6.2832.', 8 | examples: [ 9 | 'tau', 10 | '2 * pi' 11 | ], 12 | seealso: ['pi'] 13 | } 14 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/constants/true.js: -------------------------------------------------------------------------------- 1 | export const trueDocs = { 2 | name: 'true', 3 | category: 'Constants', 4 | syntax: [ 5 | 'true' 6 | ], 7 | description: 'Boolean value true', 8 | examples: [ 9 | 'true' 10 | ], 11 | seealso: ['false'] 12 | } 13 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/constants/version.js: -------------------------------------------------------------------------------- 1 | export const versionDocs = { 2 | name: 'version', 3 | category: 'Constants', 4 | syntax: [ 5 | 'version' 6 | ], 7 | description: 'A string with the version number of math.js', 8 | examples: [ 9 | 'version' 10 | ], 11 | seealso: [] 12 | } 13 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/construction/bigint.js: -------------------------------------------------------------------------------- 1 | export const bigintDocs = { 2 | name: 'bigint', 3 | category: 'Construction', 4 | syntax: [ 5 | 'bigint(x)' 6 | ], 7 | description: 8 | 'Create a bigint, an integer with an arbitrary number of digits, from a number or string.', 9 | examples: [ 10 | '123123123123123123 # a large number will lose digits', 11 | 'bigint("123123123123123123")', 12 | 'bignumber(["1", "3", "5"])' 13 | ], 14 | seealso: [ 15 | 'boolean', 'bignumber', 'number', 'complex', 'fraction', 'index', 'matrix', 'string', 'unit' 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/construction/bignumber.js: -------------------------------------------------------------------------------- 1 | export const bignumberDocs = { 2 | name: 'bignumber', 3 | category: 'Construction', 4 | syntax: [ 5 | 'bignumber(x)' 6 | ], 7 | description: 8 | 'Create a big number from a number or string.', 9 | examples: [ 10 | '0.1 + 0.2', 11 | 'bignumber(0.1) + bignumber(0.2)', 12 | 'bignumber("7.2")', 13 | 'bignumber("7.2e500")', 14 | 'bignumber([0.1, 0.2, 0.3])' 15 | ], 16 | seealso: [ 17 | 'boolean', 'bigint', 'complex', 'fraction', 'index', 'matrix', 'string', 'unit' 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/construction/boolean.js: -------------------------------------------------------------------------------- 1 | export const booleanDocs = { 2 | name: 'boolean', 3 | category: 'Construction', 4 | syntax: [ 5 | 'x', 6 | 'boolean(x)' 7 | ], 8 | description: 9 | 'Convert a string or number into a boolean.', 10 | examples: [ 11 | 'boolean(0)', 12 | 'boolean(1)', 13 | 'boolean(3)', 14 | 'boolean("true")', 15 | 'boolean("false")', 16 | 'boolean([1, 0, 1, 1])' 17 | ], 18 | seealso: [ 19 | 'bignumber', 'complex', 'index', 'matrix', 'number', 'string', 'unit' 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/construction/complex.js: -------------------------------------------------------------------------------- 1 | export const complexDocs = { 2 | name: 'complex', 3 | category: 'Construction', 4 | syntax: [ 5 | 'complex()', 6 | 'complex(re, im)', 7 | 'complex(string)' 8 | ], 9 | description: 10 | 'Create a complex number.', 11 | examples: [ 12 | 'complex()', 13 | 'complex(2, 3)', 14 | 'complex("7 - 2i")' 15 | ], 16 | seealso: [ 17 | 'bignumber', 'boolean', 'index', 'matrix', 'number', 'string', 'unit' 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/construction/createUnit.js: -------------------------------------------------------------------------------- 1 | export const createUnitDocs = { 2 | name: 'createUnit', 3 | category: 'Construction', 4 | syntax: [ 5 | 'createUnit(definitions)', 6 | 'createUnit(name, definition)' 7 | ], 8 | description: 9 | 'Create a user-defined unit and register it with the Unit type.', 10 | examples: [ 11 | 'createUnit("foo")', 12 | 'createUnit("knot", {definition: "0.514444444 m/s", aliases: ["knots", "kt", "kts"]})', 13 | 'createUnit("mph", "1 mile/hour")' 14 | ], 15 | seealso: [ 16 | 'unit', 'splitUnit' 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/construction/fraction.js: -------------------------------------------------------------------------------- 1 | export const fractionDocs = { 2 | name: 'fraction', 3 | category: 'Construction', 4 | syntax: [ 5 | 'fraction(num)', 6 | 'fraction(matrix)', 7 | 'fraction(num,den)', 8 | 'fraction({n: num, d: den})' 9 | ], 10 | description: 11 | 'Create a fraction from a number or from integer numerator and denominator.', 12 | examples: [ 13 | 'fraction(0.125)', 14 | 'fraction(1, 3) + fraction(2, 5)', 15 | 'fraction({n: 333, d: 53})', 16 | 'fraction([sqrt(9), sqrt(10), sqrt(11)])' 17 | ], 18 | seealso: [ 19 | 'bignumber', 'boolean', 'complex', 'index', 'matrix', 'string', 'unit' 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/construction/index.js: -------------------------------------------------------------------------------- 1 | export const indexDocs = { 2 | name: 'index', 3 | category: 'Construction', 4 | syntax: [ 5 | '[start]', 6 | '[start:end]', 7 | '[start:step:end]', 8 | '[start1, start 2, ...]', 9 | '[start1:end1, start2:end2, ...]', 10 | '[start1:step1:end1, start2:step2:end2, ...]' 11 | ], 12 | description: 13 | 'Create an index to get or replace a subset of a matrix', 14 | examples: [ 15 | 'A = [1, 2, 3; 4, 5, 6]', 16 | 'A[1, :]', 17 | 'A[1, 2] = 50', 18 | 'A[1:2, 1:2] = 1', 19 | 'B = [1, 2, 3]', 20 | 'B[B>1 and B<3]' 21 | ], 22 | seealso: [ 23 | 'bignumber', 'boolean', 'complex', 'matrix', 'number', 'range', 'string', 'unit' 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/construction/matrix.js: -------------------------------------------------------------------------------- 1 | export const matrixDocs = { 2 | name: 'matrix', 3 | category: 'Construction', 4 | syntax: [ 5 | '[]', 6 | '[a1, b1, ...; a2, b2, ...]', 7 | 'matrix()', 8 | 'matrix("dense")', 9 | 'matrix([...])' 10 | ], 11 | description: 12 | 'Create a matrix.', 13 | examples: [ 14 | '[]', 15 | '[1, 2, 3]', 16 | '[1, 2, 3; 4, 5, 6]', 17 | 'matrix()', 18 | 'matrix([3, 4])', 19 | 'matrix([3, 4; 5, 6], "sparse")', 20 | 'matrix([3, 4; 5, 6], "sparse", "number")' 21 | ], 22 | seealso: [ 23 | 'bignumber', 'boolean', 'complex', 'index', 'number', 'string', 'unit', 'sparse' 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/construction/number.js: -------------------------------------------------------------------------------- 1 | export const numberDocs = { 2 | name: 'number', 3 | category: 'Construction', 4 | syntax: [ 5 | 'x', 6 | 'number(x)', 7 | 'number(unit, valuelessUnit)' 8 | ], 9 | description: 10 | 'Create a number or convert a string or boolean into a number.', 11 | examples: [ 12 | '2', 13 | '2e3', 14 | '4.05', 15 | 'number(2)', 16 | 'number("7.2")', 17 | 'number(true)', 18 | 'number([true, false, true, true])', 19 | 'number(unit("52cm"), "m")' 20 | ], 21 | seealso: [ 22 | 'bignumber', 'bigint', 'boolean', 'complex', 'fraction', 'index', 'matrix', 'string', 'unit' 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/construction/sparse.js: -------------------------------------------------------------------------------- 1 | export const sparseDocs = { 2 | name: 'sparse', 3 | category: 'Construction', 4 | syntax: [ 5 | 'sparse()', 6 | 'sparse([a1, b1, ...; a1, b2, ...])', 7 | 'sparse([a1, b1, ...; a1, b2, ...], "number")' 8 | ], 9 | description: 10 | 'Create a sparse matrix.', 11 | examples: [ 12 | 'sparse()', 13 | 'sparse([3, 4; 5, 6])', 14 | 'sparse([3, 0; 5, 0], "number")' 15 | ], 16 | seealso: [ 17 | 'bignumber', 'boolean', 'complex', 'index', 'number', 'string', 'unit', 'matrix' 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/construction/splitUnit.js: -------------------------------------------------------------------------------- 1 | export const splitUnitDocs = { 2 | name: 'splitUnit', 3 | category: 'Construction', 4 | syntax: [ 5 | 'splitUnit(unit: Unit, parts: Unit[])' 6 | ], 7 | description: 8 | 'Split a unit in an array of units whose sum is equal to the original unit.', 9 | examples: [ 10 | 'splitUnit(1 m, ["feet", "inch"])' 11 | ], 12 | seealso: [ 13 | 'unit', 'createUnit' 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/construction/string.js: -------------------------------------------------------------------------------- 1 | export const stringDocs = { 2 | name: 'string', 3 | category: 'Construction', 4 | syntax: [ 5 | '"text"', 6 | 'string(x)' 7 | ], 8 | description: 9 | 'Create a string or convert a value to a string', 10 | examples: [ 11 | '"Hello World!"', 12 | 'string(4.2)', 13 | 'string(3 + 2i)' 14 | ], 15 | seealso: [ 16 | 'bignumber', 'boolean', 'complex', 'index', 'matrix', 'number', 'unit' 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/construction/unit.js: -------------------------------------------------------------------------------- 1 | export const unitDocs = { 2 | name: 'unit', 3 | category: 'Construction', 4 | syntax: [ 5 | 'value unit', 6 | 'unit(value, unit)', 7 | 'unit(string)' 8 | ], 9 | description: 10 | 'Create a unit.', 11 | examples: [ 12 | '5.5 mm', 13 | '3 inch', 14 | 'unit(7.1, "kilogram")', 15 | 'unit("23 deg")' 16 | ], 17 | seealso: [ 18 | 'bignumber', 'boolean', 'complex', 'index', 'matrix', 'number', 'string' 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/core/config.js: -------------------------------------------------------------------------------- 1 | export const configDocs = { 2 | name: 'config', 3 | category: 'Core', 4 | syntax: [ 5 | 'config()', 6 | 'config(options)' 7 | ], 8 | description: 'Get configuration or change configuration.', 9 | examples: [ 10 | 'config()', 11 | '1/3 + 1/4', 12 | 'config({number: "Fraction"})', 13 | '1/3 + 1/4' 14 | ], 15 | seealso: [] 16 | } 17 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/core/import.js: -------------------------------------------------------------------------------- 1 | export const importDocs = { 2 | name: 'import', 3 | category: 'Core', 4 | syntax: [ 5 | 'import(functions)', 6 | 'import(functions, options)' 7 | ], 8 | description: 'Import functions or constants from an object.', 9 | examples: [ 10 | 'import({myFn: f(x)=x^2, myConstant: 32 })', 11 | 'myFn(2)', 12 | 'myConstant' 13 | ], 14 | seealso: [] 15 | } 16 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/core/typed.js: -------------------------------------------------------------------------------- 1 | export const typedDocs = { 2 | name: 'typed', 3 | category: 'Core', 4 | syntax: [ 5 | 'typed(signatures)', 6 | 'typed(name, signatures)' 7 | ], 8 | description: 'Create a typed function.', 9 | examples: [ 10 | 'double = typed({ "number": f(x)=x+x, "string": f(x)=concat(x,x) })', 11 | 'double(2)', 12 | 'double("hello")' 13 | ], 14 | seealso: [] 15 | } 16 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/algebra/derivative.js: -------------------------------------------------------------------------------- 1 | export const derivativeDocs = { 2 | name: 'derivative', 3 | category: 'Algebra', 4 | syntax: [ 5 | 'derivative(expr, variable)', 6 | 'derivative(expr, variable, {simplify: boolean})' 7 | ], 8 | description: 'Takes the derivative of an expression expressed in parser Nodes. The derivative will be taken over the supplied variable in the second parameter. If there are multiple variables in the expression, it will return a partial derivative.', 9 | examples: [ 10 | 'derivative("2x^3", "x")', 11 | 'derivative("2x^3", "x", {simplify: false})', 12 | 'derivative("2x^2 + 3x + 4", "x")', 13 | 'derivative("sin(2x)", "x")', 14 | 'f = parse("x^2 + x")', 15 | 'x = parse("x")', 16 | 'df = derivative(f, x)', 17 | 'df.evaluate({x: 3})' 18 | ], 19 | seealso: [ 20 | 'simplify', 'parse', 'evaluate' 21 | ] 22 | } 23 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/algebra/leafCount.js: -------------------------------------------------------------------------------- 1 | export const leafCountDocs = { 2 | name: 'leafCount', 3 | category: 'Algebra', 4 | syntax: ['leafCount(expr)'], 5 | description: 'Computes the number of leaves in the parse tree of the given expression', 6 | examples: [ 7 | 'leafCount("e^(i*pi)-1")', 8 | 'leafCount(parse("{a: 22/7, b: 10^(1/2)}"))' 9 | ], 10 | seealso: ['simplify'] 11 | } 12 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/algebra/lsolve.js: -------------------------------------------------------------------------------- 1 | export const lsolveDocs = { 2 | name: 'lsolve', 3 | category: 'Algebra', 4 | syntax: [ 5 | 'x=lsolve(L, b)' 6 | ], 7 | description: 8 | 'Finds one solution of the linear system L * x = b where L is an [n x n] lower triangular matrix and b is a [n] column vector.', 9 | examples: [ 10 | 'a = [-2, 3; 2, 1]', 11 | 'b = [11, 9]', 12 | 'x = lsolve(a, b)' 13 | ], 14 | seealso: [ 15 | 'lsolveAll', 'lup', 'lusolve', 'usolve', 'matrix', 'sparse' 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/algebra/lsolveAll.js: -------------------------------------------------------------------------------- 1 | export const lsolveAllDocs = { 2 | name: 'lsolveAll', 3 | category: 'Algebra', 4 | syntax: [ 5 | 'x=lsolveAll(L, b)' 6 | ], 7 | description: 8 | 'Finds all solutions of the linear system L * x = b where L is an [n x n] lower triangular matrix and b is a [n] column vector.', 9 | examples: [ 10 | 'a = [-2, 3; 2, 1]', 11 | 'b = [11, 9]', 12 | 'x = lsolve(a, b)' 13 | ], 14 | seealso: [ 15 | 'lsolve', 'lup', 'lusolve', 'usolve', 'matrix', 'sparse' 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/algebra/lup.js: -------------------------------------------------------------------------------- 1 | export const lupDocs = { 2 | name: 'lup', 3 | category: 'Algebra', 4 | syntax: [ 5 | 'lup(m)' 6 | ], 7 | description: 8 | 'Calculate the Matrix LU decomposition with partial pivoting. Matrix A is decomposed in three matrices (L, U, P) where P * A = L * U', 9 | examples: [ 10 | 'lup([[2, 1], [1, 4]])', 11 | 'lup(matrix([[2, 1], [1, 4]]))', 12 | 'lup(sparse([[2, 1], [1, 4]]))' 13 | ], 14 | seealso: [ 15 | 'lusolve', 'lsolve', 'usolve', 'matrix', 'sparse', 'slu', 'qr' 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/algebra/lusolve.js: -------------------------------------------------------------------------------- 1 | export const lusolveDocs = { 2 | name: 'lusolve', 3 | category: 'Algebra', 4 | syntax: [ 5 | 'x=lusolve(A, b)', 6 | 'x=lusolve(lu, b)' 7 | ], 8 | description: 'Solves the linear system A * x = b where A is an [n x n] matrix and b is a [n] column vector.', 9 | examples: [ 10 | 'a = [-2, 3; 2, 1]', 11 | 'b = [11, 9]', 12 | 'x = lusolve(a, b)' 13 | ], 14 | seealso: [ 15 | 'lup', 'slu', 'lsolve', 'usolve', 'matrix', 'sparse' 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/algebra/lyap.js: -------------------------------------------------------------------------------- 1 | export const lyapDocs = { 2 | name: 'lyap', 3 | category: 'Algebra', 4 | syntax: [ 5 | 'lyap(A,Q)' 6 | ], 7 | description: 'Solves the Continuous-time Lyapunov equation AP+PA\'+Q=0 for P', 8 | examples: [ 9 | 'lyap([[-2, 0], [1, -4]], [[3, 1], [1, 3]])', 10 | 'A = [[-2, 0], [1, -4]]', 11 | 'Q = [[3, 1], [1, 3]]', 12 | 'lyap(A,Q)' 13 | ], 14 | seealso: [ 15 | 'schur', 'sylvester' 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/algebra/polynomialRoot.js: -------------------------------------------------------------------------------- 1 | export const polynomialRootDocs = { 2 | name: 'polynomialRoot', 3 | category: 'Algebra', 4 | syntax: [ 5 | 'x=polynomialRoot(-6, 3)', 6 | 'x=polynomialRoot(4, -4, 1)', 7 | 'x=polynomialRoot(-8, 12, -6, 1)' 8 | ], 9 | description: 'Finds the roots of a univariate polynomial given by its coefficients starting from constant, linear, and so on, increasing in degree.', 10 | examples: [ 11 | 'a = polynomialRoot(-6, 11, -6, 1)' 12 | ], 13 | seealso: [ 14 | 'cbrt', 'sqrt' 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/algebra/qr.js: -------------------------------------------------------------------------------- 1 | export const qrDocs = { 2 | name: 'qr', 3 | category: 'Algebra', 4 | syntax: [ 5 | 'qr(A)' 6 | ], 7 | description: 8 | 'Calculates the Matrix QR decomposition. Matrix `A` is decomposed in two matrices (`Q`, `R`) where `Q` is an orthogonal matrix and `R` is an upper triangular matrix.', 9 | examples: [ 10 | 'qr([[1, -1, 4], [1, 4, -2], [1, 4, 2], [1, -1, 0]])' 11 | ], 12 | seealso: [ 13 | 'lup', 'slu', 'matrix' 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/algebra/rationalize.js: -------------------------------------------------------------------------------- 1 | export const rationalizeDocs = { 2 | name: 'rationalize', 3 | category: 'Algebra', 4 | syntax: [ 5 | 'rationalize(expr)', 6 | 'rationalize(expr, scope)', 7 | 'rationalize(expr, scope, detailed)' 8 | ], 9 | description: 'Transform a rationalizable expression in a rational fraction. If rational fraction is one variable polynomial then converts the numerator and denominator in canonical form, with decreasing exponents, returning the coefficients of numerator.', 10 | examples: [ 11 | 'rationalize("2x/y - y/(x+1)")', 12 | 'rationalize("2x/y - y/(x+1)", true)' 13 | ], 14 | seealso: [ 15 | 'simplify' 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/algebra/resolve.js: -------------------------------------------------------------------------------- 1 | export const resolveDocs = { 2 | name: 'resolve', 3 | category: 'Algebra', 4 | syntax: [ 5 | 'resolve(node, scope)' 6 | ], 7 | description: 'Recursively substitute variables in an expression tree.', 8 | examples: [ 9 | 'resolve(parse("1 + x"), { x: 7 })', 10 | 'resolve(parse("size(text)"), { text: "Hello World" })', 11 | 'resolve(parse("x + y"), { x: parse("3z") })', 12 | 'resolve(parse("3x"), { x: parse("y+z"), z: parse("w^y") })' 13 | ], 14 | seealso: [ 15 | 'simplify', 'evaluate' 16 | ], 17 | mayThrow: [ 18 | 'ReferenceError' 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/algebra/schur.js: -------------------------------------------------------------------------------- 1 | export const schurDocs = { 2 | name: 'schur', 3 | category: 'Algebra', 4 | syntax: [ 5 | 'schur(A)' 6 | ], 7 | description: 'Performs a real Schur decomposition of the real matrix A = UTU\'', 8 | examples: [ 9 | 'schur([[1, 0], [-4, 3]])', 10 | 'A = [[1, 0], [-4, 3]]', 11 | 'schur(A)' 12 | ], 13 | seealso: [ 14 | 'lyap', 'sylvester' 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/algebra/simplify.js: -------------------------------------------------------------------------------- 1 | export const simplifyDocs = { 2 | name: 'simplify', 3 | category: 'Algebra', 4 | syntax: [ 5 | 'simplify(expr)', 6 | 'simplify(expr, rules)' 7 | ], 8 | description: 'Simplify an expression tree.', 9 | examples: [ 10 | 'simplify("3 + 2 / 4")', 11 | 'simplify("2x + x")', 12 | 'f = parse("x * (x + 2 + x)")', 13 | 'simplified = simplify(f)', 14 | 'simplified.evaluate({x: 2})' 15 | ], 16 | seealso: [ 17 | 'simplifyCore', 'derivative', 'evaluate', 'parse', 'rationalize', 'resolve' 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/algebra/simplifyConstant.js: -------------------------------------------------------------------------------- 1 | export const simplifyConstantDocs = { 2 | name: 'simplifyConstant', 3 | category: 'Algebra', 4 | syntax: [ 5 | 'simplifyConstant(expr)', 6 | 'simplifyConstant(expr, options)' 7 | ], 8 | description: 'Replace constant subexpressions of node with their values.', 9 | examples: [ 10 | 'simplifyConstant("(3-3)*x")', 11 | 'simplifyConstant(parse("z-cos(tau/8)"))' 12 | ], 13 | seealso: [ 14 | 'simplify', 'simplifyCore', 'evaluate' 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/algebra/simplifyCore.js: -------------------------------------------------------------------------------- 1 | export const simplifyCoreDocs = { 2 | name: 'simplifyCore', 3 | category: 'Algebra', 4 | syntax: [ 5 | 'simplifyCore(node)' 6 | ], 7 | description: 'Perform simple one-pass simplifications on an expression tree.', 8 | examples: [ 9 | 'simplifyCore(parse("0*x"))', 10 | 'simplifyCore(parse("(x+0)*2"))' 11 | ], 12 | seealso: [ 13 | 'simplify', 'simplifyConstant', 'evaluate' 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/algebra/slu.js: -------------------------------------------------------------------------------- 1 | export const sluDocs = { 2 | name: 'slu', 3 | category: 'Algebra', 4 | syntax: [ 5 | 'slu(A, order, threshold)' 6 | ], 7 | description: 'Calculate the Matrix LU decomposition with full pivoting. Matrix A is decomposed in two matrices (L, U) and two permutation vectors (pinv, q) where P * A * Q = L * U', 8 | examples: [ 9 | 'slu(sparse([4.5, 0, 3.2, 0; 3.1, 2.9, 0, 0.9; 0, 1.7, 3, 0; 3.5, 0.4, 0, 1]), 1, 0.001)' 10 | ], 11 | seealso: [ 12 | 'lusolve', 'lsolve', 'usolve', 'matrix', 'sparse', 'lup', 'qr' 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/algebra/sylvester.js: -------------------------------------------------------------------------------- 1 | export const sylvesterDocs = { 2 | name: 'sylvester', 3 | category: 'Algebra', 4 | syntax: [ 5 | 'sylvester(A,B,C)' 6 | ], 7 | description: 'Solves the real-valued Sylvester equation AX+XB=C for X', 8 | examples: [ 9 | 'sylvester([[-1, -2], [1, 1]], [[-2, 1], [-1, 2]], [[-3, 2], [3, 0]])', 10 | 'A = [[-1, -2], [1, 1]]; B = [[2, -1], [1, -2]]; C = [[-3, 2], [3, 0]]', 11 | 'sylvester(A, B, C)' 12 | ], 13 | seealso: [ 14 | 'schur', 'lyap' 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/algebra/symbolicEqual.js: -------------------------------------------------------------------------------- 1 | export const symbolicEqualDocs = { 2 | name: 'symbolicEqual', 3 | category: 'Algebra', 4 | syntax: [ 5 | 'symbolicEqual(expr1, expr2)', 6 | 'symbolicEqual(expr1, expr2, options)' 7 | ], 8 | description: 'Returns true if the difference of the expressions simplifies to 0', 9 | examples: [ 10 | 'symbolicEqual("x*y","y*x")', 11 | 'symbolicEqual("abs(x^2)", "x^2")', 12 | 'symbolicEqual("abs(x)", "x", {context: {abs: {trivial: true}}})' 13 | ], 14 | seealso: ['simplify', 'evaluate'] 15 | } 16 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/algebra/usolve.js: -------------------------------------------------------------------------------- 1 | export const usolveDocs = { 2 | name: 'usolve', 3 | category: 'Algebra', 4 | syntax: [ 5 | 'x=usolve(U, b)' 6 | ], 7 | description: 8 | 'Finds one solution of the linear system U * x = b where U is an [n x n] upper triangular matrix and b is a [n] column vector.', 9 | examples: [ 10 | 'x=usolve(sparse([1, 1, 1, 1; 0, 1, 1, 1; 0, 0, 1, 1; 0, 0, 0, 1]), [1; 2; 3; 4])' 11 | ], 12 | seealso: [ 13 | 'usolveAll', 'lup', 'lusolve', 'lsolve', 'matrix', 'sparse' 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/algebra/usolveAll.js: -------------------------------------------------------------------------------- 1 | export const usolveAllDocs = { 2 | name: 'usolveAll', 3 | category: 'Algebra', 4 | syntax: [ 5 | 'x=usolve(U, b)' 6 | ], 7 | description: 8 | 'Finds all solutions of the linear system U * x = b where U is an [n x n] upper triangular matrix and b is a [n] column vector.', 9 | examples: [ 10 | 'x=usolve(sparse([1, 1, 1, 1; 0, 1, 1, 1; 0, 0, 1, 1; 0, 0, 0, 1]), [1; 2; 3; 4])' 11 | ], 12 | seealso: [ 13 | 'usolve', 'lup', 'lusolve', 'lsolve', 'matrix', 'sparse' 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/arithmetic/abs.js: -------------------------------------------------------------------------------- 1 | export const absDocs = { 2 | name: 'abs', 3 | category: 'Arithmetic', 4 | syntax: [ 5 | 'abs(x)' 6 | ], 7 | description: 'Compute the absolute value.', 8 | examples: [ 9 | 'abs(3.5)', 10 | 'abs(-4.2)' 11 | ], 12 | seealso: ['sign'] 13 | } 14 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/arithmetic/add.js: -------------------------------------------------------------------------------- 1 | export const addDocs = { 2 | name: 'add', 3 | category: 'Operators', 4 | syntax: [ 5 | 'x + y', 6 | 'add(x, y)' 7 | ], 8 | description: 'Add two values.', 9 | examples: [ 10 | 'a = 2.1 + 3.6', 11 | 'a - 3.6', 12 | '3 + 2i', 13 | '3 cm + 2 inch', 14 | '"2.3" + "4"' 15 | ], 16 | seealso: [ 17 | 'subtract' 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/arithmetic/cbrt.js: -------------------------------------------------------------------------------- 1 | export const cbrtDocs = { 2 | name: 'cbrt', 3 | category: 'Arithmetic', 4 | syntax: [ 5 | 'cbrt(x)', 6 | 'cbrt(x, allRoots)' 7 | ], 8 | description: 9 | 'Compute the cubic root value. If x = y * y * y, then y is the cubic root of x. When `x` is a number or complex number, an optional second argument `allRoots` can be provided to return all three cubic roots. If not provided, the principal root is returned', 10 | examples: [ 11 | 'cbrt(64)', 12 | 'cube(4)', 13 | 'cbrt(-8)', 14 | 'cbrt(2 + 3i)', 15 | 'cbrt(8i)', 16 | 'cbrt(8i, true)', 17 | 'cbrt(27 m^3)' 18 | ], 19 | seealso: [ 20 | 'square', 21 | 'sqrt', 22 | 'cube', 23 | 'multiply' 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/arithmetic/ceil.js: -------------------------------------------------------------------------------- 1 | export const ceilDocs = { 2 | name: 'ceil', 3 | category: 'Arithmetic', 4 | syntax: [ 5 | 'ceil(x)', 6 | 'ceil(x, n)', 7 | 'ceil(unit, valuelessUnit)', 8 | 'ceil(unit, n, valuelessUnit)' 9 | ], 10 | description: 11 | 'Round a value towards plus infinity. If x is complex, both real and imaginary part are rounded towards plus infinity.', 12 | examples: [ 13 | 'ceil(3.2)', 14 | 'ceil(3.8)', 15 | 'ceil(-4.2)', 16 | 'ceil(3.241cm, cm)', 17 | 'ceil(3.241cm, 2, cm)' 18 | ], 19 | seealso: ['floor', 'fix', 'round'] 20 | } 21 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/arithmetic/cube.js: -------------------------------------------------------------------------------- 1 | export const cubeDocs = { 2 | name: 'cube', 3 | category: 'Arithmetic', 4 | syntax: [ 5 | 'cube(x)' 6 | ], 7 | description: 'Compute the cube of a value. The cube of x is x * x * x.', 8 | examples: [ 9 | 'cube(2)', 10 | '2^3', 11 | '2 * 2 * 2' 12 | ], 13 | seealso: [ 14 | 'multiply', 15 | 'square', 16 | 'pow' 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/arithmetic/divide.js: -------------------------------------------------------------------------------- 1 | export const divideDocs = { 2 | name: 'divide', 3 | category: 'Operators', 4 | syntax: [ 5 | 'x / y', 6 | 'divide(x, y)' 7 | ], 8 | description: 'Divide two values.', 9 | examples: [ 10 | 'a = 2 / 3', 11 | 'a * 3', 12 | '4.5 / 2', 13 | '3 + 4 / 2', 14 | '(3 + 4) / 2', 15 | '18 km / 4.5' 16 | ], 17 | seealso: [ 18 | 'multiply' 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/arithmetic/dotDivide.js: -------------------------------------------------------------------------------- 1 | export const dotDivideDocs = { 2 | name: 'dotDivide', 3 | category: 'Operators', 4 | syntax: [ 5 | 'x ./ y', 6 | 'dotDivide(x, y)' 7 | ], 8 | description: 'Divide two values element wise.', 9 | examples: [ 10 | 'a = [1, 2, 3; 4, 5, 6]', 11 | 'b = [2, 1, 1; 3, 2, 5]', 12 | 'a ./ b' 13 | ], 14 | seealso: [ 15 | 'multiply', 16 | 'dotMultiply', 17 | 'divide' 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/arithmetic/dotMultiply.js: -------------------------------------------------------------------------------- 1 | export const dotMultiplyDocs = { 2 | name: 'dotMultiply', 3 | category: 'Operators', 4 | syntax: [ 5 | 'x .* y', 6 | 'dotMultiply(x, y)' 7 | ], 8 | description: 'Multiply two values element wise.', 9 | examples: [ 10 | 'a = [1, 2, 3; 4, 5, 6]', 11 | 'b = [2, 1, 1; 3, 2, 5]', 12 | 'a .* b' 13 | ], 14 | seealso: [ 15 | 'multiply', 16 | 'divide', 17 | 'dotDivide' 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/arithmetic/dotPow.js: -------------------------------------------------------------------------------- 1 | export const dotPowDocs = { 2 | name: 'dotPow', 3 | category: 'Operators', 4 | syntax: [ 5 | 'x .^ y', 6 | 'dotPow(x, y)' 7 | ], 8 | description: 9 | 'Calculates the power of x to y element wise.', 10 | examples: [ 11 | 'a = [1, 2, 3; 4, 5, 6]', 12 | 'a .^ 2' 13 | ], 14 | seealso: [ 15 | 'pow' 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/arithmetic/exp.js: -------------------------------------------------------------------------------- 1 | export const expDocs = { 2 | name: 'exp', 3 | category: 'Arithmetic', 4 | syntax: [ 5 | 'exp(x)' 6 | ], 7 | description: 'Calculate the exponent of a value.', 8 | examples: [ 9 | 'exp(1.3)', 10 | 'e ^ 1.3', 11 | 'log(exp(1.3))', 12 | 'x = 2.4', 13 | '(exp(i*x) == cos(x) + i*sin(x)) # Euler\'s formula' 14 | ], 15 | seealso: [ 16 | 'expm', 17 | 'expm1', 18 | 'pow', 19 | 'log' 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/arithmetic/expm.js: -------------------------------------------------------------------------------- 1 | export const expmDocs = { 2 | name: 'expm', 3 | category: 'Arithmetic', 4 | syntax: [ 5 | 'exp(x)' 6 | ], 7 | description: 'Compute the matrix exponential, expm(A) = e^A. ' + 8 | 'The matrix must be square. ' + 9 | 'Not to be confused with exp(a), which performs element-wise exponentiation.', 10 | examples: [ 11 | 'expm([[0,2],[0,0]])' 12 | ], 13 | seealso: [ 14 | 'exp' 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/arithmetic/expm1.js: -------------------------------------------------------------------------------- 1 | export const expm1Docs = { 2 | name: 'expm1', 3 | category: 'Arithmetic', 4 | syntax: [ 5 | 'expm1(x)' 6 | ], 7 | description: 'Calculate the value of subtracting 1 from the exponential value.', 8 | examples: [ 9 | 'expm1(2)', 10 | 'pow(e, 2) - 1', 11 | 'log(expm1(2) + 1)' 12 | ], 13 | seealso: [ 14 | 'exp', 15 | 'pow', 16 | 'log' 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/arithmetic/fix.js: -------------------------------------------------------------------------------- 1 | export const fixDocs = { 2 | name: 'fix', 3 | category: 'Arithmetic', 4 | syntax: [ 5 | 'fix(x)', 6 | 'fix(x, n)', 7 | 'fix(unit, valuelessUnit)', 8 | 'fix(unit, n, valuelessUnit)' 9 | ], 10 | description: 11 | 'Round a value towards zero. If x is complex, both real and imaginary part are rounded towards zero.', 12 | examples: [ 13 | 'fix(3.2)', 14 | 'fix(3.8)', 15 | 'fix(-4.2)', 16 | 'fix(-4.8)', 17 | 'fix(3.241cm, cm)', 18 | 'fix(3.241cm, 2, cm)' 19 | ], 20 | seealso: ['ceil', 'floor', 'round'] 21 | } 22 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/arithmetic/floor.js: -------------------------------------------------------------------------------- 1 | export const floorDocs = { 2 | name: 'floor', 3 | category: 'Arithmetic', 4 | syntax: [ 5 | 'floor(x)', 6 | 'floor(x, n)', 7 | 'floor(unit, valuelessUnit)', 8 | 'floor(unit, n, valuelessUnit)' 9 | ], 10 | description: 11 | 'Round a value towards minus infinity.If x is complex, both real and imaginary part are rounded towards minus infinity.', 12 | examples: [ 13 | 'floor(3.2)', 14 | 'floor(3.8)', 15 | 'floor(-4.2)', 16 | 'floor(3.241cm, cm)', 17 | 'floor(3.241cm, 2, cm)' 18 | ], 19 | seealso: ['ceil', 'fix', 'round'] 20 | } 21 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/arithmetic/gcd.js: -------------------------------------------------------------------------------- 1 | export const gcdDocs = { 2 | name: 'gcd', 3 | category: 'Arithmetic', 4 | syntax: [ 5 | 'gcd(a, b)', 6 | 'gcd(a, b, c, ...)' 7 | ], 8 | description: 'Compute the greatest common divisor.', 9 | examples: [ 10 | 'gcd(8, 12)', 11 | 'gcd(-4, 6)', 12 | 'gcd(25, 15, -10)' 13 | ], 14 | seealso: ['lcm', 'xgcd'] 15 | } 16 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/arithmetic/hypot.js: -------------------------------------------------------------------------------- 1 | export const hypotDocs = { 2 | name: 'hypot', 3 | category: 'Arithmetic', 4 | syntax: [ 5 | 'hypot(a, b, c, ...)', 6 | 'hypot([a, b, c, ...])' 7 | ], 8 | description: 'Calculate the hypotenuse of a list with values.', 9 | examples: [ 10 | 'hypot(3, 4)', 11 | 'sqrt(3^2 + 4^2)', 12 | 'hypot(-2)', 13 | 'hypot([3, 4, 5])' 14 | ], 15 | seealso: ['abs', 'norm'] 16 | } 17 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/arithmetic/invmod.js: -------------------------------------------------------------------------------- 1 | export const invmodDocs = { 2 | name: 'invmod', 3 | category: 'Arithmetic', 4 | syntax: [ 5 | 'invmod(a, b)' 6 | ], 7 | description: 'Calculate the (modular) multiplicative inverse of a modulo b. Solution to the equation ax ≣ 1 (mod b)', 8 | examples: [ 9 | 'invmod(8, 12)', 10 | 'invmod(7, 13)', 11 | 'invmod(15151, 15122)' 12 | ], 13 | seealso: ['gcd', 'xgcd'] 14 | } 15 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/arithmetic/lcm.js: -------------------------------------------------------------------------------- 1 | export const lcmDocs = { 2 | name: 'lcm', 3 | category: 'Arithmetic', 4 | syntax: [ 5 | 'lcm(x, y)' 6 | ], 7 | description: 'Compute the least common multiple.', 8 | examples: [ 9 | 'lcm(4, 6)', 10 | 'lcm(6, 21)', 11 | 'lcm(6, 21, 5)' 12 | ], 13 | seealso: ['gcd'] 14 | } 15 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/arithmetic/log.js: -------------------------------------------------------------------------------- 1 | export const logDocs = { 2 | name: 'log', 3 | category: 'Arithmetic', 4 | syntax: [ 5 | 'log(x)', 6 | 'log(x, base)' 7 | ], 8 | description: 'Compute the logarithm of a value. If no base is provided, the natural logarithm of x is calculated. If base if provided, the logarithm is calculated for the specified base. log(x, base) is defined as log(x) / log(base).', 9 | examples: [ 10 | 'log(3.5)', 11 | 'a = log(2.4)', 12 | 'exp(a)', 13 | '10 ^ 4', 14 | 'log(10000, 10)', 15 | 'log(10000) / log(10)', 16 | 'b = log(1024, 2)', 17 | '2 ^ b' 18 | ], 19 | seealso: [ 20 | 'exp', 21 | 'log1p', 22 | 'log2', 23 | 'log10' 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/arithmetic/log10.js: -------------------------------------------------------------------------------- 1 | export const log10Docs = { 2 | name: 'log10', 3 | category: 'Arithmetic', 4 | syntax: [ 5 | 'log10(x)' 6 | ], 7 | description: 'Compute the 10-base logarithm of a value.', 8 | examples: [ 9 | 'log10(0.00001)', 10 | 'log10(10000)', 11 | '10 ^ 4', 12 | 'log(10000) / log(10)', 13 | 'log(10000, 10)' 14 | ], 15 | seealso: [ 16 | 'exp', 17 | 'log' 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/arithmetic/log1p.js: -------------------------------------------------------------------------------- 1 | export const log1pDocs = { 2 | name: 'log1p', 3 | category: 'Arithmetic', 4 | syntax: [ 5 | 'log1p(x)', 6 | 'log1p(x, base)' 7 | ], 8 | description: 'Calculate the logarithm of a `value+1`', 9 | examples: [ 10 | 'log1p(2.5)', 11 | 'exp(log1p(1.4))', 12 | 'pow(10, 4)', 13 | 'log1p(9999, 10)', 14 | 'log1p(9999) / log(10)' 15 | ], 16 | seealso: [ 17 | 'exp', 18 | 'log', 19 | 'log2', 20 | 'log10' 21 | ] 22 | } 23 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/arithmetic/log2.js: -------------------------------------------------------------------------------- 1 | export const log2Docs = { 2 | name: 'log2', 3 | category: 'Arithmetic', 4 | syntax: [ 5 | 'log2(x)' 6 | ], 7 | description: 'Calculate the 2-base of a value. This is the same as calculating `log(x, 2)`.', 8 | examples: [ 9 | 'log2(0.03125)', 10 | 'log2(16)', 11 | 'log2(16) / log2(2)', 12 | 'pow(2, 4)' 13 | ], 14 | seealso: [ 15 | 'exp', 16 | 'log1p', 17 | 'log', 18 | 'log10' 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/arithmetic/mod.js: -------------------------------------------------------------------------------- 1 | export const modDocs = { 2 | name: 'mod', 3 | category: 'Operators', 4 | syntax: [ 5 | 'x % y', 6 | 'x mod y', 7 | 'mod(x, y)' 8 | ], 9 | description: 10 | 'Calculates the modulus, the remainder of an integer division.', 11 | examples: [ 12 | '7 % 3', 13 | '11 % 2', 14 | '10 mod 4', 15 | 'isOdd(x) = x % 2', 16 | 'isOdd(2)', 17 | 'isOdd(3)' 18 | ], 19 | seealso: ['divide'] 20 | } 21 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/arithmetic/multiply.js: -------------------------------------------------------------------------------- 1 | export const multiplyDocs = { 2 | name: 'multiply', 3 | category: 'Operators', 4 | syntax: [ 5 | 'x * y', 6 | 'multiply(x, y)' 7 | ], 8 | description: 'multiply two values.', 9 | examples: [ 10 | 'a = 2.1 * 3.4', 11 | 'a / 3.4', 12 | '2 * 3 + 4', 13 | '2 * (3 + 4)', 14 | '3 * 2.1 km' 15 | ], 16 | seealso: [ 17 | 'divide' 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/arithmetic/norm.js: -------------------------------------------------------------------------------- 1 | export const normDocs = { 2 | name: 'norm', 3 | category: 'Arithmetic', 4 | syntax: [ 5 | 'norm(x)', 6 | 'norm(x, p)' 7 | ], 8 | description: 'Calculate the norm of a number, vector or matrix.', 9 | examples: [ 10 | 'abs(-3.5)', 11 | 'norm(-3.5)', 12 | 'norm(3 - 4i)', 13 | 'norm([1, 2, -3], Infinity)', 14 | 'norm([1, 2, -3], -Infinity)', 15 | 'norm([3, 4], 2)', 16 | 'norm([[1, 2], [3, 4]], 1)', 17 | 'norm([[1, 2], [3, 4]], "inf")', 18 | 'norm([[1, 2], [3, 4]], "fro")' 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/arithmetic/nthRoot.js: -------------------------------------------------------------------------------- 1 | export const nthRootDocs = { 2 | name: 'nthRoot', 3 | category: 'Arithmetic', 4 | syntax: [ 5 | 'nthRoot(a)', 6 | 'nthRoot(a, root)' 7 | ], 8 | description: 'Calculate the nth root of a value. ' + 9 | 'The principal nth root of a positive real number A, ' + 10 | 'is the positive real solution of the equation "x^root = A".', 11 | examples: [ 12 | '4 ^ 3', 13 | 'nthRoot(64, 3)', 14 | 'nthRoot(9, 2)', 15 | 'sqrt(9)' 16 | ], 17 | seealso: [ 18 | 'nthRoots', 19 | 'pow', 20 | 'sqrt' 21 | ] 22 | } 23 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/arithmetic/nthRoots.js: -------------------------------------------------------------------------------- 1 | export const nthRootsDocs = { 2 | name: 'nthRoots', 3 | category: 'Arithmetic', 4 | syntax: [ 5 | 'nthRoots(A)', 6 | 'nthRoots(A, root)' 7 | ], 8 | description: ('' + 9 | 'Calculate the nth roots of a value. ' + 10 | 'An nth root of a positive real number A, ' + 11 | 'is a positive real solution of the equation "x^root = A". ' + 12 | 'This function returns an array of complex values.' 13 | ), 14 | examples: [ 15 | 'nthRoots(1)', 16 | 'nthRoots(1, 3)' 17 | ], 18 | seealso: [ 19 | 'sqrt', 20 | 'pow', 21 | 'nthRoot' 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/arithmetic/pow.js: -------------------------------------------------------------------------------- 1 | export const powDocs = { 2 | name: 'pow', 3 | category: 'Operators', 4 | syntax: [ 5 | 'x ^ y', 6 | 'pow(x, y)' 7 | ], 8 | description: 9 | 'Calculates the power of x to y, x^y.', 10 | examples: [ 11 | '2^3', 12 | '2*2*2', 13 | '1 + e ^ (pi * i)', 14 | 'pow([[1, 2], [4, 3]], 2)', 15 | 'pow([[1, 2], [4, 3]], -1)' 16 | ], 17 | seealso: [ 18 | 'multiply', 19 | 'nthRoot', 20 | 'nthRoots', 21 | 'sqrt' 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/arithmetic/round.js: -------------------------------------------------------------------------------- 1 | export const roundDocs = { 2 | name: 'round', 3 | category: 'Arithmetic', 4 | syntax: [ 5 | 'round(x)', 6 | 'round(x, n)', 7 | 'round(unit, valuelessUnit)', 8 | 'round(unit, n, valuelessUnit)' 9 | ], 10 | description: 11 | 'round a value towards the nearest integer.If x is complex, both real and imaginary part are rounded towards the nearest integer. When n is specified, the value is rounded to n decimals.', 12 | examples: [ 13 | 'round(3.2)', 14 | 'round(3.8)', 15 | 'round(-4.2)', 16 | 'round(-4.8)', 17 | 'round(pi, 3)', 18 | 'round(123.45678, 2)', 19 | 'round(3.241cm, 2, cm)', 20 | 'round([3.2, 3.8, -4.7])' 21 | ], 22 | seealso: ['ceil', 'floor', 'fix'] 23 | } 24 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/arithmetic/sign.js: -------------------------------------------------------------------------------- 1 | export const signDocs = { 2 | name: 'sign', 3 | category: 'Arithmetic', 4 | syntax: [ 5 | 'sign(x)' 6 | ], 7 | description: 8 | 'Compute the sign of a value. The sign of a value x is 1 when x>0, -1 when x<0, and 0 when x=0.', 9 | examples: [ 10 | 'sign(3.5)', 11 | 'sign(-4.2)', 12 | 'sign(0)' 13 | ], 14 | seealso: [ 15 | 'abs' 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/arithmetic/sqrt.js: -------------------------------------------------------------------------------- 1 | export const sqrtDocs = { 2 | name: 'sqrt', 3 | category: 'Arithmetic', 4 | syntax: [ 5 | 'sqrt(x)' 6 | ], 7 | description: 8 | 'Compute the square root value. If x = y * y, then y is the square root of x.', 9 | examples: [ 10 | 'sqrt(25)', 11 | '5 * 5', 12 | 'sqrt(-1)' 13 | ], 14 | seealso: [ 15 | 'square', 16 | 'sqrtm', 17 | 'multiply', 18 | 'nthRoot', 19 | 'nthRoots', 20 | 'pow' 21 | ] 22 | } 23 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/arithmetic/sqrtm.js: -------------------------------------------------------------------------------- 1 | export const sqrtmDocs = { 2 | name: 'sqrtm', 3 | category: 'Arithmetic', 4 | syntax: [ 5 | 'sqrtm(x)' 6 | ], 7 | description: 8 | 'Calculate the principal square root of a square matrix. The principal square root matrix `X` of another matrix `A` is such that `X * X = A`.', 9 | examples: [ 10 | 'sqrtm([[33, 24], [48, 57]])' 11 | ], 12 | seealso: [ 13 | 'sqrt', 14 | 'abs', 15 | 'square', 16 | 'multiply' 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/arithmetic/square.js: -------------------------------------------------------------------------------- 1 | export const squareDocs = { 2 | name: 'square', 3 | category: 'Arithmetic', 4 | syntax: [ 5 | 'square(x)' 6 | ], 7 | description: 8 | 'Compute the square of a value. The square of x is x * x.', 9 | examples: [ 10 | 'square(3)', 11 | 'sqrt(9)', 12 | '3^2', 13 | '3 * 3' 14 | ], 15 | seealso: [ 16 | 'multiply', 17 | 'pow', 18 | 'sqrt', 19 | 'cube' 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/arithmetic/subtract.js: -------------------------------------------------------------------------------- 1 | export const subtractDocs = { 2 | name: 'subtract', 3 | category: 'Operators', 4 | syntax: [ 5 | 'x - y', 6 | 'subtract(x, y)' 7 | ], 8 | description: 'subtract two values.', 9 | examples: [ 10 | 'a = 5.3 - 2', 11 | 'a + 2', 12 | '2/3 - 1/6', 13 | '2 * 3 - 3', 14 | '2.1 km - 500m' 15 | ], 16 | seealso: [ 17 | 'add' 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/arithmetic/unaryMinus.js: -------------------------------------------------------------------------------- 1 | export const unaryMinusDocs = { 2 | name: 'unaryMinus', 3 | category: 'Operators', 4 | syntax: [ 5 | '-x', 6 | 'unaryMinus(x)' 7 | ], 8 | description: 9 | 'Inverse the sign of a value. Converts booleans and strings to numbers.', 10 | examples: [ 11 | '-4.5', 12 | '-(-5.6)', 13 | '-"22"' 14 | ], 15 | seealso: [ 16 | 'add', 'subtract', 'unaryPlus' 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/arithmetic/unaryPlus.js: -------------------------------------------------------------------------------- 1 | export const unaryPlusDocs = { 2 | name: 'unaryPlus', 3 | category: 'Operators', 4 | syntax: [ 5 | '+x', 6 | 'unaryPlus(x)' 7 | ], 8 | description: 9 | 'Converts booleans and strings to numbers.', 10 | examples: [ 11 | '+true', 12 | '+"2"' 13 | ], 14 | seealso: [ 15 | 'add', 'subtract', 'unaryMinus' 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/arithmetic/xgcd.js: -------------------------------------------------------------------------------- 1 | export const xgcdDocs = { 2 | name: 'xgcd', 3 | category: 'Arithmetic', 4 | syntax: [ 5 | 'xgcd(a, b)' 6 | ], 7 | description: 'Calculate the extended greatest common divisor for two values. The result is an array [d, x, y] with 3 entries, where d is the greatest common divisor, and d = x * a + y * b.', 8 | examples: [ 9 | 'xgcd(8, 12)', 10 | 'gcd(8, 12)', 11 | 'xgcd(36163, 21199)' 12 | ], 13 | seealso: ['gcd', 'lcm'] 14 | } 15 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/bitwise/bitAnd.js: -------------------------------------------------------------------------------- 1 | export const bitAndDocs = { 2 | name: 'bitAnd', 3 | category: 'Bitwise', 4 | syntax: [ 5 | 'x & y', 6 | 'bitAnd(x, y)' 7 | ], 8 | description: 'Bitwise AND operation. Performs the logical AND operation on each pair of the corresponding bits of the two given values by multiplying them. If both bits in the compared position are 1, the bit in the resulting binary representation is 1, otherwise, the result is 0', 9 | examples: [ 10 | '5 & 3', 11 | 'bitAnd(53, 131)', 12 | '[1, 12, 31] & 42' 13 | ], 14 | seealso: [ 15 | 'bitNot', 'bitOr', 'bitXor', 'leftShift', 'rightArithShift', 'rightLogShift' 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/bitwise/bitNot.js: -------------------------------------------------------------------------------- 1 | export const bitNotDocs = { 2 | name: 'bitNot', 3 | category: 'Bitwise', 4 | syntax: [ 5 | '~x', 6 | 'bitNot(x)' 7 | ], 8 | description: 'Bitwise NOT operation. Performs a logical negation on each bit of the given value. Bits that are 0 become 1, and those that are 1 become 0.', 9 | examples: [ 10 | '~1', 11 | '~2', 12 | 'bitNot([2, -3, 4])' 13 | ], 14 | seealso: [ 15 | 'bitAnd', 'bitOr', 'bitXor', 'leftShift', 'rightArithShift', 'rightLogShift' 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/bitwise/bitOr.js: -------------------------------------------------------------------------------- 1 | export const bitOrDocs = { 2 | name: 'bitOr', 3 | category: 'Bitwise', 4 | syntax: [ 5 | 'x | y', 6 | 'bitOr(x, y)' 7 | ], 8 | description: 'Bitwise OR operation. Performs the logical inclusive OR operation on each pair of corresponding bits of the two given values. The result in each position is 1 if the first bit is 1 or the second bit is 1 or both bits are 1, otherwise, the result is 0.', 9 | examples: [ 10 | '5 | 3', 11 | 'bitOr([1, 2, 3], 4)' 12 | ], 13 | seealso: [ 14 | 'bitAnd', 'bitNot', 'bitXor', 'leftShift', 'rightArithShift', 'rightLogShift' 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/bitwise/bitXor.js: -------------------------------------------------------------------------------- 1 | export const bitXorDocs = { 2 | name: 'bitXor', 3 | category: 'Bitwise', 4 | syntax: [ 5 | 'bitXor(x, y)' 6 | ], 7 | description: 'Bitwise XOR operation, exclusive OR. Performs the logical exclusive OR operation on each pair of corresponding bits of the two given values. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1.', 8 | examples: [ 9 | 'bitOr(1, 2)', 10 | 'bitXor([2, 3, 4], 4)' 11 | ], 12 | seealso: [ 13 | 'bitAnd', 'bitNot', 'bitOr', 'leftShift', 'rightArithShift', 'rightLogShift' 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/bitwise/leftShift.js: -------------------------------------------------------------------------------- 1 | export const leftShiftDocs = { 2 | name: 'leftShift', 3 | category: 'Bitwise', 4 | syntax: [ 5 | 'x << y', 6 | 'leftShift(x, y)' 7 | ], 8 | description: 'Bitwise left logical shift of a value x by y number of bits.', 9 | examples: [ 10 | '4 << 1', 11 | '8 >> 1' 12 | ], 13 | seealso: [ 14 | 'bitAnd', 'bitNot', 'bitOr', 'bitXor', 'rightArithShift', 'rightLogShift' 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/bitwise/rightArithShift.js: -------------------------------------------------------------------------------- 1 | export const rightArithShiftDocs = { 2 | name: 'rightArithShift', 3 | category: 'Bitwise', 4 | syntax: [ 5 | 'x >> y', 6 | 'rightArithShift(x, y)' 7 | ], 8 | description: 'Bitwise right arithmetic shift of a value x by y number of bits.', 9 | examples: [ 10 | '8 >> 1', 11 | '4 << 1', 12 | '-12 >> 2' 13 | ], 14 | seealso: [ 15 | 'bitAnd', 'bitNot', 'bitOr', 'bitXor', 'leftShift', 'rightLogShift' 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/bitwise/rightLogShift.js: -------------------------------------------------------------------------------- 1 | export const rightLogShiftDocs = { 2 | name: 'rightLogShift', 3 | category: 'Bitwise', 4 | syntax: [ 5 | 'x >>> y', 6 | 'rightLogShift(x, y)' 7 | ], 8 | description: 'Bitwise right logical shift of a value x by y number of bits.', 9 | examples: [ 10 | '8 >>> 1', 11 | '4 << 1', 12 | '-12 >>> 2' 13 | ], 14 | seealso: [ 15 | 'bitAnd', 'bitNot', 'bitOr', 'bitXor', 'leftShift', 'rightArithShift' 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/combinatorics/bellNumbers.js: -------------------------------------------------------------------------------- 1 | export const bellNumbersDocs = { 2 | name: 'bellNumbers', 3 | category: 'Combinatorics', 4 | syntax: [ 5 | 'bellNumbers(n)' 6 | ], 7 | description: 'The Bell Numbers count the number of partitions of a set. A partition is a pairwise disjoint subset of S whose union is S. `bellNumbers` only takes integer arguments. The following condition must be enforced: n >= 0.', 8 | examples: [ 9 | 'bellNumbers(3)', 10 | 'bellNumbers(8)' 11 | ], 12 | seealso: ['stirlingS2'] 13 | } 14 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/combinatorics/catalan.js: -------------------------------------------------------------------------------- 1 | export const catalanDocs = { 2 | name: 'catalan', 3 | category: 'Combinatorics', 4 | syntax: [ 5 | 'catalan(n)' 6 | ], 7 | description: 'The Catalan Numbers enumerate combinatorial structures of many different types. catalan only takes integer arguments. The following condition must be enforced: n >= 0.', 8 | examples: [ 9 | 'catalan(3)', 10 | 'catalan(8)' 11 | ], 12 | seealso: ['bellNumbers'] 13 | } 14 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/combinatorics/composition.js: -------------------------------------------------------------------------------- 1 | export const compositionDocs = { 2 | name: 'composition', 3 | category: 'Combinatorics', 4 | syntax: [ 5 | 'composition(n, k)' 6 | ], 7 | description: 'The composition counts of n into k parts. composition only takes integer arguments. The following condition must be enforced: k <= n.', 8 | examples: [ 9 | 'composition(5, 3)' 10 | ], 11 | seealso: ['combinations'] 12 | } 13 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/combinatorics/stirlingS2.js: -------------------------------------------------------------------------------- 1 | export const stirlingS2Docs = { 2 | name: 'stirlingS2', 3 | category: 'Combinatorics', 4 | syntax: [ 5 | 'stirlingS2(n, k)' 6 | ], 7 | description: 'he Stirling numbers of the second kind, counts the number of ways to partition a set of n labelled objects into k nonempty unlabelled subsets. `stirlingS2` only takes integer arguments. The following condition must be enforced: k <= n. If n = k or k = 1, then s(n,k) = 1.', 8 | examples: [ 9 | 'stirlingS2(5, 3)' 10 | ], 11 | seealso: ['bellNumbers'] 12 | } 13 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/complex/arg.js: -------------------------------------------------------------------------------- 1 | export const argDocs = { 2 | name: 'arg', 3 | category: 'Complex', 4 | syntax: [ 5 | 'arg(x)' 6 | ], 7 | description: 8 | 'Compute the argument of a complex value. If x = a+bi, the argument is computed as atan2(b, a).', 9 | examples: [ 10 | 'arg(2 + 2i)', 11 | 'atan2(3, 2)', 12 | 'arg(2 + 3i)' 13 | ], 14 | seealso: [ 15 | 're', 16 | 'im', 17 | 'conj', 18 | 'abs' 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/complex/conj.js: -------------------------------------------------------------------------------- 1 | export const conjDocs = { 2 | name: 'conj', 3 | category: 'Complex', 4 | syntax: [ 5 | 'conj(x)' 6 | ], 7 | description: 8 | 'Compute the complex conjugate of a complex value. If x = a+bi, the complex conjugate is a-bi.', 9 | examples: [ 10 | 'conj(2 + 3i)', 11 | 'conj(2 - 3i)', 12 | 'conj(-5.2i)' 13 | ], 14 | seealso: [ 15 | 're', 16 | 'im', 17 | 'abs', 18 | 'arg' 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/complex/im.js: -------------------------------------------------------------------------------- 1 | export const imDocs = { 2 | name: 'im', 3 | category: 'Complex', 4 | syntax: [ 5 | 'im(x)' 6 | ], 7 | description: 'Get the imaginary part of a complex number.', 8 | examples: [ 9 | 'im(2 + 3i)', 10 | 're(2 + 3i)', 11 | 'im(-5.2i)', 12 | 'im(2.4)' 13 | ], 14 | seealso: [ 15 | 're', 16 | 'conj', 17 | 'abs', 18 | 'arg' 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/complex/re.js: -------------------------------------------------------------------------------- 1 | export const reDocs = { 2 | name: 're', 3 | category: 'Complex', 4 | syntax: [ 5 | 're(x)' 6 | ], 7 | description: 'Get the real part of a complex number.', 8 | examples: [ 9 | 're(2 + 3i)', 10 | 'im(2 + 3i)', 11 | 're(-5.2i)', 12 | 're(2.4)' 13 | ], 14 | seealso: [ 15 | 'im', 16 | 'conj', 17 | 'abs', 18 | 'arg' 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/expression/compile.js: -------------------------------------------------------------------------------- 1 | export const compileDocs = { 2 | name: 'compile', 3 | category: 'Expression', 4 | syntax: [ 5 | 'compile(expr) ', 6 | 'compile([expr1, expr2, expr3, ...])' 7 | ], 8 | description: 'Parse and compile an expression. Returns a an object with a function evaluate([scope]) to evaluate the compiled expression.', 9 | examples: [ 10 | 'code1 = compile("sqrt(3^2 + 4^2)")', 11 | 'code1.evaluate() ', 12 | 'code2 = compile("a * b")', 13 | 'code2.evaluate({a: 3, b: 4})' 14 | ], 15 | seealso: ['parser', 'parse', 'evaluate'] 16 | } 17 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/expression/evaluate.js: -------------------------------------------------------------------------------- 1 | export const evaluateDocs = { 2 | name: 'evaluate', 3 | category: 'Expression', 4 | syntax: [ 5 | 'evaluate(expression)', 6 | 'evaluate(expression, scope)', 7 | 'evaluate([expr1, expr2, expr3, ...])', 8 | 'evaluate([expr1, expr2, expr3, ...], scope)' 9 | ], 10 | description: 'Evaluate an expression or an array with expressions.', 11 | examples: [ 12 | 'evaluate("2 + 3")', 13 | 'evaluate("sqrt(16)")', 14 | 'evaluate("2 inch to cm")', 15 | 'evaluate("sin(x * pi)", { "x": 1/2 })', 16 | 'evaluate(["width=2", "height=4","width*height"])' 17 | ], 18 | seealso: ['parser', 'parse', 'compile'] 19 | } 20 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/expression/help.js: -------------------------------------------------------------------------------- 1 | export const helpDocs = { 2 | name: 'help', 3 | category: 'Expression', 4 | syntax: [ 5 | 'help(object)', 6 | 'help(string)' 7 | ], 8 | description: 'Display documentation on a function or data type.', 9 | examples: [ 10 | 'help(sqrt)', 11 | 'help("complex")' 12 | ], 13 | seealso: [] 14 | } 15 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/expression/parse.js: -------------------------------------------------------------------------------- 1 | export const parseDocs = { 2 | name: 'parse', 3 | category: 'Expression', 4 | syntax: [ 5 | 'parse(expr)', 6 | 'parse(expr, options)', 7 | 'parse([expr1, expr2, expr3, ...])', 8 | 'parse([expr1, expr2, expr3, ...], options)' 9 | ], 10 | description: 'Parse an expression. Returns a node tree, which can be evaluated by invoking node.evaluate() or transformed into a functional object via node.compile().', 11 | examples: [ 12 | 'node1 = parse("sqrt(3^2 + 4^2)")', 13 | 'node1.evaluate()', 14 | 'code1 = node1.compile()', 15 | 'code1.evaluate()', 16 | 'scope = {a: 3, b: 4}', 17 | 'node2 = parse("a * b")', 18 | 'node2.evaluate(scope)', 19 | 'code2 = node2.compile()', 20 | 'code2.evaluate(scope)' 21 | ], 22 | seealso: ['parser', 'evaluate', 'compile'] 23 | } 24 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/expression/parser.js: -------------------------------------------------------------------------------- 1 | export const parserDocs = { 2 | name: 'parser', 3 | category: 'Expression', 4 | syntax: [ 5 | 'parser()' 6 | ], 7 | description: 'Create a parser object that keeps a context of variables and their values, allowing the evaluation of expressions in that context.', 8 | examples: [ 9 | 'myParser = parser()', 10 | 'myParser.evaluate("sqrt(3^2 + 4^2)")', 11 | 'myParser.set("x", 3)', 12 | 'myParser.evaluate("y = x + 3")', 13 | 'myParser.evaluate(["y = x + 3", "y = y + 1"])', 14 | 'myParser.get("y")' 15 | ], 16 | seealso: ['evaluate', 'parse', 'compile'] 17 | } 18 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/geometry/distance.js: -------------------------------------------------------------------------------- 1 | export const distanceDocs = { 2 | name: 'distance', 3 | category: 'Geometry', 4 | syntax: [ 5 | 'distance([x1, y1], [x2, y2])', 6 | 'distance([[x1, y1], [x2, y2]])' 7 | ], 8 | description: 'Calculates the Euclidean distance between two points.', 9 | examples: [ 10 | 'distance([0,0], [4,4])', 11 | 'distance([[0,0], [4,4]])' 12 | ], 13 | seealso: [] 14 | } 15 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/geometry/intersect.js: -------------------------------------------------------------------------------- 1 | export const intersectDocs = { 2 | name: 'intersect', 3 | category: 'Geometry', 4 | syntax: [ 5 | 'intersect(expr1, expr2, expr3, expr4)', 6 | 'intersect(expr1, expr2, expr3)' 7 | ], 8 | description: 'Computes the intersection point of lines and/or planes.', 9 | examples: [ 10 | 'intersect([0, 0], [10, 10], [10, 0], [0, 10])', 11 | 'intersect([1, 0, 1], [4, -2, 2], [1, 1, 1, 6])' 12 | ], 13 | seealso: [] 14 | } 15 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/logical/and.js: -------------------------------------------------------------------------------- 1 | export const andDocs = { 2 | name: 'and', 3 | category: 'Logical', 4 | syntax: [ 5 | 'x and y', 6 | 'and(x, y)' 7 | ], 8 | description: 'Logical and. Test whether two values are both defined with a nonzero/nonempty value.', 9 | examples: [ 10 | 'true and false', 11 | 'true and true', 12 | '2 and 4' 13 | ], 14 | seealso: [ 15 | 'not', 'or', 'xor' 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/logical/not.js: -------------------------------------------------------------------------------- 1 | export const notDocs = { 2 | name: 'not', 3 | category: 'Logical', 4 | syntax: [ 5 | 'not x', 6 | 'not(x)' 7 | ], 8 | description: 'Logical not. Flips the boolean value of given argument.', 9 | examples: [ 10 | 'not true', 11 | 'not false', 12 | 'not 2', 13 | 'not 0' 14 | ], 15 | seealso: [ 16 | 'and', 'or', 'xor' 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/logical/or.js: -------------------------------------------------------------------------------- 1 | export const orDocs = { 2 | name: 'or', 3 | category: 'Logical', 4 | syntax: [ 5 | 'x or y', 6 | 'or(x, y)' 7 | ], 8 | description: 'Logical or. Test if at least one value is defined with a nonzero/nonempty value.', 9 | examples: [ 10 | 'true or false', 11 | 'false or false', 12 | '0 or 4' 13 | ], 14 | seealso: [ 15 | 'not', 'and', 'xor' 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/logical/xor.js: -------------------------------------------------------------------------------- 1 | export const xorDocs = { 2 | name: 'xor', 3 | category: 'Logical', 4 | syntax: [ 5 | 'x xor y', 6 | 'xor(x, y)' 7 | ], 8 | description: 'Logical exclusive or, xor. Test whether one and only one value is defined with a nonzero/nonempty value.', 9 | examples: [ 10 | 'true xor false', 11 | 'false xor false', 12 | 'true xor true', 13 | '0 xor 4' 14 | ], 15 | seealso: [ 16 | 'not', 'and', 'or' 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/matrix/column.js: -------------------------------------------------------------------------------- 1 | export const columnDocs = { 2 | name: 'column', 3 | category: 'Matrix', 4 | syntax: [ 5 | 'column(x, index)' 6 | ], 7 | description: 'Return a column from a matrix or array.', 8 | examples: [ 9 | 'A = [[1, 2], [3, 4]]', 10 | 'column(A, 1)', 11 | 'column(A, 2)' 12 | ], 13 | seealso: ['row', 'matrixFromColumns'] 14 | } 15 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/matrix/concat.js: -------------------------------------------------------------------------------- 1 | export const concatDocs = { 2 | name: 'concat', 3 | category: 'Matrix', 4 | syntax: [ 5 | 'concat(A, B, C, ...)', 6 | 'concat(A, B, C, ..., dim)' 7 | ], 8 | description: 'Concatenate matrices. By default, the matrices are concatenated by the last dimension. The dimension on which to concatenate can be provided as last argument.', 9 | examples: [ 10 | 'A = [1, 2; 5, 6]', 11 | 'B = [3, 4; 7, 8]', 12 | 'concat(A, B)', 13 | 'concat(A, B, 1)', 14 | 'concat(A, B, 2)' 15 | ], 16 | seealso: [ 17 | 'det', 'diag', 'identity', 'inv', 'ones', 'range', 'size', 'squeeze', 'subset', 'trace', 'transpose', 'zeros' 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/matrix/count.js: -------------------------------------------------------------------------------- 1 | export const countDocs = { 2 | name: 'count', 3 | category: 'Matrix', 4 | syntax: [ 5 | 'count(x)' 6 | ], 7 | description: 'Count the number of elements of a matrix, array or string.', 8 | examples: [ 9 | 'a = [1, 2; 3, 4; 5, 6]', 10 | 'count(a)', 11 | 'size(a)', 12 | 'count("hello world")' 13 | ], 14 | seealso: [ 15 | 'size' 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/matrix/cross.js: -------------------------------------------------------------------------------- 1 | export const crossDocs = { 2 | name: 'cross', 3 | category: 'Matrix', 4 | syntax: [ 5 | 'cross(A, B)' 6 | ], 7 | description: 'Calculate the cross product for two vectors in three dimensional space.', 8 | examples: [ 9 | 'cross([1, 1, 0], [0, 1, 1])', 10 | 'cross([3, -3, 1], [4, 9, 2])', 11 | 'cross([2, 3, 4], [5, 6, 7])' 12 | ], 13 | seealso: [ 14 | 'multiply', 15 | 'dot' 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/matrix/ctranspose.js: -------------------------------------------------------------------------------- 1 | export const ctransposeDocs = { 2 | name: 'ctranspose', 3 | category: 'Matrix', 4 | syntax: [ 5 | 'x\'', 6 | 'ctranspose(x)' 7 | ], 8 | description: 'Complex Conjugate and Transpose a matrix', 9 | examples: [ 10 | 'a = [1, 2, 3; 4, 5, 6]', 11 | 'a\'', 12 | 'ctranspose(a)' 13 | ], 14 | seealso: [ 15 | 'concat', 'det', 'diag', 'identity', 'inv', 'ones', 'range', 'size', 'squeeze', 'subset', 'trace', 'zeros' 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/matrix/det.js: -------------------------------------------------------------------------------- 1 | export const detDocs = { 2 | name: 'det', 3 | category: 'Matrix', 4 | syntax: [ 5 | 'det(x)' 6 | ], 7 | description: 'Calculate the determinant of a matrix', 8 | examples: [ 9 | 'det([1, 2; 3, 4])', 10 | 'det([-2, 2, 3; -1, 1, 3; 2, 0, -1])' 11 | ], 12 | seealso: [ 13 | 'concat', 'diag', 'identity', 'inv', 'ones', 'range', 'size', 'squeeze', 'subset', 'trace', 'transpose', 'zeros' 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/matrix/diag.js: -------------------------------------------------------------------------------- 1 | export const diagDocs = { 2 | name: 'diag', 3 | category: 'Matrix', 4 | syntax: [ 5 | 'diag(x)', 6 | 'diag(x, k)' 7 | ], 8 | description: 'Create a diagonal matrix or retrieve the diagonal of a matrix. When x is a vector, a matrix with the vector values on the diagonal will be returned. When x is a matrix, a vector with the diagonal values of the matrix is returned. When k is provided, the k-th diagonal will be filled in or retrieved, if k is positive, the values are placed on the super diagonal. When k is negative, the values are placed on the sub diagonal.', 9 | examples: [ 10 | 'diag(1:3)', 11 | 'diag(1:3, 1)', 12 | 'a = [1, 2, 3; 4, 5, 6; 7, 8, 9]', 13 | 'diag(a)' 14 | ], 15 | seealso: [ 16 | 'concat', 'det', 'identity', 'inv', 'ones', 'range', 'size', 'squeeze', 'subset', 'trace', 'transpose', 'zeros' 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/matrix/dot.js: -------------------------------------------------------------------------------- 1 | export const dotDocs = { 2 | name: 'dot', 3 | category: 'Matrix', 4 | syntax: [ 5 | 'dot(A, B)', 6 | 'A * B' 7 | ], 8 | description: 'Calculate the dot product of two vectors. ' + 9 | 'The dot product of A = [a1, a2, a3, ..., an] and B = [b1, b2, b3, ..., bn] ' + 10 | 'is defined as dot(A, B) = a1 * b1 + a2 * b2 + a3 * b3 + ... + an * bn', 11 | examples: [ 12 | 'dot([2, 4, 1], [2, 2, 3])', 13 | '[2, 4, 1] * [2, 2, 3]' 14 | ], 15 | seealso: [ 16 | 'multiply', 17 | 'cross' 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/matrix/eigs.js: -------------------------------------------------------------------------------- 1 | export const eigsDocs = { 2 | name: 'eigs', 3 | category: 'Matrix', 4 | syntax: [ 5 | 'eigs(x)' 6 | ], 7 | description: 'Calculate the eigenvalues and optionally eigenvectors of a square matrix', 8 | examples: [ 9 | 'eigs([[5, 2.3], [2.3, 1]])', 10 | 'eigs([[1, 2, 3], [4, 5, 6], [7, 8, 9]], { precision: 1e-6, eigenvectors: false })' 11 | ], 12 | seealso: [ 13 | 'inv' 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/matrix/fft.js: -------------------------------------------------------------------------------- 1 | export const fftDocs = { 2 | name: 'fft', 3 | category: 'Matrix', 4 | syntax: [ 5 | 'fft(x)' 6 | ], 7 | description: 'Calculate N-dimensional Fourier transform', 8 | examples: [ 9 | 'fft([[1, 0], [1, 0]])' 10 | ], 11 | seealso: [ 12 | 'ifft' 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/matrix/filter.js: -------------------------------------------------------------------------------- 1 | export const filterDocs = { 2 | name: 'filter', 3 | category: 'Matrix', 4 | syntax: [ 5 | 'filter(x, test)' 6 | ], 7 | description: 'Filter items in a matrix.', 8 | examples: [ 9 | 'isPositive(x) = x > 0', 10 | 'filter([6, -2, -1, 4, 3], isPositive)', 11 | 'filter([6, -2, 0, 1, 0], x != 0)' 12 | ], 13 | seealso: ['sort', 'map', 'forEach'] 14 | } 15 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/matrix/flatten.js: -------------------------------------------------------------------------------- 1 | export const flattenDocs = { 2 | name: 'flatten', 3 | category: 'Matrix', 4 | syntax: [ 5 | 'flatten(x)' 6 | ], 7 | description: 'Flatten a multi dimensional matrix into a single dimensional matrix.', 8 | examples: [ 9 | 'a = [1, 2, 3; 4, 5, 6]', 10 | 'size(a)', 11 | 'b = flatten(a)', 12 | 'size(b)' 13 | ], 14 | seealso: [ 15 | 'concat', 'resize', 'size', 'squeeze' 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/matrix/forEach.js: -------------------------------------------------------------------------------- 1 | export const forEachDocs = { 2 | name: 'forEach', 3 | category: 'Matrix', 4 | syntax: [ 5 | 'forEach(x, callback)' 6 | ], 7 | description: 'Iterates over all elements of a matrix/array, and executes the given callback function.', 8 | examples: [ 9 | 'numberOfPets = {}', 10 | 'addPet(n) = numberOfPets[n] = (numberOfPets[n] ? numberOfPets[n]:0 ) + 1;', 11 | 'forEach(["Dog","Cat","Cat"], addPet)', 12 | 'numberOfPets' 13 | ], 14 | seealso: ['map', 'sort', 'filter'] 15 | } 16 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/matrix/getMatrixDataType.js: -------------------------------------------------------------------------------- 1 | export const getMatrixDataTypeDocs = { 2 | name: 'getMatrixDataType', 3 | category: 'Matrix', 4 | syntax: [ 5 | 'getMatrixDataType(x)' 6 | ], 7 | description: 'Find the data type of all elements in a matrix or array, ' + 8 | 'for example "number" if all items are a number ' + 9 | 'and "Complex" if all values are complex numbers. ' + 10 | 'If a matrix contains more than one data type, it will return "mixed".', 11 | examples: [ 12 | 'getMatrixDataType([1, 2, 3])', 13 | 'getMatrixDataType([[5 cm], [2 inch]])', 14 | 'getMatrixDataType([1, "text"])', 15 | 'getMatrixDataType([1, bignumber(4)])' 16 | ], 17 | seealso: ['matrix', 'sparse', 'typeOf'] 18 | } 19 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/matrix/identity.js: -------------------------------------------------------------------------------- 1 | export const identityDocs = { 2 | name: 'identity', 3 | category: 'Matrix', 4 | syntax: [ 5 | 'identity(n)', 6 | 'identity(m, n)', 7 | 'identity([m, n])' 8 | ], 9 | description: 'Returns the identity matrix with size m-by-n. The matrix has ones on the diagonal and zeros elsewhere.', 10 | examples: [ 11 | 'identity(3)', 12 | 'identity(3, 5)', 13 | 'a = [1, 2, 3; 4, 5, 6]', 14 | 'identity(size(a))' 15 | ], 16 | seealso: [ 17 | 'concat', 'det', 'diag', 'inv', 'ones', 'range', 'size', 'squeeze', 'subset', 'trace', 'transpose', 'zeros' 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/matrix/ifft.js: -------------------------------------------------------------------------------- 1 | export const ifftDocs = { 2 | name: 'ifft', 3 | category: 'Matrix', 4 | syntax: [ 5 | 'ifft(x)' 6 | ], 7 | description: 'Calculate N-dimensional inverse Fourier transform', 8 | examples: [ 9 | 'ifft([[2, 2], [0, 0]])' 10 | ], 11 | seealso: [ 12 | 'fft' 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/matrix/inv.js: -------------------------------------------------------------------------------- 1 | export const invDocs = { 2 | name: 'inv', 3 | category: 'Matrix', 4 | syntax: [ 5 | 'inv(x)' 6 | ], 7 | description: 'Calculate the inverse of a matrix', 8 | examples: [ 9 | 'inv([1, 2; 3, 4])', 10 | 'inv(4)', 11 | '1 / 4' 12 | ], 13 | seealso: [ 14 | 'concat', 'det', 'diag', 'identity', 'ones', 'range', 'size', 'squeeze', 'subset', 'trace', 'transpose', 'zeros' 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/matrix/kron.js: -------------------------------------------------------------------------------- 1 | export const kronDocs = { 2 | name: 'kron', 3 | category: 'Matrix', 4 | syntax: [ 5 | 'kron(x, y)' 6 | ], 7 | description: 'Calculates the Kronecker product of 2 matrices or vectors.', 8 | examples: [ 9 | 'kron([[1, 0], [0, 1]], [[1, 2], [3, 4]])', 10 | 'kron([1,1], [2,3,4])' 11 | ], 12 | seealso: [ 13 | 'multiply', 'dot', 'cross' 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/matrix/map.js: -------------------------------------------------------------------------------- 1 | export const mapDocs = { 2 | name: 'map', 3 | category: 'Matrix', 4 | syntax: [ 5 | 'map(x, callback)', 6 | 'map(x, y, ..., callback)' 7 | ], 8 | description: 'Create a new matrix or array with the results of the callback function executed on each entry of the matrix/array or the matrices/arrays.', 9 | examples: [ 10 | 'map([1, 2, 3], square)', 11 | 'map([1, 2], [3, 4], f(a,b) = a + b)' 12 | ], 13 | seealso: ['filter', 'forEach'] 14 | } 15 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/matrix/mapSlices.js: -------------------------------------------------------------------------------- 1 | export const mapSlicesDocs = { 2 | name: 'mapSlices', 3 | category: 'Matrix', 4 | syntax: ['mapSlices(A, dim, callback)'], 5 | description: 6 | 'Generate a matrix one dimension less than A by applying callback to ' + 7 | 'each slice of A along dimension dim.', 8 | examples: [ 9 | 'A = [[1, 2], [3, 4]]', 10 | 'mapSlices(A, 1, sum)', // returns [4, 6] 11 | 'mapSlices(A, 2, prod)' // returns [2, 12] 12 | ], 13 | seealso: ['map', 'forEach'] 14 | } 15 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/matrix/matrixFromColumns.js: -------------------------------------------------------------------------------- 1 | export const matrixFromColumnsDocs = { 2 | name: 'matrixFromColumns', 3 | category: 'Matrix', 4 | syntax: [ 5 | 'matrixFromColumns(...arr)', 6 | 'matrixFromColumns(row1, row2)', 7 | 'matrixFromColumns(row1, row2, row3)' 8 | ], 9 | description: 'Create a dense matrix from vectors as individual columns.', 10 | examples: [ 11 | 'matrixFromColumns([1, 2, 3], [[4],[5],[6]])' 12 | ], 13 | seealso: [ 14 | 'matrix', 'matrixFromRows', 'matrixFromFunction', 'zeros' 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/matrix/matrixFromFunction.js: -------------------------------------------------------------------------------- 1 | export const matrixFromFunctionDocs = { 2 | name: 'matrixFromFunction', 3 | category: 'Matrix', 4 | syntax: [ 5 | 'matrixFromFunction(size, fn)', 6 | 'matrixFromFunction(size, fn, format)', 7 | 'matrixFromFunction(size, fn, format, datatype)', 8 | 'matrixFromFunction(size, format, fn)', 9 | 'matrixFromFunction(size, format, datatype, fn)' 10 | ], 11 | description: 'Create a matrix by evaluating a generating function at each index.', 12 | examples: [ 13 | 'f(I) = I[1] - I[2]', 14 | 'matrixFromFunction([3,3], f)', 15 | 'g(I) = I[1] - I[2] == 1 ? 4 : 0', 16 | 'matrixFromFunction([100, 100], "sparse", g)', 17 | 'matrixFromFunction([5], random)' 18 | ], 19 | seealso: [ 20 | 'matrix', 'matrixFromRows', 'matrixFromColumns', 'zeros' 21 | ] 22 | } 23 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/matrix/matrixFromRows.js: -------------------------------------------------------------------------------- 1 | export const matrixFromRowsDocs = { 2 | name: 'matrixFromRows', 3 | category: 'Matrix', 4 | syntax: [ 5 | 'matrixFromRows(...arr)', 6 | 'matrixFromRows(row1, row2)', 7 | 'matrixFromRows(row1, row2, row3)' 8 | ], 9 | description: 'Create a dense matrix from vectors as individual rows.', 10 | examples: [ 11 | 'matrixFromRows([1, 2, 3], [[4],[5],[6]])' 12 | ], 13 | seealso: [ 14 | 'matrix', 'matrixFromColumns', 'matrixFromFunction', 'zeros' 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/matrix/ones.js: -------------------------------------------------------------------------------- 1 | export const onesDocs = { 2 | name: 'ones', 3 | category: 'Matrix', 4 | syntax: [ 5 | 'ones(m)', 6 | 'ones(m, n)', 7 | 'ones(m, n, p, ...)', 8 | 'ones([m])', 9 | 'ones([m, n])', 10 | 'ones([m, n, p, ...])' 11 | ], 12 | description: 'Create a matrix containing ones.', 13 | examples: [ 14 | 'ones(3)', 15 | 'ones(3, 5)', 16 | 'ones([2,3]) * 4.5', 17 | 'a = [1, 2, 3; 4, 5, 6]', 18 | 'ones(size(a))' 19 | ], 20 | seealso: [ 21 | 'concat', 'det', 'diag', 'identity', 'inv', 'range', 'size', 'squeeze', 'subset', 'trace', 'transpose', 'zeros' 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/matrix/partitionSelect.js: -------------------------------------------------------------------------------- 1 | export const partitionSelectDocs = { 2 | name: 'partitionSelect', 3 | category: 'Matrix', 4 | syntax: [ 5 | 'partitionSelect(x, k)', 6 | 'partitionSelect(x, k, compare)' 7 | ], 8 | description: 'Partition-based selection of an array or 1D matrix. Will find the kth smallest value, and mutates the input array. Uses Quickselect.', 9 | examples: [ 10 | 'partitionSelect([5, 10, 1], 2)', 11 | 'partitionSelect(["C", "B", "A", "D"], 1, compareText)', 12 | 'arr = [5, 2, 1]', 13 | 'partitionSelect(arr, 0) # returns 1, arr is now: [1, 2, 5]', 14 | 'arr', 15 | 'partitionSelect(arr, 1, \'desc\') # returns 2, arr is now: [5, 2, 1]', 16 | 'arr' 17 | ], 18 | seealso: ['sort'] 19 | } 20 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/matrix/pinv.js: -------------------------------------------------------------------------------- 1 | export const pinvDocs = { 2 | name: 'pinv', 3 | category: 'Matrix', 4 | syntax: [ 5 | 'pinv(x)' 6 | ], 7 | description: 'Calculate the Moore–Penrose inverse of a matrix', 8 | examples: [ 9 | 'pinv([1, 2; 3, 4])', 10 | 'pinv([[1, 0], [0, 1], [0, 1]])', 11 | 'pinv(4)' 12 | ], 13 | seealso: [ 14 | 'inv' 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/matrix/range.js: -------------------------------------------------------------------------------- 1 | export const rangeDocs = { 2 | name: 'range', 3 | category: 'Type', 4 | syntax: [ 5 | 'start:end', 6 | 'start:step:end', 7 | 'range(start, end)', 8 | 'range(start, end, step)', 9 | 'range(string)' 10 | ], 11 | description: 12 | 'Create a range. Lower bound of the range is included, upper bound is excluded.', 13 | examples: [ 14 | '1:5', 15 | '3:-1:-3', 16 | 'range(3, 7)', 17 | 'range(0, 12, 2)', 18 | 'range("4:10")', 19 | 'range(1m, 1m, 3m)', 20 | 'a = [1, 2, 3, 4; 5, 6, 7, 8]', 21 | 'a[1:2, 1:2]' 22 | ], 23 | seealso: [ 24 | 'concat', 'det', 'diag', 'identity', 'inv', 'ones', 'size', 'squeeze', 'subset', 'trace', 'transpose', 'zeros' 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/matrix/reshape.js: -------------------------------------------------------------------------------- 1 | export const reshapeDocs = { 2 | name: 'reshape', 3 | category: 'Matrix', 4 | syntax: [ 5 | 'reshape(x, sizes)' 6 | ], 7 | description: 'Reshape a multi dimensional array to fit the specified dimensions.', 8 | examples: [ 9 | 'reshape([1, 2, 3, 4, 5, 6], [2, 3])', 10 | 'reshape([[1, 2], [3, 4]], [1, 4])', 11 | 'reshape([[1, 2], [3, 4]], [4])', 12 | 'reshape([1, 2, 3, 4], [-1, 2])' 13 | ], 14 | seealso: [ 15 | 'size', 'squeeze', 'resize' 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/matrix/resize.js: -------------------------------------------------------------------------------- 1 | export const resizeDocs = { 2 | name: 'resize', 3 | category: 'Matrix', 4 | syntax: [ 5 | 'resize(x, size)', 6 | 'resize(x, size, defaultValue)' 7 | ], 8 | description: 'Resize a matrix.', 9 | examples: [ 10 | 'resize([1,2,3,4,5], [3])', 11 | 'resize([1,2,3], [5])', 12 | 'resize([1,2,3], [5], -1)', 13 | 'resize(2, [2, 3])', 14 | 'resize("hello", [8], "!")' 15 | ], 16 | seealso: [ 17 | 'size', 'subset', 'squeeze', 'reshape' 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/matrix/rotate.js: -------------------------------------------------------------------------------- 1 | export const rotateDocs = { 2 | name: 'rotate', 3 | category: 'Matrix', 4 | syntax: [ 5 | 'rotate(w, theta)', 6 | 'rotate(w, theta, v)' 7 | ], 8 | description: 'Returns a 2-D rotation matrix (2x2) for a given angle (in radians). ' + 9 | 'Returns a 2-D rotation matrix (3x3) of a given angle (in radians) around given axis.', 10 | examples: [ 11 | 'rotate([1, 0], pi / 2)', 12 | 'rotate(matrix([1, 0]), unit("35deg"))', 13 | 'rotate([1, 0, 0], unit("90deg"), [0, 0, 1])', 14 | 'rotate(matrix([1, 0, 0]), unit("90deg"), matrix([0, 0, 1]))' 15 | ], 16 | seealso: [ 17 | 'matrix', 'rotationMatrix' 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/matrix/rotationMatrix.js: -------------------------------------------------------------------------------- 1 | export const rotationMatrixDocs = { 2 | name: 'rotationMatrix', 3 | category: 'Matrix', 4 | syntax: [ 5 | 'rotationMatrix(theta)', 6 | 'rotationMatrix(theta, v)', 7 | 'rotationMatrix(theta, v, format)' 8 | ], 9 | description: 'Returns a 2-D rotation matrix (2x2) for a given angle (in radians). ' + 10 | 'Returns a 2-D rotation matrix (3x3) of a given angle (in radians) around given axis.', 11 | examples: [ 12 | 'rotationMatrix(pi / 2)', 13 | 'rotationMatrix(unit("45deg"), [0, 0, 1])', 14 | 'rotationMatrix(1, matrix([0, 0, 1]), "sparse")' 15 | ], 16 | seealso: [ 17 | 'cos', 'sin' 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/matrix/row.js: -------------------------------------------------------------------------------- 1 | export const rowDocs = { 2 | name: 'row', 3 | category: 'Matrix', 4 | syntax: [ 5 | 'row(x, index)' 6 | ], 7 | description: 'Return a row from a matrix or array.', 8 | examples: [ 9 | 'A = [[1, 2], [3, 4]]', 10 | 'row(A, 1)', 11 | 'row(A, 2)' 12 | ], 13 | seealso: ['column', 'matrixFromRows'] 14 | } 15 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/matrix/size.js: -------------------------------------------------------------------------------- 1 | export const sizeDocs = { 2 | name: 'size', 3 | category: 'Matrix', 4 | syntax: [ 5 | 'size(x)' 6 | ], 7 | description: 'Calculate the size of a matrix.', 8 | examples: [ 9 | 'size(2.3)', 10 | 'size("hello world")', 11 | 'a = [1, 2; 3, 4; 5, 6]', 12 | 'size(a)', 13 | 'size(1:6)' 14 | ], 15 | seealso: [ 16 | 'concat', 'count', 'det', 'diag', 'identity', 'inv', 'ones', 'range', 'squeeze', 'subset', 'trace', 'transpose', 'zeros' 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/matrix/sort.js: -------------------------------------------------------------------------------- 1 | export const sortDocs = { 2 | name: 'sort', 3 | category: 'Matrix', 4 | syntax: [ 5 | 'sort(x)', 6 | 'sort(x, compare)' 7 | ], 8 | description: 'Sort the items in a matrix. Compare can be a string "asc", "desc", "natural", or a custom sort function.', 9 | examples: [ 10 | 'sort([5, 10, 1])', 11 | 'sort(["C", "B", "A", "D"], "natural")', 12 | 'sortByLength(a, b) = size(a)[1] - size(b)[1]', 13 | 'sort(["Langdon", "Tom", "Sara"], sortByLength)', 14 | 'sort(["10", "1", "2"], "natural")' 15 | ], 16 | seealso: ['map', 'filter', 'forEach'] 17 | } 18 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/matrix/squeeze.js: -------------------------------------------------------------------------------- 1 | export const squeezeDocs = { 2 | name: 'squeeze', 3 | category: 'Matrix', 4 | syntax: [ 5 | 'squeeze(x)' 6 | ], 7 | description: 'Remove inner and outer singleton dimensions from a matrix.', 8 | examples: [ 9 | 'a = zeros(3,2,1)', 10 | 'size(squeeze(a))', 11 | 'b = zeros(1,1,3)', 12 | 'size(squeeze(b))' 13 | ], 14 | seealso: [ 15 | 'concat', 'det', 'diag', 'identity', 'inv', 'ones', 'range', 'size', 'subset', 'trace', 'transpose', 'zeros' 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/matrix/trace.js: -------------------------------------------------------------------------------- 1 | export const traceDocs = { 2 | name: 'trace', 3 | category: 'Matrix', 4 | syntax: [ 5 | 'trace(A)' 6 | ], 7 | description: 'Calculate the trace of a matrix: the sum of the elements on the main diagonal of a square matrix.', 8 | examples: [ 9 | 'A = [1, 2, 3; -1, 2, 3; 2, 0, 3]', 10 | 'trace(A)' 11 | ], 12 | seealso: [ 13 | 'concat', 'det', 'diag', 'identity', 'inv', 'ones', 'range', 'size', 'squeeze', 'subset', 'transpose', 'zeros' 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/matrix/transpose.js: -------------------------------------------------------------------------------- 1 | export const transposeDocs = { 2 | name: 'transpose', 3 | category: 'Matrix', 4 | syntax: [ 5 | 'x\'', 6 | 'transpose(x)' 7 | ], 8 | description: 'Transpose a matrix', 9 | examples: [ 10 | 'a = [1, 2, 3; 4, 5, 6]', 11 | 'a\'', 12 | 'transpose(a)' 13 | ], 14 | seealso: [ 15 | 'concat', 'det', 'diag', 'identity', 'inv', 'ones', 'range', 'size', 'squeeze', 'subset', 'trace', 'zeros' 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/matrix/zeros.js: -------------------------------------------------------------------------------- 1 | export const zerosDocs = { 2 | name: 'zeros', 3 | category: 'Matrix', 4 | syntax: [ 5 | 'zeros(m)', 6 | 'zeros(m, n)', 7 | 'zeros(m, n, p, ...)', 8 | 'zeros([m])', 9 | 'zeros([m, n])', 10 | 'zeros([m, n, p, ...])' 11 | ], 12 | description: 'Create a matrix containing zeros.', 13 | examples: [ 14 | 'zeros(3)', 15 | 'zeros(3, 5)', 16 | 'a = [1, 2, 3; 4, 5, 6]', 17 | 'zeros(size(a))' 18 | ], 19 | seealso: [ 20 | 'concat', 'det', 'diag', 'identity', 'inv', 'ones', 'range', 'size', 'squeeze', 'subset', 'trace', 'transpose' 21 | ] 22 | } 23 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/numeric/solveODE.js: -------------------------------------------------------------------------------- 1 | export const solveODEDocs = { 2 | name: 'solveODE', 3 | category: 'Numeric', 4 | syntax: [ 5 | 'solveODE(func, tspan, y0)', 6 | 'solveODE(func, tspan, y0, options)' 7 | ], 8 | description: 'Numerical Integration of Ordinary Differential Equations.', 9 | examples: [ 10 | 'f(t,y) = y', 11 | 'tspan = [0, 4]', 12 | 'solveODE(f, tspan, 1)', 13 | 'solveODE(f, tspan, [1, 2])', 14 | 'solveODE(f, tspan, 1, { method:"RK23", maxStep:0.1 })' 15 | ], 16 | seealso: ['derivative', 'simplifyCore'] 17 | } 18 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/probability/combinations.js: -------------------------------------------------------------------------------- 1 | export const combinationsDocs = { 2 | name: 'combinations', 3 | category: 'Probability', 4 | syntax: [ 5 | 'combinations(n, k)' 6 | ], 7 | description: 'Compute the number of combinations of n items taken k at a time', 8 | examples: [ 9 | 'combinations(7, 5)' 10 | ], 11 | seealso: ['combinationsWithRep', 'permutations', 'factorial'] 12 | } 13 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/probability/combinationsWithRep.js: -------------------------------------------------------------------------------- 1 | export const combinationsWithRepDocs = { 2 | name: 'combinationsWithRep', 3 | category: 'Probability', 4 | syntax: [ 5 | 'combinationsWithRep(n, k)' 6 | ], 7 | description: 'Compute the number of combinations of n items taken k at a time with replacements.', 8 | examples: [ 9 | 'combinationsWithRep(7, 5)' 10 | ], 11 | seealso: ['combinations', 'permutations', 'factorial'] 12 | } 13 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/probability/distribution.js: -------------------------------------------------------------------------------- 1 | export const distributionDocs = { 2 | name: 'distribution', 3 | category: 'Probability', 4 | syntax: [ 5 | 'distribution(name)', 6 | 'distribution(name, arg1, arg2, ...)' 7 | ], 8 | description: 9 | 'Create a distribution object of a specific type. ' + 10 | 'A distribution object contains functions `random([size,] [min,] [max])`, ' + 11 | '`randomInt([size,] [min,] [max])` and `pickRandom(array)`. ' + 12 | 'Available types of distributions: "uniform", "normal". ' + 13 | 'Note that the function distribution is currently not available via the expression parser.', 14 | examples: [ 15 | ], 16 | seealso: ['random', 'randomInt'] 17 | } 18 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/probability/factorial.js: -------------------------------------------------------------------------------- 1 | export const factorialDocs = { 2 | name: 'factorial', 3 | category: 'Probability', 4 | syntax: [ 5 | 'n!', 6 | 'factorial(n)' 7 | ], 8 | description: 'Compute the factorial of a value', 9 | examples: [ 10 | '5!', 11 | '5 * 4 * 3 * 2 * 1', 12 | '3!' 13 | ], 14 | seealso: ['combinations', 'combinationsWithRep', 'permutations', 'gamma'] 15 | } 16 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/probability/gamma.js: -------------------------------------------------------------------------------- 1 | export const gammaDocs = { 2 | name: 'gamma', 3 | category: 'Probability', 4 | syntax: [ 5 | 'gamma(n)' 6 | ], 7 | description: 'Compute the gamma function. For small values, the Lanczos approximation is used, and for large values the extended Stirling approximation.', 8 | examples: [ 9 | 'gamma(4)', 10 | '3!', 11 | 'gamma(1/2)', 12 | 'sqrt(pi)' 13 | ], 14 | seealso: ['factorial'] 15 | } 16 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/probability/kldivergence.js: -------------------------------------------------------------------------------- 1 | export const kldivergenceDocs = { 2 | name: 'kldivergence', 3 | category: 'Probability', 4 | syntax: [ 5 | 'kldivergence(x, y)' 6 | ], 7 | description: 'Calculate the Kullback-Leibler (KL) divergence between two distributions.', 8 | examples: [ 9 | 'kldivergence([0.7,0.5,0.4], [0.2,0.9,0.5])' 10 | ], 11 | seealso: [] 12 | } 13 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/probability/lgamma.js: -------------------------------------------------------------------------------- 1 | export const lgammaDocs = { 2 | name: 'lgamma', 3 | category: 'Probability', 4 | syntax: ['lgamma(n)'], 5 | description: 6 | 'Logarithm of the gamma function for real, positive numbers and complex numbers, ' + 7 | 'using Lanczos approximation for numbers and Stirling series for complex numbers.', 8 | examples: [ 9 | 'lgamma(4)', 10 | 'lgamma(1/2)', 11 | 'lgamma(i)', 12 | 'lgamma(complex(1.1, 2))' 13 | ], 14 | seealso: ['gamma'] 15 | } 16 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/probability/multinomial.js: -------------------------------------------------------------------------------- 1 | export const multinomialDocs = { 2 | name: 'multinomial', 3 | category: 'Probability', 4 | syntax: [ 5 | 'multinomial(A)' 6 | ], 7 | description: 'Multinomial Coefficients compute the number of ways of picking a1, a2, ..., ai unordered outcomes from `n` possibilities. multinomial takes one array of integers as an argument. The following condition must be enforced: every ai > 0.', 8 | examples: [ 9 | 'multinomial([1, 2, 1])' 10 | ], 11 | seealso: ['combinations', 'factorial'] 12 | } 13 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/probability/permutations.js: -------------------------------------------------------------------------------- 1 | export const permutationsDocs = { 2 | name: 'permutations', 3 | category: 'Probability', 4 | syntax: [ 5 | 'permutations(n)', 6 | 'permutations(n, k)' 7 | ], 8 | description: 'Compute the number of permutations of n items taken k at a time', 9 | examples: [ 10 | 'permutations(5)', 11 | 'permutations(5, 3)' 12 | ], 13 | seealso: ['combinations', 'combinationsWithRep', 'factorial'] 14 | } 15 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/probability/pickRandom.js: -------------------------------------------------------------------------------- 1 | export const pickRandomDocs = { 2 | name: 'pickRandom', 3 | category: 'Probability', 4 | syntax: [ 5 | 'pickRandom(array)', 6 | 'pickRandom(array, number)', 7 | 'pickRandom(array, weights)', 8 | 'pickRandom(array, number, weights)', 9 | 'pickRandom(array, weights, number)' 10 | ], 11 | description: 12 | 'Pick a random entry from a given array.', 13 | examples: [ 14 | 'pickRandom(0:10)', 15 | 'pickRandom([1, 3, 1, 6])', 16 | 'pickRandom([1, 3, 1, 6], 2)', 17 | 'pickRandom([1, 3, 1, 6], [2, 3, 2, 1])', 18 | 'pickRandom([1, 3, 1, 6], 2, [2, 3, 2, 1])', 19 | 'pickRandom([1, 3, 1, 6], [2, 3, 2, 1], 2)' 20 | ], 21 | seealso: ['random', 'randomInt'] 22 | } 23 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/probability/random.js: -------------------------------------------------------------------------------- 1 | export const randomDocs = { 2 | name: 'random', 3 | category: 'Probability', 4 | syntax: [ 5 | 'random()', 6 | 'random(max)', 7 | 'random(min, max)', 8 | 'random(size)', 9 | 'random(size, max)', 10 | 'random(size, min, max)' 11 | ], 12 | description: 13 | 'Return a random number.', 14 | examples: [ 15 | 'random()', 16 | 'random(10, 20)', 17 | 'random([2, 3])' 18 | ], 19 | seealso: ['pickRandom', 'randomInt'] 20 | } 21 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/probability/randomInt.js: -------------------------------------------------------------------------------- 1 | export const randomIntDocs = { 2 | name: 'randomInt', 3 | category: 'Probability', 4 | syntax: [ 5 | 'randomInt(max)', 6 | 'randomInt(min, max)', 7 | 'randomInt(size)', 8 | 'randomInt(size, max)', 9 | 'randomInt(size, min, max)' 10 | ], 11 | description: 12 | 'Return a random integer number', 13 | examples: [ 14 | 'randomInt(10, 20)', 15 | 'randomInt([2, 3], 10)' 16 | ], 17 | seealso: ['pickRandom', 'random'] 18 | } 19 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/relational/compare.js: -------------------------------------------------------------------------------- 1 | export const compareDocs = { 2 | name: 'compare', 3 | category: 'Relational', 4 | syntax: [ 5 | 'compare(x, y)' 6 | ], 7 | description: 8 | 'Compare two values. ' + 9 | 'Returns 1 when x > y, -1 when x < y, and 0 when x == y.', 10 | examples: [ 11 | 'compare(2, 3)', 12 | 'compare(3, 2)', 13 | 'compare(2, 2)', 14 | 'compare(5cm, 40mm)', 15 | 'compare(2, [1, 2, 3])' 16 | ], 17 | seealso: [ 18 | 'equal', 'unequal', 'smaller', 'smallerEq', 'largerEq', 'compareNatural', 'compareText' 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/relational/compareNatural.js: -------------------------------------------------------------------------------- 1 | export const compareNaturalDocs = { 2 | name: 'compareNatural', 3 | category: 'Relational', 4 | syntax: [ 5 | 'compareNatural(x, y)' 6 | ], 7 | description: 8 | 'Compare two values of any type in a deterministic, natural way. ' + 9 | 'Returns 1 when x > y, -1 when x < y, and 0 when x == y.', 10 | examples: [ 11 | 'compareNatural(2, 3)', 12 | 'compareNatural(3, 2)', 13 | 'compareNatural(2, 2)', 14 | 'compareNatural(5cm, 40mm)', 15 | 'compareNatural("2", "10")', 16 | 'compareNatural(2 + 3i, 2 + 4i)', 17 | 'compareNatural([1, 2, 4], [1, 2, 3])', 18 | 'compareNatural([1, 5], [1, 2, 3])', 19 | 'compareNatural([1, 2], [1, 2])', 20 | 'compareNatural({a: 2}, {a: 4})' 21 | ], 22 | seealso: [ 23 | 'equal', 'unequal', 'smaller', 'smallerEq', 'largerEq', 'compare', 'compareText' 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/relational/compareText.js: -------------------------------------------------------------------------------- 1 | export const compareTextDocs = { 2 | name: 'compareText', 3 | category: 'Relational', 4 | syntax: [ 5 | 'compareText(x, y)' 6 | ], 7 | description: 8 | 'Compare two strings lexically. Comparison is case sensitive. ' + 9 | 'Returns 1 when x > y, -1 when x < y, and 0 when x == y.', 10 | examples: [ 11 | 'compareText("B", "A")', 12 | 'compareText("A", "B")', 13 | 'compareText("A", "A")', 14 | 'compareText("2", "10")', 15 | 'compare("2", "10")', 16 | 'compare(2, 10)', 17 | 'compareNatural("2", "10")', 18 | 'compareText("B", ["A", "B", "C"])' 19 | ], 20 | seealso: [ 21 | 'compare', 'compareNatural' 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/relational/deepEqual.js: -------------------------------------------------------------------------------- 1 | export const deepEqualDocs = { 2 | name: 'deepEqual', 3 | category: 'Relational', 4 | syntax: [ 5 | 'deepEqual(x, y)' 6 | ], 7 | description: 8 | 'Check equality of two matrices element wise. Returns true if the size of both matrices is equal and when and each of the elements are equal.', 9 | examples: [ 10 | 'deepEqual([1,3,4], [1,3,4])', 11 | 'deepEqual([1,3,4], [1,3])' 12 | ], 13 | seealso: [ 14 | 'equal', 'unequal', 'smaller', 'larger', 'smallerEq', 'largerEq', 'compare' 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/relational/equal.js: -------------------------------------------------------------------------------- 1 | export const equalDocs = { 2 | name: 'equal', 3 | category: 'Relational', 4 | syntax: [ 5 | 'x == y', 6 | 'equal(x, y)' 7 | ], 8 | description: 9 | 'Check equality of two values. Returns true if the values are equal, and false if not.', 10 | examples: [ 11 | '2+2 == 3', 12 | '2+2 == 4', 13 | 'a = 3.2', 14 | 'b = 6-2.8', 15 | 'a == b', 16 | '50cm == 0.5m' 17 | ], 18 | seealso: [ 19 | 'unequal', 'smaller', 'larger', 'smallerEq', 'largerEq', 'compare', 'deepEqual', 'equalText' 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/relational/equalText.js: -------------------------------------------------------------------------------- 1 | export const equalTextDocs = { 2 | name: 'equalText', 3 | category: 'Relational', 4 | syntax: [ 5 | 'equalText(x, y)' 6 | ], 7 | description: 8 | 'Check equality of two strings. Comparison is case sensitive. Returns true if the values are equal, and false if not.', 9 | examples: [ 10 | 'equalText("Hello", "Hello")', 11 | 'equalText("a", "A")', 12 | 'equal("2e3", "2000")', 13 | 'equalText("2e3", "2000")', 14 | 'equalText("B", ["A", "B", "C"])' 15 | ], 16 | seealso: [ 17 | 'compare', 'compareNatural', 'compareText', 'equal' 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/relational/larger.js: -------------------------------------------------------------------------------- 1 | export const largerDocs = { 2 | name: 'larger', 3 | category: 'Relational', 4 | syntax: [ 5 | 'x > y', 6 | 'larger(x, y)' 7 | ], 8 | description: 9 | 'Check if value x is larger than y. Returns true if x is larger than y, and false if not. Comparing a value with NaN returns false.', 10 | examples: [ 11 | '2 > 3', 12 | '5 > 2*2', 13 | 'a = 3.3', 14 | 'b = 6-2.8', 15 | '(a > b)', 16 | '(b < a)', 17 | '5 cm > 2 inch' 18 | ], 19 | seealso: [ 20 | 'equal', 'unequal', 'smaller', 'smallerEq', 'largerEq', 'compare' 21 | ] 22 | } 23 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/relational/largerEq.js: -------------------------------------------------------------------------------- 1 | export const largerEqDocs = { 2 | name: 'largerEq', 3 | category: 'Relational', 4 | syntax: [ 5 | 'x >= y', 6 | 'largerEq(x, y)' 7 | ], 8 | description: 9 | 'Check if value x is larger or equal to y. Returns true if x is larger or equal to y, and false if not.', 10 | examples: [ 11 | '2 >= 1+1', 12 | '2 > 1+1', 13 | 'a = 3.2', 14 | 'b = 6-2.8', 15 | '(a >= b)' 16 | ], 17 | seealso: [ 18 | 'equal', 'unequal', 'smallerEq', 'smaller', 'compare' 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/relational/smaller.js: -------------------------------------------------------------------------------- 1 | export const smallerDocs = { 2 | name: 'smaller', 3 | category: 'Relational', 4 | syntax: [ 5 | 'x < y', 6 | 'smaller(x, y)' 7 | ], 8 | description: 9 | 'Check if value x is smaller than value y. Returns true if x is smaller than y, and false if not. Comparing a value with NaN returns false.', 10 | examples: [ 11 | '2 < 3', 12 | '5 < 2*2', 13 | 'a = 3.3', 14 | 'b = 6-2.8', 15 | '(a < b)', 16 | '5 cm < 2 inch' 17 | ], 18 | seealso: [ 19 | 'equal', 'unequal', 'larger', 'smallerEq', 'largerEq', 'compare' 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/relational/smallerEq.js: -------------------------------------------------------------------------------- 1 | export const smallerEqDocs = { 2 | name: 'smallerEq', 3 | category: 'Relational', 4 | syntax: [ 5 | 'x <= y', 6 | 'smallerEq(x, y)' 7 | ], 8 | description: 9 | 'Check if value x is smaller or equal to value y. Returns true if x is smaller than y, and false if not.', 10 | examples: [ 11 | '2 <= 1+1', 12 | '2 < 1+1', 13 | 'a = 3.2', 14 | 'b = 6-2.8', 15 | '(a <= b)' 16 | ], 17 | seealso: [ 18 | 'equal', 'unequal', 'larger', 'smaller', 'largerEq', 'compare' 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/relational/unequal.js: -------------------------------------------------------------------------------- 1 | export const unequalDocs = { 2 | name: 'unequal', 3 | category: 'Relational', 4 | syntax: [ 5 | 'x != y', 6 | 'unequal(x, y)' 7 | ], 8 | description: 9 | 'Check unequality of two values. Returns true if the values are unequal, and false if they are equal.', 10 | examples: [ 11 | '2+2 != 3', 12 | '2+2 != 4', 13 | 'a = 3.2', 14 | 'b = 6-2.8', 15 | 'a != b', 16 | '50cm != 0.5m', 17 | '5 cm != 2 inch' 18 | ], 19 | seealso: [ 20 | 'equal', 'smaller', 'larger', 'smallerEq', 'largerEq', 'compare', 'deepEqual' 21 | ] 22 | } 23 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/set/setCartesian.js: -------------------------------------------------------------------------------- 1 | export const setCartesianDocs = { 2 | name: 'setCartesian', 3 | category: 'Set', 4 | syntax: [ 5 | 'setCartesian(set1, set2)' 6 | ], 7 | description: 8 | 'Create the cartesian product of two (multi)sets. Multi-dimension arrays will be converted to single-dimension arrays and the values will be sorted in ascending order before the operation.', 9 | examples: [ 10 | 'setCartesian([1, 2], [3, 4])' 11 | ], 12 | seealso: [ 13 | 'setUnion', 'setIntersect', 'setDifference', 'setPowerset' 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/set/setDifference.js: -------------------------------------------------------------------------------- 1 | export const setDifferenceDocs = { 2 | name: 'setDifference', 3 | category: 'Set', 4 | syntax: [ 5 | 'setDifference(set1, set2)' 6 | ], 7 | description: 8 | 'Create the difference of two (multi)sets: every element of set1, that is not the element of set2. Multi-dimension arrays will be converted to single-dimension arrays before the operation.', 9 | examples: [ 10 | 'setDifference([1, 2, 3, 4], [3, 4, 5, 6])', 11 | 'setDifference([[1, 2], [3, 4]], [[3, 4], [5, 6]])' 12 | ], 13 | seealso: [ 14 | 'setUnion', 'setIntersect', 'setSymDifference' 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/set/setDistinct.js: -------------------------------------------------------------------------------- 1 | export const setDistinctDocs = { 2 | name: 'setDistinct', 3 | category: 'Set', 4 | syntax: [ 5 | 'setDistinct(set)' 6 | ], 7 | description: 8 | 'Collect the distinct elements of a multiset. A multi-dimension array will be converted to a single-dimension array before the operation.', 9 | examples: [ 10 | 'setDistinct([1, 1, 1, 2, 2, 3])' 11 | ], 12 | seealso: [ 13 | 'setMultiplicity' 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/set/setIntersect.js: -------------------------------------------------------------------------------- 1 | export const setIntersectDocs = { 2 | name: 'setIntersect', 3 | category: 'Set', 4 | syntax: [ 5 | 'setIntersect(set1, set2)' 6 | ], 7 | description: 8 | 'Create the intersection of two (multi)sets. Multi-dimension arrays will be converted to single-dimension arrays before the operation.', 9 | examples: [ 10 | 'setIntersect([1, 2, 3, 4], [3, 4, 5, 6])', 11 | 'setIntersect([[1, 2], [3, 4]], [[3, 4], [5, 6]])' 12 | ], 13 | seealso: [ 14 | 'setUnion', 'setDifference' 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/set/setIsSubset.js: -------------------------------------------------------------------------------- 1 | export const setIsSubsetDocs = { 2 | name: 'setIsSubset', 3 | category: 'Set', 4 | syntax: [ 5 | 'setIsSubset(set1, set2)' 6 | ], 7 | description: 8 | 'Check whether a (multi)set is a subset of another (multi)set: every element of set1 is the element of set2. Multi-dimension arrays will be converted to single-dimension arrays before the operation.', 9 | examples: [ 10 | 'setIsSubset([1, 2], [3, 4, 5, 6])', 11 | 'setIsSubset([3, 4], [3, 4, 5, 6])' 12 | ], 13 | seealso: [ 14 | 'setUnion', 'setIntersect', 'setDifference' 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/set/setMultiplicity.js: -------------------------------------------------------------------------------- 1 | export const setMultiplicityDocs = { 2 | name: 'setMultiplicity', 3 | category: 'Set', 4 | syntax: [ 5 | 'setMultiplicity(element, set)' 6 | ], 7 | description: 8 | 'Count the multiplicity of an element in a multiset. A multi-dimension array will be converted to a single-dimension array before the operation.', 9 | examples: [ 10 | 'setMultiplicity(1, [1, 2, 2, 4])', 11 | 'setMultiplicity(2, [1, 2, 2, 4])' 12 | ], 13 | seealso: [ 14 | 'setDistinct', 'setSize' 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/set/setPowerset.js: -------------------------------------------------------------------------------- 1 | export const setPowersetDocs = { 2 | name: 'setPowerset', 3 | category: 'Set', 4 | syntax: [ 5 | 'setPowerset(set)' 6 | ], 7 | description: 8 | 'Create the powerset of a (multi)set: the powerset contains very possible subsets of a (multi)set. A multi-dimension array will be converted to a single-dimension array before the operation.', 9 | examples: [ 10 | 'setPowerset([1, 2, 3])' 11 | ], 12 | seealso: [ 13 | 'setCartesian' 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/set/setSize.js: -------------------------------------------------------------------------------- 1 | export const setSizeDocs = { 2 | name: 'setSize', 3 | category: 'Set', 4 | syntax: [ 5 | 'setSize(set)', 6 | 'setSize(set, unique)' 7 | ], 8 | description: 9 | 'Count the number of elements of a (multi)set. When the second parameter "unique" is true, count only the unique values. A multi-dimension array will be converted to a single-dimension array before the operation.', 10 | examples: [ 11 | 'setSize([1, 2, 2, 4])', 12 | 'setSize([1, 2, 2, 4], true)' 13 | ], 14 | seealso: [ 15 | 'setUnion', 'setIntersect', 'setDifference' 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/set/setSymDifference.js: -------------------------------------------------------------------------------- 1 | export const setSymDifferenceDocs = { 2 | name: 'setSymDifference', 3 | category: 'Set', 4 | syntax: [ 5 | 'setSymDifference(set1, set2)' 6 | ], 7 | description: 8 | 'Create the symmetric difference of two (multi)sets. Multi-dimension arrays will be converted to single-dimension arrays before the operation.', 9 | examples: [ 10 | 'setSymDifference([1, 2, 3, 4], [3, 4, 5, 6])', 11 | 'setSymDifference([[1, 2], [3, 4]], [[3, 4], [5, 6]])' 12 | ], 13 | seealso: [ 14 | 'setUnion', 'setIntersect', 'setDifference' 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/set/setUnion.js: -------------------------------------------------------------------------------- 1 | export const setUnionDocs = { 2 | name: 'setUnion', 3 | category: 'Set', 4 | syntax: [ 5 | 'setUnion(set1, set2)' 6 | ], 7 | description: 8 | 'Create the union of two (multi)sets. Multi-dimension arrays will be converted to single-dimension arrays before the operation.', 9 | examples: [ 10 | 'setUnion([1, 2, 3, 4], [3, 4, 5, 6])', 11 | 'setUnion([[1, 2], [3, 4]], [[3, 4], [5, 6]])' 12 | ], 13 | seealso: [ 14 | 'setIntersect', 'setDifference' 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/signal/freqz.js: -------------------------------------------------------------------------------- 1 | export const freqzDocs = { 2 | name: 'freqz', 3 | category: 'Signal', 4 | syntax: [ 5 | 'freqz(b, a)', 6 | 'freqz(b, a, w)' 7 | ], 8 | description: 'Calculates the frequency response of a filter given its numerator and denominator coefficients.', 9 | examples: [ 10 | 'freqz([1, 2], [1, 2, 3])', 11 | 'freqz([1, 2], [1, 2, 3], [0, 1])', 12 | 'freqz([1, 2], [1, 2, 3], 512)' 13 | ], 14 | seealso: [] 15 | } 16 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/signal/zpk2tf.js: -------------------------------------------------------------------------------- 1 | export const zpk2tfDocs = { 2 | name: 'zpk2tf', 3 | category: 'Signal', 4 | syntax: [ 5 | 'zpk2tf(z, p, k)' 6 | ], 7 | description: 'Compute the transfer function of a zero-pole-gain model.', 8 | examples: [ 9 | 'zpk2tf([1, 2], [-1, -2], 1)', 10 | 'zpk2tf([1, 2], [-1, -2])', 11 | 'zpk2tf([1 - 3i, 2 + 2i], [-1, -2])' 12 | ], 13 | seealso: [] 14 | } 15 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/special/erf.js: -------------------------------------------------------------------------------- 1 | export const erfDocs = { 2 | name: 'erf', 3 | category: 'Special', 4 | syntax: [ 5 | 'erf(x)' 6 | ], 7 | description: 'Compute the erf function of a value using a rational Chebyshev approximations for different intervals of x', 8 | examples: [ 9 | 'erf(0.2)', 10 | 'erf(-0.5)', 11 | 'erf(4)' 12 | ], 13 | seealso: [] 14 | } 15 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/special/zeta.js: -------------------------------------------------------------------------------- 1 | export const zetaDocs = { 2 | name: 'zeta', 3 | category: 'Special', 4 | syntax: [ 5 | 'zeta(s)' 6 | ], 7 | description: 'Compute the Riemann Zeta Function using an infinite series and Riemann\'s Functional Equation for the entire complex plane', 8 | examples: [ 9 | 'zeta(0.2)', 10 | 'zeta(-0.5)', 11 | 'zeta(4)' 12 | ], 13 | seealso: [] 14 | } 15 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/statistics/corr.js: -------------------------------------------------------------------------------- 1 | export const corrDocs = { 2 | name: 'corr', 3 | category: 'Statistics', 4 | syntax: [ 5 | 'corr(A,B)' 6 | ], 7 | description: 'Compute the correlation coefficient of a two list with values, For matrices, the matrix correlation coefficient is calculated.', 8 | examples: [ 9 | 'corr([2, 4, 6, 8],[1, 2, 3, 6])', 10 | 'corr(matrix([[1, 2.2, 3, 4.8, 5], [1, 2, 3, 4, 5]]), matrix([[4, 5.3, 6.6, 7, 8], [1, 2, 3, 4, 5]]))' 11 | ], 12 | seealso: [ 13 | 'max', 14 | 'mean', 15 | 'min', 16 | 'median', 17 | 'min', 18 | 'prod', 19 | 'std', 20 | 'sum' 21 | ] 22 | } 23 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/statistics/cumsum.js: -------------------------------------------------------------------------------- 1 | export const cumSumDocs = { 2 | name: 'cumsum', 3 | category: 'Statistics', 4 | syntax: [ 5 | 'cumsum(a, b, c, ...)', 6 | 'cumsum(A)' 7 | ], 8 | description: 'Compute the cumulative sum of all values.', 9 | examples: [ 10 | 'cumsum(2, 3, 4, 1)', 11 | 'cumsum([2, 3, 4, 1])', 12 | 'cumsum([1, 2; 3, 4])', 13 | 'cumsum([1, 2; 3, 4], 1)', 14 | 'cumsum([1, 2; 3, 4], 2)' 15 | ], 16 | seealso: [ 17 | 'max', 18 | 'mean', 19 | 'median', 20 | 'min', 21 | 'prod', 22 | 'std', 23 | 'sum', 24 | 'variance' 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/statistics/mad.js: -------------------------------------------------------------------------------- 1 | export const madDocs = { 2 | name: 'mad', 3 | category: 'Statistics', 4 | syntax: [ 5 | 'mad(a, b, c, ...)', 6 | 'mad(A)' 7 | ], 8 | description: 'Compute the median absolute deviation of a matrix or a list with values. The median absolute deviation is defined as the median of the absolute deviations from the median.', 9 | examples: [ 10 | 'mad(10, 20, 30)', 11 | 'mad([1, 2, 3])' 12 | ], 13 | seealso: [ 14 | 'mean', 15 | 'median', 16 | 'std', 17 | 'abs' 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/statistics/max.js: -------------------------------------------------------------------------------- 1 | export const maxDocs = { 2 | name: 'max', 3 | category: 'Statistics', 4 | syntax: [ 5 | 'max(a, b, c, ...)', 6 | 'max(A)', 7 | 'max(A, dimension)' 8 | ], 9 | description: 'Compute the maximum value of a list of values. If any NaN values are found, the function yields the last NaN in the input.', 10 | examples: [ 11 | 'max(2, 3, 4, 1)', 12 | 'max([2, 3, 4, 1])', 13 | 'max([2, 5; 4, 3])', 14 | 'max([2, 5; 4, 3], 1)', 15 | 'max([2, 5; 4, 3], 2)', 16 | 'max(2.7, 7.1, -4.5, 2.0, 4.1)', 17 | 'min(2.7, 7.1, -4.5, 2.0, 4.1)' 18 | ], 19 | seealso: [ 20 | 'mean', 21 | 'median', 22 | 'min', 23 | 'prod', 24 | 'std', 25 | 'sum', 26 | 'variance' 27 | ] 28 | } 29 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/statistics/mean.js: -------------------------------------------------------------------------------- 1 | export const meanDocs = { 2 | name: 'mean', 3 | category: 'Statistics', 4 | syntax: [ 5 | 'mean(a, b, c, ...)', 6 | 'mean(A)', 7 | 'mean(A, dimension)' 8 | ], 9 | description: 'Compute the arithmetic mean of a list of values.', 10 | examples: [ 11 | 'mean(2, 3, 4, 1)', 12 | 'mean([2, 3, 4, 1])', 13 | 'mean([2, 5; 4, 3])', 14 | 'mean([2, 5; 4, 3], 1)', 15 | 'mean([2, 5; 4, 3], 2)', 16 | 'mean([1.0, 2.7, 3.2, 4.0])' 17 | ], 18 | seealso: [ 19 | 'max', 20 | 'median', 21 | 'min', 22 | 'prod', 23 | 'std', 24 | 'sum', 25 | 'variance' 26 | ] 27 | } 28 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/statistics/median.js: -------------------------------------------------------------------------------- 1 | export const medianDocs = { 2 | name: 'median', 3 | category: 'Statistics', 4 | syntax: [ 5 | 'median(a, b, c, ...)', 6 | 'median(A)' 7 | ], 8 | description: 'Compute the median of all values. The values are sorted and the middle value is returned. In case of an even number of values, the average of the two middle values is returned.', 9 | examples: [ 10 | 'median(5, 2, 7)', 11 | 'median([3, -1, 5, 7])' 12 | ], 13 | seealso: [ 14 | 'max', 15 | 'mean', 16 | 'min', 17 | 'prod', 18 | 'std', 19 | 'sum', 20 | 'variance', 21 | 'quantileSeq' 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/statistics/min.js: -------------------------------------------------------------------------------- 1 | export const minDocs = { 2 | name: 'min', 3 | category: 'Statistics', 4 | syntax: [ 5 | 'min(a, b, c, ...)', 6 | 'min(A)', 7 | 'min(A, dimension)' 8 | ], 9 | description: 'Compute the minimum value of a list of values. If any NaN values are found, the function yields the last NaN in the input.', 10 | examples: [ 11 | 'min(2, 3, 4, 1)', 12 | 'min([2, 3, 4, 1])', 13 | 'min([2, 5; 4, 3])', 14 | 'min([2, 5; 4, 3], 1)', 15 | 'min([2, 5; 4, 3], 2)', 16 | 'min(2.7, 7.1, -4.5, 2.0, 4.1)', 17 | 'max(2.7, 7.1, -4.5, 2.0, 4.1)' 18 | ], 19 | seealso: [ 20 | 'max', 21 | 'mean', 22 | 'median', 23 | 'prod', 24 | 'std', 25 | 'sum', 26 | 'variance' 27 | ] 28 | } 29 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/statistics/mode.js: -------------------------------------------------------------------------------- 1 | export const modeDocs = { 2 | name: 'mode', 3 | category: 'Statistics', 4 | syntax: [ 5 | 'mode(a, b, c, ...)', 6 | 'mode(A)', 7 | 'mode(A, a, b, B, c, ...)' 8 | ], 9 | description: 'Computes the mode of all values as an array. In case mode being more than one, multiple values are returned in an array.', 10 | examples: [ 11 | 'mode(2, 1, 4, 3, 1)', 12 | 'mode([1, 2.7, 3.2, 4, 2.7])', 13 | 'mode(1, 4, 6, 1, 6)' 14 | ], 15 | seealso: [ 16 | 'max', 17 | 'mean', 18 | 'min', 19 | 'median', 20 | 'prod', 21 | 'std', 22 | 'sum', 23 | 'variance' 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/statistics/prod.js: -------------------------------------------------------------------------------- 1 | export const prodDocs = { 2 | name: 'prod', 3 | category: 'Statistics', 4 | syntax: [ 5 | 'prod(a, b, c, ...)', 6 | 'prod(A)' 7 | ], 8 | description: 'Compute the product of all values.', 9 | examples: [ 10 | 'prod(2, 3, 4)', 11 | 'prod([2, 3, 4])', 12 | 'prod([2, 5; 4, 3])' 13 | ], 14 | seealso: [ 15 | 'max', 16 | 'mean', 17 | 'min', 18 | 'median', 19 | 'min', 20 | 'std', 21 | 'sum', 22 | 'variance' 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/statistics/std.js: -------------------------------------------------------------------------------- 1 | export const stdDocs = { 2 | name: 'std', 3 | category: 'Statistics', 4 | syntax: [ 5 | 'std(a, b, c, ...)', 6 | 'std(A)', 7 | 'std(A, dimension)', 8 | 'std(A, normalization)', 9 | 'std(A, dimension, normalization)' 10 | ], 11 | description: 'Compute the standard deviation of all values, defined as std(A) = sqrt(variance(A)). Optional parameter normalization can be "unbiased" (default), "uncorrected", or "biased".', 12 | examples: [ 13 | 'std(2, 4, 6)', 14 | 'std([2, 4, 6, 8])', 15 | 'std([2, 4, 6, 8], "uncorrected")', 16 | 'std([2, 4, 6, 8], "biased")', 17 | 'std([1, 2, 3; 4, 5, 6])' 18 | ], 19 | seealso: [ 20 | 'max', 21 | 'mean', 22 | 'min', 23 | 'median', 24 | 'prod', 25 | 'sum', 26 | 'variance' 27 | ] 28 | } 29 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/statistics/sum.js: -------------------------------------------------------------------------------- 1 | export const sumDocs = { 2 | name: 'sum', 3 | category: 'Statistics', 4 | syntax: [ 5 | 'sum(a, b, c, ...)', 6 | 'sum(A)', 7 | 'sum(A, dimension)' 8 | ], 9 | description: 'Compute the sum of all values.', 10 | examples: [ 11 | 'sum(2, 3, 4, 1)', 12 | 'sum([2, 3, 4, 1])', 13 | 'sum([2, 5; 4, 3])' 14 | ], 15 | seealso: [ 16 | 'max', 17 | 'mean', 18 | 'median', 19 | 'min', 20 | 'prod', 21 | 'std', 22 | 'variance' 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/statistics/variance.js: -------------------------------------------------------------------------------- 1 | export const varianceDocs = { 2 | name: 'variance', 3 | category: 'Statistics', 4 | syntax: [ 5 | 'variance(a, b, c, ...)', 6 | 'variance(A)', 7 | 'variance(A, dimension)', 8 | 'variance(A, normalization)', 9 | 'variance(A, dimension, normalization)' 10 | ], 11 | description: 'Compute the variance of all values. Optional parameter normalization can be "unbiased" (default), "uncorrected", or "biased".', 12 | examples: [ 13 | 'variance(2, 4, 6)', 14 | 'variance([2, 4, 6, 8])', 15 | 'variance([2, 4, 6, 8], "uncorrected")', 16 | 'variance([2, 4, 6, 8], "biased")', 17 | 'variance([1, 2, 3; 4, 5, 6])' 18 | ], 19 | seealso: [ 20 | 'max', 21 | 'mean', 22 | 'min', 23 | 'median', 24 | 'min', 25 | 'prod', 26 | 'std', 27 | 'sum' 28 | ] 29 | } 30 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/trigonometry/acos.js: -------------------------------------------------------------------------------- 1 | export const acosDocs = { 2 | name: 'acos', 3 | category: 'Trigonometry', 4 | syntax: [ 5 | 'acos(x)' 6 | ], 7 | description: 'Compute the inverse cosine of a value in radians.', 8 | examples: [ 9 | 'acos(0.5)', 10 | 'acos(cos(2.3))' 11 | ], 12 | seealso: [ 13 | 'cos', 14 | 'atan', 15 | 'asin' 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/trigonometry/acosh.js: -------------------------------------------------------------------------------- 1 | export const acoshDocs = { 2 | name: 'acosh', 3 | category: 'Trigonometry', 4 | syntax: [ 5 | 'acosh(x)' 6 | ], 7 | description: 'Calculate the hyperbolic arccos of a value, defined as `acosh(x) = ln(sqrt(x^2 - 1) + x)`.', 8 | examples: [ 9 | 'acosh(1.5)' 10 | ], 11 | seealso: [ 12 | 'cosh', 13 | 'asinh', 14 | 'atanh' 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/trigonometry/acot.js: -------------------------------------------------------------------------------- 1 | export const acotDocs = { 2 | name: 'acot', 3 | category: 'Trigonometry', 4 | syntax: [ 5 | 'acot(x)' 6 | ], 7 | description: 'Calculate the inverse cotangent of a value.', 8 | examples: [ 9 | 'acot(0.5)', 10 | 'acot(cot(0.5))', 11 | 'acot(2)' 12 | ], 13 | seealso: [ 14 | 'cot', 15 | 'atan' 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/trigonometry/acoth.js: -------------------------------------------------------------------------------- 1 | export const acothDocs = { 2 | name: 'acoth', 3 | category: 'Trigonometry', 4 | syntax: [ 5 | 'acoth(x)' 6 | ], 7 | description: 'Calculate the inverse hyperbolic tangent of a value, defined as `acoth(x) = (ln((x+1)/x) + ln(x/(x-1))) / 2`.', 8 | examples: [ 9 | 'acoth(2)', 10 | 'acoth(0.5)' 11 | ], 12 | seealso: [ 13 | 'acsch', 14 | 'asech' 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/trigonometry/acsc.js: -------------------------------------------------------------------------------- 1 | export const acscDocs = { 2 | name: 'acsc', 3 | category: 'Trigonometry', 4 | syntax: [ 5 | 'acsc(x)' 6 | ], 7 | description: 'Calculate the inverse cotangent of a value.', 8 | examples: [ 9 | 'acsc(2)', 10 | 'acsc(csc(0.5))', 11 | 'acsc(0.5)' 12 | ], 13 | seealso: [ 14 | 'csc', 15 | 'asin', 16 | 'asec' 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/trigonometry/acsch.js: -------------------------------------------------------------------------------- 1 | export const acschDocs = { 2 | name: 'acsch', 3 | category: 'Trigonometry', 4 | syntax: [ 5 | 'acsch(x)' 6 | ], 7 | description: 'Calculate the inverse hyperbolic cosecant of a value, defined as `acsch(x) = ln(1/x + sqrt(1/x^2 + 1))`.', 8 | examples: [ 9 | 'acsch(0.5)' 10 | ], 11 | seealso: [ 12 | 'asech', 13 | 'acoth' 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/trigonometry/asec.js: -------------------------------------------------------------------------------- 1 | export const asecDocs = { 2 | name: 'asec', 3 | category: 'Trigonometry', 4 | syntax: [ 5 | 'asec(x)' 6 | ], 7 | description: 'Calculate the inverse secant of a value.', 8 | examples: [ 9 | 'asec(0.5)', 10 | 'asec(sec(0.5))', 11 | 'asec(2)' 12 | ], 13 | seealso: [ 14 | 'acos', 15 | 'acot', 16 | 'acsc' 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/trigonometry/asech.js: -------------------------------------------------------------------------------- 1 | export const asechDocs = { 2 | name: 'asech', 3 | category: 'Trigonometry', 4 | syntax: [ 5 | 'asech(x)' 6 | ], 7 | description: 'Calculate the inverse secant of a value.', 8 | examples: [ 9 | 'asech(0.5)' 10 | ], 11 | seealso: [ 12 | 'acsch', 13 | 'acoth' 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/trigonometry/asin.js: -------------------------------------------------------------------------------- 1 | export const asinDocs = { 2 | name: 'asin', 3 | category: 'Trigonometry', 4 | syntax: [ 5 | 'asin(x)' 6 | ], 7 | description: 'Compute the inverse sine of a value in radians.', 8 | examples: [ 9 | 'asin(0.5)', 10 | 'asin(sin(0.5))' 11 | ], 12 | seealso: [ 13 | 'sin', 14 | 'acos', 15 | 'atan' 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/trigonometry/asinh.js: -------------------------------------------------------------------------------- 1 | export const asinhDocs = { 2 | name: 'asinh', 3 | category: 'Trigonometry', 4 | syntax: [ 5 | 'asinh(x)' 6 | ], 7 | description: 'Calculate the hyperbolic arcsine of a value, defined as `asinh(x) = ln(x + sqrt(x^2 + 1))`.', 8 | examples: [ 9 | 'asinh(0.5)' 10 | ], 11 | seealso: [ 12 | 'acosh', 13 | 'atanh' 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/trigonometry/atan.js: -------------------------------------------------------------------------------- 1 | export const atanDocs = { 2 | name: 'atan', 3 | category: 'Trigonometry', 4 | syntax: [ 5 | 'atan(x)' 6 | ], 7 | description: 'Compute the inverse tangent of a value in radians.', 8 | examples: [ 9 | 'atan(0.5)', 10 | 'atan(tan(0.5))' 11 | ], 12 | seealso: [ 13 | 'tan', 14 | 'acos', 15 | 'asin' 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/trigonometry/atan2.js: -------------------------------------------------------------------------------- 1 | export const atan2Docs = { 2 | name: 'atan2', 3 | category: 'Trigonometry', 4 | syntax: [ 5 | 'atan2(y, x)' 6 | ], 7 | description: 8 | 'Computes the principal value of the arc tangent of y/x in radians.', 9 | examples: [ 10 | 'atan2(2, 2) / pi', 11 | 'angle = 60 deg in rad', 12 | 'x = cos(angle)', 13 | 'y = sin(angle)', 14 | 'atan2(y, x)' 15 | ], 16 | seealso: [ 17 | 'sin', 18 | 'cos', 19 | 'tan' 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/trigonometry/atanh.js: -------------------------------------------------------------------------------- 1 | export const atanhDocs = { 2 | name: 'atanh', 3 | category: 'Trigonometry', 4 | syntax: [ 5 | 'atanh(x)' 6 | ], 7 | description: 'Calculate the hyperbolic arctangent of a value, defined as `atanh(x) = ln((1 + x)/(1 - x)) / 2`.', 8 | examples: [ 9 | 'atanh(0.5)' 10 | ], 11 | seealso: [ 12 | 'acosh', 13 | 'asinh' 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/trigonometry/cos.js: -------------------------------------------------------------------------------- 1 | export const cosDocs = { 2 | name: 'cos', 3 | category: 'Trigonometry', 4 | syntax: [ 5 | 'cos(x)' 6 | ], 7 | description: 'Compute the cosine of x in radians.', 8 | examples: [ 9 | 'cos(2)', 10 | 'cos(pi / 4) ^ 2', 11 | 'cos(180 deg)', 12 | 'cos(60 deg)', 13 | 'sin(0.2)^2 + cos(0.2)^2' 14 | ], 15 | seealso: [ 16 | 'acos', 17 | 'sin', 18 | 'tan' 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/trigonometry/cosh.js: -------------------------------------------------------------------------------- 1 | export const coshDocs = { 2 | name: 'cosh', 3 | category: 'Trigonometry', 4 | syntax: [ 5 | 'cosh(x)' 6 | ], 7 | description: 'Compute the hyperbolic cosine of x in radians.', 8 | examples: [ 9 | 'cosh(0.5)' 10 | ], 11 | seealso: [ 12 | 'sinh', 13 | 'tanh', 14 | 'coth' 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/trigonometry/cot.js: -------------------------------------------------------------------------------- 1 | export const cotDocs = { 2 | name: 'cot', 3 | category: 'Trigonometry', 4 | syntax: [ 5 | 'cot(x)' 6 | ], 7 | description: 'Compute the cotangent of x in radians. Defined as 1/tan(x)', 8 | examples: [ 9 | 'cot(2)', 10 | '1 / tan(2)' 11 | ], 12 | seealso: [ 13 | 'sec', 14 | 'csc', 15 | 'tan' 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/trigonometry/coth.js: -------------------------------------------------------------------------------- 1 | export const cothDocs = { 2 | name: 'coth', 3 | category: 'Trigonometry', 4 | syntax: [ 5 | 'coth(x)' 6 | ], 7 | description: 'Compute the hyperbolic cotangent of x in radians.', 8 | examples: [ 9 | 'coth(2)', 10 | '1 / tanh(2)' 11 | ], 12 | seealso: [ 13 | 'sech', 14 | 'csch', 15 | 'tanh' 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/trigonometry/csc.js: -------------------------------------------------------------------------------- 1 | export const cscDocs = { 2 | name: 'csc', 3 | category: 'Trigonometry', 4 | syntax: [ 5 | 'csc(x)' 6 | ], 7 | description: 'Compute the cosecant of x in radians. Defined as 1/sin(x)', 8 | examples: [ 9 | 'csc(2)', 10 | '1 / sin(2)' 11 | ], 12 | seealso: [ 13 | 'sec', 14 | 'cot', 15 | 'sin' 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/trigonometry/csch.js: -------------------------------------------------------------------------------- 1 | export const cschDocs = { 2 | name: 'csch', 3 | category: 'Trigonometry', 4 | syntax: [ 5 | 'csch(x)' 6 | ], 7 | description: 'Compute the hyperbolic cosecant of x in radians. Defined as 1/sinh(x)', 8 | examples: [ 9 | 'csch(2)', 10 | '1 / sinh(2)' 11 | ], 12 | seealso: [ 13 | 'sech', 14 | 'coth', 15 | 'sinh' 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/trigonometry/sec.js: -------------------------------------------------------------------------------- 1 | export const secDocs = { 2 | name: 'sec', 3 | category: 'Trigonometry', 4 | syntax: [ 5 | 'sec(x)' 6 | ], 7 | description: 'Compute the secant of x in radians. Defined as 1/cos(x)', 8 | examples: [ 9 | 'sec(2)', 10 | '1 / cos(2)' 11 | ], 12 | seealso: [ 13 | 'cot', 14 | 'csc', 15 | 'cos' 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/trigonometry/sech.js: -------------------------------------------------------------------------------- 1 | export const sechDocs = { 2 | name: 'sech', 3 | category: 'Trigonometry', 4 | syntax: [ 5 | 'sech(x)' 6 | ], 7 | description: 'Compute the hyperbolic secant of x in radians. Defined as 1/cosh(x)', 8 | examples: [ 9 | 'sech(2)', 10 | '1 / cosh(2)' 11 | ], 12 | seealso: [ 13 | 'coth', 14 | 'csch', 15 | 'cosh' 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/trigonometry/sin.js: -------------------------------------------------------------------------------- 1 | export const sinDocs = { 2 | name: 'sin', 3 | category: 'Trigonometry', 4 | syntax: [ 5 | 'sin(x)' 6 | ], 7 | description: 'Compute the sine of x in radians.', 8 | examples: [ 9 | 'sin(2)', 10 | 'sin(pi / 4) ^ 2', 11 | 'sin(90 deg)', 12 | 'sin(30 deg)', 13 | 'sin(0.2)^2 + cos(0.2)^2' 14 | ], 15 | seealso: [ 16 | 'asin', 17 | 'cos', 18 | 'tan' 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/trigonometry/sinh.js: -------------------------------------------------------------------------------- 1 | export const sinhDocs = { 2 | name: 'sinh', 3 | category: 'Trigonometry', 4 | syntax: [ 5 | 'sinh(x)' 6 | ], 7 | description: 'Compute the hyperbolic sine of x in radians.', 8 | examples: [ 9 | 'sinh(0.5)' 10 | ], 11 | seealso: [ 12 | 'cosh', 13 | 'tanh' 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/trigonometry/tan.js: -------------------------------------------------------------------------------- 1 | export const tanDocs = { 2 | name: 'tan', 3 | category: 'Trigonometry', 4 | syntax: [ 5 | 'tan(x)' 6 | ], 7 | description: 'Compute the tangent of x in radians.', 8 | examples: [ 9 | 'tan(0.5)', 10 | 'sin(0.5) / cos(0.5)', 11 | 'tan(pi / 4)', 12 | 'tan(45 deg)' 13 | ], 14 | seealso: [ 15 | 'atan', 16 | 'sin', 17 | 'cos' 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/trigonometry/tanh.js: -------------------------------------------------------------------------------- 1 | export const tanhDocs = { 2 | name: 'tanh', 3 | category: 'Trigonometry', 4 | syntax: [ 5 | 'tanh(x)' 6 | ], 7 | description: 'Compute the hyperbolic tangent of x in radians.', 8 | examples: [ 9 | 'tanh(0.5)', 10 | 'sinh(0.5) / cosh(0.5)' 11 | ], 12 | seealso: [ 13 | 'sinh', 14 | 'cosh' 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/units/to.js: -------------------------------------------------------------------------------- 1 | export const toDocs = { 2 | name: 'to', 3 | category: 'Units', 4 | syntax: [ 5 | 'x to unit', 6 | 'to(x, unit)' 7 | ], 8 | description: 'Change the unit of a value.', 9 | examples: [ 10 | '5 inch to cm', 11 | '3.2kg to g', 12 | '16 bytes in bits' 13 | ], 14 | seealso: [] 15 | } 16 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/utils/bin.js: -------------------------------------------------------------------------------- 1 | export const binDocs = { 2 | name: 'bin', 3 | category: 'Utils', 4 | syntax: [ 5 | 'bin(value)' 6 | ], 7 | description: 'Format a number as binary', 8 | examples: [ 9 | 'bin(2)' 10 | ], 11 | seealso: ['oct', 'hex'] 12 | } 13 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/utils/clone.js: -------------------------------------------------------------------------------- 1 | export const cloneDocs = { 2 | name: 'clone', 3 | category: 'Utils', 4 | syntax: [ 5 | 'clone(x)' 6 | ], 7 | description: 'Clone a variable. Creates a copy of primitive variables, and a deep copy of matrices', 8 | examples: [ 9 | 'clone(3.5)', 10 | 'clone(2 - 4i)', 11 | 'clone(45 deg)', 12 | 'clone([1, 2; 3, 4])', 13 | 'clone("hello world")' 14 | ], 15 | seealso: [] 16 | } 17 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/utils/format.js: -------------------------------------------------------------------------------- 1 | export const formatDocs = { 2 | name: 'format', 3 | category: 'Utils', 4 | syntax: [ 5 | 'format(value)', 6 | 'format(value, precision)' 7 | ], 8 | description: 'Format a value of any type as string.', 9 | examples: [ 10 | 'format(2.3)', 11 | 'format(3 - 4i)', 12 | 'format([])', 13 | 'format(pi, 3)' 14 | ], 15 | seealso: ['print'] 16 | } 17 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/utils/hasNumericValue.js: -------------------------------------------------------------------------------- 1 | export const hasNumericValueDocs = { 2 | name: 'hasNumericValue', 3 | category: 'Utils', 4 | syntax: [ 5 | 'hasNumericValue(x)' 6 | ], 7 | description: 'Test whether a value is an numeric value. ' + 8 | 'In case of a string, true is returned if the string contains a numeric value.', 9 | examples: [ 10 | 'hasNumericValue(2)', 11 | 'hasNumericValue("2")', 12 | 'isNumeric("2")', 13 | 'hasNumericValue(0)', 14 | 'hasNumericValue(bignumber(500))', 15 | 'hasNumericValue(fraction(0.125))', 16 | 'hasNumericValue(2 + 3i)', 17 | 'hasNumericValue([2.3, "foo", false])' 18 | ], 19 | seealso: ['isInteger', 'isZero', 'isNegative', 'isPositive', 'isNaN', 'isNumeric'] 20 | } 21 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/utils/hex.js: -------------------------------------------------------------------------------- 1 | export const hexDocs = { 2 | name: 'hex', 3 | category: 'Utils', 4 | syntax: [ 5 | 'hex(value)' 6 | ], 7 | description: 'Format a number as hexadecimal', 8 | examples: [ 9 | 'hex(240)' 10 | ], 11 | seealso: ['bin', 'oct'] 12 | } 13 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/utils/isInteger.js: -------------------------------------------------------------------------------- 1 | export const isIntegerDocs = { 2 | name: 'isInteger', 3 | category: 'Utils', 4 | syntax: [ 5 | 'isInteger(x)' 6 | ], 7 | description: 'Test whether a value is an integer number.', 8 | examples: [ 9 | 'isInteger(2)', 10 | 'isInteger(3.5)', 11 | 'isInteger([3, 0.5, -2])' 12 | ], 13 | seealso: ['isNegative', 'isNumeric', 'isPositive', 'isZero'] 14 | } 15 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/utils/isNaN.js: -------------------------------------------------------------------------------- 1 | export const isNaNDocs = { 2 | name: 'isNaN', 3 | category: 'Utils', 4 | syntax: [ 5 | 'isNaN(x)' 6 | ], 7 | description: 'Test whether a value is NaN (not a number)', 8 | examples: [ 9 | 'isNaN(2)', 10 | 'isNaN(0 / 0)', 11 | 'isNaN(NaN)', 12 | 'isNaN(Infinity)' 13 | ], 14 | seealso: ['isNegative', 'isNumeric', 'isPositive', 'isZero'] 15 | } 16 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/utils/isNegative.js: -------------------------------------------------------------------------------- 1 | export const isNegativeDocs = { 2 | name: 'isNegative', 3 | category: 'Utils', 4 | syntax: [ 5 | 'isNegative(x)' 6 | ], 7 | description: 'Test whether a value is negative: smaller than zero.', 8 | examples: [ 9 | 'isNegative(2)', 10 | 'isNegative(0)', 11 | 'isNegative(-4)', 12 | 'isNegative([3, 0.5, -2])' 13 | ], 14 | seealso: ['isInteger', 'isNumeric', 'isPositive', 'isZero'] 15 | } 16 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/utils/isNumeric.js: -------------------------------------------------------------------------------- 1 | export const isNumericDocs = { 2 | name: 'isNumeric', 3 | category: 'Utils', 4 | syntax: [ 5 | 'isNumeric(x)' 6 | ], 7 | description: 'Test whether a value is a numeric value. ' + 8 | 'Returns true when the input is a number, BigNumber, Fraction, or boolean.', 9 | examples: [ 10 | 'isNumeric(2)', 11 | 'isNumeric("2")', 12 | 'hasNumericValue("2")', 13 | 'isNumeric(0)', 14 | 'isNumeric(bignumber(500))', 15 | 'isNumeric(fraction(0.125))', 16 | 'isNumeric(2 + 3i)', 17 | 'isNumeric([2.3, "foo", false])' 18 | ], 19 | seealso: ['isInteger', 'isZero', 'isNegative', 'isPositive', 'isNaN', 'hasNumericValue'] 20 | } 21 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/utils/isPositive.js: -------------------------------------------------------------------------------- 1 | export const isPositiveDocs = { 2 | name: 'isPositive', 3 | category: 'Utils', 4 | syntax: [ 5 | 'isPositive(x)' 6 | ], 7 | description: 'Test whether a value is positive: larger than zero.', 8 | examples: [ 9 | 'isPositive(2)', 10 | 'isPositive(0)', 11 | 'isPositive(-4)', 12 | 'isPositive([3, 0.5, -2])' 13 | ], 14 | seealso: ['isInteger', 'isNumeric', 'isNegative', 'isZero'] 15 | } 16 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/utils/isPrime.js: -------------------------------------------------------------------------------- 1 | export const isPrimeDocs = { 2 | name: 'isPrime', 3 | category: 'Utils', 4 | syntax: [ 5 | 'isPrime(x)' 6 | ], 7 | description: 'Test whether a value is prime: has no divisors other than itself and one.', 8 | examples: [ 9 | 'isPrime(3)', 10 | 'isPrime(-2)', 11 | 'isPrime([2, 17, 100])' 12 | ], 13 | seealso: ['isInteger', 'isNumeric', 'isNegative', 'isZero'] 14 | } 15 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/utils/isZero.js: -------------------------------------------------------------------------------- 1 | export const isZeroDocs = { 2 | name: 'isZero', 3 | category: 'Utils', 4 | syntax: [ 5 | 'isZero(x)' 6 | ], 7 | description: 'Test whether a value is zero.', 8 | examples: [ 9 | 'isZero(2)', 10 | 'isZero(0)', 11 | 'isZero(-4)', 12 | 'isZero([3, 0, -2, 0])' 13 | ], 14 | seealso: ['isInteger', 'isNumeric', 'isNegative', 'isPositive'] 15 | } 16 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/utils/numeric.js: -------------------------------------------------------------------------------- 1 | export const numericDocs = { 2 | name: 'numeric', 3 | category: 'Utils', 4 | syntax: [ 5 | 'numeric(x)' 6 | ], 7 | description: 'Convert a numeric input to a specific numeric type: number, BigNumber, bigint, or Fraction.', 8 | examples: [ 9 | 'numeric("4")', 10 | 'numeric("4", "number")', 11 | 'numeric("4", "bigint")', 12 | 'numeric("4", "BigNumber")', 13 | 'numeric("4", "Fraction")', 14 | 'numeric(4, "Fraction")', 15 | 'numeric(fraction(2, 5), "number")' 16 | ], 17 | seealso: ['number', 'bigint', 'fraction', 'bignumber', 'string', 'format'] 18 | } 19 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/utils/oct.js: -------------------------------------------------------------------------------- 1 | export const octDocs = { 2 | name: 'oct', 3 | category: 'Utils', 4 | syntax: [ 5 | 'oct(value)' 6 | ], 7 | description: 'Format a number as octal', 8 | examples: [ 9 | 'oct(56)' 10 | ], 11 | seealso: ['bin', 'hex'] 12 | } 13 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/utils/print.js: -------------------------------------------------------------------------------- 1 | export const printDocs = { 2 | name: 'print', 3 | category: 'Utils', 4 | syntax: [ 5 | 'print(template, values)', 6 | 'print(template, values, precision)' 7 | ], 8 | description: 'Interpolate values into a string template.', 9 | examples: [ 10 | 'print("Lucy is $age years old", {age: 5})', 11 | 'print("The value of pi is $pi", {pi: pi}, 3)', 12 | 'print("Hello, $user.name!", {user: {name: "John"}})', 13 | 'print("Values: $1, $2, $3", [6, 9, 4])' 14 | ], 15 | seealso: ['format'] 16 | } 17 | -------------------------------------------------------------------------------- /src/expression/embeddedDocs/function/utils/typeOf.js: -------------------------------------------------------------------------------- 1 | export const typeOfDocs = { 2 | name: 'typeOf', 3 | category: 'Utils', 4 | syntax: [ 5 | 'typeOf(x)' 6 | ], 7 | description: 'Get the type of a variable.', 8 | examples: [ 9 | 'typeOf(3.5)', 10 | 'typeOf(2 - 4i)', 11 | 'typeOf(45 deg)', 12 | 'typeOf("hello world")' 13 | ], 14 | seealso: ['getMatrixDataType'] 15 | } 16 | -------------------------------------------------------------------------------- /src/expression/keywords.js: -------------------------------------------------------------------------------- 1 | // Reserved keywords not allowed to use in the parser 2 | export const keywords = new Set([ 3 | 'end' 4 | ]) 5 | -------------------------------------------------------------------------------- /src/expression/transform/and.transform.js: -------------------------------------------------------------------------------- 1 | import { createAnd } from '../../function/logical/and.js' 2 | import { factory } from '../../utils/factory.js' 3 | import { isCollection } from '../../utils/is.js' 4 | 5 | const name = 'and' 6 | const dependencies = ['typed', 'matrix', 'zeros', 'add', 'equalScalar', 'not', 'concat'] 7 | 8 | export const createAndTransform = /* #__PURE__ */ factory(name, dependencies, ({ typed, matrix, equalScalar, zeros, not, concat }) => { 9 | const and = createAnd({ typed, matrix, equalScalar, zeros, not, concat }) 10 | 11 | function andTransform (args, math, scope) { 12 | const condition1 = args[0].compile().evaluate(scope) 13 | if (!isCollection(condition1) && !and(condition1, true)) { 14 | return false 15 | } 16 | const condition2 = args[1].compile().evaluate(scope) 17 | return and(condition1, condition2) 18 | } 19 | 20 | andTransform.rawArgs = true 21 | 22 | return andTransform 23 | }, { isTransformFunction: true }) 24 | -------------------------------------------------------------------------------- /src/expression/transform/or.transform.js: -------------------------------------------------------------------------------- 1 | import { createOr } from '../../function/logical/or.js' 2 | import { factory } from '../../utils/factory.js' 3 | import { isCollection } from '../../utils/is.js' 4 | 5 | const name = 'or' 6 | const dependencies = ['typed', 'matrix', 'equalScalar', 'DenseMatrix', 'concat'] 7 | 8 | export const createOrTransform = /* #__PURE__ */ factory(name, dependencies, ({ typed, matrix, equalScalar, DenseMatrix, concat }) => { 9 | const or = createOr({ typed, matrix, equalScalar, DenseMatrix, concat }) 10 | 11 | function orTransform (args, math, scope) { 12 | const condition1 = args[0].compile().evaluate(scope) 13 | if (!isCollection(condition1) && or(condition1, false)) { 14 | return true 15 | } 16 | const condition2 = args[1].compile().evaluate(scope) 17 | return or(condition1, condition2) 18 | } 19 | 20 | orTransform.rawArgs = true 21 | 22 | return orTransform 23 | }, { isTransformFunction: true }) 24 | -------------------------------------------------------------------------------- /src/expression/transform/subset.transform.js: -------------------------------------------------------------------------------- 1 | import { factory } from '../../utils/factory.js' 2 | import { errorTransform } from './utils/errorTransform.js' 3 | import { createSubset } from '../../function/matrix/subset.js' 4 | 5 | const name = 'subset' 6 | const dependencies = ['typed', 'matrix', 'zeros', 'add'] 7 | 8 | export const createSubsetTransform = /* #__PURE__ */ factory(name, dependencies, ({ typed, matrix, zeros, add }) => { 9 | const subset = createSubset({ typed, matrix, zeros, add }) 10 | 11 | /** 12 | * Attach a transform function to math.subset 13 | * Adds a property transform containing the transform function. 14 | * 15 | * This transform creates a range which includes the end value 16 | */ 17 | return typed('subset', { 18 | '...any': function (args) { 19 | try { 20 | return subset.apply(null, args) 21 | } catch (err) { 22 | throw errorTransform(err) 23 | } 24 | } 25 | }) 26 | }, { isTransformFunction: true }) 27 | -------------------------------------------------------------------------------- /src/expression/transform/utils/dimToZeroBase.js: -------------------------------------------------------------------------------- 1 | import { isNumber, isBigNumber } from '../../../utils/is.js' 2 | /** 3 | * Change last argument dim from one-based to zero-based. 4 | */ 5 | export function dimToZeroBase (dim) { 6 | if (isNumber(dim)) { 7 | return dim - 1 8 | } else if (isBigNumber(dim)) { 9 | return dim.minus(1) 10 | } else { 11 | return dim 12 | } 13 | } 14 | 15 | export function isNumberOrBigNumber (n) { 16 | return isNumber(n) || isBigNumber(n) 17 | } 18 | -------------------------------------------------------------------------------- /src/expression/transform/utils/errorTransform.js: -------------------------------------------------------------------------------- 1 | import { IndexError } from '../../../error/IndexError.js' 2 | 3 | /** 4 | * Transform zero-based indices to one-based indices in errors 5 | * @param {Error} err 6 | * @returns {Error | IndexError} Returns the transformed error 7 | */ 8 | export function errorTransform (err) { 9 | if (err && err.isIndexError) { 10 | return new IndexError( 11 | err.index + 1, 12 | err.min + 1, 13 | err.max !== undefined ? err.max + 1 : undefined) 14 | } 15 | 16 | return err 17 | } 18 | -------------------------------------------------------------------------------- /src/expression/transform/utils/lastDimToZeroBase.js: -------------------------------------------------------------------------------- 1 | import { isCollection } from '../../../utils/is.js' 2 | import { dimToZeroBase, isNumberOrBigNumber } from './dimToZeroBase.js' 3 | /** 4 | * Change last argument dim from one-based to zero-based. 5 | */ 6 | export function lastDimToZeroBase (args) { 7 | if (args.length === 2 && isCollection(args[0])) { 8 | args = args.slice() 9 | const dim = args[1] 10 | if (isNumberOrBigNumber(dim)) { 11 | args[1] = dimToZeroBase(dim) 12 | } 13 | } 14 | return args 15 | } 16 | -------------------------------------------------------------------------------- /src/function/algebra/simplify/wildcards.js: -------------------------------------------------------------------------------- 1 | import { isConstantNode, isFunctionNode, isOperatorNode, isParenthesisNode } from '../../../utils/is.js' 2 | export { isConstantNode, isSymbolNode as isVariableNode } from '../../../utils/is.js' 3 | 4 | export function isNumericNode (x) { 5 | return isConstantNode(x) || (isOperatorNode(x) && x.isUnary() && isConstantNode(x.args[0])) 6 | } 7 | 8 | export function isConstantExpression (x) { 9 | if (isConstantNode(x)) { // Basic Constant types 10 | return true 11 | } 12 | if ((isFunctionNode(x) || isOperatorNode(x)) && x.args.every(isConstantExpression)) { // Can be constant depending on arguments 13 | return true 14 | } 15 | if (isParenthesisNode(x) && isConstantExpression(x.content)) { // Parenthesis are transparent 16 | return true 17 | } 18 | return false // Probably missing some edge cases 19 | } 20 | -------------------------------------------------------------------------------- /src/function/algebra/sparse/README.md: -------------------------------------------------------------------------------- 1 | # CSparse 2 | 3 | This folder contains a JavaScript port of the `CSparse` section of the open source `SuiteSparse` library by Timothy A. Davis, see: 4 | 5 | https://github.com/DrTimothyAldenDavis/SuiteSparse/tree/dev/CSparse/Source 6 | 7 | 8 | ``` 9 | CSparse: a Concise Sparse matrix package. 10 | Copyright (c) 2006, Timothy A. Davis. 11 | http://www.suitesparse.com 12 | ``` 13 | -------------------------------------------------------------------------------- /src/function/algebra/sparse/csCumsum.js: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2006-2024, Timothy A. Davis, All Rights Reserved. 2 | // SPDX-License-Identifier: LGPL-2.1+ 3 | // https://github.com/DrTimothyAldenDavis/SuiteSparse/tree/dev/CSparse/Source 4 | 5 | /** 6 | * It sets the p[i] equal to the sum of c[0] through c[i-1]. 7 | * 8 | * @param {Array} ptr The Sparse Matrix ptr array 9 | * @param {Array} c The Sparse Matrix ptr array 10 | * @param {Number} n The number of columns 11 | */ 12 | export function csCumsum (ptr, c, n) { 13 | // variables 14 | let i 15 | let nz = 0 16 | 17 | for (i = 0; i < n; i++) { 18 | // initialize ptr @ i 19 | ptr[i] = nz 20 | // increment number of nonzeros 21 | nz += c[i] 22 | // also copy p[0..n-1] back into c[0..n-1] 23 | c[i] = ptr[i] 24 | } 25 | // finalize ptr 26 | ptr[n] = nz 27 | // return sum (c [0..n-1]) 28 | return nz 29 | } 30 | -------------------------------------------------------------------------------- /src/function/algebra/sparse/csFlip.js: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2006-2024, Timothy A. Davis, All Rights Reserved. 2 | // SPDX-License-Identifier: LGPL-2.1+ 3 | // https://github.com/DrTimothyAldenDavis/SuiteSparse/tree/dev/CSparse/Source 4 | 5 | /** 6 | * This function "flips" its input about the integer -1. 7 | * 8 | * @param {Number} i The value to flip 9 | */ 10 | export function csFlip (i) { 11 | // flip the value 12 | return -i - 2 13 | } 14 | -------------------------------------------------------------------------------- /src/function/algebra/sparse/csMark.js: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2006-2024, Timothy A. Davis, All Rights Reserved. 2 | // SPDX-License-Identifier: LGPL-2.1+ 3 | // https://github.com/DrTimothyAldenDavis/SuiteSparse/tree/dev/CSparse/Source 4 | 5 | import { csFlip } from './csFlip.js' 6 | 7 | /** 8 | * Marks the node at w[j] 9 | * 10 | * @param {Array} w The array 11 | * @param {Number} j The array index 12 | */ 13 | export function csMark (w, j) { 14 | // mark w[j] 15 | w[j] = csFlip(w[j]) 16 | } 17 | -------------------------------------------------------------------------------- /src/function/algebra/sparse/csMarked.js: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2006-2024, Timothy A. Davis, All Rights Reserved. 2 | // SPDX-License-Identifier: LGPL-2.1+ 3 | // https://github.com/DrTimothyAldenDavis/SuiteSparse/tree/dev/CSparse/Source 4 | 5 | /** 6 | * Checks if the node at w[j] is marked 7 | * 8 | * @param {Array} w The array 9 | * @param {Number} j The array index 10 | */ 11 | export function csMarked (w, j) { 12 | // check node is marked 13 | return w[j] < 0 14 | } 15 | -------------------------------------------------------------------------------- /src/function/algebra/sparse/csUnflip.js: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2006-2024, Timothy A. Davis, All Rights Reserved. 2 | // SPDX-License-Identifier: LGPL-2.1+ 3 | // https://github.com/DrTimothyAldenDavis/SuiteSparse/tree/dev/CSparse/Source 4 | import { csFlip } from './csFlip.js' 5 | 6 | /** 7 | * Flips the value if it is negative of returns the same value otherwise. 8 | * 9 | * @param {Number} i The value to flip 10 | */ 11 | export function csUnflip (i) { 12 | // flip the value if it is negative 13 | return i < 0 ? csFlip(i) : i 14 | } 15 | -------------------------------------------------------------------------------- /src/function/bitwise/useMatrixForArrayScalar.js: -------------------------------------------------------------------------------- 1 | import { factory } from '../../utils/factory.js' 2 | 3 | export const createUseMatrixForArrayScalar = /* #__PURE__ */ factory('useMatrixForArrayScalar', ['typed', 'matrix'], ({ typed, matrix }) => ({ 4 | 'Array, number': typed.referTo('DenseMatrix, number', 5 | selfDn => (x, y) => selfDn(matrix(x), y).valueOf()), 6 | 7 | 'Array, BigNumber': typed.referTo('DenseMatrix, BigNumber', 8 | selfDB => (x, y) => selfDB(matrix(x), y).valueOf()), 9 | 10 | 'number, Array': typed.referTo('number, DenseMatrix', 11 | selfnD => (x, y) => selfnD(x, matrix(y)).valueOf()), 12 | 13 | 'BigNumber, Array': typed.referTo('BigNumber, DenseMatrix', 14 | selfBD => (x, y) => selfBD(x, matrix(y)).valueOf()) 15 | })) 16 | -------------------------------------------------------------------------------- /src/function/probability/util/randomMatrix.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This is a util function for generating a random matrix recursively. 3 | * @param {number[]} size 4 | * @param {function} random 5 | * @returns {Array} 6 | */ 7 | export function randomMatrix (size, random) { 8 | const data = [] 9 | size = size.slice(0) 10 | 11 | if (size.length > 1) { 12 | for (let i = 0, length = size.shift(); i < length; i++) { 13 | data.push(randomMatrix(size, random)) 14 | } 15 | } else { 16 | for (let i = 0, length = size.shift(); i < length; i++) { 17 | data.push(random()) 18 | } 19 | } 20 | 21 | return data 22 | } 23 | -------------------------------------------------------------------------------- /src/function/probability/util/seededRNG.js: -------------------------------------------------------------------------------- 1 | import seedrandom from 'seedrandom' 2 | 3 | const singletonRandom = /* #__PURE__ */ seedrandom(Date.now()) 4 | 5 | export function createRng (randomSeed) { 6 | let random 7 | 8 | // create a new random generator with given seed 9 | function setSeed (seed) { 10 | random = seed === null ? singletonRandom : seedrandom(String(seed)) 11 | } 12 | 13 | // initialize a seeded pseudo random number generator with config's random seed 14 | setSeed(randomSeed) 15 | 16 | // wrapper function so the rng can be updated via generator 17 | function rng () { 18 | return random() 19 | } 20 | 21 | return rng 22 | } 23 | -------------------------------------------------------------------------------- /src/function/relational/compareUnits.js: -------------------------------------------------------------------------------- 1 | import { factory } from '../../utils/factory.js' 2 | 3 | export const createCompareUnits = /* #__PURE__ */ factory( 4 | 'compareUnits', ['typed'], ({ typed }) => ({ 5 | 'Unit, Unit': typed.referToSelf(self => (x, y) => { 6 | if (!x.equalBase(y)) { 7 | throw new Error('Cannot compare units with different base') 8 | } 9 | return typed.find(self, [x.valueType(), y.valueType()])(x.value, y.value) 10 | }) 11 | }) 12 | ) 13 | -------------------------------------------------------------------------------- /src/function/string/hex.js: -------------------------------------------------------------------------------- 1 | import { factory } from '../../utils/factory.js' 2 | 3 | const name = 'hex' 4 | const dependencies = ['typed', 'format'] 5 | 6 | /** 7 | * Format a number as hexadecimal. 8 | * 9 | * Syntax: 10 | * 11 | * math.hex(value) 12 | * 13 | * Examples: 14 | * 15 | * math.hex(240) // returns "0xf0" 16 | * 17 | * See also: 18 | * 19 | * oct 20 | * bin 21 | * 22 | * @param {number | BigNumber} value Value to be stringified 23 | * @param {number | BigNumber} wordSize Optional word size (see `format`) 24 | * @return {string} The formatted value 25 | */ 26 | export const createHex = factory(name, dependencies, ({ typed, format }) => { 27 | return typed(name, { 28 | 'number | BigNumber': function (n) { 29 | return format(n, { notation: 'hex' }) 30 | }, 31 | 'number | BigNumber, number | BigNumber': function (n, wordSize) { 32 | return format(n, { notation: 'hex', wordSize }) 33 | } 34 | }) 35 | }) 36 | -------------------------------------------------------------------------------- /src/function/trigonometry/trigUnit.js: -------------------------------------------------------------------------------- 1 | import { factory } from '../../utils/factory.js' 2 | 3 | export const createTrigUnit = /* #__PURE__ */ factory( 4 | 'trigUnit', ['typed'], ({ typed }) => ({ 5 | Unit: typed.referToSelf(self => x => { 6 | if (!x.hasBase(x.constructor.BASE_UNITS.ANGLE)) { 7 | throw new TypeError('Unit in function cot is no angle') 8 | } 9 | return typed.find(self, x.valueType())(x.value) 10 | }) 11 | }) 12 | ) 13 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | export * from './entry/mainAny.js' 2 | -------------------------------------------------------------------------------- /src/json/reviver.js: -------------------------------------------------------------------------------- 1 | import { factory } from '../utils/factory.js' 2 | 3 | const name = 'reviver' 4 | const dependencies = [ 5 | 'classes' 6 | ] 7 | 8 | export const createReviver = /* #__PURE__ */ factory(name, dependencies, ({ classes }) => { 9 | /** 10 | * Instantiate mathjs data types from their JSON representation 11 | * @param {string} key 12 | * @param {*} value 13 | * @returns {*} Returns the revived object 14 | */ 15 | return function reviver (key, value) { 16 | const constructor = classes[value && value.mathjs] 17 | 18 | if (constructor && typeof constructor.fromJSON === 'function') { 19 | return constructor.fromJSON(value) 20 | } 21 | 22 | return value 23 | } 24 | }) 25 | -------------------------------------------------------------------------------- /src/number.js: -------------------------------------------------------------------------------- 1 | export * from './entry/mainNumber.js' 2 | -------------------------------------------------------------------------------- /src/plain/bignumber/arithmetic.js: -------------------------------------------------------------------------------- 1 | const signature1 = 'BigNumber' 2 | const signature2 = 'BigNumber, BigNumber' 3 | 4 | export function absBigNumber (a) { 5 | return a.abs() 6 | } 7 | absBigNumber.signature = signature1 8 | 9 | export function addBigNumber (a, b) { 10 | return a.add(b) 11 | } 12 | addBigNumber.signature = signature2 13 | 14 | export function subtractBigNumber (a, b) { 15 | return a.sub(b) 16 | } 17 | subtractBigNumber.signature = signature2 18 | 19 | export function multiplyBigNumber (a, b) { 20 | return a.mul(b) 21 | } 22 | multiplyBigNumber.signature = signature2 23 | 24 | export function divideBigNumber (a, b) { 25 | return a.div(b) 26 | } 27 | divideBigNumber.signature = signature2 28 | -------------------------------------------------------------------------------- /src/plain/bignumber/index.js: -------------------------------------------------------------------------------- 1 | import Decimal from 'decimal.js' 2 | 3 | export * from './arithmetic.js' 4 | 5 | // TODO: this is ugly. Instead, be able to pass your own isBigNumber function to typed? 6 | const BigNumber = Decimal.clone() 7 | BigNumber.prototype.isBigNumber = true 8 | 9 | export function bignumber (x) { 10 | return new BigNumber(x) 11 | } 12 | -------------------------------------------------------------------------------- /src/plain/number/constants.js: -------------------------------------------------------------------------------- 1 | export const pi = Math.PI 2 | export const tau = 2 * Math.PI 3 | export const e = Math.E 4 | export const phi = 1.6180339887498948 // eslint-disable-line no-loss-of-precision 5 | -------------------------------------------------------------------------------- /src/plain/number/index.js: -------------------------------------------------------------------------------- 1 | export * from './arithmetic.js' 2 | export * from './bitwise.js' 3 | export * from './combinations.js' 4 | export * from './constants.js' 5 | export * from './logical.js' 6 | export * from './relational.js' 7 | export * from './probability.js' 8 | export * from './trigonometry.js' 9 | export * from './utils.js' 10 | -------------------------------------------------------------------------------- /src/plain/number/logical.js: -------------------------------------------------------------------------------- 1 | const n1 = 'number' 2 | const n2 = 'number, number' 3 | 4 | export function notNumber (x) { 5 | return !x 6 | } 7 | notNumber.signature = n1 8 | 9 | export function orNumber (x, y) { 10 | return !!(x || y) 11 | } 12 | orNumber.signature = n2 13 | 14 | export function xorNumber (x, y) { 15 | return !!x !== !!y 16 | } 17 | xorNumber.signature = n2 18 | 19 | export function andNumber (x, y) { 20 | return !!(x && y) 21 | } 22 | andNumber.signature = n2 23 | -------------------------------------------------------------------------------- /src/plain/number/relational.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josdejong/mathjs/7933089bd49df092cc5016c46554c4f32fab6bc2/src/plain/number/relational.js -------------------------------------------------------------------------------- /src/plain/number/utils.js: -------------------------------------------------------------------------------- 1 | import { isInteger } from '../../utils/number.js' 2 | 3 | const n1 = 'number' 4 | 5 | export function isIntegerNumber (x) { 6 | return isInteger(x) 7 | } 8 | isIntegerNumber.signature = n1 9 | 10 | export function isNegativeNumber (x) { 11 | return x < 0 12 | } 13 | isNegativeNumber.signature = n1 14 | 15 | export function isPositiveNumber (x) { 16 | return x > 0 17 | } 18 | isPositiveNumber.signature = n1 19 | 20 | export function isZeroNumber (x) { 21 | return x === 0 22 | } 23 | isZeroNumber.signature = n1 24 | 25 | export function isNaNNumber (x) { 26 | return Number.isNaN(x) 27 | } 28 | isNaNNumber.signature = n1 29 | -------------------------------------------------------------------------------- /src/type/unit/function/splitUnit.js: -------------------------------------------------------------------------------- 1 | import { factory } from '../../../utils/factory.js' 2 | 3 | const name = 'splitUnit' 4 | const dependencies = ['typed'] 5 | 6 | export const createSplitUnit = /* #__PURE__ */ factory(name, dependencies, ({ typed }) => { 7 | /** 8 | * Split a unit in an array of units whose sum is equal to the original unit. 9 | * 10 | * Syntax: 11 | * 12 | * math.splitUnit(unit: Unit, parts: Array.) 13 | * 14 | * Example: 15 | * 16 | * math.splitUnit(new Unit(1, 'm'), ['feet', 'inch']) 17 | * // [ 3 feet, 3.3700787401575 inch ] 18 | * 19 | * See also: 20 | * 21 | * unit 22 | * 23 | * @param {Array} [parts] An array of strings or valueless units. 24 | * @return {Array} An array of units. 25 | */ 26 | return typed(name, { 27 | 'Unit, Array': function (unit, parts) { 28 | return unit.splitUnit(parts) 29 | } 30 | }) 31 | }) 32 | -------------------------------------------------------------------------------- /src/utils/complex.js: -------------------------------------------------------------------------------- 1 | import { nearlyEqual } from './number.js' 2 | 3 | /** 4 | * Test whether two complex values are equal provided a given relTol and absTol. 5 | * Does not use or change the global Complex.EPSILON setting 6 | * @param {Complex} x - The first complex number for comparison. 7 | * @param {Complex} y - The second complex number for comparison. 8 | * @param {number} relTol - The relative tolerance for comparison. 9 | * @param {number} absTol - The absolute tolerance for comparison. 10 | * @returns {boolean} - Returns true if the two complex numbers are equal within the given tolerances, otherwise returns false. 11 | */ 12 | export function complexEquals (x, y, relTol, absTol) { 13 | return nearlyEqual(x.re, y.re, relTol, absTol) && nearlyEqual(x.im, y.im, relTol, absTol) 14 | } 15 | -------------------------------------------------------------------------------- /src/utils/emitter.js: -------------------------------------------------------------------------------- 1 | import Emitter from 'tiny-emitter' 2 | 3 | /** 4 | * Extend given object with emitter functions `on`, `off`, `once`, `emit` 5 | * @param {Object} obj 6 | * @return {Object} obj 7 | */ 8 | export function mixin (obj) { 9 | // create event emitter 10 | const emitter = new Emitter() 11 | 12 | // bind methods to obj (we don't want to expose the emitter.e Array...) 13 | obj.on = emitter.on.bind(emitter) 14 | obj.off = emitter.off.bind(emitter) 15 | obj.once = emitter.once.bind(emitter) 16 | obj.emit = emitter.emit.bind(emitter) 17 | 18 | return obj 19 | } 20 | -------------------------------------------------------------------------------- /src/utils/log.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Log a console.warn message only once 3 | */ 4 | export const warnOnce = (() => { 5 | const messages = {} 6 | 7 | return function warnOnce (...args) { 8 | const message = args.join(', ') 9 | 10 | if (!messages[message]) { 11 | messages[message] = true 12 | 13 | console.warn('Warning:', ...args) 14 | } 15 | } 16 | })() 17 | -------------------------------------------------------------------------------- /src/utils/noop.js: -------------------------------------------------------------------------------- 1 | export function noBignumber () { 2 | throw new Error('No "bignumber" implementation available') 3 | } 4 | 5 | export function noFraction () { 6 | throw new Error('No "fraction" implementation available') 7 | } 8 | 9 | export function noMatrix () { 10 | throw new Error('No "matrix" implementation available') 11 | } 12 | 13 | export function noIndex () { 14 | throw new Error('No "index" implementation available') 15 | } 16 | 17 | export function noSubset () { 18 | throw new Error('No "matrix" implementation available') 19 | } 20 | -------------------------------------------------------------------------------- /src/utils/print.js: -------------------------------------------------------------------------------- 1 | export const printTemplate = /\$([\w.]+)/g 2 | -------------------------------------------------------------------------------- /src/utils/product.js: -------------------------------------------------------------------------------- 1 | /** @param {number} i 2 | * @param {number} n 3 | * @returns {number} product of i to n 4 | */ 5 | export function product (i, n) { 6 | if (n < i) { 7 | return 1 8 | } 9 | 10 | if (n === i) { 11 | return n 12 | } 13 | 14 | const half = (n + i) >> 1 // divide (n + i) by 2 and truncate to integer 15 | return product(i, half) * product(half + 1, n) 16 | } 17 | -------------------------------------------------------------------------------- /src/utils/scope.js: -------------------------------------------------------------------------------- 1 | import { ObjectWrappingMap, PartitionedMap } from './map.js' 2 | 3 | /** 4 | * Create a new scope which can access the parent scope, 5 | * but does not affect it when written. This is suitable for variable definitions 6 | * within a block node, or function definition. 7 | * 8 | * If parent scope has a createSubScope method, it delegates to that. Otherwise, 9 | * creates an empty map, and copies the parent scope to it, adding in 10 | * the remaining `args`. 11 | * 12 | * @param {Map} parentScope 13 | * @param {Object} args 14 | * @returns {PartitionedMap} 15 | */ 16 | export function createSubScope (parentScope, args) { 17 | return new PartitionedMap( 18 | parentScope, 19 | new ObjectWrappingMap(args), 20 | new Set(Object.keys(args)) 21 | ) 22 | } 23 | -------------------------------------------------------------------------------- /src/utils/switch.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Transpose a matrix 3 | * @param {Array} mat 4 | * @returns {Array} ret 5 | * @private 6 | */ 7 | export function _switch (mat) { 8 | const I = mat.length 9 | const J = mat[0].length 10 | let i, j 11 | const ret = [] 12 | for (j = 0; j < J; j++) { 13 | const tmp = [] 14 | for (i = 0; i < I; i++) { 15 | tmp.push(mat[i][j]) 16 | } 17 | ret.push(tmp) 18 | } 19 | return ret 20 | } 21 | -------------------------------------------------------------------------------- /src/version.js: -------------------------------------------------------------------------------- 1 | export const version = '14.5.2' 2 | // Note: This file is automatically generated when building math.js. 3 | // Changes made in this file will be overwritten. 4 | -------------------------------------------------------------------------------- /tea.yaml: -------------------------------------------------------------------------------- 1 | # https://tea.xyz/what-is-this-file 2 | --- 3 | version: 1.0.0 4 | codeOwners: 5 | - '0xfeD05d7b2D32D49259bFd15983716e848E805aC6' 6 | quorum: 1 7 | -------------------------------------------------------------------------------- /test/benchmark/derivative.js: -------------------------------------------------------------------------------- 1 | // test performance of derivative 2 | 3 | import { Bench } from 'tinybench' 4 | import { derivative, parse } from '../../lib/esm/index.js' 5 | import { formatTaskResult } from './utils/formatTaskResult.js' 6 | 7 | let expr = parse('0') 8 | for (let i = 1; i <= 5; i++) { 9 | for (let j = 1; j <= 5; j++) { 10 | expr = parse(`${expr} + sin(${i + j} * x ^ ${i} + ${i * j} * y ^ ${j})`) 11 | } 12 | } 13 | 14 | const results = [] 15 | 16 | const bench = new Bench({ time: 100, iterations: 100 }) 17 | .add('ddf', function () { 18 | const res = derivative(derivative(expr, parse('x'), { simplify: false }), parse('x'), { simplify: false }) 19 | results.splice(0, 1, res) 20 | }) 21 | .add('df ', function () { 22 | const res = derivative(expr, parse('x'), { simplify: false }) 23 | results.splice(0, 1, res) 24 | }) 25 | 26 | bench.addEventListener('cycle', (event) => console.log(formatTaskResult(bench, event.task))) 27 | await bench.run() 28 | -------------------------------------------------------------------------------- /test/benchmark/index.js: -------------------------------------------------------------------------------- 1 | // run all benchmarks 2 | import './expression_parser.js' 3 | import './algebra.js' 4 | import './derivative.js' 5 | import './roots.js' 6 | import './matrix_operations.js' 7 | import './prime.js' 8 | import './load.js' 9 | import './scope_variables.js' 10 | import './map.js' 11 | import './forEach.js' 12 | -------------------------------------------------------------------------------- /test/benchmark/matrix_operations_results.txt: -------------------------------------------------------------------------------- 1 | mathjs A+A 21 microseconds 2 | mathjs A*A 288 microseconds 3 | mathjs A' 23 microseconds 4 | mathjs det(A) 10349 microseconds 5 | sylvester A+A 20 microseconds 6 | sylvester A*A 184 microseconds 7 | sylvester A' 11 microseconds 8 | sylvester det(A) 103 microseconds 9 | numericjs A+A 6 microseconds 10 | numericjs A*A 30 microseconds 11 | numericjs A' 3 microseconds 12 | numericjs det(A) 15 microseconds 13 | ndarray A+A 6 microseconds 14 | ndarray A*A 42 microseconds 15 | ndarray A' 4 microseconds 16 | ndarray det(A) 10 microseconds 17 | 18 | -------------------------------------------------------------------------------- /test/benchmark/scope_variables.js: -------------------------------------------------------------------------------- 1 | // test performance of resolving scope variables in the expression parser 2 | 3 | import { Bench } from 'tinybench' 4 | import { evaluate } from '../../lib/esm/index.js' 5 | import { formatTaskResult } from './utils/formatTaskResult.js' 6 | 7 | const scope = { a: 2, b: 3, c: 4 } 8 | const f = evaluate('f(x, y) = a + b + c + x + y', scope) 9 | 10 | console.log('f(5, 6) = ' + f(5, 6)) 11 | 12 | const bench = new Bench({ time: 100, iterations: 100 }) 13 | let res = 0 14 | bench 15 | .add('evaluate f(x, y)', function () { 16 | res = f(-res, res) // make it dynamic, using res as argument 17 | }) 18 | 19 | bench.addEventListener('cycle', (event) => console.log(formatTaskResult(bench, event.task))) 20 | await bench.run() 21 | -------------------------------------------------------------------------------- /test/browser-test-config/browser-tests.test.js: -------------------------------------------------------------------------------- 1 | const testsContext = require.context('../unit-tests/', true, /.test\.js$/) 2 | 3 | testsContext.keys().forEach(testsContext) 4 | -------------------------------------------------------------------------------- /test/browser-test-config/local-karma.js: -------------------------------------------------------------------------------- 1 | const baseKarma = require('./base-karma') 2 | const mochaConfig = require('../../.mocharc.json') 3 | 4 | module.exports = function (config) { 5 | const baseConfig = baseKarma(config) 6 | 7 | config.set(Object.assign(baseConfig, { 8 | browsers: ['FirefoxHeadless'], 9 | 10 | client: { 11 | captureConsole: true, 12 | mocha: { 13 | timeout: mochaConfig.timeout 14 | } 15 | } 16 | })) 17 | } 18 | -------------------------------------------------------------------------------- /test/browser-test-config/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "commonjs" 3 | } 4 | -------------------------------------------------------------------------------- /test/node-tests/cli/script1: -------------------------------------------------------------------------------- 1 | 1+1 2 | -------------------------------------------------------------------------------- /test/node-tests/cli/script2: -------------------------------------------------------------------------------- 1 | 2*4 2 | -------------------------------------------------------------------------------- /test/node-tests/commonjs.test.cjs: -------------------------------------------------------------------------------- 1 | // Only use native node.js API's and references to ./lib here, this file is not transpiled! 2 | const assert = require('assert') 3 | const cp = require('child_process') 4 | const path = require('path') 5 | 6 | describe('lib/cjs', function () { 7 | it('should load via commonjs', function (done) { 8 | const filename = path.join(__dirname, 'commonjsApp.cjs') 9 | cp.exec('node ' + filename, function (error, result) { 10 | assert.strictEqual(error, null) 11 | assert.strictEqual(result, '2\n2i\n') 12 | done() 13 | }) 14 | }) 15 | 16 | it('should load numbers only via commonjs', function (done) { 17 | const filename = path.join(__dirname, 'commonjsAppNumberOnly.cjs') 18 | cp.exec('node ' + filename, function (error, result) { 19 | assert.strictEqual(error, null) 20 | assert.strictEqual(result, '2\nNaN\n2\n4\n7\n') 21 | done() 22 | }) 23 | }) 24 | }) 25 | -------------------------------------------------------------------------------- /test/node-tests/commonjsApp.cjs: -------------------------------------------------------------------------------- 1 | const { sqrt, format } = require('../..') 2 | 3 | console.log(format(sqrt(4))) 4 | console.log(format(sqrt(-4))) 5 | -------------------------------------------------------------------------------- /test/node-tests/commonjsAppNumberOnly.cjs: -------------------------------------------------------------------------------- 1 | const { e, floor, format, log, sqrt } = require('../../lib/cjs/number.js') 2 | 3 | console.log(format(sqrt(4))) 4 | console.log(format(sqrt(-4))) 5 | console.log(format(log(e * e))) 6 | console.log(format(log(625, 5))) 7 | console.log(format(floor(7 - 1e-13))) 8 | -------------------------------------------------------------------------------- /test/node-tests/esmApp.js: -------------------------------------------------------------------------------- 1 | // TODO: would be nice to call '../../' so we know for sure ESM is correctly exported 2 | import { sqrt, format } from '../../lib/esm/index.js' 3 | 4 | console.log(format(sqrt(4))) 5 | console.log(format(sqrt(-4))) 6 | -------------------------------------------------------------------------------- /test/node-tests/esmAppNumberOnly.js: -------------------------------------------------------------------------------- 1 | // TODO: would be nice to call '../../' so we know for sure ESM is correctly exported 2 | import { e, floor, format, log, sqrt } from '../../lib/esm/number.js' 3 | 4 | console.log(format(sqrt(4))) 5 | console.log(format(sqrt(-4))) 6 | console.log(format(log(e * e))) 7 | console.log(format(log(625, 5))) 8 | console.log(format(floor(7 - 1e-13))) 9 | -------------------------------------------------------------------------------- /test/node-tests/pollutedObjectPrototype.js: -------------------------------------------------------------------------------- 1 | // let's pollute the Object prototype... 2 | 3 | /* eslint no-extend-native: ["error", { "exceptions": ["Object"] }] */ 4 | // loading mathjs should not crash 5 | import { create, all } from '../../lib/esm/entry/mainAny' 6 | 7 | Object.prototype.foo = () => {} 8 | const math = create(all) 9 | 10 | // outputs '2i' 11 | console.log(math.format(math.sqrt(-4))) 12 | -------------------------------------------------------------------------------- /test/node-tests/treeShaking/.gitignore: -------------------------------------------------------------------------------- 1 | *.bundle.js 2 | *.bundle.js.LICENSE.txt 3 | -------------------------------------------------------------------------------- /test/node-tests/treeShaking/treeShakingApp.js: -------------------------------------------------------------------------------- 1 | import { abs } from '../../../lib/esm/index.js' 2 | 3 | console.log(abs(-3)) 4 | -------------------------------------------------------------------------------- /test/unit-tests/core/index.test.js: -------------------------------------------------------------------------------- 1 | // TODO: test core 2 | -------------------------------------------------------------------------------- /test/unit-tests/expression/function/parser.test.js: -------------------------------------------------------------------------------- 1 | import assert from 'assert' 2 | import math from '../../../../src/defaultInstance.js' 3 | const Parser = math.Parser 4 | 5 | describe('parser', function () { 6 | it('should create a parser', function () { 7 | const parser = math.parser() 8 | 9 | assert(parser instanceof Parser) 10 | }) 11 | 12 | it('should LaTeX parser', function () { // This doesn't really make sense in a way 13 | const expression = math.parse('parser()') 14 | assert.strictEqual(expression.toTex(), '\\mathrm{parser}\\left(\\right)') 15 | }) 16 | }) 17 | -------------------------------------------------------------------------------- /test/unit-tests/expression/keywords.test.js: -------------------------------------------------------------------------------- 1 | // test keywords 2 | import assert from 'assert' 3 | 4 | import { keywords } from '../../../src/expression/keywords.js' 5 | 6 | describe('keywords', function () { 7 | it('should return a map with reserved keywords', function () { 8 | assert.deepStrictEqual([...keywords].sort(), ['end'].sort()) 9 | }) 10 | }) 11 | -------------------------------------------------------------------------------- /test/unit-tests/function/algebra/leafCount.test.js: -------------------------------------------------------------------------------- 1 | import assert from 'assert' 2 | import math from '../../../../src/defaultInstance.js' 3 | 4 | describe('leafCount', function () { 5 | it('handles nodes', function () { 6 | assert.strictEqual(math.leafCount(new math.SymbolNode('x')), 1) 7 | assert.strictEqual(math.leafCount(math.parse('2+y')), 2) 8 | assert.strictEqual(math.leafCount(math.parse('[3,a+5,2/2,z]')), 6) 9 | }) 10 | 11 | it('handles strings', function () { 12 | assert.strictEqual(math.leafCount('3x^2-7x+2'), 6) 13 | assert.strictEqual(math.leafCount('13 < m+n < abs(n^2-m^2)'), 8) 14 | }) 15 | 16 | it('can be used in an expression', function () { 17 | assert(math.evaluate('leafCount("identity(2)[0,1]") == 4')) 18 | assert.strictEqual(math.evaluate('leafCount("{a: 7, b: x}.b")'), 3) 19 | }) 20 | }) 21 | -------------------------------------------------------------------------------- /test/unit-tests/function/matrix/ifft.test.js: -------------------------------------------------------------------------------- 1 | // test ifft 2 | 3 | import { approxDeepEqual } from '../../../../tools/approx.js' 4 | import math from '../../../../src/defaultInstance.js' 5 | const ifft = math.ifft 6 | 7 | describe('ifft', function () { 8 | it('should calculate 1-dimensional inverse Fourier transformation', function () { 9 | approxDeepEqual(ifft([2, math.complex(-2, -2), math.complex(0, -2), math.complex(4, 4)]), [1, math.complex(2, -1), math.complex(0, -1), math.complex(-1, 2)]) 10 | }) 11 | 12 | it('should calculate multidimensional inverse Fourier transformation', function () { 13 | const in1 = [ 14 | [1, 0], 15 | [1, 0] 16 | ] 17 | approxDeepEqual(math.fft(ifft(in1.valueOf())), in1.valueOf()) 18 | approxDeepEqual(math.fft(ifft(math.matrix(in1))), math.matrix(in1)) 19 | }) 20 | }) 21 | -------------------------------------------------------------------------------- /test/unit-tests/type/chain/function/chain.test.js: -------------------------------------------------------------------------------- 1 | import assert from 'assert' 2 | import math from '../../../../../src/defaultInstance.js' 3 | const Chain = math.Chain 4 | 5 | describe('chain', function () { 6 | it('should construct a chain', function () { 7 | assert.ok(math.chain(45) instanceof Chain) 8 | assert.ok(math.chain(math.complex(2, 3)) instanceof Chain) 9 | assert.ok(math.chain() instanceof Chain) 10 | }) 11 | 12 | it('should LaTeX chain', function () { 13 | const expression = math.parse('chain(1)') 14 | assert.strictEqual(expression.toTex(), '\\mathrm{chain}\\left(1\\right)') 15 | }) 16 | }) 17 | -------------------------------------------------------------------------------- /test/unit-tests/type/matrix/collection.test.js: -------------------------------------------------------------------------------- 1 | import assert from 'assert' 2 | import { isCollection } from '../../../../src/utils/is.js' 3 | import math from '../../../../src/defaultInstance.js' 4 | const DenseMatrix = math.DenseMatrix 5 | const SparseMatrix = math.SparseMatrix 6 | 7 | describe('isCollection', function () { 8 | it('should test whether an object is a collection', function () { 9 | assert.strictEqual(isCollection([]), true) 10 | assert.strictEqual(isCollection({}), false) 11 | assert.strictEqual(isCollection(2), false) 12 | assert.strictEqual(isCollection(new DenseMatrix()), true) 13 | assert.strictEqual(isCollection(new SparseMatrix()), true) 14 | }) 15 | }) 16 | -------------------------------------------------------------------------------- /test/unit-tests/type/unit/function/splitUnit.test.js: -------------------------------------------------------------------------------- 1 | import assert from 'assert' 2 | import math from '../../../../../src/defaultInstance.js' 3 | const splitUnit = math.splitUnit 4 | const Unit = math.Unit 5 | 6 | describe('splitUnit', function () { 7 | it('should split a unit into parts', function () { 8 | assert.strictEqual(splitUnit(new Unit(1, 'm'), ['ft', 'in']).toString(), '3 ft,3.3700787401574765 in') 9 | assert.strictEqual(splitUnit(new Unit(-1, 'm'), ['ft', 'in']).toString(), '-3 ft,-3.3700787401574765 in') 10 | assert.strictEqual(splitUnit(new Unit(1, 'm/s'), ['m/s']).toString(), '1 m / s') 11 | 12 | assert.strictEqual(math.evaluate('splitUnit(1 m, [ft, in])').toString(), '3 ft,3.3700787401574765 in') 13 | }) 14 | }) 15 | -------------------------------------------------------------------------------- /test/unit-tests/utils/latex.test.js: -------------------------------------------------------------------------------- 1 | import assert from 'assert' 2 | import { toSymbol } from '../../../src/utils/latex.js' 3 | 4 | describe('util.latex', function () { 5 | it('should convert symbols with underscores', function () { 6 | assert.strictEqual(toSymbol('alpha_1'), 'alpha\\_1') 7 | }) 8 | 9 | it('should convert special units', function () { 10 | assert.strictEqual(toSymbol('deg', true), '^\\circ') 11 | }) 12 | 13 | it('should convert normal units', function () { 14 | assert.strictEqual(toSymbol('cm', true), '\\mathrm{cm}') 15 | }) 16 | 17 | it('should escape strings', function () { 18 | const string = 'space tab\tunderscore_bla$/' 19 | 20 | assert.strictEqual(toSymbol(string), 'space~tab\\qquad{}underscore\\_bla\\$/') 21 | }) 22 | }) 23 | -------------------------------------------------------------------------------- /tools/utils.js: -------------------------------------------------------------------------------- 1 | 2 | // helper function to safely check whether an object as a property 3 | // copy from the function in object.js which is ES6 4 | export function hasOwnProperty (object, property) { 5 | return object && Object.hasOwnProperty.call(object, property) 6 | } 7 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": ".", 4 | "target": "ES6", 5 | "paths": { 6 | "mathjs": ["./types/index.d.ts"] 7 | }, 8 | "moduleResolution": "nodenext", 9 | "typeRoots": [], 10 | "types": [], 11 | "lib": [ 12 | "ES6", 13 | "DOM", 14 | "es2020.bigint" 15 | ], 16 | "module": "NodeNext", 17 | "noEmit": true, 18 | "noImplicitAny": true, 19 | "noImplicitThis": true, 20 | "strictNullChecks": false, 21 | "strictFunctionTypes": true, 22 | "forceConsistentCasingInFileNames": true 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /types/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "dtslint/dtslint.json", 3 | "rules": { 4 | "no-redundant-jsdoc": false 5 | } 6 | } 7 | --------------------------------------------------------------------------------