I want to test, for example with MatchQ
, if the argument of a function is an arbitrary expression in a single or several variables whose names can be assumed to be known. Except of these variables the expression should contain only numeric values. An approach would be to generate a list of unknowns in an expression and to compare this list to a given one. But I do not know either how to create that list for an arbitrary expression. By expression I mean a mathematical expression here.
Edit
Exampe:
(1-Exp[I*(x-5.6)*23.4])*Log[Abs[x-4.3]]/(1.7+3.2*I-x^2)
should be matched if I require it to be an expression in x
and
(1-Exp[I*(x-y)*23.4])*Log[Abs[x-4.3]]/(1.7+3.2*I-x^2)
should not be matched in this case. Note that this does not mean that you can assume that the expression contains only these functions and rationals.
My function
func[expr_?...,var]:=Module[{},...]
should evaluate only if the expression is e.g. of the first kind
func[(1-Exp[I*(x-5.6)*23.4])*Log[Abs[x-4.3]]/(1.7+3.2*I-x^2),x]
Union@Cases[Level[expr, {-1}], x_ /; Not@NumericQ[x]]
this should extract the variables. It gives{x}
for the first expression and{x,y}
for the second. $\endgroup$Sort[Union@Cases[Level[expr, {-1}], x_ /; Not@NumericQ[x]]] == Sort[{var, var1}]
. $\endgroup$