	(* do Dirac and Weyl algebra in components *)

sigmabar[0] = {{1, 0}, {0, 1}};
sigmabar[1] = {{0, 1}, {1, 0}};
sigmabar[2] = {{0, -I}, {I, 0}};
sigmabar[3] = {{1, 0}, {0, -1}}

epsilon = {{0, 1}, {-1, 0}}

sigma[0] = sigmabar[0];
sigma[i_] = -sigmabar[i]

null = {{0, 0}, {0, 0}}

	(* rearrange a 2x2 matrix of 2x2 matrices into a 4x4 matrix *)
to4[ mat_ ] :=
Block[ {tens},
  tens = Transpose[mat, {1, 3, 2, 4}];
  Partition[tens//Flatten, 4]
]

	(* this is the Weyl = chiral representation *)
Array[ (ga[#] = {{null, sigma[#]}, {sigmabar[#], null}}//to4)&, 4, 0 ]

unity = {{sigma[0], null}, {null, sigma[0]}}//to4

ga[5] = {{sigma[0], null}, {null, -sigma[0]}}//to4


metric[0] = 1

metric[1|2|3] = -1

Contract[a_, b_] := Plus@@ Array[a[#] b[#] metric[#] &, 4, 0]


Lor[i_][j_] := metric[j] Delta[lor[i], j]

Delta[i_Integer, i_Integer] = 1

Delta[i_Integer, j_Integer] = 0

	(* representations for the 4-dim objects *)

Rep4[ Spinor[k[n_], m_, 1] ] := Array[u[n], 4]

Rep4[ Spinor[k[n_], m_, -1] ] := Array[v[n], 4]

Rep4[ Bar[s_Spinor] ] := Conjugate[Rep4[s]] . ga[0]

Rep4[ 1 ] = unity

Rep4[ 5 ] = ga[5]

Rep4[ 6 ] = (unity + ga[5])/2

Rep4[ 7 ] = (unity - ga[5])/2

Rep4[ Lor[mu_] ] := ga[lor[mu]]

Rep4[ vec:(k|e|s)[_] ] := Contract[ga, vec]

Rep4[ Eps[p__] ] := I Det[Array[#, 4, 0]&/@ {p}]

Rep4[ Pair[a_, b_] ] := Contract[a, b]

Rep4[ DiracChain[s_, gam___] ] := Rep4/@ (Bar[s] . gam)


	(* representations for the 2-dim objects *)

Rep2[ s_Spinor[6] ] := Take[Rep4[s], 2]

Rep2[ s_Spinor[7] ] := Drop[Rep4[s], 2]

Rep2[ s_Spinor[-6] ] := Take[Conjugate[Rep4[s]], 2]

Rep2[ s_Spinor[-7] ] := Drop[Conjugate[Rep4[s]], 2]

Rep2[ eps ] = epsilon

Rep2[ sig[Lor[mu_]] ] := sigma[lor[mu]]

Rep2[ sigbar[Lor[mu_]] ] := sigmabar[lor[mu]]

Rep2[ sig[vec_] ] := Contract[sigma, vec]

Rep2[ sigbar[vec_] ] := Contract[sigmabar, vec]

Rep2[ WeylSimp[w__] ] := Rep2[ WeylChain[w] ]

Rep2[ WeylTrace[w__] ] := Tr[Rep2[ WeylChain[w] ]]

Rep2[ WeylChain[w__] ] := Rep2/@ Dot[w]


Rep[ p_Plus ] := Rep/@ p

Rep[ expr_ ] :=
Block[ {ind, sign, lor},
  ind = Cases[expr, Lor[n_] -> n, Infinity]//Union;
  sign = Times@@ (metric[lor[#]]&)/@ ind;
  IndexSum[sign expr, {lor[#], 0, 3}&/@ ind] //Expand
]


obj4 = DiracChain | Pair | Eps

obj2 = WeylChain | WeylSimp | WeylTrace


IndexSum[expr_, {ind___}] :=
  Sum[expr /. {d:obj4[__] :> Rep4[d], w:obj2[__] :> Rep2[w]}, ind]


Unprotect[Conjugate];
Format[ Conjugate[x_] ] := SequenceForm[x, Superscript["*"]];
Protect[Conjugate]

(Format[ #[n_][mu_] ] := SubsuperscriptBox[#, n, mu]//DisplayForm)&/@
  {u, v, k, e}


(* try it: *)

d1 = DiracChain[Spinor[k[1], ME, -1], 7, Lor[1], Spinor[k[2], ME, 1]]

d2 = DiracChain[Spinor[k[4], MT, 1], 7, Lor[1], Spinor[k[3], MT, -1]]

Sum[ metric[lor[1]] Rep4[d1] Rep4[d2], {lor[1], 0, 3} ]

