Consider these two expressions:
expr1 = a d g[X, c]^2 + e g[X, f] + 3 expr2 = a d g[X, c]^2 + e X + 3
How do I check whether these expressions depend on
X only as
g[X, _]. More specifically, I want to check that any occurrence of
X in a given expression must appear as the first argument of the two-variable function
g, and no other way.
In the two examples above,
expr1 satisfies this criteria,
expr2 does not.
Right now I can think of only one way to check this:
myCheck[expr_] := FreeQ[expr /. g[X, _] :> OK, X];
myCheck[expr2] yields false. Are there any other ways -- ideally ones that traverse the expression only once?
myCheck above traverses the expression twice.