Need to find matrix formulation
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I have a $B$ matrix: $B = B_ij$
I need to find closed matrix formulation of:
$$sum_i sum_j sum_m sum_n B_ij B_jm B_mn B_ni$$
But I am so confused!
Edit by Henrik:
Originally, it was asked to express
$$sum_i sum_j sum_m sum_n B_mi B_mj B_ni B_nj$$
in terms of matrices.
matrix algebra
New contributor
farhadpti is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
up vote
1
down vote
favorite
I have a $B$ matrix: $B = B_ij$
I need to find closed matrix formulation of:
$$sum_i sum_j sum_m sum_n B_ij B_jm B_mn B_ni$$
But I am so confused!
Edit by Henrik:
Originally, it was asked to express
$$sum_i sum_j sum_m sum_n B_mi B_mj B_ni B_nj$$
in terms of matrices.
matrix algebra
New contributor
farhadpti is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I formatted the math using Mathjax. Please check if I introduced any errors.
– Johu
7 hours ago
This site is about Mathematica, the software. Should we move your question over to Mathematics?
– Johu
7 hours ago
Could you also check, if you have not made any mistakes with the indexes.
– Johu
7 hours ago
@DavidG.Stork I am not sure whether your edit was meaningfull. By swapping some of the indices, you actually changed the question dramatically. For example, Louis' (imho correct) answer became invalid under this modification.
– Henrik Schumacher
31 mins ago
@LouisB I'd suggest to undelete your post. Imho, it is a perfect answer to the original question.
– Henrik Schumacher
19 mins ago
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have a $B$ matrix: $B = B_ij$
I need to find closed matrix formulation of:
$$sum_i sum_j sum_m sum_n B_ij B_jm B_mn B_ni$$
But I am so confused!
Edit by Henrik:
Originally, it was asked to express
$$sum_i sum_j sum_m sum_n B_mi B_mj B_ni B_nj$$
in terms of matrices.
matrix algebra
New contributor
farhadpti is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I have a $B$ matrix: $B = B_ij$
I need to find closed matrix formulation of:
$$sum_i sum_j sum_m sum_n B_ij B_jm B_mn B_ni$$
But I am so confused!
Edit by Henrik:
Originally, it was asked to express
$$sum_i sum_j sum_m sum_n B_mi B_mj B_ni B_nj$$
in terms of matrices.
matrix algebra
matrix algebra
New contributor
farhadpti is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
farhadpti is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 25 mins ago


