Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1999
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1999

[Date Index] [Thread Index] [Author Index]

Search the Archive

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
>
> 


  • Prev by Date: RE: Variables[] in general expressions
  • Next by Date: Re: Multiple Integrals
  • Previous by thread: RE: Variables[] in general expressions
  • Next by thread: Re: Variables[] in general expressions