# Matrix add

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

Add two equal-shape finite-number matrices elementwise.

**Use when you need to: matrix addition · elementwise matrix sum.**

## Supported

- matrix addition
- elementwise matrix sum

## 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 sum 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": [
    [
      1,
      2
    ],
    [
      3,
      4
    ]
  ],
  "b": [
    [
      5,
      6
    ],
    [
      7,
      8
    ]
  ]
}
```

Response:

```json
{
  "result": {
    "result": [
      [
        6,
        8
      ],
      [
        10,
        12
      ]
    ]
  }
}
```

## How to call it

### MCP

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

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

### HTTP (no key)

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

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

### CLI

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

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

## Related tools

- [Vector add](/tools/vector-add): Add two equal-length finite-number vectors elementwise.
- [Matrix hadamard](/tools/matrix-hadamard): Multiply two equal-shape finite-number matrices elementwise (Hadamard product).
- [Matrix subtract](/tools/matrix-subtract): Subtract two equal-shape finite-number matrices elementwise (a minus b).
- [Matrix trace](/tools/matrix-trace): Compute the trace (sum of diagonal entries) of a square finite-number matrix.
- [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.
