示例#1
0
        public void TestBiConditionalTransformation()
        {
            Sentence bic            = parser.Parse("A <=> B");
            Sentence transformedBic = ConvertToCNF.Convert(bic);

            Assert.AreEqual("(~A | B) & (~B | A)", transformedBic.ToString());
        }
示例#2
0
        public void TestFourSuccessiveNotsTransformation()
        {
            Sentence fourNots    = parser.Parse("~~~~A");
            Sentence transformed = ConvertToCNF.Convert(fourNots);

            Assert.AreEqual("A", transformed.ToString());
        }
示例#3
0
        public void TestDistributingOrCorrectly()
        {
            Sentence s           = parser.Parse("A & B & C & D & (E | (F & G)) & H & I & J & K");
            Sentence transformed = ConvertToCNF.Convert(s);

            Assert.AreEqual("A & B & C & D & (E | F) & (E | G) & H & I & J & K", transformed.ToString());
        }
示例#4
0
        public void TestImplicationTransformation()
        {
            Sentence impl            = parser.Parse("A => B");
            Sentence transformedImpl = ConvertToCNF.Convert(impl);

            Assert.AreEqual("~A | B", transformedImpl.ToString());
        }
示例#5
0
        public void TestSymbolTransform()
        {
            Sentence symbol      = parser.Parse("A");
            Sentence transformed = ConvertToCNF.Convert(symbol);

            Assert.AreEqual("A", transformed.ToString());
        }
示例#6
0
        public void TestNested()
        {
            Sentence nested      = parser.Parse("A | (B | (C | (D & E)))");
            Sentence transformed = ConvertToCNF.Convert(nested);

            Assert.AreEqual("(A | B | C | D) & (A | B | C | E)", transformed.ToString());

            nested      = parser.Parse("A | (B | (C & (D & E)))");
            transformed = ConvertToCNF.Convert(nested);
            Assert.AreEqual("(A | B | C) & (A | B | D) & (A | B | E)", transformed.ToString());

            nested      = parser.Parse("A | (B | (C & (D & (E | F))))");
            transformed = ConvertToCNF.Convert(nested);
            Assert.AreEqual("(A | B | C) & (A | B | D) & (A | B | E | F)", transformed.ToString());

            nested      = parser.Parse("(A | (B | (C & D))) | E | (F | (G | (H & I)))");
            transformed = ConvertToCNF.Convert(nested);
            Assert.AreEqual("(A | B | C | E | F | G | H) & (A | B | D | E | F | G | H) & (A | B | C | E | F | G | I) & (A | B | D | E | F | G | I)", transformed.ToString());

            nested      = parser.Parse("(((~P | ~Q) => ~(P | Q)) => R)");
            transformed = ConvertToCNF.Convert(nested);
            Assert.AreEqual("(~P | ~Q | R) & (P | Q | R)", transformed.ToString());

            nested      = parser.Parse("~(((~P | ~Q) => ~(P | Q)) => R)");
            transformed = ConvertToCNF.Convert(nested);
            Assert.AreEqual("(P | ~P) & (Q | ~P) & (P | ~Q) & (Q | ~Q) & ~R", transformed.ToString());
        }
示例#7
0
        public void TestAimaExample()
        {
            Sentence aimaEg      = parser.Parse("B11 <=> P12 | P21");
            Sentence transformed = ConvertToCNF.Convert(aimaEg);

            Assert.AreEqual("(~B11 | P12 | P21) & (~P12 | B11) & (~P21 | B11)", transformed.ToString());
        }
示例#8
0
        public void TestOrDistribution2()
        {
            Sentence or          = parser.Parse("A | B & C");
            Sentence transformed = ConvertToCNF.Convert(or);

            Assert.AreEqual("(A | B) & (A | C)", transformed.ToString());
        }
示例#9
0
        public void TestDeMorgan2()
        {
            Sentence dm          = parser.Parse("~(A | B)");
            Sentence transformed = ConvertToCNF.Convert(dm);

            Assert.AreEqual("~A & ~B", transformed.ToString());
        }
示例#10
0
        public void TestIssue78()
        {
            // (  ( NOT J1007 )  OR  ( NOT ( OR J1008 J1009 J1010 J1011 J1012 J1013 J1014 J1015  )  )  )
            Sentence issue78Eg   = parser.Parse("(  ( ~ J1007 )  |  ( ~ ( J1008 | J1009 | J1010 | J1011 | J1012 | J1013 | J1014 | J1015  )  ) )");
            Sentence transformed = ConvertToCNF.Convert(issue78Eg);

            Assert.AreEqual("(~J1007 | ~J1008) & (~J1007 | ~J1009) & (~J1007 | ~J1010) & (~J1007 | ~J1011) & (~J1007 | ~J1012) & (~J1007 | ~J1013) & (~J1007 | ~J1014) & (~J1007 | ~J1015)", transformed.ToString());
        }
        /**
         * Devuelve la sentencia especificada en su equivalente lógica de forma de conjunción de cláusulas.
         *
         * @param s
         *            una sentencia de lógica proposicional
         *
         * @return la sentencia de entrada convertida en su equivalente lógica de forma de conjunción de cláusulas.
         */
        public static ConjunctionOfClauses Convert(Sentence s)
        {
            ConjunctionOfClauses result = null;

            Sentence cnfSentence = ConvertToCNF.Convert(s);

            IList <Clause> clauses = new List <Clause>(); //ArrayList

            foreach (var c in ClauseCollector.GetClausesFrom(cnfSentence))
            {
                clauses.Add(c);
            }

            result = new ConjunctionOfClauses(clauses);

            return(result);
        }
示例#12
0
        public void TestBasicSentenceTransformation()
        {
            Sentence and            = parser.Parse("A & B");
            Sentence transformedAnd = ConvertToCNF.Convert(and);

            Assert.AreEqual("A & B", transformedAnd.ToString());

            Sentence or            = parser.Parse("A | B");
            Sentence transformedOr = ConvertToCNF.Convert(or);

            Assert.AreEqual("A | B", transformedOr.ToString());

            Sentence not            = parser.Parse("~C");
            Sentence transformedNot = ConvertToCNF.Convert(not);

            Assert.AreEqual("~C", transformedNot.ToString());
        }