Skip to content

fix(symbolic): stop accepting wrong answers to two-variable equations with powers (PIE-443) - #77

Merged
CarlaCostea merged 9 commits into
developfrom
fix/PIE-443
Nov 4, 2026
Merged

CarlaCostea merged 9 commits into
developfrom
fix/PIE-443

Conversation

@CarlaCostea

@CarlaCostea CarlaCostea commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

What

In symbolic mode, wrong answers to two-variable equations with powers (ellipses, hyperbolas, parabolas) were scored correct. Changing an exponent, a denominator, the right-hand side or a coefficient made no difference. Now they are scored incorrect, and rearranged forms of the correct answer are still accepted.

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

Why it happened

Two-variable equations were compared by setting x = 1 and solving the remaining equation for y. For equations that are quadratic in y (every item in this ticket), solveLinearEquation returns undefined for both sides, so undefined === undefined scored any such pair as equivalent. The one-variable branch already guarded against this, but the two-variable branch didn't. Separately, checking a single x value can't prove two equations equivalent even when they're linear: on develop, y=2x+1 vs y=3x is scored correct because both give y = 3 at x = 1. The PD-4890 numeric fallback didn't help, because it only runs for symbolic exponents and gave every variable the same integer values, so it couldn't tell x^2 from y^2.

