Re: Need a means to get arguments of a function
- To: mathgroup at smc.vnet.net
- Subject: [mg18588] Re: [mg18444] Need a means to get arguments of a function
- From: BobHanlon at aol.com
- Date: Tue, 13 Jul 1999 01:01:24 -0400
- Sender: owner-wri-mathgroup at wolfram.com
Patrick,
w = f[x, u, v];
v = h[x, y];
The number of arguments in f is just
Length[w]
3
You can access each argument separately
Table[w[[k]], {k, Length[w]}]
{x, u, h[x, y]}
Or you can access all arguments at once
List @@ w
{x, u, h[x, y]}
You can select only those arguments that are symbols
Select[List @@ w, Head[#] == Symbol &]
{x, u}
Cases[w, _Symbol]
{x, u}
Or those arguments that are not symbols
Select[List @@ w, Head[#] =!= Symbol &]
{h[x, y]}
Or symbols at any level (duplicates removed)
Union[Cases[w, _Symbol, Infinity]]
{u, x, y}
Or those arguments that explicitly depend on x
Select[List @@ w, ! FreeQ[#, x] &]
{x, h[x, y]}
Or the position of any argument that equals v
Cases[Table[{k, w[[k]]}, {k, Length[w]}],
{n_, v} -> n]
{3}
Bob Hanlon
In a message dated 7/7/99 1:37:43 PM, reany at xroads.com writes:
>I'm using version 3.0.1 to demonstrate the differentiation of composite
>functions. I need a means to get arguments to user-defined function(s)
>to demonstrate the chain rule. For example, if the user put in
>
>w = f[x,u,v] and v = h[x,y]
>
>I need to get at each of the arguments of f, even though Mathematica
>wants to substitute out v in f by h[x,y].
>
>Does Mathematica allow me to get at the original number of arguments of
>f and does it have an indexed function that lets me get at each
>particular argument of f, such as allowing me to determine, say, that
>the third argument of f is v?
>