Find the weights of the fundamental 3x3 representation

Define the SU(3) generators matrices λ

First define a matrix of zeroes, which will serve as basis to define the λ matrices of SU(3) by just changing the value of some elements that are not zero.

Lambda0 = SparseArray[{}, {3,3}]

MatrixForm[Lambda0]

Lambda$I$3x3=SparseArray[{i_,i_}->1,3]

Lambda$I$3x3//MatrixForm

asso=<|{1,2}->3|>

asso[{1,2}]

Lambda[list_]:= c(1/(Sqrt[2]))*SparseArray[list, 3]

Lambda=Lambda0
Lambda[[1,2]]=1
Lambda[[2,1]]=1
λ[1]=c(1/(Sqrt[2]))Lambda

Lambda=Lambda0;
Lambda[[1,2]]=-I;
Lambda[[2,1]]=I;
λ[2]=c(1/(Sqrt[2]))Lambda;

Lambda=Lambda0;
Lambda[[1,1]]=1;
Lambda[[2,2]]=-1;
λ[3]=c(1/(Sqrt[2]))Lambda;

Lambda=Lambda0;
Lambda[[1,3]]=1;
Lambda[[3,1]]=1;
λ[4]=c(1/(Sqrt[2]))Lambda;

Lambda=Lambda0;
Lambda[[1,3]]=-I;
Lambda[[3,1]]=I;
λ[5]=c(1/(Sqrt[2]))Lambda;

Lambda=Lambda0;
Lambda[[3,2]]=1;
Lambda[[2,3]]=1;
λ[6]=c(1/(Sqrt[2]))Lambda;

Lambda=Lambda0;
Lambda[[3,2]]=-I;
Lambda[[2,3]]=I;
λ[7]=c(1/(Sqrt[2]))Lambda;

Lambda=Lambda0;
Lambda[[1,1]]=1;
Lambda[[2,2]]=1;
Lambda[[3,3]]=-2;
λ[8]=c(1/(Sqrt[6]))Lambda;

λ[1]=Lambda[{{1,2}->1,{2,1}->1}];
λ[2]=Lambda[{{1,2}->-I,{2,1}->I}];
λ[3]=Lambda[{{1,1}->1,{2,2}->-1}];
λ[4]=Lambda[{{1,3}->1,{3,1}->1}];
λ[5]=Lambda[{{1,3}->-I,{3,1}->I}];
λ[6]=Lambda[{{2,3}->1,{3,2}->1}];
λ[7]=Lambda[{{2,3}->I,{3,2}->-I}];
λ[8]=(1/(Sqrt[3]))Lambda[{{1,1}->1,{2,2}->1,{3,3}->-2}];
Table[ MatrixForm[λ[i]], {i,1,8}]

AlgebraTable[λ]//MatrixForm

1/(Sqrt[3]){{1,0,0},{0,1,0},{0,0,-2}}
Tr[%.%]
%%//MatrixForm

Replace[λ[8],c->1]//MatrixForm

Define the most convenient SU(3) generators matrices

e[1]=λ[1]+I*λ[2]
e[2]=λ[1]-I*λ[2]
e[3]=λ[3]
e[4]=λ[4]+I*λ[5]
e[5]=λ[4]-I*λ[5]
e[6]=λ[6]+I*λ[7]
e[7]=λ[6]-I*λ[7]
e[8]=λ[8]

Table[SparseArray[
    Table[Tr[Commutator[e, i, j].ConjugateTranspose[e[k]]], {k, 1, 8}]
    ]["NonzeroPositions"]
  , {i, 1, 8}, {j, 1, 8}] // MatrixForm

AlgebraTable[e] //MatrixForm

Check the matrices we have defined

