# Matrix subtract

`matrix-subtract` · version 1.0.0 · Vectors & matrices · free, no key needed

Subtract two equal-shape finite-number matrices elementwise (a minus b).

**Use when you need to: matrix subtraction · elementwise matrix difference.**

## Supported

- matrix subtraction
- elementwise matrix difference

## Not supported

- matrices of different shapes
- sparse matrix representation
- arbitrary-precision arithmetic

## Behavior

- Inputs a and b are rectangular arrays of rows of finite JSON numbers with identical row and column counts (1 to 20 each), magnitude bounded to at most 1000000.
- The result is the elementwise IEEE-754 double-precision difference result[r][c] = a[r][c] - b[r][c].
- A result entry of -0 is normalized to 0.

## Input

- `a` (array of array of number, required): min items 1; max items 20
- `b` (array of array of number, required): min items 1; max items 20

## Output

- `result` (array of array of number, required)

## Limits

- max rows: 20
- max cols: 20
- max abs value: 1000000

## Example

Request input:

```json
{
  "a": [
    [
      5,
      6
    ],
    [
      7,
      8
    ]
  ],
  "b": [
    [
      1,
      2
    ],
    [
      3,
      4
    ]
  ]
}
```

Response:

```json
{
  "result": {
    "result": [
      [
        4,
        4
      ],
      [
        4,
        4
      ]
    ]
  }
}
```

## How to call it

### MCP

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

```json
{
  "id": "matrix-subtract",
  "version": "1.0.0",
  "input": {
    "a": [
      [
        5,
        6
      ],
      [
        7,
        8
      ]
    ],
    "b": [
      [
        1,
        2
      ],
      [
        3,
        4
      ]
    ]
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/matrix-subtract/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"a":[[5,6],[7,8]],"b":[[1,2],[3,4]]}'
```

The machine-readable contract is at [/v1/tools/matrix-subtract/versions/1.0.0](/v1/tools/matrix-subtract/versions/1.0.0).

### CLI

```sh
node cli.mjs run matrix-subtract 1.0.0 --input input.json --base-url https://computefirst.net
```

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

## Related tools

- [Vector subtract](/tools/vector-subtract): Subtract two equal-length finite-number vectors elementwise (a minus b).
- [Matrix add](/tools/matrix-add): Add two equal-shape finite-number matrices elementwise.
- [Matrix hadamard](/tools/matrix-hadamard): Multiply two equal-shape finite-number matrices elementwise (Hadamard product).
- [Matrix determinant](/tools/matrix-determinant): Compute the determinant of a small square finite-number matrix.
- [Matrix identity](/tools/matrix-identity): Construct the NxN identity matrix for a given size.
- [Matrix inverse](/tools/matrix-inverse): Compute the inverse of a small square finite-number matrix.
