예제 #1
0
        public override LogicExpression CloneLogic()
        {
            var localLogicBranch = new LogicBranch(Operator, Negated);

            var arrayOfLogicExpression = new LogicExpression[_logicBranches.Length];

            for (int i = 0; i < _logicBranches.Length; i++)
            {
                arrayOfLogicExpression[i] = _logicBranches[i].CloneLogic();
            }
            localLogicBranch.Branches = arrayOfLogicExpression;
            return localLogicBranch;
        }
예제 #2
0
        private static void ReplaceXorOperator(LogicBranch paramLogicBranch)
        {
            LogicExpression[] arrayOfLogicExpression1 = paramLogicBranch.Branches;

            LogicExpression[] arrayOfLogicExpression2 = {
                                                            arrayOfLogicExpression1[0].CloneLogic(),
                                                            arrayOfLogicExpression1[1].CloneLogic()
                                                        };

            arrayOfLogicExpression2[0].Negated = !arrayOfLogicExpression2[0].Negated;

            LogicExpression[] arrayOfLogicExpression3 = {
                                                            arrayOfLogicExpression1[0].CloneLogic(),
                                                            arrayOfLogicExpression1[1].CloneLogic()
                                                        };

            arrayOfLogicExpression3[1].Negated = !arrayOfLogicExpression3[1].Negated;

            var localLogicBranch1 = new LogicBranch(0, false) {Branches = arrayOfLogicExpression2};

            var localLogicBranch2 = new LogicBranch(0, false) {Branches = arrayOfLogicExpression3};

            LogicExpression[] arrayOfLogicExpression4 = {localLogicBranch1, localLogicBranch2};

            paramLogicBranch.Branches = arrayOfLogicExpression4;
            paramLogicBranch.Operator = Operator.Or;
        }
예제 #3
0
        private static void ReplaceImpliesOperator(LogicBranch paramLogicBranch)
        {
            LogicExpression[] arrayOfLogicExpression = paramLogicBranch.Branches;

            arrayOfLogicExpression[0].Negated = !arrayOfLogicExpression[0].Negated;

            paramLogicBranch.Operator = Operator.Or;
        }
예제 #4
0
        private static bool idempotency(LogicBranch paramLogicBranch)
        {
            var i = paramLogicBranch.Operator;

            LogicExpression[] arrayOfLogicExpression = (LogicExpression[]) paramLogicBranch.Branches;

            int j = arrayOfLogicExpression.Length;

            for (int k = 0; k < arrayOfLogicExpression.Length; k++)
            {
                if ((arrayOfLogicExpression[k] == null) || (!(arrayOfLogicExpression[k] is LogicLeaf)))
                    continue;
                var localLogicLeaf1 = (LogicLeaf) arrayOfLogicExpression[k];

                for (int n = k + 1; n < arrayOfLogicExpression.Length; n++)
                {
                    if ((arrayOfLogicExpression[n] == null) || (!(arrayOfLogicExpression[n] is LogicLeaf)))
                        continue;
                    var localLogicLeaf2 = (LogicLeaf) arrayOfLogicExpression[n];

                    if (!localLogicLeaf1.Name.Equals(localLogicLeaf2.Name))
                        continue;
                    if (arrayOfLogicExpression[k].Negated != arrayOfLogicExpression[n].Negated)
                    {
                        switch (i)
                        {
                            case Operator.And:
                                arrayOfLogicExpression[k] = new LogicValue(false);
                                break;
                            case Operator.Or:
                                arrayOfLogicExpression[k] = new LogicValue(true);
                                break;
                            default:
                                Console.Error.WriteLine("Software Error: Unimplemented operator: " + i);
                                break;
                        }
                    }

                    arrayOfLogicExpression[n] = null;
                    j--;
                }
            }

            if (j == arrayOfLogicExpression.Length)
                return false;
            if (j == 1)
            {
                var localObject1 = paramLogicBranch.Parent;

                if (localObject1 != null)
                {
                    (localObject1).SetBranch(arrayOfLogicExpression[0], paramLogicBranch.PositionInParent);
                }
                return true;
            }

            var localObject = new LogicExpression[j];
            j = 0;

            foreach (LogicExpression t in arrayOfLogicExpression.Where(t => t != null))
            {
                localObject[j++] = t;
            }
            paramLogicBranch.Branches = localObject;

            return true;
        }
예제 #5
0
        private static int GetBoolResolution(LogicBranch paramLogicBranch)
        {
            LogicExpression[] arrayOfLogicExpression = paramLogicBranch.Branches;

            int i = 0;
            int j = 0;

            foreach (LogicExpression t in arrayOfLogicExpression)
            {
                if (!(t is LogicValue))
                    continue;
                bool @bool = ((LogicValue) t).EqualsTrue();

                if (@bool)
                    i = 1;
                else
                {
                    j = 1;
                }
                if ((i != 0) && (j != 0))
                {
                    break;
                }
            }
            if ((i == 0) && (j == 0))
            {
                return 30;
            }
            var k1 = paramLogicBranch.Operator;

            if (k1 == Operator.And)
            {
                if (j != 0)
                {
                    return 33;
                }
                return 31;
            }
            if (k1 == Operator.Or)
            {
                if (i != 0)
                {
                    return 32;
                }
                return 31;
            }

            Console.Error.WriteLine("Software Error: Operator other than AND, OR found when looking at bool values");

            return 30;
        }
