Check validity of equation or inequality
logical(cond)
logical(
checks
whether the condition cond
)cond
is valid. To test conditions
that require assumptions or simplifications, use isAlways
instead of logical
.

Equation, inequality, or vector or matrix of equations or inequalities.
You also can combine several conditions by using the logical operators 
Use logical
to check if 3/5
is
less than 2/3
:
logical(sym(3)/5 < sym(2)/3)
ans = logical 1
Check the validity of this equation using logical
.
Without an additional assumption that x
is nonnegative,
this equation is invalid.
syms x logical(x == sqrt(x^2))
ans = logical 0
Use assume
to set an
assumption that x
is nonnegative. Now the expression sqrt(x^2)
evaluates
to x
, and logical
returns 1
:
assume(x >= 0) logical(x == sqrt(x^2))
ans = logical 1
Note that logical
typically ignores assumptions
on variables.
syms x assume(x == 5) logical(x == 5)
ans = logical 0
To compare expressions taking into account assumptions on their
variables, use isAlways
:
isAlways(x == 5)
ans = logical 1
For further computations, clear the assumption on x
:
syms x clear
Check if the following two conditions are both valid. To check
if several conditions are valid at the same time, combine these conditions
by using the logical operator and
or its shortcut &
.
syms x logical(1 < 2 & x == x)
ans = logical 1
Check this inequality. Note that logical
evaluates
the left side of the inequality.
logical(sym(11)/4  sym(1)/2 > 2)
ans = logical 1
logical
also evaluates more complicated symbolic
expressions on both sides of equations and inequalities. For example,
it evaluates the integral on the left side of this equation:
syms x logical(int(x, x, 0, 2)  1 == 1)
ans = logical 1
Do not use logical
to check equations and
inequalities that require simplification or mathematical transformations.
For such equations and inequalities, logical
might
return unexpected results. For example, logical
does
not recognize mathematical equivalence of these expressions:
syms x logical(sin(x)/cos(x) == tan(x))
ans = logical 0
logical
also does not realize that this inequality
is invalid:
logical(sin(x)/cos(x) ~= tan(x))
ans = logical 1
To test the validity of equations and inequalities that require
simplification or mathematical transformations, use isAlways
:
isAlways(sin(x)/cos(x) == tan(x))
ans = logical 1
isAlways(sin(x)/cos(x) ~= tan(x))
Warning: Unable to prove 'sin(x)/cos(x) ~= tan(x)'. ans = logical 0
For symbolic equations, logical
returns
logical 1
(true
) only if the
left and right sides are identical. Otherwise, it returns logical 0
(false
).
For symbolic inequalities constructed with ~=
, logical
returns
logical 0
(false
) only if the
left and right sides are identical. Otherwise, it returns logical 1
(true
).
For all other inequalities (constructed with <
, <=
, >
,
or >=
), logical
returns logical 1
if
it can prove that the inequality is valid and logical 0
if
it can prove that the inequality is invalid. If logical
cannot
determine whether such inequality is valid or not, it throws an error.
logical
evaluates expressions on
both sides of an equation or inequality, but does not simplify or
mathematically transform them. To compare two expressions applying
mathematical transformations and simplifications, use isAlways
.
logical
typically ignores assumptions
on variables.
assume
 assumeAlso
 assumptions
 in
 isAlways
 isequal
 isequaln
 isfinite
 isinf
 isnan
 sym
 syms