Closed ckrause closed 1 year ago
To improve the performance of generated PARI code, we should use local variables if sequences terms are computed more than once. Here is an example:
A036211: OLD VERSION: (a(n) = truncate(A019520(n+50)/A178500(2*n+100))-10*truncate(truncate(A019520(n+50)/A178500(2*n+100))/10)); (b(n) = if(n==4,100,if(n==3,10,if(n==2,10,if(n==1,10,if(n==0,10,9*b(n-1)*truncate((2*n+2)/b(n-1))+b(n-1))))))); (c(n) = if(n==4,12,if(n==3,10,if(n==2,8,if(n==1,6,if(n==0,4,2*n+4)))))); (A019520(n) = if(n==4,246810,if(n==3,2468,if(n==2,246,if(n==1,24,if(n==0,2,A019520(n-1)*(9*(9*b(n-2)*truncate(c(n-2)/b(n-2))+b(n-2))*truncate((2*n+2)/(9*b(n-2)*truncate(c(n-2)/b(n-2))+b(n-2)))+9*b(n-2)*truncate(c(n-2)/b(n-2))+b(n-2))+2*n+2)))))); (A178500(n) = (10^n)%(10^n+n)) NEW VERSION: (a(n) = local(a1 = A019520(n+50)); local(a2 = A178500(2*n+100)); truncate(a1/a2)-10*truncate(truncate(a1/a2)/10)); (b(n) = if(n==4,100,if(n==3,10,if(n==2,10,if(n==1,10,if(n==0,10,local(b1 = b(n-1)); 9*b1*truncate((2*n+2)/b1)+b1)))))); (c(n) = if(n==4,12,if(n==3,10,if(n==2,8,if(n==1,6,if(n==0,4,2*n+4)))))); (A019520(n) = if(n==4,246810,if(n==3,2468,if(n==2,246,if(n==1,24,if(n==0,2, local(d1 = b(n-2)); local(d2 = c(n-2)); A019520(n-1)*(9*(9*d1*truncate(d2/d1)+d1)*truncate((2*n+2)/(9*d1*truncate(d2/d1)+d1))+9*d1*truncate(d2/d1)+d1)+2*n+2)))))); (A178500(n) = (10^n)%(10^n+n))
To improve the performance of generated PARI code, we should use local variables if sequences terms are computed more than once. Here is an example: