inexpression(x,g) ?



Whether it actually *depends on* the variable is in general hard to
determine.  For example, does sin(x)^2+cos(x)^2 depend on x?  No, of
course not, though it contains the variable x.  Probabilistic tests
like the ones RJF outlines fail on cases like (if x=.2323 then 1 else
0).

But I suspect you actually simply want to know whether a certain
variable is named in an expression, in which case you can use

            not freeof( expr, var)
or
            member(var, listofvars(expr))

There are some annoying edge cases for both of these because they're
rather simple syntactic tests.

For example:

             freeof(sum(f(i,x),i,1,inf),x) => true (OOPS!)
             freeof(x[i],i) => true
             freeof(x[i],x) => true
             freeof(x[i],x[j]) => true

There is almost *nothing* in Maxima that should be done by looking at
the string form of an expression (except perhaps to compare length as
a sort of measure of complexity).

               -s