# Rational subtract

`rational-subtract` · version 1.0.0 · Numbers & math · free, no key needed

Subtract one rational number from another, given as numerator/denominator integer strings, and return the reduced difference.

**Use when you need to: rational subtract · subtract two rational numbers · subtract fractions as rationals.**

## Supported

- rational subtract
- subtract two rational numbers
- subtract fractions as rationals
- difference of two rationals

## Not supported

- rational add
- decimal subtract
- float subtraction
- mixed numbers
- continued fractions
- IEEE-754 arithmetic

## Behavior

- Each operand is an object with canonical integer-string numerator and denominator fields.
- The denominator must be a positive canonical integer; zero and negative denominators are rejected.
- Inputs may use -0, which is canonicalized to 0; every other integer must match 0 or -?[1-9][0-9]*.
- The result is a - b, computed as (a.numerator * b.denominator - b.numerator * a.denominator) / (a.denominator * b.denominator).
- The result is reduced by gcd, with the sign only on the numerator; 0 is numerator 0 over denominator 1.
- Input, intermediate, and output numerators and denominators may have at most 1000 digits excluding sign.

## Input

- `a` (object, required)
- `b` (object, required)

## Output

- `numerator` (string, required)
- `denominator` (string, required)

## Limits

- max digits: 1000

## Example

Request input:

```json
{
  "a": {
    "numerator": "1",
    "denominator": "2"
  },
  "b": {
    "numerator": "1",
    "denominator": "3"
  }
}
```

Response:

```json
{
  "result": {
    "numerator": "1",
    "denominator": "6"
  }
}
```

## How to call it

### MCP

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

```json
{
  "id": "rational-subtract",
  "version": "1.0.0",
  "input": {
    "a": {
      "numerator": "1",
      "denominator": "2"
    },
    "b": {
      "numerator": "1",
      "denominator": "3"
    }
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/rational-subtract/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"a":{"numerator":"1","denominator":"2"},"b":{"numerator":"1","denominator":"3"}}'
```

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

### CLI

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

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

## Related tools

- [Rational multiply](/tools/rational-multiply): Multiply two rational numbers given as numerator/denominator integer strings and return the reduced product.
- [Rational add](/tools/rational-add): Add two rational numbers given as numerator/denominator integer strings and return the reduced sum.
- [Rational compare](/tools/rational-compare): Compare two rational numbers given as numerator/denominator integer strings by exact value.
- [Array rational sum](/tools/array-rational-sum): Sum an array of canonical rationals and return the reduced total.
- [Array rational mean](/tools/array-rational-mean): Return the reduced arithmetic mean of an array of canonical rationals.
- [Array rational min max](/tools/array-rational-min-max): Return the reduced numeric minimum and maximum of an array of canonical rationals.
