Apr-18-2019, 04:11 PM
I'm working on simplifying a part of a function.
d_n
actually represents a double sequence, call it d_ki
, where both indices k
and i
begin at 0 and terminate at n
. Evaluating the sequence for any n
yields a "matrix" where the xth first columns in the xth row fall away (noting that the first row is row zero, second is first and so on). Every d_n
thus represents the nth, ever-decreasing row in the "matrix". a
is a previously defined list and x
a constant. Is there a way to simplify the code so that when evaluating the function for all n
, one mustn't change the code every time?def ln(x,n): ... d_0 =[] for k in range(n+1): d_0.append(a[k]) d_1=[] for k in range (1,n+1): d_1.append((d_0[k]-4**(-1)*d_0[k-1])/(1-4**(-1))) d_2=[] for k in range(2,n+1): d_2.append((d_1[k-1]-4**(-2)*d_1[k-2])/(1-4**(-2))) d_3=[] for k in range(3,n+1): d_3.append((d_2[k-2]-4**(-3)*d_2[k-3])/(1-4**(-3))) ... d_n=[] for k in range(n,n+1): d_n.append((d_n-1[k-(n-1)]-4**(-n)*d_n-1[k-n])/(1-4**(-n))) return (x-1)/d_n[0]