There seems to be a certain symmetry evident from how R & R results in 8 bits set on average (halfway between 1 and 16) versus R | R resulting in 24 bits set on average (halfway between 16 and 32). I'll be sure to make my hypothesis symmetrical, in that regard.

If we apply AND, the average bits set goes down due to higher likelihood of 0 bits swallowing the 1 bits. Conversely, if we apply OR, the average bits set goes up due to higher likelihood of 1 bits overriding the 0 bits.

Non-associative rules apply for AND and OR:

( (A & B) | C ) != ( A & (B | C) )

So evaluating the expression from left-to-right is important! Update: Perl gives precedence to the & operator over |

Hypothesis:

Whenever an AND/OR <op> is applied, it induces a change to the already gained average bits on the left-side. That change is a multiplicative factor determined by the average bits set on the right-side:

right_mod_factor = right_avg_set_bits / total_bits

Cases:

For <op> = AND, we would take right_mod_factor and multiply it with left_avg_bits_set to get <resulting_avg_bits_set>. Examples:

R & (R & R) => 16 * (8 / 32) = 4 bits set on average

(R | R) & (R & R & R) => 24 * (4 / 32) = 3 bits set on average

That is, if there are more bits set on average on the AND right-side, there will be less chance of swallowing, so more bits are set on average in the result.

Conversely, for <op> = OR, we would take right_mod_factor and multiply it with left_avg_unset_bits. Then, take that result and add it to left_avg_set_bits to get <resulting_avg_bits_set>. Examples: