%mathpiper,def="IsFreeOf"

1 # IsFreeOf({},_expr) <-- True;
2 # IsFreeOf(var_IsList, _expr) <-- And(IsFreeOf(First(var),expr), IsFreeOf(Rest(var),expr));

4 # IsFreeOf(_var,{}) <-- True;
5 # IsFreeOf(_var,expr_IsList) <-- And(IsFreeOf(var,First(expr)), IsFreeOf(var,Rest(expr)));

/* Accept any variable. */
10 # IsFreeOf(_expr,_expr) <-- False;

/* Otherwise check all leafs of a function. */
11 # IsFreeOf(_var,expr_IsFunction) <-- IsFreeOf(var,Rest(FunctionToList(expr)));

/* Else it doesn't depend on any variable. */
12 # IsFreeOf(_var,_expr) <-- True;

%/mathpiper



%mathpiper_docs,name="IsFreeOf",categories="User Functions;Predicates"
*CMD IsFreeOf --- test whether expression depends on variable
*STD
*CALL
	IsFreeOf(var, expr)
	IsFreeOf({var, ...}, expr)

*PARMS

{expr} -- expression to test

{var} -- variable to look for in "expr"

*DESC

This function checks whether the expression "expr" (after being
evaluated) depends on the variable "var". It returns {False} if this is the case and {True}
otherwise.

The second form test whether the expression depends on <i>any</i> of
the variables named in the list. The result is {True} if none of the variables appear in the expression and {False} otherwise.

*E.G.

In> IsFreeOf(x, Sin(x));
Result: False;
In> IsFreeOf(y, Sin(x));
Result: True;
In> IsFreeOf(x, Differentiate(x) a*x+b);
Result: True;
In> IsFreeOf({x,y}, Sin(x));
Result: False;

The third command returns {True} because the
expression {Differentiate(x) a*x+b} evaluates to {a}, which does not depend on {x}.

*SEE Contains
%/mathpiper_docs