COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

How does MATLAB exploit matrix multiplication's associativity?

• Email
• Follow

```-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

How does MATLAB exploit matrix multiplication's associativity? Given A
B C such that their product is possible (in matrix terms), it often
happens that
complexity(A(BC)) != complexity((AB)C).

So, how does MATLAB guess this? Is there a well-known algorithm about
this?

Thanks.
- --
- --

Give a man a fish and you feed him for a day; teach a man to fish
and you feed him for a lifetime.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourceforge.net/>

iEYEARECAAYFAkwbqrgACgkQM0LLzLt8MhxNbwCfY3RjXzlwKt/qwhw4nzWwdc7G
u1QAoJyztCDXqAOw3RzvPl9IMO8thR3b
=dxzd
-----END PGP SIGNATURE-----
```
 0

See related articles to this posting

```Merciadri Luca <Luca.Merciadri@student.ulg.ac.be> wrote in message <878w6cuukn.fsf@merciadriluca-station.MERCIADRILUCA>...
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hi,
>
> How does MATLAB exploit matrix multiplication's associativity? Given A
> B C such that their product is possible (in matrix terms), it often
> happens that
> complexity(A(BC)) != complexity((AB)C).
>
> So, how does MATLAB guess this? Is there a well-known algorithm about
> this?
>
> Thanks.
> - --
> - --
>
> Give a man a fish and you feed him for a day; teach a man to fish
>   and you feed him for a lifetime.
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.9 (GNU/Linux)
> Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourceforge.net/>
>
> iEYEARECAAYFAkwbqrgACgkQM0LLzLt8MhxNbwCfY3RjXzlwKt/qwhw4nzWwdc7G
> u1QAoJyztCDXqAOw3RzvPl9IMO8thR3b
> =dxzd
> -----END PGP SIGNATURE-----

this has been discussed at length in this NG...
search for stuff like
- matrix
- multiplication

us
```
 0

```Merciadri Luca <Luca.Merciadri@student.ulg.ac.be> wrote in message <878w6cuukn.fsf@merciadriluca-station.MERCIADRILUCA>...
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hi,
>
> How does MATLAB exploit matrix multiplication's associativity? Given A
> B C such that their product is possible (in matrix terms), it often
> happens that
> complexity(A(BC)) != complexity((AB)C).
>
> So, how does MATLAB guess this? Is there a well-known algorithm about
> this?

That's a good question. But Matlab does not guess, the expression is just evaluated dumbly from left to right, e.g.,

A*B*C*D = ((A*B)*C)*D

It is up to user to put the parenthesis at his/her will.

Bruno
```
 0

```"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <hvgb7a\$5u4\$1@fred.mathworks.com>...

> >
> > So, how does MATLAB guess this? Is there a well-known algorithm about
> > this?

http://en.wikipedia.org/wiki/Matrix_chain_multiplication

Bruno
```
 0

```-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Thanks all. Well, I thought that The Mathworks would have implemented
such schemes into MATLAB!

- --
- --

It is better to die on one's feet than live on one's knees.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourceforge.net/>

iEYEARECAAYFAkwb448ACgkQM0LLzLt8MhxIOwCeItbmY46mbZiyNQdiasACKzJO
kCIAnRBWLXInBOTUBQkbNyx1kOzZ2Iaq
=QgAu
-----END PGP SIGNATURE-----
```
 0

```Based on wikipedia, I have programmed the best order of multiple-matrix product. I'll submit on FEX after some cleaning.

function P = mmtimes(varargin)
% P = mmtimes(M1, M2, ... Mn)
%   multiple matrices product
%   P = M1*M2* ... *Mn
%
% MMTIMES usings optimal order of binary product to reduce the computation
%
%
% Author: Bruno Luong <brunoluong@...>
% Orginal: 19-Jun-2010

Matrices = varargin;
% Size of matrices
p = [cellfun('size',Matrices,1) size(Matrices{end},2)];

m = MatrixChainOrder(p);
P = ProdEngine(1,length(Matrices),m, Matrices);

end % mmtimes

%%
function m = MatrixChainOrder(p)
% Top-down dynamic programming, complexity O(n^3)
% http://en.wikipedia.org/wiki/Matrix_chain_multiplication

n = length(p)-1;
m = zeros(n);

for L=2:n
for i=1:n-L+1
j = i+L-1;
m(i,j) = Inf;
for k=i:j-1
q = m(i,k) + m(k+1,j) + p(i)*p(k+1)*p(j+1);
if (q < m(i,j))
m(i,j) = q;
m(j,i) = k;
end
end
end
end

end % MatrixChainOrder

%%
function P = ProdEngine(i,j,m,Matrices)
% Perform matrix product from the optimal order
if i==j
P = Matrices{i};
else
P1 = ProdEngine(i,m(j,i),m,Matrices);
P2 = ProdEngine(m(j,i)+1,j,m,Matrices);
P = P1*P2;
end

end % ProdEngine
```
 0

