본문 바로가기

프로그래밍/Python

Q-Pochhammer

반응형
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