public IExpressionNode Simplify()
        {
            LeftOperand  = LeftOperand.Simplify();
            RightOperand = RightOperand.Simplify();
            if (!LeftOperand.ContainsVariable() && !RightOperand.ContainsVariable())
            {
                return(new Constant(this.Evaluate(null)));
            }
            else if (!LeftOperand.ContainsVariable() && RightOperand.ContainsVariable())
            {
                if (LeftOperand.Evaluate(null) == 0)
                {
                    return(new Constant(0));
                }
            }
            else if (LeftOperand.ContainsVariable() && !RightOperand.ContainsVariable())
            {
                if (RightOperand.Evaluate(null) == 0)
                {
                    throw new DivideByZeroException();
                }

                if (RightOperand.Evaluate(null) == 1)
                {
                    return(LeftOperand.DeepCopy());
                }
            }

            return(this);
        }
Example #2
0
 public IExpressionNode Simplify()
 {
     Parameter = Parameter.Simplify();
     if (!Parameter.ContainsVariable())
     {
         return(new Constant(this.Evaluate(null)));
     }
     return(this);
 }
Example #3
0
        public IExpressionNode Simplify()
        {
            FirstParameter  = FirstParameter.Simplify();
            SecondParameter = SecondParameter.Simplify();
            if (!FirstParameter.ContainsVariable() && !SecondParameter.ContainsVariable())
            {
                return(new Constant(this.Evaluate(null)));
            }

            return(this);
        }