Re: Letting functions not evaluate
- To: mathgroup at smc.vnet.net
- Subject: [mg79435] Re: Letting functions not evaluate
- From: Albert <awnl at arcor.net>
- Date: Fri, 27 Jul 2007 05:39:08 -0400 (EDT)
- References: <f89qmn$60t$1@smc.vnet.net>
Josh Burkart wrote: > Say I have a function f[x], and, for certain values of the argument x, I don't want it to evaluate to anything. E.g., say > > f[x_]:=Mod[10,x], > > and if x is not an integer, then I want f[x] to yield simply f[x]. One way to achieve this is through pattern matching, i.e., > > f[x_Integer]:=Mod[10,x] > > Although this works perfectly in this example, it is somewhat limited. For instance, if I have a function taking two arguments and I want to perform some check on both arguments together to see whether the function should evaluate or not, pattern matching won't work. E.g., > > g[x_,y_]:=Mod[10,x*y] > > only if x*y is an integer (even if x and y individually aren't integers). I think there's some way to do this more generally than pattern matching, since for instance if I enter > > In[11]:= Integrate[Gamma[x]^5,x]//FullForm > Out[11]//FullForm= Integrate[Power[Gamma[x],5],x] > why are you so sure that pattern matching wouldn't do this? Try this: In[300]:= g[x_,y_]/;IntegerQ[x*y]:=Mod[10,x*y] In[301]:= g[1,2] Out[301]= 0 In[302]:= g[1/3,2] Out[302]= g[1/3, 2] In[303]:= g[1/3,3] Out[303]= 0 ...and probably learn more about the power of mathematicas pattern matcher :-). Seriously, I think you need to make up something really nasty to make it not feasible with the pattern matcher, but of course pattern matching alone is not the best solution to every problem... hth, albert