I know may be this could be a duplicate of Extract coefficients of differential form in package RGTC, but the question was not solved and in a sense different from mine. I am going to explain better: I have a differential form written in a symbolic form, with the explicit use of the basis.p = (Cos[2 \[Theta]] (-Cos[\[Alpha]] d[\[Beta]] + d[\[Gamma]]) - I d[\[Theta]]) Sin[2 \[Phi]]) where the basis of the manifold is $\{\alpha,\beta,\gamma,\theta,\phi\}$. Now what I want to do is quite simple. I want a list to convert this expression into a "list-one", $$ p = \{ 0,-\cos \alpha \cos 2\theta \sin 2\phi, \cos 2\theta \sin 2\phi, -i \sin 2\phi, 0\}$$ CoefficientList makes the job but with a lot of zero entries I don't get rid of. Any idea?

======================================================================= Update and generalisation (thanks to @Jens):

Let's say we have a differential $3$-form in $5$ dimensions, $$\omega = \frac{1}{6}\omega_{\mu\nu\rho}\mathrm{d}x^\mu \wedge\mathrm{d}x^\nu \wedge\mathrm{d}x^\rho =\\= \sin (\theta ) \cos (\theta ) \sin (\phi ) \cos (\phi )\mathrm{d}\theta \wedge\mathrm{d}\alpha\wedge \mathrm{d}\beta +2 \cos (2 \theta )\mathrm{d}\alpha \wedge\mathrm{d}\gamma \wedge\mathrm{d}\phi\, . $$ and I want to construct an antisymmetric tensor of rank $3$, which has entries equal to the coeffients, i.e. the tensor (list of lists) $\omega_{\mu\nu\rho}$.

  • $\begingroup$ I asked a similar question here (about how to discard useless elements from lists). $\endgroup$ Commented May 7, 2016 at 15:04

1 Answer 1


This works:

p = (Cos[2 θ] (-Cos[α] d[β] + d[γ]) - I d[θ]) Sin[2 ϕ];

D[p, {Thread[d[{α, β, γ, θ, ϕ}]]}]

==> {0, -Cos[α] Cos[2 θ] Sin[2 ϕ], Cos[2 θ] Sin[2 ϕ], -I Sin[2 ϕ], 0}

Edit in response to modified question

As it stands now, the goal seems to be simply to extract the totally antisymmetric tensor $\omega$ as defined in the question. This can be done by inserting the canonical unit vectors in place of the d[...] in your expression. I am assuming that the entire expression is in fact representable as a single tensor of a rank consistent with the number of factors d[...].

Since Mathematica has the built-in function TensorWedge, the task is very easily achieved if I assume that the input expression also makes use of TensorWedge to write the differential form. So here are some examples of forms to be transformed:

example = 
  Cos[x]^2 TensorWedge[d[x], d[y], d[z]] - 
   Sin[x]^2 TensorWedge[d[y], d[x], d[z]];

example2 = 
  Sin[θ] Cos[θ] Sin[ϕ] TensorWedge[d[θ], 
     d[α], d[β]] + 2 Cos[2 θ] TensorWedge[d[α], d[γ], d[ϕ]];

Now define the function that extracts the coefficients, and apply it to p as defined earlier, and then to the other examples:

diffCoeff[expr_, vars_] := Module[
  {n = Length[vars], rank, dd = Thread[d[vars]]},
  rank = Length[FirstCase[expr, _TensorWedge, {1}, Infinity]];
  TensorReduce[expr /. Thread[dd -> IdentityMatrix[n]]]

diffCoeff[p, {α, β, γ, θ, ϕ}]

{0,-Cos[α] Cos[2 θ] Sin[2 ϕ],Cos[2 θ] Sin[2 ϕ],-I Sin[2 ϕ],0}

exampleTensor = diffCoeff[example, {x, y, z}];

dr = Thread[d[{x, y, z}]]
(* ==> {d[x], d[y], d[z]} *)

Assuming[{x ∈ Reals, d[x] ∈ Arrays[{3}], d[y] ∈ Arrays[{3}], d[z] ∈ Arrays[{3}]}, 
 1/6 Simplify@
    Sum[exampleTensor[[i, j, k]] TensorWedge[dr[[i]], dr[[j]], 
       dr[[k]]], {i, 3}, {j, 3}, {k, 3}]]]

$d[x]\wedge d[y]\wedge d[z]$

Above, I first extracted the coefficient tensor $\omega$ as exampleTensor, and then put it back as a differential form using a straightforward Sum that implements the rule in the question. The simplified result agrees with what is expected.

The last example is copied from the question, and I'll print out the coefficient matrix for it (note that it doesn't contain the factorial factor $1/3!$):

diffCoeff[example2, {α, β, γ, θ, ϕ}] //Normal

{{{0,0,0,0,0},{0,0,0,Cos[θ] Sin[θ] Sin[ϕ],0},{0,0,0,0,2 Cos[2 θ]},{0,-Cos[θ] Sin[θ] Sin[ϕ],0,0,0},{0,0,-2 Cos[2 θ],0,0}},{{0,0,0,-Cos[θ] Sin[θ] Sin[ϕ],0},{0,0,0,0,0},{0,0,0,0,0},{Cos[θ] Sin[θ] Sin[ϕ],0,0,0,0},{0,0,0,0,0}},{{0,0,0,0,-2 Cos[2 θ]},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{2 Cos[2 θ],0,0,0,0}},{{0,Cos[θ] Sin[θ] Sin[ϕ],0,0,0},{-Cos[θ] Sin[θ] Sin[ϕ],0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0}},{{0,0,2 Cos[2 θ],0,0},{0,0,0,0,0},{-2 Cos[2 θ],0,0,0,0},{0,0,0,0,0},{0,0,0,0,0}}}


Antisymmetric[{1, 2, 3}]

Because of the antisymmetry, the large tensor in Normal form can be reduced to a much smaller representation using

exampleTensor2 = 
  diffCoeff[example2, {α, β, γ, θ, ϕ}];


==> {{1, 2, 4} -> 
  Cos[θ] Sin[θ] Sin[ϕ], {1, 3, 5} -> 
  2 Cos[2 θ], {_, _, _} -> 0}

There are only two independent nonzero elements in this representation.

  • $\begingroup$ Thanks, the problem is that I'd like a "general" method working also for the 2-forms (giving a matrix) or a 3-form (giving a 3rd rank tensor). $\endgroup$
    – Oscar
    Commented May 8, 2016 at 14:02
  • $\begingroup$ I think you can just use the generalization at the end of my answer here. $\endgroup$
    – Jens
    Commented May 8, 2016 at 16:09
  • $\begingroup$ Thanks @Jens, but it will not work, since the Hessian is a symmetric matrix... $\endgroup$
    – Oscar
    Commented May 10, 2016 at 9:26
  • $\begingroup$ @Oscar Please let me know if the edit doesn't do what you want. $\endgroup$
    – Jens
    Commented May 17, 2016 at 14:56

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.