@@ -7030,7 +7030,20 @@ node is Powf(var xAgain, Number.Integer power) && xAgain == x && power.EInteger.
70307030 /// cancelled, power for power; the factors are kept as factors.
70317031 /// </summary>
70327032 private static Entity WithTheFactorsWrittenOnBothSidesCancelled(Entity.Variable u, Entity quotient)
7033+ => WithTheFactorsWrittenOnBothSidesCancelled(u, quotient, keepTheWrittenBases: false, out _);
7034+
7035+ /// <summary>
7036+ /// <paramref name="quotient"/> with each factor written alike above and below the bar, read
7037+ /// as its polynomial in <paramref name="u"/>, cancelled, power for power. What is left is
7038+ /// written over one bar with its bases as polynomials, or, with
7039+ /// <paramref name="keepTheWrittenBases"/>, with its bases as they were written and the
7040+ /// factors below the bar as negative powers. <paramref name="anyCancelled"/> says whether a
7041+ /// sum was on both sides; a power of <paramref name="u"/> alone is not counted, since the
7042+ /// differential of an exponential's substitution writes one below every integrand.
7043+ /// </summary>
7044+ private static Entity WithTheFactorsWrittenOnBothSidesCancelled(Entity.Variable u, Entity quotient, bool keepTheWrittenBases, out bool anyCancelled)
70337045 {
7046+ anyCancelled = false;
70347047 var (top, bottom) = Functions.SingleQuotient.Of(quotient);
70357048 Entity AsItsPolynomial(Entity @base)
70367049 {
@@ -7049,19 +7062,19 @@ Entity AsItsPolynomial(Entity @base)
70497062 }
70507063 return written.InnerSimplified;
70517064 }
7052- List<(Entity Base, EInteger Power)> Factors(Entity side)
7065+ List<(Entity Base, Entity Written, EInteger Power)> Factors(Entity side)
70537066 {
7054- var factors = new List<(Entity Base, EInteger Power)>();
7067+ var factors = new List<(Entity Base, Entity Written, EInteger Power)>();
70557068 foreach (var factor in Mulf.LinearChildren(side))
70567069 {
7057- var (@base , power) = factor is Powf(var raised , Number.Integer exponent) && exponent.EInteger.Sign > 0
7058- ? (raised , exponent.EInteger) : (factor, EInteger.One);
7059- @base = AsItsPolynomial(@base );
7070+ var (raised , power) = factor is Powf(var raisedBase , Number.Integer exponent) && exponent.EInteger.Sign > 0
7071+ ? (raisedBase , exponent.EInteger) : (factor, EInteger.One);
7072+ var @base = AsItsPolynomial(raised );
70607073 var at = factors.FindIndex(written => written.Base == @base);
70617074 if (at < 0)
7062- factors.Add((@base, power));
7075+ factors.Add((@base, keepTheWrittenBases ? raised : @base, power));
70637076 else
7064- factors[at] = (@base, factors[at].Power.Add(power));
7077+ factors[at] = (@base, factors[at].Written, factors[at]. Power.Add(power));
70657078 }
70667079 return factors;
70677080 }
@@ -7075,12 +7088,17 @@ Entity AsItsPolynomial(Entity @base)
70757088 if (j < 0)
70767089 continue;
70777090 var common = EInteger.Min(above[i].Power, below[j].Power);
7078- above[i] = (above[i].Base, above[i].Power.Subtract(common));
7079- below[j] = (below[j].Base, below[j].Power.Subtract(common));
7091+ if (common.Sign > 0 && above[i].Base is Sumf or Minusf)
7092+ anyCancelled = true;
7093+ above[i] = (above[i].Base, above[i].Written, above[i].Power.Subtract(common));
7094+ below[j] = (below[j].Base, below[j].Written, below[j].Power.Subtract(common));
70807095 }
7081- static Entity Product(List<(Entity Base, EInteger Power)> factors)
7096+ static Entity Product(List<(Entity Base, Entity Written, EInteger Power)> factors)
70827097 => factors.Where(written => !written.Power.IsZero).Aggregate((Entity)Number.Integer.One,
7083- (product, written) => product * (written.Power.Equals(EInteger.One) ? written.Base : MathS.Pow(written.Base, Number.Integer.Create(written.Power))));
7098+ (product, written) => product * (written.Power.Equals(EInteger.One) ? written.Written : MathS.Pow(written.Written, Number.Integer.Create(written.Power))));
7099+ if (keepTheWrittenBases)
7100+ return below.Where(written => !written.Power.IsZero).Aggregate(Product(above),
7101+ (product, written) => product * MathS.Pow(written.Written, Number.Integer.Create(written.Power.Negate()))).InnerSimplified;
70847102 return (Product(above) / Product(below)).InnerSimplified;
70857103 }
70867104
@@ -26609,8 +26627,22 @@ static bool IsAMonomialIn(Entity expr, Entity.Variable x)
2660926627 // `1/((a + b u)^2 ln F)` is a quadratic below the bar with `ln F` in every
2661026628 // coefficient, and the symbolic quadratic rule answers that as a piecewise on
2661126629 // whether `b^2 ln F` is zero, where `1/(a + b u)^2` is `-1/(b (a + b u))`.
26612- var integrand = Functions.SingleQuotient.Combine(
26613- rewritten / (Number.Rational.Create(k) * u)).Simplify();
26630+ // With symbols in it, a sum the substitution writes on both sides is cancelled as it is
26631+ // written, in place of the simplification: `csch(x)^2/(a + b coth(x))^2` is
26632+ // `4 (u^2 - 1)^2 u^2/((u^2 - 1)^2 (a (u^2 - 1) + b (u^2 + 1))^2 u)`, and the search for a
26633+ // simpler form, which with the factor in it grows with the symbols, ran past twenty
26634+ // seconds on it -- Rubi's 6.4.2 `x csch(x)^2/(a + b coth(x))^2` timed out on that, by
26635+ // parts against the whole rational function -- where cancelled it is
26636+ // `4 u (a (u^2 - 1) + b (u^2 + 1))^(-2)` in seven milliseconds. Left as the product the
26637+ // cancellation writes, which is what the search wrote for the tangent's
26638+ // `sech(x)^2/(a + b tanh(x))^2` after three seconds: simplified once more it is a
26639+ // quotient, which the symbolic quadratic rule answers with the case `a + b = 0` apart,
26640+ // and a piecewise antiderivative leaves parts a piecewise to integrate. With numbers
26641+ // alone, or no sum written twice, it is simplified as it was.
26642+ var combined = Functions.SingleQuotient.Combine(rewritten / (Number.Rational.Create(k) * u));
26643+ var integrand = combined.Vars.Any(symbol => symbol != u)
26644+ && WithTheFactorsWrittenOnBothSidesCancelled(u, combined, keepTheWrittenBases: true, out var anyCancelled) is var cancelled && anyCancelled
26645+ ? cancelled : combined.Simplify();
2661426646 if (integrand is Providedf(var inner, _))
2661526647 integrand = inner;
2661626648 integrand = WithLogarithmArgumentsOverOneBar(integrand, u);
0 commit comments