# xor

Logical XOR for symbolic expressions

## Description

example

xor(A,B) represents the logical exclusive disjunction. xor(A,B) is true when either A or B is true. If both A and B are true or false, xor(A,B) is false.

## Examples

### Set and Evaluate Condition

Combine two symbolic inequalities into a logical expression using xor.

syms x
range = xor(x > -10, x < 10);

Replace variable x with 11 and 0. If you replace x with 11, then inequality x > -10 is valid and x < 10 is invalid. If you replace x with 0, both inequalities are valid. Note that subs only substitutes the numeric values into the inequalities. It does not evaluate the inequalities to logical 1 or 0.

x1 = subs(range,x,11)
x2 = subs(range,x,0)
x1 =
-10 < 11 xor 11 < 10

x2 =
-10 < 0 xor 0 < 10

To evaluate these inequalities to logical 1 or 0, use isAlways. If only one inequality is valid, the expression with xor evaluates to logical 1. If both inequalities are valid, the expression with xor evaluates to logical 0.

isAlways(x1)
isAlways(x2)
ans =
logical
1

ans =
logical
0

Note that simplify does not simplify these logical expressions to logical 1 or 0. Instead, simplify returns symbolic constants symtrue or symfalse.

s1 = simplify(x1)
s2 = simplify(x2)
s1 =
symtrue

s2 =
symfalse

Convert symbolic symtrue or symfalse to logical values using logical.

logical(s1)
logical(s2)
ans =
logical
1

ans =
logical
0

## Input Arguments

collapse all

Operands, specified as symbolic equations, inequalities, expressions, or arrays. Inputs A and B must either be the same size or have sizes that are compatible (for example, A is an M-by-N matrix and B is a scalar or 1-by-N row vector). For more information, see Compatible Array Sizes for Basic Operations.

## Tips

• If you call simplify for a logical expression containing symbolic subexpressions, you can get the symbolic constants symtrue and symfalse. These two constants are not the same as logical 1 (true) and logical 0 (false). To convert symbolic symtrue and symfalse to logical values, use logical.

• assume and assumeAlso do not accept assumptions that contain xor.

## Compatibility Considerations

expand all

Behavior changed in R2016b