Since & halves the number of 1s and | halves the number of 0s one would expect that the pattern for 1-X would just be the pattern for X with all the operators inverted:
21 = (32 - 11) => ( ( R & R ) | R & R ) | R
27 = (32 - 5) => ( R | R & R ) | R | R
I see that 9 is also missing from your list.
I presume that the goal is to get exact ratios with the smallest number of operators? One way to explore this space is to create a Perl script to list the resulting spread for all the expressions with a certain number of operators
Update: I think this is about right (and if not then it should be fixable)
use strict;
use warnings;
sub operations
{
my($num_ops) = @_;
#return (["M | M", 3 , 4], ["M & M", 1, 4])
# if($num_ops == 1);
return ["M", 1, 2] if($num_ops == 0);
my @result;
for(my $i=0;$i<$num_ops;$i++)
{
my @first = operations($i);
my @second = operations($num_ops - $i - 1);
foreach my $first_part (@first)
{
my($fp_expr,$fp_top,$fp_bot) = @{$first_part};
foreach my $second_part (@second)
{
my($sp_expr,$sp_top,$sp_bot) = @{$second_part};
# Two choices & or |
# (NY + M(X-N))/(X*Y)
# (X*Y - ((X-N)Y + (Y-M)N))/(X*Y)
push @result,["($fp_expr) & ($sp_expr)",
$fp_bot*$sp_bot -
($fp_bot - $fp_top)*$sp_bot -
($sp_bot - $sp_top)*$fp_top,
$fp_bot*$sp_bot],
["($fp_expr) | ($sp_expr)",
$fp_top*$sp_bot +
$sp_top*($fp_bot - $fp_top),
$fp_bot*$sp_bot];
}
}
}
return @result;
}
# Update: Edited the calling routine to provide easier to use results
my @got;
foreach my $count_expr (0..4)
{
foreach my $expr (operations($count_expr))
{
my($sp_expr,$top,$bot) = @{$expr};
$top = $top * (32 / $bot);
next if(defined $got[$top]);
$sp_expr =~ s/\(M\)/M/g;
$got[$top] = sprintf "%02d: $sp_expr\n",$top;
}
}
for(my $i=1;$i<32;$i++)
{
print $got[$i];
}
Which gives results:
01: M & (M & (M & (M & M)))
02: M & (M & (M & M))
03: M & (M & (M & (M | M)))
04: M & (M & M)
05: M & (M & (M | (M & M)))
06: M & (M & (M | M))
07: M & (M & (M | (M | M)))
08: M & M
09: M & (M | (M & (M & M)))
10: M & (M | (M & M))
11: M & (M | (M & (M | M)))
12: M & (M | M)
13: M & (M | (M | (M & M)))
14: M & (M | (M | M))
15: M & (M | (M | (M | M)))
16: M
17: M | (M & (M & (M & M)))
18: M | (M & (M & M))
19: M | (M & (M & (M | M)))
20: M | (M & M)
21: M | (M & (M | (M & M)))
22: M | (M & (M | M))
23: M | (M & (M | (M | M)))
24: M | M
25: M | (M | (M & (M & M)))
26: M | (M | (M & M))
27: M | (M | (M & (M | M)))
28: M | (M | M)
29: M | (M | (M | (M & M)))
30: M | (M | (M | M))
31: M | (M | (M | (M | M)))