MathGroup Archive 2001

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

Search the Archive

Re: tricky question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg27965] Re: [mg27960] tricky question
  • From: BobHanlon at aol.com
  • Date: Tue, 27 Mar 2001 01:26:03 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Clear[g];

g[x_,y_] :=  Map[ Times[ x, # ]&, y ];

ans = g[x, {y1, y2, y3}]

{x*y1, x*y2, x*y3}

As a pure function

Clear[g];

g := Thread[Times[#1, #2]]&

g[x, {y1, y2, y3}] == ans

True

However, since Times is Listable this simplifys to

Clear[g];

g := #1*#2&;

g[x, {y1, y2, y3}] == ans

True


Bob Hanlon

In a message dated 2001/3/26 5:56:44 AM, linsuain+ at andrew.cmu.edu writes:

>this question has been teasing my brain for a while. It is about the
>apparent IMPOSSIBILITY of defining certain functions as pure functions.
>
>first take a simple case where it is POSSIBLE to define a pure function:
>
>g[x_,y_]:= Times[x,y]   will do the same as      g := Times[ #1, #2 ] &
>
>now in this case it seems to me it is IMPOSSIBLE to define a pure function:
>
>g[x_,y_] :=  Map[ Times[ x, # ]&, y ]
>
>is NOT the same as g :=  Map[ Times[ #1, #]& , #2]&  
>
>the reason these two are not the same is that in the function on the top
>line the arguments of Times would be x and the parts of y at level 1
>taken in sequence, while in the function on the botton line, the
>arguments of Times would both be just x, since #1 and # stand for the
>same.
>
>So, the question is: can  g[x_,y_] :=  Map[ Times[ x, # ]&, y ] be input
>as a pure function?
>


  • Prev by Date: Re: Counting Elements in a List
  • Next by Date: Re: Number Theory - Chinese Remainder Theorem
  • Previous by thread: tricky question
  • Next by thread: Re: tricky question