|
[Date Index]
[Thread Index]
[Author Index]
Re: Variables[] in general expressions
- To: mathgroup at smc.vnet.net
- Subject: [mg20041] Re: Variables[] in general expressions
- From: "Allan Hayes" <hay at haystack.demon.co.uk>
- Date: Sat, 25 Sep 1999 18:46:06 -0400
- References: <7shptg$1r2@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Ken Rice <kmr1004 at hermes.cam.ac.uk> wrote in message
news:7shptg$1r2 at smc.vnet.net...
> 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
>
>
Ken,
What is a variable? For mathematics, taking it to be a symbol that is not a
head and is not a
system constant, and allowing for some other exclusions, we might use
AllVariables[expr_, exclusions_List:{}] :=
Complement[Cases[expr, _Symbol, {-1}, Heads -> True],
Cases[expr, h_Symbol[___] -> h, Infinity, Heads -> True],
{Catalan, Degree, E, EulerGamma, Glaisher, GoldenRatio, Khinchin, Pi},
exclusions
]This gives
AllVariables[y + Exp[x]]
{x, y}
AllVariables[y + Exp[x], {x}]
{y}
Note that Exp[a] is converted to E^a on evaluation.
Exp[a] // InputForm
E^a
However we might also want to allow for programming constructs like
Function[x,Sin[x]],
With[{x=a} Sin[x]]
--
Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565
Prev by Date:
Re: Select cell
Next by Date:
Re: TeXForm in v4 better?
Previous by thread:
Re: Variables[] in general expressions
Next by thread:
Re: Variables[] in general expressions
|