Message Boards Message Boards


Avoid nonatomic expression error message?

Posted 1 month ago
1 Reply
2 Total Likes

This code produces a correct result, but gives an error message:

Clear[l, CI]

2 CI[{{2, 2}}] + 2 CI[{{1, 2}, {2, 1}}] /. CI[l_] -> j^(Total[l][[2]])

Total::normal: Nonatomic expression expected at position 1 in Total[l].

Part::partw: Part 2 of Total[l] does not exist.

2 j^2 + 2 j^3

Is there an easy way to eliminate the error message?

Use RuleDelayed instead of Rule:

In[236]:= 2 CI[{{2,2}}]+2 CI[{{1,2},{2,1}}]/.CI[l_]:>j^(Total[l][[2]])

Out[236]= 2 j^2+2 j^3
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract