public void TestModusPonens() { RephraserType r1 = new ModusPonens(), r2 = new ModusPonens(), r3 = new ModusPonens(); r1.AddLeftBlock(new Block("a")).AddRightBlock(new Block("b")); r2.AddLeftBlock(ClauseParser.Parse("(a&b)")).AddRightBlock(new Block("c")); r3.AddLeftBlock(ClauseParser.Parse("(a&b)")).AddRightBlock(ClauseParser.Parse("(c||d)")); Assert.AreEqual("~a||b", r1.Translate().ToString()); Assert.AreEqual("~(a&b)||c", r2.Translate().ToString()); Assert.AreEqual("~(a&b)||(c||d)", r3.Translate().ToString()); }
/// <summary> /// /// </summary> /// <param name="logic"></param> /// <param name="rootBlock"></param> /// <param name="currentBlock"></param> private void TranslateToCNF( PropositionalLogic logic, ref Block rootBlock, ref Block currentBlock) { RephraserType type = null; if (logic.IsBiconditional) { type = new BiconditionalElimination(); } else if (logic.IsImplication) { type = new ModusPonens(); } else if (logic.IsDisjunction) { type = new Distribution(); } if (type == null) { throw new System.Exception("Obligatory exception"); } System.Console.WriteLine("{0}, {1}", currentBlock.GetContent(true).ToString(), currentBlock.GetHashCode()); var unAffectedBlock = currentBlock.NextBlock.NextBlock; var newList = Translation( ref rootBlock, type, currentBlock.PreviousBlock, logic, currentBlock.NextBlock); currentBlock = unAffectedBlock.Equals(currentBlock) ? newList : unAffectedBlock.ExtendFront(newList); System.Console.WriteLine("{0}, {1}", currentBlock.GetContent(true).ToString(), currentBlock.GetHashCode()); }