00001 package edu.tum.cs.logic; 00002 00003 import edu.tum.cs.srl.Database; 00004 00005 import java.util.Collection; 00006 00007 public class Implication extends ComplexFormula { 00008 public Implication(Collection<Formula> c) throws Exception { 00009 super(c); 00010 if(c.size() != 2) 00011 throw new Exception("An implication must have exactly two children (antecedent and consequent)."); 00012 } 00013 00014 public Implication(Formula antecedent, Formula consequent) { 00015 super(new Formula[]{antecedent, consequent}); 00016 } 00017 00018 public String toString() { 00019 return "(" + children[0] + " => " + children[1] + ")"; 00020 } 00021 00022 @Override 00023 public boolean isTrue(IPossibleWorld w) { 00024 return !children[0].isTrue(w) || children[1].isTrue(w); 00025 } 00026 00027 @Override 00028 public Formula toCNF() { 00029 return new Disjunction(new Negation(children[0]), children[1]).toCNF(); 00030 } 00031 00032 @Override 00033 public Formula toNNF() { 00034 return new Disjunction(new Negation(children[0]), children[1]).toNNF(); 00035 } 00036 00037 @Override 00038 public Formula simplify(Database evidence) { 00039 return (new Disjunction(new Negation(children[0]), children[1])).simplify(evidence); 00040 } 00041 }