Pensieve header: Figuring out the commutation relations of sl(3).

sl3rule={h1->(({{1, 0, 0}, {0, -1, 0}, {0, 0, 0}})), h2->(({{0, 0, 0}, {0, 1, 0}, {0, 0, -1}})),e1->(({{0, 1, 0}, {0, 0, 0}, {0, 0, 0}})),e2->(({{0, 0, 0}, {0, 0, 1}, {0, 0, 0}})),e3->(({{0, 0, 1}, {0, 0, 0}, {0, 0, 0}})),f1->(({{0, 0, 0}, {1, 0, 0}, {0, 0, 0}})),f2->(({{0, 0, 0}, {0, 0, 0}, {0, 1, 0}})),f3->(({{0, 0, 0}, {0, 0, 0}, {1, 0, 0}}))}

InverseRule[rules_List][m_] := Module[{k,s,a,g},
k=0; s=Sum[a[++k]g, {g,First/@rules}];
s /. First@Solve[
Thread[Flatten[s /. rules]==Flatten[m]]
]
];

B[x_,y_]:=InverseRule[sl3rule][x.y-y.x/.sl3rule]

{B[h1,e1], B[h1,f1], B[e1,f1]}

{B[h2,e2], B[h2,f2], B[e2,f2]}

{B[h1,e3], B[h1,f3], B[e3,f3]}

{B[h1+h2,e3], B[h1+h2,f3], B[e3,f3]}

{B[e1,e2], B[e1,e3], B[e2,e3]}

{B[f1,f2], B[f1,f3], B[f2,f3]}

{B[e1,f2], B[e1,f3], B[e2,f3]}