@@ -32216,6 +32216,16 @@ static System.Numerics.Complex ToComplex(Number.Complex number)
3221632216
3221732217 // dx = c dt.
3221832218 var t = Variable.CreateUnique(expr, "u_scale");
32219+ // Homogeneous or not, read at two points first: the scaled integrand over itself at
32220+ // c = 1 is c^k wherever it is c^k h(t), the same at every t for a positive c, and
32221+ // where it is not the same the simplifications below cannot make it so. Each of
32222+ // them is a simplification of the whole integrand with the symbol in it, and the
32223+ // third alone, of the quotient, ran past thirty seconds on the rational function the
32224+ // imaginary tangent's substitution makes of Rubi's `tan(c + d x)^4/(a + i a tan(c + d x))^(4/3)`
32225+ // before it was declined. https://github.com/asc-community/AngouriMath/issues/718
32226+ var scaledAsWritten = expr.Substitute(x, scale * t) * scale;
32227+ if (VariesWith((scaledAsWritten / scaledAsWritten.Substitute(scale, Number.Integer.One)).Substitute(scale, Number.Rational.Create(137, 100)), t))
32228+ return null;
3221932229 // With the imaginary unit in the integrand the simplifier's search beside the symbol
3222032230 // does not end within any budget, and inner simplification separates what a whole
3222132231 // power of the scale does: `((1 + i a x)/(1 - i a x))^(-5/4)/x^2` under its radical's
@@ -39713,6 +39723,55 @@ void Add(Entity root, Entity times)
3971339723 }
3971439724 }
3971539725
39726+ /// <summary>
39727+ /// Whether <paramref name="expr"/> takes two clearly different values at two positive
39728+ /// points of <paramref name="x"/>, every other symbol pinned to the same number at both:
39729+ /// then it depends on <paramref name="x"/> as a function of all its symbols, and no
39730+ /// rewriting that keeps its value writes it without <paramref name="x"/>. False wherever
39731+ /// a value cannot be had, and wherever the two agree.
39732+ /// </summary>
39733+ private static bool VariesWith(Entity expr, Entity.Variable x)
39734+ {
39735+ var values = new[] { "1.37", "0.61", "2.23", "1.91", "0.83", "1.13" };
39736+ var pinned = expr;
39737+ var index = 0;
39738+ foreach (var symbol in expr.Vars.Distinct().ToList())
39739+ if (symbol != x)
39740+ pinned = pinned.Substitute(symbol, Number.Real.Create(EDecimal.FromString(values[index++ % values.Length])));
39741+ Number.Complex? At(string point)
39742+ => pinned.Substitute(x, Number.Real.Create(EDecimal.FromString(point))).Evaled is Number.Complex { IsNaN: false } number && number.IsFinite
39743+ ? number : null;
39744+ if (At("0.47") is not { } first || At("1.53") is not { } second)
39745+ return false;
39746+ var scale = System.Math.Max(1.0, System.Math.Max(((Number.Real)first.Abs()).EDecimal.ToDouble(), ((Number.Real)second.Abs()).EDecimal.ToDouble()));
39747+ return ((Number.Real)(first - second).Abs()).EDecimal.ToDouble() > 1e-6 * scale;
39748+ }
39749+
39750+ /// <summary>
39751+ /// Whether <paramref name="candidate"/> is a factor free of <paramref name="x"/> with a
39752+ /// symbol in it times a function of <paramref name="x"/>, and what it leaves of
39753+ /// <paramref name="x"/> in <paramref name="integrandInU"/> may be a constant times its power
39754+ /// from -2 to 2: the quotient by one of those powers does not vary with <paramref name="x"/>,
39755+ /// read off two points, or cannot be read there. That is what
39756+ /// <see cref="WithTheCandidatesPowerLeftInX"/> takes from the simplified quotient, where the
39757+ /// factor stands on both sides of the bar and its cancelling is the condition that it is not
39758+ /// zero, under which the candidate varies at all. Never beside a linear candidate, which that
39759+ /// rewriting does not read.
39760+ /// </summary>
39761+ private static bool APowerOfACandidateWithASymbolicFactorMayBeLeftIn(Entity integrandInU, Entity candidate, Entity.Variable x)
39762+ {
39763+ if (IsWrittenAsAPolynomial(candidate, x) && TreeAnalyzer.TryGetPolynomial(candidate, x, out var asAPolynomial)
39764+ && asAPolynomial.Keys.Max()!.CompareTo(EInteger.One) <= 0)
39765+ return false;
39766+ var (above, below) = Functions.SingleQuotient.Of(candidate);
39767+ if (!Mulf.LinearChildren(above).Concat(Mulf.LinearChildren(below)).Any(factor => !factor.ContainsNode(x) && factor.Vars.Any()))
39768+ return false;
39769+ foreach (var power in new[] { -1, 1, -2, 2 })
39770+ if (!VariesWith(integrandInU / MathS.Pow(candidate, power), x))
39771+ return true;
39772+ return false;
39773+ }
39774+
3971639775 /// <summary>
3971739776 /// Whether <paramref name="expr"/> over <paramref name="derivative"/> takes two values at
3971839777 /// two points where <paramref name="candidate"/> takes one -- every other symbol pinned --
@@ -40108,6 +40167,10 @@ private static bool VariesWithTheVariableWhereTheCandidateIsHeld(Entity expr, Va
4010840167 /// </remarks>
4010940168 private static Entity? WithTheCandidatesPowerLeftInX(Entity integrandInU, Entity u, Variable uSub, Entity.Variable x)
4011040169 {
40170+ // A condition on the constants, `provided not e = 0` from a change of scale, is read
40171+ // past and kept: as one factor it held both x and the candidate's variable.
40172+ if (integrandInU is Providedf(var provided, var condition) && !condition.ContainsNode(x) && !condition.ContainsNode(uSub))
40173+ return WithTheCandidatesPowerLeftInX(provided, u, uSub, x) is { } read ? read.Provided(condition) : null;
4011140174 // Not for a linear candidate: what is left of x beside `u = f x` is always a power of u,
4011240175 // and taking the change of scale here asks the same question again in u, ahead of the
4011340176 // rules that answer it. `(c + d x)^2/(a + i a tan(e + f x))^3` is answered in 33 s,
@@ -43771,6 +43834,10 @@ private static bool IsAFunctionOfTheTangentAlone(Entity expr, Entity.Variable u)
4377143834 var complemented = WithTheComplementInEvenPowers(firstPass[u], u, uSub);
4377243835 if (complemented == firstPass[u])
4377343836 continue; // nothing the first pass did not see
43837+ // Nothing after the simplification here reads the candidate, so an x the quotient
43838+ // varies with, which the simplification cannot take out, refuses it at once.
43839+ if (VariesWith(complemented, x))
43840+ continue;
4377443841 integrandInU = SimplifiedWithoutTheImaginaryUnit(complemented, expr);
4377543842 }
4377643843 else
@@ -43841,7 +43908,36 @@ private static bool IsAFunctionOfTheTangentAlone(Entity expr, Entity.Variable u)
4384143908 && !inTermsOfU.Nodes.Any(node => IsASpecialFunction(node) && node.ContainsNode(x))
4384243909 && VariesWhereASpecialFunctionIsHeld(inTermsOfU, uSub, x))
4384343910 continue;
43844- integrandInU = !inTermsOfU.ContainsNode(x)
43911+ // An x left that the quotient in u and x, the two read as independent, varies
43912+ // with: the simplification, the cancelling and the gathering below keep the
43913+ // value, and none of them can take that x out, so none is tried. Each was a
43914+ // simplification of a rational function with symbols in it to be told so, and
43915+ // one alone can run past any budget: the remainder the division leaves of
43916+ // `t^(11/2)/((a/b + t)^3 (1 + t^2))`, which the tangent makes of Rubi's
43917+ // `tan(c + d x)^(11/2)/(a + b tan(c + d x))^3`, took thirty-one seconds to be
43918+ // simplified under `u = t^(3/2)` and forty-four for the four powers of t before
43919+ // `u = sqrt(t)` answered it. The rewritings after them, which read u = g(x),
43920+ // still see the quotient. Not under a sine or a cosine, whose quotient the pass
43921+ // in the complement reads simplified.
43922+ // And not where the candidate has a symbolic factor free of x and what is left
43923+ // in x may be a constant times a power of it, which the rewriting below reads off
43924+ // the simplified quotient: under `u = k sqrt(1 - a x)/sqrt(1 + a x)` Rubi's
43925+ // `F^u/(1 - a^2 x^2)` over du/dx is `-F^u/(a u)`, and read off the simplified
43926+ // quotient it keeps a `k/k` whose cancelling is the answer's `provided not k = 0`,
43927+ // where the candidate varies at all. Read off the quotient as written, the answer
43928+ // came back without it. Beside a candidate with no such factor the rewriting
43929+ // reads either spelling alike, and the simplification is still not tried.
43930+ // https://github.com/asc-community/AngouriMath/issues/718
43931+ var keepsTheVariable = u is not (Sinf or Cosf) && inTermsOfU.ContainsNode(x) && VariesWith(inTermsOfU, x)
43932+ && !APowerOfACandidateWithASymbolicFactorMayBeLeftIn(inTermsOfU, u, x);
43933+ // Kept, its sums in x alone have their like terms collected, which the inner
43934+ // simplification leaves standing: under `u = t^2`, what Rubi's
43935+ // `1/((d + e x) (a + b (d + e x)^2 + c (d + e x)^4)^3)` leaves in `t = d + e x` is
43936+ // `1/((d + t - d) 2 t (a + b u + c u^2)^3)`, whose `t^2` is the candidate, and read
43937+ // with the `d` in it, it was refused as a power of nothing.
43938+ integrandInU = keepsTheVariable
43939+ ? inTermsOfU.InnerSimplified.Replace(node => node is Sumf or Minusf && node.ContainsNode(x) && !node.ContainsNode(uSub) ? Collected(node) : node)
43940+ : !inTermsOfU.ContainsNode(x)
4384543941 && TreeAnalyzer.TryGetPolyLinear(u, x, out var slope, out var offset) && !slope.ContainsNode(x) && !offset.ContainsNode(x)
4384643942 && IsAFunctionOfTheTangentAlone(inTermsOfU, uSub) && !HoldsTheImaginaryUnit(inTermsOfU)
4384743943 ? Functions.PartialFractions.Bare(inTermsOfU.InnerSimplified)
@@ -43856,7 +43952,7 @@ private static bool IsAFunctionOfTheTangentAlone(Entity expr, Entity.Variable u)
4385643952 // A factor written on both sides of the bar cancelled, where x survived:
4385743953 // the one-level simplification leaves `u/((a w + b)^2 p u)` as it is, and
4385843954 // the candidate was refused for the u it did not cancel.
43859- if (integrandInU.ContainsNode(x))
43955+ if (!keepsTheVariable && integrandInU.ContainsNode(x))
4386043956 {
4386143957 var (top, bottom) = Functions.SingleQuotient.Of(Functions.SingleQuotient.Combine(integrandInU));
4386243958 var cancelled = CancelCommonFactors(top, bottom);
@@ -43885,7 +43981,7 @@ private static bool IsAFunctionOfTheTangentAlone(Entity expr, Entity.Variable u)
4388543981 // from: done for every candidate that left an x, it gathered the exponentials of
4388643982 // `1/((c + d x)^3 (a + a tanh(e + f x)))` and simplified them for every one, and
4388743983 // a decline in a third of a second became a timeout.
43888- if (integrandInU.ContainsNode(x) && IsASpecialFunction(u))
43984+ if (!keepsTheVariable && integrandInU.ContainsNode(x) && IsASpecialFunction(u))
4388943985 {
4389043986 var (above, below) = Functions.SingleQuotient.Of(Functions.SingleQuotient.Combine(integrandInU));
4389143987 var spread = above;
@@ -43916,7 +44012,14 @@ private static bool IsAFunctionOfTheTangentAlone(Entity expr, Entity.Variable u)
4391644012 // linears on either side of a nested division.
4391744013 var (aboveTheBar, belowTheBar) = Functions.SingleQuotient.Of(Functions.SingleQuotient.Combine(integrandInU));
4391844014 var inTheCandidate = WithPolynomialsInTheCandidate(aboveTheBar, u, uSub, x) / WithPolynomialsInTheCandidate(belowTheBar, u, uSub, x);
43919- if (inTheCandidate.ContainsNode(x) == false || inTheCandidate != aboveTheBar / belowTheBar)
44015+ // And not simplified where what is left still varies with x: `t` below the
44016+ // bar beside `u = 1 - t^2` is no polynomial in it, and the simplification of
44017+ // `u^(9/2)/(2 t (c u + d (2 - u))^2 (2 - u))`, which the half-angle tangent
44018+ // leaves of Rubi's `1/((a + a sec(e + f x))^(5/2) (c + d sec(e + f x))^2)`,
44019+ // did not return in five minutes.
44020+ if (inTheCandidate.ContainsNode(x) && VariesWith(inTheCandidate, x) && !APowerOfACandidateWithASymbolicFactorMayBeLeftIn(inTheCandidate, u, x))
44021+ integrandInU = inTheCandidate.InnerSimplified;
44022+ else if (inTheCandidate.ContainsNode(x) == false || inTheCandidate != aboveTheBar / belowTheBar)
4392044023 {
4392144024 integrandInU = SimplifiedWithoutTheImaginaryUnit(inTheCandidate, expr);
4392244025 }
0 commit comments