On Wednesday, November 19, 2014 12:05:03 AM UTC+1, William wrote:
>
> Does anybody know how to do this sort of thing in Sage?  Asked by me 
> today by a Stanford CS professor... 
>
> "It would be nice if it knew how to simplify the tail probability of a 
> binomial distribution. Mathematica can do: 
>
> FullSimplify[ Sum[Binomial[total, k] x^k (1 - x)^(total - k), {k, 0, n}]] 
> -> (1 - x)^total ((1/(1 - x))^ 
>    total - (1 - x)^(-1 - n) x^(1 + n) 
>      Binomial[total, 1 + n] Hypergeometric2F1[1, 1 + n - total, 2 + n, 
>       x/(-1 + x)]) 
>
> With Sage it doesn't seem to have the hypergeometric functions (or 
> maybe it just doesn't know the simplification): 
>
> total, n, x, k = var('total', 'n', 'x', 'k') 
>
> simplify( sum( binomial(total,k) * x^k * (1-x)^(total - k), k, 0, n)) 
> -> sum(x^k*(-x + 1)^(-k + total)*binomial(total, k), k, 0, n) 
>

It appears that SymPy can solve it:

sage: import sympy
sage: s = sympy.Sum( binomial(total,k) * x^k * (1-x)^(total - k), (k, 0, n
)); s
Sum(x**k*(-x + 1)**(-k + total)*binomial(total, k), (k, 0, n))
sage: s.doit()
Piecewise((-x**(n + 1)*(-x + 1)**total*(-x + 1)**(-n - 1)*binomial(total, n 
+ 1)*hyper((1, n - total + 1), (n + 2,), x/(x - 1)) + (-x + 1)**total*(-x/(x 
- 1) + 1)**total, Or(And(-re(total) < 0, Abs(x/(x - 1)) <= 1), And(-re(total
) < 1, -re(total) >= 0, Abs(x/(x - 1)) <= 1, x/(x - 1) != 1), And(-re(total) 
>= 1, Abs(x/(x - 1)) < 1))), (Sum(x**k*(-x + 1)**(-k)*(-x + 1)**total*
binomial(total, k), (k, 0, n)), True))


At the moment, this can't be converted back to Sage. To simplify you will 
have to pick the right assumptions.

Regards,

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.

Reply via email to