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))); }
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); } }
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)); }
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); }
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); }
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); }
public override Sentence visitBinarySentence(ComplexSentence s, object arg) { Sentence result = null; if (s.isImplicationSentence()) { // Eliminate =>, replacing α => β // with ~α | β 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); }
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 α <=> β // with (α => β) & (β => α) 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; }
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()) { // ~(~α) ≡ α (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()) { // ~(α & β) ≡ (~α | ~β) (De Morgan) result = new ComplexSentence(Connective.OR, notAlpha, notBeta); } else { // ~(α | β) ≡ (~α & ~β) (De Morgan) result = new ComplexSentence(Connective.AND, notAlpha, notBeta); } } else { throw new IllegalArgumentException("Biconditionals and Implications should not exist in input: " + s); } return(result); }
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()) { // (α & (β | γ)) // 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 // ((β | γ) & α) alpha = s2; betaAndGamma = s1; } Sentence beta = betaAndGamma.getSimplerSentence(0); Sentence gamma = betaAndGamma.getSimplerSentence(1); if (s2.isOrSentence()) { // ((α & β) | (α & γ)) 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 { // ((β & α) | (γ & α)) 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); }
public virtual ISet <T> visitUnarySentence(ComplexSentence s, ISet <T> arg) { return(SetOps.union(arg, s.getSimplerSentence(0).accept(this, arg))); }