You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 081b56f
Browse filesBrowse the repository at this point in the historyBrowse files
Cancel a power of a cosine over a binomial in the sine (#1930)
* Cancel a power of a cosine over a power of one plus a sine before integrating
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
* Record the cosine powers over a binomial in the sine in BREAKING-CHANGES
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
---------
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
static IEnumerable<(Entity Factor, bool Below)> Factors(Entity e, bool below) => e switch
26732
+
{
26733
+
Mulf(var l, var r) => Factors(l, below).Concat(Factors(r, below)),
26734
+
Divf(var l, var r) => Factors(l, below).Concat(Factors(r, !below)),
26735
+
_ => new[] { (e, below) }
26736
+
};
26737
+
var factors = Factors(expr, false).ToList();
26738
+
foreach (var (candidate, isBelow) in factors)
26739
+
{
26740
+
if (!isBelow)
26741
+
continue;
26742
+
var (binomial, n) = candidate is Powf(var b0, Number.Integer { EInteger: var p0 }) && p0.Sign > 0 && p0.CanFitInInt32()
26743
+
? (b0, p0.ToInt32Unchecked()) : (candidate, 1);
26744
+
// k (1 + sigma f(y)), f a sine or a cosine.
26745
+
var functions = binomial.Nodes.Where(node => node is Sinf or Cosf && node.ContainsNode(x)).Distinct().ToList();
26746
+
if (functions.Count != 1)
26747
+
continue;
26748
+
var function = functions[0];
26749
+
var s0 = Variable.CreateUnique(expr, "s_cs");
26750
+
if (!TreeAnalyzer.TryGetPolyLinear(binomial.Substitute(function, s0), s0, out var slope, out var k)
26751
+
|| slope is null || k is null || slope.ContainsNode(x) || k.ContainsNode(x)
26752
+
|| Functions.PartialFractions.IsZeroAsAValue(k))
26753
+
continue;
26754
+
var sigma = (slope / k).InnerSimplified;
26755
+
int sign;
26756
+
if (Functions.PartialFractions.IsZeroAsAValue((sigma - 1).InnerSimplified)) sign = 1;
26757
+
else if (Functions.PartialFractions.IsZeroAsAValue((sigma + 1).InnerSimplified)) sign = -1;
26758
+
else continue;
26759
+
var argument = function is Sinf(var ys) ? ys : ((Cosf)function).Argument;
26760
+
Entity complement = function is Sinf ? MathS.Cos(argument) : MathS.Sin(argument);
26761
+
// The complement's power above the bar.
26762
+
var m = 0;
26763
+
foreach (var (factor, below) in factors)
26764
+
if (!below && (factor == complement ? 1 : factor is Powf(var b1, Number.Integer { EInteger: var p1 }) && b1 == complement && p1.CanFitInInt32() ? p1.ToInt32Unchecked() : 0) is var power and > 0)
26765
+
m += power;
26766
+
if (m < 2 * n)
26767
+
continue;
26768
+
// Everything but the binomial and the complement's powers, times what the cancelling leaves.
26769
+
Entity rest = Number.Integer.One;
26770
+
foreach (var (factor, below) in factors)
26771
+
{
26772
+
if (below && factor == candidate)
26773
+
continue;
26774
+
if (!below && (factor == complement || factor is Powf(var b2, Number.Integer) && b2 == complement))
0 commit comments