I've some problems with the error mentioned in the title. Unfortunately, my code is full of subscripts so I'll show it in a photo. In this code the central aspect is to assign a scalar value to an element of tensor. The indices of this element of the tensor are given by a certrain array evaluated by some stuff of the code.

When I try to change something I receive the same error

Tag Times in Null (...) is Protected

The code is given below. After the code there is the photo. Sorry but my laptop has problems with screenshots.

CCC = D*Subscript[x, 1]*Subscript[x, 2]*Subscript[x, 7] + 
   K*Subscript[x, 3]*Subscript[x, 4]*Subscript[x, 5] + 
   S*Subscript[x, 2]*Subscript[x, 6]*Subscript[x, 7];
DimCCC = 3;
Array[TensorCCC, Table[10, DimCCC], 0]; 
ListaCCC = MonomialList[CCC];
Array[ListaIndici, 10, 0];
For[t = 1, t <= Length[ListaCCC], t++,
 For[q = 0, q <= 9, q++,
    If[(D[ListaCCC[[t]], Subscript[x, q]]*
         Subscript[x, q] /ListaCCC[[t]]) == 1, ListaIndici[q] = 1, 
      ListaIndici[q] = 0];
   TensorCCC @@ Position[Array[ListaIndici, 10, 0], 1] = 
    k - 1], {k, Position[Array[ListaIndici, 10, 0], 1]}] 
(*  there is the error even if we put only 
    TensorCCC @@ Position[Array[ListaIndici, 10, 0], 1] = ListaCCC[[t]] *)]


How could I solve this problem?


Format[x[n]] := Subscript[x, n];

CCC = H*x[1]*x[2]*x[7] + K*x[3]*x[4]*x[5] + S*x[2]*x[6]*x[7]; 
DimCCC = 3; 
Array[TensorCCC, Table[10, DimCCC], 0]; 
ListaCCC = MonomialList[CCC]; 
Array[ListaIndici, 10, 0]; 
Do[Do[If[D[ListaCCC[[t]], x[q]]*(x[q]/ListaCCC[[t]]) == 1, ListaIndici[q] = 1, 
      ListaIndici[q] = 0], {q, 0, 9, 1}]TensorCCC @@ Position[Array[ListaIndici, 10, 0], 
      1] = ListaCCC[[t]]/Product[x[k - 1], {k, Position[Array[ListaIndici, 10, 0], 1]}], 
  {t, 1, Length[ListaCCC], 1}]

Unfortunately the errors remain the same.

Anyway as I said in the comment, I think the problem is also related to the assignment to the tensor through a vector in the way TensorCCC @@ Position[Array[...]] is using @@.


closed as off-topic by Henrik Schumacher, Chris K, Daniel Lichtblau, m_goldberg, Johu Oct 9 '18 at 8:00

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Henrik Schumacher, Chris K, Daniel Lichtblau, Johu
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 5
    $\begingroup$ There is a semicolon missing after the second For. Btw.: Try to avoid Subscript; it's evil. And better use Do instead of For. And D is a built-in symbol. Don't use it as variable. $\endgroup$ – Henrik Schumacher Oct 6 '18 at 18:22
  • 1
    $\begingroup$ Use indexed variables (Making Definitions for Indexed Objects) rather than subscripts. You can display the indexed variables as subscripted variables using Format, e.g., Format[x[n_]] := Subscript[x, n]; Array[x, 5] $\endgroup$ – Bob Hanlon Oct 6 '18 at 18:33
  • $\begingroup$ @HenrikSchumacher OK thank you, there is the photo if you want see clearly the code. $\endgroup$ – siderius Oct 6 '18 at 18:53
  • 1
    $\begingroup$ Make the recommended changes to your code and if you still have problems, update your question with the revised code showing any errors that are returned. Use the menu command Cell | Convert To | Raw InputForm before copy and paste of code. $\endgroup$ – Bob Hanlon Oct 6 '18 at 19:06
  • 1
    $\begingroup$ What are you trying to accomplish with the code shown? With that information I may be able to help. $\endgroup$ – bbgodfrey Oct 7 '18 at 14:30

The following, I believe, produces the desired result:

CCC = H*x[1]*x[2]*x[7] + K*x[3]*x[4]*x[5] + S*x[2]*x[6]*x[7];
ListaCCC = MonomialList[CCC];
Do[Do[If[D[ListaCCC[[t]], x[q]]*(x[q]/ListaCCC[[t]]) == 1, 
    ListaIndici[q] = 1, ListaIndici[q] = 0], {q, 0, 9}]; 
    Evaluate[TensorCCC @@ Flatten[Position[Array[ListaIndici, 10, 0], 1]]] = 
    ListaCCC[[t]]/Product[x[k - 1], {k, Flatten[Position[Array[ListaIndici, 10, 0], 1]]}], 
    {t, 1, Length[ListaCCC]}]

The key changes from the question are

  1. Place a semicolon after the inner Do-loop.
  2. Flatten the result of Position to eliminate extraneous curly brackets.
  3. Evaluate the lhs of the final Set to avoid the error messages reported in the question.

In addition, unnecessary lines of code were removed. To see the result of this computation, use






DownValues also can be used to show the results.


A more compact code producing the same results is

CCC = H*x[1]*x[2]*x[7] + K*x[3]*x[4]*x[5] + S*x[2]*x[6]*x[7];
(Evaluate[TensorCCC @@ Cases[#, x[z_] -> z + 1]] = First[#]) & /@ CCC;

Note that this relies on {H, K, S} preceding x in canonical order. If this is not the case, replace First[#] by First@Cases[#, Except[x[_]]].

  • $\begingroup$ yes thank you very very much. I've just discovered another expression: at the assignment use TensorCCC[Sequence @@Position... ] , unfortunately in this way it doesn't simplify the output giving this (H x[1] x[2] x[7])/(x[{1}] x[{2}] x[{7}]) . Thank you again. $\endgroup$ – siderius Oct 7 '18 at 20:19
  • $\begingroup$ @siderius That is because x[1] and x[{1}] are different variables in Mathematica. Thanks for accepting my answer. $\endgroup$ – bbgodfrey Oct 7 '18 at 20:37

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