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 the binding of empty Or formulas in the TseitinEncoder #67

Merged
merged 1 commit into from
Aug 19, 2024
Merged
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
26 changes: 25 additions & 1 deletion crates/pindakaas/src/propositional_logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ impl Formula {
}
Formula::Or(sub) => {
match sub.len() {
0 => return Err(Unsatisfiable),
0 => {
let name = name.unwrap_or_else(|| db.new_var().into());
db.add_clause([!name])?;
name
}
1 => return sub[0].bind(db, name),
_ => {
let name = name.unwrap_or_else(|| db.new_var().into());
Expand Down Expand Up @@ -365,6 +369,16 @@ mod tests {
=> vec![lits![-1, -2, 3], lits![1, -3], lits![2, -3]],
vec![lits![1, 2, 3], lits![-1, 2, -3], lits![-1, -2, -3], lits![1, -2, -3]]
);
// Regression test: empty and
assert_enc_sol!(
TseitinEncoder,
1,
&Formula::Equiv(vec![
Formula::Atom(1.into()),
Formula::And(vec![])
])
=> vec![lits![1]], vec![lits![1]]
);
}

#[test]
Expand Down Expand Up @@ -393,6 +407,16 @@ mod tests {
=> vec![lits![1, 2, -3], lits![-1, 3], lits![-2, 3]],
vec![lits![1, 2, 3], lits![-1, 2, 3], lits![-1, -2, -3], lits![1, -2, 3]]
);
// Regression test: empty or
assert_enc_sol!(
TseitinEncoder,
1,
&Formula::Equiv(vec![
Formula::Atom(1.into()),
Formula::Or(vec![])
])
=> vec![lits![-1]], vec![lits![-1]]
);
}

#[test]
Expand Down
Loading