Exemplo n.º 1
0
 public virtual Sentence visitBinarySentence(ComplexSentence s, A arg)
 {
     // a new Complex Sentence with the same connective but possibly
     // with its simpler sentences replaced by the visitor.
     return(new ComplexSentence(s.getConnective(), s.getSimplerSentence(0)
                                .accept(this, arg), s.getSimplerSentence(1).accept(this, arg)));
 }
Exemplo n.º 2
0
        public bool?visitBinarySentence(ComplexSentence bs, bool?arg)
        {
            bool?firstValue  = bs.getSimplerSentence(0).accept(this, null);
            bool?secondValue = bs.getSimplerSentence(1).accept(this, null);

            if ((firstValue == null) || (secondValue == null))
            {
                // strictly not true for or/and
                // -FIX later
                return(null);
            }
            else
            {
                Connective connective = bs.getConnective();
                if (connective.Equals(Connective.AND))
                {
                    return(firstValue.Value && secondValue.Value);
                }
                else if (connective.Equals(Connective.OR))
                {
                    return(firstValue.Value || secondValue.Value);
                }
                else if (connective.Equals(Connective.IMPLICATION))
                {
                    return(!(firstValue.Value && !secondValue.Value));
                }
                else if (connective.Equals(Connective.BICONDITIONAL))
                {
                    return(firstValue.Equals(secondValue));
                }
                return(null);
            }
        }
Exemplo n.º 3
0
        public virtual ISet <T> visitBinarySentence(ComplexSentence s, ISet <T> arg)
        {
            ISet <T> termunion = SetOps.union(
                s.getSimplerSentence(0).accept(this, arg), s
                .getSimplerSentence(1).accept(this, arg));

            return(SetOps.union(arg, termunion));
        }
Exemplo n.º 4
0
 public override ISet <Literal> visitBinarySentence(ComplexSentence s, ISet <Literal> arg)
 {
     if (s.isOrSentence())
     {
         s.getSimplerSentence(0).accept(this, arg);
         s.getSimplerSentence(1).accept(this, arg);
     }
     else
     {
         throw new IllegalArgumentException("Sentence is not in CNF: " + s);
     }
     return(arg);
 }
Exemplo n.º 5
0
        public override ISet <Clause> visitUnarySentence(ComplexSentence s, ISet <Clause> arg)
        {
            if (!s.getSimplerSentence(0).isPropositionSymbol())
            {
                throw new IllegalStateException("Sentence is not in CNF: " + s);
            }

            // a negative unit clause
            Literal negativeLiteral = new Literal((PropositionSymbol)s.getSimplerSentence(0), false);

            arg.Add(new Clause(negativeLiteral));

            return(arg);
        }
Exemplo n.º 6
0
        public override ISet <Clause> visitBinarySentence(ComplexSentence s, ISet <Clause> arg)
        {
            if (s.isAndSentence())
            {
                s.getSimplerSentence(0).accept(this, arg);
                s.getSimplerSentence(1).accept(this, arg);
            }
            else if (s.isOrSentence())
            {
                ICollection <Literal> literals = CollectionFactory.CreateQueue <Literal>(LiteralCollector.getLiterals(s));
                arg.Add(new Clause(literals));
            }
            else
            {
                throw new IllegalArgumentException("Sentence is not in CNF: " + s);
            }

            return(arg);
        }
Exemplo n.º 7
0
        public override Sentence visitBinarySentence(ComplexSentence s, object arg)
        {
            Sentence result = null;

            if (s.isImplicationSentence())
            {
                // Eliminate =>, replacing &alpha; => &beta;
                // with ~&alpha; | &beta;
                Sentence alpha    = s.getSimplerSentence(0).accept(this, arg);
                Sentence beta     = s.getSimplerSentence(1).accept(this, arg);
                Sentence notAlpha = new ComplexSentence(Connective.NOT, alpha);

                result = new ComplexSentence(Connective.OR, notAlpha, beta);
            }
            else
            {
                result = base.visitBinarySentence(s, arg);
            }
            return(result);
        }
Exemplo n.º 8
0
        public bool?visitUnarySentence(ComplexSentence fs, bool?arg)
        {
            object negatedValue = fs.getSimplerSentence(0).accept(this, null);

            if (negatedValue != null)
            {
                return(!((bool)negatedValue));
            }
            else
            {
                return(null);
            }
        }
        public override Sentence visitBinarySentence(ComplexSentence s, object arg)
        {
            Sentence result = null;
            if (s.isBiconditionalSentence())
            {
                // Eliminate <=>, replace &alpha; <=> &beta;
                // with (&alpha; => &beta;) & (&beta; => &alpha;)
                Sentence alpha = s.getSimplerSentence(0).accept(this, arg);
                Sentence beta = s.getSimplerSentence(1).accept(this, arg);
                Sentence alphaImpliesBeta = new ComplexSentence(
                        Connective.IMPLICATION, alpha, beta);
                Sentence betaImpliesAlpha = new ComplexSentence(
                        Connective.IMPLICATION, beta, alpha);

                result = new ComplexSentence(Connective.AND, alphaImpliesBeta,
                        betaImpliesAlpha);
            }
            else
            {
                result = base.visitBinarySentence(s, arg);
            }
            return result;
        }
