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);
            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));
        }
        /// <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());
        }