xor

Logical XOR for symbolic expressions

Syntax

Description

example

xor(A,B) represents the logical exclusive disjunction. xor(A,B) is true when either A or B are 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 the logical expression using xor:

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

Replace variable x with these numeric values. 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 does not evaluate these 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, they return symbolic values TRUE or FALSE.

s1 = simplify(x1)
s2 = simplify(x2)
s1 =
TRUE
 
s2 =
FALSE

Convert symbolic TRUE or FALSE to logical values using isAlways:

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

ans =
  logical
     0

Input Arguments

collapse all

Input, specified as a number, vector, matrix, or array, or a symbolic number, variable, array, function, or expression.

Input, specified as a number, vector, matrix, or array, or a symbolic number, variable, array, function, or expression.

Tips

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

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

See Also

| | | | |

Introduced in R2012a