-
Notifications
You must be signed in to change notification settings - Fork 365
[Interactive Graph] Update tangent notes for AI shared context #3333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| --- | ||
| --- |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 The claim that grapher-util.ts's
canonicalTangentCoefficients()is "kept in sync with the kmath version" (line 50) is inaccurate. The grapher-util.ts version (lines 58-91) guarantees botha > 0andb > 0using aphase += period/2step, while this same PR's documentation elsewhere correctly states the kmath version can only guaranteeb > 0using the odd function identity. Consider rewording to note that the grapher-util.ts copy uses a different (and mathematically questionable) normalization strategy.Extended reasoning...
What the bug is
Line 50 of the updated tangent.md introduces the phrase: grapher-util.ts has "its own copy of
canonicalTangentCoefficients()(kept in sync with the kmath version)". This claim is internally inconsistent with the rest of the documentation added by this same PR.The inconsistency in detail
The grapher-util.ts
canonicalTangentCoefficients()(lines 58-91) implements a two-step normalization:a > 0: flips signs ofamplitude,angularFrequency, andphaseb > 0: flipsangularFrequencyandphase, then doesphase += period/2Meanwhile, the PR's own documentation at lines 113-116 describes the kmath version as using a fundamentally different approach:
b > 0using the odd function identity:a * tan(-|b|x - c) = (-a) * tan(|b|x - (-c)), which flips signs ofaandcb > 0can be guaranteed"These are different algorithms with different guarantees (
a > 0 AND b > 0vs onlyb > 0).Why the grapher-util.ts approach is mathematically questionable
The grapher-util.ts version uses
phase += period/2(i.e.,phase += π/2) to guaranteeb > 0. This step implicitly relies ontan(x + π/2) = -tan(x), but that identity is incorrect:tan(x + π/2) = -cot(x), not-tan(x). The sine version works becausesin(x + π) = -sin(x)is a valid identity. The tangent version appears to be a copy-paste from the sine normalization with only the period changed from2πtoπ, without accounting for the different trigonometric identities.Step-by-step proof of the discrepancy
Consider
f(x) = -1 * tan(-2x - 1) + 0(a = -1, b = -2, c = 1, d = 0).grapher-util.ts algorithm:
tan(2x - 2.14)with a = 1, b = 2kmath algorithm (as documented):
Actually: a * tan(-|b|x - c) = (-a) * tan(|b|x + c), so a becomes 1, c becomes -1, b becomes 2
1 * tan(2x - 2.14)with a = 1, b = 2In this case they agree, but the key difference is that the grapher-util.ts version always guarantees a > 0 as an independent first step, while the kmath version does not have this guarantee. For cases where a < 0 and b > 0, the grapher-util.ts version will flip a positive while also flipping b negative, then use the questionable phase shift to fix b. The kmath version would leave a negative since b is already positive.
Impact
This is a documentation-only issue in an AI shared context notes file. The "kept in sync" claim could mislead developers or AI assistants into thinking the two implementations are interchangeable or identical, when they are not. Since this PR is specifically updating these notes for accuracy, the claim should be corrected.
Suggested fix
Replace "kept in sync with the kmath version" with something like "uses a different normalization algorithm that guarantees both a > 0 and b > 0, unlike the kmath version which only guarantees b > 0".