Support inequalities in the answer and response - #276
Open
m-messer wants to merge 6 commits into
Open
Conversation
…s and preview functions
…ests, with restrictions on chaining and combinations with order operators
…ndling in the current implementation
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.
Problem
compareExpressionshas limited support for equalities in the answer andresponse (
x^2 = 5y^2 + 7, see the user docs) but no support forinequalities. Issue #271 asks for the analogous feature.
Separately,
!=was silently mis-parsed:x != 5becameEq(factorial(x), 5)(the
!consumed as factorial, the=as equality), so a response ofx != 5against an answer of
x != 5only "passed" because both sides mis-parsedidentically, and
5 != xbecameEq(120, x).Changes
app/utility/expression_utilities.py:parse_expressionnow detects relationaloperators before the
=split.<,<=,>,>=→ the matching SymPyrelation; a two-operator, single-direction chain (
1 < x < 5) → anAndof tworelations;
!=(and unicode≠, normalised to!=) →Ne. Chains of three ormore operators, mixed-direction chains (
1 < x > 5), and!=combined with anyother operator raise a parse error.
app/context/symbolic.py:inequality_bounds()— classifies a parsed expression as a single relation, achained order inequality (
Andof order relations), or neither.check_inequality_equivalence()with helpers_compare_single_inequality,_compare_not_equal,_compare_chained_inequalities. Two relations areequivalent when, after moving all terms to one side, the difference ratio
D_response / D_answeris a positive constant with matchingstrictness — a negative constant ⇒ opposite direction,
<vs<=⇒strictness mismatch.
!=uses the same ratio test but any non-zero constantcounts and direction/strictness do not apply. Chains are matched bound by
bound in either pairing. This mirrors the existing
equality_equivalencecheck that
(a-b)/(c-d)is a constant.criterion_equality_nodegains ause_inequality_equivalencebranch(parallel to
use_equality_equivalence), used when either the response or theanswer parses to a relation. Emits
_TRUE/_FALSE/_UNKNOWN/_WRONG_DIRECTION/_STRICTNESS_MISMATCH/_RESPONSE_NOT_INEQUALITY/_ANSWER_NOT_INEQUALITYtags.check_equalityguards relational operands so they never reach thelhs - rhssubtraction (which raisesTypeErroron SymPy relations).app/feedback/symbolic.py: feedback strings for the seven newINEQUALIT*/*_NOT_INEQUALITYINTERNALtags.app/preview_implementations/symbolic_preview.py: split the previewed responseon a lone
=only (re.split(r"(?<![<>=!])=(?!=)", …)), sox >= 5,x != 5and1 < x < 5preview instead of erroring or splitting on the=inside
>=/!=.app/docs/user.md,app/docs/dev.md: document the feature, the equivalencerule and the limitations.
TestParseInequalitiesinapp/tests/expression_utilities_test.py;test_inequality_*,test_chained_inequality_*,test_not_equal_*inapp/tests/symbolic_evaluation_test.py; inequality preview cases inapp/tests/preview_test.py.Behaviour
2x - 10 >= 0x >= 5,5 <= x,4x - 20 >= 0,10 - 2x <= 0x > 5(strictness),x <= 5(opposite direction)1 < x < 55 > x > 1,0 < x - 1 < 4,2 < 2x < 101 <= x < 5(strictness)x != 55 != x,2x != 10,x - 5 != 0,x ≠ 5x = 5(not comparable)Known limitation: when the student response's bound is not a scalar multiple
of the answer's — e.g. a response of
x > 1against an answer ofx > 5, or aresponse of
x != 3against an answer ofx != 5— the result isUNKNOWNrather than
FALSE. The response is still marked incorrect; only the feedbacktag is weaker. This matches the existing ratio-based equality-equivalence
behaviour.
plus_minus-expanded relation sets and<>are not supported.Checklist
app/docs/user.md,app/docs/dev.md)Closes #271
🤖 Generated with Claude Code
https://claude.ai/code/session_01DzjPKz78pwESTLPdSGXF4q