Class BooleanAlgebra

java.lang.Object
org.episteme.core.mathematics.algebra.algebras.BooleanAlgebra
All Implemented Interfaces:
Iterable<Boolean>, AbelianMonoid<Boolean>, Magma<Boolean>, Monoid<Boolean>, Semiring<Boolean>, FiniteSet<Boolean>, Set<Boolean>

public final class BooleanAlgebra extends Object implements Semiring<Boolean>, FiniteSet<Boolean>
Boolean algebra - a special algebraic structure for logic operations.

A Boolean algebra is a complemented distributive lattice. It provides the mathematical foundation for logic, digital circuits, and set operations.

Mathematical Definition

A Boolean algebra (B, ∧, ∨, ¬, 0, 1) consists of:

  • A set B (typically {false, true} or {0, 1})
  • Binary operations: ∧ (AND), ∨ (OR)
  • Unary operation: ¬ (NOT)
  • Constants: 0 (false), 1 (true)

Boolean Algebra Laws

Commutative:    a ∧ b = b ∧ a,  a ∨ b = b ∨ a
Associative:    (a ∧ b) ∧ c = a ∧ (b ∧ c)
Distributive:   a ∧ (b ∨ c) = (a ∧ b) ∨ (a ∧ c)
Identity:       a ∧ 1 = a,  a ∨ 0 = a
Complement:     a ∧ ¬a = 0,  a ∨ ¬a = 1
De Morgan:      ¬(a ∧ b) = ¬a ∨ ¬b

Applications

  • Digital Logic: Circuit design, gates
  • Programming: Conditional logic, bitwise operations
  • Set Theory: ∩ (AND), ∪ (OR), complement (NOT)
  • Database Queries: SQL WHERE clauses
  • AI/Logic: Propositional logic, inference

Usage Examples

BooleanAlgebra bool = BooleanAlgebra.getInstance();

// Logic operations
Boolean result = bool.and(true, false); // false
Boolean result2 = bool.or(true, false); // true
Boolean result3 = bool.not(true); // false
Boolean result4 = bool.xor(true, true); // false

// De Morgan's laws
Boolean a = true, b = false;
assert bool.not(bool.and(a, b)).equals(
        bool.or(bool.not(a), bool.not(b)));

// Digital circuit simulation
Boolean nandGate = bool.not(bool.and(input1, input2));

Relation to Other Structures

  • Boolean algebra is NOT a field (no meaningful addition)
  • It's a special case of a lattice
  • Two-element Boolean algebra: {0, 1} or {false, true}
  • Can have larger Boolean algebras (power sets)

References

  • George Boole, "The Mathematical Analysis of Logic", Cambridge: Macmillan, Barclay, and Macmillan, 1847
  • Claude E. Shannon, "A Symbolic Analysis of Relay and Switching Circuits", Master's Thesis, MIT, 1937
  • Alfred North Whitehead and Bertrand Russell, "Principia Mathematica", Cambridge University Press, 1910-1913
