master > master: codego - cleanup

This commit is contained in:
RD 2021-05-14 18:35:06 +02:00
parent 89c8e63f4b
commit 39be87d52f
5 changed files with 57 additions and 42 deletions

View File

@ -8,13 +8,28 @@ import (
* METHOD: Atoms
* ---------------------------------------------------------------- */
func Atoms(tree formulae.Formula) []string {
func Atoms(fml formulae.Formula) []string {
// Definiere Schema:
var schema = func(tree formulae.Formula, prevValues [][]string) []string {
var schema = func(fml formulae.Formula, prevValues [][]string) []string {
// Herausforderung: schreibe diese Funktion!
return []string{}
}
// Erzeuge Funktion aus Schema und berechne Wert:
fn := formulae.CreateFromSchemeStringsValued(schema)
return fn(tree)
return fn(fml)
}
/* ---------------------------------------------------------------- *
* METHOD: Subformulae
* ---------------------------------------------------------------- */
func Subformulae(fml formulae.Formula) []string {
// Definiere Schema:
var schema = func(fml formulae.Formula, prevValues [][]string) []string {
// Herausforderung: schreibe diese Funktion!
return []string{}
}
// Erzeuge Funktion aus Schema und berechne Wert:
fn := formulae.CreateFromSchemeStringsValued(schema)
return fn(fml)
}

View File

@ -8,42 +8,42 @@ import (
* METHOD: Formula Depth
* ---------------------------------------------------------------- */
func FmlDepth(tree formulae.Formula) int {
func FmlDepth(fml formulae.Formula) int {
// Definiere Schema:
var schema = func(tree formulae.Formula, prevValues []int) int {
var schema = func(fml formulae.Formula, prevValues []int) int {
// Herausforderung: schreibe diese Funktion!
return 0
}
// Erzeuge Funktion aus Schema und berechne Wert:
fn := formulae.CreateFromSchemeIntValued(schema)
return fn(tree)
return fn(fml)
}
/* ---------------------------------------------------------------- *
* METHOD: Formula Length
* ---------------------------------------------------------------- */
func FmlLength(tree formulae.Formula) int {
func FmlLength(fml formulae.Formula) int {
// Definiere Schema:
var schema = func(tree formulae.Formula, prevValues []int) int {
var schema = func(fml formulae.Formula, prevValues []int) int {
// Herausforderung: schreibe diese Funktion!
return 0
}
// Erzeuge Funktion aus Schema und berechne Wert:
fn := formulae.CreateFromSchemeIntValued(schema)
return fn(tree)
return fn(fml)
}
/* ---------------------------------------------------------------- *
* METHOD: Number of Parentheses
* ---------------------------------------------------------------- */
func NrParentheses(tree formulae.Formula) int {
func NrParentheses(fml formulae.Formula) int {
// Definiere Schema:
var schema = func(tree formulae.Formula, prevValues []int) int {
var schema = func(fml formulae.Formula, prevValues []int) int {
// Herausforderung: schreibe diese Funktion!
return 0
}
// Erzeuge Funktion aus Schema und berechne Wert:
fn := formulae.CreateFromSchemeIntValued(schema)
return fn(tree)
return fn(fml)
}

View File

@ -9,27 +9,27 @@ import (
* METHOD: Evaluation of fomulae in models
* ---------------------------------------------------------------- */
func Eval(tree formulae.Formula, I []string) int {
func Eval(fml formulae.Formula, I []string) int {
// Definiere (parameterisiertes) Schema:
var schema = func(_I []string) func(formulae.Formula, []int) int {
return func(tree formulae.Formula, prevValues []int) int {
if tree.IsAtom() || tree.IsGeneric() {
return utils.BoolToInt(utils.StrListContains(_I, tree.GetExpr()))
} else if tree.IsTautologySymbol() {
return func(fml formulae.Formula, prevValues []int) int {
if fml.IsAtom() || fml.IsGeneric() {
return utils.BoolToInt(utils.StrListContains(_I, fml.GetExpr()))
} else if fml.IsTautologySymbol() {
return 1
} else if tree.IsContradictionSymbol() {
} else if fml.IsContradictionSymbol() {
return 0
} else if tree.IsNegation() {
} else if fml.IsNegation() {
return 1 - prevValues[0]
} else if tree.IsConjunction2() {
} else if fml.IsConjunction2() {
return utils.Min2(prevValues[0], prevValues[1])
} else if tree.IsConjunction() {
} else if fml.IsConjunction() {
return utils.MinList(prevValues)
} else if tree.IsDisjunction2() {
} else if fml.IsDisjunction2() {
return utils.Max2(prevValues[0], prevValues[1])
} else if tree.IsDisjunction() {
} else if fml.IsDisjunction() {
return utils.MaxList(prevValues)
} else if tree.IsImplication() {
} else if fml.IsImplication() {
return utils.BoolToInt(prevValues[0] <= prevValues[1])
} else {
panic("Could not evaluate expression!")
@ -38,5 +38,5 @@ func Eval(tree formulae.Formula, I []string) int {
}
// Erzeuge Funktion aus Schema und berechne Wert:
fn := formulae.CreateFromSchemeIntValued(schema(I))
return fn(tree)
return fn(fml)
}

View File

@ -9,60 +9,60 @@ import (
* ---------------------------------------------------------------- */
// NOTE: diese bedarf einer Art Doppeltrekursion
func NNF(tree formulae.Formula) formulae.Formula {
func NNF(fml formulae.Formula) formulae.Formula {
// Definiere Schema:
var schema = func(tree formulae.Formula, prevValues []formulae.FormulaPair) formulae.FormulaPair {
var schema = func(fml formulae.Formula, prevValues []formulae.FormulaPair) formulae.FormulaPair {
// separate out positive and negative parts:
var pairs = formulae.NewFormulaPairs(prevValues)
var prevPos = pairs.Pos()
var prevNeg = pairs.Neg()
// compute value from previous positive/negative parts:
if tree.IsPositiveLiteral() {
if fml.IsPositiveLiteral() {
return formulae.FormulaPair{
Pos: tree.Deepcopy(),
Neg: formulae.Negation(tree),
Pos: fml.Deepcopy(),
Neg: formulae.Negation(fml),
}
} else if tree.IsNegativeLiteral() {
} else if fml.IsNegativeLiteral() {
return formulae.FormulaPair{
Pos: tree.Deepcopy(),
Pos: fml.Deepcopy(),
Neg: prevPos[0],
}
} else if tree.IsTautologySymbol() {
} else if fml.IsTautologySymbol() {
return formulae.FormulaPair{
Pos: formulae.Tautology,
Neg: formulae.Contradiction,
}
} else if tree.IsContradictionSymbol() {
} else if fml.IsContradictionSymbol() {
return formulae.FormulaPair{
Pos: formulae.Contradiction,
Neg: formulae.Tautology,
}
} else if tree.IsNegation() {
} else if fml.IsNegation() {
return formulae.FormulaPair{
Pos: prevNeg[0],
Neg: prevPos[0],
}
} else if tree.IsConjunction2() {
} else if fml.IsConjunction2() {
return formulae.FormulaPair{
Pos: formulae.Conjunction2(prevPos[0], prevPos[1]),
Neg: formulae.Disjunction2(prevNeg[0], prevNeg[1]),
}
} else if tree.IsConjunction() {
} else if fml.IsConjunction() {
return formulae.FormulaPair{
Pos: formulae.Conjunction(prevPos),
Neg: formulae.Disjunction(prevNeg),
}
} else if tree.IsDisjunction2() {
} else if fml.IsDisjunction2() {
return formulae.FormulaPair{
Pos: formulae.Disjunction2(prevPos[0], prevPos[1]),
Neg: formulae.Conjunction2(prevNeg[0], prevNeg[1]),
}
} else if tree.IsDisjunction() {
} else if fml.IsDisjunction() {
return formulae.FormulaPair{
Pos: formulae.Disjunction(prevPos),
Neg: formulae.Conjunction(prevNeg),
}
} else if tree.IsImplication() {
} else if fml.IsImplication() {
return formulae.FormulaPair{
Pos: formulae.Implies(prevPos[0], prevPos[1]),
Neg: formulae.Conjunction2(prevPos[0], prevNeg[1]),
@ -73,5 +73,5 @@ func NNF(tree formulae.Formula) formulae.Formula {
}
// Erzeuge Funktion aus Schema und berechne Wert:
fn := formulae.CreateFromSchemeFmlPairValued(schema)
return fn(tree).Pos
return fn(fml).Pos
}

View File

@ -66,6 +66,6 @@ function run_programme() {
check_requirements;
# Code als Programm kompilieren und ausführen:
# precompile_grammars;
precompile_grammars;
compile_programme;
run_programme;