예제 #6
0
        private static bool Distributivity(LogicBranch paramLogicBranch)
        {
            var i = paramLogicBranch.Operator;

            LogicExpression[] arrayOfLogicExpression1 = paramLogicBranch.Branches;
            var arrayOfLogicExpression = new LogicExpression[arrayOfLogicExpression1.Length][];

            int j = 0;
            int k = 1;
            LogicExpression[] arrayOfLogicExpression2;
            foreach (LogicExpression t in arrayOfLogicExpression1)
            {
                if ((t is LogicLeaf) || (t is LogicValue))
                {
                    arrayOfLogicExpression2 = new[] {t};
                    arrayOfLogicExpression[(j++)] = arrayOfLogicExpression2;
                }
                else
                {
                    arrayOfLogicExpression[j] = ((LogicBranch) t).Branches;
                    k *= arrayOfLogicExpression[j].Length;
                    j++;
                }
            }

            if (k*arrayOfLogicExpression1.Length == j)
            {
                return false;
            }
            var arrayOfInt = new int[arrayOfLogicExpression.Length];
            arrayOfInt[(arrayOfInt.Length - 1)] = -1;
            arrayOfLogicExpression2 = new LogicExpression[k];

            int n;
            for (n = 0; n < arrayOfLogicExpression2.Length; n++)
            {
                arrayOfInt[(arrayOfInt.Length - 1)] += 1;

                for (int i1 = arrayOfInt.Length - 1; i1 > 0; i1--)
                {
                    if (arrayOfInt[i1] != arrayOfLogicExpression[i1].Length)
                        break;
                    arrayOfInt[i1] = 0;
                    arrayOfInt[(i1 - 1)] += 1;
                }

                var arrayOfLogicExpression3 = new LogicExpression[arrayOfLogicExpression.Length];

                for (int i2 = 0; i2 < arrayOfLogicExpression3.Length; i2++)
                {
                    arrayOfLogicExpression3[i2] = arrayOfLogicExpression[i2][arrayOfInt[i2]];
                }
                if (arrayOfLogicExpression3.Length == 1)
                {
                    arrayOfLogicExpression2[n] = arrayOfLogicExpression3[0];
                }
                else
                {
                    var localLogicBranch = new LogicBranch(i, false)
                                               {
                                                   Branches = arrayOfLogicExpression3
                                               };
                    arrayOfLogicExpression2[n] = localLogicBranch;
                }
            }

            var nn = i == Operator.And ? Operator.Or : Operator.And;

            paramLogicBranch.Branches = arrayOfLogicExpression2;
            paramLogicBranch.Operator = nn;

            return true;
        }
예제 #7
0
        private static bool DeMorgans(LogicBranch paramLogicBranch)
        {
            var i = paramLogicBranch.Operator;

            if (!paramLogicBranch.Negated)
            {
                return false;
            }
            LogicExpression[] arrayOfLogicExpression = paramLogicBranch.Branches;

            foreach (LogicExpression t in arrayOfLogicExpression)
            {
                t.Negated = !t.Negated;
            }
            Operator j = i == Operator.And ? Operator.Or : Operator.And;

            paramLogicBranch.Operator = j;
            paramLogicBranch.Negated = false;

            return true;
        }
예제 #8
0
        private static bool associativity(LogicBranch paramLogicBranch)
        {
            LogicExpression[] arrayOfLogicExpression1 = paramLogicBranch.Branches;

            int i = 0;

            for (int j = 0; j < arrayOfLogicExpression1.Length; j++)
            {
                if (!(arrayOfLogicExpression1[j] is LogicBranch))
                    continue;
                var localLogicBranch1 = (LogicBranch) arrayOfLogicExpression1[j];

                if ((localLogicBranch1.Operator != paramLogicBranch.Operator) ||
                    localLogicBranch1.Negated)
                {
                    continue;
                }
                i += localLogicBranch1.Branches.Length - 1;
            }

            if (i == 0)
            {
                return false;
            }

            var arrayOfLogicExpression2 = new LogicExpression[arrayOfLogicExpression1.Length + i];

            int k = 0;

            for (int m = 0; m < arrayOfLogicExpression1.Length; m++)
            {
                if ((arrayOfLogicExpression1[m] is LogicBranch))
                {
                    var localLogicBranch2 = (LogicBranch) arrayOfLogicExpression1[m];

                    if ((localLogicBranch2.Operator == paramLogicBranch.Operator) &&
                        (!localLogicBranch2.Negated))
                    {
                        LogicExpression[] arrayOfLogicExpression3 = localLogicBranch2.Branches;

                        for (int n = 0; n < arrayOfLogicExpression3.Length; n++)
                            arrayOfLogicExpression2[(k++)] = arrayOfLogicExpression3[n];
                    }
                    else
                    {
                        arrayOfLogicExpression2[(k++)] = arrayOfLogicExpression1[m];
                    }
                }
                else
                {
                    arrayOfLogicExpression2[(k++)] = arrayOfLogicExpression1[m];
                }
            }
            paramLogicBranch.Branches = arrayOfLogicExpression2;

            return true;
        }
