       Re: Extracting the domain of a function, dynamic programming

• To: mathgroup at smc.vnet.net
• Subject: [mg8272] Re: Extracting the domain of a function, dynamic programming
• From: John M Lee <lee at math.washington.edu>
• Date: Sat, 23 Aug 1997 01:59:13 -0400
• Organization: University of Washington Department of Mathematics
• Sender: owner-wri-mathgroup at wolfram.com

```John JOWETT wrote:
>
> Hello, I would like to extract the set of values on which a function is
> defined.   Consider the following toy example (to illustrate a
> situation I have while using dynamic programming):
>
> In:=
> Clear[f]
> In:=
> f:=f1;
> f:=f2;
>
> To find out about f, I can always do
>
> In:=
> ?f
> Global`f
> f := f1
>
> f := f2
>
> However in my application, the values f1 and f2 are enormous expressions
> that I have to avoid appearing in my notebook  (even if I allow them to
> print, it is quite hard to sift through the output cells looking for
> what I want).  In any case I would like to get hold of this domain
> list and do other things with it.
>
> I would like something
> that returns just the list {1,2}, ie, the domain or set of values for
> which the function has been explicitly defined.
>
> I have tried
>
> In:=
> DownValues[f]
> Out=
> {HoldPattern[f]\[RuleDelayed]f1,HoldPattern[f]\[RuleDelayed]f2}
>
> and  then
>
> In:=
> First /@ DownValues[f]
> Out=
> {HoldPattern[f],HoldPattern[f]}
>
> Then I can use Length[] to find out at least for how many cases f
> is defined but I have trouble extracting my domain (basically because
> attempts to dig deeper into the DownValues list always evaluate f
> and f at some point.
>
> I am sure that someone who really understands held expressions
> can help me .....
>
> (I realise that I could simply accumulate an auxiliary list at
> each point where a new value is defined for f but that's not really
> satisfactory.)
>
> Thanks for any efforts,
> John Jowett

A slight modification of your idea works.

In:= f := f1;

In:= f := f2;

In:= domain[function_] :=
Function[ x, x[[1,1,1]] ] /@ DownValues[function];

In:= domain[f]

Out= {1, 2}

Jack Lee
+----------------------------------------------------------------------+
| John M. Lee, Professor of Mathematics       University of Washington |
| lee at math.washington.edu                     Mathematics Department   |
| http://www.math.washington.edu/~lee         Box 354350               |
| Phone 206-543-1735, Fax 206-543-0397        Seattle, WA 98195-4350   |
+----------------------------------------------------------------------+

```

• Prev by Date: Book/CD Announcement: The Beginner's Guide to Mathematica V3
• Next by Date: Re: Limit a^n / n!
• Previous by thread: Extracting the domain of a function, dynamic programming
• Next by thread: Re: Extracting the domain of a function, dynamic programming