0
$\begingroup$

For a physics application, I have to compute components of a rank-4 tensor, the Riemann tensor. I do this using a module (subroutine) which looks like this

Riemann[mu,nu,rho,sigma] = Module[{a=mu,b=nu,c=rho,d=sigma},Coefficient[(*expression1*), (*expression2*)]

(I have suppressed the details of expression 1 and expression 2 for clarity, as they are not relevant to my question. But it suffices to say that to extract the component of the tensor, I am picking out the coefficient of some term in another expression. This extraction works, as I have tested it for many cases.)

So when I call Riemann[1,2,3,4] (say), I get an expression, which is correct.

However, what I want is to dump it into an array, using for example:

dim = 11
RiemannArray = Array[ Riemann[#1,#2,#3,#4]&, {dim,dim,dim,dim} ]

If this worked, I would have been able Riemann[mu,nu,rho,sigma] stored in RiemanArray[[mu,nu,rho,sigma]].

However, what I get is a series of errors of the form:

Coefficient::ivar: 0 is not a valid variable. General::stop: Further output of Coefficient::ivar will be suppressed during this calculation.

Even if I remove the evaluation of the tensor components from a module and put it as an inline statement inside Array[...], I get the same set of errors.

Is there a way out of this?

Note that if I ignore these errors, the array seems to have been created.

$\endgroup$
  • 1
    $\begingroup$ It looks like the error is from the Coefficient in your definition of Riemann, not from the creation of your array which, as you say, seems to work fine. Something odd might be going on with your definition of Riemann, which you could clean up as Riemann[mu_, nu_, rho_, sigma_] := Module[ *etc* ]. $\endgroup$ – aardvark2012 Jul 28 '17 at 3:08
  • $\begingroup$ Hi @aardvark2012, thanks for your reply. On the contrary, the Module works fine -- all calls to it are non-erroneous. It is only when I am dumping its output into an array do I generate errors. So it is the opposite of what you say. Does that help pinpoint the problem? $\endgroup$ – leastaction Jul 28 '17 at 5:02
  • 2
    $\begingroup$ The ::ivar error is often generated when a variable has inadvertently been given a value (search for "ivar" on this site). That is, somewhere your code is trying use 0 as a variable. Your error message Coefficient::ivar indicates that this is occurring in Coefficient. I would guess the problem is with your expression2, leading to something along the lines of Coefficient[(x + y)^2, 0] (for certain entries in your array), which generates the exact same error message as you're getting. $\endgroup$ – aardvark2012 Jul 28 '17 at 7:31
  • 1
    $\begingroup$ @leastaction As you can see, without the details of expression1 and expression2 to test with, the cause of your problem is unclear. Time to include the details of your code, or the question might be closed as missing valid code to reproduce. $\endgroup$ – MarcoB Jul 28 '17 at 18:38
  • $\begingroup$ Hi. Please close the question if forum rules so demand, as I am traveling now and won't be able to update it for another 24 hours. It seems there is no technical problem and these errors are warnings that arise because Coefficient is picking the coefficient of $dx^i \wedge dx^j$ in an expression and when $i=j$ this term is zero so the coefficient is undefined. The wedge indicates an exterior product. $\endgroup$ – leastaction Jul 28 '17 at 18:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.