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