Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

Topic: Question about Thread & Total
Replies: 1   Last Post: Jan 26, 2013 4:58 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View  
Bob Hanlon

Posts: 906
Registered: 10/29/11
Re: Question about Thread & Total
Posted: Jan 26, 2013 4:58 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Thread[Total[{{1}, {2, 3}}]] // Trace

shows that there is an initial attempt to evaluate the Total before
the Thread is used . You can quiet the evaluation

Thread[Total[{{1}, {2, 3}}]] // Quiet

{1, 5}

If you use two distinct steps to implement the second method, you can
see why the second method works without complaint. The different
length lists are never used together.

Thread[h[{{1}, {2, 3}}]]

{h[{1}], h[{2, 3}]}

% /. h -> Total

{1, 5}

However, Map is better than Thread for this specific case.

Total /@ {{1}, {2, 3}}

{1, 5}


Bob Hanlon


On Sat, Jan 26, 2013 at 1:37 AM, Themis Matsoukas <tmatsoukas@me.com> wrote:
> I was wondering why the error message in the example below:
>
> Thread[Total[{{1}, {2, 3}}]]
>
> Total::tllen: Lists of unequal length in {{1},{2,3}} cannot be added. >>
>
> {1, 5}
>
> On the other hand, the construction below gives the same answer without complaints:
>
> Thread[h[{{1}, {2, 3}}]] /. h -> Total
>
> {1, 5}
>





Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.