1
$\begingroup$

I have a situation like this (for example):

vv[1, 2, 3] = a;
vv[1, 3, 2] = 11;
vv[3, 1, 2] = 7;
vv[2, 1, 3] = 5;

Sum[LeviCivitaTensor[3][[mu, nu, eta]]*vv[mu, nu, eta], {mu, 1, 
  3}, {nu, 1, 3}, {eta, 1, 3}]

I obtain this:

   -9 + a + vv[2, 3, 1] - vv[3, 2, 1]

I have not defined vv[2, 3, 1] and vv[3, 2, 1]so they appear as symbolic expressions, there is another symbolic expr which is vv[1, 2, 3] = a. Now here is the question. Is there a way to set to zero all the components not defined like these ones, if yes does it discriminate the variable a and vv[3, 2, 1] ?

Thank you.

$\endgroup$
5
  • 2
    $\begingroup$ Something like vv[__] = 0? $\endgroup$
    – Carl Woll
    Oct 12, 2018 at 23:12
  • 2
    $\begingroup$ Sum[LeviCivitaTensor[3][[mu, nu, eta]]*vv[mu, nu, eta], {mu, 1, 3}, {nu, 1, 3}, {eta, 1, 3}] /. _vv :> 0 $\endgroup$
    – Bob Hanlon
    Oct 12, 2018 at 23:36
  • $\begingroup$ @BobHanlon please could you tell me why using your sintax the code works even if some parts of array are not defined? $\endgroup$
    – siderius
    Oct 13, 2018 at 19:08
  • $\begingroup$ @siderius - any undefined terms have the form vv[mu, nu, eta], that is, an expression with the Head of vv. The rule _vv :> 0 replaces any expression with Head of vv with 0. $\endgroup$
    – Bob Hanlon
    Oct 13, 2018 at 19:10
  • $\begingroup$ @BobHanlon and correctly it discriminates a. Thank you for the answer. $\endgroup$
    – siderius
    Oct 13, 2018 at 19:16

1 Answer 1

2
$\begingroup$

One approach is to use a SparseArray (which sets all non-defined elements to zero by default):

vv = SparseArray[{{1, 2, 3} -> a, {1, 3, 2} -> 11, 
                  {3, 1, 2} -> 7, {2, 1, 3} -> 5}];
Sum[LeviCivitaTensor[3][[mu, nu, eta]]*vv[[mu, nu, eta]], 
                  {mu, 1, 3}, {nu, 1, 3}, {eta, 1, 3}]
-9 + a
$\endgroup$

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.