Repository navigation
fix(symbolic): stop accepting wrong answers to two-variable equations with powers (PIE-443) - #77
Merged
Merged
Conversation
…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.
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.
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),
solveLinearEquationreturnsundefinedfor both sides, soundefined === undefinedscored 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: ondevelop,y=2x+1vsy=3xis 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 tellx^2fromy^2.Change
compare-equations.ts, two-variable equations: replaced the x = 1 solve with a numeric check. Both equations are moved toF = 0andG = 0form and evaluated at sample points. They are equivalent whenF/Gis 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 inlinear-equations-in-two-variables.tsaccept multiplying or dividing both sides by a variable (for examplex+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 (fromrationalize).F = N/Dis zero exactly whereNis, so this accepts both sides multiplied by an expression such asx-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.rationalizeexpands 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}=1vs(x+1)^7=2(y-1)^7would otherwise take about 40 seconds.compare-equations.ts, one-variable equations: when neither the linear nor the quadratic solver applies (both used to returnundefined, so the answer was scored incorrect), fall back to the same check, but with a strict constant ratio only. Multiplying byxwould add the rootx = 0.compare-equations.ts, two-variable inequalities: the x = 1 path is kept, with the missing!== undefinedguard 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 tellx^2fromy^2, and negative values tell|x|fromxand\sqrt{x^6}fromx^3. Points where a side isn't a real number (for example\sqrt{x}at negativex) 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:
\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}...,...=5y=2x+1vsy=3x.y=\left|x\right|vsy=xory=-x, andy=\sqrt{x^2}vsy=x.x^2+y^2=-1vsx^2+y^2=-4. Both have no real solutions, so strictly they're equivalent.developaccepted them only through theundefined === undefinedbug.Answers that were previously scored incorrect and are now scored correct:
x^3=8vs2x^3=16.Answers whose scoring is unchanged:
36x^2+64y^2=2,304.\frac{y-1}{x-2}=3vsy-1=3(x-2),y=\frac{2x+1}{x-3}vsy(x-3)=2x+1,y=\frac{4}{x+3}vsxy+3y=4.\sqrt{x^6}=8,\left|x\right|^3=8and\left|x^3\right|=8vsx^3=8.Tests
develop): 1546 passed. After: 1638 passed (+83 new fixtures insrc/fixtures/latex-equal/symbolic/PIE-443.ts, +9 unit tests insrc/__tests__/utils.spec.ts).tsc --noEmitis clean.src/symbolicfromdevelop, exactly the 31 changed-answer cases fail.Follow-up
docs/) to be regenerated after merge.xy=0vs\frac{x}{y}=0is scored correct, even thoughxy=0also contains the liney = 0. This is the same trade-off as the existingx+2y=7≡x^2+2yx-7x=0fixture.\frac{x^3-8}{x-2}=0vs2x^3=16is scored correct, even though x = 2 is excluded from the first. Similar pairs such as\frac{x^2-4}{x-2}=0vsx^2-4=0were already accepted ondevelop.x > 0andy > 0. So expressions that are real only there (for examplex^{0.5}+y^{0.5}), or only forx > 3(sample values reach 4.5), get fewer than 3 usable points and are rejected.developrejects the cases tried as well.(x^2)^{\frac32}=8vsx^3=8is still accepted on both branches, probably because the simplifier rewrites(a^b)^cbefore the numeric check runs.expressionsCanBeComparedinutils.tsonly checks the second expression for functions (noFunctionOrArray || ...is always true for the first). SolatexEqualisn't symmetric.y=\left|x\right|as the target is compared, but as the answer it's always rejected. Worth its own ticket.