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: [mg44135] Re: [mg44111] extracting variables from an expression
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Fri, 24 Oct 2003 04:24:05 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

You are quite right. I forgot about that. The function you need is 
Union. The correct code is:


Vars[expr_] := Union[Cases[expr,
    _Symbol?( !MemberQ[Attributes[#1], Protected] & ),
    Infinity]]


expr1 = a || b || c || (a && d);
Vars[expr1]


{a, b, c, d}


On Friday, October 24, 2003, at 02:05 AM, Peter Schinko wrote:

> Thank you very much for your help! The function works properly, but 
> there is
> still one minor problem: the function isolates every single occurance 
> of a
> variable, so for example:
>
> expr1 = a || b || c || (a && d)
> Vars[expr1]
> will return
> {a, b, c, a, d}
>
> I need to remove all variables from the list that appear two times or 
> more,
> so that I can construct a table with true and false to evaluate the
> expression. I have tried to find such function, but I could not find
> anything in "List Manipulation". Is there an easy way to do this 
> myself, or
> is there such a function built in?
>
> Thank you very much for your help!
> Kind regards
> Peter Schinko
>
> University of Linz, Austria
>
> www.pkos17.at
>
>
>
Andrzej Kozlowski
Yokohama, Japan
http://www.mimuw.edu.pl/~akoz/


  • Prev by Date: Re: Confused by levels in Outer
  • Next by Date: Re: NIntegrate and Delayed Functions
  • Previous by thread: Re: extracting variables from an expression
  • Next by thread: Re: Re: extracting variables from an expression