internal static Set?SolveLinear(Entity expr, Entity.Variable x) { var replacement = Variable.CreateTemp(expr.Vars); Func <Entity, Entity> preparator = e => e switch { Powf(var @base, var arg) when TreeAnalyzer.TryGetPolyLinear(arg, x, out var a, out var b) => MathS.Pow(@base, b) * MathS.Pow(MathS.Pow(MathS.e, x), MathS.Ln(@base) * a), _ => e, }; Func <Entity, Entity> replacer = e => e switch { Powf(var @base, var arg) when @base == MathS.e && arg == x => replacement, _ => e, }; expr = expr.Replace(preparator); expr = expr.Replace(replacer); if (expr.ContainsNode(x)) { return(null); // cannot be solved, not a pure exponential } expr = expr.InnerSimplified; if (AnalyticalEquationSolver.Solve(expr, replacement) is FiniteSet els && els.Any()) { return((Set)els.Select(sol => MathS.Pow(MathS.e, x).Invert(sol, x).ToSet()).Unite().InnerSimplified); }
public void TestComplex() { var expr = MathS.FromString("ln(x) + sqrt(x) + tan(x) + sec(x) + cosec(x) + cotan(x)"); var expected = MathS.Ln(x) + MathS.Sqrt(x) + MathS.Tan(x) + MathS.Sec(x) + MathS.Cosec(x) + MathS.Cotan(x); Assert.IsTrue(expr == expected); }
public DerivationTest() { IterCount = 10000; tests = new List <Func <object> > { () => x.Derive(x), () => (MathS.Cos(x) * MathS.Sin(x)).Derive(x), () => (MathS.Sqr(MathS.Sin(x + 2 * y)) + MathS.Sqr(MathS.Cos(x + 2 * y))).Derive(x), () => (x * MathS.Cos(x) / MathS.Sin(MathS.Sqrt(x / MathS.Ln(x))) * x * MathS.Cos(x) / MathS.Sin(MathS.Sqrt(x / MathS.Ln(x))) * x * MathS.Cos(x) / MathS.Sin(MathS.Sqrt(x / MathS.Ln(x))) * x * MathS.Cos(x) / MathS.Sin(MathS.Sqrt(x / MathS.Ln(x)))).Derive(x) }; }
public SubsTest() { IterCount = 10000; tests = new List <Func <object> > { () => (x * MathS.Sin(x)).Substitute(x, 3).Eval(), () => (MathS.Cos(x) * MathS.Sin(x)).Substitute(x, 3).Eval(), () => (MathS.Sqr(MathS.Sin(x + 2 * x)) + MathS.Sqr(MathS.Cos(x + 2 * x))).Substitute(x, 3).Eval(), () => (x * MathS.Cos(x) / MathS.Sin(MathS.Sqrt(x / MathS.Ln(x))) * x * MathS.Cos(x) / MathS.Sin(MathS.Sqrt(x / MathS.Ln(x))) * x * MathS.Cos(x) / MathS.Sin(MathS.Sqrt(x / MathS.Ln(x))) * x * MathS.Cos(x) / MathS.Sin(MathS.Sqrt(x / MathS.Ln(x)))).Substitute(x, 3).Eval() }; }
public SimplificationTest() { IterCount = 1500; tests = new List <Func <object> > { () => (x * MathS.Sin(x)).Simplify(), () => (MathS.Cos(x) * MathS.Sin(x)).Simplify(), () => (MathS.Sqr(MathS.Sin(x + 2 * y)) + MathS.Sqr(MathS.Cos(x + 2 * y))).Simplify(), () => (x * MathS.Cos(x) / MathS.Sin(MathS.Sqrt(x / MathS.Ln(x))) * x * MathS.Cos(x) / MathS.Sin(MathS.Sqrt(x / MathS.Ln(x))) * x * MathS.Cos(x) / MathS.Sin(MathS.Sqrt(x / MathS.Ln(x))) * x * MathS.Cos(x) / MathS.Sin(MathS.Sqrt(x / MathS.Ln(x)))).Simplify() }; }
[Fact] public void Test31() => TestLimit("ln(ln((e^2*x + t) / (x + 1)))", Real.PositiveInfinity, ApproachFrom.Left, MathS.Ln(2));
[Fact] public void Test25() => TestLimit("ln((x - 1) / (2x + 1))", Real.PositiveInfinity, ApproachFrom.Right, MathS.Ln(0.5));
[TestMethod] public void Ln() => Test(@"\ln\left(10\right)", MathS.Ln(10));
public void Test6() => Assert.IsTrue(Measure(() => (x * MathS.Pow(MathS.e, x) * MathS.Ln(x) - MathS.Sqrt(x / (x * x - 1))).Derive(x).Substitute(x, 3).Eval()) < 50);
public void Test5() => Assert.IsTrue(Measure(() => (x * MathS.Pow(MathS.e, x) * MathS.Ln(x) - MathS.Sqrt(x / (x * x - 1))).Derive(x)) < 30);
[Fact] public void Ln() => Test(@"\ln\left(10\right)", MathS.Ln(10));
TreeAnalyzer.TryGetPolyLinear(arg, x, out var a, out _) => MathS.Ln(MathS.Sin(arg)) / a,