static void simplify_PostProcess(ObservableCollection <IBooleanUnit> condition)
        {
            //remove same item in little units
            //i.e. AABC+BCBD=ABC+BCD
            IList <IBooleanUnit> temp     = new List <IBooleanUnit>();
            IList <int>          toRemove = new List <int>();
            int i = 0;

            while (i < condition.Count)
            {
                if (condition[i] is BooleanVeriable)
                {
                    if (temp.Contains(condition[i]))
                    {
                        toRemove.Add(i);
                    }
                    else
                    {
                        temp.Add(condition[i]);
                    }
                }
                else if (condition[i] == LogicalOperator.Or)
                {
                    temp.Clear();
                }
                i++;
            }
            if (toRemove.Count > 0)
            {
                System.Console.WriteLine("去除最小项中的重复项");
                Log("Del redundent veriables in term");
                int ii = 0;
                foreach (var removeI in toRemove)
                {
                    condition.RemoveAt(removeI - ii);
                    if (condition[removeI - ii] == LogicalOperator.And)
                    {
                        condition.RemoveAt(removeI - ii);
                    }
                    else if (condition[removeI - ii - 1] == LogicalOperator.And)
                    {
                        condition.RemoveAt(removeI - ii - 1);
                    }
                    else
                    {
                        System.Diagnostics.Debug.Assert(false, "we should not come here!");
                    }
                    ii += 2;
                }
                BooleanExpressionToStringConverter cv = new BooleanExpressionToStringConverter();
                System.Console.WriteLine(cv.Convert(condition, null, null, null));
                Log(cv.Convert(condition, null, null, null).ToString());
            }
        }
        //http://www.allaboutcircuits.com/vol_4/chpt_7/5.html
        //http://webster.cs.ucr.edu/AoA/Windows/HTML/DigitalDesigna3.html
        //http://en.wikipedia.org/wiki/Boolean_algebra
        static bool simplify(ObservableCollection <IBooleanUnit> condition)
        {
            if (condition == null || condition.Count == 0)
            {
                return(true);
            }
            BooleanExpressionToStringConverter cv = new BooleanExpressionToStringConverter();

            System.Console.WriteLine("表达式:");
            Log("Expression:");
            System.Console.WriteLine(cv.Convert(condition, null, null, null));
            Log(cv.Convert(condition, null, null, null).ToString());
            //remove meaningless parenthesis
            //(ABC)(!A)=ABC!A
            int  leftParenthesisIndex_toRemove   = -1;
            int  rightParennthesisIndex_toRemove = -1;
            bool toRemoveAgain = true;

            while (toRemoveAgain)
            {
                toRemoveAgain = false;
                for (int i = 0; i < condition.Count; i++)
                {
                    if (condition[i] == Parenthesis.LeftParenthesis)
                    {
                        leftParenthesisIndex_toRemove = i;
                    }
                    else if (condition[i] == LogicalOperator.Or)
                    {
                        leftParenthesisIndex_toRemove = -1;
                    }
                    else if (condition[i] == Parenthesis.RightParenthesis && leftParenthesisIndex_toRemove != -1)
                    {
                        //remove
                        rightParennthesisIndex_toRemove = i;
                        condition.RemoveAt(leftParenthesisIndex_toRemove);
                        condition.RemoveAt(rightParennthesisIndex_toRemove - 1);
                        System.Console.WriteLine("去除无意义的括号:");
                        Log("Del meaningless parenthesises");
                        System.Console.WriteLine(cv.Convert(condition, null, null, null));
                        Log(cv.Convert(condition, null, null, null).ToString());
                        toRemoveAgain = true;
                        break;
                    }
                }
            }

            //end remove meanlingless parenthesis

            //find a pair of inner parenthesis
            int lastLeftParenthesisIndex  = -1;
            int lastRightParenthesisIndex = -1;

            for (int i = 0; i < condition.Count; i++)
            {
                if (condition[i] == Parenthesis.LeftParenthesis)
                {
                    lastLeftParenthesisIndex = i;
                }
                if (condition[i] == Parenthesis.RightParenthesis)
                {
                    lastRightParenthesisIndex = i;
                    if (lastLeftParenthesisIndex == -1)
                    {
                        MessageBox.Show("左右括号不匹配");
                        return(false);
                    }
                    break;
                }
            }
            if (lastLeftParenthesisIndex != -1 && lastRightParenthesisIndex == -1)
            {
                MessageBox.Show("左右括号不匹配");
                return(false);
            }
            //sucess
            if (lastLeftParenthesisIndex == -1 && lastRightParenthesisIndex == -1)
            {
                if (condition[condition.Count - 1] is LogicalOperator)
                {
                    MessageBox.Show("最后一项为逻辑运算符,请确保输入正确");
                    return(false);
                }
                return(true);
            }

            //remove the parentheris
            ///left
            if (lastLeftParenthesisIndex > 0)
            {
                IBooleanUnit lastLeftOutputUnit = condition[lastLeftParenthesisIndex - 1];
                if (lastLeftOutputUnit == LogicalOperator.Neg)
                {
                    NegParenthesis(condition, ref lastLeftParenthesisIndex, ref lastRightParenthesisIndex);
                    System.Console.WriteLine("!左乘括弧");
                    Log("Evaluate !(abc..) expression");
                    System.Console.WriteLine(cv.Convert(condition, null, null, null));
                    Log(cv.Convert(condition, null, null, null).ToString());
                }
                else if (lastLeftOutputUnit == LogicalOperator.And)
                {
                    AndParethesis_Left(condition, ref lastLeftParenthesisIndex, ref lastRightParenthesisIndex);
                    System.Console.WriteLine("左乘括弧");
                    Log("Evaluate A(B+C...) expression");
                    System.Console.WriteLine(cv.Convert(condition, null, null, null));
                    Log(cv.Convert(condition, null, null, null).ToString());
                }
            }


            ///right
            if (lastRightParenthesisIndex < condition.Count - 1)
            {
                IBooleanUnit nextRightOutputUnit = condition[lastRightParenthesisIndex + 1];
                if (nextRightOutputUnit == LogicalOperator.And)
                {
                    if (!AndParethesis_Right(condition, ref lastLeftParenthesisIndex, ref lastRightParenthesisIndex))
                    {
                        return(false);
                    }
                    else
                    {
                        System.Console.WriteLine("右乘括弧");
                        Log("Evaluate (B+C...)A expression");
                        System.Console.WriteLine(cv.Convert(condition, null, null, null));
                        Log(cv.Convert(condition, null, null, null).ToString());
                    }
                }
            }

            //remove
            bool toRemove = true;

            if ((lastLeftParenthesisIndex > 0 && condition[lastLeftParenthesisIndex - 1] == LogicalOperator.And) ||
                (lastLeftParenthesisIndex > 0 && condition[lastLeftParenthesisIndex - 1] == LogicalOperator.Neg))
            {
                toRemove = false;
            }
            if (lastRightParenthesisIndex < condition.Count - 1 && condition[lastRightParenthesisIndex - 1] == LogicalOperator.And)
            {
                toRemove = false;
            }
            if (toRemove)
            {
                System.Console.WriteLine("删除左右括弧");
                Log("DEL left and right parenthesises");
                condition.RemoveAt(lastLeftParenthesisIndex); lastRightParenthesisIndex--;
                condition.RemoveAt(lastRightParenthesisIndex);
            }

            //re
            if (simplify(condition))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }