MathGroup Archive 2001

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

Search the Archive

Re: Re: Thread and MapThread

  • To: mathgroup at smc.vnet.net
  • Subject: [mg29882] Re: [mg29870] Re: Thread and MapThread
  • From: Mianlai Zhou <lailai at nikhef.nl>
  • Date: Tue, 17 Jul 2001 01:00:29 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

There is another alternative to fulfill that:

SetAttributes[Thread, HoldFirst];
Thread[ ftest[{x1, x2, x3}, {y1, y2, y3}] ]

Then it will give the answer you want:

{{f1[x1], f2[y1]}, {f1[x2], f2[y2]}, {f1[x3], f2[y3]}}

Enjoy it.

Mianlai Zhou
Theory Group, NIKHEF
Amsterdam, The Netherlands

On Sun, 15 Jul 2001, Allan Hayes wrote:

> David,
>
> Here are the relevant evaluation steps of
> Thread[ftest[{x1, x2, x3}, {y1, y2, y3}]]
>
>        Thread[ {f1[{x1, x2, x3}], f2[{y1, y2, y3}]}]
> (*ftest[...] evaluates before Thread acts*)
>
>        {f1[{x1, x2, x3}], f2[{y1, y2, y3}]}]
> (*Thread does nothing since it has not, for example, been told to thread
> over f1}*)
>
> Compare
>
> Thread[ftest[{x1,x2,x3},{y1,y2,y3}],f1]
>
>         f1[{{x1, x2, x3}, f2[{y1, y2, y3}]}]
>
>
> There are many ways of avoiding premature evaluation, here are a few
>
> Thread[Unevaluated[ftest[{x1,x2,x3},{y1,y2,y3}]]] (*caution:x1, ... are
> held*)
>
>         {{f1[x1], f2[y1]}, {f1[x2], f2[y2]}, {f1[x3], f2[y3]}}
>
>
> Block[{ftest},Thread[ftest[{x1,x2,x3},{y1,y2,y3}]]]
>
>         {{f1[x1], f2[y1]}, {f1[x2], f2[y2]}, {f1[x3], f2[y3]}}
>
>
> Evaluate[Thread[#[{x1,x2,x3},{y1,y2,y3}]]]&[ftest]
>
> {{f1[x1], f2[y1]}, {f1[x2], f2[y2]}, {f1[x3], f2[y3]}}
>
> --
> Allan
> ---------------------
> Allan Hayes
> Mathematica Training and Consulting
> Leicester UK
> www.haystack.demon.co.uk
> hay at haystack.demon.co.uk
> Voice: +44 (0)116 271 4198
> Fax: +44 (0)870 164 0565
>



  • Prev by Date: Nonlinear regression with a complex-valued model function
  • Next by Date: Art competition :-)
  • Previous by thread: Re: Thread and MapThread
  • Next by thread: Re: Re: Re: Thread and MapThread