public static Entity Simplify(List <Entity> args) { MathFunctions.AssertArgs(args.Count, 2); var r1 = args[0].InnerSimplify(); var r2 = args[1].InnerSimplify(); if (r1.entType == Entity.EntType.NUMBER && r2.entType == Entity.EntType.NUMBER) { // TODO: Consider cases like sqrt(12) which could be simplified to 2 sqrt(3) var(n1, n2) = ((r1 as NumberEntity).Value, (r2 as NumberEntity).Value); return(InnerSimplifyAdditionalFunctional.KeepIfBad(Number.Pow(n1, n2), MathS.Pow(r1, r2), n1, n2)); } else if (r1 == 0 || r1 == 1) { return(r1); } else if (r2 == 1) { return(r1); } else if (r2 == 0) { return(1); } else { return(r1.Pow(r2)); } }
public static Entity Simplify(List <Entity> args) { MathFunctions.AssertArgs(args.Count, 2); var r1 = args[0].InnerSimplify(); var r2 = args[1].InnerSimplify(); args = new List <Entity> { r1, r2 }; if (MathFunctions.IsOneNumber(args, 1)) { return(MathFunctions.GetAnotherEntity(args, 1)); } else if (MathFunctions.IsOneNumber(args, 0)) { return(0); } else if (r1.entType == Entity.EntType.NUMBER && r2.entType == Entity.EntType.NUMBER) { var(n1, n2) = ((r1 as NumberEntity).Value, (r2 as NumberEntity).Value); return(InnerSimplifyAdditionalFunctional.KeepIfBad(n1 * n2, r1 * r2, n1, n2)); } else { return(r1 * r2); } }
public static Entity Simplify(List <Entity> args) { MathFunctions.AssertArgs(args.Count, 1); var r = args[0].InnerSimplify(); ComplexNumber evaled = null; if (MathS.CanBeEvaluated(r)) { evaled = r.Eval(); } if (!(evaled is null)) { var n = evaled; if (InnerSimplifyAdditionalFunctional.KeepIfBad(Number.Sin(n), out var res, true, n)) { return(res); }
public static Entity Simplify(List <Entity> args) { MathFunctions.AssertArgs(args.Count, 2); var r1 = args[0].InnerSimplify(); var r2 = args[1].InnerSimplify(); if (r1.entType == Entity.EntType.NUMBER && r2.entType == Entity.EntType.NUMBER) { var(n1, n2) = ((r1 as NumberEntity).Value, (r2 as NumberEntity).Value); return(InnerSimplifyAdditionalFunctional.KeepIfBad(n1 / n2, r1 / r2, n1, n2)); } else if (r1 == 0) { return(0); } else if (r2 == 1) { return(r1); } else { return(r1 / r2); } }