Henrik Schumacher
38.8k254114
38.8k254114
New contributor
farhadpti is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 7 hours ago
farhadpti
61
61
New contributor
farhadpti is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
farhadpti is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
farhadpti is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I formatted the math using Mathjax. Please check if I introduced any errors.
– Johu
7 hours ago
This site is about Mathematica, the software. Should we move your question over to Mathematics?
– Johu
7 hours ago
Could you also check, if you have not made any mistakes with the indexes.
– Johu
7 hours ago
@DavidG.Stork I am not sure whether your edit was meaningfull. By swapping some of the indices, you actually changed the question dramatically. For example, Louis' (imho correct) answer became invalid under this modification.
– Henrik Schumacher
31 mins ago
@LouisB I'd suggest to undelete your post. Imho, it is a perfect answer to the original question.
– Henrik Schumacher
19 mins ago
add a comment |Â
I formatted the math using Mathjax. Please check if I introduced any errors.
– Johu
7 hours ago
This site is about Mathematica, the software. Should we move your question over to Mathematics?
– Johu
7 hours ago
Could you also check, if you have not made any mistakes with the indexes.
– Johu
7 hours ago
@DavidG.Stork I am not sure whether your edit was meaningfull. By swapping some of the indices, you actually changed the question dramatically. For example, Louis' (imho correct) answer became invalid under this modification.
– Henrik Schumacher
31 mins ago
@LouisB I'd suggest to undelete your post. Imho, it is a perfect answer to the original question.
– Henrik Schumacher
19 mins ago
I formatted the math using Mathjax. Please check if I introduced any errors.
– Johu
7 hours ago
I formatted the math using Mathjax. Please check if I introduced any errors.
– Johu
7 hours ago
This site is about Mathematica, the software. Should we move your question over to Mathematics?
– Johu
7 hours ago
This site is about Mathematica, the software. Should we move your question over to Mathematics?
– Johu
7 hours ago
Could you also check, if you have not made any mistakes with the indexes.
– Johu
7 hours ago
Could you also check, if you have not made any mistakes with the indexes.
– Johu
7 hours ago
@DavidG.Stork I am not sure whether your edit was meaningfull. By swapping some of the indices, you actually changed the question dramatically. For example, Louis' (imho correct) answer became invalid under this modification.
– Henrik Schumacher
31 mins ago
@DavidG.Stork I am not sure whether your edit was meaningfull. By swapping some of the indices, you actually changed the question dramatically. For example, Louis' (imho correct) answer became invalid under this modification.
– Henrik Schumacher
31 mins ago
@LouisB I'd suggest to undelete your post. Imho, it is a perfect answer to the original question.
– Henrik Schumacher
19 mins ago
@LouisB I'd suggest to undelete your post. Imho, it is a perfect answer to the original question.
– Henrik Schumacher
19 mins ago
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
4
down vote
If this is indeed a Mathematica question, then first note that:
$$sum _j B_i,j B_j,kequiv (B.B)_i,j$$
and
$$sum _i B_i,iequiv operatornameTr[B]$$
So, the Mathematica equivalent of:
$$sum _i sum _j sum _m sum _n B_i,j B_j,m B_m,n B_n,i $$
is:
Tr[B . B . B . B]
or:
Tr[MatrixPower[B, 4]]
For the original form of the question, note that:
$$ B_i,jequiv B^T_j,i $$
So, the Mathematica equivalent of:
$$sum _i sum _j sum _k sum _l B_m,i B_m,j B_n,i B_n,j$$
is:
Tr[B.Transpose[B].B.Transpose[B]]
add a comment |Â
up vote
1
down vote
This is a closed matrix formulation of $B^4$.
2
It's the trace of $B^4$, no?
– LouisB
6 hours ago
add a comment |Â
up vote
0
down vote
Carl's answer is perfect as it is. His use of MatrixPower
inspired me to think a little about computational complexity: Matrix-matrix multiplication has complexity $O(n^3)$ (in the straight-forward implementations, not these theoretically fancy but practically irrelevant algorithms). If we can get rid of one or two of them, we can even afford a transposition to speed up the computation:
n = 5000;
B = RandomReal[-1, 1, n, n];
a = Tr[B.B.B.B]; // RepeatedTiming // First
b = Tr[MatrixPower[B, 4]]; // RepeatedTiming // First
c = With[A = B.B, Total[A Transpose[A], 2]]; // RepeatedTiming // First
a == b == c
5.7
4.207
2.5
True
For the original question, LouisB's answer (c
below) seems to be both correct and efficient:
n = 5000;
B = RandomReal[-1, 1, n, n];
a = Tr[B.Transpose[B].B.Transpose[B]]; // RepeatedTiming // First
b = With[u = Flatten[B.Transpose[B]], u.u]; // RepeatedTiming // First
c = Total[(Transpose[B].B)^2, 2]; // RepeatedTiming // First
a == b == c
5.8
2.4
2.40
True
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
If this is indeed a Mathematica question, then first note that:
$$sum _j B_i,j B_j,kequiv (B.B)_i,j$$
and
$$sum _i B_i,iequiv operatornameTr[B]$$
So, the Mathematica equivalent of:
$$sum _i sum _j sum _m sum _n B_i,j B_j,m B_m,n B_n,i $$
is:
Tr[B . B . B . B]
or:
Tr[MatrixPower[B, 4]]
For the original form of the question, note that:
$$ B_i,jequiv B^T_j,i $$
So, the Mathematica equivalent of:
$$sum _i sum _j sum _k sum _l B_m,i B_m,j B_n,i B_n,j$$
is:
Tr[B.Transpose[B].B.Transpose[B]]
add a comment |Â
up vote
4
down vote
If this is indeed a Mathematica question, then first note that:
$$sum _j B_i,j B_j,kequiv (B.B)_i,j$$
and
$$sum _i B_i,iequiv operatornameTr[B]$$
So, the Mathematica equivalent of:
$$sum _i sum _j sum _m sum _n B_i,j B_j,m B_m,n B_n,i $$
is:
Tr[B . B . B . B]
or:
Tr[MatrixPower[B, 4]]
For the original form of the question, note that:
$$ B_i,jequiv B^T_j,i $$
So, the Mathematica equivalent of:
$$sum _i sum _j sum _k sum _l B_m,i B_m,j B_n,i B_n,j$$
is:
Tr[B.Transpose[B].B.Transpose[B]]
add a comment |Â
up vote
4
down vote
up vote
4
down vote
If this is indeed a Mathematica question, then first note that:
$$sum _j B_i,j B_j,kequiv (B.B)_i,j$$
and
$$sum _i B_i,iequiv operatornameTr[B]$$
So, the Mathematica equivalent of:
$$sum _i sum _j sum _m sum _n B_i,j B_j,m B_m,n B_n,i $$
is:
Tr[B . B . B . B]
or:
Tr[MatrixPower[B, 4]]
For the original form of the question, note that:
$$ B_i,jequiv B^T_j,i $$
So, the Mathematica equivalent of:
$$sum _i sum _j sum _k sum _l B_m,i B_m,j B_n,i B_n,j$$
is:
Tr[B.Transpose[B].B.Transpose[B]]
If this is indeed a Mathematica question, then first note that:
$$sum _j B_i,j B_j,kequiv (B.B)_i,j$$
and
$$sum _i B_i,iequiv operatornameTr[B]$$
So, the Mathematica equivalent of:
$$sum _i sum _j sum _m sum _n B_i,j B_j,m B_m,n B_n,i $$
is:
Tr[B . B . B . B]
or:
Tr[MatrixPower[B, 4]]
For the original form of the question, note that:
$$ B_i,jequiv B^T_j,i $$
So, the Mathematica equivalent of:
$$sum _i sum _j sum _k sum _l B_m,i B_m,j B_n,i B_n,j$$
is:
Tr[B.Transpose[B].B.Transpose[B]]
answered 5 hours ago