```-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

"Bruno Luong" <b.luong@fogale.findmycountry> writes:

> Based on wikipedia, I have programmed the best order of multiple-matrix product. I'll submit on FEX after some cleaning.
>
> function P = mmtimes(varargin)
> % P = mmtimes(M1, M2, ... Mn)
> %   multiple matrices product
> %   P = M1*M2* ... *Mn
> %
> % MMTIMES usings optimal order of binary product to reduce the computation
> %
> %
> % Author: Bruno Luong <brunoluong@...>
> % Orginal: 19-Jun-2010
>
> Matrices = varargin;
> % Size of matrices
> p = [cellfun('size',Matrices,1) size(Matrices{end},2)];
>
> m = MatrixChainOrder(p);
> P = ProdEngine(1,length(Matrices),m, Matrices);
>
> end % mmtimes
>
> %%
> function m = MatrixChainOrder(p)
> % Top-down dynamic programming, complexity O(n^3)
> % http://en.wikipedia.org/wiki/Matrix_chain_multiplication
>
> n = length(p)-1;
> m = zeros(n);
>
> for L=2:n
>     for i=1:n-L+1
>         j = i+L-1;
>         m(i,j) = Inf;
>         for k=i:j-1
>             q = m(i,k) + m(k+1,j) + p(i)*p(k+1)*p(j+1);
>             if (q < m(i,j))
>                 m(i,j) = q;
>                 m(j,i) = k;
>             end
>         end
>     end
> end
>
> end % MatrixChainOrder
>
> %%
> function P = ProdEngine(i,j,m,Matrices)
> % Perform matrix product from the optimal order
> if i==j
>     P = Matrices{i};
> else
>     P1 = ProdEngine(i,m(j,i),m,Matrices);
>     P2 = ProdEngine(m(j,i)+1,j,m,Matrices);
>     P = P1*P2;
> end
>
> end % ProdEngine
Thanks!
- --
- --

Necessity is the mother of all invention.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourceforge.net/>

iEYEARECAAYFAkwd9W0ACgkQM0LLzLt8MhxY0ACgn/SAYCklbDRasWn7lMeSrYfX
1AIAnisby1Ho21VxeZ4OrNLzM5A0Pd9Z
=GteA
-----END PGP SIGNATURE-----
```
 0

```"Merciadri Luca" <Luca.Merciadri@student.ulg.ac.be> wrote in message
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hi,
>
> How does MATLAB exploit matrix multiplication's associativity? Given A
> B C such that their product is possible (in matrix terms), it often
> happens that
> complexity(A(BC)) != complexity((AB)C).
>
> So, how does MATLAB guess this? Is there a well-known algorithm about
> this?

MATLAB does not exploit associativity; it performs the operations from left
to right, taking sets of parentheses into account.

One reason for this is that while operations may _theoretically_ be
associative, in _practice_ they may not be.  For example, take a look at

x = -1 + (1+1e-30);
y = (-1 + 1) + 1e-30;
areTheyEqual = (x==y) % false!

And this is NOT a bug; the answers of 0 for x and 1e-30 for y are BOTH
correct, given the computations performed.  Search for "associative" in this
document for some discussion as to why this occurs:

http://docs.sun.com/source/806-3568/ncg_goldberg.html

This group has had several discussions like this in the past -- mainly
dealing with what's "the right way" to SUM a vector of numbers?

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
http://www.mathworks.com

```
 0

