Beispiel #1
0
        public static LogicDerivation ManipulateLogic(String paramString, LogicExpression paramLogicExpression)
        {
            var localLogicDerivation = new LogicDerivation(paramString, paramLogicExpression);

            if (localLogicDerivation.CNFAndDNF)
            {
                return localLogicDerivation;
            }

            CarryOutNonPrimaryOperatorReplacement(localLogicDerivation);
            CarryOutBoolValues(localLogicDerivation);

            if (localLogicDerivation.CNFAndDNF)
            {
                return localLogicDerivation;
            }
            CarryOutAssociativity(localLogicDerivation);
            CarryOutDeMorgans(localLogicDerivation);
            CarryOutAssociativity(localLogicDerivation);
            CarryOutIdempotency(localLogicDerivation);
            CarryOutBoolValues(localLogicDerivation);
            CarryOutAbsorbtion(localLogicDerivation);

            do
            {
                CarryOutDistributivity(localLogicDerivation);
                CarryOutAssociativity(localLogicDerivation);
                CarryOutIdempotency(localLogicDerivation);
                CarryOutBoolValues(localLogicDerivation);
                CarryOutAbsorbtion(localLogicDerivation);
            } while (!localLogicDerivation.CNFAndDNF);
            return localLogicDerivation;
        }
Beispiel #2
0
        private static void CarryOutIdempotency(LogicDerivation paramLogicDerivation)
        {
            LogicExpression localLogicExpression1 = paramLogicDerivation.Next;

            int i = 0;

            int j = 0;
            LogicExpression localLogicExpression2;
            while ((localLogicExpression2 = localLogicExpression1.GetSubExpression(2, j)) != null)
            {
                if (idempotency((LogicBranch) localLogicExpression2))
                {
                    i = 1;
                    continue;
                }
                j++;
            }

            if (i != 0)
            {
                if ((localLogicExpression1 is LogicBranch))
                {
                    LogicExpression[] arrayOfLogicExpression = ((LogicBranch) localLogicExpression1).Branches;

                    if (arrayOfLogicExpression.Length == 1)
                    {
                        localLogicExpression1 = arrayOfLogicExpression[0];
                        localLogicExpression1.SetParent(null, -1);
                    }
                }

                paramLogicDerivation.AddStep(localLogicExpression1, "Idempotency");
            }
        }
Beispiel #3
0
        private static void CarryOutNonPrimaryOperatorReplacement(LogicDerivation paramLogicDerivation)
        {
            LogicExpression localLogicExpression1 = paramLogicDerivation.Next;

            int i = localLogicExpression1.GetDepth();

            for (int k = 2; k <= i; k++)
            {
                int j = 0;
                LogicExpression localLogicExpression2;
                while ((localLogicExpression2 = localLogicExpression1.GetSubExpression(k, j++)) != null)
                {
                    var localLogicBranch = (LogicBranch) localLogicExpression2;

                    switch (localLogicBranch.Operator)
                    {
                        case Operator.Implies:
                            ReplaceImpliesOperator(localLogicBranch);
                            j += 2;
                            paramLogicDerivation.AddStep(localLogicExpression1, "Replaced IMPLIES operator");

                            localLogicExpression1 = paramLogicDerivation.Next;
                            break;
                        case Operator.Biimplies:
                            ReplaceBiimpliesOperator(localLogicBranch);
                            j++;
                            paramLogicDerivation.AddStep(localLogicExpression1, "Replaced BIIMPLIES operator");

                            localLogicExpression1 = paramLogicDerivation.Next;
                            break;
                        case Operator.Xor:
                            ReplaceXorOperator(localLogicBranch);
                            j++;
                            paramLogicDerivation.AddStep(localLogicExpression1, "Replaced XOR operator");

                            localLogicExpression1 = paramLogicDerivation.Next;
                            break;
                        default:
                            j++;
                            break;
                    }
                }
            }
        }
Beispiel #4
0
        private static void CarryOutDistributivity(LogicDerivation paramLogicDerivation)
        {
            LogicExpression localLogicExpression1 = paramLogicDerivation.Next;

            int i = 0;
            LogicExpression localLogicExpression2;
            while ((localLogicExpression2 = localLogicExpression1.GetSubExpression(3, i++)) != null)
            {
                if (!Distributivity((LogicBranch) localLogicExpression2))
                    continue;
                paramLogicDerivation.AddStep(localLogicExpression1, "Distributivity");
                localLogicExpression1 = paramLogicDerivation.Next;
            }
        }
Beispiel #5
0
        private static void CarryOutDeMorgans(LogicDerivation paramLogicDerivation)
        {
            LogicExpression localLogicExpression1 = paramLogicDerivation.Next;

            int i = localLogicExpression1.GetDepth();

            for (int k = i; k >= 2; k--)
            {
                int j = 0;
                LogicExpression localLogicExpression2;
                while ((localLogicExpression2 = localLogicExpression1.GetSubExpression(k, j)) != null)
                {
                    if (DeMorgans((LogicBranch) localLogicExpression2))
                    {
                        paramLogicDerivation.AddStep(localLogicExpression1, "De Morgan's");
                        localLogicExpression1 = paramLogicDerivation.Next;
                        continue;
                    }

                    j++;
                }
            }
        }
