I wonder if you're not making this too complicated. If I'm not mistaken,
E(X & R) = E(X)/2 E(X | R) = (E(X)+1)/2
so it should be possible to build the expression from the binary expansion of the desired probability:
#! /usr/bin/perl use strict; use warnings; my $bits = shift; my $den = 2**$bits; foreach my $num (1 .. $den-1) { my $str = sprintf "%0${bits}b", $num; $str =~ s/0*$//; my $len = length $str; $str =~ s/0/R & (/g; $str =~ s/1/R | (/g; $str .= ")" x $len; $str =~ s/ \| \(\)//; $str =~ s/\(R\)/R/; print "E($num/$den) = $str\n"; }
The output has more parentheses than strictly necessary, but odds are there's a CPAN module that can fix that.
E(1/32) = R & (R & (R & (R & R))) E(2/32) = R & (R & (R & R)) E(3/32) = R & (R & (R & (R | R))) E(4/32) = R & (R & R) E(5/32) = R & (R & (R | (R & R))) E(6/32) = R & (R & (R | R)) E(7/32) = R & (R & (R | (R | R))) E(8/32) = R & R E(9/32) = R & (R | (R & (R & R))) E(10/32) = R & (R | (R & R)) E(11/32) = R & (R | (R & (R | R))) E(12/32) = R & (R | R) E(13/32) = R & (R | (R | (R & R))) E(14/32) = R & (R | (R | R)) E(15/32) = R & (R | (R | (R | R))) E(16/32) = R E(17/32) = R | (R & (R & (R & R))) E(18/32) = R | (R & (R & R)) E(19/32) = R | (R & (R & (R | R))) E(20/32) = R | (R & R) E(21/32) = R | (R & (R | (R & R))) E(22/32) = R | (R & (R | R)) E(23/32) = R | (R & (R | (R | R))) E(24/32) = R | R E(25/32) = R | (R | (R & (R & R))) E(26/32) = R | (R | (R & R)) E(27/32) = R | (R | (R & (R | R))) E(28/32) = R | (R | R) E(29/32) = R | (R | (R | (R & R))) E(30/32) = R | (R | (R | R)) E(31/32) = R | (R | (R | (R | R)))

In reply to Re^6: Boolean math: Fill in the blanks. by jdalbec
in thread Boolean math: Fill in the blanks. by BrowserUk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.