[Date Index]
[Thread Index]
[Author Index]
Re: listing user defined, independent variables
*To*: mathgroup at smc.vnet.net
*Subject*: [mg96819] Re: listing user defined, independent variables
*From*: Albert Retey <awnl at gmx-topmail.de>
*Date*: Wed, 25 Feb 2009 04:07:25 -0500 (EST)
*References*: <go0j0p$mta$1@smc.vnet.net>
Paul Ellsmore wrote:
> Hi,
>
>
>
> I have a notebook in which there are over 1300 variables (symbols) defined.
> The vast majority of these are dependent variables. I can get a list of them
> all with Names["Global`*"], but what I really want is a list of only the
> independent variables. Is there any obvious way to do this? Mathematica must
> "know" which variables are functions of other symbols, so I was hoping that
> there would be an "attribute" of a dependent variable that I could use as a
> filter on Names[]. Any thoughts? I am using V5.1.
I don't think that there is an attribute for that information. The
internals of mathematica are mostly rule based, and OwnValues[] will
give you the information which can be used to determine the dependencies
that you are seeking. I could only think about a rather involved way to
extract that information, since you need to be careful to not evaluate
too early. The following is an approach to determine the dependencies:
(*ensure that we can see the symbols, not only the values:*)
SetAttributes[dependentQ, HoldFirst]
(* if we get a symbol which has an OwnValue, extract the unevaluated RHS
of its OwnValue and see whether it contains symbols from the Global
context: *)
dependentQ[var_Symbol] :=
If[TrueQ[Length[OwnValues[var]] > 0],
Not[FreeQ[Extract[OwnValues[var], {1, 2}, Hold],
s_Symbol /; Context[s] == "Global`"]],
False
]
(* as a filter for variable names, it is handy if we accept strings as
arguments, too: *)
dependentQ[name_String] :=
dependentQ @@ ToExpression[name, InputForm, Hold]
(* use as filter: *)
Select[Names["Global`*"], dependentQ]
It might well be that there are simpler and/or more efficient ways to do
this, but I can't think of one now and it should be a starting point...
hth,
albert
Prev by Date:
**Re: newbie: can't Manipulate ListPlot of recurrence**
Next by Date:
**Re: newbie: can't Manipulate ListPlot of recurrence**
Previous by thread:
**RE: listing user defined, independent variables**
Next by thread:
**Re: Re: listing user defined, independent variables**
| |