반응형
def q_pochhammer(a, q, n):
"""
calculate q-pochhammer defined as
n-1 k
(a;q) = prod (1 - a q )
n k=0
"""
product = 1
for k in range(n):
term = 1 - a * (q ** k)
product *= term
return product
for a, q, n in [
(2, 2, 1),
(2, 2, 4),
(5, 5, 4),
(1 / 3, 1 / 3, 100),
(1 / 2, 1 / 2, 1),
(1 / 2, 1 / 2, 2),
(1 / 2, 1 / 2, 3),
(1 / 2, 1 / 2, 4),
(1 / 2, 1 / 2, 10),
(1 / 2, 1 / 2, 50),
(1 / 2, 1 / 2, 100),
(1 / 2, 1 / 2, 150),
]:
print(f"qpochhammer({a:.03f},{q:.03f},{n:.03f}) = {q_pochhammer(a,q,n)}")
qpochhammer(2.000,2.000,1.000) = -1
qpochhammer(2.000,2.000,4.000) = 315
qpochhammer(5.000,5.000,4.000) = 7428096
qpochhammer(0.333,0.333,100.000) = 0.5601260779279486
qpochhammer(0.500,0.500,1.000) = 0.5
qpochhammer(0.500,0.500,2.000) = 0.375
qpochhammer(0.500,0.500,3.000) = 0.328125
qpochhammer(0.500,0.500,4.000) = 0.3076171875
qpochhammer(0.500,0.500,10.000) = 0.28907029841974896
qpochhammer(0.500,0.500,50.000) = 0.28878809508660264
qpochhammer(0.500,0.500,100.000) = 0.2887880950866024
qpochhammer(0.500,0.500,150.000) = 0.2887880950866024
728x90
'프로그래밍 > Python' 카테고리의 다른 글
python 3d plotting (0) | 2022.04.27 |
---|---|
파이썬 지수 수치계산방식에 따른 차이 (0) | 2022.04.27 |
0과 1 사이에서 랜덤하게 뽑은 숫자를 평균적으로 몇 번 더해야 1보다 커질까요? (0) | 2022.03.18 |
[파이썬초보] AttributeError: 'NoneType' object has no attribute (3) | 2022.01.27 |
find (a, b) such that am + bn = gcd(m, n) (0) | 2022.01.24 |