3
$\begingroup$

I have this simple question, given the following sum: Sum[A[i][j][k],{j,0,10},{k,0,10},{i,0,5}]

I would like to apply the condition

$ A[i][j][k]=A[i][k][j] $

How can i do that ?

Thanks

$\endgroup$
1
  • 3
    $\begingroup$ Maybe something like Sum[If[j == k, A[i][j][k], 2 A[i][j][k]], {j, 0, 10}, {k, j, 10}, {i, 0, 5}]. $\endgroup$
    – JimB
    Sep 8, 2022 at 17:52

1 Answer 1

5
$\begingroup$

Using a conditional pattern:

Sum[A[i][j][k], {j, 0, 10}, {k, 0, 10}, {i, 0, 5}] /.
  A[i_][j_][k_] /; j > k -> A[i][k][j]

(*    A[0][0][0] + 2 A[0][0][1] + 2 A[0][0][2] + ...
      ... + A[5][9][9] + 2 A[5][9][10] + A[5][10][10]    *)

Using explicit construction:

Sum[A[i][Min[j, k]][Max[j, k]], {j, 0, 10}, {k, 0, 10}, {i, 0, 5}]

(*    same as above    *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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