Construct SU(N) generators

ClearAll[SUNGenerators];

SUNGenerators[n_Integer/;n>=2]:=Module[{sym,asym,diag},(*1. Symmetric (Off-Diagonal) Matrices*)sym=Flatten[Table[Normal@SparseArray[{{j,k}->1,{k,j}->1},{n,n}],{j,1,n-1},{k,j+1,n}],1];
(*2. Antisymmetric (Off-Diagonal) Matrices*)asym=Flatten[Table[Normal@SparseArray[{{j,k}->-I,{k,j}->I},{n,n}],{j,1,n-1},{k,j+1,n}],1];
(*3. Diagonal Matrices*)diag=Table[Sqrt[2/(m*(m+1))]*Normal@SparseArray[Join[Table[{i,i}->1,{i,1,m}],{{m+1,m+1}->-m}],{n,n}],{m,1,n-1}];
(*Combine all matrices into a single list*)Join[sym,asym,diag]]

SUNGen=SUNGenerators[4];

(*The generators of SU(N)*)
MatrixForm/@SUNGen

(*Verify the number of generators ((N^2)-1)*)
Length[SUNGen]

(*Verify they are traceless (Tr((Subscript[T, a]))=0)*)
Tr/@SUNGen

(*Verify the normalization (Tr((Subscript[T, a])(Subscript[T, b]))=2(Subscript[δ, ab]))*)
Table[Tr[SUNGen[[i]].SUNGen[[i]]],{i,1,Length[SUNGen]}]

Fundamental representation, structure constants, and d-coefficients

(*Physics convention*)
tGens=SUNGen/2;

(*Define functions for individual coefficients*)(*Commutator:[A,B]=A.B-B.A*)fCoeff[a_,b_,c_,gens_]:=Simplify[-2 I*Tr[(gens[[a]].gens[[b]]-gens[[b]].gens[[a]]).gens[[c]]]]

(*Anticommutator:{A,B}=A.B+B.A*)
dCoeff[a_,b_,c_,gens_]:=Simplify[2*Tr[(gens[[a]].gens[[b]]+gens[[b]].gens[[a]]).gens[[c]]]]

(*3. Define functions to extract all non-zero coefficients*)
(*We use select to filter out the zeros,and only look at unique combinations*)
NonZeroF[gens_]:=Module[{dim=Length[gens],result={}},Do[(*Because f_abc is completely antisymmetric,we only need a<b<c*)If[a<b<c,With[{val=fCoeff[a,b,c,gens]},If[val!=0,AppendTo[result,{"f",a,b,c,"->",val}]]]],{a,1,dim},{b,1,dim},{c,1,dim}];
result]

NonZeroD[gens_]:=Module[{dim=Length[gens],result={}},Do[(*Because d_abc is completely symmetric,we only need a<=b<=c*)If[a<=b<=c,With[{val=dCoeff[a,b,c,gens]},If[val!=0,AppendTo[result,{"d",a,b,c,"->",val}]]]],{a,1,dim},{b,1,dim},{c,1,dim}];
result]

(*Calculate a specific structure constant*)
fCoeff[1,2,3,tGens]
dCoeff[1,2,4,tGens]

(*List all non-zero structure constants for SU(N)*)
Grid[NonZeroF[tGens],Frame->All]

(*List all non-zero d-coefficients for SU(N)*)
Grid[NonZeroD[tGens],Frame->All]