Beispiel #1
0
        // 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));
        }
Beispiel #2
0
        // 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));
        }
Beispiel #3
0
        // (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);
        }
Beispiel #4
0
        // 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)));
        }
Beispiel #5
0
 /// <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));
     }
 }
Beispiel #6
0
        // (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)));
            }
        }
Beispiel #7
0
        /// <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);
        }
Beispiel #8
0
 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)
Beispiel #11
0
 /// <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));
 }
Beispiel #12
0
 /// <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);
Beispiel #13
0
 /// <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);
Beispiel #14
0
 public static Entity InvokeDerive(string typeName, List <Entity> args, VariableEntity x)
 {
     return(deriveTable[typeName](args, x));
 }
Beispiel #15
0
 public static Entity Quack(Entity expr, VariableEntity x)
 => CommonDenominatorSolver.FindCD(expr, x);
Beispiel #16
0
 /// <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);