```-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

"Steven Lord" <slord@mathworks.com> writes:

>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> Hi,
>>
>> How does MATLAB exploit matrix multiplication's associativity? Given A
>> B C such that their product is possible (in matrix terms), it often
>> happens that
>> complexity(A(BC)) != complexity((AB)C).
>>
>> So, how does MATLAB guess this? Is there a well-known algorithm about
>> this?
>
> MATLAB does not exploit associativity; it performs the operations from left
> to right, taking sets of parentheses into account.
>
> One reason for this is that while operations may _theoretically_ be
> associative, in _practice_ they may not be.  For example, take a look at
>
> x = -1 + (1+1e-30);
> y = (-1 + 1) + 1e-30;
> areTheyEqual = (x==y) % false!
>
> And this is NOT a bug; the answers of 0 for x and 1e-30 for y are BOTH
> correct, given the computations performed.  Search for "associative" in this
> document for some discussion as to why this occurs:
>
> http://docs.sun.com/source/806-3568/ncg_goldberg.html
>
> This group has had several discussions like this in the past -- mainly
> dealing with what's "the right way" to SUM a vector of numbers?
Well, you're totally right, Steven. But there are some conditions
under which such rounding errors appear more often (just like finding
the inverse of a matrix and the relation with the condition
number). And MATLAB could verify, or at least warn, if the computation
is going to take a long time, and that, by modifying the parenthesis
order, it would take less time, with some given modification on the result.
- --
- --

Laugh and the world laughs with you ... Cry and you will find no one
with tears.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourceforge.net/>

iEYEARECAAYFAkwhzkMACgkQM0LLzLt8MhyxswCfXa4pHEKS734L4Jlm6XCNMCl6
LWMAnjJg7ZpihbruHM6Ux+/MaiHQtn+/
=SA8P
-----END PGP SIGNATURE-----
```
 0

```-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

"Steven Lord" <slord@mathworks.com> writes:

>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> Hi,
>>
>> How does MATLAB exploit matrix multiplication's associativity? Given A
>> B C such that their product is possible (in matrix terms), it often
>> happens that
>> complexity(A(BC)) != complexity((AB)C).
>>
>> So, how does MATLAB guess this? Is there a well-known algorithm about
>> this?
>
> MATLAB does not exploit associativity; it performs the operations from left
> to right, taking sets of parentheses into account.
>
> One reason for this is that while operations may _theoretically_ be
> associative, in _practice_ they may not be.  For example, take a look at
>
> x = -1 + (1+1e-30);
> y = (-1 + 1) + 1e-30;
> areTheyEqual = (x==y) % false!
>
> And this is NOT a bug; the answers of 0 for x and 1e-30 for y are BOTH
> correct, given the computations performed.  Search for "associative" in this
> document for some discussion as to why this occurs:
>
> http://docs.sun.com/source/806-3568/ncg_goldberg.html
>
> This group has had several discussions like this in the past -- mainly
> dealing with what's "the right way" to SUM a vector of numbers?
And if we go until there, we could also say that `+' is not an
associative operator for reals, also because of reals' machine's encoding!
- --
- --

Life is like a box of chocolate, you never know what you're gonna
get.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourceforge.net/>

iEYEARECAAYFAkwhznsACgkQM0LLzLt8MhwDlgCgjdGdVDje+3JyyZJiZuPeKqGN
XP8An2HU8mNJCKCmCsr074xq3CBVJwQ/
=ZrwK
-----END PGP SIGNATURE-----
```
 0

```"Merciadri Luca" <Luca.Merciadri@student.ulg.ac.be> wrote in message
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> "Steven Lord" <slord@mathworks.com> writes:
>

*snip*

>> This group has had several discussions like this in the past -- mainly
>> dealing with what's "the right way" to SUM a vector of numbers?
>
> Well, you're totally right, Steven. But there are some conditions
> under which such rounding errors appear more often (just like finding
> the inverse of a matrix and the relation with the condition
> number). And MATLAB could verify, or at least warn, if the computation
> is going to take a long time, and that, by modifying the parenthesis
> order, it would take less time, with some given modification on the
> result.

Yes, MATLAB could check if you're multiplying together N+1 (for some large
N) matrices in a chain and determine the most efficient way to perform that
multiplication.  But how common is it that you're performing such a
multiplication with a large number of matrices?  I believe it's fairly rare.
Should we introduce a potentially time-consuming analysis like this in all
cases where you perform matrix multiplication to try to save a bit of time
in a rare case?

I believe in previous releases we had a demo that did this sort of analysis
when given the sizes of a set of matrices that you wanted to multiply
together, but I don't see it in the list of demos anymore.  I guess it
wasn't used that often.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
http://www.mathworks.com

```
 0

```"Merciadri Luca" <Luca.Merciadri@student.ulg.ac.be> wrote in message

*snip*

> And if we go until there, we could also say that `+' is not an
> associative operator for reals, also because of reals' machine's encoding!

"In theory, there is no difference between theory and practice.  In
practice, there is."

http://en.wikiquote.org/wiki/Fact_and_theory

Theoretically, addition is associative.  In practice, for double precision
values, it isn't.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
http://www.mathworks.com

```
 0
