Track bare-symbol values across a modulus instead of skipping
A line like `x = <formula> mod N` can't be solved for x (it's just a name for "whatever this reduces to"), so the chain handler gave up on any modular equation once a bare symbol was involved. That silently passed over real errors in exactly the shape a CRT reconstruction produces: `x = 2*77*2+... mod 231` followed by a contradicting `x ≡ 57+66+126 mod 231` (the latter reduces to a different value mod 231) went unflagged. Now, when exactly one side of the chain is a bare single letter and every other side is a plain number, its reduced value is tracked in known_vars the same way solved variables already are - catching the mismatch as a contradiction without ever needing to solve for x. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
e819e230e4
commit
41c98fc1ab
1 changed files with 31 additions and 4 deletions
|
|
@ -284,11 +284,38 @@ def verify_claim(line):
|
||||||
shown = ', '.join(str(r) for r in red)
|
shown = ', '.join(str(r) for r in red)
|
||||||
return ('wrong', f"{shown} mod {mod}" if mod is not None else shown)
|
return ('wrong', f"{shown} mod {mod}" if mod is not None else shown)
|
||||||
|
|
||||||
# --- symbolic fallback: one unknown, e.g. "2x + 3 = 7" ----------
|
# --- bare symbol across a modulus, e.g. "x = 2*77*2+... mod 231" --
|
||||||
# Skipped when the chain carries a modulus: solving `x ≡ 2 mod 5` as
|
# `x` can't be solved for (it's just a name standing for "whatever
|
||||||
# the equation x = 2 would drop the modulus and report a verification
|
# this reduces to"), but when exactly one side is a bare single
|
||||||
# that never happened.
|
# 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 ≡ <different formula> 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:
|
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)
|
return ('skip', None)
|
||||||
# Prose sentences must not reach sympy: `parse_expr` with implicit
|
# Prose sentences must not reach sympy: `parse_expr` with implicit
|
||||||
# multiplication turns every letter into a symbol, which is both
|
# multiplication turns every letter into a symbol, which is both
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue