Repository navigation
Grade strict-syntax ^ (XOR) instead of crashing check_equality/check_order - #325
Merged
Merged
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #307.
Problem
With
strict_syntax: true,^is Python XOR (intended), sox^2parses to a SymPyBooleanFunction(Not(...)). The guardis_inequality_or_booleanonly checkedRelationalandBooleanAtom, solhs_expr - rhs_exprraisedTypeErrorand the learner got an EvaluationError.check_orderhad no guard at all.Changes (
app/context/symbolic/comparison.py)cannot_be_subtracted():Relational,BooleanAtomorBooleanFunction(Booleanis still excluded, sinceSymbolsubclasses it).is_inequality_or_boolean()uses it, socheck_equalitygrades a boolean side as incorrect.check_orderreturnsNone("cannot determine") when either side can't be subtracted, ascheck_equalitydoes.The existing
NOTATION_WARNING_EXPONENTfeedback ("use**for powers") now shows up, because grading no longer crashes.Behaviour change to note
is_inequality_or_booleanis also used to validate the task's answer. Under strict syntax, an answer written asx^2now raisesTaskConfigurationErrorwith the tagRESERVED_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^2vsx**2, andx^2with the criteriaresponse > answer/answer < response: graded incorrect, withNOTATION_WARNING_EXPONENT.x^2under strict syntax raisesTaskConfigurationError.mainand pass here. The rest of the fast suite (-m "not slow") has the same results as onmainlocally, and mypy passes.🤖 Generated with Claude Code