Skip to content

expression-parsing: parse inequalities, != and chained equalities - #13

Draft
m-messer wants to merge 2 commits into
mainfrom
feat/relational-parsing
Draft

m-messer wants to merge 2 commits into
mainfrom
feat/relational-parsing

Conversation

@m-messer

Copy link
Copy Markdown
Member

Ports the parsing half of compareExpressions#276 (inequalities and !=) and #278 (chained equalities) to expression_parsing. There is one commit for each. The grading, feedback tags and preview stay in compareExpressions.

expression_parsing (#276)

  • parse_expression reads <, <=, >, >= and != as the unevaluated SymPy relations.
  • Two inequalities that point the same way (1 < x <= 5) give And of both.
  • ≠, ≤ and ≥ are normalised to !=, <= and >=.
  • Before, x != 5 was read as Eq(factorial(x), 5), and x <= 5 failed to parse.
  • split_relations(expr, error) (exported, along with RELATIONAL_OPERATORS) splits out the operands and checks the rules. It rejects a chain that points both ways, more than two inequalities, =/!= combined with another relation, and an empty operand.

expression_parsing (#278)

  • x = y = z gives And(Eq(x, y), Eq(y, z)) from both parse_expression and parse_latex. Before, more than one = raised an error.
  • A single = still gives a bare Equality.
  • An empty side (x = = y) is an error, and so is a chain that mixes = with another relation (x = y < z).
  • The parity check's a=b=c expected change is updated to record the chain.

Downstream (compareExpressions)

  • Without the #276/#278 grading ported, an inequality or a chain reaches check_equality, which handles only Equality. The app ports stack on #289 after the pin bump to rc4.

Verification

  • ruff, format and mypy are clean. All package tests pass, and so does the parity check (0 unexpected, 0 mismatched).

🤖 Generated with Claude Code

m-messer and others added 2 commits October 23, 2026 15:25
x = y = z parses as And(Eq(x, y), Eq(y, z)) in parse_expression and
parse_latex; an empty side is an error. Adds tests/test_relations.py,
which also covers the relational operators from the previous commit.
From compareExpressions#278.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant