Пример #1
0
        private void ApplyDoubleNegationRule(Proposition proposition)
        {
            HashSet <Proposition> propositions = new HashSet <Proposition>();

            foreach (Proposition p in Propositions)
            {
                if (!p.Equals(proposition))
                {
                    propositions.Add(p);
                }
            }

            Proposition doubleNegationRemoved = null;

            if (proposition.GetType() == typeof(Negation))
            {
                Negation    negation           = (Negation)proposition;
                Proposition negatedProposition = negation.LeftSuccessor;

                if (negatedProposition.GetType() == typeof(Negation))
                {
                    Negation negatedNegation = (Negation)negatedProposition;

                    doubleNegationRemoved = negatedNegation.LeftSuccessor;
                    propositions.Add(doubleNegationRemoved);
                }
            }

            LeftChild = new SemanticTableauxElement(propositions, new HashSet <char>(ReplacementVariables));
        }
Пример #2
0
        private static void NumberElements(SemanticTableaux semanticTableaux)
        {
            List <SemanticTableauxElement> queue = new List <SemanticTableauxElement>();

            queue.Add(semanticTableaux.Head);
            int nodeCounter = 1;
            SemanticTableauxElement currentElement = null;

            while (queue.Count > 0)
            {
                currentElement = queue[0];
                queue.RemoveAt(0);

                currentElement.NodeNumber = nodeCounter;

                if (currentElement.LeftChild != null)
                {
                    queue.Add(currentElement.LeftChild);
                }

                if (currentElement.RightChild != null)
                {
                    queue.Add(currentElement.RightChild);
                }

                nodeCounter++;
            }
        }
Пример #3
0
        public SemanticTableaux(Proposition proposition)
        {
            Proposition = proposition;

            if (proposition == null)
            {
                throw new NullReferenceException("A proposition is required to make use of the semantic tableaux");
            }

            Negation negation = new Negation();

            negation.LeftSuccessor = proposition;

            HashSet <Proposition> propositions = new HashSet <Proposition>()
            {
                negation
            };

            // Then the type of semantic tableaux element could be
            // set by the semantic tableaux by perhaps setting
            // an enum on the semantic tableaux element
            // which calls a create method
            SemanticTableauxElement.ResetReplacementVariables();
            Head = new SemanticTableauxElement(propositions);
        }
Пример #4
0
        private void ApplyAlphaRule(Proposition proposition)
        {
            HashSet <Proposition> childPropositions = new HashSet <Proposition>();

            foreach (Proposition p in Propositions)
            {
                if (!p.Equals(proposition))
                {
                    childPropositions.Add(p);
                }
            }

            if (proposition.GetType() == typeof(Conjunction))
            {
                BinaryConnective connective = (BinaryConnective)proposition;

                childPropositions.Add(connective.LeftSuccessor);
                childPropositions.Add(connective.RightSuccessor);
            }

            if (proposition.GetType() == typeof(Negation))
            {
                Negation         negation         = (Negation)proposition;
                BinaryConnective nestedConnective = (BinaryConnective)negation.LeftSuccessor;

                if (nestedConnective.GetType() != typeof(Nand))
                {
                    // Both cases have a negation of the right successor.
                    Negation negatedRight = new Negation();
                    negatedRight.LeftSuccessor = nestedConnective.RightSuccessor;

                    // Only disjunction results in a left side negated as well.
                    if (nestedConnective.GetType() == typeof(Disjunction))
                    {
                        Negation negatedLeft = new Negation();
                        negatedLeft.LeftSuccessor = nestedConnective.LeftSuccessor;

                        childPropositions.Add(negatedLeft);
                    }

                    // Should not forget to add the implication's left successor
                    if (nestedConnective.GetType() == typeof(Implication))
                    {
                        childPropositions.Add(nestedConnective.LeftSuccessor);
                    }

                    childPropositions.Add(negatedRight);
                }
                else
                {
                    // It's a negated Nand and we can add left and right to the set
                    childPropositions.Add(nestedConnective.LeftSuccessor);
                    childPropositions.Add(nestedConnective.RightSuccessor);
                }
            }

            LeftChild = new SemanticTableauxElement(childPropositions, new HashSet <char>(ReplacementVariables));
        }
Пример #5
0
        private void ApplyDeltaRule(Proposition proposition)
        {
            // COULD BE: GetAllDifferingChildPropositions(proposition)
            // REFACTOR WORTHY: otherwise needs to be tested for every rule which is all the same
            HashSet <Proposition> childPropositions = new HashSet <Proposition>();

            foreach (Proposition p in Propositions)
            {
                if (!p.Equals(proposition))
                {
                    childPropositions.Add(p);
                }
            }
            // REFACTOR WORTHY

            // Current proposition we want to break up again into new pieces.
            Quantifier  quantifier = null;
            Proposition predicate  = null;

            if (proposition.GetType() == typeof(Negation))
            {
                Negation negatedUniversalQuantifier = (Negation)proposition;
                quantifier = (Quantifier)negatedUniversalQuantifier.LeftSuccessor;

                predicate = quantifier.LeftSuccessor;
                Negation negatedPredicate = new Negation();
                negatedPredicate.LeftSuccessor = predicate;

                predicate = negatedPredicate;
            }
            else
            {
                quantifier = (Quantifier)proposition;
                predicate  = quantifier.LeftSuccessor;
            }

            char boundVariable        = quantifier.GetBoundVariable();
            char replacementCharacter = GenerateReplacementVariable();

            Proposition predicateCopy = predicate.Copy();

            predicateCopy.Replace(boundVariable, replacementCharacter);

            // Get current set locally, add new variable and pass them down.
            HashSet <char> childReplacementVariables = new HashSet <char>(ReplacementVariables);

            childReplacementVariables.Add(replacementCharacter);

            childPropositions.Add(predicateCopy);

            LeftChild = new SemanticTableauxElement(childPropositions, childReplacementVariables);
        }
