MathGroup Archive 2003

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

Search the Archive

Re: How to copy pattern from one expression to another?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg45268] Re: [mg45254] How to copy pattern from one expression to another?
  • From: Tomas Garza <tgarza01 at prodigy.net.mx>
  • Date: Wed, 24 Dec 2003 17:42:25 -0500 (EST)
  • References: <200312240935.EAA22289@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

One possibility is to set the attribute Listable to your function f (I'd
rather use lower case):

In[1]:=
XX = {{x11, x12, x13}, x2, x3, x4, {x51, x52}, x6,
   {x71, x72}, x8};

In[2]:=
f /@ XX
Out[15]=
{f[{x11, x12, x13}], f[x2], f[x3], f[x4],
  f[{x51, x52}], f[x6], f[{x71, x72}], f[x8]}

Now, if you set

In[3]:=
SetAttributes[f, Listable]
In[4]:=
f /@ XX
Out[4]=
{{f[x11], f[x12], f[x13]}, f[x2], f[x3], f[x4],
  {f[x51], f[x52]}, f[x6], {f[x71], f[x72]}, f[x8]}

Tomas Garza
Mexico City
----- Original Message ----- 
From: "Nico" <pipponep at hotmail.com>
To: mathgroup at smc.vnet.net
Subject: [mg45268] [mg45254] How to copy pattern from one expression to another?


> Hi everyone and Merry Christmas!
> Here's my issue: I have a vector such as
> XX={{x11,x12,x13},x2,x3,x4,{x51,x52},x6,{x71,x72},x8} and I would like to
> apply the same function F[x_] to each single element in it. This is indeed
> pretty straightforward even to a very basic user like I am: I can first
> Flatten[XX] and then apply F[Flatten[XX]]. What I get is then
> YY={F[x11],F[x12],F[x12],...}.
> The question is: how can I then have YY with the same pattern of XX, that
is
> YY_hat={{F[x11],F[x12],F[x12]},F[x2],....,{F[x51],F[x52]},F[x6],{F..,F}}?
> I have tried but I'm afraid I cannot focus exactly the way I should
approach
> the problem.
> Any suggestion anyone? I'd really appreciate it...
>
> Kind regards and many thanks!
> The Net
>
>



  • Prev by Date: Re: Usage of "//" Operator
  • Next by Date: RE: Usage of "//" Operator with Multiargument Functions
  • Previous by thread: Re: How to copy pattern from one expression to another?
  • Next by thread: Re: How to copy pattern from one expression to another?