Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cnfRec for more complex subclauses #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion bf/bf.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,9 @@ func cnfRec(f Formula, vars *vars) [][]int {
lits = append(lits, d)
for _, sub2 := range sub {
cnf := cnfRec(sub2, vars)
cnf[0] = append(cnf[0], -d)
for i := range cnf {
cnf[i] = append(cnf[i], -d)
}
res = append(res, cnf...)
}
default:
Expand Down
41 changes: 41 additions & 0 deletions bf/bf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,47 @@ func TestReproduceInvalidSolutionBug2(t *testing.T) {
}
}

func TestInvalidUnsatBug(t *testing.T) {
f := And(
Not(Var("a")),
Not(Or(
And(Var("a"), Not(Var("b"))),
And(Var("b"), Not(Var("a"))),
)),
Or(
And(And(Var("a"), Var("b")), Not(Not(Var("c")))),
And(Not(Var("c")), Not(And(Var("a"), Var("b")))),
),
Not(Or(
And(Or(And(And(Var("a"), Var("b")), Not(Var("c"))), Var("c")), Not(Var("d"))),
And(Var("d"), Not(Or(And(And(Var("a"), Var("b")), Not(Var("c"))), Var("c")))),
)),
Not(Or(
And(And(Or(And(And(Var("a"), Var("b")), Not(Var("c"))), Var("c")), Var("d")), Not(Var("e"))),
And(Var("e"), Not(And(Or(And(And(Var("a"), Var("b")), Not(Var("c"))), Var("c")), Var("d")))),
)),
)

model := map[string]bool{
"a": false,
"b": false,
"c": false,
"d": false,
"e": false,
}
if !f.Eval(model) {
t.Errorf("Model check with known solution failed")
}

model = Solve(f)
if model == nil {
t.Fatalf("Failed to solve; f:\n%s", f)
}
if !f.Eval(model) {
t.Errorf("Model check failed")
}
}

func TestPanic1(t *testing.T) {
ans := Solve(And(Var("x"), Var("x")))
if len(ans) != 1 {
Expand Down