🔍

COMP 1113 Week 6 Derived Operators

Oct 19, 2025

Overview

This lecture covers derived Boolean operators (NAND, NOR, XOR, XNOR), their representation in Java and databases, and how logic differs in three-valued (ternary) systems.

Derived Boolean Operators

  • NAND is NOT-AND; true except when both inputs are true.
  • NOR is NOT-OR; true only when both inputs are false.
  • XOR (exclusive OR) is true when inputs differ; false when both are the same.
  • XNOR (equivalence) is true when inputs are the same; false otherwise.
  • Derived operators have special symbols and gates (e.g., NAND: AND gate with circle, XOR: OR gate with extra line).
  • All derived operators can be written using AND, OR, and NOT.

Boolean Operators in Java

  • Java uses | (bitwise OR), & (bitwise AND), ^ (XOR), ! (NOT), || (Boolean OR), and && (Boolean AND).
  • Single | and & evaluate both sides always; double || and && short-circuit evaluation.
  • Short-circuiting avoids unnecessary operations and errors (e.g., division by zero).
  • Bitwise operators compare each corresponding bit of two integers.

Logic Simplification & Coding

  • Simplifying Boolean expressions improves code readability and efficiency.
  • Use Boolean algebra theorems (e.g., De Morgan's, absorption) for simplification.
  • Always list theorems used for each simplification step.

Boolean Logic in Databases (Ternary Logic)

  • Databases may use three logical values: true, false, and unknown (null).
  • NOT unknown remains unknown; AND/OR with unknown follows special truth tables.
  • Boolean logic must address cases where data is missing (null).

Key Terms & Definitions

  • NAND — NOT of AND; outputs false only if all inputs are true.
  • NOR — NOT of OR; outputs true only if all inputs are false.
  • XOR — Exclusive OR; outputs true if inputs differ.
  • XNOR — Exclusive NOR (equivalence); outputs true if inputs are the same.
  • Bitwise Operator — Evaluates logic on each bit of binary values.
  • Short-circuit Evaluation — Stops evaluation as soon as result is certain.
  • Ternary Logic — Logic system with three values: true, false, unknown (null).

Action Items / Next Steps

  • Practice writing and simplifying Boolean expressions.
  • Review Java Boolean and bitwise operator syntax.
  • Experiment with logic operators in Java or another language.
  • Be aware of ternary logic cases when working with databases.