{"id":"dimension-expression-check","version":"1.0.0","description":"Check a formula over dimensioned symbols is consistent and has the claimed dimension; returns the first bad node.","supported_operations":["check dimensions of a formula","dimensional analysis of an expression","is this formula dimensionally consistent","verify the units of a derived quantity","find where unlike quantities are added","check claimed dimension L^2 M T^-2","בדיקת ממדים של נוסחה"],"unsupported_operations":["numeric evaluation or unit conversion of the formula","quantity kinds (torque and energy share L^2 M T^-2 and are not distinguished)","symbolic or decimal exponents such as x^n or x^1.5","unit symbols such as kg m s^-2 in place of dimension symbols"],"semantics":["Reference: ISO 80000-1:2022 (quantity dimension; only quantities of the same dimension are added or compared; arguments of exp, log and trigonometric functions have dimension one) and SI Brochure 9th ed. 2019 (section 2.3.3 dimension symbols, Table 4); every output carries reference_version \"iso-80000-1-2022+si-brochure-9e-2019\".","Dimension strings: \"1\" or space-separated factors L, M, T, I, Θ (U+0398), N, J with optional ^n, ^-n or ^(p/q) (|p|, q <= 1000), any order, each base once. Outputs are canonical: SI order L M T I Θ N J, zero exponents dropped, exponent 1 unwritten, fractions as ^(p/q).","Grammar: + - * / with usual precedence, unary minus, ^ with a literal integer or (p/q) exponent only, parentheses, numbers (dimension one), symbols [\\p{L}_][\\p{L}\\p{M}\\p{N}_]* (no Unicode normalization), functions sqrt, cbrt, abs, exp, ln, log, log10, log2, sin, cos, tan, asin, acos, atan, sinh, cosh, tanh. Syntax errors are invalid_input with details.reason and offset.","symbols: [{symbol, dimension}] with unique names (at most 128, names at most 64 UTF-8 bytes). Undeclared symbols are reported as unknown_symbol, not thrown.","Nodes are checked in post-order (left subtree, right subtree, node); the first failure is reported with path (\"/i/j\" child indexes from the root, \"\" for the root), start and end (0-based code point offsets) and text: unknown_symbol {symbol}, unlike_addition {operator, left, right}, non_dimensionless_argument {function, argument}. Then dimension_mismatch {claimed, actual} if the formula dimension differs from claimed_dimension.","dimension is the canonical formula dimension when it could be computed (also on dimension_mismatch), else null. Limits: 2048 UTF-8 bytes, 512 nodes, nesting depth 64 (parentheses, calls, unary minus), 128 symbols, 200-character dimension strings."],"limits":{"max_expression_bytes":2048,"max_symbols":128,"max_symbol_bytes":64,"max_dimension_chars":200,"max_nodes":512,"max_depth":64},"pricing":{"status":"unpriced","charge_usd":null},"input_schema":{"type":"object","additionalProperties":false,"required":["expression","symbols","claimed_dimension"],"properties":{"expression":{"type":"string","minLength":1},"symbols":{"type":"array","maxItems":128,"items":{"type":"object","additionalProperties":false,"required":["symbol","dimension"],"properties":{"symbol":{"type":"string","minLength":1},"dimension":{"type":"string","minLength":1,"maxLength":200}}}},"claimed_dimension":{"type":"string","minLength":1,"maxLength":200}}},"output_schema":{"type":"object","additionalProperties":false,"required":["valid","reason","first_discrepancy","dimension","node_count","reference_version"],"properties":{"valid":{"type":"boolean"},"reason":{"type":["string","null"],"enum":["unknown_symbol","unlike_addition","non_dimensionless_argument","dimension_mismatch",null]},"first_discrepancy":{"type":["object","null"],"additionalProperties":false,"properties":{"side":{"type":"string","enum":["left","right"]},"path":{"type":"string"},"start":{"type":"integer","minimum":0},"end":{"type":"integer","minimum":0},"text":{"type":"string"},"operator":{"type":"string","enum":["+","-"]},"left":{"type":"string"},"right":{"type":"string"},"function":{"type":"string"},"argument":{"type":"string"},"symbol":{"type":"string"},"claimed":{"type":"string"},"actual":{"type":"string"}}},"dimension":{"type":["string","null"]},"node_count":{"type":"integer","minimum":0},"reference_version":{"type":"string","const":"iso-80000-1-2022+si-brochure-9e-2019"}}},"examples":[{"input":{"expression":"m*a","symbols":[{"symbol":"m","dimension":"M"},{"symbol":"a","dimension":"L T^-2"},{"symbol":"s","dimension":"L"}],"claimed_dimension":"L M T^-2"},"output":{"valid":true,"reason":null,"first_discrepancy":null,"dimension":"L M T^-2","node_count":3,"reference_version":"iso-80000-1-2022+si-brochure-9e-2019"}},{"input":{"expression":"s + a*m","symbols":[{"symbol":"m","dimension":"M"},{"symbol":"a","dimension":"L T^-2"},{"symbol":"s","dimension":"L"}],"claimed_dimension":"L"},"output":{"valid":false,"reason":"unlike_addition","first_discrepancy":{"path":"","start":0,"end":7,"text":"s + a*m","operator":"+","left":"L","right":"L M T^-2"},"dimension":null,"node_count":5,"reference_version":"iso-80000-1-2022+si-brochure-9e-2019"}}],"execute_url":"/v1/tools/dimension-expression-check/versions/1.0.0/execute"}