<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def dlmk(l,m,k,theta1):
 """ returns value of d^l_mk as defined in allen, ottewill 97. Called by Dlmk """

    
    if m >= k:
        
        factor = sqrt(factorial(l-k)*factorial(l+m)/factorial(l+k)/factorial(l-m))
        part2 = (cos(theta1/2))**(2*l+k-m)*(-sin(theta1/2))**(m-k)/factorial(m-k)
        part3 = sp.hyp2f1(m-l,-k-l,m-k+1,-(tan(theta1/2))**2)

        return factor*part2*part3
    
    else:
        
        return (-1)**(m-k) * dlmk(l,k,m,theta1)