Error: cannot evaluate boolean
Maple can't determine whether something is true or false in an "if" statement or "while" clause. This usually arises when a procedure that is meant to work for numeric arguments is called with symbolic arguments instead. It is often a case of "premature evaluation". Typical examples of this are
> f:= proc(x) if x > 0 then x^2 else -x^2 fi end:
> plot(f(x), x = -1 .. 1);
Error, (in f) cannot evaluate boolean: -x < 0
> evalf(Int(f(x), x = -1 .. 1));
Error, (in f) cannot evaluate boolean: -x < 0
> fsolve(f(x) = 0, x);
Error, (in f) cannot evaluate boolean: -x < 0
The trouble is that Maple evaluates the inputs to a procedure such as plot before it calls the procedure, resulting in f being called with the symbolic argument x . The problem can be fixed as follows:
> plot('f(x)', x = -1 .. 1);
> evalf(Int(f, -1 .. 1));
> fsolve('f(x)' = 0, x);
or modify the definition of f so that it accepts symbolic inputs (returning unevaluated), e.g.
>
f:= proc(x)
if not type(x, numeric) then 'f(x)'
elif x > 0 then x^2
else -x^2
fi
end:
> f(x);
Note that symbolic constants such as Pi or non-rational expressions such as sqrt(2) are not considered to be of type numeric , and in fact a comparison involving these will fail:
> if Pi < 3 then yes else no fi;
Error, cannot evaluate boolean: Pi < 3
Moreover, a comparison involving variables on which assumptions have been made will not take advantage of those assumptions.
>
assume(p > 0);
if p > -1 then yes else no fi;
Error, cannot evaluate boolean: -p < 1
A work-around for both these problems is to use is .
>
if is(Pi < 3) then yes else no fi;
if is(p > -1) then yes else no fi;
Another way this error can occur is in the numerical solution of a differential equation when the equation contains something symbolic (e.g. a parameter that has not been given a numerical value, or an undefined function). In some cases this arises by a misspelling. In the example below, the user probably intended to type sin rather than sim .
> f:= dsolve({D(y)(x)=sim(y(x)), y(0)=1},y(x),numeric);
> f(3);
Error, (in dsolve/numeric/rkf45) cannot evaluate boolean: -243.*abs(sim(1.)) < -.2e-7
See also: plot , Numerical integration , fsolve , dsolve/numeric
Maple Advisor Database R. Israel, 1997