Repository navigation
fix(symbolic): stop treating large numbers as infinity (PIE-1418) - #78
Merged
Merged
Conversation
normalize() replaced any constant result >= 1,497,258 (or <= -1,497,258) with Infinity, so 2000000 and 3000000 were scored as equal. The cutoff was tan(90°) under the 355/113 approximation of pi. Undefined trigonometric values are now detected directly: before normalizing, tan/sec at odd multiples of pi/2 and cot/csc at multiples of pi become Infinity, and sin/cos at their zeros become an exact 0. A constant expression containing an undefined value is evaluated numerically, since simplify treats Infinity as a variable. The size cutoff is removed, so large numbers are compared by value.
…zero no sign (PIE-1418) Tighten the angle tolerance to 2e-7 quarter turns relative to k, so angles that are only close (89.9999°, 1.5708) are no longer undefined. Snap tan and cot to 0 at their zeros, evaluate every constant expression with a snapped value so -1/cos(90°) is unsigned Infinity, and keep indeterminate results such as tan(90°)-tan(90°) as NaN instead of 0.
…s next to replaced zeros (PIE-1418)
Keeps both sides of the conflict in src/symbolic/index.ts: the numeric comparison helpers from PIE-905 and isIndeterminate from PIE-1418. Degrees now convert with Math.PI, so angles are matched against Math.PI only.
|
🎉 This PR is included in version 1.4.3 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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, any answer that worked out to 1,497,258 or more (or −1,497,258 or less) was treated as infinity, so any two large numbers were scored as equal (
2000000vs3000000). Large numbers are now compared by value. Only trigonometric values that are undefined at an exact multiple of 90° (such as\tan(90°)) and an explicit\inftycount as infinity.Jira: https://illuminate.atlassian.net/browse/PIE-1418
Why it happened
normalize()insrc/symbolic/index.tsreplaced any constant result at or beyond±1.497258191621251e6with theInfinitysymbol. That number istan(90°)when degrees are converted with the 355/113 approximation of π: 90° lands about 1e-7 away from π/2, sotan(90°)comes out as a large finite number rather than infinity. The cutoff was meant to catch those undefined trig values, but it applied to every number.Change
src/symbolic/index.ts:tan/secat odd k andcot/cscat even k becomeInfinity.sin,cos,tanandcotat their zeros become0.Math.PI, so exact multiples of 90° land within that. Angles that are only close don't match, however large k is:89.9999°,1.5708,9090.001°,\tan(10000000).Infinity, is evaluated numerically before normalizing. Other constant expressions keep the normal symbolic path, so exact values stay exact (\sin(0)+\frac{1}{3}=\frac{1}{3}). OnlypiandInfinitycount as constants. Any other letter is a variable, even names mathjs knows, such ase,Eandphi.simplify/rationalizetreatInfinityas a variable, for example1/\tan(90°)+3becomes(1 + 3·Infinity)/Infinity. They also keep the sign of a division by zero.-\tan(90°)and-\frac{1}{\cos(90°)}are both ∞. That keeps2\tan(90°)= ∞ and\frac{1}{\tan(90°)}= 0 working as before.\tan(90°)-\tan(90°),0\cdot\tan(90°),\frac{\tan(90°)}{\tan(90°)}) becomesNaN, whichisMathEqualnever treats as equal to anything, including another indeterminate result.Infinity.Builds on PIE-905 (#76, merged), which moved degree conversion to
Math.PIand removed the 4-decimal rounding.developis merged in. The conflict was inindex.ts, where both PRs add helpers in the same place, and it was resolved by keeping both.Scoring impact
Compared with
develop.Answers that were previously scored correct and are now scored incorrect:
2000000vs3000000,2000001,1999999, and10^9vs10^{10}2000000vs\inftyand\tan(90°)-2000000vs20000001497259vs1497260and1600000\inftyvs-\infty, because-\inftyalso fell under the negative cutoff, and-\frac{1}{\cos(90°)}vs-\infty\tan(90°)-\tan(90°)and0\cdot\tan(90°)vs0,\frac{\tan(90°)}{\tan(90°)}vs1, and0\cdot\tan(90°)vs\frac{0}{0}Answers that were previously scored incorrect and are now scored correct:
\cos(90°)\cdot10^7vs0x=\tan(90°)vsx=\infty,x+\tan(90°)vsx+\inftyy=\tan(90°)xvsy=\infty x, andx<\tan(90°)vsx<\inftyAnswers whose scoring is unchanged:
degrees-and-gradians.tsis still ∞:\tan(90°),\cot(0°),\csc(180°),\sec(270°),\tan(\pi/2),\tan(100\grad)and the rest.\tan(450°),\tan(-90°),-\tan(90°)and2\tan(90°)are still ∞.\frac{1}{\cos(90°)},-\frac{1}{\cos(90°)},\frac{1}{\tan(180°)},\frac{1}{\cot(90°)}, and\frac{2}{\sin(180°)}vs\frac{-2}{\sin(180°)}.\frac{1}{\tan(90°)}+3is still 3.\tan(1.5708),\tan(89.9999°),\tan(9090.001°),\csc(3.1416), and\sin(3.1416)\cdot10^6≠ 0.\sin(0)+\frac{1}{3}=\frac{1}{3},\tan(0°)+\frac{5}{6}=\frac{5}{6}, and\sin(0)+\phi=\phi.Tests
develop, with fix(symbolic): stop accepting near-miss numbers (PIE-905) #76): 1597 passed. After: 1681 passed (+84 fixtures insrc/fixtures/latex-equal/symbolic/PIE-1418.ts).tsc --noEmitis clean.develop'ssrc/symbolic/index.ts, exactly the 24 changed-answer cases fail.Follow-up
docs/) to be regenerated after merge.0<x<\tan(90°)vs0<x<\inftythrew ondevelopand is now scored incorrect. The compound-inequality path doesn't go through this normalization yet.x=0\cdot\tan(90°)vsx=0and0\cdot\tan(90°)+xvsx.\infty-\inftywithout trig is still 0, as ondevelop.\tan90\deg(no parentheses) parses astan(90 rad)·deg, a separate parser issue that was already wrong ondevelop.