예제 #1
0
 protected override XElement VisitTrigonometry(MethodCallExpression term, TrigonometryFunction function)
 {
     return(new XElement(
                "apply",
                new XElement(((MathMLTrigonometryFunction)function).ToString()),
                Visit(term.Arguments[0])));
 }
예제 #2
0
        public static bool TryParse(MethodInfo method, out TrigonometryFunction function)
        {
            string name = method.Name;

            if (method.DeclaringType == typeof(System.Math))
            {
                // We map System.Math.Sin(double) to Trig for better usability
                switch (name)
                {
                case "Sin":
                    function = TrigonometryFunction.Sine;
                    return(true);

                case "Cos":
                    function = TrigonometryFunction.Cosine;
                    return(true);

                case "Tan":
                    function = TrigonometryFunction.Tangent;
                    return(true);

                case "Sinh":
                    function = TrigonometryFunction.HyperbolicSine;
                    return(true);

                case "Cosh":
                    function = TrigonometryFunction.HyperbolicCosine;
                    return(true);

                case "Tanh":
                    function = TrigonometryFunction.HyperbolicTangent;
                    return(true);

                case "Asin":
                    function = TrigonometryFunction.InverseSine;
                    return(true);

                case "Acos":
                    function = TrigonometryFunction.InverseCosine;
                    return(true);

                case "Atan":
                    function = TrigonometryFunction.InverseTangent;
                    return(true);

                default:
                    function = (TrigonometryFunction)0;
                    return(false);
                }
            }

            if (!Enum.IsDefined(typeof(TrigonometryFunction), name))
            {
                function = (TrigonometryFunction)0;
                return(false);
            }

            function = (TrigonometryFunction)Enum.Parse(typeof(TrigonometryFunction), name);
            return(true);
        }
예제 #3
0
        protected virtual Expression VisitTrigonometry(MethodCallExpression term, TrigonometryFunction function)
        {
            ReadOnlyCollection <Expression> newArguments = VisitExpressionList(term.Arguments);

            if (newArguments != term.Arguments)
            {
                if (newArguments.Count != 1)
                {
                    throw new InvalidOperationException("Single Argument Expected.");
                }

                return(Trigonometry.Apply(function, newArguments[0]));
            }

            return(term);
        }
        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()));
            }
        }
 protected abstract T VisitTrigonometry(MethodCallExpression term, TrigonometryFunction function);
 public static Expression Apply(TrigonometryFunction function, Expression argument)
 {
     return ExpressionBuilder.CallDouble(_trigType, function.ToString(), argument);
 }
        public static bool TryParse(MethodInfo method, out TrigonometryFunction function)
        {
            string name = method.Name;

            if(method.DeclaringType == typeof(System.Math))
            {
                // We map System.Math.Sin(double) to Trig for better usability
                switch(name)
                {
                    case "Sin":
                        function = TrigonometryFunction.Sine;
                        return true;
                    case "Cos":
                        function = TrigonometryFunction.Cosine;
                        return true;
                    case "Tan":
                        function = TrigonometryFunction.Tangent;
                        return true;
                    case "Sinh":
                        function = TrigonometryFunction.HyperbolicSine;
                        return true;
                    case "Cosh":
                        function = TrigonometryFunction.HyperbolicCosine;
                        return true;
                    case "Tanh":
                        function = TrigonometryFunction.HyperbolicTangent;
                        return true;
                    case "Asin":
                        function = TrigonometryFunction.InverseSine;
                        return true;
                    case "Acos":
                        function = TrigonometryFunction.InverseCosine;
                        return true;
                    case "Atan":
                        function = TrigonometryFunction.InverseTangent;
                        return true;
                    default:
                        function = (TrigonometryFunction)0;
                        return false;
                }
            }

            if(!Enum.IsDefined(typeof(TrigonometryFunction), name))
            {
                function = (TrigonometryFunction)0;
                return false;
            }

            function = (TrigonometryFunction)Enum.Parse(typeof(TrigonometryFunction), name);
            return true;
        }
        protected virtual Expression VisitTrigonometry(MethodCallExpression term, TrigonometryFunction function)
        {
            ReadOnlyCollection<Expression> newArguments = VisitExpressionList(term.Arguments);
            if(newArguments != term.Arguments)
            {
                if(newArguments.Count != 1)
                {
                    throw new InvalidOperationException("Single Argument Expected.");
                }

                return Trigonometry.Apply(function, newArguments[0]);
            }

            return term;
        }
예제 #9
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()));
            }
        }
예제 #10
0
 public static Expression Apply(TrigonometryFunction function, Expression argument)
 {
     return(ExpressionBuilder.CallDouble(_trigType, function.ToString(), argument));
 }
 protected override T VisitTrigonometry(MethodCallExpression term, TrigonometryFunction function)
 {
     return(VisitMethodCall(term));
 }