in reply to Optimize a generic boolean expression

In order to come up with the minterms, you would need a value table. Here is some code to find the variables and the value table:

use strict; use warnings; $"="\t"; my $bool = 'Fred&Teddy&(Fred|Teddy)|(Fred)&(John)'; my @vars = keys %{{ map { $_ => 1 } $bool =~ /\b(\w+)\b/g }}; $bool =~ s/($_)/\$b\{${1}\}/g for @vars; my $n = @vars; my %b; print "@vars\tValue\n"; for (0..2**$n-1) { @b{@vars} = split //, sprintf "%0${n}b", $_; print "@b{@vars}\t"; print eval $bool; print "\n"; }