예제 #1
0
        private static void PrintTrace(ParsedExpression expression, LogicDerivation derivation, string initialText)
        {
            LogicSyntax logicSyntax = expression.LogicSyntax;
            NegationSyntax negationSyntax = expression.NegationSyntax;
            int i = initialText.Length;
            var localStringBuilder = new StringBuilder();

            for (int j = 0; j < i; j++)
            {
                localStringBuilder.Append(" ");
            }
            String str = localStringBuilder.ToString();
            int k = 1;

            foreach (LogicStep localLogicStep in derivation.Steps)
            {
                Console.WriteLine(
                    new StringBuilder().Append(k != 0 ? initialText : str).Append(" |=| ").Append(
                        localLogicStep.Expression.ToString(logicSyntax, negationSyntax)).Append(" - ").Append(localLogicStep.Comment).Append(
                            " - ").Append(LogicHandler.GetFormName(localLogicStep.Form)).ToString());

                k = 0;
            }

            Console.WriteLine(new StringBuilder().Append("CNF: ").Append(derivation.CNF.ToString(logicSyntax, negationSyntax)).ToString());
            Console.WriteLine(new StringBuilder().Append("DNF: ").Append(derivation.DNF.ToString(logicSyntax, negationSyntax)).ToString());
        }
예제 #2
0
		public static LogicDerivation LocalLogicDerivation(ParsedExpression expression)
		{
			var derivation = new LogicDerivation(expression.Expression);

			if (derivation.CNFandDNF)
			{
				return derivation;
			}

			derivation.CarryOutNonPrimaryOperatorReplacement();
			derivation.CarryOutBoolValues();

			if (derivation.CNFandDNF)
			{
				return derivation;
			}
			derivation.CarryOutAssociativity();
			derivation.CarryOutDeMorgans();
			derivation.CarryOutAssociativity();
			derivation.CarryOutIdempotency();
			derivation.CarryOutBoolValues();
			derivation.CarryOutAbsorbtion();

			if (derivation.CNFandDNF)
			{
				return derivation;
			}

			do
			{
				derivation.CarryOutDistributivity();
				derivation.CarryOutAssociativity();
				derivation.CarryOutIdempotency();
				derivation.CarryOutBoolValues();
				derivation.CarryOutAbsorbtion();
			} while (!derivation.CNFandDNF);
			return derivation;
		}