master > master: codego - iff
This commit is contained in:
@@ -145,3 +145,4 @@ func (fml Formula) IsConjunction() bool { return fml.kind == "and" || fm
|
||||
func (fml Formula) IsDisjunction2() bool { return fml.kind == "or2" }
|
||||
func (fml Formula) IsDisjunction() bool { return fml.kind == "or" || fml.kind == "or2" }
|
||||
func (fml Formula) IsImplication() bool { return fml.kind == "implies" }
|
||||
func (fml Formula) IsDoubleImplication() bool { return fml.kind == "iff" }
|
||||
|
||||
@@ -115,3 +115,12 @@ func Implies(fml1 Formula, fml2 Formula) Formula {
|
||||
subformulae: [](*Formula){&fml1, &fml2},
|
||||
}
|
||||
}
|
||||
|
||||
func DoubleImplication(fml1 Formula, fml2 Formula) Formula {
|
||||
return Formula{
|
||||
kind: "iff",
|
||||
expr: "(" + fml1.expr + " <-> " + fml2.expr + ")",
|
||||
valence: 2,
|
||||
subformulae: [](*Formula){&fml1, &fml2},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,8 @@ func Eval(fml formulae.Formula, I []string) int {
|
||||
return utils.MaxList(prevValues)
|
||||
} else if fml.IsImplication() {
|
||||
return utils.BoolToInt(prevValues[0] <= prevValues[1])
|
||||
} else if fml.IsDoubleImplication() {
|
||||
return utils.BoolToInt(prevValues[0] == prevValues[1])
|
||||
} else {
|
||||
panic("Could not evaluate expression!")
|
||||
}
|
||||
|
||||
@@ -139,6 +139,11 @@ func (ant antlrTree) toFormula() formulae.Formula {
|
||||
if nChildren == 3 {
|
||||
return formulae.Implies(subants[0].toFormula(), subants[2].toFormula())
|
||||
}
|
||||
case "iff":
|
||||
// NOTE: expr = expr <=> expr
|
||||
if nChildren == 3 {
|
||||
return formulae.DoubleImplication(subants[0].toFormula(), subants[2].toFormula())
|
||||
}
|
||||
case "and", "or":
|
||||
// NOTE: expr = expr op expr op ... op expr
|
||||
var n int = int((len(subants) + 1) / 2)
|
||||
|
||||
Reference in New Issue
Block a user