diff --git a/notes/README.md b/notes/README.md new file mode 100644 index 0000000..ad628bd --- /dev/null +++ b/notes/README.md @@ -0,0 +1,74 @@ +# Math & CS Notes Repository + +A structured collection of study notes spanning pure mathematics, theoretical computer science, physics, programming, networking, and AI architecture. + +## Contents + +### Math +- [Complex Numbers](math/complex-numbers.md) -- Conjugates, Euler's formula, Taylor expansion of e^(ix) +- [Modular Arithmetic](math/modular-arithmetic.md) -- Definition, clock arithmetic, congruence properties +- [Linear Algebra](math/linear-algebra.md) -- Function spaces K^X, scalar-product associativity proof + +### Theoretical Computer Science +- [The Halting Problem](theoretical-cs/halting-problem.md) -- Turing's undecidability proof, h/h+ construction, self-reference +- [Paradoxes & Self-Reference](theoretical-cs/paradoxes.md) -- Liar paradox, Cantor diagonalization, Monty Hall Trolley Problem + +### Physics +- [Quantum Mechanics](physics/quantum-mechanics.md) -- Schrodinger equation, wave functions, Hilbert space + +### Programming +- [Python Mutability](programming/python-mutability.md) -- References vs copies, list aliasing, += rebinding behavior + +### Networking +- [VLAN Configuration](networking/vlan-configuration.md) -- Cisco switch commands, access/trunk modes +- [IPv4 Subnetting](networking/ipv4-subnetting.md) -- Complete CIDR table, binary calculations, private ranges, IPv4 classes +- [DNS](networking/dns.md) -- Resolution flow, hierarchy, record types + +### AI Architecture +- [Agentic Patterns](ai-architecture/agentic-patterns.md) -- Multi-agent patterns: parallel, sequential, loop, router, aggregator, network, hierarchical + +### Puzzles & Misc +- [Connect All 9](puzzles/connect-nine.md) -- Classic dot puzzle, triangular numbers (termial) +- [Orbital Mechanics](puzzles/orbital-mechanics.md) -- Planetary orbits, Kepler's laws + +## Topic Map + +``` + ┌─────────────────┐ + │ Complex Numbers│ + └────────┬────────┘ + │ Euler's formula + ▼ + ┌─────────────────┐ ┌──────────────┐ + │ Quantum │────────→ │ Linear │ + │ Mechanics │ Hilbert │ Algebra │ + └─────────────────┘ space └──────────────┘ + │ + ┌─────────────────┐ │ finite fields + │ Modular │ ←───────────────┘ + │ Arithmetic │ + └────────┬────────┘ + │ binary math + ▼ + ┌─────────────────┐ + │ IPv4 Subnetting │ + └────────┬────────┘ + │ + ┌────────┴────────┐ + │ VLAN DNS │ + └─────────────────┘ + + ┌─────────────────┐ ┌──────────────────┐ + │ Halting Problem │────────→│ Paradoxes & │ + │ (Turing 1936) │ self- │ Self-Reference │ + └──────────────────┘ ref └──────────────────┘ + + ┌─────────────────┐ ┌──────────────────┐ + │ Python │ shared │ Agentic │ + │ Mutability │ state │ Architectures │ + └──────────────────┘────────└──────────────────┘ +``` + +## Source + +Notes transcribed from handwritten pages, reference images, and community discussions (r/askmath, r/trolleyproblem, r/askastronomy, r/PythonLearnersHub, networks.baseline, leadgenman). diff --git a/notes/ai-architecture/agentic-patterns.md b/notes/ai-architecture/agentic-patterns.md new file mode 100644 index 0000000..d888f59 --- /dev/null +++ b/notes/ai-architecture/agentic-patterns.md @@ -0,0 +1,136 @@ +# Agentic Architectures + +## Single System vs Multi-Agent System + +### Single System +``` +User ──→ AI Agent ──→ Response + │ + Memory + Tools +``` + +### Multi-Agent System +``` +User ──→ AI Agent ←──→ AI Agent + │ │ + Memory Tools + Tools Memory +``` + +Multiple agents collaborate, each with their own memory and tools. + +## Patterns in Multi-Agent Systems + +### 1. Parallel +``` + ┌─ AI Agent ─┐ +In ──→───┤ ├───→ Out + └─ AI Agent ─┘ +``` +Multiple agents process the same input simultaneously. Good for speed and redundancy. + +### 2. Sequential +``` +In ──→ AI Agent ──→ AI Agent ──→ Out +``` +Each agent's output feeds into the next. Good for pipelines and staged processing. + +### 3. Loop +``` +In ──→ AI Agent ──→ AI Agent ──→ Out + ▲ │ + └──────────────┘ +``` +Agents iterate until a condition is met. Good for refinement and self-correction. + +### 4. Router +``` + ┌──→ Out +In ──→ AI Agent + └──→ Out +``` +One agent decides where to send the input. Good for classification and routing. + +### 5. Aggregator +``` +In ──→───┐ + AI Agent ──→ Out +In ──→───┘ +``` +Combines multiple inputs into a single output. Good for summarization and synthesis. + +### 6. Network +``` + ┌─────────────┐ +In ──→ AI Agent ←→ AI Agent ──→ Out + └─→ AI Agent ←─┘ +``` +Fully connected agents that can communicate freely. Good for complex reasoning. + +### 7. Hierarchical +``` + AI Agent (manager) + / \ + AI Agent AI Agent +``` +A manager agent delegates to worker agents. Good for task decomposition. + +## Architecture Examples (with Tools) + +### Hierarchical (with external services) +``` + AI Agent (orchestrator) + / | \ + AI Agent AI Agent AI Agent + | | | + Vector Search Web Search Gmail + Vector Search Vector Search +``` + +### Human-in-the-Loop +``` +User Input ──→ AI Agent ──→ Person ──→ Response + │ │ + AI Agent ←─────────────────┘ +``` + +### Shared Tools +``` +User Input ──→ AI Agent ──→ Response + │ + ┌─────┼─────┐ + Vector Search Web Search Vector DB +``` + +### Database with Tools +``` +User Input ──→ AI Agent ──→ Response + │ + ┌─────┼─────┐ + AI/KB Web Search Vector DB + Data Transform +``` + +### Memory Transformation +``` +User Input ──→ AI Agent ──→ Response + │ + ┌─────┼──────────┐ + Web Search Vector Search Vector DB + AI Agent Memory Data Transform +``` + +## Relevance to BlackRoad + +BlackRoad's architecture uses several of these patterns: +- **Router**: The Operator classifies and routes requests +- **Hierarchical**: Cece delegates to specialized tools/services +- **Sequential**: Request → classify → route → execute → respond +- **Shared Tools**: Multiple agents share NumPy, Claude, GPT, Hailo-8 + +## Connections + +- Routing patterns connect to [DNS](../networking/dns.md) (hierarchical resolution) +- Agent memory relates to [Python Mutability](../programming/python-mutability.md) (shared vs. isolated state) +- The halting problem ([Halting Problem](../theoretical-cs/halting-problem.md)) limits what agents can decide diff --git a/notes/math/complex-numbers.md b/notes/math/complex-numbers.md new file mode 100644 index 0000000..91a972a --- /dev/null +++ b/notes/math/complex-numbers.md @@ -0,0 +1,60 @@ +# Complex Numbers + +## Multiplication of Complex Conjugates + +``` +a(a - aib + aib - ibib) += a² - (ib)² += a² + b² +``` + +**Key identity:** + +``` +(a + ib)(a - ib) = a² + b² +``` + +This is the **complex conjugate product** -- multiplying a complex number by its conjugate always yields a real number. + +## Imaginary Numbers + +``` +(y + x)² y +``` + +- Imaginary unit: `i² = -1` +- Complex number form: `z = a + bi` + +## Real Numbers + +- `x` is real +- **Euler's identity:** `e^(iπ) + 1 = 0` +- Magnitude: `(y + x)²` + +### Absolute Value + +``` +|x| = 1 +|x - 1| = -1 (Note: absolute value is always >= 0; this explores when the inner expression is negative) +A = 1 +``` + +## Euler's Formula Expansion + +``` +e^(ix) = 1 + ix - x²/2 - ix³/6 + x⁴/24 - ... +``` + +This is the **Taylor series expansion** of `e^(ix)`: + +``` +e^(ix) = cos(x) + i·sin(x) + +cos(x) = 1 - x²/2! + x⁴/4! - ... +sin(x) = x - x³/3! + x⁵/5! - ... +``` + +## Connections + +- Complex numbers connect to [Quantum Mechanics](../physics/quantum-mechanics.md) via the Schrodinger equation +- Euler's formula connects to [Modular Arithmetic](modular-arithmetic.md) through cyclic groups diff --git a/notes/math/linear-algebra.md b/notes/math/linear-algebra.md new file mode 100644 index 0000000..55c8a87 --- /dev/null +++ b/notes/math/linear-algebra.md @@ -0,0 +1,71 @@ +# Linear Algebra - Function Spaces + +## Function Space Definition + +The set of all functions from X to a field K: + +``` +K^X = { f : X → K } +``` + +This is a **vector space** of functions. + +## Operations on Function Spaces + +### Addition of Functions +``` +(f + g)(x) := f(x) + g(x) +``` + +### Scalar Multiplication +``` +(λ · f)(x) := λ · f(x) +``` + +### Pointwise Multiplication +``` +(f * g)(x) := f(x) · g(x) +``` + +## Key Property: Scalar-Product Associativity + +**Proposition 2.2:** + +``` +λ · (a * b) = (λ · a) * b = a * (λ · b) +``` + +### Proof + +Starting from the left side: + +``` +(λ · (f * g))(x) = λ · ((f * g)(x)) + = λ · (f(x) · g(x)) + = (λ · f(x)) · g(x) + = ((λ · f) * g)(x) +``` + +And from the right side: + +``` += f(x) · (λ · g(x)) += (f * (λ · g))(x) +``` + +This shows scalar multiplication can "pass through" the pointwise product to either factor. + +## Why This Matters + +This property establishes that **K^X is an algebra over K** -- not just a vector space, but one with a compatible multiplication operation. This is fundamental to: + +- **Functional analysis** +- **Operator theory** +- **Quantum mechanics** (operators on Hilbert spaces) +- **Signal processing** (function spaces) + +## Connections + +- Function spaces connect to [Quantum Mechanics](../physics/quantum-mechanics.md) (wave functions live in Hilbert space) +- Scalar properties relate to [Modular Arithmetic](modular-arithmetic.md) through ring theory +- [Complex Numbers](complex-numbers.md) form the field K in quantum mechanics diff --git a/notes/math/modular-arithmetic.md b/notes/math/modular-arithmetic.md new file mode 100644 index 0000000..7739bd2 --- /dev/null +++ b/notes/math/modular-arithmetic.md @@ -0,0 +1,98 @@ +# Modular Arithmetic + +## Definition + +If A and B are two integers, and A is divided by B, then the relationship: + +``` +A = B × Q + R +``` + +is written in modular arithmetic as: + +``` +A (mod B) = R +``` + +Where: +- **A** = Dividend +- **B** = Divisor (modulus) +- **Q** = Quotient +- **R** = Remainder + +## Examples + +### Basic Example + +``` +14 ÷ 3 = 4, remainder 2 +→ 14 (mod 3) = 2 +``` + +### Detailed Breakdown + +``` +In Math: 11 : 3 = 3 remaining 2 + +In Modular: 2 ≡ 11 mod 3 + 11 = (3 × 3) + 2 + +In Alteryx: Mod(11, 3) → "Modulo of 11 divided by 3" +``` + +## Clock Arithmetic (mod 12) + +The clock is the most intuitive example of modular arithmetic: + +``` +9 o'clock + 4 hours = 1 o'clock +Because: 9 + 4 = 13 ≡ 1 (mod 12) +``` + +**13 is the same as 1 when divided by 12.** + +Other clock examples: +``` +10 + 5 = 15 ≡ 3 (mod 12) +6 + 6 = 12 ≡ 0 (mod 12) +11 + 3 = 14 ≡ 2 (mod 12) +``` + +## Properties of Modular Arithmetic + +If `a ≡ b (mod n)`, then: + +### Addition +``` +a + k ≡ b + k (mod n) +``` + +### Subtraction +``` +a - k ≡ b - k (mod n) +``` + +### Scalar Multiplication +``` +k·a ≡ k·b (mod n) +``` + +### Exponentiation +``` +a^k ≡ b^k (mod n) +``` + +These properties mean you can **add, subtract, multiply, and exponentiate** both sides of a modular congruence and the relationship holds. + +## Applications + +- **Cryptography** (RSA, Diffie-Hellman) +- **Hash functions** +- **Clock arithmetic / cyclic systems** +- **Error-detecting codes** (ISBN, checksums) +- **Calendar calculations** (day of week) + +## Connections + +- Modular arithmetic underlies much of [IPv4 Subnetting](../networking/ipv4-subnetting.md) (binary math) +- Connects to [Linear Algebra](linear-algebra.md) through finite fields diff --git a/notes/networking/dns.md b/notes/networking/dns.md new file mode 100644 index 0000000..48d6356 --- /dev/null +++ b/notes/networking/dns.md @@ -0,0 +1,81 @@ +# DNS (Domain Name System) + +## What is DNS? + +DNS translates human-readable domain names to IP addresses. + +``` +www.google.com → DNS → 142.250.185.36 +(Domain Name) (IP Address) +``` + +## DNS Resolution Flow + +``` + ┌──────────────┐ + │ Root DNS │ + │ Server │ + └──────┬───────┘ + │ + ▼ + ┌──────────────┐ + │ TLD Server │ + │ (.com, .edu)│ + └──────┬───────┘ + │ + ▼ + ┌──────────────┐ + │ Authoritative│ + │ Domain Server│ + └──────────────┘ + ▲ + │ +┌──────────┐ ┌──────────────┐ │ +│ HOST │ ←──→ │ DNS Resolver │───┘ +│ (client) │ │ │ +└──────────┘ └──────┬───────┘ + │ + ▼ + ┌──────────────┐ + │ Cache │ + └──────────────┘ +``` + +## Resolution Steps + +1. **Host** sends query to **DNS Resolver** (usually your ISP or 8.8.8.8) +2. **Resolver** checks its **Cache** first +3. If not cached, queries the **Root DNS Server** +4. Root points to the **TLD Server** (.com, .edu, .org, etc.) +5. TLD points to the **Authoritative Domain Server** +6. Authoritative server returns the actual IP address +7. Resolver **caches** the result and returns it to the host + +## DNS Hierarchy + +``` + Root (.) + / \ + .com .edu + | | + google mit + | | + www www +``` + +## Record Types + +| Type | Purpose | Example | +|------|---------|---------| +| A | IPv4 address | google.com → 142.250.185.36 | +| AAAA | IPv6 address | google.com → 2607:f8b0:... | +| CNAME | Alias | www.google.com → google.com | +| MX | Mail server | google.com → smtp.google.com | +| NS | Nameserver | google.com → ns1.google.com | +| TXT | Text data | SPF, DKIM, verification | + +## Connections + +- DNS names map to IPs in [IPv4 Subnetting](ipv4-subnetting.md) ranges +- VLANs ([VLAN Configuration](vlan-configuration.md)) can affect DNS resolution paths +- DNS is part of the networking layer that [BlackRoad's routing](../ai-architecture/agentic-patterns.md) builds upon diff --git a/notes/networking/ipv4-subnetting.md b/notes/networking/ipv4-subnetting.md new file mode 100644 index 0000000..87e40e3 --- /dev/null +++ b/notes/networking/ipv4-subnetting.md @@ -0,0 +1,90 @@ +# IPv4 Subnetting + +## Subnetting Table + +| CIDR | Subnet Mask | Wildcard | Addresses | +|------|-------------|----------|-----------| +| /32 | 255.255.255.255 | 0.0.0.0 | 1 | +| /31 | 255.255.255.254 | 0.0.0.1 | 2 | +| /30 | 255.255.255.252 | 0.0.0.3 | 4 | +| /29 | 255.255.255.248 | 0.0.0.7 | 8 | +| /28 | 255.255.255.240 | 0.0.0.15 | 16 | +| /27 | 255.255.255.224 | 0.0.0.31 | 32 | +| /26 | 255.255.255.192 | 0.0.0.63 | 64 | +| /25 | 255.255.255.128 | 0.0.0.127 | 128 | +| /24 | 255.255.255.0 | 0.0.0.255 | 256 | +| /23 | 255.255.254.0 | 0.0.1.255 | 512 | +| /22 | 255.255.252.0 | 0.0.3.255 | 1,024 | +| /21 | 255.255.248.0 | 0.0.7.255 | 2,048 | +| /20 | 255.255.240.0 | 0.0.15.255 | 4,096 | +| /19 | 255.255.224.0 | 0.0.31.255 | 8,192 | +| /18 | 255.255.192.0 | 0.0.63.255 | 16,384 | +| /17 | 255.255.128.0 | 0.0.127.255 | 32,768 | +| /16 | 255.255.0.0 | 0.0.255.255 | 65,536 | +| /15 | 255.254.0.0 | 0.1.255.255 | 131,072 | +| /14 | 255.252.0.0 | 0.3.255.255 | 262,144 | +| /13 | 255.248.0.0 | 0.7.255.255 | 524,288 | +| /12 | 255.240.0.0 | 0.15.255.255 | 1,048,576 | +| /11 | 255.224.0.0 | 0.31.255.255 | 2,097,152 | +| /10 | 255.192.0.0 | 0.63.255.255 | 4,194,304 | +| /9 | 255.128.0.0 | 0.127.255.255 | 8,388,608 | +| /8 | 255.0.0.0 | 0.255.255.255 | 16,777,216 | +| /4 | 240.0.0.0 | 15.255.255.255 | 268,435,456 | +| /0 | 0.0.0.0 | 255.255.255.255 | 4,294,967,296 | + +## Subnet Sizes (Visual) + +The larger the CIDR prefix, the smaller the subnet: + +``` +/25 ████████████████████░░░░░░░░░░░░░░░░░░░░ 128 hosts +/26 ██████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 64 hosts +/27 █████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 32 hosts +/28 ███░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 16 hosts +/29 ██░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 8 hosts +/30 █░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 4 hosts +``` + +## Private IPv4 Ranges + +| Prefix | Range | +|--------|-------| +| 10.0.0.0/8 | 10.0.0.0 - 10.255.255.255 | +| 172.16.0.0/12 | 172.16.0.0 - 172.31.255.255 | +| 192.168.0.0/16 | 192.168.0.0 - 192.168.255.255 | + +## Binary Calculation Reference + +| Subnet Mask | Binary | Wildcard | +|-------------|--------|----------| +| 255 | 1111 1111 | 0 (0000 0000) | +| 254 | 1111 1110 | 1 (0000 0001) | +| 252 | 1111 1100 | 3 (0000 0011) | +| 248 | 1111 1000 | 7 (0000 0111) | +| 240 | 1111 0000 | 15 (0000 1111) | +| 224 | 1110 0000 | 31 (0001 1111) | +| 192 | 1100 0000 | 63 (0011 1111) | +| 128 | 1000 0000 | 127 (0111 1111) | +| 0 | 0000 0000 | 255 (1111 1111) | + +## IPv4 Classes + +| Class | Range | +|-------|-------| +| A | 0.0.0.0 - 127.255.255.255 | +| B | 128.0.0.0 - 191.255.255.255 | +| C | 192.0.0.0 - 223.255.255.255 | + +## Key Formula + +``` +Usable hosts = 2^(32 - CIDR) - 2 +``` + +Subtract 2 for the network address and broadcast address. + +## Connections + +- Binary math connects to [Modular Arithmetic](../math/modular-arithmetic.md) +- Network segmentation relates to [VLAN Configuration](vlan-configuration.md) +- Name resolution happens via [DNS](dns.md) diff --git a/notes/networking/vlan-configuration.md b/notes/networking/vlan-configuration.md new file mode 100644 index 0000000..79f2917 --- /dev/null +++ b/notes/networking/vlan-configuration.md @@ -0,0 +1,51 @@ +# VLAN Configuration - Cisco Switch + +## What is a VLAN? + +A **Virtual LAN (VLAN)** segments a physical network into isolated logical networks at Layer 2. Devices in different VLANs cannot communicate without a router (Layer 3). + +## Configuration Steps + +### 1. Create a VLAN + +``` +Switch(config)# vlan 10 +Switch(config-vlan)# name IT_Department +``` + +### 2. Assign VLAN to a Port + +``` +Switch(config)# interface Fa0/1 +Switch(config-if)# switchport mode access +Switch(config-if)# switchport access vlan 10 +``` + +### 3. Verification + +``` +Switch# show vlan brief +Switch# show interface fa0/1 switchport +``` + +## Quick Reference + +| Command | Purpose | +|---------|---------| +| `vlan ` | Create VLAN with given ID | +| `name ` | Name the VLAN | +| `interface Fa0/1` | Select a port | +| `switchport mode access` | Set port to access mode (single VLAN) | +| `switchport access vlan ` | Assign port to VLAN | +| `show vlan brief` | View all VLANs and port assignments | +| `show interface fa0/1 switchport` | View port's VLAN config | + +## VLAN Modes + +- **Access mode**: Port belongs to one VLAN (end devices) +- **Trunk mode**: Port carries traffic for multiple VLANs (switch-to-switch links) + +## Connections + +- VLANs segment traffic at Layer 2, while [IPv4 Subnetting](ipv4-subnetting.md) segments at Layer 3 +- [DNS](dns.md) resolves names within and across VLAN boundaries diff --git a/notes/physics/quantum-mechanics.md b/notes/physics/quantum-mechanics.md new file mode 100644 index 0000000..6600b8b --- /dev/null +++ b/notes/physics/quantum-mechanics.md @@ -0,0 +1,57 @@ +# Quantum Mechanics + +## The Schrodinger Equation + +From the handwritten notes: + +``` +HΨ = iℏ (∂Ψ/∂t) +``` + +Where: +- **H** = Hamiltonian operator (total energy of the system) +- **Ψ** (Psi) = Wave function (describes the quantum state) +- **i** = Imaginary unit (√-1) +- **ℏ** = Reduced Planck's constant (h/2π ≈ 1.055 × 10⁻³⁴ J·s) +- **∂Ψ/∂t** = Partial derivative of the wave function with respect to time + +## What It Means + +The Schrodinger equation is the **fundamental equation of quantum mechanics**. It describes how the quantum state of a physical system changes over time. + +### Left side: `HΨ` +- The Hamiltonian `H` acting on the wave function +- Represents the total energy (kinetic + potential) of the system +- `H` is a **linear operator** (connects to [Linear Algebra](../math/linear-algebra.md)) + +### Right side: `iℏ (∂Ψ/∂t)` +- How the wave function evolves in time +- The `i` makes the evolution **unitary** (preserves probability) +- The `ℏ` sets the scale of quantum effects + +## Why Complex Numbers Are Essential + +The `i` in the Schrodinger equation is not optional -- quantum mechanics **requires** complex numbers: + +- Wave functions are complex-valued: `Ψ(x,t) ∈ ℂ` +- Probability = |Ψ|² (magnitude squared of complex number) +- Interference comes from complex phase: `e^(iθ)` + +This connects directly to [Complex Numbers](../math/complex-numbers.md) and Euler's formula: + +``` +e^(ix) = cos(x) + i·sin(x) +``` + +## Wave Functions Live in Hilbert Space + +- Hilbert space is an infinite-dimensional [function space](../math/linear-algebra.md) +- K^X = { f : X → K } where K = ℂ (complex numbers) +- Inner product: ⟨f|g⟩ = ∫ f*(x)·g(x) dx +- Operators (like H) act on this space + +## Connections + +- Complex numbers: [Complex Numbers](../math/complex-numbers.md) -- Euler's formula, e^(ix) +- Function spaces: [Linear Algebra](../math/linear-algebra.md) -- Hilbert space, operators +- Undecidability: [Halting Problem](../theoretical-cs/halting-problem.md) -- some quantum systems are undecidable too diff --git a/notes/programming/python-mutability.md b/notes/programming/python-mutability.md new file mode 100644 index 0000000..6dc5bbd --- /dev/null +++ b/notes/programming/python-mutability.md @@ -0,0 +1,96 @@ +# Python Mutability & References + +## The Puzzle (from r/PythonLearnersHub) + +```python +# Output of this Python program? +a = [[1], [2]] +b = a +b[0].append(11) +b += [[3]] +b[1].append(22) +b[2].append(33) + +print(a) +``` + +### Possible Answers +``` +A) [[1], [2]] +B) [[1, 11], [2]] +C) [[1, 11], [2, 22]] +D) [[1, 11], [2, 22], [3, 33]] +``` + +### Correct Answer: **C) [[1, 11], [2, 22]]** + +## Why? + +### Step-by-step trace: + +```python +a = [[1], [2]] # a points to a list of two lists +b = a # b points to the SAME object as a (no copy!) + +b[0].append(11) # Mutates the first inner list + # a is now [[1, 11], [2]] (same object!) + +b += [[3]] # THIS IS THE KEY LINE + # b += [[3]] is equivalent to b = b + [[3]] + # This creates a NEW list and reassigns b + # Now b = [[1, 11], [2], [3]] + # But a still points to the ORIGINAL list! + # a = [[1, 11], [2]] + +b[1].append(22) # Mutates b's second element + # But b[1] is still the SAME object as a[1] + # So a[1] also becomes [2, 22] + # a = [[1, 11], [2, 22]] + +b[2].append(33) # Mutates b's third element [3] → [3, 33] + # a has no third element, unaffected +``` + +### Final state: +```python +a = [[1, 11], [2, 22]] # Answer C +b = [[1, 11], [2, 22], [3, 33]] +``` + +## Key Concepts + +### Assignment creates references, not copies +```python +b = a # b and a point to the SAME object +``` + +### `+=` on lists can rebind +```python +b += [[3]] # Creates new list, rebinds b + # Different from b.extend([[3]]) which mutates in-place +``` + +### Inner lists are shared objects +Even after `b` is reassigned, `b[0]` and `a[0]` still point to the same inner list, so mutations to one affect the other. + +## Mental Model + +``` +Before b += [[3]]: +a ──→ [ ref0, ref1 ] +b ──→ ↑ (same object) + ref0 → [1, 11] + ref1 → [2] + +After b += [[3]]: +a ──→ [ ref0, ref1 ] (original list) +b ──→ [ ref0, ref1, ref2 ] (NEW list, but shares ref0 and ref1) + ref0 → [1, 11] + ref1 → [2, 22] + ref2 → [3, 33] +``` + +## Connections + +- Memory models relate to [Agentic Architecture](../ai-architecture/agentic-patterns.md) (shared memory vs. isolated agents) +- Binary representation relates to [IPv4 Subnetting](../networking/ipv4-subnetting.md) diff --git a/notes/puzzles/connect-nine.md b/notes/puzzles/connect-nine.md new file mode 100644 index 0000000..edb9761 --- /dev/null +++ b/notes/puzzles/connect-nine.md @@ -0,0 +1,55 @@ +# Connect All 9 Puzzle + +## The Problem + +Given a 3x3 grid of 9 dots: + +``` +● ● ● +● ● ● +● ● ● +``` + +**Rules:** +1. Connect all 9 dots +2. Use four straight lines +3. Without lifting your pen +4. Without retracing + +## The Termial (Triangular Number) + +From the comments: **"Termial of 9 is 45"** + +The **termial** (triangular number) of n is: + +``` +T(n) = 1 + 2 + 3 + ... + n = n(n+1)/2 +``` + +For n = 9: +``` +T(9) = 9 × 10 / 2 = 45 +``` + +This is the sum of all integers from 1 to 9. + +## The Solution (Thinking Outside the Box) + +The classic solution requires extending lines **beyond the grid boundary**: + +``` +Start ──→──→──→──┐ + │ (line extends past the dots) + ┌──←──←──←──←┘ + │ + └──→──→──→──→──┐ + │ + ←──←──←──←┘ +``` + +This is the origin of the phrase **"thinking outside the box."** + +## Connections + +- Connects to [Paradoxes](../theoretical-cs/paradoxes.md) -- breaking assumed constraints +- The triangular number formula uses concepts from [Modular Arithmetic](../math/modular-arithmetic.md) (summation patterns) diff --git a/notes/puzzles/orbital-mechanics.md b/notes/puzzles/orbital-mechanics.md new file mode 100644 index 0000000..30f1742 --- /dev/null +++ b/notes/puzzles/orbital-mechanics.md @@ -0,0 +1,42 @@ +# Orbital Mechanics + +## The Question (from r/askastronomy) + +**"How can this be possible?"** -- referring to a diagram showing what appears to be overlapping planetary orbits that look chaotic. + +## What the Diagram Shows + +The rough diagram shows orbital paths of planets/bodies around a central star/point. The orbits appear as nested, overlapping ellipses with different eccentricities and inclinations, creating a pattern that looks like a spirograph. + +Key points visible: +- Multiple colored dots representing different bodies (planets/moons) +- Orbits are **not** perfect circles -- they're ellipses +- Orbits have different **inclinations** (tilted relative to each other) +- Paths cross each other in 2D projection but are separated in 3D + +## Why It Works + +1. **Orbits are 3D**: What looks like crossing paths in a 2D projection actually have separation in the third dimension +2. **Kepler's Laws**: Each orbit is an ellipse with the star at one focus +3. **Different orbital planes**: Planets orbit in slightly different planes (inclinations) +4. **Resonances**: Some orbits are locked in mathematical ratios (e.g., Neptune:Pluto = 3:2) + +## The Math + +### Kepler's Third Law +``` +T² ∝ a³ +``` +Where T = orbital period, a = semi-major axis. + +### Orbital velocity +``` +v = √(GM/r) +``` +Where G = gravitational constant, M = central mass, r = distance. + +## Connections + +- Orbital mechanics uses [Complex Numbers](../math/complex-numbers.md) in some formulations +- Resonance ratios connect to [Modular Arithmetic](../math/modular-arithmetic.md) +- The [Schrodinger Equation](../physics/quantum-mechanics.md) describes electron "orbits" at quantum scale diff --git a/notes/theoretical-cs/halting-problem.md b/notes/theoretical-cs/halting-problem.md new file mode 100644 index 0000000..d38dc52 --- /dev/null +++ b/notes/theoretical-cs/halting-problem.md @@ -0,0 +1,124 @@ +# The Halting Problem + +## Overview + +The Halting Problem asks: **Given a program and an input, can we determine whether the program will eventually halt (stop) or run forever?** + +``` +Program ──→ [ h ] +Input ──→ ──→ "Halts" or "Loops forever" +``` + +- `h` is a hypothetical program that takes another program as input +- `h` will tell you: will this problem halt or will it not? +- The key insight: **some problems will go on forever** + +## Examples of Halting vs Looping + +### Program that loops FOREVER + +```python +>>> x = 4 +>>> while x > 3: +... x += 1 # x keeps growing, always > 3 +``` + +This never terminates because `x` starts at 4 and only increases, so `x > 3` is always true. + +### Program that HALTS + +```python +>>> x = 4 +>>> while x < 1000: +... x += 1 # x eventually reaches 1000 +``` + +This terminates because `x` increments until it reaches 1000, then the condition fails. + +## The Halting Machine Diagram + +``` + ┌─────┐ + │ h │──→ halts ──→ [begin infinite loop] +code ──→ │ │ + │ │──→ loops ──→ [halt] ──→ h+ + └─────┘ +``` + +`h+` is a modified version of `h` that does the **opposite**: +- If `h` says "halts" → `h+` loops forever +- If `h` says "loops" → `h+` halts + +## The Paradox (Cantor Diagonalization Applied) + +### Setup + +Use the **same code both as the program AND the input**: + +``` +code ──→ [ h ] + ↑ │ + └──────────┘ + use that code both as the program and the input +``` + +Code can be represented as binary: `1 1 0 0 1 0 1 1` + +`h+` receives its own source code as input. + +### The Contradiction + +**What happens when you feed source `x` into itself?** + +``` +x ──→ [ h ] ──→ halts ──→ loops (contradiction!) + ──→ loops ──→ halts h+ (contradiction!) +``` + +- If `h+` says it halts → it loops (by construction) +- If `h+` says it loops → it halts (by construction) + +**Therefore, `h` cannot exist.** No program can solve the halting problem for all possible inputs. + +## Related Concepts + +### Golden Braid +Reference to Douglas Hofstadter's *"Godel, Escher, Bach: An Eternal Golden Braid"* -- explores self-reference, recursion, and the limits of formal systems. + +### The Liar Paradox +``` +"This sentence is false" +→ refers to its own truth value +→ if true, then it's false; if false, then it's true +``` + +This is the **linguistic analog** of the halting problem's self-referential contradiction. + +### Levels of Abstraction +- Programs that analyze programs +- Statements that refer to themselves +- Systems that try to fully describe themselves + +### Cantor Diagonalization +The proof technique used here is the same as Cantor's proof that the reals are uncountable: +- Assume a complete list exists +- Construct something not on the list +- Contradiction → the list can't be complete + +Applied to computation: +- Assume a halting decider `h` exists +- Construct `h+` that contradicts `h` +- Therefore `h` cannot exist + +## Significance + +This is one of the most important results in computer science (Alan Turing, 1936): +- There are **undecidable problems** -- questions that no algorithm can answer +- Connects to Godel's Incompleteness Theorems +- Sets fundamental limits on what computation can achieve + +## Connections + +- Self-reference connects to [Paradoxes & Logic](paradoxes.md) +- Formal systems connect to [Linear Algebra](../math/linear-algebra.md) (both study structural limits) +- Binary encoding (`1 1 0 0 1 0 1 1`) connects to [IPv4 Subnetting](../networking/ipv4-subnetting.md) diff --git a/notes/theoretical-cs/paradoxes.md b/notes/theoretical-cs/paradoxes.md new file mode 100644 index 0000000..d656ff2 --- /dev/null +++ b/notes/theoretical-cs/paradoxes.md @@ -0,0 +1,64 @@ +# Paradoxes & Self-Reference + +## The Liar Paradox + +``` +"This sentence is false" +``` + +- If the sentence is **true**, then it must be false (because it says so) +- If the sentence is **false**, then it must be true (because "this sentence is false" would be wrong) +- **It refers to its own truth value** -- creating an unresolvable loop + +## Levels of Abstraction + +The key insight: paradoxes arise when a system tries to **talk about itself**. + +| Level | Example | +|-------|---------| +| Object level | A program running | +| Meta level | A program analyzing another program | +| Self-referential | A program analyzing itself | + +When the meta level and object level collapse into each other, paradoxes emerge. + +## Cantor Diagonalization + +**Georg Cantor's proof that the real numbers are uncountable:** + +1. Assume you can list ALL real numbers between 0 and 1 +2. Construct a new number by changing each diagonal digit +3. This new number differs from every number on the list +4. Contradiction: the list was supposed to be complete + +**Applied to computation** → [The Halting Problem](halting-problem.md) + +1. Assume a program `h` can decide halting for ALL programs +2. Construct `h+` that does the opposite of what `h` predicts +3. Feed `h+` its own source code +4. Contradiction: `h` gives the wrong answer + +## The Monty Hall Trolley Problem + +A creative fusion of two classic problems (from r/trolleyproblem): + +> You are forced to blindly choose a path for a trolley to travel down, knowing one has only 1 person tied to it and the other two have 5. As the trolley approaches, one pathway (which you did not choose) is revealed to have 5 people. Is it in your moral best interest to switch to the unknown path? + +This combines: +- **Monty Hall Problem** (probability -- you should switch, 2/3 chance of saving more people) +- **Trolley Problem** (ethics -- is it moral to actively switch and potentially cause harm?) + +### The Math + +If you initially pick randomly among 3 tracks: +- P(picked the 1-person track) = 1/3 +- P(picked a 5-person track) = 2/3 +- After reveal: switching gives 2/3 chance of the 1-person track + +**Switching is both probabilistically and ethically optimal.** + +## Connections + +- Self-reference is the core of the [Halting Problem](halting-problem.md) +- Abstract reasoning connects to [Linear Algebra function spaces](../math/linear-algebra.md) +- Godel's Incompleteness Theorems (related to Golden Braid / GEB)