Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2003
*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 2003

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

Search the Archive

Re: extracting variables from an expression

  • To: mathgroup at smc.vnet.net
  • Subject: [mg44178] Re: [mg44111] extracting variables from an expression
  • From: Daniel Lichtblau <danl at wolfram.com>
  • Date: Sat, 25 Oct 2003 06:26:29 -0400 (EDT)
  • References: <200310231115.HAA23760@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Peter Schinko wrote:
> 
> Hi,
> 
> I'm looking for a function that extracts all variables from a boolean
> expression.
> For example:
> x || y || z
> should return something similar to {x, y, z}.
> 
> Is there a similar function in Mathematica? If so, how does it work?
> 
> Thanks very much
> Peter


Several replies show nice ways to do this assuming variables are atomic.
If you want to allow variables to be more general non-numeric things,
e.g. x[1], you might convert the input to a nested list structure and
use Variables.

listify[expr_] := expr /. {Or->List,And->List,Not->List,Xor->List}

In[15]:= Variables[listify[
  a&&b||c&&Not[d&&a||a[2]]&&b[w]||d&&a[2]&&Sin[x]||Pi||Sin[2]]]
Out[15]= {a, b, c, d, a[2], b[w], Sin[x]}


Daniel Lichtblau
Wolfram Research


  • Prev by Date: Re: Baffling Failure when plotting multiple curves.
  • Next by Date: Re: Re: extracting variables from an expression
  • Previous by thread: extracting variables from an expression
  • Next by thread: Re: extracting variables from an expression