> ## Documentation Index
> Fetch the complete documentation index at: https://programming-for-career.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Boolean Algebra

> A comprehensive guide to Boolean algebra, covering fundamental concepts, logic gates, truth tables, and problem-solving techniques.

## Introduction

Boolean algebra is a branch of algebra that deals with binary variables and logical operations. It is fundamental in digital logic design, computer architecture, and circuit design.

## Basic Boolean Operations

Boolean algebra operates on binary values: `0` (False) and `1` (True). The fundamental operations are:

### AND (`⋅` or `∧`)

The AND operation returns `1` only if both inputs are `1`.

```plaintext Truth Table for AND theme={null}
A | B | A ⋅ B
--|--|------
0 | 0 |  0
0 | 1 |  0
1 | 0 |  0
1 | 1 |  1
```

### OR (`+` or `∨`)

The OR operation returns `1` if at least one input is `1`.

```plaintext Truth Table for OR theme={null}
A | B | A + B
--|--|------
0 | 0 |  0
0 | 1 |  1
1 | 0 |  1
1 | 1 |  1
```

### NOT (`¬` or `!`)

The NOT operation inverts the input.

```plaintext Truth Table for NOT theme={null}
A | ¬A
--|---
0 |  1
1 |  0
```

## Other Important Boolean Operations

### NAND (`⊼`)

NAND is the negation of AND.

```plaintext Truth Table for NAND theme={null}
A | B | A ⊼ B
--|--|------
0 | 0 |  1
0 | 1 |  1
1 | 0 |  1
1 | 1 |  0
```

### NOR (`⊽`)

NOR is the negation of OR.

```plaintext Truth Table for NOR theme={null}
A | B | A ⊽ B
--|--|------
0 | 0 |  1
0 | 1 |  0
1 | 0 |  0
1 | 1 |  0
```

### XOR (`⊕`)

XOR returns `1` if the inputs are different.

```plaintext Truth Table for XOR theme={null}
A | B | A ⊕ B
--|--|------
0 | 0 |  0
0 | 1 |  1
1 | 0 |  1
1 | 1 |  0
```

### XNOR (`⊙`)

XNOR returns `1` if the inputs are the same.

```plaintext Truth Table for XNOR theme={null}
A | B | A ⊙ B
--|--|------
0 | 0 |  1
0 | 1 |  0
1 | 0 |  0
1 | 1 |  1
```

## Boolean Algebra Laws

The following laws simplify Boolean expressions:

* **Identity Law**: `A + 0 = A`, `A ⋅ 1 = A`
* **Null Law**: `A + 1 = 1`, `A ⋅ 0 = 0`
* **Idempotent Law**: `A + A = A`, `A ⋅ A = A`
* **Complement Law**: `A + ¬A = 1`, `A ⋅ ¬A = 0`
* **Commutative Law**: `A + B = B + A`, `A ⋅ B = B ⋅ A`
* **Associative Law**: `(A + B) + C = A + (B + C)`, `(A ⋅ B) ⋅ C = A ⋅ (B ⋅ C)`
* **Distributive Law**: `A ⋅ (B + C) = (A ⋅ B) + (A ⋅ C)`
* **De Morgan’s Theorems**:
  * `¬(A ⋅ B) = ¬A + ¬B`
  * `¬(A + B) = ¬A ⋅ ¬B`

## Real-World Applications

### Digital Circuits

Boolean algebra is used in designing digital circuits such as:

* Logic gates (AND, OR, NOT, etc.)
* Flip-flops and memory storage
* Arithmetic logic units (ALUs)

### Programming & Conditional Statements

Boolean expressions control loops and conditions in programming:

```js JavaScript Example theme={null}
if (isUserLoggedIn && hasPermission) {
  console.log("Access granted");
} else {
  console.log("Access denied");
}
```

### Database Queries

SQL uses Boolean logic to filter data:

```sql SQL Example theme={null}
SELECT * FROM users WHERE age > 18 AND city = 'New York';
```

## Problem-Solving with Boolean Algebra

### Example 1: Simplify the Expression

Simplify `A ⋅ (A + B)`.

**Solution:**
Using the Absorption Law:

```
A ⋅ (A + B) = A
```

### Example 2: Circuit Implementation

Design a circuit that outputs `1` only when exactly one of two switches is ON.

**Solution:**
Use the XOR gate (`A ⊕ B`).

## Conclusion

Boolean algebra is a foundational concept in computer science and engineering. Mastering it allows for efficient circuit design, logical problem-solving, and optimized programming logic.
