F=(a,b=a)=>a?(b+~a)*F(--a,b-2)+F(a,b)*++b:+!b
Hãy thử trực tuyến!
EnF(n,i)−F(n,i)nF′(n,i)=(−1)nF(n,i)FF′F′(n,i)=(i−n−1)F′(n−1,i−2)+(i+1)F′(n−1,i)
F=(a,b=a)=>a?-F(--a,b)*++b+F(a,b-=3)*(a-b):+!b
Hãy thử trực tuyến!
Ngạc nhiên khi không tìm thấy câu trả lời JavaScript nào, vì vậy tôi sẽ thử.
sech(x)
Giải trình
Tn:=tanhn(t)Sn:=sechn(t)
dnSdtn=∑i=0nF(n,i)Tn−iSi+1
dTdt=S2dSdt=−TS
ddt(TaSb)=aTa−1(S2)(Sb)+bSb−1(−TS)(Ta)=aTa−1Sb+2−bTa+1Sb
b=i+1a=n−i
ddt(Tn−iSi+1)=(n−i)Tn−i−1Si+3−(i+1)Tn−i+1Si+1=(n−i)T(n+1)−(i+2)S(i+2)+1−(i+1)T(n+1)−iSi+1
That is, F(n,i) contributes to both F(n+1,i+2) and F(n+1,i). As a result, we can write F(n,i) in terms of F(n−1,i−2) and F(n−1,i):
F(n,i)=(n−i+1)F(n−1,i−2)−(i+1)F(n−1,i)
with initial condition F(0,0)=1 and F(0,i)=0 where i≠0.
The related part of the code a?-F(--a,b)*++b+F(a,b-=3)*(a-b):+!b
is exactly calculating using the above recurrence formula. Here's the breakdown:
-F(--a,b) // -F(n-1, i) [ a = n-1, b = i ]
*++b // *(i+1) [ a = n-1, b = i+1 ]
+F(a,b-=3) // +F(n-1, i-2) [ a = n-1, b = i-2 ]
*(a-b) // *((n-1)-(i-2)) [ a = n-1, b = i-2 ]
// which is equivalent to *(n-i+1)
Since T(0)=0 and S(0)=1, En equals the coefficient of Sn+1 in the expansion of dnSdtn, which is F(n,n).
For branches that F(0,0) can never be reached, the recurrences always end at 0, so F(n,i)=0 where i<0 or i is odd. The latter one, particularly, implies that En=0 for all odd ns. For even is strictly larger than n, the recurrence may eventually allow 0≤i≤n to happen at some point, but before that step it must reach a point where i=n+1, and the recurrence formula shows that the value must be 0 at that point (since the first term is multiplied by n−i+1=n−(n+1)+1=0, and the second term is farther from the "triangle" of 0≤i≤n). As a result, F(n,i)=0 where i>n. This completes the proof of the validity of the algorithm.
Extensions
The code can be modified to calculate three more related sequences:
Tangent Numbers (46 bytes)
F=(a,b=a)=>a?F(--a,b)*++b+F(a,b-=3)*(a-b):+!~b
Secant Numbers (45 bytes)
F=(a,b=a)=>a?F(--a,b)*++b+F(a,b-=3)*(a-b):+!b
Euler Zigzag Numbers (48 bytes)
F=(a,b=a)=>a?F(--a,b)*++b+F(a,b-=3)*(a-b):!b+!~b
-i/2
, sẽ sinh ra-i
khi thêm vào. Nhân số đó vớii
bên ngoài của tổng kết, và bạn nhận được1
.