public static void ReplaceBIIMPLIESOperator(OperatorExpression paramOperatorExpression) { LogicExpression[] arrayOfLogicExpression1 = paramOperatorExpression.Branches; LogicExpression[] arrayOfLogicExpression2 = { arrayOfLogicExpression1[0].Clone(), arrayOfLogicExpression1[1].Clone() }; LogicExpression[] arrayOfLogicExpression3 = { arrayOfLogicExpression1[0].Clone(), arrayOfLogicExpression1[1].Clone() }; arrayOfLogicExpression3[0].Negated = !arrayOfLogicExpression3[0].Negated; arrayOfLogicExpression3[1].Negated = !arrayOfLogicExpression3[1].Negated; var localLogicBranch1 = new OperatorExpression(Operator.And) { Branches = arrayOfLogicExpression2 }; var localLogicBranch2 = new OperatorExpression(Operator.And) { Branches = arrayOfLogicExpression3 }; LogicExpression[] arrayOfLogicExpression4 = {localLogicBranch1, localLogicBranch2}; paramOperatorExpression.Branches = arrayOfLogicExpression4; paramOperatorExpression.Operator = Operator.Or; }
public static void ReplaceIMPLIESOperator(OperatorExpression paramOperatorExpression) { LogicExpression[] arrayOfLogicExpression = paramOperatorExpression.Branches; arrayOfLogicExpression[0].Negated = !arrayOfLogicExpression[0].Negated; paramOperatorExpression.Operator = (Operator) 1; }
public override LogicExpression Clone() { var localLogicBranch = new OperatorExpression(Operator, Negated); var arrayOfLogicExpression = new LogicExpression[_logicBranches.Length]; for (int i = 0; i < _logicBranches.Length; i++) { arrayOfLogicExpression[i] = _logicBranches[i].Clone(); } localLogicBranch.Branches = arrayOfLogicExpression; return localLogicBranch; }
public static BoolResolution GetBoolResolution(OperatorExpression paramOperatorExpression) { LogicExpression[] arrayOfLogicExpression = paramOperatorExpression.Branches; bool i = false; bool j = false; foreach (bool b in arrayOfLogicExpression.OfType<LogicValue>().Select(t => t.EqualsTrue())) { if (b) i = true; else j = true; if (i && j) { break; } } if (i || j) { var k = paramOperatorExpression.Operator; switch (k) { case Operator.And: return j ? BoolResolution.BoolResolveFalse : BoolResolution.BoolRemoveBoolValues; case Operator.Or: return i ? BoolResolution.BoolResolveTrue : BoolResolution.BoolRemoveBoolValues; } Console.Error.WriteLine("Software Error: Operator other than AND, OR found when looking at bool values"); return BoolResolution.BoolNotFound; } return BoolResolution.BoolNotFound; }
public static int Absorbtion(OperatorExpression paramOperatorExpression) { LogicExpression[] arrayOfLogicExpression1 = paramOperatorExpression.Branches; int j = 0; int m; 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; var q = IsAbsorbtion(arrayOfLogicExpression1[k], arrayOfLogicExpression1[m]); switch (q) { case Absorption.AbsorbedRight: arrayOfLogicExpression1[m] = null; j++; break; case Absorption.AbsorbedLeft: arrayOfLogicExpression1[k] = null; j++; break; } } } if (j > 0) { var arrayOfLogicExpression2 = new LogicExpression[arrayOfLogicExpression1.Length - j]; m = 0; foreach (LogicExpression t in arrayOfLogicExpression1.Where(t => t != null)) { arrayOfLogicExpression2[m++] = t; } paramOperatorExpression.Branches = arrayOfLogicExpression2; } return j; }
public static bool Distributivity(OperatorExpression paramOperatorExpression) { Operator @operator = paramOperatorExpression.Operator; LogicExpression[] branches = paramOperatorExpression.Branches; var arrayOfLogicExpression = new LogicExpression[branches.Length][]; int j = 0; int k = 1; foreach (LogicExpression expression in branches) { if (((expression is ParameterLogicExpression)) || ((expression is LogicValue))) { arrayOfLogicExpression[(j++)] = new[] {expression}; } else { arrayOfLogicExpression[j] = ((OperatorExpression) expression).Branches; k *= arrayOfLogicExpression[j].Length; j++; } } if (k*branches.Length == j) { return false; } var arrayOfInt = new int[arrayOfLogicExpression.Length]; arrayOfInt[arrayOfInt.Length - 1] = -1; var expressions = new LogicExpression[k]; for (int n = 0; n < expressions.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) { expressions[n] = arrayOfLogicExpression3[0]; } else { expressions[n] = new OperatorExpression(@operator) { Branches = arrayOfLogicExpression3 }; } } var nn = (Operator) (@operator == 0 ? 1 : 0); paramOperatorExpression.Branches = expressions; paramOperatorExpression.Operator = nn; return true; }
public static bool Associativity(OperatorExpression paramOperatorExpression) { LogicExpression[] arrayOfLogicExpression1 = paramOperatorExpression.Branches; int i = arrayOfLogicExpression1.OfType<OperatorExpression>() .Where( branch => (branch.Operator == paramOperatorExpression.Operator) && (!branch.Negated)) .Sum(branch => branch.Branches.Length - 1); if (i == 0) { return false; } var arrayOfLogicExpression2 = new LogicExpression[arrayOfLogicExpression1.Length + i]; int k = 0; foreach (LogicExpression t in arrayOfLogicExpression1) { var operatorExpression = t as OperatorExpression; if (operatorExpression != null) { var localLogicBranch2 = operatorExpression; if ((localLogicBranch2.Operator == paramOperatorExpression.Operator) && (!localLogicBranch2.Negated)) { LogicExpression[] arrayOfLogicExpression3 = localLogicBranch2.Branches; foreach (LogicExpression t1 in arrayOfLogicExpression3) arrayOfLogicExpression2[k++] = t1; } else { arrayOfLogicExpression2[k++] = t; } } else { arrayOfLogicExpression2[(k++)] = t; } } paramOperatorExpression.Branches = arrayOfLogicExpression2; return true; }
public static bool DeMorgans(OperatorExpression paramOperatorExpression) { Operator i = paramOperatorExpression.Operator; if (!paramOperatorExpression.Negated) { return false; } LogicExpression[] arrayOfLogicExpression = paramOperatorExpression.Branches; foreach (LogicExpression t in arrayOfLogicExpression) { t.Negated = !t.Negated; } paramOperatorExpression.Operator = i == Operator.And ? Operator.Or : Operator.And; paramOperatorExpression.Negated = false; return true; }
public static void ReplaceXOROperator(OperatorExpression paramOperatorExpression) { LogicExpression[] branches = paramOperatorExpression.Branches; LogicExpression[] expressions = { branches[0].Clone(), branches[1].Clone() }; expressions[0].Negated = !expressions[0].Negated; LogicExpression[] arrayOfLogicExpression3 = { branches[0].Clone(), branches[1].Clone() }; arrayOfLogicExpression3[1].Negated = !arrayOfLogicExpression3[1].Negated; LogicExpression[] arrayOfLogicExpression4 = { new OperatorExpression(Operator.And) { Branches = expressions }, new OperatorExpression(Operator.And) { Branches = arrayOfLogicExpression3 } }; paramOperatorExpression.Branches = arrayOfLogicExpression4; paramOperatorExpression.Operator = Operator.Or; }
// EmptyLogicException, DifferentSyntaxesUsedException, UnexpectedSymbolException, InvalidVariableNameException, UnclosedBracketException private static LogicExpression SplitWordsByOperator(String[] paramArrayOfString, int paramInt1, Operator paramInt2, ParserSyntax paramParserSyntax) { if (paramInt1 == 0) throw new UnexpectedSymbolException("Operator at beginning of list of arguments"); if (paramInt1 == paramArrayOfString.Length - 1) { throw new UnexpectedSymbolException("Operator at end of list of arguments"); } int m; if ((paramInt2 == Operator.OperatorXor) || (paramInt2 == Operator.OperatorImplies) || (paramInt2 == Operator.OperatorBiimplies)) { var arrayOfLogicExpression1 = new LogicExpression[2]; var arrayOfString1 = new String[paramInt1]; var arrayOfString2 = new String[paramArrayOfString.Length - paramInt1 - 1]; for (var mm = 0; mm < arrayOfString1.Length; mm++) { arrayOfString1[mm] = paramArrayOfString[mm]; } m = paramInt1 + 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 OperatorExpression(paramInt2) { Branches = arrayOfLogicExpression1 }; return localLogicBranch1; } int i = 2; for (int k = paramInt1 - 1; k >= 0; k--) { var j = GetOperatorValue(paramArrayOfString[k]); if (j == Operator.NonOperator) 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 OperatorExpression(paramInt2) { Branches = arrayOfLogicExpression2 }; return localLogicBranch2; }
public void SetParent(OperatorExpression paramOperatorExpression, int paramInt) { _parent = paramOperatorExpression; _positionInParent = paramInt; }