* @author Silvere Martin-Michiellot
Since:
1.0
Author:
Gemini AI (Google DeepMind)
  • Method Details

    • getInstance

      public static BooleanAlgebra getInstance()
      Returns the singleton instance.
      Returns:
      the Boolean algebra instance
    • operate

      public Boolean operate(Boolean a, Boolean b)
      Description copied from interface: Magma
      Performs the binary operation on two elements.

      This is the fundamental operation of a magma. The result must be an element of this magma (closure property).

      Properties: None required (not necessarily associative or commutative)

      Specified by:
      operate in interface Magma<Boolean>
      Parameters:
      a - the first operand
      b - the second operand
      Returns:
      the result of a ∗ b
      See Also:
    • add

      public Boolean add(Boolean a, Boolean b)
      Description copied from interface: AbelianMonoid
      Returns the sum of two elements (additive notation).

      Delegates to Magma.operate(Object, Object).

      Specified by:
      add in interface AbelianMonoid<Boolean>
      Parameters:
      a - the first addend
      b - the second addend
      Returns:
      a + b
    • zero

      public Boolean zero()
      Description copied from interface: AbelianMonoid
      Returns the additive identity (zero element).

      Delegates to AbelianMonoid.identity().

      Specified by:
      zero in interface AbelianMonoid<Boolean>
      Returns:
      the zero element
    • multiply

      public Boolean multiply(Boolean a, Boolean b)
      Description copied from interface: Semiring
      Returns the product of two elements.

      Multiplication must be associative and distribute over addition.

      Specified by:
      multiply in interface Semiring<Boolean>
      Parameters:
      a - the first factor
      b - the second factor
      Returns:
      a × b
    • one

      public Boolean one()
      Description copied from interface: Semiring
      Returns the multiplicative identity (one element).

      Satisfies: 1 × a = a × 1 = a for all elements a.

      Specified by:
      one in interface Semiring<Boolean>
      Returns:
      the multiplicative identity
    • isMultiplicationCommutative

      public boolean isMultiplicationCommutative()
      Description copied from interface: Semiring
      Tests whether multiplication is commutative in this semiring.
      Specified by:
      isMultiplicationCommutative in interface Semiring<Boolean>
      Returns:
      true if multiplication commutes
    • size

      public long size()
      Description copied from interface: FiniteSet
      Returns the number of elements in this set (its cardinality).
      Specified by:
      size in interface FiniteSet<Boolean>
      Returns:
      the cardinality of this set
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: Set
      Returns true if this set contains no elements.

      The empty set (∅) is a fundamental concept in set theory. It is the unique set containing no elements.

      Specified by:
      isEmpty in interface Set<Boolean>
      Returns:
      true if this set is empty
    • contains

      public boolean contains(Boolean element)
      Description copied from interface: Set
      Tests whether this set contains the specified element.

      This is the fundamental operation of a set - membership testing.

      Specified by:
      contains in interface Set<Boolean>
      Parameters:
      element - the element to test for membership
      Returns:
      true if this set contains the element, false otherwise
      See Also:
    • iterator

      public Iterator<Boolean> iterator()
      Description copied from interface: FiniteSet
      Returns an iterator over the elements in this set.
      Specified by:
      iterator in interface FiniteSet<Boolean>
      Specified by:
      iterator in interface Iterable<Boolean>
      Returns:
      an iterator over the elements in this set
    • stream

      public Stream<Boolean> stream()
      Description copied from interface: FiniteSet
      Returns a sequential Stream with this set as its source.
      Specified by:
      stream in interface FiniteSet<Boolean>
      Returns:
      a stream over the elements in this set
    • description

      public String description()
      Description copied from interface: Set
      Returns a human-readable description of this set.

      Examples:

      • "ℝ (Real Numbers)"
      • "ℤ/12ℤ (Integers modulo 12)"
      • "{1, 2, 3, 4, 5}"

      Specified by:
      description in interface Set<Boolean>
      Returns:
      a description of this set
    • and

      public Boolean and(Boolean a, Boolean b)
      Logical AND (conjunction, meet, ∧).

      Truth table:

      a     b     a ∧ b
      false false false
      false true  false
      true  false false
      true  true  true
      

      Parameters:
      a - first operand
      b - second operand
      Returns:
      a ∧ b
    • or

      public Boolean or(Boolean a, Boolean b)
      Logical OR (disjunction, join, ∨).

      Truth table:

      a     b     a ∨ b
      false false false
      false true  true
      true  false true
      true  true  true
      

      Parameters:
      a - first operand
      b - second operand
      Returns:
      a ∨ b
    • not

      public Boolean not(Boolean a)
      Logical NOT (complement, negation, ¬).
      Parameters:
      a - the operand
      Returns:
      ¬a
    • xor

      public Boolean xor(Boolean a, Boolean b)
      Logical XOR (exclusive or, ⊕).

      Returns true if operands differ.

      Parameters:
      a - first operand
      b - second operand
      Returns:
      a ⊕ b
    • nand

      public Boolean nand(Boolean a, Boolean b)
      Logical NAND (NOT AND).

      Universal gate - can construct any logic circuit.

      Parameters:
      a - first operand
      b - second operand
      Returns:
      ¬(a ∧ b)
    • nor

      public Boolean nor(Boolean a, Boolean b)
      Logical NOR (NOT OR).

      Universal gate - can construct any logic circuit.

      Parameters:
      a - first operand
      b - second operand
      Returns:
      ¬(a ∨ b)
    • implies

      public Boolean implies(Boolean a, Boolean b)
      Logical implication (→).

      a → b is equivalent to ¬a ∨ b. False implies anything; true implies only true.

      Parameters:
      a - premise
      b - conclusion
      Returns:
      a → b
    • equivalent

      public Boolean equivalent(Boolean a, Boolean b)
      Logical equivalence (biconditional, ↔).

      True if both operands have the same value.

      Parameters:
      a - first operand
      b - second operand
      Returns:
      a ↔ b
    • toString

      public String toString()
      Overrides:
      toString in class Object