@@ -11418,6 +11418,97 @@ static bool IsEvenIn(Entity polynomial, Entity.Variable even, Entity.Variable ot
1141811418 return !inPlaceholder.ContainsNode(x) && TreeAnalyzer.TryGetPolynomial(inPlaceholder, placeholder, out _);
1141911419 }
1142011420
11421+ /// <summary>
11422+ /// A function whose argument is a quotient of two linears, <c>(a + b x)/(c + d x)</c>, with
11423+ /// that argument written over the denominator: <c>b/d + (a d - b c)/(d (c + d x))</c>, a
11424+ /// constant plus a multiple of the reciprocal of a linear.
11425+ /// </summary>
11426+ /// <remarks>
11427+ /// <para>
11428+ /// Rubi's <c>sin((a + b x)/(c + d x))</c> and its powers were declined, and the hyperbolic
11429+ /// sine and cosine of the same, written in exponentials, likewise, where
11430+ /// <c>sin(a + k/(c + d x))</c> is answered in sines and cosine integrals and
11431+ /// <c>e^(a + k/(c + d x))</c> in exponential integrals: those rules read a reciprocal of a
11432+ /// linear, and a quotient of two linears is one plus a constant. Exact: polynomial division,
11433+ /// for <c>d</c> and <c>a d - b c</c> not zero, as everywhere in the integrator.
11434+ /// </para>
11435+ /// <para>
11436+ /// The arguments of the sine, cosine, tangent, cotangent, secant and cosecant and the
11437+ /// exponents of the exponential, each written so; the same question in another spelling.
11438+ /// https://github.com/asc-community/AngouriMath/issues/718
11439+ /// </para>
11440+ /// </remarks>
11441+ internal static Entity? SolveByWritingAQuotientOfLinearsOverItsDenominator(Entity expr, Entity.Variable x, bool integrateByParts)
11442+ {
11443+ var names = new Dictionary<Variable, Entity>();
11444+ Entity? Divided(Entity argument)
11445+ {
11446+ // Written as a quotient, or a constant times one: the sum this writes is neither,
11447+ // so the same question asked again does not divide it a second time.
11448+ Entity factor = Number.Integer.One;
11449+ var quotient = argument;
11450+ // The product's two children as written: read through, `-(a + b x)/(c + d x)` as a
11451+ // constant times a quotient is a quotient taken apart into its factors.
11452+ if (argument is Mulf(var left, var right))
11453+ (factor, quotient) = left.ContainsNode(x) ? (right, left) : (left, right);
11454+ if (factor.ContainsNode(x))
11455+ return null;
11456+ if (quotient is not Divf(var above, var below))
11457+ return null;
11458+ if (!below.ContainsNode(x) || !above.ContainsNode(x)
11459+ || !TreeAnalyzer.TryGetPolyLinear(above, x, out var b, out var a) || b.ContainsNode(x) || a.ContainsNode(x)
11460+ || !TreeAnalyzer.TryGetPolyLinear(below, x, out var d, out var c) || d.ContainsNode(x) || c.ContainsNode(x))
11461+ return null;
11462+ var remainder = (a * d - b * c).InnerSimplified;
11463+ if (remainder.Evaled is Number.Complex { IsZero: true } || d.Evaled is Number.Complex { IsZero: true })
11464+ return null;
11465+ // The constant and the multiple named, each a symbol of its own while the question
11466+ // is asked: `sin(b/d + ((a d - b c)/d)/(c + d x))` was declined where
11467+ // `sin(p + k/(c + d x))` is answered, the rules reading a symbol where they meet a
11468+ // quotient of symbols.
11469+ Entity Named(Entity value)
11470+ {
11471+ value = value.InnerSimplified;
11472+ if (value is Variable || value is Number)
11473+ return value;
11474+ foreach (var pair in names)
11475+ if (pair.Value == value)
11476+ return pair.Key;
11477+ var name = Variable.CreateUnique(expr + names.Keys.Aggregate((Entity)Number.Integer.Zero, (sum, v) => sum + v), "k_quotient");
11478+ names[name] = value;
11479+ return name;
11480+ }
11481+ // A constant in front stays in front, so that `e^Q` and `e^(-Q)` keep one argument
11482+ // and their product is 1.
11483+ var divided = Named(b / d) + Named(remainder / d) / below;
11484+ return factor == Number.Integer.One ? divided : factor * divided;
11485+ }
11486+ var changed = false;
11487+ var rewritten = expr.Replace(node =>
11488+ {
11489+ Entity? divided;
11490+ switch (node)
11491+ {
11492+ case Sinf(var y) when (divided = Divided(y)) is not null: changed = true; return MathS.Sin(divided);
11493+ case Cosf(var y) when (divided = Divided(y)) is not null: changed = true; return MathS.Cos(divided);
11494+ case Tanf(var y) when (divided = Divided(y)) is not null: changed = true; return MathS.Tan(divided);
11495+ case Cotanf(var y) when (divided = Divided(y)) is not null: changed = true; return MathS.Cotan(divided);
11496+ case Secantf(var y) when (divided = Divided(y)) is not null: changed = true; return MathS.Sec(divided);
11497+ case Cosecantf(var y) when (divided = Divided(y)) is not null: changed = true; return MathS.Cosec(divided);
11498+ case Powf(var @base, var exponent) when @base == MathS.e && (divided = Divided(exponent)) is not null:
11499+ changed = true;
11500+ return MathS.Pow(MathS.e, divided);
11501+ default:
11502+ return node;
11503+ }
11504+ });
11505+ if (!changed || Integration.ComputeAsTheSameQuestion(rewritten, x, integrateByParts) is not { } answer)
11506+ return null;
11507+ foreach (var pair in names)
11508+ answer = answer.Substitute(pair.Key, pair.Value);
11509+ return answer;
11510+ }
11511+
1142111512 /// <summary>
1142211513 /// Trigonometric functions of several arguments that are whole or rational multiples of one
1142311514 /// linear, <c>p + q x</c>, written in <c>u = p + q x</c>: <c>csc(a + b x) csc(2a + 2b x)^2</c>
0 commit comments