Beispiel #1
0
        public override Expr Substitute(VariableExpr target, Expr expression)
        {
            var argument = target.Equals(Argument) ? expression : Argument.Substitute(target, expression);

            if (argument.Equals(Argument))
            {
                return(this);
            }

            return(Unary(Op, argument));
        }
Beispiel #2
0
 public override Expr Substitute(VariableExpr target, Expr expression)
 {
     return(new ArrayExpr(Elements.Select((item) => item.Substitute(target, expression)).ToArray()));
 }
Beispiel #3
0
 /// <summary>
 /// Get the partial derivative of the expression with respect to a variable.
 /// </summary>
 /// <param name="variable">The variable.</param>
 /// </example>
 public override Expr Partial(VariableExpr variable)
 {
     return(new ArrayExpr(Elements.Select((item) => item.Partial(variable)).ToArray()));
 }
Beispiel #4
0
 public override Expr Partial(VariableExpr variable)
 {
     return(0);
 }
Beispiel #5
0
 public override Expr Substitute(VariableExpr target, Expr expression)
 {
     return(this);
 }
Beispiel #6
0
        public override Expr Partial(VariableExpr variable)
        {
            Expr x = Argument, xp = Argument.Partial(variable);

            switch (Op)
            {
            case UnaryOp.Identity: return(xp);

            case UnaryOp.Negate: return(-xp);

            case UnaryOp.Inverse: return(-xp / (x ^ 2));

            case UnaryOp.Rnd: return(0);

            case UnaryOp.Pi: return(Math.PI * xp);

            case UnaryOp.Abs: return(Sign(x) * xp);

            case UnaryOp.Sign: return(0);

            case UnaryOp.Exp: return(Exp(x) * xp);

            case UnaryOp.Log: return(xp / x);

            case UnaryOp.Log2: return(xp / (Math.Log(2) * x));

            case UnaryOp.Log10: return(xp / (Math.Log(10) * x));

            case UnaryOp.Sqr: return(x * (2 * xp));

            case UnaryOp.Cub: return((x ^ 2) * (3 * xp));

            case UnaryOp.Sqrt: return(xp / (2 * Sqrt(x)));

            case UnaryOp.Cbrt: return(xp / (3 * (x ^ (2.0 / 3))));

            case UnaryOp.Floor: return(0);

            case UnaryOp.Ceiling: return(0);

            case UnaryOp.Round: return(0);

            case UnaryOp.Sin: return(Cos(x) * xp);

            case UnaryOp.Cos: return((-Sin(x)) * xp);

            case UnaryOp.Tan: return(2 * xp / (1 + Cos(2 * x)));

            case UnaryOp.Sinh: return(Cosh(x) * xp);

            case UnaryOp.Cosh: return(Sinh(x) * xp);

            case UnaryOp.Tanh: return(xp / (0.5 * (1 + Cosh(2 * x))));

            case UnaryOp.Asin: return(xp / Sqrt(1 - (x ^ 2)));

            case UnaryOp.Acos: return(-xp / Sqrt(1 - (x ^ 2)));

            case UnaryOp.Atan: return(xp / (1 + (x ^ 2)));

            case UnaryOp.Asinh: return(xp / Sqrt((x ^ 2) + 1));

            case UnaryOp.Acosh: return(xp / Sqrt((x ^ 2) - 1));

            case UnaryOp.Atanh: return(xp / (1 - (x ^ 2)));

            case UnaryOp.Sum: return(Sum(xp));

            case UnaryOp.Transpose: return(Transpose(xp));

            default:
                throw new NotImplementedException($"Operator {Key} does not have slope defined.");
            }
        }