2021-05-06 12:44:29 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
# IMPORTS
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
from __future__ import annotations;
|
|
|
|
from lark import Tree;
|
|
|
|
from typing import List;
|
|
|
|
|
2021-05-06 15:29:44 +02:00
|
|
|
from aussagenlogik.schema import isAtom;
|
|
|
|
from aussagenlogik.schema import isBeliebig;
|
|
|
|
from aussagenlogik.schema import isTrueSymbol;
|
|
|
|
from aussagenlogik.schema import isFalseSymbol;
|
|
|
|
from aussagenlogik.schema import isNegation;
|
|
|
|
from aussagenlogik.schema import isConjunction;
|
|
|
|
from aussagenlogik.schema import isDisjunction;
|
|
|
|
from aussagenlogik.schema import isImplication;
|
|
|
|
from aussagenlogik.schema import getTeilformeln;
|
|
|
|
from aussagenlogik.schema import getName;
|
|
|
|
|
2021-05-06 12:44:29 +02:00
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
# GLOBALE KONSTANTEN
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
# METHODEN
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
2021-05-06 15:29:44 +02:00
|
|
|
def rekursiv_eval(fml: Tree, I: List[str]) -> int:
|
|
|
|
teilfml = getTeilformeln(fml);
|
|
|
|
if isAtom(fml):
|
|
|
|
name = getName(fml);
|
|
|
|
return 1 if (name in I) else 0;
|
|
|
|
if isBeliebig(fml):
|
|
|
|
name = getName(fml);
|
|
|
|
return 1 if (name in I) else 0;
|
|
|
|
elif isTrueSymbol(fml):
|
|
|
|
return 1;
|
|
|
|
elif isFalseSymbol(fml):
|
|
|
|
return 0;
|
|
|
|
elif isNegation(fml):
|
|
|
|
val0 = rekursiv_eval(teilfml[0], I);
|
|
|
|
return 1 - val0;
|
|
|
|
elif isConjunction(fml):
|
|
|
|
val0 = rekursiv_eval(teilfml[0], I);
|
|
|
|
val1 = rekursiv_eval(teilfml[1], I);
|
|
|
|
return min(val0, val1);
|
|
|
|
elif isDisjunction(fml):
|
|
|
|
val0 = rekursiv_eval(teilfml[0], I);
|
|
|
|
val1 = rekursiv_eval(teilfml[1], I);
|
|
|
|
return max(val0, val1);
|
|
|
|
elif isImplication(fml):
|
|
|
|
val0 = rekursiv_eval(teilfml[0], I);
|
|
|
|
val1 = rekursiv_eval(teilfml[1], I);
|
|
|
|
return 0 if val0 == 1 and val1 == 0 else 1;
|
|
|
|
raise Exception('Evaluation nicht möglich!');
|
|
|
|
|
2021-05-06 12:44:29 +02:00
|
|
|
def rekursiv_atoms(fml: Tree) -> List[str]:
|
|
|
|
## Herausforderung: schreibe diese Funktion!
|
|
|
|
return [];
|
|
|
|
|
|
|
|
def rekursiv_depth(fml: Tree) -> int:
|
|
|
|
## Herausforderung: schreibe diese Funktion!
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
def rekursiv_length(fml: Tree) -> int:
|
|
|
|
## Herausforderung: schreibe diese Funktion!
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
def rekursiv_parentheses(fml: Tree) -> int:
|
|
|
|
## Herausforderung: schreibe diese Funktion!
|
|
|
|
return 0
|