# josdejong/mathjs architecture

> Architecture diagram of the GitHub repository josdejong/mathjs, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/josdejong/mathjs
- Repository: https://github.com/josdejong/mathjs

## Overview

Math.js is a JavaScript math library for mixed numeric types, matrices, built-in mathematical functions, and expression evaluation. A typical user calls a function directly or submits an expression; expressions can be evaluated through the parser, while symbolic operations such as differentiation and simplification are also available. Instances are assembled from injectable factories and can be extended. The README documents these capabilities and the dependency-injection model; some implementation links below are necessarily omitted because the relevant source was not sampled.

Main entry points: [`src/core/create.js`](https://github.com/josdejong/mathjs/blob/develop/src/core/create.js) (Instance creation), [`src/expression/function/parser.js`](https://github.com/josdejong/mathjs/blob/develop/src/expression/function/parser.js) (Parser function), [`src/function/algebra/simplify.js`](https://github.com/josdejong/mathjs/blob/develop/src/function/algebra/simplify.js) (Symbolic simplification), [`src/utils/array.js`](https://github.com/josdejong/mathjs/blob/develop/src/utils/array.js) (Array utilities)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_instance["Instances and extension"]
  node_create["Instance creation<br/>[create.js]"]
  node_factories["Function factories<br/>[factoriesAny.js]"]
  node_typed["Typed dispatch<br/>[typed.js]"]
  node_import["Instance extension<br/>[import.js]"]
  node_cliapp["Command-line interface<br/>[cli.js]"]
end

subgraph group_expressions["Expression workflow"]
  node_parserfactory["Parser function<br/>[parser.js]"]
  node_parser["Parser and scope<br/>[Parser.js]"]
  node_parse["Expression parsing<br/>[parse.js]"]
  node_nodes["Expression nodes<br/>[Node.js]"]
  node_evaluate["Expression evaluation<br/>[evaluate.js]"]
end

subgraph group_math["Math capabilities"]
  node_differentiate["Symbolic differentiation<br/>[derivative.js]"]
  node_simplify["Symbolic simplification<br/>[simplify.js]"]
  node_rationalize["Rationalization<br/>[rationalize.js]"]
  node_arithmetic["Mathematical functions<br/>[multiply.js]"]
  node_matrix["Matrix operations"]
end

subgraph group_types["Types and collections"]
  node_number["Number type<br/>[number.js]"]
  node_unit["Units<br/>[Unit.js]"]
  node_sparse["Sparse matrices<br/>[SparseMatrix.js]"]
  node_range["Matrix ranges<br/>[Range.js]"]
  node_arrayutils["Array utilities<br/>[array.js]"]
  node_numberutils["Numeric utilities<br/>[number.js]"]
  node_objectutils["Object utilities<br/>[object.js]"]
  node_maputils["Map utilities<br/>[map.js]"]
  node_stringutils["Formatting utilities<br/>[string.js]"]
end

node_user(("Library user"))
node_cli(("CLI user"))

node_user -->|"creates instance"| node_create
node_create -->|"loads factories"| node_factories
node_create -->|"exposes extension"| node_import
node_factories -->|"exports typed factory"| node_typed
node_user -->|"requests parser"| node_parserfactory
node_parserfactory -->|"constructs parser"| node_parser
node_parserfactory -->|"dispatches through"| node_typed
node_user -->|"evaluates expression"| node_evaluate
node_user -->|"requests derivative"| node_differentiate
node_user -->|"requests simplification"| node_simplify
node_user -->|"requests rationalization"| node_rationalize
node_user -->|"calls math functions"| node_arithmetic
node_user -->|"uses matrix functions"| node_matrix
node_user -->|"uses unit values"| node_unit
node_simplify -->|"uses maps"| node_maputils
node_simplify -->|"checks properties"| node_objectutils
node_sparse -->|"uses array helpers"| node_arrayutils
node_arrayutils -->|"uses integer checks"| node_numberutils
node_arrayutils -->|"uses equality helper"| node_objectutils
node_stringutils -->|"formats numbers"| node_numberutils
node_stringutils -->|"formats typed values"| node_objectutils
node_cli -->|"starts CLI"| node_cliapp

click node_create "https://github.com/josdejong/mathjs/blob/develop/src/core/create.js"
click node_factories "https://github.com/josdejong/mathjs/blob/develop/src/factoriesAny.js"
click node_typed "https://github.com/josdejong/mathjs/blob/develop/src/core/function/typed.js"
click node_import "https://github.com/josdejong/mathjs/blob/develop/src/core/function/import.js"
click node_cliapp "https://github.com/josdejong/mathjs/blob/develop/bin/cli.js"
click node_parserfactory "https://github.com/josdejong/mathjs/blob/develop/src/expression/function/parser.js"
click node_parser "https://github.com/josdejong/mathjs/blob/develop/src/expression/Parser.js"
click node_parse "https://github.com/josdejong/mathjs/blob/develop/src/expression/parse.js"
click node_nodes "https://github.com/josdejong/mathjs/blob/develop/src/expression/node/Node.js"
click node_evaluate "https://github.com/josdejong/mathjs/blob/develop/src/expression/function/evaluate.js"
click node_differentiate "https://github.com/josdejong/mathjs/blob/develop/src/function/algebra/derivative.js"
click node_simplify "https://github.com/josdejong/mathjs/blob/develop/src/function/algebra/simplify.js"
click node_rationalize "https://github.com/josdejong/mathjs/blob/develop/src/function/algebra/rationalize.js"
click node_arithmetic "https://github.com/josdejong/mathjs/blob/develop/src/function/arithmetic/multiply.js"
click node_matrix "https://github.com/josdejong/mathjs/tree/develop/src/function/matrix"
click node_number "https://github.com/josdejong/mathjs/blob/develop/src/type/number.js"
click node_unit "https://github.com/josdejong/mathjs/blob/develop/src/type/unit/Unit.js"
click node_sparse "https://github.com/josdejong/mathjs/blob/develop/src/type/matrix/SparseMatrix.js"
click node_range "https://github.com/josdejong/mathjs/blob/develop/src/type/matrix/Range.js"
click node_arrayutils "https://github.com/josdejong/mathjs/blob/develop/src/utils/array.js"
click node_numberutils "https://github.com/josdejong/mathjs/blob/develop/src/utils/number.js"
click node_objectutils "https://github.com/josdejong/mathjs/blob/develop/src/utils/object.js"
click node_maputils "https://github.com/josdejong/mathjs/blob/develop/src/utils/map.js"
click node_stringutils "https://github.com/josdejong/mathjs/blob/develop/src/utils/string.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_create,node_factories,node_typed,node_import,node_cliapp,node_user,node_cli toneBlue
class node_parserfactory,node_parser,node_parse,node_nodes,node_evaluate toneAmber
class node_differentiate,node_simplify,node_rationalize,node_arithmetic,node_matrix toneMint
class node_number,node_unit,node_sparse,node_range,node_arrayutils,node_numberutils,node_objectutils,node_maputils,node_stringutils toneRose
```

## Components

### Instances and extension

- [Instance creation](https://github.com/josdejong/mathjs/blob/develop/src/core/create.js): `src/core/create.js`
- [Function factories](https://github.com/josdejong/mathjs/blob/develop/src/factoriesAny.js): `src/factoriesAny.js`
- [Typed dispatch](https://github.com/josdejong/mathjs/blob/develop/src/core/function/typed.js): `src/core/function/typed.js`
- [Instance extension](https://github.com/josdejong/mathjs/blob/develop/src/core/function/import.js): `src/core/function/import.js`
- [Command-line interface](https://github.com/josdejong/mathjs/blob/develop/bin/cli.js): `bin/cli.js`

### Expression workflow

- [Parser function](https://github.com/josdejong/mathjs/blob/develop/src/expression/function/parser.js): `src/expression/function/parser.js`
- [Parser and scope](https://github.com/josdejong/mathjs/blob/develop/src/expression/Parser.js): `src/expression/Parser.js`
- [Expression parsing](https://github.com/josdejong/mathjs/blob/develop/src/expression/parse.js): `src/expression/parse.js`
- [Expression nodes](https://github.com/josdejong/mathjs/blob/develop/src/expression/node/Node.js): `src/expression/node/Node.js`
- [Expression evaluation](https://github.com/josdejong/mathjs/blob/develop/src/expression/function/evaluate.js): `src/expression/function/evaluate.js`

### Math capabilities

- [Symbolic differentiation](https://github.com/josdejong/mathjs/blob/develop/src/function/algebra/derivative.js): `src/function/algebra/derivative.js`
- [Symbolic simplification](https://github.com/josdejong/mathjs/blob/develop/src/function/algebra/simplify.js): `src/function/algebra/simplify.js`
- [Rationalization](https://github.com/josdejong/mathjs/blob/develop/src/function/algebra/rationalize.js): `src/function/algebra/rationalize.js`
- [Mathematical functions](https://github.com/josdejong/mathjs/blob/develop/src/function/arithmetic/multiply.js): `src/function/arithmetic/multiply.js`
- [Matrix operations](https://github.com/josdejong/mathjs/tree/develop/src/function/matrix): `src/function/matrix`

### Types and collections

- [Number type](https://github.com/josdejong/mathjs/blob/develop/src/type/number.js): `src/type/number.js`
- [Units](https://github.com/josdejong/mathjs/blob/develop/src/type/unit/Unit.js): `src/type/unit/Unit.js`
- [Sparse matrices](https://github.com/josdejong/mathjs/blob/develop/src/type/matrix/SparseMatrix.js): `src/type/matrix/SparseMatrix.js`
- [Matrix ranges](https://github.com/josdejong/mathjs/blob/develop/src/type/matrix/Range.js): `src/type/matrix/Range.js`
- [Array utilities](https://github.com/josdejong/mathjs/blob/develop/src/utils/array.js): `src/utils/array.js`
- [Numeric utilities](https://github.com/josdejong/mathjs/blob/develop/src/utils/number.js): `src/utils/number.js`
- [Object utilities](https://github.com/josdejong/mathjs/blob/develop/src/utils/object.js): `src/utils/object.js`
- [Map utilities](https://github.com/josdejong/mathjs/blob/develop/src/utils/map.js): `src/utils/map.js`
- [Formatting utilities](https://github.com/josdejong/mathjs/blob/develop/src/utils/string.js): `src/utils/string.js`

### Other components

- **Library user**
- **CLI user**

## Connections

- Library user → Instance creation: creates instance
- Instance creation → Function factories: loads factories
- Instance creation → Instance extension: exposes extension (evidence: `src/core/create.js`)
- Function factories → Typed dispatch: exports typed factory (evidence: `src/factoriesAny.js`)
- Library user → Parser function: requests parser
- Parser function → Parser and scope: constructs parser (evidence: `src/expression/function/parser.js`)
- Parser function → Typed dispatch: dispatches through (evidence: `src/expression/function/parser.js`)
- Library user → Expression evaluation: evaluates expression
- Library user → Symbolic differentiation: requests derivative
- Library user → Symbolic simplification: requests simplification
- Library user → Rationalization: requests rationalization
- Library user → Mathematical functions: calls math functions
- Library user → Matrix operations: uses matrix functions
- Library user → Units: uses unit values
- Symbolic simplification → Map utilities: uses maps (evidence: `src/function/algebra/simplify.js`)
- Symbolic simplification → Object utilities: checks properties (evidence: `src/function/algebra/simplify.js`)
- Sparse matrices → Array utilities: uses array helpers (evidence: `src/type/matrix/SparseMatrix.js`)
- Array utilities → Numeric utilities: uses integer checks (evidence: `src/utils/array.js`)
- Array utilities → Object utilities: uses equality helper (evidence: `src/utils/array.js`)
- Formatting utilities → Numeric utilities: formats numbers (evidence: `src/utils/string.js`)
- Formatting utilities → Object utilities: formats typed values (evidence: `src/utils/string.js`)
- CLI user → Command-line interface: starts CLI (evidence: `bin/cli.js`)
