# [seqfan] Re: Help needed with Mathematica program for square array with two linked recurrences.

Olivier Gerard olivier.gerard at gmail.com
Sun Jul 10 13:53:39 CEST 2011

```Mats,

Further comments: this is closer to the version you had in mind.
Note that you don't need to clear i,n,k.  Sum and Table variables
are scoped and declarative variables as well.
Which is more elegant than cascading Ifs

Clear[t]
t[1, 1] = 1;
t[2, 1] = t[1, 2] = 2;
t[n_Integer, k_Integer] := t[n, k] = Which[
n == 1, (-t[n, k - 1] - Sum[t[i, k], {i, 2, k - 1}])/(k + 1) + t[n, k -
1],
k == 1, (-t[n - 1, k] - Sum[t[n, i], {i, 2, n - 1}])/(n + 1) + t[n - 1,
k],
n >= k, -Sum[t[n - i, k], {i, 1, k - 1}],
True, -Sum[t[k - i, n], {i, 1, n - 1}]
];

MatrixForm[Array[t, {12, 12}]]

On Sun, Jul 10, 2011 at 10:45, Mats Granvik <mgranvik at abo.fi> wrote:

> Clear[t, n, k, i, nn]
>  t[n_, k_] :=
>   t[n, k] =
>    If[And[n == 1, k == 1], 1,
>     If[Or[And[n == 1, k == 2], And[n == 2, k == 1]], 2,
>      If[n == 1, (-t[n, k - 1] - Sum[t[i, k], {i, 2, k - 1}])/(k + 1) + t[n,
> k - 1],
>       If[k == 1, (-t[n - 1, k] - Sum[t[n, i], {i, 2, n - 1}])/(n + 1) + t[n
> - 1, k],
>        If[n >= k, -Sum[t[n - i, k], {i, 1, k - 1}], -Sum[t[k - i, n], {i,
> 1, n - 1}]]]]]];
>  nn = 12;
>
>  MatrixForm[Table[Table[t[n, k], {k, 1, nn}], {n, 1, nn}]]
>

```