MathGroup Archive 1997

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

Search the Archive

Re: Combining several pure functions into a single pure function

  • To: mathgroup at smc.vnet.net
  • Subject: [mg7297] Re: [mg7262] Combining several pure functions into a single pure function
  • From: wself at viking.emcmt.edu (Will Self)
  • Date: Thu, 22 May 1997 09:20:08 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Bob Lawrence asked an interesting question about creating disjunctions
and conjunctions of pure functions.  In essence, I think, what is required
is a function disj that would accept two pure functions as arguments and
return a pure function.  The pure function returned would itself accept
two Boolean inputs and return their disjuntion.  To get around Bob's
difficulty, we can use Literal to prevent too-early evaluation of Function.

In[59]:= disj[f1_,f2_]:=Function[x,Evaluate[f1[x] || f2[x] /. 
Literal[Function[a_,b_]]->Function[a,b][x]]]
         
In[60]:= g1=Function[x,x>0]

Out[60]= Function[x, x > 0]

In[61]:= g2=Function[y, y<2]

Out[61]= Function[y, y < 2]

In[62]:= disj[g1,g2]

Out[62]= Function[x$, x$ > 0 || x$ < 2]

In[63]:= h=#<3&

Out[63]= #1 < 3 & 

In[64]:= disj[g1,h]

Out[64]= Function[x$, x$ > 0 || x$ < 3]


Will Self
Montana


  • Prev by Date: Re: Nonlinear Fit Problem
  • Next by Date: PS printing problems: MMA V3.0 and Macs
  • Previous by thread: Combining several pure functions into a single pure function
  • Next by thread: Re: Combining several pure functions into a single pure function