Repository navigation
Add up two arctangents, and name the angles arctan knows - #692
Merged
Happypig375 merged 1 commit intoAug 4, 2026
Merged
Conversation
arctan(1/2) + arctan(1/3) is pi/4, and neither half of that was reachable: the two could not be added, and arctan(1) stayed as it was. The addition formula is the tangent one read backwards, arctan(a) + arctan(b) = arctan((a + b)/(1 - ab)). It holds as written only while ab < 1: past that the sum leaves the range arctan answers in and the identity is off by a whole pi, so arctan(2) + arctan(3) is 3pi/4 rather than arctan(-1). Both arguments are required to be numbers, which makes ab < 1 a question with an answer, and the ones past the boundary are left alone. arctan(1) and arctan(-1) are handled where arctan is simplified rather than offered to the simplifier as candidates. A candidate has to win on node count, and pi/4 does not beat arctan(1), so a sum that came to it stopped one step short. They sit beside the values at plus and minus infinity, which were already there. The two irrational ones, arctan(sqrt(3)) and arctan(1/sqrt(3)), do win their contest and stay where the other trigonometric patterns are. Checked over 289 pairs either side of the boundary: whatever a sum of two arctangents simplifies to is the same number it was. 17 tests, 8 of which fail without the change. 4026 in all, 127 F#, corpus 102/117 with simp:inverse-trig at 100% from 50%, and 1320 property checks.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #692 +/- ##
==========================================
- Coverage 80.99% 80.47% -0.53%
==========================================
Files 155 156 +1
Lines 13687 12938 -749
Branches 1957 2123 +166
==========================================
- Hits 11086 10412 -674
+ Misses 1990 1919 -71
+ Partials 611 607 -4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
It is pi/4, and neither half of that was reachable.
The addition formula
The tangent one read backwards:
arctan(a) + arctan(b) = arctan((a + b)/(1 − ab)).It holds as written only while
ab < 1. Past that the sum leaves the range arctan answers in and the identity is off by a whole pi —arctan(2) + arctan(3)is3pi/4, notarctan(−1). Both arguments are required to be numbers, which makesab < 1a question with an answer; the pairs past the boundary are left alone rather than answered wrongly.Why arctan(1) is not a simplification candidate
The two rational values are handled where arctan is simplified, beside the values at plus and minus infinity that were already there — not in the pattern pool.
A candidate offered to the simplifier has to win on node count, and
pi / 4does not beatarctan(1). So a sum that came all the way toarctan(1)stopped one step short of the answer. The two irrational ones,arctan(sqrt(3))andarctan(1/sqrt(3)), do win their contest and stay with the other trigonometric patterns.Verification
Checked over 289 pairs either side of the boundary, negatives included: whatever a sum of two arctangents simplifies to is the same number it was. That check is in the tests.
17 tests, 8 of which fail without the change. 4026 unit tests and 127 F# tests on both target frameworks, none failing. 117-problem self-verifying corpus at 102/117 —
simp:inverse-triggoes from 50% to 100% — with nothing wrong, in error or timing out. 1320 property checks over 151 expressions, none failing.