Skip to content

fix(symbolic): compare two-variable inequalities by region instead of at x = 1 (PIE-1419) - #86

Merged
CarlaCostea merged 16 commits into
developfrom
fix/PIE-1419
Nov 4, 2026
Merged

CarlaCostea merged 16 commits into
developfrom
fix/PIE-1419

Conversation

@CarlaCostea

@CarlaCostea CarlaCostea commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

What

In symbolic mode, a wrong answer to an inequality in two variables was scored correct whenever it gave the same boundary value as the correct answer at x = 1. For example, y>2x+1 vs y>3x was scored correct because both give y > 3 at x = 1. Two-variable inequalities are now equivalent only when they describe the same region.

Jira: https://illuminate.atlassian.net/browse/PIE-1419

Depends on #77 (PIE-443). This PR reuses areEquationsNumericallyEquivalent and the sample points from #77, so until #77 merges, this PR's diff against develop also shows #77's commits. Review and merge #77 first. This PR's own changes are in the (PIE-1419) commits.

Why it happened

compareEquations in src/symbolic/compare-equations.ts turned a two-variable inequality into a one-variable one by setting x = 1, then compared the y values. One value of x can't show that two inequalities describe the same region. Inequalities that aren't linear in y, such as x^2+y^2\le4, couldn't be solved this way at all. #77 replaced this check for equations and left inequalities on it to keep that change scoped.

Change

compare-equations.ts: two-variable inequalities now use the same numeric check as two-variable equations, with positiveOnly: true, even-power variable factors only, and no numerator comparison.

  • Both inequalities are moved to F ⋚ 0 / G ⋚ 0 form. They're equivalent when F/G is the same positive constant at every sample point.
  • A negative constant would mean the sign flipped, so it's rejected. Multiplying or dividing both sides by an even power of a variable can't flip the sign, so it's allowed: y>x^2 ≡ \frac{y}{x^2}>1 and y>x ≡ x^2y>x^3. An odd power such as x, or clearing a variable denominator, can change sign across the region, so neither is allowed (utils.ts filters the variable factors to even powers when positiveOnly is set).
  • By the time pairs reach this function they always have the same operator: index.ts only sends larger/larger or largerEq/largerEq pairs. So a positive ratio means the same region.
  • fix(symbolic): stop accepting wrong answers to two-variable equations with powers (PIE-443) #77's sample points include negative values, so inequalities that only agree for positive x and y are told apart.

The x = 1 block is removed because nothing reaches it anymore, and so is its only helper, setXToOne. One-variable inequalities still use the existing solve and sign-flip check.

Scoring impact

All of these are compared with #77. On develop, the first group is also scored correct.

Answers that were previously scored correct and are now scored incorrect:

  • Linear inequalities that agree at x = 1 but have a different slope, for example y>2x+1 vs y>3x and y>x+2
  • 3x-2y\ge6 vs 3x-2y\le6 (the same line with the region on the opposite side)
  • Inequalities that only describe the same region when x or y is positive, for example y>x vs \frac{y}{x}>1, \frac{1}{y}<\frac{1}{x}, y\cdot y>x\cdot y and (y-x)x>0, xy>1 vs y>\frac{1}{x}, and y>x^2 vs \frac{y}{x}>x and xy>x^3
  • y>\left|x\right| vs y>x
  • x^2+y^2\le4 vs x^2+y^2\le5. fix(symbolic): stop accepting wrong answers to two-variable equations with powers (PIE-443) #77 scores this correct when it's called on its own, which is how scoring runs. In the full fixture suite it already comes out incorrect, so it isn't in the count below.
  • Correct answers that are now rejected: both sides multiplied by an always-positive expression that isn't an even power, for example y>x vs (y-x)(x^2+1)>0 and \frac{y-x}{x^2+1}>0, and y>x^2+1 vs \frac{y}{x^2+1}>1. The ratio isn't constant, so the check can't tell these apart from different regions. Students are unlikely to write them.

Answers that were previously scored incorrect and are now scored correct:

  • Inequalities that aren't linear in y but are positive multiples or rearrangements of each other, for example x^2+y^2\le4 vs 2x^2+2y^2\le8 and x^2+y^2-4\le0, y^2>x vs 2y^2>2x, and (y-x)^2>0 vs (x-y)^2>0

Answers whose scoring is unchanged:

  • Rearrangements of linear inequalities are still accepted: terms moved across, sides swapped with the sign flipped, both sides multiplied by a positive number, or by a negative number with the sign flipped. Fractions with constant denominators, such as \frac{y-1}{2}>x, are also still accepted.
  • Mixing strict and non-strict signs is still rejected, for example y>2x+1 vs 2x+1\le y.
  • Both sides multiplied by an even power of a variable are still accepted, for example y>x vs x^2y>x^3 and y>2x+1 vs x^2y>x^2(2x+1).
  • All existing fixtures give the same results, including 2-way-inequalities-with-variables.ts and 3-way-inequalities-with-variables.ts.

Tests

Follow-up

  • Demo page (docs/) to be regenerated after merge.
  • Known limitation: multiplying both sides by an always-positive expression other than an even power is rejected (see Scoring impact). So are monotonic rewrites such as y^3>x^3 and 2^y>2^x. They describe the same region, but the ratio isn't constant. Students are unlikely to write these. On develop, 2^y>2^x was accepted only because every variable got the same sample values.
  • Known limitation, inherited from fix(symbolic): stop accepting wrong answers to two-variable equations with powers (PIE-443) #77: points where one side isn't a real number are skipped. So with the root in the target (the known asymmetry), y>\sqrt{x}\cdot\sqrt{x} vs y>x is still accepted, even though the first only covers x ≥ 0. This was already the case on develop and fix(symbolic): stop accepting wrong answers to two-variable equations with powers (PIE-443) #77.
  • Nit: constants that differ by less than the 1e-9 relative tolerance count as equal, for example y>2x vs y>2x+0.0000000001. Differences of 1e-8 or more are caught.
  • Found while testing, not fixed here: on develop, x^2+y^2\le4 vs x^2+y^2\le5 is scored correct when called on its own, but incorrect inside the full fixture suite, which points to state leaking between calls. This PR scores it incorrect either way.

…eric checks (PIE-443)

areNumericallyEquivalent gave every variable the same integer values,
so it could not tell x^2 from y^2. Use fixed-seed pseudo-random values,
different for each variable, and add a check for equations that are
constant (or variable-factor) multiples of each other.
…valent (PIE-443)

Two-variable equations were compared by solving for y at x = 1. For
equations that are not linear in y both solutions were undefined, and
undefined === undefined scored any such pair as equivalent. Compare
equations in two variables numerically instead, guard the inequality
path against undefined solutions, and fall back to the numeric check
for one-variable equations that are neither linear nor quadratic.
…PIE-443)

Targets are the correct answers of items E217532, E232686, E234938
and E234162; ne cases are the changes reported in the ticket.
@CarlaCostea
CarlaCostea changed the base branch from fix/PIE-443 to develop November 3, 2026 13:45
@CarlaCostea
CarlaCostea merged commit 494c945 into develop Nov 4, 2026
3 checks passed
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 1.4.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant