diff --git a/hooks/verify-calculations.sh b/hooks/verify-calculations.sh index d0fee23..0f96f27 100755 --- a/hooks/verify-calculations.sh +++ b/hooks/verify-calculations.sh @@ -284,11 +284,38 @@ def verify_claim(line): shown = ', '.join(str(r) for r in red) return ('wrong', f"{shown} mod {mod}" if mod is not None else shown) - # --- symbolic fallback: one unknown, e.g. "2x + 3 = 7" ---------- - # Skipped when the chain carries a modulus: solving `x ≡ 2 mod 5` as - # the equation x = 2 would drop the modulus and report a verification - # that never happened. + # --- bare symbol across a modulus, e.g. "x = 2*77*2+... mod 231" -- + # `x` can't be solved for (it's just a name standing for "whatever + # this reduces to"), but when exactly one side is a bare single + # letter and every other side is a plain number, the modular VALUE + # it's being defined as can still be tracked across lines the same + # way known_vars already tracks solved variables. This is what + # catches e.g. a later `x ≡ mod 231` that + # reduces to a different value - a real contradiction, even though + # `x` itself is never pinned to one absolute number. if mod is not None: + bare = [i for i, p in enumerate(parts) if re.fullmatch(r'[a-zA-Z]', p)] + numeric = {} + for i, p in enumerate(parts): + if i in bare: + continue + try: + numeric[i] = eval_expr(p) % mod + except Exception: + pass + if len(bare) == 1 and len(numeric) == len(parts) - 1 and numeric: + var = parts[bare[0]] + reduced = list(numeric.values()) + if not all(v == reduced[0] for v in reduced): + shown = ', '.join(str(v) for v in reduced) + return ('wrong', f"{shown} mod {mod}") + value = reduced[0] + prev = known_vars.get(var) + if prev is not None and prev != value: + return ('wrong', + f"{var} = {value} contredit {var} = {prev} (mod {mod})") + known_vars[var] = value + return ('ok', None) return ('skip', None) # Prose sentences must not reach sympy: `parse_expr` with implicit # multiplication turns every letter into a symbol, which is both