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 ArgumentException("Sentence is not in CNF: " + s); //IllegalArgumentException } return(arg); }
// No hace falta override porque PLVisitor es una interfaz public bool?VisitBinarySentence(ComplexSentence bs, bool?arg) { bool? firstValue = (bool?)bs.GetSimplerSentence(0).Accept(this, null); bool? secondValue = (bool?)bs.GetSimplerSentence(1).Accept(this, null); bool bothValuesKnown = firstValue != null && secondValue != null; Connective connective = bs.GetConnective(); // He reprogramado todo esto if (connective.Equals(Connective.AND)) { if (firstValue.Equals(false) || secondValue.Equals(false)) { return(false); } else if (bothValuesKnown) { return(true); // Si no se cumple, saldrá como null } } else if (connective.Equals(Connective.OR)) { if (firstValue.Equals(true) || secondValue.Equals(true)) { return(true); } else if (bothValuesKnown) { return(false); // Si no se cumple, saldrá como null } } else if (connective.Equals(Connective.IMPLICATION)) { if (firstValue.Equals(false) || secondValue.Equals(true)) { return(true); } else if (bothValuesKnown) { return(false); // Si no se cumple, saldrá como null } } else if (connective.Equals(Connective.BICONDITIONAL)) { if (bothValuesKnown) { return(firstValue.Equals(secondValue)); // Si no se cumple, saldrá como null } } return(null); }
public override ISet <Literal> VisitUnarySentence(ComplexSentence s, ISet <Literal> arg) { if (!s.GetSimplerSentence(0).IsPropositionSymbol()) { throw new InvalidOperationException("Sentence is not in CNF: " + s); //IllegalStateException } // un literal negativo Literal negativeLiteral = new Literal((PropositionSymbol)s.GetSimplerSentence(0), false); arg.Add(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()) { IList <Literal> literals = new List <Literal>(LiteralCollector.getLiterals(s)); //ArrayList arg.Add(new Clause(literals)); } else { throw new ArgumentException("Sentence is not in CNF: " + s); //IllegalArgumentException } return(arg); }
public override Sentence VisitBinarySentence(ComplexSentence s, object arg) { Sentence result = null; if (s.IsImplicationSentence()) { // Elimina =>, reemplazando & alpha; => β< br > con ~α | β 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); }
// No hace falta override porque PLVisitor es una interfaz 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()) { // Elimina <=>, reemplazando α <=> β con (α => β) & (β => α) 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()) { // Ya se ha movido completamente result = s; } else if (negated.IsNotSentence()) { // ~(~α) ≡ α (eliminación de la doble negación) 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); // Esto asegura que la eliminación de la doble negación sucede 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 ArgumentException( //IllegalArgumentException "Biconditionals and Implications should not exist in input: " + s); } return(result); }
// No hace falta override porque PLVisitor es una interfaz, pero pongo virtual por si queremos seguir sobreescribiendo public virtual Sentence VisitBinarySentence(ComplexSentence s, A arg) { // Una nueva sentencia compleja con la misma conectiva pero posiblemente con sus sentencias más simples reemplazadas por el visitante. return(new ComplexSentence(s.GetConnective(), s.GetSimplerSentence(0).Accept(this, arg), s.GetSimplerSentence(1).Accept(this, arg))); }
// Es virtual por si hace falta sobreescribirlo 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)); }
// Es virtual por si hace falta sobreescribirlo public virtual ISet <T> VisitUnarySentence(ComplexSentence s, ISet <T> arg) { return(SetOps.Union(arg, s.GetSimplerSentence(0).Accept(this, arg))); }
public override Sentence VisitBinarySentence(ComplexSentence s, object arg) { Sentence result = null; if (s.IsOrSentence()) { Sentence s1 = s.GetSimplerSentence(0).Accept(this, arg); Sentence s2 = s.GetSimplerSentence(1).Accept(this, arg); if (s1.IsAndSentence() || s2.IsAndSentence()) { Sentence alpha, betaAndGamma; if (s2.IsAndSentence()) { // (α | (β & γ)) // Nota: incluso si ambos son sentencias 'and' preferiremos usar s2 alpha = s1; betaAndGamma = s2; } else { // Nota: Hace falta manejar este caso también // ((β & γ) | α) alpha = s2; betaAndGamma = s1; } Sentence beta = betaAndGamma.GetSimplerSentence(0); Sentence gamma = betaAndGamma.GetSimplerSentence(1); if (s2.IsAndSentence()) { // ((α | β) & (α | γ)) Sentence alphaOrBeta = (new ComplexSentence(Connective.OR, alpha, beta)).Accept(this, null); Sentence alphaOrGamma = (new ComplexSentence(Connective.OR, alpha, gamma)).Accept(this, null); result = new ComplexSentence(Connective.AND, alphaOrBeta, alphaOrGamma); } else { // ((β | α) & (γ | α)) Sentence betaOrAlpha = (new ComplexSentence(Connective.OR, beta, alpha)).Accept(this, null); Sentence gammaOrAlpha = (new ComplexSentence(Connective.OR, gamma, alpha)).Accept(this, null); result = new ComplexSentence(Connective.AND, betaOrAlpha, gammaOrAlpha); } } else { result = new ComplexSentence(Connective.OR, s1, s2); } } else { result = base.VisitBinarySentence(s, arg); } return(result); }