{"id":"rational-expression-check","version":"1.0.0","description":"Check a claimed exact rational value of an integer/fraction expression; reports the true value and the difference.","supported_operations":["verify a claimed fraction result","check exact value of a fraction expression","is this rational arithmetic answer correct","validate a claimed sum of fractions","check my fraction calculation exactly","confirm reduced fraction answer of an expression","בדיקת תוצאה של חישוב שברים"],"unsupported_operations":["decimal literals, exponents or functions (use decimal-expression-evaluate)","variables or symbolic algebra","floating-point or approximate comparison","rounding the result"],"semantics":["Reference: ISO/IEC 10967-2:2001 (LIA-2) exact-result terminology; exact arithmetic over the rationals with canonical reduced form; RFC 8259 sec. 6 integer grammar and sec. 7 strings.","Grammar: expr := term ((\"+\" | \"-\") term)*; term := unary ((\"*\" | \"/\") unary)*; unary := \"-\" unary | primary; primary := INTEGER | \"(\" expr \")\". Left associative (1/2/2 = 1/4); unary minus binds tighter than * and / (2*-3 = -6). No unary plus, no ^, no implicit multiplication.","INTEGER is RFC 8259 int (0 or no leading zero); decimals, exponents and separators are invalid_input. U+2212, U+00D7 and U+00F7 are accepted as - * /; whitespace is space, tab, LF, CR. Positions are 0-based code point offsets.","claimed_value is a string -?(0|[1-9][0-9]*)(/[1-9][0-9]*)?, never a JSON number; it is compared exactly by value. require_canonical (required): true also demands the canonical form (reduced, no \"/1\", no \"-0\").","Check order: fields; expression bytes and surrogates; claimed_value; require_canonical; tokenise and parse (errors); evaluation in post-order, left before right (division_by_zero with position and divisor_text of the first zero divisor); value (value_mismatch with difference = value - claim); form (not_canonical).","value is the canonical exact value, or null for division_by_zero. Reported differences are exact and not subject to the digit cap.","Limits: 4096 UTF-8 bytes, 1024 tokens, nesting depth 64 (parentheses plus pending unary minus), 500 digits per literal, claim or reduced intermediate value; over a limit is limit_exceeded."],"limits":{"max_expression_bytes":4096,"max_tokens":1024,"max_depth":64,"max_value_digits":500},"pricing":{"status":"unpriced","charge_usd":null},"input_schema":{"type":"object","additionalProperties":false,"required":["expression","claimed_value","require_canonical"],"properties":{"expression":{"type":"string","minLength":1},"claimed_value":{"type":"string","pattern":"^-?(0|[1-9][0-9]*)(/[1-9][0-9]*)?$"},"require_canonical":{"type":"boolean"}}},"output_schema":{"type":"object","additionalProperties":false,"required":["valid","reason","value","first_discrepancy","reference_version"],"properties":{"valid":{"type":"boolean"},"reason":{"type":["string","null"],"enum":[null,"division_by_zero","value_mismatch","not_canonical"]},"value":{"type":["string","null"],"pattern":"^-?(0|[1-9][0-9]*)(/[1-9][0-9]*)?$"},"first_discrepancy":{"type":["object","null"],"additionalProperties":false,"required":["field","claimed_value","canonical_claim","actual_value","difference","position","divisor_text"],"properties":{"field":{"type":"string","enum":["expression","claimed_value"]},"claimed_value":{"type":"string"},"canonical_claim":{"type":"string","pattern":"^-?(0|[1-9][0-9]*)(/[1-9][0-9]*)?$"},"actual_value":{"type":["string","null"]},"difference":{"type":["string","null"]},"position":{"type":["integer","null"],"minimum":0},"divisor_text":{"type":["string","null"]}}},"reference_version":{"type":"string","const":"ISO/IEC 10967-2:2001 (LIA-2) exact-result terminology; exact arithmetic over the rationals with canonical reduced form; RFC 8259 sec. 6 integer grammar and sec. 7 strings"}}},"examples":[{"input":{"expression":"1 + 1/2 + 1/3 + 1/4","claimed_value":"25/12","require_canonical":true},"output":{"valid":true,"reason":null,"value":"25/12","first_discrepancy":null,"reference_version":"ISO/IEC 10967-2:2001 (LIA-2) exact-result terminology; exact arithmetic over the rationals with canonical reduced form; RFC 8259 sec. 6 integer grammar and sec. 7 strings"}},{"input":{"expression":"1/3 - 1/2","claimed_value":"1/6","require_canonical":true},"output":{"valid":false,"reason":"value_mismatch","value":"-1/6","first_discrepancy":{"field":"claimed_value","claimed_value":"1/6","canonical_claim":"1/6","actual_value":"-1/6","difference":"-1/3","position":null,"divisor_text":null},"reference_version":"ISO/IEC 10967-2:2001 (LIA-2) exact-result terminology; exact arithmetic over the rationals with canonical reduced form; RFC 8259 sec. 6 integer grammar and sec. 7 strings"}},{"input":{"expression":"1/(2-2) + 1","claimed_value":"1","require_canonical":false},"output":{"valid":false,"reason":"division_by_zero","value":null,"first_discrepancy":{"field":"expression","claimed_value":"1","canonical_claim":"1","actual_value":null,"difference":null,"position":1,"divisor_text":"(2-2)"},"reference_version":"ISO/IEC 10967-2:2001 (LIA-2) exact-result terminology; exact arithmetic over the rationals with canonical reduced form; RFC 8259 sec. 6 integer grammar and sec. 7 strings"}}],"execute_url":"/v1/tools/rational-expression-check/versions/1.0.0/execute"}