Carl Woll
58.1k274150
58.1k274150
add a comment |Â
add a comment |Â
up vote
1
down vote
This is a closed matrix formulation of $B^4$.
2
It's the trace of $B^4$, no?
– LouisB
6 hours ago
add a comment |Â
up vote
1
down vote
This is a closed matrix formulation of $B^4$.
2
It's the trace of $B^4$, no?
– LouisB
6 hours ago
add a comment |Â
up vote
1
down vote
up vote
1
down vote
This is a closed matrix formulation of $B^4$.
This is a closed matrix formulation of $B^4$.
answered 7 hours ago


David G. Stork
21.5k11646
21.5k11646
2
It's the trace of $B^4$, no?
– LouisB
6 hours ago
add a comment |Â
2
It's the trace of $B^4$, no?
– LouisB
6 hours ago
2
2
It's the trace of $B^4$, no?
– LouisB
6 hours ago
It's the trace of $B^4$, no?
– LouisB
6 hours ago
add a comment |Â
up vote
0
down vote
Carl's answer is perfect as it is. His use of MatrixPower
inspired me to think a little about computational complexity: Matrix-matrix multiplication has complexity $O(n^3)$ (in the straight-forward implementations, not these theoretically fancy but practically irrelevant algorithms). If we can get rid of one or two of them, we can even afford a transposition to speed up the computation:
n = 5000;
B = RandomReal[-1, 1, n, n];
a = Tr[B.B.B.B]; // RepeatedTiming // First
b = Tr[MatrixPower[B, 4]]; // RepeatedTiming // First
c = With[A = B.B, Total[A Transpose[A], 2]]; // RepeatedTiming // First
a == b == c
5.7
4.207
2.5
True
For the original question, LouisB's answer (c
below) seems to be both correct and efficient:
n = 5000;
B = RandomReal[-1, 1, n, n];
a = Tr[B.Transpose[B].B.Transpose[B]]; // RepeatedTiming // First
b = With[u = Flatten[B.Transpose[B]], u.u]; // RepeatedTiming // First
c = Total[(Transpose[B].B)^2, 2]; // RepeatedTiming // First
a == b == c
5.8
2.4
2.40
True
add a comment |Â
up vote
0
down vote
Carl's answer is perfect as it is. His use of MatrixPower
inspired me to think a little about computational complexity: Matrix-matrix multiplication has complexity $O(n^3)$ (in the straight-forward implementations, not these theoretically fancy but practically irrelevant algorithms). If we can get rid of one or two of them, we can even afford a transposition to speed up the computation:
n = 5000;
B = RandomReal[-1, 1, n, n];
a = Tr[B.B.B.B]; // RepeatedTiming // First
b = Tr[MatrixPower[B, 4]]; // RepeatedTiming // First
c = With[A = B.B, Total[A Transpose[A], 2]]; // RepeatedTiming // First
a == b == c
5.7
4.207
2.5
True
For the original question, LouisB's answer (c
below) seems to be both correct and efficient:
n = 5000;
B = RandomReal[-1, 1, n, n];
a = Tr[B.Transpose[B].B.Transpose[B]]; // RepeatedTiming // First
b = With[u = Flatten[B.Transpose[B]], u.u]; // RepeatedTiming // First
c = Total[(Transpose[B].B)^2, 2]; // RepeatedTiming // First
a == b == c
5.8
2.4
2.40
True
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Carl's answer is perfect as it is. His use of MatrixPower
inspired me to think a little about computational complexity: Matrix-matrix multiplication has complexity $O(n^3)$ (in the straight-forward implementations, not these theoretically fancy but practically irrelevant algorithms). If we can get rid of one or two of them, we can even afford a transposition to speed up the computation:
n = 5000;
B = RandomReal[-1, 1, n, n];
a = Tr[B.B.B.B]; // RepeatedTiming // First
b = Tr[MatrixPower[B, 4]]; // RepeatedTiming // First
c = With[A = B.B, Total[A Transpose[A], 2]]; // RepeatedTiming // First
a == b == c
5.7
4.207
2.5
True
For the original question, LouisB's answer (c
below) seems to be both correct and efficient:
n = 5000;
B = RandomReal[-1, 1, n, n];
a = Tr[B.Transpose[B].B.Transpose[B]]; // RepeatedTiming // First
b = With[u = Flatten[B.Transpose[B]], u.u]; // RepeatedTiming // First
c = Total[(Transpose[B].B)^2, 2]; // RepeatedTiming // First
a == b == c
5.8
2.4
2.40
True
Carl's answer is perfect as it is. His use of MatrixPower
inspired me to think a little about computational complexity: Matrix-matrix multiplication has complexity $O(n^3)$ (in the straight-forward implementations, not these theoretically fancy but practically irrelevant algorithms). If we can get rid of one or two of them, we can even afford a transposition to speed up the computation:
n = 5000;
B = RandomReal[-1, 1, n, n];
a = Tr[B.B.B.B]; // RepeatedTiming // First
b = Tr[MatrixPower[B, 4]]; // RepeatedTiming // First
c = With[A = B.B, Total[A Transpose[A], 2]]; // RepeatedTiming // First
a == b == c
5.7
4.207
2.5
True
For the original question, LouisB's answer (c
below) seems to be both correct and efficient:
n = 5000;
B = RandomReal[-1, 1, n, n];
a = Tr[B.Transpose[B].B.Transpose[B]]; // RepeatedTiming // First
b = With[u = Flatten[B.Transpose[B]], u.u]; // RepeatedTiming // First
c = Total[(Transpose[B].B)^2, 2]; // RepeatedTiming // First
a == b == c
5.8
2.4
2.40
True
edited 21 mins ago
answered 34 mins ago


Henrik Schumacher
38.8k254114
38.8k254114
add a comment |Â
add a comment |Â
farhadpti is a new contributor. Be nice, and check out our Code of Conduct.
farhadpti is a new contributor. Be nice, and check out our Code of Conduct.
farhadpti is a new contributor. Be nice, and check out our Code of Conduct.
farhadpti is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f182391%2fneed-to-find-matrix-formulation%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
I formatted the math using Mathjax. Please check if I introduced any errors.
– Johu
7 hours ago
This site is about Mathematica, the software. Should we move your question over to Mathematics?
– Johu
7 hours ago
Could you also check, if you have not made any mistakes with the indexes.
– Johu
7 hours ago
@DavidG.Stork I am not sure whether your edit was meaningfull. By swapping some of the indices, you actually changed the question dramatically. For example, Louis' (imho correct) answer became invalid under this modification.
– Henrik Schumacher
31 mins ago
@LouisB I'd suggest to undelete your post. Imho, it is a perfect answer to the original question.
– Henrik Schumacher
19 mins ago