public void LiteralStringTest()
 {
     Literal a = new Literal("", "A");
     Literal b = new Literal("~", "B");
     Assert.AreEqual(a.ToString(), "A", "ToString result incorrect");
     Assert.AreEqual(b.ToString(), "~B", "ToString result incorrect");
 }
 public void LiteralNegationTest()
 {
     Literal a = new Literal("", "A");
     Literal b = new Literal("~", "B");
     Assert.AreEqual(a.GetNegation().ToString(), "~A", "First negation incorrect");
     Assert.AreEqual(b.GetNegation().ToString(), "B", "Second negation incorrect");
 }
 public void ClauseStringTest()
 {
     Clause clause = new Clause();
     Literal a = new Literal("","A");
     Literal b = new Literal("~", "B");
     clause.AddLiteral(a);
     clause.AddLiteral(b);
     Assert.AreEqual(clause.ToString(), "( A v ~B )", "Clause.ToString result incorrect");
 }
 public void ClauseNegationTest()
 {
     Clause clause = new Clause();
     Literal a = new Literal("","A");
     Literal b = new Literal("~", "B");
     clause.AddLiteral(a);
     clause.AddLiteral(b);
     Sentence s = clause.GetNegation();
     Assert.AreEqual(s.ToString(), "( ~A ) ^ ( B )", "Negated clause incorrect");
 }
 public void ClauseListTest()
 {
     Clause clause = new Clause();
     Literal a = new Literal("", "A");
     Literal b = new Literal("~", "B");
     clause.AddLiteral(a);
     clause.AddLiteral(b);
     Assert.AreEqual(clause.Literals[0], a, "First element incorrect");
     Assert.AreEqual(clause.Literals[1], b, "Second element incorrect");
 }
        public void LiteralConstructorTest()
        {
            Literal literal = new Literal("", "A");
            Assert.AreEqual(literal.Negation, "", "Negation is incorrect");
            Assert.AreEqual(literal.Variable, "A", "Variable is incorrect");

            Literal unliteral = new Literal("~", "B");
            Assert.AreEqual(unliteral.Negation, "~", "Negation incorrect");
            Assert.AreEqual(unliteral.Variable, "B", "Variable incorrect");
        }
 public void AddLiteral(Literal literal)
 {
     Literals.Add(literal);
 }
 public void RemoveLiteral(Literal literal)
 {
     Literals.Remove(literal);
 }
        public static void resolutionTest2()
        {
            Console.WriteLine("******************** start resolutionTest2 ********************");

            Sentence premises = new Sentence();

            Clause tempClause = new Clause();

            Literal tempLiteral = new Literal("", "A");
            tempClause.AddLiteral(tempLiteral);
            tempLiteral = new Literal("~", "B");
            tempClause.AddLiteral(tempLiteral);

            premises.AddClause(tempClause);

            tempClause = new Clause();
            tempLiteral = new Literal("", "B");
            tempClause.AddLiteral(tempLiteral);
            tempLiteral = new Literal("~", "D");
            tempClause.AddLiteral(tempLiteral);

            premises.AddClause(tempClause);

            tempClause = new Clause();
            tempLiteral = new Literal("", "E");
            tempClause.AddLiteral(tempLiteral);
            tempLiteral = new Literal("~", "F");
            tempClause.AddLiteral(tempLiteral);
            tempLiteral = new Literal("~", "A");
            tempClause.AddLiteral(tempLiteral);

            premises.AddClause(tempClause);

            //Console.WriteLine("premises\n"+premises);

            ///////////////
            ////////////
            /////////////////

            Sentence conclusion = new Sentence();
            tempClause = new Clause();
            tempLiteral = new Literal("", "C");
            tempClause.AddLiteral(tempLiteral);

            conclusion.AddClause(tempClause);

            tempClause = new Clause();
            tempLiteral = new Literal("~", "X");
            tempClause.AddLiteral(tempLiteral);

            conclusion.AddClause(tempClause);

            Console.WriteLine("**** premises " + premises);
            Console.WriteLine("***** conclusion " + conclusion);

            bool canResolve = TheoremProver.PlResolution(premises, conclusion);

            Console.WriteLine("canResolve " + canResolve);

            Console.WriteLine("******************** end resolutionTest2 ********************");
        }
        public static void basicTests()
        {
            Console.WriteLine("******************** start basicTests ********************");
            Sentence theSentence = new Sentence();

            Clause tempClause = new Clause();

            Literal tempLiteral = new Literal("", "A");
            Console.WriteLine("tempLiteral (should be 'A')\n" + tempLiteral);
            tempClause.AddLiteral(tempLiteral);
            tempLiteral = new Literal("~", "B");
            Console.WriteLine("tempLiteral (should be '~B')\n" + tempLiteral);
            tempClause.AddLiteral(tempLiteral);
            Console.WriteLine("tempClause (should be '( A v ~B )')\n" + tempClause);

            theSentence.AddClause(tempClause);
            Console.WriteLine("theSentence (should be '( A v ~B )')\n" + theSentence);

            tempClause = new Clause();
            tempLiteral = new Literal("", "B");
            tempClause.AddLiteral(tempLiteral);
            tempLiteral = new Literal("~", "D");
            tempClause.AddLiteral(tempLiteral);

            theSentence.AddClause(tempClause);
            Console.WriteLine("theSentence (should be '( A v ~B ) ^ ( B v ~D )'\n" + theSentence);

            tempClause = new Clause();
            tempLiteral = new Literal("", "E");
            tempClause.AddLiteral(tempLiteral);
            tempLiteral = new Literal("~", "F");
            tempClause.AddLiteral(tempLiteral);
            tempLiteral = new Literal("~", "A");
            tempClause.AddLiteral(tempLiteral);

            theSentence.AddClause(tempClause);

            Console.WriteLine("theSentence (should be '( A v ~B ) ^ ( B v ~D ) ^ ( E v ~F v ~A )'\n" + theSentence);

            tempLiteral = new Literal("", "A");
            Console.WriteLine("tempLiteral (should be 'A')\n" + tempLiteral);
            tempLiteral = tempLiteral.GetNegation();
            Console.WriteLine("negation of tempLiteral (should be '~A')\n" + tempLiteral);
            tempLiteral = tempLiteral.GetNegation();
            Console.WriteLine("negation of negation of tempLiteral (should be 'A')\n" + tempLiteral);

            tempClause = new Clause();
            tempClause.AddLiteral(tempLiteral);
            tempLiteral = new Literal("", "B");
            tempClause.AddLiteral(tempLiteral);

            Console.WriteLine("tempClause   (should be '( A v B )'\n" + tempClause);

            Sentence negatedTempClause = tempClause.GetNegation();
            Console.WriteLine("negatedTempClause   (should be '( ~A ) ^ ( ~B )'\n" + negatedTempClause);

            Sentence negatedSentence = negatedTempClause.GetNegation();

            Console.WriteLine("negatedSentence   (should be '( A v B )'\n" + tempClause);

            Console.WriteLine("=======");
            Console.WriteLine("=======");

            Sentence testerSentence = new Sentence();

            tempClause = new Clause();
            tempLiteral = new Literal("~", "A");
            tempClause.AddLiteral(tempLiteral);
            tempLiteral = new Literal("", "B");
            tempClause.AddLiteral(tempLiteral);
            tempLiteral = new Literal("~", "C");
            tempClause.AddLiteral(tempLiteral);

            Console.WriteLine("tempClause   (should be '( ~A v B v ~C )'\n" + tempClause);

            testerSentence.AddClause(tempClause);
            Console.WriteLine("testerSentence   (should be '( ~A v B v ~C )'\n" + testerSentence);

            tempClause = new Clause();
            tempLiteral = new Literal("", "C");
            tempClause.AddLiteral(tempLiteral);
            tempLiteral = new Literal("", "D");
            tempClause.AddLiteral(tempLiteral);
            tempLiteral = new Literal("", "E");
            tempClause.AddLiteral(tempLiteral);

            Console.WriteLine("tempClause   (should be '( C v D v E )'\n" + tempClause);

            testerSentence.AddClause(tempClause);
            Console.WriteLine("testerSentence   (should be '( ~A v B v ~C ) ^ ( C v D v E )'\n" + testerSentence);

            //WE START WITH     ( ~A v B v ~C ) ^ ( C v D v E )

            //NEGATE IT        ~ ( ( ~A v B v ~C ) ^ ( C v D v E ) )
            //DeMorgan's gives us   ~ ( ~A v B v ~C ) v ~ ( C v D v E )
            //DeMorgan's again      ( A ^ ~B ^ C ) v (~C ^ ~D ^ ~E )

            //now do distribution to arrive at CNF

            ///  ( A v ~C) ^ ( A v ~D ) ^ ( A v ~E ) ^ ( ~B v ~C ) ^ ( ~B v ~D ) ^ ( ~B v ~E ) ^ ( C v ~C ) ^ ( C v ~D ) ^ ( C v ~E )

            Sentence negatedTesterSentence = testerSentence.GetNegation();

            Console.WriteLine("negatedTesterSentence   (should be '( A v ~C ) ^ ( A v ~D ) ^ ( A v ~E ) ^ ( ~B v ~C ) ^ ( ~B v ~D ) ^ ( ~B v ~E ) ^ ( C v ~C ) ^ ( C v ~D ) ^ ( C v ~E ) \n" +
            "        '\n" + negatedTesterSentence);

            Console.WriteLine("******************** end basicTests ********************");
        }