Skip to content

A squared sine and cosine with one coefficient are found anywhere in a sum - #2175

Merged
Rafael-SOWNet merged 1 commit into
masterfrom
a-pythagorean-pair-with-a-coefficient-is-found-anywhere
Oct 27, 2026
Merged

Rafael-SOWNet merged 1 commit into
masterfrom
a-pythagorean-pair-with-a-coefficient-is-found-anywhere

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

Part of #2133: the part where the result depends on how a sum is written.

The defect: the gathered Pythagorean rule matches sin(x)^2 and cos(x)^2 wherever they sit in a sum, but only with a coefficient of 1. With a coefficient, the pair was left to SharedFactor, which sees two siblings only, so the order the sum was sorted into decided:

  • y + (-2) cos(x)^2 + (-2) sin(x)^2 came out y - 2;
  • 2 + (-2) cos(x)^2 + (-2) sin(x)^2, where the constant sorts between the two, stayed as written.

#2133's 2 + (-2) cos(2x) + (-4) sin(x)^2 opens to that second form and stopped there, while 2 - 2 cos(2x) - 4 sin(x)^2 reached 0.

The change: a second rule in the set, squared-sine-and-cosine-with-one-coefficient-sum-to-it. It gathers k sin(x)^2 and k cos(x)^2 with the same argument and the same coefficient, and writes k.

  • It is Sound for every complex k and x, has a pattern on both sides, and its growth is Collects.
  • It has no backwards reading, since it forgets the angle, as the first rule does.
  • Unequal coefficients and different arguments are left alone: 2 sin(x)^2 + 3 cos(x)^2, and k sin(x)^2 + k cos(y)^2.

The census moves by one in WritingARule.md, in the remark in Saturation.cs, and in the tests that pin them. ReversibleRuleTest now checks every rule of the set, where it used Single().

Simplify 2.6.0 this PR
2 + (-2)*cos(x)^2 + (-2)*sin(x)^2 unchanged 0
2 + (-2) * cos(2 * x) + (-4) * sin(x) ^ 2 unchanged 0

Not in this PR: (cos(2x) - 1)^2 + sin(2x)^2 - 4 sin(x)^2 still stops at 2 + (-2) cos(2x) + (-4) sin(x)^2, which one more Simplify now takes to 0. That is #2133's main point, Simplify not simplifying its own answer. Making it iterate would cost every call whose answer differs from its input, so it needs its own measurement.

Checked:

🤖 Generated with Claude Code

https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura

…a sum

The gathered Pythagorean rule matches sin(x)^2 and cos(x)^2 wherever they
sit in a sum, but only with a coefficient of one. With a coefficient the
pair was left to SharedFactor, which sees two siblings, so the sort
decided: y + (-2) cos(x)^2 + (-2) sin(x)^2 came out y - 2, and
2 + (-2) cos(x)^2 + (-2) sin(x)^2, where the constant sorts between the
two, stayed. #2133's 2 + (-2) cos(2x) + (-4) sin(x)^2 opens to that and
stopped there, while 2 - 2 cos(2x) - 4 sin(x)^2 reached 0.

squared-sine-and-cosine-with-one-coefficient-sum-to-it gathers
k sin(x)^2 and k cos(x)^2 of one argument and one coefficient and writes
k: Sound for every complex k and x, two-sided, Collects, and with no
backwards reading, since it forgets the angle as the first rule does. The
census moves by one in WritingARule.md, Saturation's remark and the tests
that pin them; ReversibleRuleTest asks every rule of the set instead of
Single().

(cos(2x) - 1)^2 + sin(2x)^2 - 4 sin(x)^2 still stops at
2 + (-2) cos(2x) + (-4) sin(x)^2, which one more Simplify now takes to 0:
that is #2133's main point, Simplify not simplifying its own answer, and
is not this change.

On 2.6.0 and on this branch, Simplify:
  2 + (-2)*cos(x)^2 + (-2)*sin(x)^2           unchanged -> 0
  2 + (-2) * cos(2 * x) + (-4) * sin(x) ^ 2   unchanged -> 0
Chain against master 966f26a: verdicts identical, 0 moves; performance
gate passed on all 19; unit suite 17,159 passed, 0 failed. RuleCheck
passes, Confluence and CanonCheck match their baselines, SimpSweep
10,463/10,463.

Part of #2133

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
@Rafael-SOWNet Rafael-SOWNet added this to the 2.7.0 milestone Oct 27, 2026
@Rafael-SOWNet Rafael-SOWNet moved this from Todo to In review in AngouriMath Oct 27, 2026
@codecov

codecov Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.45%. Comparing base (966f26a) to head (20743ad).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #2175   +/-   ##
=======================================
  Coverage   86.44%   86.45%           
=======================================
  Files         295      295           
  Lines       64905    64930   +25     
  Branches    19092    19092           
=======================================
+ Hits        56108    56132   +24     
+ Misses       4770     4769    -1     
- Partials     4027     4029    +2     
Flag Coverage Δ
cpp 37.77% <ø> (ø)
csharp 87.02% <100.00%> (+<0.01%) ⬆️
fsharp 32.97% <ø> (ø)
interactive 40.72% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...Math/Core/Transformations/Matching/MatchedRules.cs 99.57% <100.00%> (+<0.01%) ⬆️
...ces/AngouriMath/Core/Transformations/Saturation.cs 93.33% <ø> (ø)

... and 8 files with indirect coverage changes

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

@Rafael-SOWNet
Rafael-SOWNet merged commit c90db9f into master Oct 27, 2026
35 checks passed
@github-project-automation github-project-automation Bot moved this from In review to Done in AngouriMath Oct 27, 2026
Rafael-SOWNet added a commit that referenced this pull request Oct 27, 2026
…e's is (#2177)

sin(x)^2 - (1 - cos(2x))/2 simplified to 0 and cos(x)^2 - (1 + cos(2x))/2
did not. Its candidates reach -1/2 + cos(x)^2 / 2 + sin(x)^2 / 2, which is 0,
and stopped there: a rational coefficient is written as a divisor, so
k sin(x)^2 + k cos(x)^2 = k (#2175) does not see cos(x)^2 / 2, and the
two squares are not siblings for the switch's rules either.

squared-sine-and-cosine-over-one-divisor-sum-to-its-reciprocal gathers
sin(x)^2 / d and cos(x)^2 / d of one argument and one divisor and writes
1 / d: Sound, since both sides are defined exactly where d is not 0,
two-sided, Collects, and with no backwards reading, as it forgets the
angle. Two different divisors are left alone. The census moves by one in
WritingARule.md, Saturation's remark and the tests that pin them.

On 2.6.0 and on this branch, Simplify:
  cos(x)^2 - (1 + cos(2*x))/2   unchanged -> 0
Chain against master 856b3cb: verdicts identical, 0 moves; performance
gate passed on all 19; unit suite 17,169 passed, 0 failed. RuleCheck
passes, Confluence and CanonCheck match their baselines, SimpSweep
10,463/10,463.

Part of #2142


Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant