MathGroup Archive 2006

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

Search the Archive

Re: Extracting a Function's Domain and Image

  • To: mathgroup at smc.vnet.net
  • Subject: [mg68050] Re: Extracting a Function's Domain and Image
  • From: David Bailey <dave at Remove_Thisdbailey.co.uk>
  • Date: Fri, 21 Jul 2006 05:37:42 -0400 (EDT)
  • References: <e9ku8v$l1v$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Bruce Colletti wrote:
> Re Mathematica 5.2.2.
> 
> Why does the last line of code return {x} and not {a,b,_}, while if the f[_]=0 is struck, the answer is {a,b}?  
> 
> I want to extract the domain and image of a user-defined function, and tech support recommended using DownValues (pretty handy).  If you have an easier approach, please share it.  Thanks.
> 
> Bruce
> 
> Remove@f;
> f[_]=0;
> f["a"]=1;
> f["b"]=2;
> Clear@x;
> h=DownValues@f
> Cases[h,f[x_]->x,Infinity]
> 
> Out[52]=
> {HoldPattern[f[a]]:>1,HoldPattern[f[
>    b]]:>2,HoldPattern[f[_]]:>0}
> 
> Out[53]=
> {x} 
> 
Hello,

The problem here is that you are using an expression involving f (inside 
your Cases command) which can itself evaluate using your definition of 
f. This sort of slippery problem is often encountered when you 
manipulate held expressions. One way round this is to replace f with 
another function - ff, say - and then manipulate that:

Cases[h /. f -> ff, ff[x_] -> x, Infinity]

I am not very happy with your use of the terms domain and image for the 
information that you can extract in this way. I hope you are using these 
terms loosely, and not with their precise maths meaning.

David Bailey
http://www.dbaileyconsultancy.co.uk


  • Prev by Date: Re: building a list provided the position of element is known
  • Next by Date: Re: MapThread and If
  • Previous by thread: Re: Extracting a Function's Domain and Image
  • Next by thread: Norm