Пример #6
0
        private void ApplyBetaRule(Proposition proposition)
        {
            HashSet <Proposition> leftChildPropositions  = new HashSet <Proposition>();
            HashSet <Proposition> rightChildPropositions = new HashSet <Proposition>();

            Proposition leftSetProposition = null;
            Proposition rightSetPropostion = null;

            foreach (Proposition p in Propositions)
            {
                if (!p.Equals(proposition))
                {
                    // Add copies to the set for all other propositions
                    // ensuring that each quantifier will at least be unique.
                    leftChildPropositions.Add(p.Copy());
                    rightChildPropositions.Add(p.Copy());
                }
            }

            BinaryConnective connective = null;

            if (proposition.GetType() == typeof(Negation) || proposition.GetType() == typeof(Nand))
            {
                Negation leftNegation  = new Negation();
                Negation rightNegation = new Negation();

                // Possibly Not and or Not bi-implication
                if (proposition.GetType() == typeof(Negation))
                {
                    Negation negation = (Negation)proposition;
                    connective = (BinaryConnective)negation.LeftSuccessor;

                    // If Bi-Implication
                    if (connective.GetType() == typeof(BiImplication))
                    {
                        leftChildPropositions.Add(connective.LeftSuccessor);
                        leftNegation.LeftSuccessor = connective.RightSuccessor;

                        rightChildPropositions.Add(connective.RightSuccessor);
                        rightNegation.LeftSuccessor = connective.LeftSuccessor;
                    }
                    else
                    {
                        // If And
                        leftNegation.LeftSuccessor  = connective.LeftSuccessor;
                        rightNegation.LeftSuccessor = connective.RightSuccessor;
                    }
                }
                else
                {
                    // If Nand
                    connective = (BinaryConnective)proposition;

                    leftNegation.LeftSuccessor  = connective.LeftSuccessor;
                    rightNegation.LeftSuccessor = connective.RightSuccessor;
                }

                leftSetProposition = leftNegation;
                rightSetPropostion = rightNegation;
            }

            if (proposition.GetType() == typeof(Disjunction))
            {
                connective = (BinaryConnective)proposition;

                leftSetProposition = connective.LeftSuccessor;
                rightSetPropostion = connective.RightSuccessor;
            }

            if (proposition.GetType() == typeof(Implication))
            {
                Negation leftNegation = new Negation();
                connective = (BinaryConnective)proposition;

                leftNegation.LeftSuccessor = connective.LeftSuccessor;

                leftSetProposition = leftNegation;
                rightSetPropostion = connective.RightSuccessor;
            }

            if (proposition.GetType() == typeof(BiImplication))
            {
                connective = (BinaryConnective)proposition;

                Negation leftNegated = new Negation();
                leftNegated.LeftSuccessor = connective.LeftSuccessor;

                Negation rightNegated = new Negation();
                rightNegated.LeftSuccessor = connective.RightSuccessor;

                // First add the left part of the bi-implication to both left and right branch
                // sets
                leftChildPropositions.Add(connective.LeftSuccessor);
                rightChildPropositions.Add(leftNegated);

                // Then the right part to keep a certain order.
                leftSetProposition = connective.RightSuccessor;
                rightSetPropostion = rightNegated;
            }

            leftChildPropositions.Add(leftSetProposition);
            rightChildPropositions.Add(rightSetPropostion);

            LeftChild  = new SemanticTableauxElement(leftChildPropositions, new HashSet <char>(ReplacementVariables));
            RightChild = new SemanticTableauxElement(rightChildPropositions, new HashSet <char>(ReplacementVariables));
        }
Пример #7
0
        // Both, just the ordering is different and for predicates we
        // have two additional rules that should be placed in between.
        protected void CreateChildren()
        {
            bool childCreated = false;

            foreach (Proposition proposition in Propositions)
            {
                childCreated = TryToCreateDoubleNegation(proposition);

                if (childCreated)
                {
                    return;
                }
            }

            foreach (Proposition proposition in Propositions)
            {
                childCreated = TryToCreateAlphaRule(proposition);

                if (childCreated)
                {
                    return;
                }
            }

            foreach (Proposition proposition in Propositions)
            {
                childCreated = TryToCreateDeltaRule(proposition);

                if (childCreated)
                {
                    return;
                }
            }

            foreach (Proposition proposition in Propositions)
            {
                childCreated = TryToCreateBetaRule(proposition);

                if (childCreated)
                {
                    return;
                }
            }

            HashSet <Proposition> childPropositionSet = new HashSet <Proposition>();

            foreach (Proposition proposition in Propositions)
            {
                if (IsGammaRule(proposition))
                {
                    foreach (Proposition p in ApplyGammaRule(proposition))
                    {
                        childPropositionSet.Add(p);
                    }
                }
            }

            if (childPropositionSet.Count > Propositions.Count)
            {
                LeftChild = new SemanticTableauxElement(childPropositionSet, ReplacementVariables);

                return;
            }
        }