Beispiel #6
0
        private static void CarryOutBoolValues(LogicDerivation paramLogicDerivation)
        {
            var logicExpression = paramLogicDerivation.Next;

            int i = logicExpression.GetDepth();

            for (int m = 2; m <= i; m++)
            {
                int k = 0;
                int j = 0;
                LogicExpression localLogicExpression;
                while ((localLogicExpression = logicExpression.GetSubExpression(m, j)) != null)
                {
                    var localLogicBranch1 = (LogicBranch) localLogicExpression;
                    int n = GetBoolResolution(localLogicBranch1);
                    if (n == 31)
                    {
                        LogicExpression[] arrayOfLogicExpression = localLogicBranch1.Branches;
                        int i1 = arrayOfLogicExpression.Length;

                        i1 -= arrayOfLogicExpression.Count(t => (t is LogicValue));

                        if (i1 == 1)
                        {
                            LogicExpression localObject2 = arrayOfLogicExpression.FirstOrDefault(t => (!(t is LogicValue)));

                            LogicBranch localLogicBranch2 = localLogicExpression.Parent;

                            if (localLogicBranch2 == null)
                            {
                                logicExpression = localObject2;
                                localObject2.SetParent(null, -1);
                            }
                            else
                            {
                                localLogicBranch2.SetBranch(localObject2, localLogicExpression.PositionInParent);
                            }
                        }
                        else
                        {
                            var localObject22 = new LogicExpression[i1];

                            int i4 = 0;

                            foreach (LogicExpression t in arrayOfLogicExpression)
                            {
                                if (!(t is LogicValue))
                                {
                                    localObject22[(i4++)] = t;
                                }
                            }
                            localLogicBranch1.Branches = localObject22;

                            j++;
                        }

                        k = 1;
                    }
                    else if ((n == 32) || (n == 33))
                    {
                        bool @bool = n == 32;
                        var localLogicValue = new LogicValue(@bool);

                        var localObject2 = localLogicBranch1.Parent;

                        if (localObject2 == null)
                        {
                            localLogicValue.SetParent(null, -1);
                            paramLogicDerivation.AddStep(localLogicValue, "Resolved bool values");
                            break;
                        }

                        (localObject2).SetBranch(localLogicValue, localLogicBranch1.PositionInParent);

                        k = 1;
                    }
                    else
                    {
                        j++;
                    }
                }

                if (k == 0)
                    continue;
                paramLogicDerivation.AddStep(logicExpression, "Removed redundant bool values");
                logicExpression = paramLogicDerivation.Next;
            }
        }
Beispiel #7
0
        private static void CarryOutAssociativity(LogicDerivation paramLogicDerivation)
        {
            LogicExpression localLogicExpression1 = paramLogicDerivation.Next;

            int i = localLogicExpression1.GetDepth();

            for (int k = 3; k <= i; k++)
            {
                int j = 0;
                LogicExpression localLogicExpression2;
                while ((localLogicExpression2 = localLogicExpression1.GetSubExpression(k, j)) != null)
                {
                    if (associativity((LogicBranch) localLogicExpression2))
                    {
                        paramLogicDerivation.AddStep(localLogicExpression1, "Associativity");
                        localLogicExpression1 = paramLogicDerivation.Next;
                        continue;
                    }

                    j++;
                }
            }

            i = localLogicExpression1.GetDepth();

            if (i == 2)
            {
                var localLogicBranch = (LogicBranch) localLogicExpression1;
                LogicExpression[] arrayOfLogicExpression = localLogicBranch.Branches;

                if (arrayOfLogicExpression.Length == 1)
                {
                    localLogicExpression1 = arrayOfLogicExpression[0];
                    localLogicExpression1.SetParent(null, -1);

                    paramLogicDerivation.AddStep(localLogicExpression1, "Associativity");
                }
            }
        }
Beispiel #8
0
        private static void CarryOutAbsorbtion(LogicDerivation paramLogicDerivation)
        {
            Object localObject = paramLogicDerivation.Next;

            int i = 0;
            LogicExpression localLogicExpression1;
            while ((localLogicExpression1 = ((LogicExpression) localObject).GetSubExpression(3, i)) != null)
            {
                var localLogicBranch1 = (LogicBranch) localLogicExpression1;
                int j = localLogicBranch1.Branches.Length;
                int k = Absorbtion(localLogicBranch1);

                if (k > 0)
                {
                    if (j - k == 1)
                    {
                        LogicBranch localLogicBranch2 = localLogicExpression1.Parent;

                        LogicExpression[] arrayOfLogicExpression = localLogicBranch1.Branches;
                        LogicExpression localLogicExpression2 = arrayOfLogicExpression[0];

                        if (localLogicBranch2 == null)
                        {
                            localObject = localLogicExpression2;
                            ((LogicExpression) localObject).SetParent(null, -1);
                        }
                        else
                        {
                            localLogicBranch2.SetBranch(localLogicExpression2, localLogicBranch1.PositionInParent);
                        }

                        i--;
                    }

                    paramLogicDerivation.AddStep((LogicExpression) localObject, "Absorbtion");
                    localObject = paramLogicDerivation.Next;
                    continue;
                }

                i++;
            }
        }