%mathpiper,def="VarListArith"

/// VarListArith --- obtain arithmetic variables
// currently the VarList(x,y) semantic is convoluted so let's introduce a new name; but in principle this needs to be cleaned up
VarListArith(expr) := VarListSome(expr, {ToAtom("+"), ToAtom("-"), *, /});

%/mathpiper



%mathpiper_docs,name="VarListArith",categories="User Functions;Lists (Operations)"
*CMD VarList --- list of variables appearing in an expression
*CMD VarListArith --- list of variables appearing in an expression
*CMD VarListSome --- list of variables appearing in an expression
*STD
*CALL
	VarList(expr)
	VarListArith(expr)
	VarListSome(expr, list)

*PARMS

{expr} -- an expression

{list} -- a list of function atoms

*DESC

The command {VarList(expr)} returns a list of all variables that appear in the
expression {expr}. The expression is traversed recursively.

The command {VarListSome} looks only at arguments of functions in the {list}. All other functions are considered "opaque" (as if they do not contain any variables) and their arguments are not checked.
For example, {VarListSome(a + Sin(b-c))} will return {{a, b, c}}, but {VarListSome(a*Sin(b-c), {*})} will not look at arguments of {Sin()} and will return {{a,Sin(b-c)}}. Here {Sin(b-c)} is considered a "variable" because the function {Sin} does not belong to {list}.


The command {VarListArith} returns a list of all variables that appear
arithmetically in the expression {expr}. This is implemented through
{VarListSome} by restricting to the arithmetic functions {+}, {-}, {*}, {/}.
Arguments of other functions are not checked.

Note that since the operators "{+}" and "{-}" are prefix as well as infix operators, it is currently required to use {ToAtom("+")} to obtain the unevaluated atom "{+}".

*E.G.

In> VarList(Sin(x))
Result: {x};
In> VarList(x+a*y)
Result: {x,a,y};
In> VarListSome(x+a*y, {ToAtom("+")})
Result: {x,a*y};
In> VarListArith(x+y*Cos(Ln(x)/x))
Result: {x,y,Cos(Ln(x)/x)}
In> VarListArith(x+a*y^2-1)
Result: {x,a,y^2};

*SEE IsFreeOf, IsVariable, FuncList, HasExpr, HasFunc
%/mathpiper_docs