Re: Distribute
- To: mathgroup at smc.vnet.net
- Subject: [mg2817] Re: [mg2808] Distribute
- From: Allan Hayes <hay at haystack.demon.co.uk>
- Date: Wed, 20 Dec 1995 01:16:21 -0500
"Arnold Seiken" <SEIKENA at gar.union.edu>
>Subject: [mg2808] Distribute
Asks, amongst other things, about the following contrasting behaviour
(*1*)Distribute[Plus[{a,b,c}, {1,2,3}], List]
{{1 + a, 2 + b, 3 + c}}
(*2*)Distribute[Plus[{a,b,c}, {1,2,3,4}], List]
Thread::tdlen: Objects of unequal length in {a, b, c} + {1,
2, 3, 4} cannot be combined.
{1 + a, 2 + a, 3 + a, 4 + a, 1 + b, 2 + b, 3 + b, 4 + b,
1 + c, 2 + c, 3 + c, 4 + c}
Explanation: the difference lies in the evaluation of the entries
of Distribute, which is attempted before Distribute acts.
In (*1*), Plus adds the two lists of equal length to give
Distribute[{1+a,2+b,3+c}, List]
1 + a 2 + b 3 + c
You can use Unevaluated to stop Plus acting:
Distribute[Unevaluated[Plus[{a,b,c}, {1,2,3}]], List]
{1 + a, 2 + a, 3 + a, 1 + b, 2 + b, 3 + b, 1 + c, 2 + c, 3 + c}
In (*2*) the message tells us that Plus cannot add lists of unequal
length, then the evaluation continues with them not added
Allan Hayes
hay at haystack.demon.co.uk