Re: finding all definitions matching a pattern
- To: mathgroup at smc.vnet.net
- Subject: [mg98010] Re: finding all definitions matching a pattern
- From: Albert Retey <awnl at gmx-topmail.de>
- Date: Sat, 28 Mar 2009 05:39:58 -0500 (EST)
- References: <gqiaar$opg$1@smc.vnet.net>
Roman wrote: > Dear Mathematica user: > > Assume we have a number of definitions associated with a symbol F, for > example: > F[0] = 3; > F[1] = 7; > F[3] = 11; > > What I need is an automated way to generate the list of definitions, > something like > In[1] := getdefs[F] > Out[1] = {{0,3},{1,7},{3,11}} > > Would you know how to write this function "getdefs"? I am having > trouble extracting any useful information from a call to Definition[F] > since it seems to wrap its output somehow. Definition just gives a visual representation. What you are after is DownValues: f[0] = 3; f[1] = 7; f[3] = 11; In[21]:= DownValues[f] Out[21]= {HoldPattern[f[0]] :> 3, HoldPattern[f[1]] :> 7, HoldPattern[f[3]] :> 11} The format is more complicated since it can deal with all kind of definitions, not only the ones you have in mind. If you are sure that only definitions like the ones you mentioned are present, you could extract the list you want with e.g.: In[16]:= Transpose[{DownValues[f][[All, 1, 1, 1]], DownValues[f][[All, 2]]}] Out[16]= {{0, 3}, {1, 7}, {3, 11}} hth, albert