# Multiset difference check

`multiset-difference-check` · version 1.0.0 · Numbers & math · free, no key needed

Check claimed left-only and right-only scalar bag differences in deterministic source order.

**Use when you need to: check multiset difference claim · validate bag subtraction result · check left and right residuals.**

## Decide before calling

Read the [versioned contract](/v1/tools/multiset-difference-check/versions/1.0.0) and the supported scope below. Reuse `multiset-difference-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 `multiset-difference-check@1.0.0` for check multiset difference claim. 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 multiset difference claim
- validate bag subtraction result
- check left and right residuals
- verify duplicate difference
- audit claimed array difference
- compare claimed bag delta

## Not supported

- compute a replacement claim
- compare nested JSON values

## Behavior

- Bag subtraction removes matching occurrences one for one using RFC 8785 scalar serialization; -0 equals 0.
- Residuals must appear in their original source order; left_only is checked completely before right_only.
- Missing positions use null as the representable absence marker in discrepancies; null data remains distinguished by the path and list length.
- Every output names ISO/IEC 9075-2:2023 multiset terminology; RFC 8785 (JCS), June 2020.

## Input

- `left` (array of string or number or boolean or null, required): max items 10000
- `right` (array of string or number or boolean or null, required): max items 10000
- `claim` (object, required)

## Output

- `valid` (boolean, required)
- `reason` (one of "claim_mismatch", optional)
- `discrepancy` (object, optional)
- `reference_version` (constant "ISO/IEC 9075-2:2023 multiset terminology; RFC 8785 (JCS), June 2020", required)

## Limits

- max items: 10000
- max distinct: 10000

## Example

Request input:

```json
{
  "left": [
    "a",
    "a",
    "b"
  ],
  "right": [
    "a",
    "c"
  ],
  "claim": {
    "left_only": [
      "a",
      "b"
    ],
    "right_only": [
      "c"
    ]
  }
}
```

Response:

```json
{
  "result": {
    "valid": true,
    "reference_version": "ISO/IEC 9075-2:2023 multiset terminology; RFC 8785 (JCS), June 2020"
  }
}
```

## How to call it

### MCP

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

```json
{
  "id": "multiset-difference-check",
  "version": "1.0.0",
  "input": {
    "left": [
      "a",
      "a",
      "b"
    ],
    "right": [
      "a",
      "c"
    ],
    "claim": {
      "left_only": [
        "a",
        "b"
      ],
      "right_only": [
        "c"
      ]
    }
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/multiset-difference-check/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"left":["a","a","b"],"right":["a","c"],"claim":{"left_only":["a","b"],"right_only":["c"]}}'
```

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

### CLI

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

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

## Related tools

- [Multiset equality check](/tools/multiset-equality-check): Check whether a claimed array has exactly the same canonical JSON scalar multiplicities as a source array.
- [Dedupe first check](/tools/dedupe-first-check): Check an exact first-wins SameValueZero deduplication claim and report its first discrepancy.
- [Dedupe keyed check](/tools/dedupe-keyed-check): Check an exact keyed Map deduplication claim and report its first discrepancy.
- [Dedupe last check](/tools/dedupe-last-check): Check an exact last-wins SameValueZero deduplication claim and report its first discrepancy.
- [Join left result check](/tools/join-left-result-check): Check a claimed ordered left join index result and report its first discrepancy.
- [Multiset counts check](/tools/multiset-counts-check): Check an exact claimed multiplicity table for canonical JSON scalars in first-occurrence order.
