octave: Element-by-element Boolean Operators

 
 8.5.1 Element-by-element Boolean Operators
 ------------------------------------------
 
 An “element-by-element boolean expression” is a combination of
 comparison expressions using the boolean operators “or” (‘|’), “and”
 (‘&’), and “not” (‘!’), along with parentheses to control nesting.  The
 truth of the boolean expression is computed by combining the truth
 values of the corresponding elements of the component expressions.  A
 value is considered to be false if it is zero, and true otherwise.
 
    Element-by-element boolean expressions can be used wherever
 comparison expressions can be used.  They can be used in ‘if’ and
 ‘while’ statements.  However, a matrix value used as the condition in an
 ‘if’ or ‘while’ statement is only true if _all_ of its elements are
 nonzero.
 
    Like comparison operations, each element of an element-by-element
 boolean expression also has a numeric value (1 if true, 0 if false) that
 comes into play if the result of the boolean expression is stored in a
 variable, or used in arithmetic.
 
    Here are descriptions of the three element-by-element boolean
 operators.
 
 ‘BOOLEAN1 & BOOLEAN2’
      Elements of the result are true if both corresponding elements of
      BOOLEAN1 and BOOLEAN2 are true.
 
 ‘BOOLEAN1 | BOOLEAN2’
      Elements of the result are true if either of the corresponding
      elements of BOOLEAN1 or BOOLEAN2 is true.
 
 ‘! BOOLEAN’
 ‘~ BOOLEAN’
      Each element of the result is true if the corresponding element of
      BOOLEAN is false.
 
    These operators work on an element-by-element basis.  For example,
 the expression
 
      [1, 0; 0, 1] & [1, 0; 2, 3]
 
 returns a two by two identity matrix.
 
    For the binary operators, broadcasting rules apply.  See
 Broadcasting.  In particular, if one of the operands is a scalar and
 the other a matrix, the operator is applied to the scalar and each
 element of the matrix.
 
    For the binary element-by-element boolean operators, both
 subexpressions BOOLEAN1 and BOOLEAN2 are evaluated before computing the
 result.  This can make a difference when the expressions have side
 effects.  For example, in the expression
 
      a & b++
 
 the value of the variable B is incremented even if the variable A is
 zero.
 
    This behavior is necessary for the boolean operators to work as
 described for matrix-valued operands.
 
  -- : Z = and (X, Y)
  -- : Z = and (X1, X2, ...)
      Return the logical AND of X and Y.
 
      This function is equivalent to the operator syntax ‘X & Y’.  If
      more than two arguments are given, the logical AND is applied
      cumulatively from left to right:
 
           (...((X1 & X2) & X3) & ...)
 
      At least one argument is required.
 
      See also: Seeor XREFor, Seenot XREFnot, Seexor XREFxor.
 
  -- : Z = not (X)
      Return the logical NOT of X.
 
      This function is equivalent to the operator syntax ‘! X’.
 
      See also: Seeand XREFand, Seeor XREFor, Seexor XREFxor.
 
  -- : Z = or (X, Y)
  -- : Z = or (X1, X2, ...)
      Return the logical OR of X and Y.
 
      This function is equivalent to the operator syntax ‘X | Y’.  If
      more than two arguments are given, the logical OR is applied
      cumulatively from left to right:
 
           (...((X1 | X2) | X3) | ...)
 
      At least one argument is required.
 
DONTPRINTYET       See also: Seeand XREFand, Seenot XREFnot, *notexor:
DONTPRINTYET       See also: Seeand XREFand, Seenot XREFnot, Seexor

      XREFxor.