@Override
 public Sequence[] expand(Sequence sigma) {
   if (!isEvaluated()) {
     throw new LogicalException("Can't expand not evaluated implication!");
   }
   if (value == LogicalValue.TRUE) {
     Sequence firstBranch = new Sequence(sigma);
     Formula newLeft = left.clone();
     newLeft.setValue(LogicalValue.FALSE);
     firstBranch.addFront(newLeft);
     Sequence secondBranch = new Sequence(sigma);
     Formula newRight = right.clone();
     newRight.setValue(LogicalValue.TRUE);
     secondBranch.addFront(newRight);
     return new Sequence[] {firstBranch, secondBranch};
   } else {
     Sequence resultSequence = new Sequence(sigma);
     Formula newRight = right.clone();
     newRight.setValue(LogicalValue.FALSE);
     resultSequence.addFront(newRight);
     Formula newLeft = left.clone();
     newLeft.setValue(LogicalValue.TRUE);
     resultSequence.addFront(newLeft);
     return new Sequence[] {resultSequence};
   }
 }
Example #2
0
 public void run() {
   Tokenizer tokenizer = new Tokenizer(input);
   tokenizer.run();
   InfixToPostfixConverter converter = new InfixToPostfixConverter(tokenizer.getLexemes());
   converter.run();
   FormulaGenerator generator = new FormulaGenerator(converter.getRPN());
   generator.run();
   formula = generator.getFormula();
   formula.setValue(LogicalValue.FALSE);
 }