Reply slord (13686) 6/23/2010 2:02:47 PM

```"Steven Lord" <slord@mathworks.com> wrote in message <hvt419\$ql1\$1@fred.mathworks.com>...
>
> > -----BEGIN PGP SIGNED MESSAGE-----
> > Hash: SHA1
> >
> > "Steven Lord" <slord@mathworks.com> writes:
> >
>
>
> *snip*
>
> >> This group has had several discussions like this in the past -- mainly
> >> dealing with what's "the right way" to SUM a vector of numbers?
> >
> > Well, you're totally right, Steven. But there are some conditions
> > under which such rounding errors appear more often (just like finding
> > the inverse of a matrix and the relation with the condition
> > number). And MATLAB could verify, or at least warn, if the computation
> > is going to take a long time, and that, by modifying the parenthesis
> > order, it would take less time, with some given modification on the
> > result.
>
> Yes, MATLAB could check if you're multiplying together N+1 (for some large
> N) matrices in a chain and determine the most efficient way to perform that
> multiplication.  But how common is it that you're performing such a
> multiplication with a large number of matrices?

When multiplying more than 2 matrix, such question is pertinent.

> I believe it's fairly rare.
> Should we introduce a potentially time-consuming analysis like this in all
> cases where you perform matrix multiplication to try to save a bit of time
> in a rare case?

The time consumed by the analysis is negligible even in my own Matlab implementation. One can of course programmed the analysis in C to make it even faster. Mathworks can even makes it even faster than faster because they can further more remove some of the overhead. Here is a quick test:

>> A=rand(1000);
>> B=rand(1000);
>> C=rand(1000,1);
>> tic; y1=A*B*C; toc
Elapsed time is 0.094221 seconds.
>> tic; y2=A*(B*C); toc
Elapsed time is 0.004542 seconds.
>> tic; y3=mmtimes(A,B,C); toc
Elapsed time is 0.004994 seconds.
>>

TMW takes a pain to change the order of SUM two years ago (in the degree that user can't even access to the original order of summing from left to right). It should be trivial for them to make such analysis in chain MTIMES, unless if they consider breaking the compatibility is too risky. The big difference between SUM and MTIMES is that the smart MTIMES reduces the amount of computation, and not only splitting the intermediate results for different processors/cores, and I bet that the overall accuracy can also be improved.

Bruno
```
 0

```-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

"Steven Lord" <slord@mathworks.com> writes:

> Yes, MATLAB could check if you're multiplying together N+1 (for some large
> N) matrices in a chain and determine the most efficient way to perform that
> multiplication.  But how common is it that you're performing such a
> multiplication with a large number of matrices?
Not common.
> I believe it's fairly rare.
/
> Should we introduce a potentially time-consuming analysis like this in all
> cases where you perform matrix multiplication to try to save a bit of time
> in a rare case?
Might be interesting though.

> I believe in previous releases we had a demo that did this sort of analysis
> when given the sizes of a set of matrices that you wanted to multiply
> together, but I don't see it in the list of demos anymore.  I guess it
> wasn't used that often.
Okay. I did not know it.

- --
- --

There is a thin line between love and hate.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourceforge.net/>

iEYEARECAAYFAkwmOzUACgkQM0LLzLt8MhzPiACfan7dpJqSDbAG+OfvrZGG123u
9JYAoIwZYkkcaX0/XsPb829bDiFOt714
=aqpN
-----END PGP SIGNATURE-----
```
 0

