MathGroup Archive 2000

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

Search the Archive

Re: Mapping of mapping functions in metadefinitons

  • To: mathgroup at smc.vnet.net
  • Subject: [mg21997] Re: [mg21981] Mapping of mapping functions in metadefinitons
  • From: Hartmut Wolf <hwolf at debis.com>
  • Date: Thu, 10 Feb 2000 02:25:39 -0500 (EST)
  • Organization: debis Systemhaus
  • References: <200002071802.NAA08395@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Roland Franzius schrieb:
> 
> I have a problem in using metafunctions defining groups of
> other functions. Having a group f={f1,f2,f3} of vector
> functions I may define the functor bs=
> SetDelayed[#[a_vector,b_vector] , Inner[Times,a,b,#]]&  and
> apply it as Map[bs,f].

>                         To generate the function behaviour for
> numbers and vectors like
> f1[a_Integer,b_vector]:=Map[f1[a,#]&,b] I seek a possibilty to
> use a functor  fs=SetDelayed[#[a_Integer,b_vector],
> Map[Function[x,Times[a,x],b]]& to use it as Map[fs,f].

>                                                           Any
> suggestions using Through, Thread, Scan, Hold? Or have I togo
> back  compiling string and execute them?
> 

Dear Roland,

to me it's not clear what you want to attain. So I need to stick to the
literal. Let me take your simpler example first. Suppose you want to
have functions like

In[1]:= f1[a_Integer, b_?VectorQ] := Map[f1[a #] &, b]
In[2]:= f1[777, {b1, b2}]
Out[2]=
{f1[777 b1], f1[777 b2]}

Now, if you have a vector of symbols

In[4]:= f = {f1, f2, f3}

you may give them all this property with

In[8]:=
fs = Function[f, f[a_Integer, b_?VectorQ] := (f[a #] &) /@ b ];

In[9]:= fs /@ f
Out[9]= {Null, Null, Null}

and then you have

In[10]:= Through[f[666, {b1, b2}]]
Out[10]=
{{f1[666 b1], f1[666 b2]}, {f2[666 b1], f2[666 b2]}, {f3[666 b1], f3[666
b2]}}

So every "function" f<i> now has this property.

Now for your other case 

In[20]:= Clear[f1, f2, f3]

In[22]:=
f1[a_?VectorQ, b_?VectorQ] := Inner[Times, a, b, f1]

In[23]:= f1[{a1, a2}, {b1, b2}]
Out[23]= f1[a1 b1, a2 b2]

If that is it what you want for all your f<i>, you can attain it simply
through the same means:

In[26]:=
bs = ((#[a_?VectorQ, b_?VectorQ] := Inner[Times, a, b, #]) &);

In[27]:= bs /@ f
Out[27]= {Null, Null, Null}

In[28]:= Through[f[{a1, a2}, {b1, b2}]]
Out[28]=
{f1[a1 b1, a2 b2], f2[a1 b1, a2 b2], f3[a1 b1, a2 b2]}

There is no need for Hold etc. in these cases. But none of your symbols
(for "functions") must have OwnValues. In that case you'd get  $Failed
instead of Null when applying your "functors" (I'd not call them such),
so Clear them beforehand. 

Kind regards, Hartmut


  • Prev by Date: Re: numeric inverse laplace transform of numeric data
  • Next by Date: Language Challenge 2000
  • Previous by thread: Mapping of mapping functions in metadefinitons
  • Next by thread: Q: Scroll-mouse support for Mathematica 4 under NT4?