2021-05-06 12:44:29 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
# IMPORTS
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
2021-05-06 23:34:25 +02:00
|
|
|
from __future__ import annotations
|
2021-05-06 12:44:29 +02:00
|
|
|
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;
|
2021-05-06 23:34:25 +02:00
|
|
|
from aussagenlogik.schema import isLongConjunction;
|
2021-05-06 15:29:44 +02:00
|
|
|
from aussagenlogik.schema import isDisjunction;
|
2021-05-06 23:34:25 +02:00
|
|
|
from aussagenlogik.schema import isLongDisjunction;
|
2021-05-06 15:29:44 +02:00
|
|
|
from aussagenlogik.schema import isImplication;
|
|
|
|
from aussagenlogik.schema import getName;
|
2021-05-06 23:34:25 +02:00
|
|
|
from aussagenlogik.schema import SyntaxBaum;
|
2021-05-06 15:29:44 +02:00
|
|
|
|
2021-05-06 12:44:29 +02:00
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
# GLOBALE KONSTANTEN
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
# METHODEN
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
2021-05-06 23:34:25 +02:00
|
|
|
def rekursiv_eval(fml: SyntaxBaum, I: List[str]) -> int:
|
|
|
|
subfml = fml.children;
|
2021-05-06 15:29:44 +02:00
|
|
|
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):
|
2021-05-06 23:34:25 +02:00
|
|
|
val0 = rekursiv_eval(subfml[0], I);
|
2021-05-06 15:29:44 +02:00
|
|
|
return 1 - val0;
|
|
|
|
elif isConjunction(fml):
|
2021-05-06 23:34:25 +02:00
|
|
|
val0 = rekursiv_eval(subfml[0], I);
|
|
|
|
val1 = rekursiv_eval(subfml[1], I);
|
2021-05-06 15:29:44 +02:00
|
|
|
return min(val0, val1);
|
2021-05-06 23:34:25 +02:00
|
|
|
elif isLongConjunction(fml):
|
|
|
|
values = [rekursiv_eval(t, I) for t in subfml];
|
|
|
|
return min(values);
|
2021-05-06 15:29:44 +02:00
|
|
|
elif isDisjunction(fml):
|
2021-05-06 23:34:25 +02:00
|
|
|
val0 = rekursiv_eval(subfml[0], I);
|
|
|
|
val1 = rekursiv_eval(subfml[1], I);
|
2021-05-06 15:29:44 +02:00
|
|
|
return max(val0, val1);
|
2021-05-06 23:34:25 +02:00
|
|
|
elif isLongDisjunction(fml):
|
|
|
|
values = [rekursiv_eval(t, I) for t in subfml];
|
|
|
|
return max(values);
|
2021-05-06 15:29:44 +02:00
|
|
|
elif isImplication(fml):
|
2021-05-06 23:34:25 +02:00
|
|
|
val0 = rekursiv_eval(subfml[0], I);
|
|
|
|
val1 = rekursiv_eval(subfml[1], I);
|
2021-05-06 15:29:44 +02:00
|
|
|
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
|