An algorithm to automatically minimize boolean expressions.
```rust extern crate quinemccluskey;
use quinemccluskey::; use quine_mc_cluskey::Bool::;
fn main() { // !false => true asserteq!(Not(Box::new(False)).simplify(), vec![True]); // a && (b || a) => a asserteq!(And(vec![Term(0), Or(vec![Term(1), Term(0)])]).simplify(), vec![Term(0)]); } ```
Sometimes an expression of the for a && (b || c)
is shorter than the a && b || a && c
form.
We can simply negate the original expression and negate all the resulting simplified expressions to obtain that form.
```rust
let a: Bool = ....;
let simplified: Vec
fn simplenegate(b: Bool) -> Bool { use quinemccluskey::Bool::*; match b { True => False, False => True, t @ Term() => Not(Box::new(t)), And(mut v) => { for el in &mut v { *el = simplenegate(::std::mem::replace(el, True)); } Or(v) }, Or(mut v) => { for el in &mut v { *el = simplenegate(::std::mem::replace(el, True)); } And(v) }, Not(inner) => *inner, } } ```