# Half kth term if n is even and k=n/2?

I am trying to write a function which will perform the equation in the attached image. So far, I have:

x[n_] :=
x[n] =
2^(1 - n) Sum[Binomial[n, k] T[n - 2 k], {k, 0, n/2}]

x[6]


which outputs:

$\frac{1}{32} (20 T(0)+15 T(2)+6 T(4)+T(6))$

How can I write an If[] (or similar) statement to half the kth term when n is even and k=n/2? Thanks in advance!

-

You can write it like this:-

x[n_] :=
x[n] =
2^(1 - n) Sum[Binomial[n, k] T[n - 2 k]/If[EvenQ[n] && k == n/2, 2, 1],
{k, 0, n/2}]

x[6]


1/32 (10 T[0] + 15 T[2] + 6 T[4] + T[6])

-

I'd like to suggest a solution that makes use of pattern matching - the (to me) a little awkward phrasing 'if n is even and k=n/2 simply means the following:

In the case of even n (as Floor[n/2] == n/2 if EvenQ[n]==True), run the sum to n-1 (as k==n/2 means 'the last term' in this case) and add the last term (which is 2^(-n) Binomial[n, n/2] T[0] manually.

So:

x[n_] := 2^(1 - n) Sum[Binomial[n, k] T[n - 2 k], {k, 0, n/2}]
x[n_/; EvenQ[n]] := x[n-1] + 2^(-n) Binomial[n,n/2] T[0]

-

I think an elegant way is using PieceWise:

x[n_] := 2^(1 - n) Sum[
Piecewise[{{1/2, EvenQ[n] && k == n/2}, {1, True}}] Binomial[n, k] T[n - 2 k], {k, 0, n/2}]


so the first six terms are:

x /@ Range[6]


-