Skip to content

Grade strict-syntax ^ (XOR) instead of crashing check_equality/check_order - #325

Merged
m-messer merged 2 commits into
mainfrom
fix/strict-caret-crash
Dec 1, 2026
Merged

m-messer merged 2 commits into
mainfrom
fix/strict-caret-crash

Conversation

@m-messer

@m-messer m-messer commented Dec 1, 2026

Copy link
Copy Markdown
Member

Fixes #307.

Problem

With strict_syntax: true, ^ is Python XOR (intended), so x^2 parses to a SymPy BooleanFunction (Not(...)). The guard is_inequality_or_boolean only checked Relational and BooleanAtom, so lhs_expr - rhs_expr raised TypeError and the learner got an EvaluationError. check_order had no guard at all.

Changes (app/context/symbolic/comparison.py)

  • New cannot_be_subtracted(): Relational, BooleanAtom or BooleanFunction (Boolean is still excluded, since Symbol subclasses it).
  • is_inequality_or_boolean() uses it, so check_equality grades a boolean side as incorrect.
  • check_order returns None ("cannot determine") when either side can't be subtracted, as check_equality does.

The existing NOTATION_WARNING_EXPONENT feedback ("use ** for powers") now shows up, because grading no longer crashes.

Behaviour change to note

is_inequality_or_boolean is also used to validate the task's answer. Under strict syntax, an answer written as x^2 now raises TaskConfigurationError with the tag RESERVED_EXPRESSION_INEQUALITY_answer ("is an inequality or evaluates to true/false"), instead of a generic EvaluationError. It's an authoring mistake, so a configuration error seems right.

Tests (app/tests/symbolic_evaluation_test.py)

  • x^2 vs x**2, and x^2 with the criteria response > answer / answer < response: graded incorrect, with NOTATION_WARNING_EXPONENT.
  • An answer of x^2 under strict syntax raises TaskConfigurationError.
  • All four fail on main and pass here. The rest of the fast suite (-m "not slow") has the same results as on main locally, and mypy passes.

🤖 Generated with Claude Code

m-messer and others added 2 commits December 1, 2026 12:19
…order

With strict_syntax, `x^2` parses to a BooleanFunction (XOR/Not), which
slipped past is_inequality_or_boolean, so `lhs - rhs` raised TypeError.
check_order had no guard at all.

- cannot_be_subtracted() covers Relational, BooleanAtom and BooleanFunction
- is_inequality_or_boolean() builds on it
- check_order returns None (cannot determine) for such sides

An answer written with ^ under strict syntax now raises
TaskConfigurationError (RESERVED_EXPRESSION_INEQUALITY_answer).

Fixes #307

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@m-messer
m-messer merged commit 5074d86 into main Dec 1, 2026
2 checks passed
@m-messer
m-messer deleted the fix/strict-caret-crash branch December 1, 2026 12:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

strict_syntax ^ (XOR) and relational sides crash check_equality/check_order instead of giving feedback

1 participant