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: [mg67995] Re: [mg67970] Extracting a Function's Domain and Image
  • From: "Christoph Lhotka" <lhotka at astro.univie.ac.at>
  • Date: Thu, 20 Jul 2006 06:04:38 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Try this:

In[]:= #[[1, 1]] & /@ ReleaseHold[DownValues[f] /. f -> Unique[]]
Out[]:= {"a","b",_}

christoph

On Wed, 19 Jul 2006 05:21:10 -0400 (EDT)
 Bruce Colletti <vze269bv at verizon.net> 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} 
> 

-- Mag. Christoph Lhotka --
University of Vienna / Institute for Astronomy
fon. +43 (1) 4277 51841
mail. lhotka at astro.univie.ac.at


  • Prev by Date: Re: Extracting a Function's Domain and Image
  • Next by Date: Reasonable integration speed? (24 hrs and counting)
  • Previous by thread: Re: Extracting a Function's Domain and Image
  • Next by thread: Re: Extracting a Function's Domain and Image