-
Notifications
You must be signed in to change notification settings - Fork 0
/
reccurences.py
53 lines (42 loc) · 903 Bytes
/
reccurences.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from math import comb
import functools
@functools.cache
def C(l, p):
if l <= 0:
return 1
return p ** (l + 1)
@functools.cache
def D(l, p):
if l <= 0:
return 1
return p * D(l - 1, p) + R(l, p)
@functools.cache
def R(l, p):
if l == 0:
return 0
ans = 0
for n in range(32, 64):
ans2 = 0
for d in range(n - 32, 32):
ans2 += comb(32, d) * ((p * D(l - 1, p)) ** d) * comb(32, n - d) * ((p * C(l - 1, p)) ** (n-d))
ans += ans2 * ((1-p) ** (64 - n))
return ans
@functools.cache
def B(l, p):
return (p * D(l - 1, p)) ** 32 + R(l, p)
# print(D(1, 0.25))
# print(D(1, 0.5))
print(R(1, 0.75))
print(B(1, 0.75))
# print(D(1, 1))
print()
print(B(1, 0.25))
print(B(1, 0.5))
print(B(1, 0.75))
print(B(1, 1))
print()
print(B(2, 0.25))
print(B(2, 0.5))
print(B(2, 0.75))
print(B(2, .95))
print(B(2, 1))