Skip to content

Commit

Permalink
Fix the binding of Not formulas in the TseitinEncoder bind helper
Browse files Browse the repository at this point in the history
  • Loading branch information
Dekker1 committed Aug 15, 2024
1 parent 0e6cfbb commit 54412b6
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion crates/pindakaas/src/propositional_logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl Formula {
*lit
}
}
Formula::Not(f) => !(f.bind(db, name)?),
Formula::Not(f) => !(f.bind(db, name.map(|lit| !lit))?),
Formula::And(sub) => {
match sub.len() {
0 => {
Expand Down Expand Up @@ -257,6 +257,10 @@ impl<DB: ClauseDatabase> Encoder<DB, Formula> for TseitinEncoder {
let neg_els: Formula = !*els.clone();
self.encode(&mut cdb, &neg_els)
}
Formula::Xor(sub) => {
let neg_sub = sub.iter().map(|f| !(f.clone())).collect();
self.encode(db, &Formula::Xor(neg_sub))
}
_ => {
let l = f.bind(db, None)?;
db.add_clause([!l])
Expand Down Expand Up @@ -509,4 +513,21 @@ mod tests {
vec![lits![-1, -2, -3, -4], lits![-1, -2, 3, 4], lits![1, -2, 3, -4], lits![1, 2, 3, 4], lits![1, 2, -3, 4], lits![1, -2, -3, -4], lits![-1, 2, 3, 4], lits![-1, 2, -3, -4]]
);
}

#[test]
fn encode_prop_neg_equiv() {
// Regression test
assert_enc_sol!(
TseitinEncoder,
2,
&Formula::Equiv(vec![
Formula::Atom(2.into()),
Formula::Not(Box::new(Formula::Xor(vec![Formula::Atom(1.into())]))),
])
=> vec![
lits![1,2], lits![-1,-2]
],
vec![lits![1,-2], lits![-1,2]]
);
}
}

0 comments on commit 54412b6

Please sign in to comment.