Finding trivial solutions, of the type 0 = 0, of an equation involving su(N) structure constants

so I have a bunch of equations $f_{abc} = f_{egd}m_{ae}m_{bg}m_{cd}$ (sum over repeated indices), where $f_{abc}$ are the structure constants of $su(N)$, for some $N$, and $m_{ab}$ are elements of some matrix. I want to find how many of the $(N^2 -1)\times(N^2 -1)\times(N^2 -1)$ equations above are trivial, meaning that we have 0 at both sides. I did this for $su(3)$ with the code below, and I got the expected answer (I basically used this code to build the struture constants). Firts I define B = 0 as the variable that will do the counting, then

For[i = 1, i <= 8, i++,
For[j = 1, j <= 8, j++,
For[k = 1, k <= 8, k++,
If[SU3f[i, j, k] == 0,
If[Sum[SU3f[l, r, n]*M[[i, l]]*M[[j, r]]*M[[k, n]], {l, 1, 8}, {r,
1, 8}, {n, 1, 8}] == 0, B = B + 1]]]]]


This gives B = 176 or something like that in the end. Now, when I do the same thing for $su(4)$ and $su(5)$, only changing the generators and dimensions, I end up with B = 0, no equations are trivial, which I find a bit odd. My question is, does my code looks like it does what I want it to do? Is this a good way to do what I described, or is there a better way? Thanks in advance.

• Almost never use For since Table is preferable. Never use upper-case letters at the beginning of a variable name (B, M, SU3f) as this may conflict with Mathematica's naming conventions. I suspect you're a C++ programmer and are quite unaware of the style and syntax of Mathematica. – David G. Stork Jan 17 '18 at 0:03
• You'll probably get better answers if you post the actual code you used. At a guess (which is all I can do without the code), I'd try using Simplify, PossibleZeroQ, or something like that, because sometimes complicated expressions don't get simplified all the way. – aardvark2012 Jan 17 '18 at 0:05
• Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! – Michael E2 Jan 17 '18 at 0:34
• @DavidG.Stork Yes, I'm used to work with C/C++ only, and I'm new to Mathematica. Thanks for the tips. – l_xavier Jan 17 '18 at 13:25
• @aardvark2012 The code is just the one that I posted. The only missing part is the definition of the structure constants that is in the link I also posted. Thanks for the tips. – l_xavier Jan 17 '18 at 13:32