I would like to calculate following type of contraction:

$$ P_{ij}^{p-k} P_{mn}^{k} ((p_l - k_l) \delta_{ij} + k_j \delta_{il}) (k_n \delta_{lm} - p_m\delta_{ln}) = ? $$ where p,k are d-dimensional vectors and $$ P_{ij}^{k} = \delta_{ij} - \frac{k_ik_j}{k^2}, \quad P_{ij}^{p-k} = \delta_{ij} - \frac{(p_i-k_i)(p_j-k_j)}{(p-k)^2} $$ are projection operators.

First I tried to define projector operators as a function of vector variable k

P[k_] = 1 - TensorProduct[k, k]/k.k

but I cannot figure out how to define a vector function.

Is this even a good idea or is there a better way how to deal with this?

  • $\begingroup$ I think you are better off implementing your own tensor quantities. I.e. sc /: sc[{a_}, {b_}] sc[t_, {a_}] := sc[t, {b}]; so that for example sc[{i},{j}]sc[p,j] will evaluate to sc[p,i]. Btw these projectors look familiar, are you doing some conformal stuff? $\endgroup$
    – Prastt
    Commented Nov 22, 2015 at 1:11
  • $\begingroup$ Welcome to Mathematica.SE! I hope you will become a regular contributor. To get started, 1) take the introductory tour now, 2) 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, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise. $\endgroup$
    – bbgodfrey
    Commented Nov 22, 2015 at 2:18
  • $\begingroup$ Thank you! But no, I am working with stochastic field theory. I am trying to solve tensor structures which appears when you write down field theoretical formulation for navier-stokes equations and try to study its critical dynamics (loop corrections, renormalization, RG) $\endgroup$
    – user35780
    Commented Nov 22, 2015 at 18:26
  • $\begingroup$ Your expression in the tensor above has a misplaced index somewhere — the index $i$ appears three times. If you correct this, I can probably write up some code that will do some of what you want. $\endgroup$ Commented Nov 23, 2015 at 16:28
  • $\begingroup$ In the corrected version, the index $l$ appears three times, so it's still not a valid tensor contraction. $\endgroup$ Commented Aug 4, 2017 at 20:25

1 Answer 1


I have a few suggestions, but I'm not sure about their efficiency. I'm sure that if this is the only thing that you want to compute my suggestion is good enough.

What I do when I have to compute something like this is to use a lot of replacement rules and a dot product. First, define

P[k_,i_,j_]:=delta[i,j] - k[i] k[j]/k^2

For the P[p-k,i,j] term just use a replacement rule (one of many):

P[p - k, i, j]//. {(a_ - b_)[c_] -> a[c] - b[c]}

gives you the desired output.

Now you only need to use replacement rules, for example

k[i] delta[i,j]-> k[j]

is achieved with rule={p_[a_] delta[a_, b_] -> p[b]}

for k^2 rule2={p_[i_] p_[i_]->p^2}

The dimension of your system


You have to make sure to add all the replacement, I just added a few, you need also the case

k[i] delta[j,i]-> k[j]

but now you know how. Finally, you can either keep the use of k[i] p[i] or define a dot product

k[i] p[i]->dot[p,k]

I go for the second, always. If you follow my advise, define P as

P[k_,i_,j_]:=delta[i,j] dot[k,k] - k[i] k[j]

now, when you face your expression, keep in mind that you have to divide for (k^2 (k-p)^2). Why do I use the dot? Because (p-k)^2 is not p^2+k^2-2pk. Mathematica will take p[i]p[i] k[j]k[j] to be the same as p[i]k[i] p[j] k[j] which is wrong. Now it is easier to simplify.



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.