public void Test3() { ObjectVariableTerm x = new ObjectVariable('x'); IndividualConstantTerm <RationalNumber> half = (IndividualConstant <RationalNumber>)(new RationalNumber(1, 2)); IndividualConstantTerm <RationalNumber> one = (IndividualConstant <RationalNumber>)(new RationalNumber(1, 1)); var pr1 = new PredicateFormula(Predicates.More, x, half); var pr2 = new PredicateFormula(Predicates.Less, x, one); var f1 = new PropositionalConnectiveFormula(Conjunction.GetInstance(), pr1, pr2); var f2 = new QuantifierFormula(ExistentialQuantifier.GetInstance(), x, f1); IndividualConstantTerm <int> twoConst = new IndividualConstant <int>(2); var xSqr = new FunctionTerm(Functions.Pow, x, twoConst); var pr3 = new PredicateFormula(Predicates.MoreZero, xSqr); var pr4 = new PredicateFormula(Predicates.EqualZero, x); var f3 = new PropositionalConnectiveFormula(Disjunction.GetInstance(), pr3, pr4); var f4 = new QuantifierFormula(UniversalQuantifier.GetInstance(), x, f3); var f = new PropositionalConnectiveFormula(Conjunction.GetInstance(), f2, f4); var actual = SimpleTarskiAlgorithm.QuantifiersElimination(f); Formula expected = new PredicateFormula(True.GetInstance()); Assert.AreEqual(expected, actual); }
public void Constructor_CreateUniversalQuantifierNoReplacementVariablesPresent_GammaRuleShouldNotBeAppliedNoChildrenGenerated() { // Arrange char boundVariable = PropositionGenerator.GenerateBoundVariable(); List <char> boundVariables = new List <char>() { boundVariable }; Predicate predicate = new Predicate(PropositionGenerator.GetRandomVariableLetter(), boundVariables); UniversalQuantifier universalQuantifier = new UniversalQuantifier(boundVariable); universalQuantifier.LeftSuccessor = predicate; HashSet <Proposition> propositions = new HashSet <Proposition>() { universalQuantifier }; // Act SemanticTableauxElement semanticTableauxElement = new SemanticTableauxElement(propositions); bool isReplaced = predicate.IsReplaced(boundVariable); // Assert isReplaced.Should().BeFalse("Because no replacement variables are available"); semanticTableauxElement.LeftChild.Should().BeNull("Because no replacement variables are available and thus no child was created"); }
private static Symbol SpecialSymbol(string str, ref int index) { ++index; if (index >= str.Length) { throw new ArgumentException( $"a tag was expected, but there is no tag before the symbol \\ with the number {index - 1}"); } var tag = GetTag(str, ref index); if (tag.Length == 0) { throw new ArgumentException( $"a tag was expected, but there is no tag before the symbol \\ with the number {index - 1}"); } return(tag switch { "lnot" => Negation.GetInstance(), "lor" => Disjunction.GetInstance(), "land" => Conjunction.GetInstance(), "to" => Implication.GetInstance(), "forall" => UniversalQuantifier.GetInstance(), "exists" => ExistentialQuantifier.GetInstance(), "over" => Division.GetInstance(), "func" => GetFunction(str, ref index), // \func{name arity} "pr" => GetPredicate(str, ref index), // \pr{name arity} _ => throw new ArgumentException($"unknown tag {tag} before the symbol with the number {index}") });
public void ZeroEqualZero() { ObjectVariableTerm x = new ObjectVariable('x'); IndividualConstantTerm <int> zero = (IndividualConstant <int>) 0; var pr = new PredicateFormula(Predicates.Equal, zero, zero); var f = new QuantifierFormula(UniversalQuantifier.GetInstance(), x, pr); var actual = SimpleTarskiAlgorithm.QuantifiersElimination(f); var expected = new PredicateFormula(True.GetInstance()); Assert.AreEqual(expected, actual); }
public void Constructor_CreateNegatedUniversalQuantifier_DeltaRuleShouldBeAppliedChildShouldBePredicateAndVariableShouldBeIntroduced() { // Arrange char boundVariable = PropositionGenerator.GenerateBoundVariable(); List <char> boundVariables = new List <char>() { boundVariable }; Predicate predicate = new Predicate(PropositionGenerator.GetRandomVariableLetter(), boundVariables); UniversalQuantifier universalQuantifier = new UniversalQuantifier(boundVariable); universalQuantifier.LeftSuccessor = predicate; Negation negatedUniversalQuantifier = new Negation(); negatedUniversalQuantifier.LeftSuccessor = universalQuantifier; HashSet <Proposition> propositions = new HashSet <Proposition>() { negatedUniversalQuantifier }; // Act SemanticTableauxElement semanticTableauxElement = new SemanticTableauxElement(propositions); List <char> replacementVariables = semanticTableauxElement.LeftChild.ReplacementVariables.ToList(); int expectedNumberOfReplacementVariables = 1; int actualNumberOfReplacementVariables = replacementVariables.Count; // Assert actualNumberOfReplacementVariables.Should().Be(expectedNumberOfReplacementVariables, "Because the only bound variable should be replaced based on the rules"); foreach (Proposition proposition in semanticTableauxElement.LeftChild.Propositions) { if (proposition is Predicate) { predicate = (Predicate)proposition; bool isReplaced = predicate.IsReplaced(boundVariable); isReplaced.Should().BeTrue("Because after applying a delta rule, the only bound variable in the predicate should be replaced"); } } }
public void Constructor_CreateUniversalQuantifierWithReplacementVariablePresent_GammaRuleShouldBeAppliedAndNewChildrenCreated() { // Arrange char boundVariable = PropositionGenerator.GenerateBoundVariable(); List <char> boundVariables = new List <char>() { boundVariable }; Predicate predicate = new Predicate(PropositionGenerator.GetRandomVariableLetter(), boundVariables); UniversalQuantifier universalQuantifier = new UniversalQuantifier(boundVariable); universalQuantifier.LeftSuccessor = predicate; HashSet <Proposition> propositions = new HashSet <Proposition>() { universalQuantifier }; // Act char availableReplacementVariable = 'd'; SemanticTableauxElement semanticTableauxElement = new SemanticTableauxElement(propositions, new HashSet <char>() { availableReplacementVariable }); // Assert semanticTableauxElement.LeftChild.Should().NotBeNull("Because children should be created now that a replacement variable is present"); foreach (Proposition proposition in semanticTableauxElement.LeftChild.Propositions) { if (proposition is Predicate) { Predicate pred = (Predicate)proposition; bool isReplaced = pred.IsReplaced(boundVariable); isReplaced.Should().BeTrue($"Because the replacement variable {availableReplacementVariable} is available"); } } }