Subato

Resource Files

Aussagenlogische Formel Implikation Umformen

In dieser Aufgabe verwenden wir einige Preview Fetures aus Java 15.

Gegeben sei ein Datentyp für aussagenlogische Formeln.

package name.panitz.util;
public interface Logic{
  static record Var(String n) implements Logic{}
  static record Neg(Logic f) implements Logic{}
  static record Implication(Logic l,Logic r) implements Logic{}
  static record And(Logic l,Logic r) implements Logic{}
  static record Or(Logic l,Logic r) implements Logic{}
}

Für die Abgabe und die bessere Lesbarkeit der Formeln wurde die Methode toString in der Lösungsvorlage überschrieben.

Ebenso wurden Methoden zur einfachen Konstruktion von Formeln hinzu gefügt.

Vervollständigen Sie die Methode, die in einer Formel alle Implikation umwandeln soll in eine Disjunktion nach der bekannten Umformung:

  • (A → B) wird zu (¬A ∨ B).

Hierzu müssen Sie rekursiv in alle Teilformeln von this absteigen, also eine Rekursion auf die Teilformeln machen.


package name.panitz.util; import java.util.Map; public interface Logic{ static record Var(String n) implements Logic{ public String toString(){return n;} } static record Neg(Logic f) implements Logic{ public String toString(){return "¬"+f;} } static record Implication(Logic l,Logic r) implements Logic{ public String toString(){return "("+l+"→"+r+")";} } static record And(Logic l,Logic r) implements Logic{ public String toString(){return "("+l+"∧"+r+")";} } static record Or(Logic l,Logic r) implements Logic{ public String toString(){return "("+l+"∨"+r+")";} } default Logic transformImplications(){ if (this instanceof Var v) return v; if (this instanceof Neg n) return new Neg(n.f.transformImplications()); //TODO remaining cases throw new RuntimeException("unhandled Logic class case: "+this); } //utility function for easy creation default Logic and(Logic that){return new And(this,that);} default Logic or(Logic that){return new Or(this,that);} default Logic implication(Logic that){return new Implication(this,that);} default Logic neg(){return new Neg(this);} }
java
You are not logged in and therefore you cannot submit a solution.