master > master: codego methoden statt properties verwenden

This commit is contained in:
RD 2021-05-09 20:41:24 +02:00
parent 5c43006abd
commit cd21b1f035
2 changed files with 34 additions and 37 deletions

View File

@ -12,50 +12,49 @@ import (
func RekursivEval(tree syntaxbaum.SyntaxBaum, I []string) int {
var children = tree.GetChildren()
switch tree.Kind {
case "atom", "generic":
if tree.IsAtom() || tree.IsGeneric() {
if utils.StrListContains(I, tree.Expr) {
return 1
}
return 0
case "taut":
} else if tree.IsTautologySymbol() {
return 1
case "contradiction":
} else if tree.IsContradictionSymbol() {
return 0
case "not":
} else if tree.IsNegation() {
subtree0, _ := tree.GetChild()
val0 := RekursivEval(subtree0, I)
return 1 - val0
case "and2":
} else if tree.IsConjunction2() {
val0 := RekursivEval(children[0], I)
val1 := RekursivEval(children[1], I)
return utils.Min2(val0, val1)
case "and":
} else if tree.IsConjunction() {
var val = 1
for _, subtree := range children {
var val_ = RekursivEval(subtree, I)
val = utils.Min2(val, val_)
}
return val
case "or2":
} else if tree.IsDisjunction2() {
val0 := RekursivEval(children[0], I)
val1 := RekursivEval(children[1], I)
return utils.Max2(val0, val1)
case "or":
} else if tree.IsDisjunction() {
var val = 0
for _, subtree := range children {
var val_ = RekursivEval(subtree, I)
val = utils.Max2(val, val_)
}
return val
case "implies":
} else if tree.IsImplication() {
val0 := RekursivEval(children[0], I)
val1 := RekursivEval(children[1], I)
if val0 <= val1 {
return 1
}
return 0
default:
} else {
log.Fatal("Could not evaluate expression!")
return 0
}

View File

@ -73,64 +73,62 @@ func (tree SyntaxBaum) pretty(preindent string, tab string, prepend string, dept
// METHODS: Recognitong of Formula-Types
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
func (tree SyntaxBaum) isAtom() bool {
func (tree SyntaxBaum) IsIrreducible() bool {
return tree.Valence == 0
}
func (tree SyntaxBaum) IsAtom() bool {
return tree.Kind == "atom"
}
func (tree SyntaxBaum) isLiteral() bool {
if tree.isAtom() {
func (tree SyntaxBaum) IsLiteral() bool {
if tree.IsAtom() {
return true
} else if tree.isNegation() {
} else if tree.IsNegation() {
subtree, err := tree.GetChild()
if err == nil {
return subtree.isAtom()
return subtree.IsAtom()
}
}
return false
}
func (tree SyntaxBaum) isBeliebig() bool {
func (tree SyntaxBaum) IsGeneric() bool {
return tree.Kind == "generic"
}
func (tree SyntaxBaum) isTrueSymbol() bool {
func (tree SyntaxBaum) IsTautologySymbol() bool {
return tree.Kind == "taut"
}
func (tree SyntaxBaum) isFalseSymbol() bool {
func (tree SyntaxBaum) IsContradictionSymbol() bool {
return tree.Kind == "contradiction"
}
func (tree SyntaxBaum) isNegation() bool {
func (tree SyntaxBaum) IsConnective() bool {
return tree.Valence > 0
}
func (tree SyntaxBaum) IsNegation() bool {
return tree.Kind == "not"
}
func (tree SyntaxBaum) isConjunction() bool {
func (tree SyntaxBaum) IsConjunction2() bool {
return tree.Kind == "and2"
}
func (tree SyntaxBaum) isLongConjunction() bool {
switch tree.Kind {
case "and", "and2":
return true
default:
return false
}
func (tree SyntaxBaum) IsConjunction() bool {
return tree.Kind == "and" || tree.Kind == "and2"
}
func (tree SyntaxBaum) isDisjunction() bool {
func (tree SyntaxBaum) IsDisjunction2() bool {
return tree.Kind == "or2"
}
func (tree SyntaxBaum) isLongDisjunction() bool {
switch tree.Kind {
case "or", "or2":
return true
default:
return false
}
func (tree SyntaxBaum) IsDisjunction() bool {
return tree.Kind == "or" || tree.Kind == "or2"
}
func (tree SyntaxBaum) isImplication() bool {
func (tree SyntaxBaum) IsImplication() bool {
return tree.Kind == "implies"
}