Rational expression check
rational-expression-check · version 1.0.0 · Numbers & math · free, no key needed
Check a claimed exact rational value of an integer/fraction expression; reports the true value and the difference.
Use when you need to: verify a claimed fraction result · check exact value of a fraction expression · is this rational arithmetic answer correct.
Decide before calling
Read the versioned contract and the supported scope below. Reuse rational-expression-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 rational-expression-check@1.0.0 for verify a claimed fraction result. 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 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
- בדיקת תוצאה של חישוב שברים
Not supported
- decimal literals, exponents or functions (use decimal-expression-evaluate)
- variables or symbolic algebra
- floating-point or approximate comparison
- rounding the result
Behavior
- 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.
Input
expression(string, required): min length 1claimed_value(string, required): pattern^-?(0|[1-9][0-9]*)(/[1-9][0-9]*)?$require_canonical(boolean, required)
Output
valid(boolean, required)reason(one of null, "division_by_zero", "value_mismatch", "not_canonical", required)value(string or null, required): pattern^-?(0|[1-9][0-9]*)(/[1-9][0-9]*)?$first_discrepancy(object or null, required)reference_version(constant "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", required)
Limits
- max expression bytes: 4096
- max tokens: 1024
- max depth: 64
- max value digits: 500
Example
Request input:
{
"expression": "1 + 1/2 + 1/3 + 1/4",
"claimed_value": "25/12",
"require_canonical": true
}
Response:
{
"result": {
"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"
}
}
How to call it
MCP
Connect https://computefirst.net/mcp (setup), then call execute with:
{
"id": "rational-expression-check",
"version": "1.0.0",
"input": {
"expression": "1 + 1/2 + 1/3 + 1/4",
"claimed_value": "25/12",
"require_canonical": true
}
}
HTTP (no key)
curl -X POST https://computefirst.net/v1/tools/rational-expression-check/versions/1.0.0/execute \
-H "Content-Type: application/json" \
-d '{"expression":"1 + 1/2 + 1/3 + 1/4","claimed_value":"25/12","require_canonical":true}'
The machine-readable contract is at /v1/tools/rational-expression-check/versions/1.0.0.
CLI
node cli.mjs run rational-expression-check 1.0.0 --input input.json --base-url https://computefirst.net
Get the client at /clients/cli/.
Related tools
- Lp primal feasibility check: Check that a claimed LP point satisfies x >= 0 and Ax <= b exactly; report the first violated bound or row.
- Rational equation check: Check a chained claim like 1/2 + 1/3 = 5/6 < 1 exactly; returns the first false relation or division by zero.
- Rational trace check: Check a step-by-step rational calculation trace; reports the first step whose operand, operator or result disagrees.
- Linear residual check: Check a claimed residual r = b - A x (per component and/or its max norm) exactly for an approximate solution x.
- 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.
- Maximum flow certificate check: Check a claimed max flow with a min-cut certificate or residual search; reports the first failure or augmenting path.