예제 #9
0
        private static int Absorbtion(LogicBranch paramLogicBranch)
        {
            LogicExpression[] arrayOfLogicExpression1 = paramLogicBranch.Branches;

            int j = 0;
            int m;
            int n;
            for (int k = 0; k < arrayOfLogicExpression1.Length - 1; k++)
            {
                for (m = k + 1; (m < arrayOfLogicExpression1.Length) && (arrayOfLogicExpression1[k] != null); m++)
                {
                    if (arrayOfLogicExpression1[m] == null)
                        continue;
                    n = IsAbsorbtion(arrayOfLogicExpression1[k], arrayOfLogicExpression1[m]);
                    switch (n)
                    {
                        case 21:
                            arrayOfLogicExpression1[m] = null;
                            j++;
                            break;
                        case 22:
                            arrayOfLogicExpression1[k] = null;
                            j++;
                            break;
                    }
                }
            }

            if (j > 0)
            {
                var arrayOfLogicExpression2 = new LogicExpression[arrayOfLogicExpression1.Length - j];

                m = 0;

                for (n = 0; n < arrayOfLogicExpression1.Length; n++)
                {
                    if (arrayOfLogicExpression1[n] != null)
                    {
                        arrayOfLogicExpression2[(m++)] = arrayOfLogicExpression1[n];
                    }
                }
                paramLogicBranch.Branches = arrayOfLogicExpression2;
            }

            return j;
        }
예제 #10
0
        private static LogicExpression SplitWordsByOperator(String[] paramArrayOfString, int position, Operator paramInt2,
            ParserSyntax paramParserSyntax)
        {
            int m;
            if (position == 0)
                throw new UnexpectedSymbolException("Operator at beginning of list of arguments");
            if (position == paramArrayOfString.Length - 1)
            {
                throw new UnexpectedSymbolException("Operator at end of list of arguments");
            }
            if ((paramInt2 == Operator.Implies) || (paramInt2 == Operator.Biimplies) || (paramInt2 == Operator.Xor))
            {
                var arrayOfLogicExpression1 = new LogicExpression[2];

                var arrayOfString1 = new String[position];
                var arrayOfString2 = new String[paramArrayOfString.Length - position - 1];
                for (m = 0; m < arrayOfString1.Length; m++)
                {
                    arrayOfString1[m] = paramArrayOfString[m];
                }
                m = position + 1;

                for (int n = 0; n < arrayOfString2.Length; n++)
                {
                    arrayOfString2[n] = paramArrayOfString[(m++)];
                }
                arrayOfLogicExpression1[0] = ParseWords(arrayOfString1, paramParserSyntax);
                arrayOfLogicExpression1[1] = ParseWords(arrayOfString2, paramParserSyntax);

                var localLogicBranch1 = new LogicBranch(paramInt2, false) {Branches = arrayOfLogicExpression1};
                return localLogicBranch1;
            }

            int i = 2;
            for (int k = position - 1; k >= 0; k--)
            {
                Operator j = GetOperatorValue(paramArrayOfString[k]);

                if (j == Operator.None)
                    continue;
                if (j != paramInt2)
                {
                    break;
                }
                paramParserSyntax.UpdateLogicSyntax(GetLogicSyntax(paramArrayOfString[k]));

                i++;
            }

            var arrayOfLogicExpression2 = new LogicExpression[i];

            m = paramArrayOfString.Length - 1;
            for (int i2 = arrayOfLogicExpression2.Length - 1; i2 >= 0; i2--)
            {
                int i1 = 0;

                int i3;
                for (i3 = m; i3 >= 0; i3--)
                {
                    var j = GetOperatorValue(paramArrayOfString[i3]);

                    if (j != paramInt2)
                        i1++;
                    else if (j == paramInt2)
                    {
                        break;
                    }
                }
                var arrayOfString3 = new String[i1];

                i3 = m - i1;
                int i4 = i1 - 1;

                for (int i5 = m; i5 > i3; i5--)
                {
                    arrayOfString3[(i4--)] = paramArrayOfString[i5];
                }

                m = m - i1 - 1;

                arrayOfLogicExpression2[i2] = ParseWords(arrayOfString3, paramParserSyntax);
            }

            var localLogicBranch2 = new LogicBranch(paramInt2, false) {Branches = arrayOfLogicExpression2};
            return localLogicBranch2;
        }
예제 #11
0
 public void SetParent(LogicBranch parent, int positionInParent)
 {
     Parent = parent;
     PositionInParent = positionInParent;
 }