ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 21 Nov 2023 16:34:51 +0100Calculating very complex probability equationhttps://ask.sagemath.org/question/74237/calculating-very-complex-probability-equation/ I want to calculate the probability of following statement. It will be very close to $1$ ,but I need to see how close it is.
I could not calculate it using standart python, so I need very sensitive tool. I think that sage can handle it. However, I could not take proper solution. Maybe, i am missing something. $$\frac{(39 \times 10^{96})!}{(39 \times 10^{96}-16 \times10^9)! \times (39 \times 10^{96})^{16 \times10^9}}$$Wed, 08 Nov 2023 14:13:47 +0100https://ask.sagemath.org/question/74237/calculating-very-complex-probability-equation/Comment by jacop for <p>I want to calculate the probability of following statement. It will be very close to $1$ ,but I need to see how close it is.
I could not calculate it using standart python, so I need very sensitive tool. I think that sage can handle it. However, I could not take proper solution. Maybe, i am missing something. $$\frac{(39 \times 10^{96})!}{(39 \times 10^{96}-16 \times10^9)! \times (39 \times 10^{96})^{16 \times10^9}}$$</p>
https://ask.sagemath.org/question/74237/calculating-very-complex-probability-equation/?comment=74243#post-id-74243it is pen and paper problem with mandatory
computationWed, 08 Nov 2023 20:03:45 +0100https://ask.sagemath.org/question/74237/calculating-very-complex-probability-equation/?comment=74243#post-id-74243Comment by Max Alekseyev for <p>I want to calculate the probability of following statement. It will be very close to $1$ ,but I need to see how close it is.
I could not calculate it using standart python, so I need very sensitive tool. I think that sage can handle it. However, I could not take proper solution. Maybe, i am missing something. $$\frac{(39 \times 10^{96})!}{(39 \times 10^{96}-16 \times10^9)! \times (39 \times 10^{96})^{16 \times10^9}}$$</p>
https://ask.sagemath.org/question/74237/calculating-very-complex-probability-equation/?comment=74240#post-id-74240You don't need to calculate it explicitly to get an estimation. It sounds more like a homework pen-and-paper problem than a computational one.Wed, 08 Nov 2023 18:15:55 +0100https://ask.sagemath.org/question/74237/calculating-very-complex-probability-equation/?comment=74240#post-id-74240Comment by jacop for <p>I want to calculate the probability of following statement. It will be very close to $1$ ,but I need to see how close it is.
I could not calculate it using standart python, so I need very sensitive tool. I think that sage can handle it. However, I could not take proper solution. Maybe, i am missing something. $$\frac{(39 \times 10^{96})!}{(39 \times 10^{96}-16 \times10^9)! \times (39 \times 10^{96})^{16 \times10^9}}$$</p>
https://ask.sagemath.org/question/74237/calculating-very-complex-probability-equation/?comment=74239#post-id-74239@maxalekseyev, stirling formula is good for factorial, but sage could not calculate the exponential expression in the denominator. If you can calculate them,can you please share your code with me ?Wed, 08 Nov 2023 16:20:43 +0100https://ask.sagemath.org/question/74237/calculating-very-complex-probability-equation/?comment=74239#post-id-74239Comment by Max Alekseyev for <p>I want to calculate the probability of following statement. It will be very close to $1$ ,but I need to see how close it is.
I could not calculate it using standart python, so I need very sensitive tool. I think that sage can handle it. However, I could not take proper solution. Maybe, i am missing something. $$\frac{(39 \times 10^{96})!}{(39 \times 10^{96}-16 \times10^9)! \times (39 \times 10^{96})^{16 \times10^9}}$$</p>
https://ask.sagemath.org/question/74237/calculating-very-complex-probability-equation/?comment=74238#post-id-74238See https://en.wikipedia.org/wiki/Stirling%27s_approximationWed, 08 Nov 2023 15:13:20 +0100https://ask.sagemath.org/question/74237/calculating-very-complex-probability-equation/?comment=74238#post-id-74238Answer by dan_fulea for <p>I want to calculate the probability of following statement. It will be very close to $1$ ,but I need to see how close it is.
I could not calculate it using standart python, so I need very sensitive tool. I think that sage can handle it. However, I could not take proper solution. Maybe, i am missing something. $$\frac{(39 \times 10^{96})!}{(39 \times 10^{96}-16 \times10^9)! \times (39 \times 10^{96})^{16 \times10^9}}$$</p>
https://ask.sagemath.org/question/74237/calculating-very-complex-probability-equation/?answer=74405#post-id-74405The first rule of a computer algebra system is that the human must go humaly as far as possible, the program a humanly meaningful path and result. In our case...
----------
Let $N$ be the number $39\cdot 10^{96}$, and let $k$ be the number $16\cdot 10^9$. You want to calculate:
$$
A =
\frac
{N\cdot(N-1)\cdot (N-2)\cdot\dots\cdot(N-k+1)}
{N\cdot N\cdot N\cdot\dots\cdot N}
=1
\cdot
\left(1-\frac 1N\right)\cdot
\left(1-\frac 2N\right)\cdot\dots\cdot
\left(1-\frac {k-1}N\right)\ .
$$
We can try to estimate and approximate.
For instance, the product is between $1$ and $\left(1-\frac kn\right)^k$, and for the last power use Bernoulli in order to not use the computer. So a lower bound is $1-\frac {k^2}N$.
But we can do better:
$$
-\log(1-x) = x+\frac 12x^2+\frac 13x^3+\frac 14x^4+\dots
$$
so that it is for values of $x$ in our range, $|x|\le k/N$, between $x$ and $x+x^2$. (We may want to refine later, if this does not work.) Then:
$$
e^{-x-x^2}\le (1-x)\le e^{-x}\ .
$$
So our product is between the following numbers:
$$
\begin{aligned}
A_0 &:=\exp-\sum_{1\le j< k}\frac jN +\frac {j^2}{N^2}
=\exp\left(-\frac 1N k(k-1)-\frac 1{N^2}k(k-1)(2k-1)\right)\ ,\\\\
A_1 &:=\exp-\sum_{1\le j< k}\frac jN =\exp\left(-\frac 1N k(k-1)\right) \ .
\end{aligned}
$$
It is time to use the computer:
k, N = 16. * 10^9, 39. * 10^96
A1 = exp( -k*(k-1)/N )
A0 = A1 * exp( -k*(k-1)*(2*k-1) / N^2 )
print(f"A0 = {A0}")
print(f"A1 = {A1}")
And we get of course:
A0 = 1.00000000000000
A1 = 1.00000000000000
Because $A_1$ is in fact the exponential of the tiny number
sage: -k*(k-1)/N
-6.56410256369231e-78
and in order to also have $A_0$ we need the contribution of the tiny-tiny number...
sage: -k*(k-1)*(2*k-1)/N^2
-5.38593030850230e-165
Mon, 20 Nov 2023 21:46:37 +0100https://ask.sagemath.org/question/74237/calculating-very-complex-probability-equation/?answer=74405#post-id-74405Comment by achrzesz for <p>The first rule of a computer algebra system is that the human must go humaly as far as possible, the program a humanly meaningful path and result. In our case...</p>
<hr>
<p>Let $N$ be the number $39\cdot 10^{96}$, and let $k$ be the number $16\cdot 10^9$. You want to calculate:
$$
A =
\frac
{N\cdot(N-1)\cdot (N-2)\cdot\dots\cdot(N-k+1)}
{N\cdot N\cdot N\cdot\dots\cdot N}
=1
\cdot
\left(1-\frac 1N\right)\cdot
\left(1-\frac 2N\right)\cdot\dots\cdot
\left(1-\frac {k-1}N\right)\ .
$$
We can try to estimate and approximate.
For instance, the product is between $1$ and $\left(1-\frac kn\right)^k$, and for the last power use Bernoulli in order to not use the computer. So a lower bound is $1-\frac {k^2}N$.</p>
<p>But we can do better:
$$
-\log(1-x) = x+\frac 12x^2+\frac 13x^3+\frac 14x^4+\dots
$$
so that it is for values of $x$ in our range, $|x|\le k/N$, between $x$ and $x+x^2$. (We may want to refine later, if this does not work.) Then:
$$
e^{-x-x^2}\le (1-x)\le e^{-x}\ .
$$
So our product is between the following numbers:
$$
\begin{aligned}
A_0 &:=\exp-\sum_{1\le j< k}\frac jN +\frac {j^2}{N^2}
=\exp\left(-\frac 1N k(k-1)-\frac 1{N^2}k(k-1)(2k-1)\right)\ ,\\
A_1 &:=\exp-\sum_{1\le j< k}\frac jN =\exp\left(-\frac 1N k(k-1)\right) \ .
\end{aligned}
$$
It is time to use the computer:</p>
<pre><code>k, N = 16. * 10^9, 39. * 10^96
A1 = exp( -k*(k-1)/N )
A0 = A1 * exp( -k*(k-1)*(2*k-1) / N^2 )
print(f"A0 = {A0}")
print(f"A1 = {A1}")
</code></pre>
<p>And we get of course:</p>
<pre><code>A0 = 1.00000000000000
A1 = 1.00000000000000
</code></pre>
<p>Because $A_1$ is in fact the exponential of the tiny number</p>
<pre><code>sage: -k*(k-1)/N
-6.56410256369231e-78
</code></pre>
<p>and in order to also have $A_0$ we need the contribution of the tiny-tiny number...</p>
<pre><code>sage: -k*(k-1)*(2*k-1)/N^2
-5.38593030850230e-165
</code></pre>
https://ask.sagemath.org/question/74237/calculating-very-complex-probability-equation/?comment=74430#post-id-74430Using numerical computations with 100 decimals precision in GP/Pari one can check that the product A is equal
0.9999999999999999999999999999999999999999999999999999999999999999999999999999967179487158974358974359Tue, 21 Nov 2023 16:34:51 +0100https://ask.sagemath.org/question/74237/calculating-very-complex-probability-equation/?comment=74430#post-id-74430