{"id":"contingency-expected-check","version":"1.0.0","description":"Check claimed expected counts (row total x column total / N) of a count table exactly; returns the first wrong cell.","supported_operations":["check expected counts of a contingency table","verify expected frequencies row total times column total over n","are my expected cell values right","check expected values for a chi-square test","find the wrong expected count in a cross tab","validate rounded expected frequencies","בדיקת שכיחויות צפויות בטבלת שכיחות"],"unsupported_operations":["expected counts under a goodness-of-fit hypothesis with given proportions","compute a chi-square statistic or p-value (use chi-square-decomposition-check for the statistic)","floating-point tolerance comparisons","exponent notation such as 7.04e2"],"semantics":["Reference: NIST/SEMATECH e-Handbook of Statistical Methods (doi:10.18434/M32189), section 7.4.5: E_ij = (row i total)(column j total) / N; every output carries reference_version \"nist-sematech-ehandbook-doi-10.18434-M32189\".","table: 1..64 rows of 1..64 equal-length rows, at most 1024 cells, each a JSON integer 0..9007199254740991 (not -0); arithmetic is exact BigInt rational arithmetic, never floating point.","expected: the claimed r x c matrix; each claim is an integer, a finite decimal (no exponent or sign) or a fraction p/q (need not be reduced), compared exactly as a rational.","decimals (0..20) is optional. Omitted: claims must equal E_ij exactly. Given: claims must equal E_ij rounded to that many places with ties to even (IEEE 754 roundTiesToEven on the exact rational); the comparison is numeric, so 2.000 equals 2.","Check order: claimed row count, then each claimed row length (shape_mismatch, field \"expected\"), then cells in row-major order (expected_cell_mismatch {row_index, column_index, row_label?, column_label?, claimed, exact as reduced p/q, rounded when decimals is given}).","N = 0 is not_computable. A zero row or column total gives E_ij = 0, which is valid here. Optional row_labels / column_labels (unique, at most 64 UTF-8 bytes, no Unicode normalization) are echoed in first_discrepancy."],"limits":{"max_rows":64,"max_columns":64,"max_cells":1024,"max_claim_chars":1000,"max_label_bytes":64},"pricing":{"status":"unpriced","charge_usd":null},"input_schema":{"type":"object","additionalProperties":false,"required":["table","expected"],"properties":{"table":{"type":"array","minItems":1,"maxItems":64,"items":{"type":"array","minItems":1,"maxItems":64,"items":{"type":"integer","minimum":0,"maximum":9007199254740991}}},"expected":{"type":"array","maxItems":64,"items":{"type":"array","maxItems":64,"items":{"type":"string","minLength":1,"maxLength":1000,"pattern":"^(0|[1-9][0-9]*)(\\.[0-9]+|/[1-9][0-9]*)?$"}}},"decimals":{"type":"integer","minimum":0,"maximum":20},"row_labels":{"type":"array","minItems":1,"maxItems":64,"items":{"type":"string","minLength":1}},"column_labels":{"type":"array","minItems":1,"maxItems":64,"items":{"type":"string","minLength":1}}}},"output_schema":{"type":"object","additionalProperties":false,"required":["valid","reason","first_discrepancy","row_count","column_count","grand_total","reference_version"],"properties":{"valid":{"type":"boolean"},"reason":{"type":["string","null"],"enum":["shape_mismatch","expected_cell_mismatch",null]},"first_discrepancy":{"type":["object","null"],"additionalProperties":false,"properties":{"field":{"type":"string"},"claimed_length":{"type":"integer","minimum":0},"actual_length":{"type":"integer","minimum":0},"row_index":{"type":"integer","minimum":0},"row_label":{"type":"string"},"column_index":{"type":"integer","minimum":0},"column_label":{"type":"string"},"claimed":{"type":"string"},"exact":{"type":"string"},"rounded":{"type":"string"}}},"row_count":{"type":"integer","minimum":0},"column_count":{"type":"integer","minimum":0},"grand_total":{"type":"string","pattern":"^(0|[1-9][0-9]*)$"},"reference_version":{"type":"string","const":"nist-sematech-ehandbook-doi-10.18434-M32189"}}},"examples":[{"input":{"table":[[762,327,468],[484,239,477]],"expected":[["703.7","319.6","533.7"],["542.3","246.4","411.3"]],"decimals":1},"output":{"valid":true,"reason":null,"first_discrepancy":null,"row_count":2,"column_count":3,"grand_total":"2757","reference_version":"nist-sematech-ehandbook-doi-10.18434-M32189"}},{"input":{"table":[[0,1],[1,2]],"expected":[["0.2","0.8"],["0.8","2.3"]],"decimals":1},"output":{"valid":false,"reason":"expected_cell_mismatch","first_discrepancy":{"row_index":1,"column_index":1,"claimed":"2.3","exact":"9/4","rounded":"2.2"},"row_count":2,"column_count":2,"grand_total":"4","reference_version":"nist-sematech-ehandbook-doi-10.18434-M32189"}},{"input":{"table":[[0,1],[1,2]],"expected":[["1/4","3/4"],["0.75","9/4"]]},"output":{"valid":true,"reason":null,"first_discrepancy":null,"row_count":2,"column_count":2,"grand_total":"4","reference_version":"nist-sematech-ehandbook-doi-10.18434-M32189"}}],"execute_url":"/v1/tools/contingency-expected-check/versions/1.0.0/execute"}