Re: Variables[] in general expressions
- To: mathgroup at smc.vnet.net
 - Subject: [mg20037] Re: [mg20024] Variables[] in general expressions
 - From: "Andrzej Kozlowski" <andrzej at tuins.ac.jp>
 - Date: Sat, 25 Sep 1999 18:46:04 -0400
 - Sender: owner-wri-mathgroup at wolfram.com
 
Here is one definition that seems to work:
In[12]:=
variables[expr_] := 
  Cases[expr, _Symbol?(FreeQ[Attributes[#], Protected] &), Infinity]
The idea is that a variable should be something that is a Symbol but does
not have the attribute Protected, which all built-in symbols like Plus,
Power etc have.
It works in your example:
In[13]:=
variables[y + Exp[x]]
Out[13]=
{x, y}
I think it will always work unless WRI has forgotten to give the attribute
protected to some built-in symbol.
--
Andrzej Kozlowski
Toyama International University
JAPAN
http://sigma.tuins.ac.jp
http://eri2.tuins.ac.jp
----------
>From: Ken Rice <kmr1004 at hermes.cam.ac.uk>
To: mathgroup at smc.vnet.net
>To: mathgroup at smc.vnet.net
>Subject: [mg20037] [mg20024] Variables[] in general expressions
>Date: Sat, Sep 25, 1999, 3:40 PM
>
> Hi there,
>
> Is there any way of extracting a list of variables from a general
> expression, not just a polynomial? I want something which will do,
> e.g.
>
> In AllVariables[y + Exp[x]]
> Out {y,x}
>
> Apologies if I'm just being dim.
>
> Ken Rice
> _____________________________________________________
> Kenneth Rice
> Churchill College
> Cambridge
> CB3 0DS, UK
> E-mail: kmr1004 at cam.ac.uk
>
>