I have 2 rules of recursive relation of the derivative, I want to use it several times get the higher derivative on [\Theta] of P[\[Theta],n,m] only expressed by P[\[Theta], n, m] and P[\[Theta], n-1, m]. (Yes, P is Associated Legendre polynomials here)
This is my rule (Sorry, I don't know how to wrap this long line of code):
rule1 = D[P[\[Theta], n, m], {\[Theta], i}] :> D[D[P[\[Theta], n, m], {\[Theta], i - 1}], {\[Theta], 1}];(*i>=2*) rule2 = D[P[\[Theta], n, m], {\[Theta], 1}] :> 1/Sin[\[Theta]] (n Cos[\[Theta]]*P[\[Theta], n, m] - (n + m) P[\[Theta], n - 1, m]); rule = {rule1, rule2}; Then I use this first code and it return the needed result.
D[P[\[Theta], n, m], {\[Theta], 1}] //. rule However, the higher derivative on [\Theta] canot work. How to the let it works?
D[P[\[Theta], n, m], {\[Theta], 2}] //. rule (* return with calcuation *) We can make rule 1 execute first, consider rule 2 during the compute, and repeat the process to get what I want. But how to implement it in code?
Another try (Try these two rules in each calculation step) :
r1 = D[P[\[Theta], n_, m], {\[Theta], 1}] :> (1/Sin[\[Theta]] (n Cos[\[Theta]]*P[\[Theta], n, m] - (n + m) P[\[Theta], n - 1, m])); r2 = D[P[\[Theta], n_, m], {\[Theta], i_}] :> (D[D[P[\[Theta], n, m], {\[Theta], i - 1}] /. r1, \[Theta] ] /. r1);(*i>=2*) D[P[\[Theta], n, m], {\[Theta], 2}] /. r2 (* Out contains P[\[Theta], -2 + n, m], This is not what you want to see *) D[P[\[Theta], n, m], {\[Theta], 3}] /. r2 (* Nothing changed *) 

