Esempio n. 1
0
        private Proposition GenerateExpressionRecursively(Proposition result, int level)
        {
            if (!(result is UnaryConnective))
            {
                return(result);
            }

            int newLevel = level + 1;

            if (level >= 5)
            {
                newLevel = level + 4;
            }

            if (result is UnaryConnective)
            {
                // Generate a random left
                UnaryConnective connective = (UnaryConnective)result;
                connective.LeftSuccessor = GenerateProposition(level);

                GenerateExpressionRecursively(connective.LeftSuccessor, newLevel);
            }

            if (result is BinaryConnective)
            {
                // Generate a random right
                BinaryConnective connective = (BinaryConnective)result;
                connective.RightSuccessor = GenerateProposition(level);

                GenerateExpressionRecursively(connective.RightSuccessor, newLevel);
            }

            return(result);
        }
Esempio n. 2
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));
        }
Esempio n. 3
0
        public override bool Equals(object obj)
        {
            if (!base.Equals(obj))
            {
                return(false);
            }
            if (GetType() != obj.GetType())
            {
                return(false);
            }

            BinaryConnective binaryConnective = (BinaryConnective)obj;

            return(binaryConnective.RightSuccessor.Equals(RightSuccessor));
        }
Esempio n. 4
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));
        }