Skip to content

Open up multiple angles, and integrate the squares of sine and cosine - #671

Merged
Happypig375 merged 1 commit into
ASC-Community:masterfrom
Rafael-SOWNet:feat/multiple-angle-trig
Aug 3, 2026
Merged

Happypig375 merged 1 commit into
ASC-Community:masterfrom
Rafael-SOWNet:feat/multiple-angle-trig

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

Two things the library could not do, both reached by wiring up machinery that was
already here.

Multiple angles never opened

sin(2x) and cos(2x) stayed as written, so identities in them did not close:

cos(2x) - (1 - 2sin(x)^2)      →  unchanged     now  0
sin(2x) - 2sin(x)cos(x)        →  unchanged     now  0
sin(4x) - 2sin(2x)cos(2x)      →  unchanged     now  0
cos(2x) + sin(x)^2             →  unchanged     now  cos(x)^2

The expansions were not missing. TrigonometricAngleExpansion.ExpandSineArgumentMultiplied
and its cosine twin have been in the tree all along, and were only ever reached for
numeric angles that are multiples of pi. This wires them to a symbolic sin(n x) for
whole n up to 8, past which the expansion is longer than anything it buys.

The expanded form is offered to the simplifier as a candidate, the way the
polynomial factorer's is, so the complexity metric decides. sin(2x) on its own
therefore still prints as sin(2x) — opening it there would only make it longer.

The squares of sine and cosine could not be integrated

∫ sin(x)^2 dx fell through to integration by parts and cycled there until it ran out
of stack. Power reduction, sin(u)^2 = (1 - cos(2u))/2, gives the integral outright, so
it goes in the integral table:

∫ sin(x)^2 dx        →  x/2 - sin(2x)/4
∫ cos(3x)^2 dx       →  x/2 + sin(6x)/12
∫ sin(2x + 1)^2 dx   →  x/2 - sin(2(2x+1))/8

Each is checked by differentiating back at several points, not by comparing strings.

What this does not fix

Worth being explicit, because #557 is the issue this looked like it would close and it
does not:

Both need a pair of trigonometric terms to be recognised across a subtraction.
sin^2 + cos^2 = 1 is matched as a pair of adjacent terms, and in these two the pair
sits either side of a -. That is the same pairwise-versus-flattened gap as #531, in
trigonometry rather than in a polynomial sum, and opening the angle cannot reach it.
There are tests pinning exactly where each of them stops, so the remaining distance is
recorded rather than implied.

Testing

UnitTests 3676 passed / 0 failed, FSharpWrapperUnitTests 127 passed / 0 failed, and
both netstandard2.0 and net7.0 build.

18 new tests: the identities that close, the two that do not, the compact forms that
must be left alone, value preservation under expansion at several points, and the four
integrals.

Independent of #663 through #670.

🤖 Generated with Claude Code

sin(2x) and cos(2x) never opened into single-angle form, so identities in them did
not close: cos(2x) - (1 - 2sin(x)^2) stayed as it was written rather than reducing
to 0.

The expansions were already here. TrigonometricAngleExpansion.ExpandSineArgument-
Multiplied and its cosine twin have been in the tree all along, reached only for
numeric angles that are multiples of pi. This wires them to a symbolic sin(n x) for
whole n up to 8, past which the expansion is longer than anything it buys.

The expanded form is offered to the simplifier as a candidate rather than taken, the
way the polynomial factorer's is, so the complexity metric decides. sin(2x) on its
own therefore still prints as sin(2x), while cos(2x) + sin(x)^2 now comes back as
cos(x)^2.

Separately, power reduction goes into the integral table: sin(u)^2 = (1 - cos(2u))/2
gives the integral directly, where before sin(x)^2 fell through to integration by
parts and cycled there until it ran out of stack.

Not fixed, and worth being clear about: #557 itself gets further than it did but
still does not reach 0, and cos(2x) - (2cos(x)^2 - 1) stops at 1 - cos(x)^2 -
sin(x)^2. Both need a pair of trigonometric terms to be spotted across a
subtraction, which is the pairwise-versus-flattened gap of #531 rather than
anything about angles. Tests pin where each of them actually stops.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 94.59459% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.49%. Comparing base (90c00a8) to head (c8bf8cc).
⚠️ Report is 41 commits behind head on master.

Files with missing lines Patch % Lines
...ouriMath/Functions/Simplification/Simplificator.cs 83.33% 0 Missing and 2 partials ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #671      +/-   ##
==========================================
- Coverage   80.99%   79.49%   -1.50%     
==========================================
  Files         155      155              
  Lines       13687    12331    -1356     
  Branches     1957     1990      +33     
==========================================
- Hits        11086     9803    -1283     
+ Misses       1990     1940      -50     
+ Partials      611      588      -23     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Happypig375
Happypig375 merged commit e7cab69 into ASC-Community:master Aug 3, 2026
21 of 24 checks passed
@Rafael-SOWNet
Rafael-SOWNet deleted the feat/multiple-angle-trig branch August 4, 2026 20:48
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.

3 participants