Re: Variables?

• To: mathgroup at yoda.physics.unc.edu
• Subject: Re: Variables?
• From: jfh124 at rsphy1.anu.edu.au (jason harris)
• Date: Sun, 30 May 1993 20:24:29 -0500

```Levent Kitis writes...

>Is the following a bug or is Variables[..] supposed to work this way?

>In[1]:= p[x_] := 1 + E x + Pi x^2

>In[2]:= Variables[p[x]]

>Out[2]= {E, Pi, x}

No this is not a bug. In expression In[2], p[x] evaluates to 1 + E x + Pi
x^2. Then it returns Variables[1 + E x + Pi x^2], which is {E, Pi, x}. If
you wamted to know the variable inside the head you could define

In[1]:=
MyVariables[h_[x__]]:={x};
SetAttributes[MyVariables,HoldAll]
(* this attribute HoldAll makes sure that h[x] is not evaluated and *)
(* will match the pattern *)

then,

In[2]:= MyVariables[p[x,y]]

Out[2]= {x,y}

In[3]:= MyVariables[p[x]]

Out[3]= {x}

hope this helps,

Jason

\$ at %?\$@%?\$ at %?\$@%?\$ at %?\$@%?\$ at %?\$@%?\$ at %?\$@%?\$ at %?\$@%?\$ at %?\$@%?\$ at %?\$@%

Jason Harris                   jfh124 at rsphysse.anu.edu.au
Optical Sciences Center
Australian National University
ACT 0200, Canberra             Tel.:  495-0191
Australia.                     Fax.:  249-5184

\$ at %?\$@%?\$ at %?\$@%?\$ at %?\$@%?\$ at %?\$@%?\$ at %?\$@%?\$ at %?\$@%?\$ at %?\$@%?\$ at %?\$@%?

```

• Prev by Date: matrix manipulation using transformations
• Next by Date: Re:FlatStrings
• Previous by thread: matrix manipulation using transformations