title: Majority logic decoding Haskell
body: <p>I have to calculate the probability of the proper decoding of a bit copied <code>n</code> times.
  The following formula is supposed to be the answer:</p>
  
  <p><img src="https://i.stack.imgur.com/R3wLS.png" alt="the formula"></p>
  
  <p>In Haskell, I coded it as follows:</p>
  
  <pre><code>fac 1 = 1
  fac n = fac (n-1) * n
  --prob :: (Integral b, Fractional b) =&gt; (b, b) -&gt; b
  --prob :: (Int,Int) -&gt; Double
  prob (n, k)
      | n==k = (0.01**k)
      | otherwise = factor (n, k) * (0.01 ** k) * (0.99**(n-k)) + prob (n, (k+1)) 
      where
          factor (n, k) = (fac n / ((fac k)* (fac n-k)))
  </code></pre>
  
  <p><code>1 - prob (3,2)</code> gives the result <code>0.99992575</code>, which is incorrect, as it should be <code>0.99970</code>. Does anyone know where I went wrong?</p>