MathGroup Archive 2001

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

Search the Archive

Re: Thread and MapThread

  • To: mathgroup at smc.vnet.net
  • Subject: [mg29870] Re: Thread and MapThread
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Sun, 15 Jul 2001 00:58:58 -0400 (EDT)
  • References: <9iomi4$i17$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

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

"David Park" <djmp at earthlink.net> wrote in message
news:9iomi4$i17$1 at smc.vnet.net...
> Dear MathGroup,
>
> Here is a function:
>
> ftest[x_, y_] := {f1[x], f2[y]}
>
> Why does the following work...
>
> MapThread[ftest, {{x1, x2, x3}, {y1, y2, y3}}]
> {{f1[x1], f2[y1]}, {f1[x2], f2[y2]}, {f1[x3], f2[y3]}}
>
> ...but the following does not work.
>
> Thread[ftest[{x1, x2, x3}, {y1, y2, y3}]]
> {f1[{x1, x2, x3}], f2[{y1, y2, y3}]}
>
> David Park
> djmp at earthlink.net
> http://home.earthlink.net/~djmp/
>




  • Prev by Date: Re: 1) Numerical precision, 2) Bug in Plot?
  • Next by Date: Exponents and notation
  • Previous by thread: Re: Thread and MapThread
  • Next by thread: Re: Re: Thread and MapThread