Equations with Tensor product and Ket in Mathematica:

I tried to express this equation in Mathematica:

enter image description here

I defined necessary things:

P = {{Ket[0], Ket[2], Ket[1], Ket[3], Ket[5], Ket[4], Ket[6], Ket[8],     Ket[7]}, {Ket[2], Ket[1], Ket[0], Ket[5], Ket[4], Ket[3], Ket[8],     Ket[7], Ket[6]}, {Ket[1], Ket[0], Ket[2], Ket[4], Ket[3], Ket[5],     Ket[7], Ket[6], Ket[8]}, {Ket[6], Ket[8], Ket[7], Ket[0], Ket[2],     Ket[1], Ket[3], Ket[5], Ket[4]}, {Ket[8], Ket[7], Ket[6], Ket[2],     Ket[1], Ket[0], Ket[5], Ket[4], Ket[3]}, {Ket[7], Ket[6], Ket[8],     Ket[1], Ket[0], Ket[2], Ket[4], Ket[3], Ket[5]}, {Ket[a], Ket[c],     Ket[b], Ket[6], Ket[8], Ket[7], Ket[\[Alpha]], Ket[\[Gamma]],     Ket[\[Beta]]}, {Ket[c], Ket[b], Ket[a], Ket[8], Ket[7], Ket[6],     Ket[\[Gamma]], Ket[\[Beta]], Ket[\[Alpha]]}, {Ket[b], Ket[a],     Ket[c], Ket[7], Ket[6], Ket[8], Ket[\[Beta]], Ket[\[Alpha]],     Ket[\[Gamma]]}}  hadamand[\[Omega]_, \[Omega]2_] := {   {1, 1, 1, 1, 1, 1, 1, 1, 1},   {1, \[Omega], \[Omega]2, 1, \[Omega], \[Omega]2,     1, \[Omega], \[Omega]2},   {1, \[Omega]2, \[Omega], 1, \[Omega]2, \[Omega],     1, \[Omega]2, \[Omega]},   {1, 1, 1, \[Omega], \[Omega], \[Omega], \[Omega]2, \[Omega]2, \ \[Omega]2},   {1, 1, 1, \[Omega], \[Omega], \[Omega], \[Omega]2, \[Omega]2, \ \[Omega]2},   {1, \[Omega]2, \[Omega], \[Omega],     1, \[Omega]2, \[Omega]2, \[Omega], 1},   {1, 1, 1, \[Omega]2, \[Omega]2, \[Omega]2, \[Omega], \[Omega], \ \[Omega]},   {1, \[Omega], \[Omega]2, \[Omega]2,     1, \[Omega], \[Omega], \[Omega]2, 1},   {1, \[Omega]2, \[Omega], \[Omega]2, \[Omega], 1, \[Omega],     1, \[Omega]2}   } H = hadamand[\[Omega], \[Omega]^2]  

My attempt is:

A[u_, j_][n_, P_, Had_] :=   1/Sqrt[n] Sum[    TensorProduct[Ket[k], Part[P, k, j]]* Bra[k].Had. Ket[u], {k, 0,      n - 1}]  B[1, 2][9, P, H] 

I obtain: enter image description here

Where is issues?