```-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

"Bruno Luong" <b.luong@fogale.findmycountry> writes:

> "Steven Lord" <slord@mathworks.com> wrote in message <hvt419\$ql1\$1@fred.mathworks.com>...
>>
>> > -----BEGIN PGP SIGNED MESSAGE-----
>> > Hash: SHA1
>> >
>> > "Steven Lord" <slord@mathworks.com> writes:
>> >
>>
>>
>> *snip*
>>
>> >> This group has had several discussions like this in the past -- mainly
>> >> dealing with what's "the right way" to SUM a vector of numbers?
>> >
>> > Well, you're totally right, Steven. But there are some conditions
>> > under which such rounding errors appear more often (just like finding
>> > the inverse of a matrix and the relation with the condition
>> > number). And MATLAB could verify, or at least warn, if the computation
>> > is going to take a long time, and that, by modifying the parenthesis
>> > order, it would take less time, with some given modification on the
>> > result.
>>
>> Yes, MATLAB could check if you're multiplying together N+1 (for some large
>> N) matrices in a chain and determine the most efficient way to perform that
>> multiplication.  But how common is it that you're performing such a
>> multiplication with a large number of matrices?
>
> When multiplying more than 2 matrix, such question is pertinent.
>
>> I believe it's fairly rare.
>> Should we introduce a potentially time-consuming analysis like this in all
>> cases where you perform matrix multiplication to try to save a bit of time
>> in a rare case?
>
> The time consumed by the analysis is negligible even in my own Matlab implementation. One can of course programmed the analysis in C to make it even faster. Mathworks can even makes it even faster than faster because they can further more remove some of the overhead. Here is a quick test:
>
>>> A=rand(1000);
>>> B=rand(1000);
>>> C=rand(1000,1);
>>> tic; y1=A*B*C; toc
> Elapsed time is 0.094221 seconds.
>>> tic; y2=A*(B*C); toc
> Elapsed time is 0.004542 seconds.
>>> tic; y3=mmtimes(A,B,C); toc
> Elapsed time is 0.004994 seconds.
>>>
I suppose `mmtimes' is some function you defined in some homemade
m-file. Well, how did you proceed to find the best way to achieve the
product? (I do not know if there is an already-established, and
efficient algorithm for doing this; it should not be difficult to find
a good implementation of this, though.)

