There is a problem that it is not related to Python, but Set the settings so that you are happy with the calculator and solve.
The player pulled out one of the 52 playing cards excluding the joker and placed it face down. When the dealer randomly picked out 3 cards from the remaining mountains and turned them to the front, they were all diamonds.
(Solution)
P_0 = sym.Rational(1, 4)
P_0dia = sym.Rational(13*12*11, 51*50*49)
P_dia = sym.Rational(14*13*12, 52*51*50)
P_0 * P_0dia / P_dia
There is a lottery with a winning probability of $ p $. If all the people on the earth draw lots once, the probability of losing all will be 0.5 or more How much does $ p $ have to be? The population of the earth is 7.2 billion.
(Solution) Approximate with Poisson distribution.
N = 7200000000
F = sym.exp(-p*N) - 0.5
sym.solve([F], [p])
By the way, if you try this much, the normal distribution will be about 7 times the standard deviation. In the Pareto distribution, it is not strange that values that are more than 100 million times apart appear.
(Solution)
import sympy as sym
A = sym.functions.combinatorial.numbers.nC(12, 2)
B = sym.functions.combinatorial.numbers.nC(8, 1)
C = sym.functions.combinatorial.numbers.nC(20, 3)
A*B/C
log_n = n * sym.log(n) - n + sym.log(2 * Pi * n) / 2
A1 = log_n.subs([(n, 4*10**24)])
A2 = log_n.subs([(n, 3*10**24)])
B1 = log_n.subs([(n, 6*10**24)])
B2 = log_n.subs([(n, 2*10**24)])
B3 = log_n.subs([(n, 1*10**24)])
Log_P = A1 + 2 * A2 - B1 - B2 - 2 * B3
sym.N(Log_P, 10)
Consider a random walk that starts from the yellow part in the center of the triangular grid in the figure and moves to the adjacent grid with equal probability every second. Let $ P_t $ be the probability of being in the center after $ t $ seconds.
(Solution)
N = 1
P = 0
Q = sym.Rational(1, 6)
R = 0
Pn = sym.Rational(3, 2) * q
Qn = p/6 + q/2 + r/2
Rn = q/2
while N < 10:
N += 1
Ptemp = Pn.subs([(q, Q)])
Qtemp = Qn.subs([(p, P), (q, Q), (r, R)])
Rtemp = Rn.subs([(q, Q)])
P = Ptemp
Q = Qtemp
R = Rtemp
print(N)
print(P)
print(Q)
print(R)
F1 = sym.Rational(3, 2) * q - p
F2 = p/6 + q/2 + r/2 - q
F3 = q/2 - r
Ft = p + 6*q + 3*r - 1
sym.solve([F1, F2, F3, Ft], [p, q, r])
Suppose that $ n $ uniform random numbers in the range of 0 to 65535 are generated.
(Solution)
def birthday(N, K):
return sym.functions.combinatorial.numbers.nP(N, K)/N**K
N = 65536
K = 255 #You can start with the square root
P = 0.0
while P <= 0.5:
K += 1
P = 1 - birthday(N, K)
print(K)
sym.N(P, 10)
The boundary part of $ K / 2 $ does not have much effect, so add it without worrying about it.
def birthday2(N, K, P1):
return (sym.functions.combinatorial.numbers.nP(N,K) + P1) / N**K
def P1(N,K,X):
return sym.functions.combinatorial.numbers.nC(N-X,X)*sym.functions.combinatorial.numbers.nP(N,K-X)
N = 65536
K = 300
P = 0.0
while P <= 0.5:
K += 1
L = 1
SUM = 0
while L <= K/2:
SUM += P1(N, K, L)
L += 1
P = 1 - birthday2(N, K, SUM)
print(K)
sym.N(P, 10)
Recommended Posts