Change

  • compare-equations.ts, two-variable equations: replaced the x = 1 solve with a numeric check. Both equations are moved to F = 0 and G = 0 form and evaluated at sample points. They are equivalent when F/G is constant across the points. Points where both are zero are skipped, and a point where only one is zero means the equations are not equivalent. The ratio may also be the constant times a power of each variable (exponents from −2 to 2), because the existing fixtures in linear-equations-in-two-variables.ts accept multiplying or dividing both sides by a variable (for example x+2y=7 ≡ x^2+2yx-7x=0).
  • utils.ts, variable denominators: if the ratio check fails and either side has a variable denominator, the check is repeated on the numerators (from rationalize). F = N/D is zero exactly where N is, so this accepts both sides multiplied by an expression such as x-2, for example \frac{y-1}{x-2}=3 ≡ y-1=3(x-2). Inequalities skip this step (see fix(symbolic): compare two-variable inequalities by region instead of at x = 1 (PIE-1419) #86), because multiplying by an expression can flip the sign. rationalize expands powers and gets very slow on them, so expressions with a power above 4 or more than 60 nodes skip this step. For example, \frac{(x+1)^7}{(y-1)^7}=1 vs (x+1)^7=2(y-1)^7 would otherwise take about 40 seconds.
  • compare-equations.ts, one-variable equations: when neither the linear nor the quadratic solver applies (both used to return undefined, so the answer was scored incorrect), fall back to the same check, but with a strict constant ratio only. Multiplying by x would add the root x = 0.
  • compare-equations.ts, two-variable inequalities: the x = 1 path is kept, with the missing !== undefined guard added. fix(symbolic): compare two-variable inequalities by region instead of at x = 1 (PIE-1419) #86 replaces it.
  • utils.ts, sample points: 12 fixed-seed pseudo-random points (mulberry32, seed 443). Each variable gets its own non-integer value between 0.5 and 4.5 in size, with a random sign, evaluated with a plain floating-point mathjs instance. Results are deterministic. Distinct values tell x^2 from y^2, and negative values tell |x| from x and \sqrt{x^6} from x^3. Points where a side isn't a real number (for example \sqrt{x} at negative x) are skipped, and at least 3 usable points are required. areNumericallyEquivalent (PD-4890) uses the same points and the same skipping.

Why scoped this way: the numeric check only decides cases the existing paths couldn't decide or got wrong. Structurally equal expressions, one-variable linear and quadratic equations, and the PD-4890 symbolic-exponent path work as before, apart from the better sample points.

Scoring impact

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

  • Every change listed in the ticket, against the items' real correct answers, for example:
    • \frac{(y+0)^2}{16}-\frac{(x+2)^2}{9}=1 (E217532) vs \frac{(y+0)^2}{17}-\frac{(x+2)^2}{9}=1, \frac{(y+0)^2}{16}-\frac{(3x+7)^2}{9}=1, ...=5, and exponents changed to 3
    • (y-7)^2=60(x-15) (E232686) vs (y-7)^3=60(x-15), (2y-8)^2=60(x-15), (y-7)^2=40(x-15), (y-7)^2=60(4x-14), (y-7)^2=60(x-15)^2
    • \frac{x^2}{64}+\frac{y^2}{36}=1 (E234938) vs \frac{x^4}{64}+..., \frac{x^2}{6}+..., ...\frac{3y^{-2}}{36}..., ...\frac{y^2}{360}..., ...=3
    • \frac{(x+10)^2}{275}+\frac{y^2}{900}=1 (E234162) vs \frac{(2x+11)^2}{275}+..., \frac{(x+10)^2}{27.5}+..., ...\frac{3y^8}{900}..., ...\frac{y^2}{3}..., ...=5
  • Non-equivalent linear equations in two variables that happen to agree at x = 1, for example y=2x+1 vs y=3x.
  • Targets with an absolute value or a square root that only match for positive values, for example y=\left|x\right| vs y=x or y=-x, and y=\sqrt{x^2} vs y=x.
  • x^2+y^2=-1 vs x^2+y^2=-4. Both have no real solutions, so strictly they're equivalent. develop accepted them only through the undefined === undefined bug.

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

  • One-variable equations that are constant multiples of each other but neither linear nor quadratic, for example x^3=8 vs 2x^3=16.

Answers whose scoring is unchanged:

  • Rearrangements of these items were already accepted and still are: sides swapped, terms reordered, expanded, both sides multiplied by the denominators, and E234938's alternate answer 36x^2+64y^2=2,304.
  • Both sides multiplied by a variable denominator are still accepted: \frac{y-1}{x-2}=3 vs y-1=3(x-2), y=\frac{2x+1}{x-3} vs y(x-3)=2x+1, y=\frac{4}{x+3} vs xy+3y=4.
  • Variable renames are still rejected, and so are \sqrt{x^6}=8, \left|x\right|^3=8 and \left|x^3\right|=8 vs x^3=8.
  • All existing fixtures give the same results.

Tests

  • Before (develop): 1546 passed. After: 1638 passed (+83 new fixtures in src/fixtures/latex-equal/symbolic/PIE-443.ts, +9 unit tests in src/__tests__/utils.spec.ts). tsc --noEmit is clean.
  • Re-enabled or changed fixtures: none. With src/symbolic from develop, exactly the 31 changed-answer cases fail.

Follow-up

  • Demo page (docs/) to be regenerated after merge.
  • fix(symbolic): compare two-variable inequalities by region instead of at x = 1 (PIE-1419) #86 (PIE-1419) is stacked on this PR and replaces the x = 1 check for two-variable inequalities.
  • Known limitation, by design: because multiplying both sides by a variable is accepted, xy=0 vs \frac{x}{y}=0 is scored correct, even though xy=0 also contains the line y = 0. This is the same trade-off as the existing x+2y=7 ≡ x^2+2yx-7x=0 fixture.
  • Known limitation: dropping the denominator also drops the points it excludes, so a removable singularity is ignored. For example, \frac{x^3-8}{x-2}=0 vs 2x^3=16 is scored correct, even though x = 2 is excluded from the first. Similar pairs such as \frac{x^2-4}{x-2}=0 vs x^2-4=0 were already accepted on develop.
  • Known limitation: with random signs, only a few of the 12 points have both x > 0 and y > 0. So expressions that are real only there (for example x^{0.5}+y^{0.5}), or only for x > 3 (sample values reach 4.5), get fewer than 3 usable points and are rejected. develop rejects the cases tried as well.
  • Not changed here (pre-existing): (x^2)^{\frac32}=8 vs x^3=8 is still accepted on both branches, probably because the simplifier rewrites (a^b)^c before the numeric check runs.
  • Found while testing, not changed here: expressionsCanBeCompared in utils.ts only checks the second expression for functions (noFunctionOrArray || ... is always true for the first). So latexEqual isn't symmetric. y=\left|x\right| as the target is compared, but as the answer it's always rejected. Worth its own ticket.

…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 master to develop November 3, 2026 13:38
@CarlaCostea
CarlaCostea merged commit 5b01946 into develop Nov 4, 2026
3 checks passed
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