Regression normal equations check
regression-normal-equations-check · version 1.0.0 · Numbers & math · free, no key needed
Check that claimed coefficients and residuals satisfy X^T e = 0 exactly; rejects singular, ambiguous designs.
Use when you need to: verify normal equations of a regression · check that residuals are orthogonal to the design matrix · prove a least squares fit is optimal.
Decide before calling
Read the versioned contract and the supported scope below. Reuse regression-normal-equations-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 regression-normal-equations-check@1.0.0 for verify normal equations of a regression. 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
- verify normal equations of a regression
- check that residuals are orthogonal to the design matrix
- prove a least squares fit is optimal
- validate X transpose residual equals zero
- check optimality certificate of a regression
- verify least squares solution without refitting
- אימות משוואות נורמליות של רגרסיה
Not supported
- computing the coefficients (use regression-coefficients-check)
- constrained or regularized least squares
- approximate optimality within a tolerance
- weighted normal equations
Behavior
- Reference: NIST/SEMATECH e-Handbook of Statistical Methods sec. 4.1.4.1 and 4.4.3.1 (ordinary least squares, normal equations); exact rational arithmetic.
- Model (NIST e-Handbook 4.1.4.1): y_i = sum_j beta_j X_ij + e_i; X has a leading column of ones when intercept is true (required, no default), then the x features in order; coefficient 0 is the intercept when present.
- Values are exact strings: integer, decimal ("3.5") or fraction ("7/2"), never JSON numbers or exponents; comparisons are exact and outputs canonical reduced fractions. difference = claimed - actual.
- Ragged rows, len(y) != rows or empty x are invalid_input; a claimed vector of the wrong length is valid:false dimension_mismatch, checked first.
- Rank is exact; dependent_column is the first column of X that is a combination of earlier columns. rank < k (including fewer samples than columns) is singular_design: the least-squares coefficients are not unique.
- The certificate is optimal exactly when X^T e = 0 (the normal equations X^T X beta = X^T y, NIST e-Handbook 4.4.3.1).
- Check order: coefficient count, residual count, residuals in sample order (residual_mismatch), normal equations in column order (normal_equation_violated with the exact (X^T e)_j), then rank (singular_design: a least-squares solution, but not the unique one). gradient is X^T e for the claimed coefficients, or null when the coefficient count is wrong.
- Limits: 256 samples, 8 features, 30 digits per sample value, 1000 digits per claimed value, 9 claimed coefficients, 256 claimed residuals, and common denominators of at most 100 digits for the x values and for the y values and 1000 digits for the claimed coefficients; over a limit is limit_exceeded.
Input
x(array of array of string, required): min items 1; max items 256; each min items 1; each max items 8; each each pattern^-?(0|[1-9][0-9]*)(\.[0-9]+|/[1-9][0-9]*)?$y(array of string, required): min items 1; max items 256; each pattern^-?(0|[1-9][0-9]*)(\.[0-9]+|/[1-9][0-9]*)?$intercept(boolean, required)coefficients(array of string, required): max items 9; each pattern^-?(0|[1-9][0-9]*)(\.[0-9]+|/[1-9][0-9]*)?$residuals(array of string, required): max items 256; each pattern^-?(0|[1-9][0-9]*)(\.[0-9]+|/[1-9][0-9]*)?$
Output
valid(boolean, required)reason(one of null, "dimension_mismatch", "residual_mismatch", "normal_equation_violated", "singular_design", required)rank(integer, required): min 0gradient(array or null, required)first_discrepancy(object or null, required)reference_version(constant "NIST/SEMATECH e-Handbook of Statistical Methods sec. 4.1.4.1 and 4.4.3.1 (ordinary least squares, normal equations); exact rational arithmetic", required)
Limits
- max samples: 256
- max features: 8
- max sample digits: 30
- max claim digits: 1000
- max data denominator digits: 100
- max claim denominator digits: 1000
Example
Request input:
{
"x": [
[
"1"
],
[
"2"
],
[
"3"
],
[
"4"
]
],
"y": [
"6",
"5",
"7",
"10"
],
"intercept": true,
"coefficients": [
"3.5",
"1.4"
],
"residuals": [
"1.1",
"-1.3",
"-0.7",
"0.9"
]
}
Response:
{
"result": {
"valid": true,
"reason": null,
"rank": 2,
"gradient": [
"0",
"0"
],
"first_discrepancy": null,
"reference_version": "NIST/SEMATECH e-Handbook of Statistical Methods sec. 4.1.4.1 and 4.4.3.1 (ordinary least squares, normal equations); exact rational arithmetic"
}
}
How to call it
MCP
Connect https://computefirst.net/mcp (setup), then call execute with:
{
"id": "regression-normal-equations-check",
"version": "1.0.0",
"input": {
"x": [
[
"1"
],
[
"2"
],
[
"3"
],
[
"4"
]
],
"y": [
"6",
"5",
"7",
"10"
],
"intercept": true,
"coefficients": [
"3.5",
"1.4"
],
"residuals": [
"1.1",
"-1.3",
"-0.7",
"0.9"
]
}
}
HTTP (no key)
curl -X POST https://computefirst.net/v1/tools/regression-normal-equations-check/versions/1.0.0/execute \
-H "Content-Type: application/json" \
-d '{"x":[["1"],["2"],["3"],["4"]],"y":["6","5","7","10"],"intercept":true,"coefficients":["3.5","1.4"],"residuals":["1.1","-1.3","-0.7","0.9"]}'
The machine-readable contract is at /v1/tools/regression-normal-equations-check/versions/1.0.0.
CLI
node cli.mjs run regression-normal-equations-check 1.0.0 --input input.json --base-url https://computefirst.net
Get the client at /clients/cli/.
Related tools
- Lp optimality certificate check: Check an LP optimum claim from a primal x and dual y: feasibility, complementary slackness and zero duality gap.
- Linear inconsistency certificate check: Check a witness y that A x = b has no solution (yA = 0, yb != 0) or no x >= 0 solution (Farkas: yA >= 0, yb < 0).
- Linear residual check: Check a claimed residual r = b - A x (per component and/or its max norm) exactly for an approximate solution x.
- Lp primal feasibility check: Check that a claimed LP point satisfies x >= 0 and Ax <= b exactly; report the first violated bound or row.
- Regression coefficients check: Check claimed least-squares regression coefficients against exact samples; reports rank and the first mismatch.
- Regression residuals check: Check claimed residuals and SSE for given regression coefficients and exact samples; reports the first wrong residual.