-
Notifications
You must be signed in to change notification settings - Fork 0
/
grover.py
38 lines (31 loc) · 942 Bytes
/
grover.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
from scipy.special import factorial
from numpy import exp
from math import pi, sqrt
import matplotlib.pyplot as plt
def grover_approx(n):
ret = pow(n, n)/exp(n)
ret *= sqrt(pi*(2*n + 1/3))
return ret
def stirling_approx(n):
ret = pow(n, n)/exp(n)
ret *= sqrt(pi*(2*n))
return ret
def exp_approx(n):
ret = pow(n, n)/exp(n)
return ret
def upper_bound(n):
return pow(n, n)
def main():
n = int(input())
x = list(range(1, n + 1))
grov_y = [factorial(i)/grover_approx(i) for i in range(1, n + 1)]
stirling_y = [factorial(i)/stirling_approx(i) for i in range(1, n + 1)]
exp_y = [factorial(i)/exp_approx(i) for i in range(1, n + 1)]
upper_bound_y = [factorial(i)/upper_bound(i) for i in range(1, n + 1)]
plt.plot(x, grov_y, 'r')
plt.plot(x, stirling_y, 'b')
plt.plot(x, exp_y, 'g')
plt.plot(x, upper_bound_y, 'v')
plt.show()
if __name__ == "__main__":
main()