MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Q: Thread behaviour

  • To: mathgroup at smc.vnet.net
  • Subject: [mg57954] Re: [mg57933] Q: Thread behaviour
  • From: Andrzej Kozlowski <andrzej at akikoz.net>
  • Date: Tue, 14 Jun 2005 05:10:19 -0400 (EDT)
  • References: <200506130950.FAA29336@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

On 13 Jun 2005, at 18:50, Dick Barends wrote:

> Hallo,
>
> k[x_,y_] = x^2+y^2
> Thread[k[a+b,c d],Plus]
> gives: (a+b)^2+c^2 d^2
> I would expect: a^2 + (c d)^2 + b^2 + (c d)^2 (See below)
>
> -----------------
> When I use:
> Thread[m[a+b, c d],Plus]
> gives: m[a, c d] + m[b, c d]
> This is what should happen.
>
> What gives "m" a different solution than "k"????
>
> I hoop some of you will answer:-)
>
> greetings
> Dick
>
>



Compare

In[39]:=
Thread[k[a + b, c*d], Plus]


(a + b)^2 + c^2*d^2

with


Thread[Unevaluated[k[a + b, c*d]], Plus]


a^2 + b^2 + 2*c^2*d^2

Alternatively, give k the attribute HoldAll


SetAttributes[k, HoldAll]


Thread[k[a + b, c*d], Plus]


(a + b)^2 + c^2*d^2

Andrzej Kozlowski

Chiba, Japan


  • Prev by Date: Re: Applying function to nested lists
  • Next by Date: Re: Q: Thread behaviour
  • Previous by thread: Q: Thread behaviour
  • Next by thread: Re: Q: Thread behaviour