Exemple #1
0
 /// <inheritdoc/>
 public override Expression Reduce()
 {
     Contract.Ensures(Contract.Result <Expression>() != null);
     // TODO: use some square root utility method that does not take the square root of a square
     return(ReductionExpressionGenerator.Generate("SquareRoot", InnerExpression)
            ?? new SquareRootExpression(InnerExpression, ReductionExpressionGenerator));
 }
        /// <inheritdoc/>
        public override Expression Reduce()
        {
            Contract.Ensures(Contract.Result <Expression>() != null);
            var method = typeof(decimal) == Type
                ? MathFloorDecimalMethod
                : MathFloorDoubleMethod;

            return(ReductionExpressionGenerator.BuildConversionCall(method, UnaryParameter, Type));
        }
Exemple #3
0
 /// <inheritdoc/>
 public override Expression Reduce()
 {
     Contract.Ensures(Contract.Result <Expression>() != null);
     return(ReductionExpressionGenerator.BuildConversionCall(
                MathLogMethod,
                Type,
                LeftParameter,
                RightParameter));
 }
 private Expression GenerateExpression(Expression left, Expression right)
 {
     Contract.Requires(left != null);
     Contract.Requires(right != null);
     Contract.Requires(left.IsMemoryLocationOrConstant());
     Contract.Requires(right.IsMemoryLocationOrConstant());
     Contract.Ensures(Contract.Result <Expression>() != null);
     return(Condition(
                ReductionExpressionGenerator.GenerateOrThrow("GREATEREQUAL", left, right),
                left,
                right
                ));
 }
        /// <inheritdoc/>
        public override Expression Reduce()
        {
            Contract.Ensures(Contract.Result <Expression>() != null);

            // TODO: should there be an optimization option?
            var squareExpression = UnaryParameter as SquareExpression;

            if (squareExpression != null)
            {
                return(squareExpression.UnaryParameter);
            }

            return(ReductionExpressionGenerator.BuildConversionCall(MathSqrtMethod, UnaryParameter, Type));
        }
        /// <inheritdoc/>
        public override Expression Reduce()
        {
            Contract.Ensures(Contract.Result <Expression>() != null);
            var gen       = ReductionExpressionGenerator;
            var halfCount = Components.Length / 2;
            var deltas    = new Expression[halfCount];

            for (int i = 0; i < halfCount; i++)
            {
                Contract.Assume(halfCount + i < Components.Length);
                deltas[i] = ReductionExpressionGenerator.GenerateOrThrow(
                    "SUBTRACT",
                    Components[i],
                    Components[halfCount + i]);
            }
            return(gen.Generate("SQUAREDMAGNITUDE", deltas)
                   ?? new SquaredMagnitudeExpression(deltas, gen));
        }
Exemple #7
0
        /// <inheritdoc/>
        public override Expression Reduce()
        {
            Contract.Ensures(Contract.Result <Expression>() != null);
            var method = typeof(Math).GetPublicStaticInvokableMethod("Abs", Type);

            if (null != method)
            {
                return(ReductionExpressionGenerator.BuildConversionCall(method, UnaryParameter, Type));
            }

            if (UnaryParameter.IsMemoryLocationOrConstant())
            {
                return(GenerateExpression(UnaryParameter));
            }

            return(new BlockExpressionBuilder()
                   .AddUsingMemoryLocationOrConstant(
                       local => new[] { GenerateExpression(local) }, UnaryParameter)
                   .GetExpression());
        }
        /// <inheritdoc/>
        public override Expression Reduce()
        {
            Contract.Ensures(Contract.Result <Expression>() != null);
            var squareRootExpression = UnaryParameter as SquareRootExpression;

            if (squareRootExpression != null)
            {
                return(squareRootExpression.UnaryParameter);
            }

            if (UnaryParameter.IsMemoryLocationOrConstant())
            {
                return(ReductionExpressionGenerator.GenerateOrThrow("MULTIPLY", UnaryParameter, UnaryParameter));
            }

            return(new BlockExpressionBuilder().AddUsingMemoryLocationOrConstant(
                       local => new[] { ReductionExpressionGenerator.GenerateOrThrow("MULTIPLY", local, local) },
                       UnaryParameter
                       ).GetExpression());
        }
Exemple #9
0
 /// <inheritdoc/>
 public override Expression Reduce()
 {
     Contract.Ensures(Contract.Result <Expression>() != null);
     return(ReductionExpressionGenerator.BuildConversionCall(MathSinMethod, UnaryParameter, Type));
 }