> TMW takes a pain to change the order of SUM two years ago (in the degree that user can't even access to the original order of summing from left to right). It should be trivial for them to make such analysis in chain MTIMES, unless if they consider breaking the compatibility is too risky. The big difference between SUM and MTIMES is that the smart MTIMES reduces the amount of computation, and not only splitting the intermediate results for different processors/cores, and I bet that the overall accuracy can also be improved.

- --
- --

The dog is nude though the clothing cost a penny.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourceforge.net/>

iEYEARECAAYFAkwmO8cACgkQM0LLzLt8Mhyp/gCdHv7x4Jzk1O9Nop0Pae2TeY5k
xj0An0vw/K6b2CaZL2meB/VbRvTwwA4J
=bKcJ
-----END PGP SIGNATURE-----
```
 0

```-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

"Steven Lord" <slord@mathworks.com> writes:

>
> *snip*
>
>> And if we go until there, we could also say that `+' is not an
>> associative operator for reals, also because of reals' machine's encoding!
>
> "In theory, there is no difference between theory and practice.  In
> practice, there is."
>
> http://en.wikiquote.org/wiki/Fact_and_theory
>
> Theoretically, addition is associative.  In practice, for double precision
> values, it isn't.
Well, I know that. I was not laughing: I just wanted to mention that
if you speak about such errors for matrices, this is also valid for

- --
- --

The secret of life is not to do what you like, but to like what you do.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourceforge.net/>

iEYEARECAAYFAkwmO/4ACgkQM0LLzLt8MhwikQCfbPgcwSbNcj8MdPV8kbp+qpZA
yjEAnj+sQ8Caf3VrSMabWE+ZtDaTpJye
=IZ1C
-----END PGP SIGNATURE-----
```
 0

```Merciadri Luca <Luca.Merciadri@student.ulg.ac.be> wrote in message <87mxuhelo7.fsf@merciadriluca-station.MERCIADRILUCA>...

> >>>
> I suppose `mmtimes' is some function you defined in some homemade
> m-file. Well, how did you proceed to find the best way to achieve the
> product? (I do not know if there is an already-established, and
> efficient algorithm for doing this; it should not be difficult to find
> a good implementation of this, though.)
>

I'm confused about your question, the mmtimes is the function I provides in post #6, and an improved version is submitted in FEX here
http://www.mathworks.com/matlabcentral/fileexchange/27950-mmtimes-matrix-chain-product

The timing is carried with FEX version.

You have replied in post #7, so why the question that sounds like from someone who has not followed the thread at all?

Bruno
```
 0

```-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

"Bruno Luong" <b.luong@fogale.findmycountry> writes:

>
>> >>>
>> I suppose `mmtimes' is some function you defined in some homemade
>> m-file. Well, how did you proceed to find the best way to achieve the
>> product? (I do not know if there is an already-established, and
>> efficient algorithm for doing this; it should not be difficult to find
>> a good implementation of this, though.)
>>
>
> I'm confused about your question, the mmtimes is the function I provides in post #6, and an improved version is submitted in FEX here
> http://www.mathworks.com/matlabcentral/fileexchange/27950-mmtimes-matrix-chain-product
Well, sorry, I try to follow so much threads that I sometimes forget

> The timing is carried with FEX version.
Ok.
>
> You have replied in post #7, so why the question that sounds like
> from someone who has not followed the thread at all?
it, and it came back to my mind.) I'm sure you understand my
absentmindedness. The fact is that I even tested it partially when
receiving your answer. That makes the whole story even weirder for my memory.

- --
- --

Education is the best provision for the journey to old age. (Aristotle)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourceforge.net/>

iEYEARECAAYFAkwpCV0ACgkQM0LLzLt8MhxRnQCgiQfXkWkXIbvK4xHcJcu3ClFg
NyYAoJK+m1lW7tl6BTptDJNCfh5433oz
=kqcA
-----END PGP SIGNATURE-----
```
 0

```Merciadri Luca <Luca.Merciadri@student.ulg.ac.be> wrote in message <87y6dy3n35.fsf@merciadriluca-station.MERCIADRILUCA>...

> I'm sure you understand my
> absentmindedness.

Yeah no problem. That's happens sometime to me too when a topic is not particular of my interest or get lost inside a junk of junks.

Bruno
```
 0

```-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

"Bruno Luong" <b.luong@fogale.findmycountry> writes:

>
>> I'm sure you understand my
>> absentmindedness.
>
> Yeah no problem. That's happens sometime to me too when a topic is not particular of my interest or get lost inside a junk of junks.
Sarcastic and caustic remark. This topic is not the topic which I'm
the most interested in (and same for others, I think), but that does
not justify my absentmindedness.

- --
- --

If it's too good to be true, then it probably is.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourceforge.net/>

iEYEARECAAYFAkwpqHsACgkQM0LLzLt8MhzJEwCfd2JX4M50P3Q8mEWqdAj4mWIn
UOwAoJidvYed8qClBDg7XggQkMk/I6GH
=v9lZ
-----END PGP SIGNATURE-----
```
 0

```Merciadri Luca <Luca.Merciadri@student.ulg.ac.be> wrote in message <87r5jq6zcy.fsf@merciadriluca-station.MERCIADRILUCA>...
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> "Bruno Luong" <b.luong@fogale.findmycountry> writes:
>
> >
> >> I'm sure you understand my
> >> absentmindedness.
> >
> > Yeah no problem. That's happens sometime to me too when a topic is not particular of my interest or get lost inside a junk of junks.
> Sarcastic and caustic remark. This topic is not the topic which I'm
> the most interested in (and same for others, I think), but that does
> not justify my absentmindedness.
>
> - --
> - --
>
> If it's too good to be true, then it probably is.
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.9 (GNU/Linux)
> Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourceforge.net/>
>
> iEYEARECAAYFAkwpqHsACgkQM0LLzLt8MhzJEwCfd2JX4M50P3Q8mEWqdAj4mWIn
> UOwAoJidvYed8qClBDg7XggQkMk/I6GH
> =v9lZ
> -----END PGP SIGNATURE-----

I suggest you to clean up your signature and leave a blank line before replying.

Oleg
```
 0

```-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

"Oleg Komarov" <oleg.komarovRemove.this@hotmail.it> writes:

> I suggest you to clean up your signature and leave a blank line

- --
- --

Don't try to teach a pig to sing. It doesn't work, and you'll annoy
the pig.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourceforge.net/>

iEYEARECAAYFAkwqKzEACgkQM0LLzLt8MhwRowCfT2++Ec33AiB347NYKbAPWFaF
45MAoJz4FB+bQS2MJuL+GzL8Izdj/mhm
=Ke7o
-----END PGP SIGNATURE-----
```
 0

```Dear Steven,

> I believe in previous releases we had a demo that did this sort of analysis
> when given the sizes of a set of matrices that you wanted to multiply
> together, but I don't see it in the list of demos anymore.  I guess it
> wasn't used that often.

In Matlab 6.5 there was a powerful demo function CHAINMULT and a corresponding GUI, which allows to create an M-file. The computation could be optimized for number of flops or intermediate storage size. A flag allowed to control the re-using of memory and for each matrix the existence of imaginary values could be defined.

The GUI had some UITOGGLE buttons, a help-topic system (enable help and click on the object), a status line and some menus. It was a really nice demo for building GUIs.
I'm sad that CHAINMULT and CHAINGUI is not supported anymore.

Jan
```
 0