# Polynomial identity check

`polynomial-identity-check` · version 1.0.0 · Numbers & math · free, no key needed

Check a polynomial identity over exact rationals by expanding both sides; report the lowest disagreeing coefficient.

**Use when you need to: check that two polynomial expressions are equal · verify a polynomial identity by exact expansion · is this expansion of a product of polynomials correct.**

## Decide before calling

Read the [versioned contract](/v1/tools/polynomial-identity-check/versions/1.0.0) and the supported scope below. Reuse `polynomial-identity-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 `polynomial-identity-check@1.0.0` for check that two polynomial expressions are equal. 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 that two polynomial expressions are equal
- verify a polynomial identity by exact expansion
- is this expansion of a product of polynomials correct
- find the first wrong coefficient in a polynomial expansion
- check an algebraic identity with rational coefficients
- verify sum of products of polynomials equals another

## Not supported

- parsing algebraic text such as "(x+1)^2" (give coefficient arrays)
- multivariate polynomials, powers as exponents, or symbolic constants
- floating-point or approximate coefficients
- simplifying or factoring an expression (this only checks a claimed equality)

## Behavior

- Polynomials are canonical ascending coefficient arrays (entry k = coefficient of x^k, last entry nonzero, [] = zero) of exact rational strings (integer, p/q or finite decimal, <= 40 characters). Reference: Cohen 1993, A Course in Computational Algebraic Number Theory, s3.1 (reference_version cohen-gtm138-1993-ch3).
- lhs and rhs are sums of up to 8 terms; each term is a product of 1 to 4 polynomials of degree <= 32 (subtract with a ["-1"] factor; an empty side is 0). Both sides are expanded exactly by convolution; all coefficient strings together are at most 4096 characters.
- Coefficients are compared from degree 0 upward; the first difference is returned as first_discrepancy {check: coefficient, degree, lhs, relation: =, rhs} with reason coefficient_mismatch. lhs_degree and rhs_degree are the expanded degrees (null for the zero polynomial).

## Input

- `lhs` (array of array of array of string, required): max items 8; each min items 1; each max items 4; each each max items 33; each each each max length 40; each each each pattern `^-?(0|[1-9][0-9]*)(/[1-9][0-9]*|\.[0-9]+)?$`
- `rhs` (array of array of array of string, required): max items 8; each min items 1; each max items 4; each each max items 33; each each each max length 40; each each each pattern `^-?(0|[1-9][0-9]*)(/[1-9][0-9]*|\.[0-9]+)?$`

## Output

- `valid` (boolean, required)
- `reason` (one of "coefficient_mismatch", null, required)
- `first_discrepancy` (object or null, required)
- `lhs_degree` (integer or null, required): min 0
- `rhs_degree` (integer or null, required): min 0
- `reference_version` (constant "cohen-gtm138-1993-ch3", required)

## Limits

- max degree: 32
- max terms per side: 8
- max factors per term: 4
- max number chars: 40
- max total number chars: 4096

## Example

Request input:

```json
{
  "lhs": [
    [
      [
        "4",
        "0",
        "0",
        "0",
        "1"
      ]
    ]
  ],
  "rhs": [
    [
      [
        "2",
        "2",
        "1"
      ],
      [
        "2",
        "-2",
        "1"
      ]
    ]
  ]
}
```

Response:

```json
{
  "result": {
    "valid": true,
    "reason": null,
    "first_discrepancy": null,
    "lhs_degree": 4,
    "rhs_degree": 4,
    "reference_version": "cohen-gtm138-1993-ch3"
  }
}
```

## How to call it

### MCP

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

```json
{
  "id": "polynomial-identity-check",
  "version": "1.0.0",
  "input": {
    "lhs": [
      [
        [
          "4",
          "0",
          "0",
          "0",
          "1"
        ]
      ]
    ],
    "rhs": [
      [
        [
          "2",
          "2",
          "1"
        ],
        [
          "2",
          "-2",
          "1"
        ]
      ]
    ]
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/polynomial-identity-check/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"lhs":[[["4","0","0","0","1"]]],"rhs":[[["2","2","1"],["2","-2","1"]]]}'
```

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

### CLI

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

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

## Related tools

- [Rational trace check](/tools/rational-trace-check): Check a step-by-step rational calculation trace; reports the first step whose operand, operator or result disagrees.
- [Chi square decomposition check](/tools/chi-square-decomposition-check): Check a claimed Pearson chi-square, its per-cell (O-E)^2/E terms and df exactly; returns the first wrong term.
- [Lp optimality certificate check](/tools/lp-optimality-certificate-check): Check an LP optimum claim from a primal x and dual y: feasibility, complementary slackness and zero duality gap.
- [Polynomial division check](/tools/polynomial-division-check): Check a claimed polynomial division A = BQ + R over exact rationals: remainder degree, quotient degree, coefficients.
- [Rational expression check](/tools/rational-expression-check): Check a claimed exact rational value of an integer/fraction expression; reports the true value and the difference.
- [Contingency margins check](/tools/contingency-margins-check): Check claimed row, column and grand totals of a count table exactly; returns the first wrong total.
