1 | initial version |

It is arguable, that

```
lambda n: 2*n^2-1 # if n in ZZ and n > 0 else None
```

is the solution getting the full score in an exam. (But this is always a good test for the sense of humor of the examiner. And for the own courage in real life.)

Instead, we may translate as follows from the Italian:

Write a function in Sage that computes the matrix of the linear map $F$, written in suitable bases,

from the space $V_A\times V_B$, where $V_A=V_A(n)$, $V_B=V_B(n)$ are two copies of $M_n(R)$

to the space $W=W(n)$ of endomorphisms of $M_n(R)$,

constructed as follows: For $A\in V_A$ and $B\in V_B$ we associate $F(A,B) = F(A,0)+F(0,B)$ which acts on a matrix $X$ as follows: $F(A,B)(X)=AX+XB$.

Then compute the rank for some small values of n.

My choice of the bases is as follows. Let $E_A(j,k)$ be the standard generators of $V_A$. And $E_B(j,k)$ be the standard generators of $V_B$. It is clear that the family of $2n^2$ endomorphisms in $W$ of the shape $F(\ E_A(j,k), 0\ )$ and $F(\ 0,E_B(j,k)\ )$ generate the image of $F$. We associate the matrix for them and the standard generators of $W$, which are the homomorphisms $E(\ (s,t)\to(u,v)\ )$ mapping all standard generators to zero, except for $E(s,t)$, which is mapped to $E(u,v)$.

It is clear now, that a non-trivial liniar combination leads to an equation of the shape $AX+XB\equiv 0$, an identity in $X$. ($A$ and $B$ come by assembling the coefficients in the non-trivial linear combination.) This is the case only for $A=-B$ a diagonal matrix. So the dimension of the kernel is one. The following lines compute the matrix explicitly, and the rank is as expected. The programmer has no problems with the linear algebra, but rather with the reshaping of a matrix as a vector.

```
def FMatrix( n ):
R = range(n)
A = matrix( QQ, n^4, n^2+n^2 )
count_columns = 0
for j, k in cartesian_product( [R, R] ):
# the elementary matrix (j,k) acts on the vector of morphisms ( (s,t) -> (u,v) )
# first of all from the left, then from the right,
# from the left
count_rows = 0
for s, t, u, v in cartesian_product( [R,R,R,R] ):
# is (j,k) o (s,t) = (u,v) ?
if j == u and k == s and t == v:
A[ count_rows, count_columns ] = 1
count_rows += 1
count_columns += 1
# from the right
count_rows = 0
for s, t, u, v in cartesian_product( [R,R,R,R] ):
# is (s,t) o (j,k) = (u,v) ?
if s == u and t == j and k == v:
A[ count_rows, count_columns ] = 1
count_rows += 1
count_columns += 1
return A
for n in [1..4]:
print "Dimension of W(%s) is: %s" % ( n, FMatrix(n).rank() )
```

And after a short thrill:

```
Dimension of W(1) is: 1
Dimension of W(2) is: 7
Dimension of W(3) is: 17
Dimension of W(4) is: 31
```

2 | No.2 Revision |

It is arguable, that

```
lambda n: 2*n^2-1 # if n in ZZ and n > 0 else None
```

is the solution getting the full score in an exam. (But this is always a good test for the sense of humor of the examiner. And for the own courage in real life.)

Instead, we may translate as follows from the Italian:

Write a function in Sage that computes the matrix of the linear map $F$, written in suitable bases,

from the space $V_A\times V_B$, where $V_A=V_A(n)$, $V_B=V_B(n)$ are two copies of $M_n(R)$

to the space $W=W(n)$ of endomorphisms of $M_n(R)$,

constructed as follows: For $A\in V_A$ and $B\in V_B$ we associate $F(A,B) = F(A,0)+F(0,B)$ which acts on a matrix $X$ as follows: $F(A,B)(X)=AX+XB$.

Then compute the rank for some small values of n.

My choice of the bases is as follows. Let $E_A(j,k)$ be the standard generators of $V_A$. And $E_B(j,k)$ be the standard generators of $V_B$. It is clear that the family of $2n^2$ endomorphisms in $W$ of the shape $F(\ E_A(j,k), 0\ )$ and $F(\ 0,E_B(j,k)\ )$ generate the image of $F$. We associate the matrix for them and the standard generators of $W$, which are the homomorphisms $E(\ (s,t)\to(u,v)\ )$ mapping all standard generators to zero, except for $E(s,t)$, which is mapped to $E(u,v)$.

It is clear now, that a non-trivial liniar combination leads to an equation of the shape $AX+XB\equiv 0$, an identity in $X$. ($A$ and $B$ come by assembling the coefficients in the non-trivial linear combination.) This is the case only for $A=-B$ a diagonal matrix, moreover a scalar times unit matrix. (This was exactly my first exercise in von Neuman algebras.) So the dimension of the kernel is one. The following lines compute the matrix explicitly, and the rank is as expected. The programmer has no problems with the linear algebra, but rather with the reshaping of a matrix as a vector.

```
def FMatrix( n ):
R = range(n)
A = matrix( QQ, n^4, n^2+n^2 )
count_columns = 0
for j, k in cartesian_product( [R, R] ):
# the elementary matrix (j,k) acts on the vector of morphisms ( (s,t) -> (u,v) )
# first of all from the left, then from the right,
# from the left
count_rows = 0
for s, t, u, v in cartesian_product( [R,R,R,R] ):
# is (j,k) o (s,t) = (u,v) ?
if j == u and k == s and t == v:
A[ count_rows, count_columns ] = 1
count_rows += 1
count_columns += 1
# from the right
count_rows = 0
for s, t, u, v in cartesian_product( [R,R,R,R] ):
# is (s,t) o (j,k) = (u,v) ?
if s == u and t == j and k == v:
A[ count_rows, count_columns ] = 1
count_rows += 1
count_columns += 1
return A
for n in [1..4]:
print "Dimension of W(%s) is: %s" % ( n, FMatrix(n).rank() )
```

And after a short thrill:

```
Dimension of W(1) is: 1
Dimension of W(2) is: 7
Dimension of W(3) is: 17
Dimension of W(4) is: 31
```

Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.