// tan(a) = -1 / sin(a) ^ 2 public static Entity Derive(List <Entity> args, VariableEntity variable) { MathFunctions.AssertArgs(args.Count, 1); var a = args[0]; return(-1 / a.Sin().Pow(2) * a.Derive(variable)); }
// arccotan(x)' = -1 / (1 + x^2) public static Entity Derive(List <Entity> args, VariableEntity variable) { MathFunctions.AssertArgs(args.Count, 1); var a = args[0]; return(-1 / (1 + MathS.Sqr(a)) * a.Derive(variable)); }
// (a * b)' = a' * b + b' * a public static Entity Derive(List <Entity> args, VariableEntity variable) { MathFunctions.AssertArgs(args.Count, 2); var a = args[0]; var b = args[1]; return(a.Derive(variable) * b + b.Derive(variable) * a); }
// log(a, b) = (ln(a) / ln(b))' = (ln(a)' * ln(b) - ln(a) * ln(b)') / ln(b)^2 = (a' / a * ln(b) - ln(a) * b' / b) / ln(b)^2 public static Entity Derive(List <Entity> args, VariableEntity variable) { MathFunctions.AssertArgs(args.Count, 2); var a = args[0]; var b = args[1]; return((a.Derive(variable) / a * MathS.Ln(b) - MathS.Ln(a) * b.Derive(variable) / b) / (MathS.Ln(b).Pow(2))); }
/// <summary> /// Derivation over a variable (without simplification) /// </summary> /// <param name="x"> /// The variable to derive over /// </param> /// <returns></returns> public Entity Derive(VariableEntity x) { if (IsLeaf) { if (this.entType == Entity.EntType.VARIABLE && this.Name == x.Name) { return(new NumberEntity(1)); } else { return(new NumberEntity(0)); } } else { return(MathFunctions.InvokeDerive(Name, Children, x)); } }
// (a ^ b)' = e ^ (ln(a) * b) * (a' * b / a + ln(a) * b') // (a ^ const)' = const * a ^ (const - 1) // (const ^ b)' = e^b * b' public static Entity Derive(List <Entity> args, VariableEntity variable) { MathFunctions.AssertArgs(args.Count, 2); var a = args[0]; var b = args[1]; if (b.entType == Entity.EntType.NUMBER) { var cons = (b as NumberEntity).Value - 1; var res = b * (a.Pow(cons)) * a.Derive(variable); return(res); } else if (a.entType == Entity.EntType.NUMBER) { return(a.Pow(b) * MathS.Ln(a) * b.Derive(variable)); } else { return(a.Pow(b) * (a.Derive(variable) * b / a + MathS.Ln(a) * b.Derive(variable))); } }
/// <summary> /// See Substitute instead /// </summary> /// <param name="x"></param> /// <param name="value"></param> /// <param name="inPlace"> /// If no need to copy, we do it in place /// </param> /// <returns></returns> public Entity Substitute(VariableEntity x, Entity value, bool inPlace) { Entity res; if (inPlace) { res = this; } else { res = DeepCopy(); } if (res == x) { return(value); } for (int i = 0; i < res.Children.Count; i++) { res.Children[i] = res.Children[i].Substitute(x, value, true); } return(res); }
public Set SolveNt(VariableEntity v, int precision = 30) => SolveNt(v, (-10, -10), (10, 10), (10, 10), precision: precision);
/// <summary> /// Attempt to find analytical roots of a custom equation /// </summary> /// <param name="x"></param> /// <returns> /// Returns Set. Work with it as with a list /// </returns> public Set SolveEquation(VariableEntity x) => EquationSolver.Solve(this, x);
/// <summary> /// Returns a value of a definite integral of a function. Only works for one-variable functions /// </summary> /// <param name="x"> /// Variable to integrate over /// </param> /// <param name="from"> /// The down bound for integrating /// </param> /// <param name="to"> /// The up bound for integrating /// </param> /// <returns></returns> public ComplexNumber DefiniteIntegral(VariableEntity x, (decimal Re, decimal Im) from, (decimal Re, decimal Im) to)
/// <summary> /// Will be soon! /// Solves an inequality numerically /// </summary> /// <param name="inequality"> /// This must only contain one variable, which is var /// </param> /// <param name="var"> /// The only variable /// </param> /// <param name="sign"> /// ">", "<", ">=", "<=" /// </param> /// <returns></returns> public static Set SolveInequalityNumerically(Entity inequality, VariableEntity var, string sign) { throw new NotSupportedException("Will be added soon"); return(NumericalInequalitySolver.Solve(inequality, var, sign)); }
/// <summary> /// Returns an entity in polynomial order if possible /// </summary> /// <param name="expr"> /// To parse from /// </param> /// <param name="variable"> /// Polynomial is a function of a variable /// </param> /// <param name="dst"> /// To return to /// </param> /// <returns> /// true if success /// false otherwise (do not access dst in this case, it's undefined) /// </returns> public static bool TryPolynomial(Entity expr, VariableEntity variable, out Entity dst) => Functions.Utils.TryPolynomial(expr, variable, out dst);
/// <summary> /// Solves one equation over one variable /// </summary> /// <param name="equation"></param> /// <param name="var"></param> /// <returns></returns> public static Set SolveEquation(Entity equation, VariableEntity var) => EquationSolver.Solve(equation, var);
public static Entity InvokeDerive(string typeName, List <Entity> args, VariableEntity x) { return(deriveTable[typeName](args, x)); }
public static Entity Quack(Entity expr, VariableEntity x) => CommonDenominatorSolver.FindCD(expr, x);
/// <summary> /// Substitute a variable with an expression /// </summary> /// <param name="x"> /// A variable to substitute /// </param> /// <param name="value"> /// The value we replace variable with /// </param> /// <returns></returns> public Entity Substitute(VariableEntity x, Entity value) => Substitute(x, value, false);