Exemplo n.º 10
0
        public override Sentence visitUnarySentence(ComplexSentence s, object arg)
        {
            Sentence result = null;

            Sentence negated = s.getSimplerSentence(0);

            if (negated.isPropositionSymbol())
            {
                // Already moved in fully
                result = s;
            }
            else if (negated.isNotSentence())
            {
                // ~(~&alpha;) &equiv; &alpha; (double-negation elimination)
                Sentence alpha = negated.getSimplerSentence(0);
                result = alpha.accept(this, arg);
            }
            else if (negated.isAndSentence() || negated.isOrSentence())
            {
                Sentence alpha = negated.getSimplerSentence(0);
                Sentence beta  = negated.getSimplerSentence(1);

                // This ensures double-negation elimination happens
                Sentence notAlpha = (new ComplexSentence(Connective.NOT, alpha)).accept(this, null);
                Sentence notBeta  = (new ComplexSentence(Connective.NOT, beta)).accept(this, null);
                if (negated.isAndSentence())
                {
                    // ~(&alpha; & &beta;) &equiv; (~&alpha; | ~&beta;) (De Morgan)
                    result = new ComplexSentence(Connective.OR, notAlpha, notBeta);
                }
                else
                {
                    // ~(&alpha; | &beta;) &equiv; (~&alpha; & ~&beta;) (De Morgan)
                    result = new ComplexSentence(Connective.AND, notAlpha, notBeta);
                }
            }
            else
            {
                throw new IllegalArgumentException("Biconditionals and Implications should not exist in input: " + s);
            }

            return(result);
        }
Exemplo n.º 11
0
        public override Sentence visitBinarySentence(ComplexSentence s, object arg)
        {
            Sentence result = null;

            if (s.isAndSentence())
            {
                Sentence s1 = s.getSimplerSentence(0).accept(this, arg);
                Sentence s2 = s.getSimplerSentence(1).accept(this, arg);
                if (s1.isOrSentence() || s2.isOrSentence())
                {
                    Sentence alpha, betaAndGamma;
                    if (s2.isOrSentence())
                    {
                        // (&alpha; & (&beta; | &gamma;))
                        // Note: even if both are 'or' sentence
                        // we will prefer to use s2
                        alpha        = s1;
                        betaAndGamma = s2;
                    }
                    else
                    {
                        // Note: Need to handle this case too
                        // ((&beta; | &gamma;) & &alpha;)
                        alpha        = s2;
                        betaAndGamma = s1;
                    }

                    Sentence beta  = betaAndGamma.getSimplerSentence(0);
                    Sentence gamma = betaAndGamma.getSimplerSentence(1);

                    if (s2.isOrSentence())
                    {
                        // ((&alpha; & &beta;) | (&alpha; & &gamma;))
                        Sentence alphaAndBeta = (new ComplexSentence(Connective.AND,
                                                                     alpha, beta)).accept(this, null);
                        Sentence alphaAndGamma = (new ComplexSentence(Connective.AND,
                                                                      alpha, gamma)).accept(this, null);

                        result = new ComplexSentence(Connective.OR, alphaAndBeta,
                                                     alphaAndGamma);
                    }
                    else
                    {
                        // ((&beta; & &alpha;) | (&gamma; & &alpha;))
                        Sentence betaAndAlpha = (new ComplexSentence(Connective.AND,
                                                                     beta, alpha)).accept(this, null);
                        Sentence gammaAndAlpha = (new ComplexSentence(Connective.AND,
                                                                      gamma, alpha)).accept(this, null);

                        result = new ComplexSentence(Connective.OR, betaAndAlpha,
                                                     gammaAndAlpha);
                    }
                }
                else
                {
                    result = new ComplexSentence(Connective.AND, s1, s2);
                }
            }
            else
            {
                result = base.visitBinarySentence(s, arg);
            }

            return(result);
        }
Exemplo n.º 12
0
 public virtual ISet <T> visitUnarySentence(ComplexSentence s, ISet <T> arg)
 {
     return(SetOps.union(arg, s.getSimplerSentence(0).accept(this, arg)));
 }