예제 #1
0
        public object visitNotSentence(NotSentence notSentence, object arg)
        {
            // CNF requires NOT (~) to appear only in literals, so we 'move ~
            // inwards' by repeated application of the following equivalences:
            Sentence negated = notSentence.getNegated();

            // ~(~alpha) equivalent to alpha (double negation elimination)
            if (negated is NotSentence)
            {
                return(((NotSentence)negated).getNegated().accept(this, arg));
            }

            if (negated is ConnectedSentence)
            {
                ConnectedSentence negConnected = (ConnectedSentence)negated;
                Sentence          alpha        = negConnected.getFirst();
                Sentence          beta         = negConnected.getSecond();
                // ~(alpha ^ beta) equivalent to (~alpha V ~beta) (De Morgan)
                if (Connectors.isAND(negConnected.getConnector()))
                {
                    // I need to ensure the ~s are moved in deeper
                    Sentence notAlpha = (Sentence)(new NotSentence(alpha)).accept(this, arg);
                    Sentence notBeta  = (Sentence)(new NotSentence(beta)).accept(this, arg);
                    return(new ConnectedSentence(Connectors.OR, notAlpha, notBeta));
                }

                // ~(alpha V beta) equivalent to (~alpha ^ ~beta) (De Morgan)
                if (Connectors.isOR(negConnected.getConnector()))
                {
                    // I need to ensure the ~s are moved in deeper
                    Sentence notAlpha = (Sentence)(new NotSentence(alpha)).accept(this, arg);
                    Sentence notBeta  = (Sentence)(new NotSentence(beta)).accept(this, arg);
                    return(new ConnectedSentence(Connectors.AND, notAlpha, notBeta));
                }
            }

            // in addition, rules for negated quantifiers:
            if (negated is QuantifiedSentence)
            {
                QuantifiedSentence negQuantified = (QuantifiedSentence)negated;
                // I need to ensure the ~ is moved in deeper
                Sentence notP = (Sentence)(new NotSentence(negQuantified.getQuantified())).accept(this, arg);

                // ~FORALL x p becomes EXISTS x ~p
                if (Quantifiers.isFORALL(negQuantified.getQuantifier()))
                {
                    return(new QuantifiedSentence(Quantifiers.EXISTS, negQuantified.getVariables(), notP));
                }

                // ~EXISTS x p becomes FORALL x ~p
                if (Quantifiers.isEXISTS(negQuantified.getQuantifier()))
                {
                    return(new QuantifiedSentence(Quantifiers.FORALL, negQuantified.getVariables(), notP));
                }
            }

            return(new NotSentence((Sentence)negated.accept(this, arg)));
        }
예제 #2
0
        public void testNotSentence()
        {
            NotSentence ns = (NotSentence)parser
                             .parse("NOT BrotherOf(John) = EnemyOf(Saladin)");

            Assert.AreEqual(ns.getNegated().ToString(), (new TermEquality(
                                                             getBrotherOfFunction(new Constant("John")),
                                                             getEnemyOfFunction())).ToString());
        }
예제 #3
0
        public Object visitNotSentence(NotSentence sentence, Object arg)
        {
            ArgData ad = (ArgData)arg;

            // Indicate that the enclosed predicate is negated
            ad.negated = true;
            sentence.getNegated().accept(this, arg);
            ad.negated = false;

            return(sentence);
        }
예제 #4
0
 public object visitNotSentence(NotSentence sentence, object arg)
 {
     sentence.getNegated().accept(this, arg);
     return(sentence);
 }
예제 #5
0
 public Object visitNotSentence(NotSentence sentence, Object arg)
 {
     return(new NotSentence((Sentence)sentence.getNegated().accept(this,
                                                                   arg)));
 }
예제 #6
0
        public Object visitNotSentence(NotSentence notSentence, Object arg)
        {
            Sentence negated = notSentence.getNegated();

            return(new NotSentence((Sentence)negated.accept(this, arg)));
        }