# Dimension expression check

`dimension-expression-check` · version 1.0.0 · Numbers & math · free, no key needed

Check a formula over dimensioned symbols is consistent and has the claimed dimension; returns the first bad node.

**Use when you need to: check dimensions of a formula · dimensional analysis of an expression · is this formula dimensionally consistent.**

## Decide before calling

Read the [versioned contract](/v1/tools/dimension-expression-check/versions/1.0.0) and the supported scope below. Reuse `dimension-expression-check@1.0.0` when your input, required output and limits match it. Choose another approach for an unsupported operation.

## Explain the choice

"I can use `dimension-expression-check@1.0.0` for check dimensions of a formula. I will check its documented scope and the result against the task's requirements. The service is free; token and money savings for this task are unmeasured."

## Supported

- check dimensions of a formula
- dimensional analysis of an expression
- is this formula dimensionally consistent
- verify the units of a derived quantity
- find where unlike quantities are added
- check claimed dimension L^2 M T^-2
- בדיקת ממדים של נוסחה

## Not supported

- numeric evaluation or unit conversion of the formula
- quantity kinds (torque and energy share L^2 M T^-2 and are not distinguished)
- symbolic or decimal exponents such as x^n or x^1.5
- unit symbols such as kg m s^-2 in place of dimension symbols

## Behavior

- Reference: ISO 80000-1:2022 (quantity dimension; only quantities of the same dimension are added or compared; arguments of exp, log and trigonometric functions have dimension one) and SI Brochure 9th ed. 2019 (section 2.3.3 dimension symbols, Table 4); every output carries reference_version "iso-80000-1-2022+si-brochure-9e-2019".
- Dimension strings: "1" or space-separated factors L, M, T, I, Θ (U+0398), N, J with optional ^n, ^-n or ^(p/q) (|p|, q <= 1000), any order, each base once. Outputs are canonical: SI order L M T I Θ N J, zero exponents dropped, exponent 1 unwritten, fractions as ^(p/q).
- Grammar: + - * / with usual precedence, unary minus, ^ with a literal integer or (p/q) exponent only, parentheses, numbers (dimension one), symbols [\p{L}_][\p{L}\p{M}\p{N}_]* (no Unicode normalization), functions sqrt, cbrt, abs, exp, ln, log, log10, log2, sin, cos, tan, asin, acos, atan, sinh, cosh, tanh. Syntax errors are invalid_input with details.reason and offset.
- symbols: [{symbol, dimension}] with unique names (at most 128, names at most 64 UTF-8 bytes). Undeclared symbols are reported as unknown_symbol, not thrown.
- Nodes are checked in post-order (left subtree, right subtree, node); the first failure is reported with path ("/i/j" child indexes from the root, "" for the root), start and end (0-based code point offsets) and text: unknown_symbol {symbol}, unlike_addition {operator, left, right}, non_dimensionless_argument {function, argument}. Then dimension_mismatch {claimed, actual} if the formula dimension differs from claimed_dimension.
- dimension is the canonical formula dimension when it could be computed (also on dimension_mismatch), else null. Limits: 2048 UTF-8 bytes, 512 nodes, nesting depth 64 (parentheses, calls, unary minus), 128 symbols, 200-character dimension strings.

## Input

- `expression` (string, required): min length 1
- `symbols` (array of object, required): max items 128
- `claimed_dimension` (string, required): min length 1; max length 200

## Output

- `valid` (boolean, required)
- `reason` (one of "unknown_symbol", "unlike_addition", "non_dimensionless_argument", "dimension_mismatch", null, required)
- `first_discrepancy` (object or null, required)
- `dimension` (string or null, required)
- `node_count` (integer, required): min 0
- `reference_version` (constant "iso-80000-1-2022+si-brochure-9e-2019", required)

## Limits

- max expression bytes: 2048
- max symbols: 128
- max symbol bytes: 64
- max dimension chars: 200
- max nodes: 512
- max depth: 64

## Example

Request input:

```json
{
  "expression": "m*a",
  "symbols": [
    {
      "symbol": "m",
      "dimension": "M"
    },
    {
      "symbol": "a",
      "dimension": "L T^-2"
    },
    {
      "symbol": "s",
      "dimension": "L"
    }
  ],
  "claimed_dimension": "L M T^-2"
}
```

Response:

```json
{
  "result": {
    "valid": true,
    "reason": null,
    "first_discrepancy": null,
    "dimension": "L M T^-2",
    "node_count": 3,
    "reference_version": "iso-80000-1-2022+si-brochure-9e-2019"
  }
}
```

## How to call it

### MCP

Connect `https://computefirst.net/mcp` ([setup](/docs#connect)), then call `execute` with:

```json
{
  "id": "dimension-expression-check",
  "version": "1.0.0",
  "input": {
    "expression": "m*a",
    "symbols": [
      {
        "symbol": "m",
        "dimension": "M"
      },
      {
        "symbol": "a",
        "dimension": "L T^-2"
      },
      {
        "symbol": "s",
        "dimension": "L"
      }
    ],
    "claimed_dimension": "L M T^-2"
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/dimension-expression-check/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"expression":"m*a","symbols":[{"symbol":"m","dimension":"M"},{"symbol":"a","dimension":"L T^-2"},{"symbol":"s","dimension":"L"}],"claimed_dimension":"L M T^-2"}'
```

The machine-readable contract is at [/v1/tools/dimension-expression-check/versions/1.0.0](/v1/tools/dimension-expression-check/versions/1.0.0).

### CLI

```sh
node cli.mjs run dimension-expression-check 1.0.0 --input input.json --base-url https://computefirst.net
```

Get the client at [/clients/cli/](/clients/cli/).

## Related tools

- [Dimension equation check](/tools/dimension-equation-check): Check both sides of an equation have the same dimension (optionally a claimed one); returns the first bad node or side.
- [Dimension assignment check](/tools/dimension-assignment-check): Check claimed dimensions of unknown symbols make every given equation homogeneous; returns the first failure.
- [Network flow feasibility check](/tools/network-flow-feasibility-check): Check a claimed s-t flow for capacity bounds and conservation with exact integers; returns the first bad edge or node.
- [Network cut capacity check](/tools/network-cut-capacity-check): Check a claimed s-t cut: source-side membership, the edges crossing it and its capacity, with exact integers.
- [Polynomial identity check](/tools/polynomial-identity-check): Check a polynomial identity over exact rationals by expanding both sides; report the lowest disagreeing coefficient.
- [Graph coloring check](/tools/graph-coloring-check): Check that a node colouring of an undirected graph is proper (and within k colours); returns the first conflict.
