Services & Resources / Wolfram Forums
MathGroup Archive
*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
  • Subject: [mg20037] Re: [mg20024] Variables[] in general expressions
  • From: "Andrzej Kozlowski" <andrzej at>
  • Date: Sat, 25 Sep 1999 18:46:04 -0400
  • Sender: owner-wri-mathgroup at

Here is one definition that seems to work:

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:

variables[y + Exp[x]]
{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

>From: Ken Rice <kmr1004 at>
To: mathgroup at
>To: mathgroup at
>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

  • 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