コード例 #1
0
        protected override Expression VisitTrigonometry(MethodCallExpression methodCall, TrigonometryFunction function)
        {
            Expression argument = methodCall.Arguments[0];

            switch (function)
            {
            case TrigonometryFunction.Sine:
            {
                Expression innerDerivative = Visit(argument);
                return(Arithmeric.Multiply(
                           innerDerivative,
                           Trigonometry.Cosine(argument)));
            }

            case TrigonometryFunction.Cosine:
            {
                Expression innerDerivative = Visit(argument);
                return(Arithmeric.Negate(
                           Arithmeric.Multiply(
                               innerDerivative,
                               Trigonometry.Sine(argument))));
            }

            default:
                throw new NotSupportedException(String.Format("Trigonometric function {0} is not supported.", function.ToString()));
            }
        }
コード例 #2
0
        protected override Expression VisitMultiply(BinaryExpression binaryExpression)
        {
            Expression leftDerivative  = Visit(binaryExpression.Left);
            Expression rightDerivative = Visit(binaryExpression.Right);

            return(Arithmeric.Add(
                       Arithmeric.Multiply(leftDerivative, binaryExpression.Right),
                       Arithmeric.Multiply(rightDerivative, binaryExpression.Left)));
        }
コード例 #3
0
        protected override Expression VisitParameter(ParameterExpression p)
        {
            if (p.Name == _variableName)
            {
                return(Arithmeric.One());
            }

            return(Arithmeric.Zero());
        }
コード例 #4
0
        protected override Expression VisitDivide(BinaryExpression binaryExpression)
        {
            Expression leftDerivative  = Visit(binaryExpression.Left);
            Expression rightDerivative = Visit(binaryExpression.Right);

            return(Arithmeric.Subtract(
                       Arithmeric.Divide(leftDerivative, binaryExpression.Right),
                       Arithmeric.Divide(
                           Arithmeric.Multiply(binaryExpression.Left, rightDerivative),
                           Arithmeric.Multiply(binaryExpression.Right, binaryExpression.Right))));
        }
コード例 #5
0
        public static Expression Negate(Expression term)
        {
            if (Elementary.IsConstantZero(term))
            {
                return(Arithmeric.Zero());
            }

            if (term.NodeType == ExpressionType.Negate)
            {
                UnaryExpression unary = (UnaryExpression)term;
                return(unary.Operand);
            }

            return(Expression.Negate(term));
        }
コード例 #6
0
        protected override Expression VisitPower(BinaryExpression binaryExpression)
        {
            Expression leftDerivative  = Visit(binaryExpression.Left);
            Expression rightDerivative = Visit(binaryExpression.Right);

            return(Arithmeric.Multiply(
                       binaryExpression,
                       Arithmeric.Add(
                           Arithmeric.Multiply(
                               rightDerivative,
                               Exponential.Ln(binaryExpression.Left)),
                           Arithmeric.Divide(
                               Arithmeric.Multiply(binaryExpression.Right, leftDerivative),
                               binaryExpression.Left))));
        }
コード例 #7
0
        public static Expression Divide(Expression a, Expression b)
        {
            if (Elementary.IsConstantZero(a))
            {
                return(Arithmeric.Zero());
            }

            if (Elementary.IsConstantOne(b))
            {
                return(a);
            }

            TypeInference     type        = new TypeInference(a, b);
            List <Expression> expressions = type.CastToMaxNumericList();

            return(Expression.Divide(expressions[0], expressions[1]));
        }
コード例 #8
0
 protected override Expression VisitConstant(ConstantExpression c)
 {
     return(Arithmeric.Zero());
 }