{"id":"contingency-margins-check","version":"1.0.0","description":"Check claimed row, column and grand totals of a count table exactly; returns the first wrong total.","supported_operations":["check contingency table totals","verify row and column totals of a cross tab","are my marginal totals correct","check grand total of a count table","find the wrong row total in a table","validate crosstab margins exactly","בדיקת סכומי שורות ועמודות בטבלה"],"unsupported_operations":["compute expected counts or a chi-square statistic (use contingency-expected-check or chi-square-decomposition-check)","weighted or fractional counts","tables over 64 x 64 or 1024 cells","locale-formatted numbers such as 2,757"],"semantics":["Reference: NIST/SEMATECH e-Handbook of Statistical Methods (doi:10.18434/M32189), section 7.4.5 (row totals, column totals, 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). Sums are exact BigInt integers, so totals above 2^53 stay exact.","Claims row_totals, column_totals and grand_total are optional but at least one is required; each total is a non-negative integer string without leading zeros, sign or separators.","Check order: row_totals length (length_mismatch, field \"row_totals\"), row totals in row order (row_total_mismatch), column_totals length (length_mismatch, field \"column_totals\"), column totals in column order (column_total_mismatch), grand_total (grand_total_mismatch). first_discrepancy carries claimed and actual as integer strings.","Optional row_labels / column_labels: exactly one unique non-empty label per row / column (at most 64 UTF-8 bytes, no lone surrogate, no Unicode normalization); they are echoed as row_label / column_label.","Validation order: table shape and size limits, cell values row-major, labels, then claims; over-limit sizes are limit_exceeded before later elements are read."],"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"],"properties":{"table":{"type":"array","minItems":1,"maxItems":64,"items":{"type":"array","minItems":1,"maxItems":64,"items":{"type":"integer","minimum":0,"maximum":9007199254740991}}},"row_totals":{"type":"array","maxItems":64,"items":{"type":"string","minLength":1,"maxLength":1000,"pattern":"^(0|[1-9][0-9]*)$"}},"column_totals":{"type":"array","maxItems":64,"items":{"type":"string","minLength":1,"maxLength":1000,"pattern":"^(0|[1-9][0-9]*)$"}},"grand_total":{"type":"string","minLength":1,"maxLength":1000,"pattern":"^(0|[1-9][0-9]*)$"},"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":["length_mismatch","row_total_mismatch","column_total_mismatch","grand_total_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"},"actual":{"type":"string","pattern":"^(0|[1-9][0-9]*)$"}}},"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]],"row_totals":["1557","1200"],"column_totals":["1246","566","945"],"grand_total":"2757"},"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":[[762,327,468],[484,239,477]],"column_totals":["1246","556","945"],"column_labels":["Dem","Ind","Rep"]},"output":{"valid":false,"reason":"column_total_mismatch","first_discrepancy":{"column_index":1,"column_label":"Ind","claimed":"556","actual":"566"},"row_count":2,"column_count":3,"grand_total":"2757","reference_version":"nist-sematech-ehandbook-doi-10.18434-M32189"}}],"execute_url":"/v1/tools/contingency-margins-check/versions/1.0.0/execute"}