The variables command extracts all variables present in an expression A.
f = sin(x) + cos(y) + z; variables(f); [x, y, z]