I want to check if a user input the function with all the specified variables or not. For that I choose the replace variables with some values and check for if the result is a number or not via a doloop. I am thinking there might be more elegant way of doing it such as ReplaceList
but it is not working the way I want it.
Lets assume
u = z^2 Sin[π x] + z^4 Cos[π y] + I y^6 Cos[2 π y] + w;
(*and user give variables as *)
vas = {x, y, z, w};
(* I need to check if all the variables are in the function *)
Do[
u = u /. vas[[i]] -> 1.1;
(* 1.1 is within where the function is going to get \
evaluated *)
If[i == 4, numc9 = NumericQ[u]; Print[numc9];];
(* if numc9 False either there infinity or one of \
the variables in the list is not present in the function or function \
has extra variable(s) *)
Print[u];
, {i, 4}]
Is there more elegant way doing it?
EDIT I
After @Mr.Wizard 's answer I realized that my question was not covering everything I wanted. @Mr. Wizard answer is working, if I was checking all the variables are present in u. However, at the same time I want to check if there is no extra variables in u. Because at the end I want to evaluate u using vars and if u has an extra variable I won't get a value at the end.
For example:
u = z^2 Sin[π x] + z^4 Cos[π y] + I y^6 Cos[2 π y]+ w y] + w + z^p;
vas = {z, x, y, p};
Level and FreeQ commands give all the variables in function u. After that you check if all the variables in vas are present in this list of variables coming from Level or FreeQ and in the example above its.
In this situation @J.M. undocumented command does what I need. Or I will need to stick with my DoLoop.