Table[e[i] // MatrixForm, {i, 1, 8}]

Table[λ[i]//MatrixForm,{i,1,8}]

Table[Tr[λ[i]],{i,1,8}]

we have defined them as to have all same trace

Tr (Subscript[λ, i])(Subscript[λ, j])=(c^2) (Subscript[δ, ij])

Table[Tr[λ[i].λ[j]],{i,1,8},{j,1,8}]//MatrixForm

2*ToExpression["3.0"]

Table["[i="<>ToString[i]<>", j="<>ToString[j]<>"]", {i, 1, 4}, {j, 1, 8}] // MatrixForm

λ[8]//MatrixForm

The commutator

First define a function that is convenient to compute any commutator of elements i and j of a list of matrices λ

Commutator[λ_, i_, j_] := λ[i].λ[j] - λ[j].λ[i]

Make explicitly a table of the (Subscript[C, ij])=[(Subscript[λ, i]),(Subscript[λ, j])]

Table[λ[i].λ[j]-λ[j].λ[i],{i,1,8},{j,1,8}]//MatrixForm

Make a table of the (Subscript[C, ij])=[(Subscript[λ, i]),(Subscript[λ, j])] using the function as to test it is working properly.

Table[Commutator[λ,i,j],{i,1,8},{j,1,8}]//MatrixForm

The table of commutators

Use trace as a scalar product of matrices to identify along which directions in the space of generators each (Subscript[C, ij]) is directed. E.g. if 
					(Subscript[C, ij])=[(Subscript[λ, i]),(Subscript[λ, j])]∝(Subscript[λ, k])
I will find that 
						Tr {(Subscript[C, 12])((Subscript[λ, k])^T)}= (Subscript[δ, k3])

Table[Table[Tr[Commutator[λ,i,j].Transpose[λ[k]]],{k,1,8}],{i,1,8},{j,1,8}]//MatrixForm

Check the proportionality of each commutator to each element of the set of matrices. The property “NonzeroPositions” of a SparseArray tells us which are not zero.

Table[SparseArray[
Table[Tr[Commutator[λ,i,j].ConjugateTranspose[λ[k]]],{k,1,8}]
]["NonzeroPositions"]
,{i,1,8},{j,1,8}]//MatrixForm

Table[
Position[Table[Tr[Commutator[λ,i,j].ConjugateTranspose[λ[k]]],{k,1,8}],x_/;!TrueQ[x==0],{1},Heads->False]
,{i,1,8},{j,1,8}]//MatrixForm

Make a function that encapsulates all this for a generic set of matrices. This will require a function that finds how many elements are not zero in the list of matrices 1...N

FunctionLength[τ_] := Block[{$i},
    For[$i = 1, Head[τ[$i]] == List || Head[τ[$i]] == SparseArray, $i++]; $i - 1]

and the encapsulated functions, including an option to do or not to do the identification of the non-zero coefficients (useful to check normalizations)

Clear[AlgebraTable]
Options[AlgebraTable] = {Treatment -> PositionNonZero}
AlgebraTable[τ_, opt : OptionsPattern[]] := Table[
  OptionValue[Treatment][
   Table[Tr[
       Commutator[τ, i, j].ConjugateTranspose[τ[k]]
       ], {k, 1, FunctionLength[τ]}
    ]], {i, 1, FunctionLength[τ]}, {j, 1, FunctionLength[τ]}]

which uses

PositionNonZero[list_] := Position[list, x_ /; ! TrueQ[x == 0], {1}, Heads -> False]

AlgebraTable[λ] // MatrixForm

Sub-algebras

Let’s check the SU(2) sub-algebra

Table[
  Position[Table[Tr[Commutator[λ, i, j].Transpose[λ[k]]], {k, 1, 8}], x_ /; ! TrueQ[x == 0], {1}, Heads -> False]
  , {i, 1, 3}, {j, 1, 3}] // MatrixForm

Let’s check the Cartan sub-algebra

Table[
  Position[Table[Tr[Commutator[λ, i, j].Transpose[λ[k]]], {k, 1, 8}], x_ /; ! TrueQ[x == 0], {1}, Heads -> False]
  , {i, {3, 8}}, {j, {3, 8}}] // MatrixForm

From Cartan Sub-algebra obtain the weights of the fundamental (3-dim representation)

Let us define an element of the {3,8} sub-space, that we found is the Cartan Sub-Algebra

h[a_,b_]:=a*λ[3]+b*λ[8]

h[a,b]//MatrixForm

For our 3-by-3 representation made of matrices we can take basis of the vector space onto which the matrices work the following vectors

ϕ:=SparseArray[{i_,j_}->KroneckerDelta[i,j],3]

Table[ϕ[[i]]//MatrixForm,{i,1,3}]

The eigen-values 
				H (ϕ^a) = (M^a)(h) (ϕ^a)
of each of these vectors are

Table[ϕ[[k]].h[a,b].ϕ[[k]]//MatrixForm,{k,1,3}]

let’s find the coefficient of a and b in each expression (this will be a row for a and a row for b, hence a 2-by-2 matrix)

Table[CoefficientList[ϕ[[k]].h[a,b].ϕ[[k]],{a,b}],{k,1,3}]

Tr[{{a,b},{c,d}},Plus,1]

Table[Tr[CoefficientList[ϕ[[k]].h[a,b].ϕ[[k]],{a,b}],Plus,1],{k,1,3}]
%/.c->1(*/(Sqrt[2])*)
Map[{{0,0},#}&,%]
Graphics[Arrow[%]]

Find the adjoint and its weights

The adjoint for generic NxN matrices

Clear[Ad]
Ad[k_,$λ_] := Table[
Tr[
   Commutator[$λ, k, j].ConjugateTranspose[ $λ[i] ]
]
   , {i, 1, FunctionLength[$λ]}, {j, 1, FunctionLength[$λ]}]

Ad[3, e]/. c->1/(Sqrt[2])// MatrixForm

Table[Ad[i, e]//MatrixForm,{i,1,8}]

Table[Tr[Commutator[e, i, j].ConjugateTranspose[e[3]]],{i, 1, 8}, {j, 1, 8}]/.c->1//MatrixForm

ad[i_]:=Ad[i, e]/.c->1

AlgebraTable[e]//MatrixForm

AlgebraTable[ad] // MatrixForm

Clear[AdTwist]
AdTwist[k_,$λ_] := Table[
Tr[
   Commutator[$λ, i, j].ConjugateTranspose[ $λ[k] ]
]
   , {i, 1, FunctionLength[$λ]}, {j, 1, FunctionLength[$λ]}]

adTwist[i_]:=AdTwist[i, e]/.c->1

AlgebraTable[adTwist] // MatrixForm