# SageMath code for the centralizer of so(p,q)

** Published :**

# Centralizer of $\mathfrak{so}_{p,q}(\mathbb{R})$

This notebook describe a SageMath script designed to compute the centralizer of the real Lie algebra $ \mathfrak{so}*{p,q} $ considered as a sub-algebra of $\mathfrak{gl}*{p+q}(\mathbb{R})$.

We drop the notation $\mathbb{R}$ and set $n=p+q$ for simplicity.

```
# Define dimensions
p = 2; q = 2;
m = p + q; d = (m*(m-1))/2;
```

Let $E_{i,j}\in\mathfrak{gl}*n$ be the matrix whose $(i,j)$ entry is $1$ and all others are $0$. A common basis of $\mathfrak{so}*{p,q}$ is given by,

```
S = {} # basis for so(p,q)
k = 1
for i in range(0, p-1): # A_{i,j} = E_{i,j} - E_{j,i} \forall 1 \leq i < j \leq p
for j in range(i+1, p):
A = matrix(m)
A[i,j] = 1
S[k] = A - A.transpose()
k = k + 1
for i in range(p, m-1): # D_{i,j} = E_{i,j} - E_{j,i} \forall p+1 \leq i < j \leq m
for j in range(i+1, m):
A = matrix(m)
A[i,j] = 1
S[k] = A - A.transpose()
k = k + 1
for i in range(0, p): # B_{i,j} = E_{i,j} + E_{j,i} \forall 1\leq i\leq p, p+1\leq j\leq m
for j in range(p, m):
A = matrix(m)
A[i,j] = 1
S[k] = A + A.transpose()
k = k + 1
```

Let $X$ be an element of the centralizer, then certainly $X$ commutes with every element of the basis.

```
# Define commutators equations
x = var(['x_%d%d' %(i,j) for (i,j) in cartesian_product([range(1,m+1), range(1,m+1)])]);
X = matrix(SR, m, m, x)
E = {} # set of equations
J = {} # set of jacobian
for k in range(1, d+1):
E[k] = X*S[k] - S[k]*X
J[k] = jacobian(E[k].list(), x)
eqns = [] # list of equations
for k in range(1, d+1):
eqns = eqns + [(J[k]*vector(SR, x))[n] == 0 for n in range(m*m)]
```

We now just solve the equations and substitute the solution in $X$ to get a common representation of the centralizer.

```
# solve equations
sol = solve(eqns, x)
print X.subs(sol)
```

```
[r2 0 0 0]
[ 0 r2 0 0]
[ 0 0 r2 0]
[ 0 0 0 r2]
```

This code is consistent with the following result,