Skip to content
LAM
Read Home Blog
Make Projects HTML Tools Games
Touch grass Notes Resume Links
Home Blog HTML Projects
Tools Games Notes Resume Links
Back Advanced Mathematics for Computer Science - Complete Reference Math
Download Open
Show description 2,401 chars · Math

Advanced Mathematics for Computer Science - Complete Reference

Advanced Mathematics for Computer Science - Complete Reference












Calculus
Multivariable Calculus
Differential Equations
Linear Algebra
Discrete Mathematics
Probability & Statistics
Numerical Analysis
Complex Analysis
Graph Theory
Number Theory
Algorithm Analysis
Cryptography
Optimization





Advanced Mathematics for Computer Science

Complete Reference: Calculus • Multivariable Calculus • Linear Algebra • Discrete Math • Graph Theory • Algorithms • Cryptography





Calculus

Multivariable Calculus

Differential Equations

Linear Algebra

Discrete Mathematics

Probability & Statistics

Numerical Analysis

Complex Analysis

Graph Theory

Number Theory

Algorithm Analysis

Cryptography

Optimization





Calculus



Limits



Definition of a Limit


$$\lim_{x \to a} f(x) = L$$
means: For every $\varepsilon > 0$, there exists $\delta > 0$ such that
$$0 < |x - a| < \delta \implies |f(x) - L| < \varepsilon$$






Important Limits


$$\lim_{x \to 0} \frac{\sin x}{x} = 1$$
$$\lim_{x \to 0} \frac{1 - \cos x}{x} = 0$$
$$\lim_{x \to 0} \frac{e^x - 1}{x} = 1$$
$$\lim_{x \to \infty} \left(1 + \frac{1}{x}\right)^x = e$$






L'Hôpital's Rule


If $\lim_{x \to a} f(x) = \lim_{x \to a} g(x) = 0$ or $\pm\infty$, then:
$$\lim_{x \to a} \frac{f(x)}{g(x)} = \lim_{x \to a} \frac{f'(x)}{g'(x)}$$
(provided the right side exists)










Derivatives



Definition


$$f'(x) = \lim_{h \to 0} \frac{f(x + h) - f(x)}{h}$$
Alternative notation: $\frac{df}{dx}$, $\frac{d}{dx}f(x)$, $D_x f$






Derivative Rules


Power Rule: $\frac{d}{dx}(x^n) = nx^{n-1}$

Product Rule: $(fg)' = f'g + fg'$

Quotient Rule: $\left(\frac{f}{g}\right)' = \frac{f'g - fg'}{g^2}$

Chain Rule: $\frac{d}{dx}f(g(x)) = f'(g(x)) \cdot g'(x)$






Common Derivatives


$$\frac{d}{dx}(\sin x) = \cos x \qquad \frac{d}{dx}(\cos x) = -\sin x$$
$$\frac{d}{dx}(e^x) = e^x \qquad \frac{d}{dx}(\ln x) = \frac{1}{x}$$
$$\frac{d}{dx}(\tan x) = \sec^2 x \qquad \frac{d}{dx}(\arctan x) = \frac{1}{1+x^2}$$








Mean Value Theorem


If $f$ is continuous on $[a,b]$ and differentiable on $(a,b)$, then there exists $c \in (a,b)$ such that:
$$f'(c) = \frac{f(b) - f(a)}{b - a}$$








Integrals



Definite Integral


$$\int_a^b f(x)\,dx = \lim_{n \to \infty} \sum_{i=1}^n f(x_i^*) \Delt…

Advanced Mathematics for Computer Science - Complete Reference

372,077 bytes · HTML source
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Advanced Mathematics for Computer Science - Complete Reference</title>
    
    <!-- KaTeX for beautiful math rendering -->
   <link rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/katex@0.16.22/dist/katex.min.css"
      integrity="sha384-5TcZemv2l/9On385z///+d7MSYlvIEw9FuZTIdZ14vJLqWphw7e7ZPuOiCHJcFCP"
      crossorigin="anonymous">
<script defer
        src="https://cdn.jsdelivr.net/npm/katex@0.16.22/dist/katex.min.js"
        integrity="sha384-<hash>" crossorigin="anonymous"></script>
<script defer
        src="https://cdn.jsdelivr.net/npm/katex@0.16.22/dist/contrib/auto-render.min.js"
        integrity="sha384-<hash>" crossorigin="anonymous"
        onload="renderMathInElement(document.body, {
          delimiters: [
            {left: '$$', right: '$$', display: true},
            {left: '$',  right: '$',  display: false}
          ]
        });"></script>

<!-- Google Fonts (always latest) -->
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;700&family=Inter:wght@400;600;700&display=swap"
      rel="stylesheet">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Inter', sans-serif;
            background: #ffffff;
            color: #1a1a1a;
            min-height: 100vh;
            line-height: 1.6;
        }

        .container {
            max-width: 1600px;
            margin: 0 auto;
            padding: 20px;
        }

        .header {
            text-align: center;
            margin-bottom: 40px;
            padding: 30px;
            background: linear-gradient(135deg, #000000, #333333);
            color: white;
            border-radius: 12px;
            box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
        }

        .header h1 {
            font-size: 2.5rem;
            margin-bottom: 10px;
            font-weight: 700;
        }

        .header p {
            font-size: 1.1rem;
            opacity: 0.9;
        }

        .nav-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
            gap: 15px;
            margin-bottom: 40px;
        }

        .nav-card {
            background: #f8f9fa;
            border: 2px solid #e9ecef;
            border-radius: 8px;
            padding: 15px;
            text-align: center;
            transition: all 0.3s ease;
            cursor: pointer;
        }

        .nav-card:hover {
            border-color: #333333;
            background: #f0f0f0;
            transform: translateY(-2px);
        }

        .nav-card a {
            text-decoration: none;
            color: #000000;
            font-weight: 600;
            font-size: 0.9rem;
        }

        .section {
            margin-bottom: 50px;
            padding: 30px;
            background: #ffffff;
            border: 1px solid #e9ecef;
            border-radius: 12px;
            box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
        }

        .section h2 {
            color: #000000;
            font-size: 1.8rem;
            margin-bottom: 25px;
            border-bottom: 3px solid #333333;
            padding-bottom: 10px;
            font-weight: 700;
        }

        .topic {
            margin-bottom: 30px;
            padding: 20px;
            background: #f8f9fa;
            border-left: 4px solid #333333;
            border-radius: 0 8px 8px 0;
        }

        .topic h3 {
            color: #1a1a1a;
            font-size: 1.3rem;
            margin-bottom: 15px;
            font-weight: 600;
        }

        .formula-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
            gap: 20px;
            margin: 20px 0;
        }

        .formula-card {
            background: #ffffff;
            border: 1px solid #dee2e6;
            border-radius: 8px;
            padding: 20px;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
        }

        .formula-card h4 {
            color: #333333;
            font-size: 1rem;
            margin-bottom: 12px;
            font-weight: 600;
        }

        .math-display {
            background: #f8f9fa;
            padding: 20px;
            border-radius: 6px;
            margin: 10px 0;
            overflow-x: auto;
            font-size: 1.1rem;
        }

        .math-display mjx-container {
            font-size: 1.2em;
        }

        .theorem {
            background: linear-gradient(135deg, #f0f0f0, #e5e5e5);
            border: 1px solid #666666;
            border-radius: 8px;
            padding: 20px;
            margin: 15px 0;
        }

        .theorem h4 {
            color: #000000;
            font-size: 1.1rem;
            margin-bottom: 10px;
            font-weight: 700;
        }

        .proof-sketch {
            background: #f5f5f5;
            border-left: 4px solid #666666;
            padding: 15px;
            margin: 10px 0;
            border-radius: 0 6px 6px 0;
            font-size: 0.9rem;
        }

        .complexity-table {
            width: 100%;
            border-collapse: collapse;
            margin: 15px 0;
            background: white;
        }

        .complexity-table th,
        .complexity-table td {
            border: 1px solid #dee2e6;
            padding: 12px;
            text-align: left;
        }

        .complexity-table th {
            background: #333333;
            color: white;
            font-weight: 600;
        }

        .complexity-table tr:nth-child(even) {
            background: #f8f9fa;
        }

        .algorithm-box {
            background: #f8f8f8;
            border: 1px solid #666666;
            border-radius: 8px;
            padding: 20px;
            margin: 15px 0;
        }

        .algorithm-box h5 {
            color: #1a1a1a;
            font-size: 1rem;
            margin-bottom: 10px;
            font-weight: 600;
        }

        .code-block {
            background: #263238;
            color: #ffffff;
            padding: 15px;
            border-radius: 6px;
            font-family: 'JetBrains Mono', monospace;
            font-size: 0.85rem;
            overflow-x: auto;
            margin: 10px 0;
        }

        .important {
            background: linear-gradient(135deg, #f8f8f8, #e8e8e8);
            border: 2px solid #666666;
            border-radius: 8px;
            padding: 15px;
            margin: 15px 0;
        }

        .important h5 {
            color: #1a1a1a;
            font-size: 1rem;
            margin-bottom: 8px;
            font-weight: 600;
        }

        .matrix-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
            gap: 15px;
        }

        .stats-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
            gap: 15px;
        }

        .graph-theory-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
            gap: 18px;
        }

        .navigation {
            position: fixed;
            top: 20px;
            right: 20px;
            background: rgba(255, 255, 255, 0.95);
            border: 1px solid #dee2e6;
            border-radius: 8px;
            padding: 15px;
            max-height: 80vh;
            overflow-y: auto;
            z-index: 1000;
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
        }

        .nav-link {
            display: block;
            color: #000000;
            text-decoration: none;
            font-size: 0.8rem;
            margin-bottom: 8px;
            padding: 6px;
            border-radius: 4px;
            transition: background 0.3s;
        }

        .nav-link:hover {
            background: #f0f0f0;
        }

        .cs-application {
            background: linear-gradient(135deg, #f5f5f5, #e8e8e8);
            border: 1px solid #666666;
            border-radius: 8px;
            padding: 15px;
            margin: 10px 0;
        }

        .cs-application h5 {
            color: #1a1a1a;
            font-size: 0.95rem;
            margin-bottom: 8px;
            font-weight: 600;
        }

        /* Special styling for inline math */
        mjx-container {
            margin: 0 0.2em;
        }

        /* Make display math centered */
        mjx-container[display="true"] {
            margin: 0.5em 0;
        }

        @media (max-width: 1024px) {
            .navigation {
                position: relative;
                margin-bottom: 30px;
            }
            
            .formula-grid {
                grid-template-columns: 1fr;
            }
            
            .header h1 {
                font-size: 2rem;
            }
        }
    </style>
</head>
<body>
    <div class="navigation">
        <a href="#calculus" class="nav-link">Calculus</a>
        <a href="#calc3" class="nav-link">Multivariable Calculus</a>
        <a href="#diffeq" class="nav-link">Differential Equations</a>
        <a href="#linear" class="nav-link">Linear Algebra</a>
        <a href="#discrete" class="nav-link">Discrete Mathematics</a>
        <a href="#probability" class="nav-link">Probability & Statistics</a>
        <a href="#numerical" class="nav-link">Numerical Analysis</a>
        <a href="#complex" class="nav-link">Complex Analysis</a>
        <a href="#graph" class="nav-link">Graph Theory</a>
        <a href="#number" class="nav-link">Number Theory</a>
        <a href="#algorithms" class="nav-link">Algorithm Analysis</a>
        <a href="#crypto" class="nav-link">Cryptography</a>
        <a href="#optimization" class="nav-link">Optimization</a>
    </div>

    <div class="container">
        <div class="header">
            <h1>Advanced Mathematics for Computer Science</h1>
            <p>Complete Reference: Calculus • Multivariable Calculus • Linear Algebra • Discrete Math • Graph Theory • Algorithms • Cryptography</p>
        </div>

        <div class="nav-grid">
            <div class="nav-card"><a href="#calculus">Calculus</a></div>
            <div class="nav-card"><a href="#calc3">Multivariable Calculus</a></div>
            <div class="nav-card"><a href="#diffeq">Differential Equations</a></div>
            <div class="nav-card"><a href="#linear">Linear Algebra</a></div>
            <div class="nav-card"><a href="#discrete">Discrete Mathematics</a></div>
            <div class="nav-card"><a href="#probability">Probability & Statistics</a></div>
            <div class="nav-card"><a href="#numerical">Numerical Analysis</a></div>
            <div class="nav-card"><a href="#complex">Complex Analysis</a></div>
            <div class="nav-card"><a href="#graph">Graph Theory</a></div>
            <div class="nav-card"><a href="#number">Number Theory</a></div>
            <div class="nav-card"><a href="#algorithms">Algorithm Analysis</a></div>
            <div class="nav-card"><a href="#crypto">Cryptography</a></div>
            <div class="nav-card"><a href="#optimization">Optimization</a></div>
        </div>

        <section id="calculus" class="section">
            <h2>Calculus</h2>
            
            <div class="topic">
                <h3>Limits</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Definition of a Limit</h4>
                        <div class="math-display">
                            $$\lim_{x \to a} f(x) = L$$
                            means: For every $\varepsilon > 0$, there exists $\delta > 0$ such that
                            $$0 < |x - a| < \delta \implies |f(x) - L| < \varepsilon$$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Important Limits</h4>
                        <div class="math-display">
                            $$\lim_{x \to 0} \frac{\sin x}{x} = 1$$
                            $$\lim_{x \to 0} \frac{1 - \cos x}{x} = 0$$
                            $$\lim_{x \to 0} \frac{e^x - 1}{x} = 1$$
                            $$\lim_{x \to \infty} \left(1 + \frac{1}{x}\right)^x = e$$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>L'Hôpital's Rule</h4>
                        <div class="math-display">
                            If $\lim_{x \to a} f(x) = \lim_{x \to a} g(x) = 0$ or $\pm\infty$, then:
                            $$\lim_{x \to a} \frac{f(x)}{g(x)} = \lim_{x \to a} \frac{f'(x)}{g'(x)}$$
                            (provided the right side exists)
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Derivatives</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Definition</h4>
                        <div class="math-display">
                            $$f'(x) = \lim_{h \to 0} \frac{f(x + h) - f(x)}{h}$$
                            Alternative notation: $\frac{df}{dx}$, $\frac{d}{dx}f(x)$, $D_x f$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Derivative Rules</h4>
                        <div class="math-display">
                            Power Rule: $\frac{d}{dx}(x^n) = nx^{n-1}$
                            
                            Product Rule: $(fg)' = f'g + fg'$
                            
                            Quotient Rule: $\left(\frac{f}{g}\right)' = \frac{f'g - fg'}{g^2}$
                            
                            Chain Rule: $\frac{d}{dx}f(g(x)) = f'(g(x)) \cdot g'(x)$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Common Derivatives</h4>
                        <div class="math-display">
                            $$\frac{d}{dx}(\sin x) = \cos x \qquad \frac{d}{dx}(\cos x) = -\sin x$$
                            $$\frac{d}{dx}(e^x) = e^x \qquad \frac{d}{dx}(\ln x) = \frac{1}{x}$$
                            $$\frac{d}{dx}(\tan x) = \sec^2 x \qquad \frac{d}{dx}(\arctan x) = \frac{1}{1+x^2}$$
                        </div>
                    </div>
                </div>

                <div class="theorem">
                    <h4>Mean Value Theorem</h4>
                    <div class="math-display">
                        If $f$ is continuous on $[a,b]$ and differentiable on $(a,b)$, then there exists $c \in (a,b)$ such that:
                        $$f'(c) = \frac{f(b) - f(a)}{b - a}$$
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Integrals</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Definite Integral</h4>
                        <div class="math-display">
                            $$\int_a^b f(x)\,dx = \lim_{n \to \infty} \sum_{i=1}^n f(x_i^*) \Delta x$$
                            where $\Delta x = \frac{b-a}{n}$ and $x_i^* \in [x_{i-1}, x_i]$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Fundamental Theorem of Calculus</h4>
                        <div class="math-display">
                            Part 1: If $F(x) = \int_a^x f(t)\,dt$, then $F'(x) = f(x)$
                            
                            Part 2: If $F'(x) = f(x)$, then
                            $$\int_a^b f(x)\,dx = F(b) - F(a)$$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Integration Techniques</h4>
                        <div class="math-display">
                            Substitution: $\int f(g(x))g'(x)\,dx = \int f(u)\,du$
                            
                            Integration by Parts: $\int u\,dv = uv - \int v\,du$
                            
                            Partial Fractions: Decompose rational functions
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Common Integrals</h4>
                        <div class="math-display">
                            $$\int x^n\,dx = \frac{x^{n+1}}{n+1} + C \quad (n \neq -1)$$
                            $$\int \frac{1}{x}\,dx = \ln|x| + C$$
                            $$\int e^x\,dx = e^x + C$$
                            $$\int \sin x\,dx = -\cos x + C$$
                            $$\int \frac{1}{\sqrt{1-x^2}}\,dx = \arcsin x + C$$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Series and Sequences</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Sequences</h4>
                        <div class="math-display">
                            A sequence $\{a_n\}$ converges to $L$ if:
                            $$\lim_{n \to \infty} a_n = L$$
                            
                            Common limits:
                            $$\lim_{n \to \infty} \frac{1}{n} = 0 \qquad \lim_{n \to \infty} \sqrt[n]{n} = 1$$
                            $$\lim_{n \to \infty} \left(1 + \frac{1}{n}\right)^n = e$$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Series Convergence Tests</h4>
                        <div class="math-display">
                            Geometric Series: $\sum_{n=0}^{\infty} ar^n = \frac{a}{1-r}$ if $|r| < 1$
                            
                            p-Series: $\sum_{n=1}^{\infty} \frac{1}{n^p}$ converges if $p > 1$
                            
                            Ratio Test: If $\lim_{n \to \infty} \left|\frac{a_{n+1}}{a_n}\right| = L$
                            then series converges if $L < 1$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Taylor Series</h4>
                        <div class="math-display">
                            $$f(x) = \sum_{n=0}^{\infty} \frac{f^{(n)}(a)}{n!}(x-a)^n$$
                            
                            Common Taylor series:
                            $$e^x = \sum_{n=0}^{\infty} \frac{x^n}{n!}$$
                            $$\sin x = \sum_{n=0}^{\infty} \frac{(-1)^n x^{2n+1}}{(2n+1)!}$$
                            $$\ln(1+x) = \sum_{n=1}^{\infty} \frac{(-1)^{n+1} x^n}{n}$$
                        </div>
                    </div>
                </div>

                <div class="cs-application">
                    <h5>CS Applications:</h5>
                    Machine learning (gradient descent, backpropagation), computer graphics (physics simulations), numerical methods, algorithm complexity analysis, signal processing
                </div>
            </div>

            <div class="topic">
                <h3>Applications of Calculus</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Optimization</h4>
                        <div class="math-display">
                            Critical points: $f'(x) = 0$ or $f'(x)$ undefined
                            
                            Second derivative test:
                            - If $f''(c) > 0$: local minimum at $x = c$
                            - If $f''(c) < 0$: local maximum at $x = c$
                            - If $f''(c) = 0$: test inconclusive
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Related Rates</h4>
                        <div class="math-display">
                            If variables $x$ and $y$ are related by an equation and vary with time $t$:
                            $$\frac{dy}{dt} = \frac{dy}{dx} \cdot \frac{dx}{dt}$$
                            
                            Example: Area of circle $A = \pi r^2$
                            $$\frac{dA}{dt} = 2\pi r \frac{dr}{dt}$$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Arc Length & Surface Area</h4>
                        <div class="math-display">
                            Arc length: $L = \int_a^b \sqrt{1 + (f'(x))^2}\,dx$
                            
                            Surface area (revolution about x-axis):
                            $$S = 2\pi \int_a^b f(x)\sqrt{1 + (f'(x))^2}\,dx$$
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <section id="calc3" class="section">
            <h2>Multivariable Calculus</h2>
            
            <div class="topic">
                <h3>Partial Derivatives & Gradients</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Partial Derivatives</h4>
                        <div class="math-display">
                            $$\frac{\partial f}{\partial x} = \lim_{h \to 0} \frac{f(x+h,y) - f(x,y)}{h}$$
                            
                            Mixed partials theorem (Clairaut):
                            $$\frac{\partial^2 f}{\partial x \partial y} = \frac{\partial^2 f}{\partial y \partial x}$$
                            (if both are continuous)
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Gradient & Directional Derivatives</h4>
                        <div class="math-display">
                            $$\nabla f = \left( \frac{\partial f}{\partial x}, \frac{\partial f}{\partial y}, \frac{\partial f}{\partial z} \right)$$
                            
                            Directional derivative:
                            $$D_{\mathbf{u}} f = \nabla f \cdot \mathbf{u}$$
                            
                            Maximum rate of change: $|\nabla f|$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Chain Rule (Multivariable)</h4>
                        <div class="math-display">
                            If $z = f(x,y)$ where $x = g(t)$ and $y = h(t)$:
                            $$\frac{dz}{dt} = \frac{\partial z}{\partial x}\frac{dx}{dt} + \frac{\partial z}{\partial y}\frac{dy}{dt}$$
                            
                            General form:
                            $$\frac{\partial z}{\partial t} = \sum_{i} \frac{\partial z}{\partial x_i}\frac{\partial x_i}{\partial t}$$
                        </div>
                    </div>
                </div>
                
                <div class="cs-application">
                    <h5>CS Applications:</h5>
                    Machine learning optimization (gradient descent), computer graphics (surface normals), image processing (edge detection), neural network training
                </div>
            </div>

            <div class="topic">
                <h3>Multiple Integrals</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Double Integrals</h4>
                        <div class="math-display">
                            $$\iint_R f(x,y) \, dA = \int_a^b \int_{c(x)}^{d(x)} f(x,y) \, dy \, dx$$
                            
                            Fubini's Theorem: For continuous $f$,
                            $$\int_a^b \int_c^d f(x,y) \, dy \, dx = \int_c^d \int_a^b f(x,y) \, dx \, dy$$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Change of Variables</h4>
                        <div class="math-display">
                            $$\iint_R f(x,y) \, dx \, dy = \iint_S f(x(u,v), y(u,v)) |J| \, du \, dv$$
                            
                            Jacobian: $J = \frac{\partial(x,y)}{\partial(u,v)} = \begin{vmatrix} \frac{\partial x}{\partial u} & \frac{\partial x}{\partial v} \\ \frac{\partial y}{\partial u} & \frac{\partial y}{\partial v} \end{vmatrix}$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Cylindrical & Spherical Coordinates</h4>
                        <div class="math-display">
                            Cylindrical: $\begin{cases} x = r\cos\theta \\ y = r\sin\theta \\ z = z \end{cases}$ 
                            $dV = r \, dr \, d\theta \, dz$
                            
                            Spherical: $\begin{cases} x = \rho\sin\phi\cos\theta \\ y = \rho\sin\phi\sin\theta \\ z = \rho\cos\phi \end{cases}$
                            $dV = \rho^2\sin\phi \, d\rho \, d\phi \, d\theta$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Vector Calculus</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Vector Fields & Line Integrals</h4>
                        <div class="math-display">
                            $$\int_C \mathbf{F} \cdot d\mathbf{r} = \int_a^b \mathbf{F}(\mathbf{r}(t)) \cdot \mathbf{r}'(t) \, dt$$
                            
                            Conservative field: $\nabla \times \mathbf{F} = \mathbf{0}$
                            
                            If $\mathbf{F} = \nabla f$: $\int_C \mathbf{F} \cdot d\mathbf{r} = f(B) - f(A)$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Green's Theorem</h4>
                        <div class="math-display">
                            $$\oint_C (P \, dx + Q \, dy) = \iint_D \left( \frac{\partial Q}{\partial x} - \frac{\partial P}{\partial y} \right) dA$$
                            
                            Area formula: $A = \frac{1}{2} \oint_C (x \, dy - y \, dx)$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Divergence & Curl</h4>
                        <div class="math-display">
                            $$\text{div } \mathbf{F} = \nabla \cdot \mathbf{F} = \frac{\partial P}{\partial x} + \frac{\partial Q}{\partial y} + \frac{\partial R}{\partial z}$$
                            
                            $$\text{curl } \mathbf{F} = \nabla \times \mathbf{F} = \begin{vmatrix} \mathbf{i} & \mathbf{j} & \mathbf{k} \\ \frac{\partial}{\partial x} & \frac{\partial}{\partial y} & \frac{\partial}{\partial z} \\ P & Q & R \end{vmatrix}$$
                        </div>
                    </div>
                </div>

                <div class="theorem">
                    <h4>Stokes' Theorem</h4>
                    <div class="math-display">
                        $$\oint_C \mathbf{F} \cdot d\mathbf{r} = \iint_S (\nabla \times \mathbf{F}) \cdot \mathbf{n} \, dS$$
                    </div>
                    Relates line integral around boundary to surface integral of curl
                </div>

                <div class="theorem">
                    <h4>Divergence Theorem</h4>
                    <div class="math-display">
                        $$\iint_S \mathbf{F} \cdot \mathbf{n} \, dS = \iiint_E \nabla \cdot \mathbf{F} \, dV$$
                    </div>
                    Relates surface integral to volume integral of divergence
                </div>
            </div>
        </section>

        <section id="diffeq" class="section">
            <h2>Differential Equations</h2>
            
            <div class="topic">
                <h3>First-Order ODEs</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Separable Equations</h4>
                        <div class="math-display">
                            $$\frac{dy}{dx} = f(x)g(y)$$
                            
                            Solution method:
                            $$\int \frac{dy}{g(y)} = \int f(x) \, dx$$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Linear First-Order</h4>
                        <div class="math-display">
                            $$\frac{dy}{dx} + P(x)y = Q(x)$$
                            
                            Integrating factor: $\mu(x) = e^{\int P(x) \, dx}$
                            
                            Solution: $y = \frac{1}{\mu(x)}\left[\int \mu(x)Q(x) \, dx + C\right]$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Exact Equations</h4>
                        <div class="math-display">
                            $$M(x,y) \, dx + N(x,y) \, dy = 0$$
                            
                            Exact if: $\frac{\partial M}{\partial y} = \frac{\partial N}{\partial x}$
                            
                            Solution: Find $F(x,y)$ where $\frac{\partial F}{\partial x} = M$ and $\frac{\partial F}{\partial y} = N$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Second-Order Linear ODEs</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Homogeneous with Constant Coefficients</h4>
                        <div class="math-display">
                            $$ay'' + by' + cy = 0$$
                            
                            Characteristic equation: $ar^2 + br + c = 0$
                            
                            Solutions:
                            - If $r_1 \neq r_2$: $y = c_1e^{r_1x} + c_2e^{r_2x}$
                            - If $r_1 = r_2 = r$: $y = (c_1 + c_2x)e^{rx}$
                            - If $r = \alpha \pm \beta i$: $y = e^{\alpha x}(c_1\cos(\beta x) + c_2\sin(\beta x))$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Method of Undetermined Coefficients</h4>
                        <div class="math-display">
                            For $ay'' + by' + cy = f(x)$:
                            
                            - If $f(x) = e^{\alpha x}$: try $y_p = Ae^{\alpha x}$
                            - If $f(x) = \text{polynomial}$: try polynomial of same degree
                            - If $f(x) = \sin(\alpha x)$ or $\cos(\alpha x)$: 
                              try $y_p = A\cos(\alpha x) + B\sin(\alpha x)$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Variation of Parameters</h4>
                        <div class="math-display">
                            For $y'' + P(x)y' + Q(x)y = f(x)$
                            
                            If $y_1, y_2$ are homogeneous solutions:
                            $$y_p = -y_1\int\frac{y_2f}{W}dx + y_2\int\frac{y_1f}{W}dx$$
                            
                            Wronskian: $W = y_1y_2' - y_2y_1'$
                        </div>
                    </div>
                </div>

                <div class="cs-application">
                    <h5>CS Applications:</h5>
                    System dynamics, control theory, signal processing, population models in algorithms, oscillator circuits, physics simulations
                </div>
            </div>

            <div class="topic">
                <h3>Laplace Transforms</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Definition & Properties</h4>
                        <div class="math-display">
                            $$\mathcal{L}\{f(t)\} = F(s) = \int_0^{\infty} e^{-st}f(t) \, dt$$
                            
                            Properties:
                            - $\mathcal{L}\{af + bg\} = a\mathcal{L}\{f\} + b\mathcal{L}\{g\}$
                            - $\mathcal{L}\{f'\} = sF(s) - f(0)$
                            - $\mathcal{L}\{f''\} = s^2F(s) - sf(0) - f'(0)$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Common Transforms</h4>
                        <div class="math-display">
                            $$\mathcal{L}\{1\} = \frac{1}{s}$$
                            $$\mathcal{L}\{t^n\} = \frac{n!}{s^{n+1}}$$
                            $$\mathcal{L}\{e^{at}\} = \frac{1}{s-a}$$
                            $$\mathcal{L}\{\sin(at)\} = \frac{a}{s^2+a^2}$$
                            $$\mathcal{L}\{\cos(at)\} = \frac{s}{s^2+a^2}$$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Systems of ODEs</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Matrix Form</h4>
                        <div class="math-display">
                            $$\mathbf{x}' = A\mathbf{x} + \mathbf{b}$$
                            
                            Solution: $\mathbf{x}(t) = e^{At}\mathbf{x}_0 + \int_0^t e^{A(t-\tau)}\mathbf{b}(\tau) \, d\tau$
                            
                            Matrix exponential: $e^{At} = \sum_{n=0}^{\infty} \frac{A^n t^n}{n!}$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Eigenvalue Method</h4>
                        <div class="math-display">
                            If $A\mathbf{v} = \lambda\mathbf{v}$, then $\mathbf{x} = \mathbf{v}e^{\lambda t}$ is a solution
                            
                            General solution:
                            $$\mathbf{x} = c_1\mathbf{v}_1e^{\lambda_1 t} + c_2\mathbf{v}_2e^{\lambda_2 t} + \cdots$$
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <section id="linear" class="section">
            <h2>Linear Algebra</h2>
            
            <div class="topic">
                <h3>Matrix Operations & Properties</h3>
                <div class="matrix-grid">
                    <div class="formula-card">
                        <h4>Basic Operations</h4>
                        <div class="math-display">
                            $(AB)C = A(BC)$ - Associative
                            
                            $A(B + C) = AB + AC$ - Distributive
                            
                            $(AB)^T = B^T A^T$
                            
                            $(AB)^{-1} = B^{-1}A^{-1}$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Determinants</h4>
                        <div class="math-display">
                            $\det(AB) = \det(A)\det(B)$
                            
                            $\det(A^T) = \det(A)$
                            
                            $\det(A^{-1}) = \frac{1}{\det(A)}$
                            
                            For $2 \times 2$: $\det\begin{pmatrix}a & b\\c & d\end{pmatrix} = ad - bc$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Matrix Inverse</h4>
                        <div class="math-display">
                            $A^{-1} = \frac{1}{\det(A)} \cdot \text{adj}(A)$
                            
                            For $2 \times 2$: $A^{-1} = \frac{1}{ad-bc}\begin{pmatrix}d & -b\\-c & a\end{pmatrix}$
                            
                            Gauss-Jordan: $[A|I] \rightarrow [I|A^{-1}]$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Vector Spaces & Linear Independence</h3>
                <div class="theorem">
                    <h4>Vector Space Axioms</h4>
                    A vector space $V$ over field $F$ satisfies:
                    <div class="math-display">
                        1. $\mathbf{u} + \mathbf{v} \in V$ (closure under addition)
                        2. $\mathbf{u} + \mathbf{v} = \mathbf{v} + \mathbf{u}$ (commutativity)
                        3. $(\mathbf{u} + \mathbf{v}) + \mathbf{w} = \mathbf{u} + (\mathbf{v} + \mathbf{w})$ (associativity)
                        4. $\exists \mathbf{0} \in V: \mathbf{v} + \mathbf{0} = \mathbf{v}$ (additive identity)
                        5. $\forall \mathbf{v} \exists (-\mathbf{v}): \mathbf{v} + (-\mathbf{v}) = \mathbf{0}$ (additive inverse)
                        6-10. Scalar multiplication axioms
                    </div>
                </div>
                
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Linear Independence</h4>
                        <div class="math-display">
                            Vectors $\mathbf{v}_1, \mathbf{v}_2, \ldots, \mathbf{v}_n$ are linearly independent if:
                            $$c_1\mathbf{v}_1 + c_2\mathbf{v}_2 + \cdots + c_n\mathbf{v}_n = \mathbf{0} \implies c_1 = c_2 = \cdots = c_n = 0$$
                            
                            Matrix form: $A\mathbf{x} = \mathbf{0}$ has only trivial solution
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Basis & Dimension</h4>
                        <div class="math-display">
                            Basis: linearly independent set that spans the space
                            
                            $\dim(V) = $ number of vectors in any basis
                            
                            If $\dim(V) = n$, then any $n$ linearly independent vectors form a basis
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Eigenvalues & Eigenvectors</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Characteristic Equation</h4>
                        <div class="math-display">
                            $$A\mathbf{v} = \lambda\mathbf{v} \quad (\mathbf{v} \neq \mathbf{0})$$
                            
                            Characteristic polynomial: $\det(A - \lambda I) = 0$
                            
                            Eigenspace: $E_{\lambda} = \{\mathbf{v} : A\mathbf{v} = \lambda\mathbf{v}\} = \text{null}(A - \lambda I)$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Diagonalization</h4>
                        <div class="math-display">
                            $$A = PDP^{-1}$$
                            where $D$ is diagonal
                            
                            $P = [\mathbf{v}_1 \, \mathbf{v}_2 \, \cdots \, \mathbf{v}_n]$ (eigenvectors)
                            
                            $D = \text{diag}(\lambda_1, \lambda_2, \ldots, \lambda_n)$ (eigenvalues)
                            
                            $A^k = PD^k P^{-1}$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Properties</h4>
                        <div class="math-display">
                            $$\text{tr}(A) = \lambda_1 + \lambda_2 + \cdots + \lambda_n$$
                            $$\det(A) = \lambda_1 \times \lambda_2 \times \cdots \times \lambda_n$$
                            
                            If $A$ symmetric: all eigenvalues real, eigenvectors orthogonal
                        </div>
                    </div>
                </div>

                <div class="cs-application">
                    <h5>CS Applications:</h5>
                    Google PageRank algorithm, Principal Component Analysis (PCA), computer graphics transformations, quantum computing gates, network analysis
                </div>
            </div>

            <div class="topic">
                <h3>Orthogonality & Least Squares</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Inner Products & Norms</h4>
                        <div class="math-display">
                            $$\langle \mathbf{u}, \mathbf{v} \rangle = \mathbf{u}^T\mathbf{v} = u_1v_1 + u_2v_2 + \cdots + u_nv_n$$
                            
                            $$\|\mathbf{v}\| = \sqrt{\langle \mathbf{v}, \mathbf{v} \rangle} = \sqrt{v_1^2 + v_2^2 + \cdots + v_n^2}$$
                            
                            Cauchy-Schwarz: $|\langle \mathbf{u}, \mathbf{v} \rangle| \leq \|\mathbf{u}\| \|\mathbf{v}\|$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Gram-Schmidt Process</h4>
                        <div class="math-display">
                            $$\mathbf{u}_1 = \mathbf{v}_1$$
                            $$\mathbf{u}_2 = \mathbf{v}_2 - \text{proj}_{\mathbf{u}_1}\mathbf{v}_2$$
                            $$\mathbf{u}_3 = \mathbf{v}_3 - \text{proj}_{\mathbf{u}_1}\mathbf{v}_3 - \text{proj}_{\mathbf{u}_2}\mathbf{v}_3$$
                            
                            where $\text{proj}_{\mathbf{u}}\mathbf{v} = \frac{\langle \mathbf{v}, \mathbf{u} \rangle}{\langle \mathbf{u}, \mathbf{u} \rangle}\mathbf{u}$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Least Squares</h4>
                        <div class="math-display">
                            Normal equation: $A^T A\hat{\mathbf{x}} = A^T\mathbf{b}$
                            
                            Solution: $\hat{\mathbf{x}} = (A^T A)^{-1}A^T\mathbf{b}$
                            
                            If $A$ has orthonormal columns: $\hat{\mathbf{x}} = A^T\mathbf{b}$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Singular Value Decomposition</h3>
                <div class="theorem">
                    <h4>SVD Theorem</h4>
                    Every $m \times n$ matrix $A$ can be written as:
                    <div class="math-display">
                        $$A = U\Sigma V^T$$
                        
                        $U$: $m \times m$ orthogonal (left singular vectors)
                        $\Sigma$: $m \times n$ diagonal (singular values $\sigma_1 \geq \sigma_2 \geq \cdots \geq 0$)
                        $V$: $n \times n$ orthogonal (right singular vectors)
                    </div>
                </div>
                
                <div class="cs-application">
                    <h5>CS Applications:</h5>
                    Image compression, dimensionality reduction, recommender systems, data analysis, pseudoinverse computation
                </div>
            </div>
        </section>

        <section id="discrete" class="section">
            <h2>Discrete Mathematics</h2>
            
            <div class="topic">
                <h3>Logic & Proofs</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Logical Operators</h4>
                        <div class="math-display">
                            $\neg$ (NOT), $\land$ (AND), $\lor$ (OR), $\rightarrow$ (IMPLIES), $\leftrightarrow$ (IFF)
                            
                            De Morgan's Laws:
                            $$\neg(P \land Q) \equiv \neg P \lor \neg Q$$
                            $$\neg(P \lor Q) \equiv \neg P \land \neg Q$$
                            
                            $P \rightarrow Q \equiv \neg P \lor Q$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Quantifiers</h4>
                        <div class="math-display">
                            $\forall x \, P(x)$: "for all $x$, $P(x)$"
                            
                            $\exists x \, P(x)$: "there exists $x$ such that $P(x)$"
                            
                            $$\neg\forall x \, P(x) \equiv \exists x \, \neg P(x)$$
                            $$\neg\exists x \, P(x) \equiv \forall x \, \neg P(x)$$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Proof Techniques</h4>
                        <div class="math-display">
                            Direct proof: $P \rightarrow Q$
                            
                            Contrapositive: $\neg Q \rightarrow \neg P$
                            
                            Contradiction: Assume $\neg Q$ and derive contradiction
                            
                            Induction: Base case + inductive step
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Set Theory</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Set Operations</h4>
                        <div class="math-display">
                            $A \cup B = \{x : x \in A \text{ or } x \in B\}$
                            
                            $A \cap B = \{x : x \in A \text{ and } x \in B\}$
                            
                            $A - B = \{x : x \in A \text{ and } x \notin B\}$
                            
                            $A^c = \{x : x \notin A\}$
                            
                            $|A \cup B| = |A| + |B| - |A \cap B|$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Relations</h4>
                        <div class="math-display">
                            Reflexive: $\forall x \, (x,x) \in R$
                            
                            Symmetric: $\forall x,y \, ((x,y) \in R \rightarrow (y,x) \in R)$
                            
                            Transitive: $\forall x,y,z \, ((x,y) \in R \land (y,z) \in R \rightarrow (x,z) \in R)$
                            
                            Equivalence relation: reflexive + symmetric + transitive
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Functions</h4>
                        <div class="math-display">
                            Injective (one-to-one): $\forall x,y \, (f(x) = f(y) \rightarrow x = y)$
                            
                            Surjective (onto): $\forall y \, \exists x \, (f(x) = y)$
                            
                            Bijective: injective + surjective
                            
                            $|A| = |B|$ iff $\exists$ bijection $f: A \rightarrow B$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Combinatorics</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Counting Principles</h4>
                        <div class="math-display">
                            Addition Principle: $|A \cup B| = |A| + |B|$ if $A \cap B = \emptyset$
                            
                            Multiplication Principle: $|A \times B| = |A| \times |B|$
                            
                            Pigeonhole Principle: If $n$ objects in $m$ boxes and $n > m$, then some box contains $> 1$ object
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Permutations & Combinations</h4>
                        <div class="math-display">
                            $$P(n,r) = \frac{n!}{(n-r)!} \text{ (permutations)}$$
                            
                            $$C(n,r) = \binom{n}{r} = \frac{n!}{r!(n-r)!} \text{ (combinations)}$$
                            
                            Binomial theorem: $(x+y)^n = \sum_{k=0}^n \binom{n}{k} x^k y^{n-k}$
                            
                            Stars and bars: $\binom{n+k-1}{k-1}$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Inclusion-Exclusion</h4>
                        <div class="math-display">
                            $$|A_1 \cup A_2 \cup \cdots \cup A_n| =$$
                            $$\sum |A_i| - \sum |A_i \cap A_j| + \sum |A_i \cap A_j \cap A_k| - \cdots$$
                            $$+ (-1)^{n+1}|A_1 \cap \cdots \cap A_n|$$
                        </div>
                    </div>
                </div>

                <div class="cs-application">
                    <h5>CS Applications:</h5>
                    Algorithm analysis, database query optimization, complexity theory, coding theory, cryptographic protocols
                </div>
            </div>

            <div class="topic">
                <h3>Generating Functions</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Ordinary Generating Functions</h4>
                        <div class="math-display">
                            $$G(x) = \sum_{n=0}^{\infty} a_n x^n = a_0 + a_1x + a_2x^2 + \cdots$$
                            
                            Fibonacci: $F(x) = \frac{x}{1 - x - x^2}$
                            
                            Geometric: $\frac{1}{1-x} = \sum_{n=0}^{\infty} x^n$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Exponential Generating Functions</h4>
                        <div class="math-display">
                            $$E(x) = \sum_{n=0}^{\infty} a_n \frac{x^n}{n!}$$
                            
                            $e^x = \sum_{n=0}^{\infty} \frac{x^n}{n!}$
                            
                            Useful for problems with labels/arrangements
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Recurrence Relations</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Linear Homogeneous</h4>
                        <div class="math-display">
                            $$a_n = c_1a_{n-1} + c_2a_{n-2} + \cdots + c_ka_{n-k}$$
                            
                            Characteristic equation: $r^k - c_1r^{k-1} - \cdots - c_k = 0$
                            
                            If roots distinct: $a_n = A_1r_1^n + A_2r_2^n + \cdots$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Master Theorem</h4>
                        <div class="math-display">
                            For $T(n) = aT(n/b) + f(n)$:
                            
                            Case 1: $f(n) = O(n^{\log_b a - \varepsilon}) \Rightarrow T(n) = \Theta(n^{\log_b a})$
                            
                            Case 2: $f(n) = \Theta(n^{\log_b a}) \Rightarrow T(n) = \Theta(n^{\log_b a} \log n)$
                            
                            Case 3: $f(n) = \Omega(n^{\log_b a + \varepsilon}) \Rightarrow T(n) = \Theta(f(n))$
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <section id="probability" class="section">
            <h2>Probability & Statistics</h2>
            
            <div class="topic">
                <h3>Probability Theory</h3>
                <div class="stats-grid">
                    <div class="formula-card">
                        <h4>Basic Probability</h4>
                        <div class="math-display">
                            $$P(A \cup B) = P(A) + P(B) - P(A \cap B)$$
                            $$P(A^c) = 1 - P(A)$$
                            $$P(A|B) = \frac{P(A \cap B)}{P(B)}$$
                            
                            Independence: $P(A \cap B) = P(A)P(B)$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Bayes' Theorem</h4>
                        <div class="math-display">
                            $$P(A|B) = \frac{P(B|A)P(A)}{P(B)}$$
                            
                            Law of Total Probability:
                            $$P(B) = \sum_i P(B|A_i)P(A_i)$$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Random Variables</h4>
                        <div class="math-display">
                            $$E[X] = \sum_x x \cdot P(X = x) \text{ (discrete)}$$
                            $$E[X] = \int_{-\infty}^{\infty} x \cdot f(x) \, dx \text{ (continuous)}$$
                            
                            $\text{Var}(X) = E[X^2] - (E[X])^2$
                            
                            $\text{Var}(aX + b) = a^2\text{Var}(X)$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Common Distributions</h3>
                <div class="stats-grid">
                    <div class="formula-card">
                        <h4>Discrete Distributions</h4>
                        <div class="math-display">
                            Bernoulli: $P(X = 1) = p$, $P(X = 0) = 1-p$
                            
                            Binomial: $P(X = k) = \binom{n}{k}p^k(1-p)^{n-k}$
                            $E[X] = np$, $\text{Var}(X) = np(1-p)$
                            
                            Poisson: $P(X = k) = \frac{\lambda^k e^{-\lambda}}{k!}$
                            $E[X] = \text{Var}(X) = \lambda$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Continuous Distributions</h4>
                        <div class="math-display">
                            Uniform: $f(x) = \frac{1}{b-a}$ for $x \in [a,b]$
                            $E[X] = \frac{a+b}{2}$, $\text{Var}(X) = \frac{(b-a)^2}{12}$
                            
                            Normal: $f(x) = \frac{1}{\sigma\sqrt{2\pi}}e^{-\frac{(x-\mu)^2}{2\sigma^2}}$
                            $E[X] = \mu$, $\text{Var}(X) = \sigma^2$
                            
                            Exponential: $f(x) = \lambda e^{-\lambda x}$ for $x \geq 0$
                            $E[X] = \frac{1}{\lambda}$, $\text{Var}(X) = \frac{1}{\lambda^2}$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Central Limit Theorem</h4>
                        <div class="math-display">
                            If $X_1, X_2, \ldots, X_n$ are i.i.d. with $E[X_i] = \mu$, $\text{Var}(X_i) = \sigma^2$:
                            
                            $$\frac{\bar{X} - \mu}{\sigma/\sqrt{n}} \xrightarrow{d} N(0,1) \text{ as } n \to \infty$$
                            
                            where $\bar{X} = \frac{1}{n}\sum_{i=1}^n X_i$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Statistical Inference</h3>
                <div class="stats-grid">
                    <div class="formula-card">
                        <h4>Confidence Intervals</h4>
                        <div class="math-display">
                            For mean $\mu$ ($\sigma$ known):
                            $$\bar{x} \pm z_{\alpha/2} \times \frac{\sigma}{\sqrt{n}}$$
                            
                            For mean $\mu$ ($\sigma$ unknown):
                            $$\bar{x} \pm t_{\alpha/2,n-1} \times \frac{s}{\sqrt{n}}$$
                            
                            For proportion $p$:
                            $$\hat{p} \pm z_{\alpha/2} \times \sqrt{\frac{\hat{p}(1-\hat{p})}{n}}$$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Hypothesis Testing</h4>
                        <div class="math-display">
                            Test statistic for mean:
                            $$z = \frac{\bar{x} - \mu_0}{\sigma/\sqrt{n}} \text{ or } t = \frac{\bar{x} - \mu_0}{s/\sqrt{n}}$$
                            
                            p-value = P(observing test statistic or more extreme | $H_0$)
                            
                            Reject $H_0$ if p-value $< \alpha$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Regression</h4>
                        <div class="math-display">
                            Simple linear: $\hat{y} = a + bx$
                            
                            $$b = \frac{\sum (x_i - \bar{x})(y_i - \bar{y})}{\sum (x_i - \bar{x})^2}$$
                            $$a = \bar{y} - b\bar{x}$$
                            
                            $R^2 = 1 - \frac{SSE}{SST}$ (coefficient of determination)
                        </div>
                    </div>
                </div>

                <div class="cs-application">
                    <h5>CS Applications:</h5>
                    Machine learning algorithms, A/B testing, data mining, quality assurance, performance analysis, randomized algorithms
                </div>
            </div>
        </section>

        <section id="numerical" class="section">
            <h2>Numerical Analysis</h2>
            
            <div class="topic">
                <h3>Root Finding</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Bisection Method</h4>
                        <div class="math-display">
                            If $f(a)f(b) < 0$, then $\exists c \in (a,b): f(c) = 0$
                            
                            Algorithm:
                            1. $c = \frac{a + b}{2}$
                            2. If $f(a)f(c) < 0$: $b = c$, else $a = c$
                            3. Repeat until $|b - a| < $ tolerance
                            
                            Convergence: $O(\log_2((b-a)/\varepsilon))$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Newton's Method</h4>
                        <div class="math-display">
                            $$x_{n+1} = x_n - \frac{f(x_n)}{f'(x_n)}$$
                            
                            Quadratic convergence when $f'(\text{root}) \neq 0$
                            
                            May fail if $f'(x_n) \approx 0$ or poor initial guess
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Secant Method</h4>
                        <div class="math-display">
                            $$x_{n+1} = x_n - f(x_n)\frac{x_n - x_{n-1}}{f(x_n) - f(x_{n-1})}$$
                            
                            Approximates derivative using secant line
                            
                            Superlinear convergence: $\varphi = \frac{1+\sqrt{5}}{2} \approx 1.618$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Interpolation</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Lagrange Interpolation</h4>
                        <div class="math-display">
                            $$P(x) = \sum_{i=0}^n y_i L_i(x)$$
                            
                            where $L_i(x) = \prod_{j=0, j \neq i}^n \frac{x - x_j}{x_i - x_j}$
                            
                            Unique polynomial of degree $\leq n$ through $n+1$ points
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Newton's Divided Differences</h4>
                        <div class="math-display">
                            $$P(x) = f[x_0] + f[x_0,x_1](x-x_0) + f[x_0,x_1,x_2](x-x_0)(x-x_1) + \cdots$$
                            
                            $f[x_i,x_{i+1}] = \frac{f[x_{i+1}] - f[x_i]}{x_{i+1} - x_i}$
                            
                            More efficient for adding new points
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Spline Interpolation</h4>
                        <div class="math-display">
                            Cubic spline: $S(x) = a_i + b_i(x-x_i) + c_i(x-x_i)^2 + d_i(x-x_i)^3$
                            
                            Conditions:
                            - $S(x_i) = y_i$
                            - $S'(x_i^-) = S'(x_i^+)$
                            - $S''(x_i^-) = S''(x_i^+)$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Numerical Integration</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Composite Rules</h4>
                        <div class="math-display">
                            Composite Trapezoidal:
                            $$\int_a^b f(x)\,dx \approx \frac{h}{2}[f(x_0) + 2f(x_1) + \cdots + 2f(x_{n-1}) + f(x_n)]$$
                            Error: $O(h^2)$
                            
                            Composite Simpson's:
                            $$\int_a^b f(x)\,dx \approx \frac{h}{3}[f(x_0) + 4f(x_1) + 2f(x_2) + 4f(x_3) + \cdots + f(x_n)]$$
                            Error: $O(h^4)$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Gaussian Quadrature</h4>
                        <div class="math-display">
                            $$\int_{-1}^1 f(x)\,dx \approx \sum_{i=1}^n w_i f(x_i)$$
                            
                            Optimal choice of points $x_i$ and weights $w_i$
                            
                            $n$-point Gauss rule exact for polynomials of degree $\leq 2n-1$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Ordinary Differential Equations</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Euler's Method</h4>
                        <div class="math-display">
                            $$y_{n+1} = y_n + h \cdot f(x_n, y_n)$$
                            
                            First-order accuracy: $O(h)$
                            
                            Simple but may be unstable for large $h$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Runge-Kutta Methods</h4>
                        <div class="math-display">
                            RK4 (Fourth-order):
                            $$k_1 = hf(x_n, y_n)$$
                            $$k_2 = hf(x_n + h/2, y_n + k_1/2)$$
                            $$k_3 = hf(x_n + h/2, y_n + k_2/2)$$
                            $$k_4 = hf(x_n + h, y_n + k_3)$$
                            
                            $$y_{n+1} = y_n + \frac{k_1 + 2k_2 + 2k_3 + k_4}{6}$$
                        </div>
                    </div>
                </div>

                <div class="cs-application">
                    <h5>CS Applications:</h5>
                    Computer graphics (ray tracing), scientific computing, game physics, signal processing, finite element analysis
                </div>
            </div>
        </section>

        <section id="complex" class="section">
            <h2>Complex Analysis</h2>
            
            <div class="topic">
                <h3>Complex Numbers</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Basic Operations</h4>
                        <div class="math-display">
                            $$z = x + iy = re^{i\theta} = r(\cos\theta + i\sin\theta)$$
                            
                            $|z| = \sqrt{x^2 + y^2} = r$
                            
                            $\arg(z) = \theta = \arctan(y/x)$
                            
                            $z^* = x - iy = re^{-i\theta}$ (complex conjugate)
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Polar Form</h4>
                        <div class="math-display">
                            $$z_1z_2 = r_1r_2e^{i(\theta_1+\theta_2)}$$
                            $$\frac{z_1}{z_2} = \frac{r_1}{r_2}e^{i(\theta_1-\theta_2)}$$
                            
                            De Moivre's theorem: $z^n = r^n e^{in\theta}$
                            
                            $n$th roots: $z^{1/n} = r^{1/n} e^{i(\theta+2\pi k)/n}$, $k = 0,1,\ldots,n-1$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Analytic Functions</h3>
                <div class="theorem">
                    <h4>Cauchy-Riemann Equations</h4>
                    If $f(z) = u(x,y) + iv(x,y)$ is analytic:
                    <div class="math-display">
                        $$\frac{\partial u}{\partial x} = \frac{\partial v}{\partial y}$$
                        $$\frac{\partial u}{\partial y} = -\frac{\partial v}{\partial x}$$
                    </div>
                </div>
                
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Elementary Functions</h4>
                        <div class="math-display">
                            $$e^z = e^x(\cos y + i\sin y)$$
                            
                            $$\sin z = \frac{e^{iz} - e^{-iz}}{2i}$$
                            $$\cos z = \frac{e^{iz} + e^{-iz}}{2}$$
                            
                            $\log z = \ln|z| + i(\arg z + 2\pi n)$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Power Series</h4>
                        <div class="math-display">
                            $$f(z) = \sum_{n=0}^{\infty} a_n(z - z_0)^n$$
                            
                            Radius of convergence: $R = \frac{1}{\limsup_{n \to \infty} |a_n|^{1/n}}$
                            
                            Convergent for $|z - z_0| < R$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Integration & Residues</h3>
                <div class="theorem">
                    <h4>Cauchy's Theorem</h4>
                    If $f$ is analytic in simply connected domain $D$ and $C$ is a closed curve in $D$:
                    <div class="math-display">
                        $$\oint_C f(z) \, dz = 0$$
                    </div>
                </div>

                <div class="theorem">
                    <h4>Residue Theorem</h4>
                    <div class="math-display">
                        $$\oint_C f(z) \, dz = 2\pi i \sum_k \text{Res}(f, z_k)$$
                    </div>
                    where $z_k$ are poles inside $C$
                </div>
                
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Computing Residues</h4>
                        <div class="math-display">
                            Simple pole at $z_0$:
                            $$\text{Res}(f, z_0) = \lim_{z \to z_0} (z - z_0)f(z)$$
                            
                            Pole of order $n$:
                            $$\text{Res}(f, z_0) = \frac{1}{(n-1)!} \lim_{z \to z_0} \frac{d^{n-1}}{dz^{n-1}}[(z-z_0)^n f(z)]$$
                        </div>
                    </div>
                </div>

                <div class="cs-application">
                    <h5>CS Applications:</h5>
                    Signal processing (Fourier transforms), control systems, quantum computing, computer graphics (fractals), digital filters
                </div>
            </div>
        </section>

        <section id="graph" class="section">
            <h2>Graph Theory</h2>
            
            <div class="topic">
                <h3>Basic Definitions</h3>
                <div class="graph-theory-grid">
                    <div class="formula-card">
                        <h4>Graph Properties</h4>
                        <div class="math-display">
                            Graph $G = (V, E)$ where $V =$ vertices, $E =$ edges
                            
                            Order: $|V|$ (number of vertices)
                            Size: $|E|$ (number of edges)
                            
                            Degree: $\deg(v) = $ number of edges incident to $v$
                            
                            Handshaking lemma: $\sum_{v \in V} \deg(v) = 2|E|$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Special Graphs</h4>
                        <div class="math-display">
                            Complete graph $K_n$: $|E| = \frac{n(n-1)}{2}$
                            
                            Complete bipartite $K_{m,n}$: $|E| = mn$
                            
                            Cycle $C_n$: $n$ vertices, $n$ edges
                            
                            Path $P_n$: $n$ vertices, $n-1$ edges
                            
                            Tree: connected, acyclic, $|E| = |V| - 1$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Matrix Representations</h4>
                        <div class="math-display">
                            Adjacency matrix $A$: $A[i,j] = 1$ if edge $(i,j)$ exists
                            
                            Incidence matrix: rows = vertices, columns = edges
                            
                            Number of walks of length $k$ from $i$ to $j$: $(A^k)[i,j]$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Connectivity</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Paths & Cycles</h4>
                        <div class="math-display">
                            Walk: sequence of vertices $v_0, v_1, \ldots, v_k$
                            
                            Trail: walk with distinct edges
                            
                            Path: walk with distinct vertices
                            
                            Connected: path exists between any two vertices
                            
                            Distance $d(u,v)$: length of shortest path from $u$ to $v$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Euler & Hamilton</h4>
                        <div class="math-display">
                            Eulerian path: uses every edge exactly once
                            Exists iff graph connected and $\leq 2$ odd-degree vertices
                            
                            Eulerian cycle: closed Eulerian path
                            Exists iff graph connected and all vertices even degree
                            
                            Hamiltonian path: visits every vertex exactly once
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Trees & Spanning Trees</h3>
                <div class="theorem">
                    <h4>Tree Properties</h4>
                    For a graph $G$ with $n$ vertices, these are equivalent:
                    <div class="math-display">
                        1. $G$ is a tree
                        2. $G$ is connected and has $n-1$ edges
                        3. $G$ is acyclic and has $n-1$ edges
                        4. $G$ is connected and removing any edge disconnects it
                        5. $G$ is acyclic and adding any edge creates exactly one cycle
                    </div>
                </div>
                
                <div class="algorithm-box">
                    <h5>Kruskal's Algorithm (Minimum Spanning Tree)</h5>
                    <div class="code-block">
                        1. Sort edges by weight
                        2. Initialize disjoint sets for each vertex
                        3. For each edge (u,v):
                           - If u and v in different components:
                             - Add edge to MST
                             - Union components of u and v
                        4. Stop when n-1 edges added
                        
                        Time complexity: O(E log E)
                    </div>
                </div>
                
                <div class="algorithm-box">
                    <h5>Prim's Algorithm</h5>
                    <div class="code-block">
                        1. Start with arbitrary vertex
                        2. Maintain priority queue of edges from current tree
                        3. Repeatedly add minimum weight edge that connects
                           tree to new vertex
                        4. Update priority queue
                        
                        Time complexity: O(E log V) with binary heap
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Shortest Paths</h3>
                <div class="algorithm-box">
                    <h5>Dijkstra's Algorithm</h5>
                    <div class="code-block">
                        1. Initialize distances: d[source] = 0, d[v] = ∞ for v ≠ source
                        2. Priority queue Q with all vertices
                        3. While Q not empty:
                           - u = extract minimum from Q
                           - For each neighbor v of u:
                             - If d[u] + weight(u,v) < d[v]:
                               - d[v] = d[u] + weight(u,v)
                               - parent[v] = u
                        
                        Time: O((V + E) log V) with binary heap
                        Requirements: non-negative weights
                    </div>
                </div>
                
                <div class="algorithm-box">
                    <h5>Bellman-Ford Algorithm</h5>
                    <div class="code-block">
                        1. Initialize distances: d[source] = 0, d[v] = ∞ for v ≠ source
                        2. For i = 1 to |V| - 1:
                           - For each edge (u,v):
                             - If d[u] + weight(u,v) < d[v]:
                               - d[v] = d[u] + weight(u,v)
                        3. Check for negative cycles
                        
                        Time: O(VE)
                        Handles negative weights
                    </div>
                </div>
                
                <div class="algorithm-box">
                    <h5>Floyd-Warshall Algorithm</h5>
                    <div class="code-block">
                        1. Initialize distance matrix D
                        2. For k = 1 to n:
                           - For i = 1 to n:
                             - For j = 1 to n:
                               - D[i][j] = min(D[i][j], D[i][k] + D[k][j])
                        
                        Time: O(V³)
                        Finds all-pairs shortest paths
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Network Flow</h3>
                <div class="theorem">
                    <h4>Max-Flow Min-Cut Theorem</h4>
                    In any flow network, the maximum value of flow equals the minimum capacity of all cuts.
                </div>
                
                <div class="algorithm-box">
                    <h5>Ford-Fulkerson Method</h5>
                    <div class="code-block">
                        1. Initialize flow f = 0
                        2. While there exists augmenting path P from source to sink:
                           - Find bottleneck capacity c along P
                           - Augment flow along P by c
                           - Update residual graph
                        3. Return maximum flow
                        
                        Time: O(E × max_flow) for integer capacities
                        With Edmonds-Karp (BFS): O(VE²)
                    </div>
                </div>

                <div class="cs-application">
                    <h5>CS Applications:</h5>
                    Social networks, internet routing, database optimization, compiler optimization, bioinformatics, recommendation systems
                </div>
            </div>

            <div class="topic">
                <h3>Graph Coloring</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Chromatic Number</h4>
                        <div class="math-display">
                            $\chi(G) = $ minimum number of colors needed
                            
                            $\chi(K_n) = n$
                            
                            $\chi(C_n) = 2$ if $n$ even, $3$ if $n$ odd
                            
                            $\chi(\text{bipartite graph}) = 2$
                            
                            Four Color Theorem: $\chi(\text{planar graph}) \leq 4$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Greedy Coloring</h4>
                        <div class="math-display">
                            Brooks' Theorem: If $G$ connected, not complete, not odd cycle, then $\chi(G) \leq \Delta(G)$
                            
                            where $\Delta(G) = $ maximum degree
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <section id="number" class="section">
            <h2>Number Theory</h2>
            
            <div class="topic">
                <h3>Divisibility & GCD</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Division Algorithm</h4>
                        <div class="math-display">
                            For integers $a, b$ with $b > 0$:
                            $$a = qb + r \text{ where } 0 \leq r < b$$
                            
                            $q = $ quotient, $r = $ remainder
                            
                            $a \equiv r \pmod{b}$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Euclidean Algorithm</h4>
                        <div class="math-display">
                            $$\gcd(a, b) = \gcd(b, a \bmod b)$$
                            
                            Extended Euclidean Algorithm:
                            $$\gcd(a, b) = ax + by$$
                            for some integers $x, y$
                            
                            Time complexity: $O(\log \min(a, b))$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Properties</h4>
                        <div class="math-display">
                            $$\gcd(a, b) \times \text{lcm}(a, b) = ab$$
                            
                            If $\gcd(a, n) = 1$ and $\gcd(b, n) = 1$,
                            then $\gcd(ab, n) = 1$
                            
                            Bézout's identity: $\gcd(a, b) = ax + by$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Modular Arithmetic</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Congruences</h4>
                        <div class="math-display">
                            $a \equiv b \pmod{n}$ iff $n \mid (a - b)$
                            
                            Properties:
                            $(a + b) \bmod n = ((a \bmod n) + (b \bmod n)) \bmod n$
                            
                            $(a \times b) \bmod n = ((a \bmod n) \times (b \bmod n)) \bmod n$
                            
                            Reflexive: $a \equiv a \pmod{n}$
                            Symmetric: $a \equiv b \implies b \equiv a \pmod{n}$
                            Transitive: $a \equiv b, b \equiv c \implies a \equiv c \pmod{n}$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Modular Inverse</h4>
                        <div class="math-display">
                            $a^{-1} \pmod{n}$ exists iff $\gcd(a, n) = 1$
                            
                            Finding inverse: use Extended Euclidean Algorithm
                            $ax + ny = 1 \implies ax \equiv 1 \pmod{n} \implies a^{-1} \equiv x \pmod{n}$
                            
                            Fermat's Little Theorem: If $p$ prime, $\gcd(a, p) = 1$:
                            $$a^{-1} \equiv a^{p-2} \pmod{p}$$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Prime Numbers</h3>
                <div class="theorem">
                    <h4>Fundamental Theorem of Arithmetic</h4>
                    Every integer $n > 1$ has a unique prime factorization:
                    <div class="math-display">
                        $$n = p_1^{a_1} \times p_2^{a_2} \times \cdots \times p_k^{a_k}$$
                    </div>
                    where $p_1 < p_2 < \cdots < p_k$ are primes and $a_i > 0$
                </div>
                
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Prime Testing</h4>
                        <div class="math-display">
                            Trial division: test divisibility up to $\sqrt{n}$
                            Time: $O(\sqrt{n})$
                            
                            Sieve of Eratosthenes: find all primes $\leq n$
                            Time: $O(n \log \log n)$
                            
                            Miller-Rabin: probabilistic primality test
                            Time: $O(k \log^3 n)$ for $k$ rounds
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Prime Distribution</h4>
                        <div class="math-display">
                            Prime Number Theorem:
                            $$\pi(n) \approx \frac{n}{\ln(n)}$$
                            
                            where $\pi(n) = $ number of primes $\leq n$
                            
                            There are infinitely many primes
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Euler's Function</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Definition & Properties</h4>
                        <div class="math-display">
                            $$\varphi(n) = |\{k : 1 \leq k \leq n, \gcd(k, n) = 1\}|$$
                            
                            $\varphi(p) = p - 1$ for prime $p$
                            
                            $\varphi(p^k) = p^k - p^{k-1} = p^{k-1}(p - 1)$
                            
                            If $\gcd(m, n) = 1$: $\varphi(mn) = \varphi(m)\varphi(n)$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Euler's Theorem</h4>
                        <div class="math-display">
                            If $\gcd(a, n) = 1$, then:
                            $$a^{\varphi(n)} \equiv 1 \pmod{n}$$
                            
                            Fermat's Little Theorem (special case):
                            If $p$ prime and $\gcd(a, p) = 1$:
                            $$a^{p-1} \equiv 1 \pmod{p}$$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Chinese Remainder Theorem</h3>
                <div class="theorem">
                    <h4>CRT Statement</h4>
                    If $n_1, n_2, \ldots, n_k$ are pairwise coprime, then the system:
                    <div class="math-display">
                        $$\begin{cases}
                        x \equiv a_1 \pmod{n_1} \\
                        x \equiv a_2 \pmod{n_2} \\
                        \vdots \\
                        x \equiv a_k \pmod{n_k}
                        \end{cases}$$
                    </div>
                    has a unique solution modulo $N = n_1n_2 \cdots n_k$
                </div>
                
                <div class="algorithm-box">
                    <h5>CRT Algorithm</h5>
                    <div class="code-block">
                        1. Compute N = n₁n₂...nₖ
                        2. For each i, compute Nᵢ = N/nᵢ
                        3. Find Mᵢ such that NᵢMᵢ ≡ 1 (mod nᵢ)
                        4. Solution: x ≡ Σ aᵢNᵢMᵢ (mod N)
                    </div>
                </div>

                <div class="cs-application">
                    <h5>CS Applications:</h5>
                    Cryptography (RSA, ElGamal), hash functions, pseudorandom number generation, error-correcting codes, computer algebra
                </div>
            </div>
        </section>

        <section id="algorithms" class="section">
            <h2>Algorithm Analysis</h2>
            
            <div class="topic">
                <h3>Asymptotic Notation</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Big O Notation</h4>
                        <div class="math-display">
                            $f(n) = O(g(n))$ if $\exists c > 0, n_0$ such that
                            $f(n) \leq c \cdot g(n)$ for all $n \geq n_0$
                            
                            Upper bound: $f$ grows no faster than $g$
                            
                            $f(n) = \Omega(g(n))$ if $g(n) = O(f(n))$
                            Lower bound: $f$ grows at least as fast as $g$
                            
                            $f(n) = \Theta(g(n))$ if $f(n) = O(g(n))$ and $f(n) = \Omega(g(n))$
                            Tight bound: $f$ and $g$ grow at same rate
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Common Complexities</h4>
                        <div class="math-display">
                            $$O(1) < O(\log n) < O(n) < O(n \log n) < O(n^2) < O(n^3) < O(2^n) < O(n!)$$
                            
                            Logarithmic: binary search, balanced tree operations
                            Linear: linear search, single loop
                            Linearithmic: merge sort, heap sort
                            Quadratic: nested loops, simple sorting
                            Exponential: brute force subsets
                            Factorial: brute force permutations
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Sorting Algorithms</h3>
                
                <table class="complexity-table">
                    <thead>
                        <tr>
                            <th>Algorithm</th>
                            <th>Best Case</th>
                            <th>Average Case</th>
                            <th>Worst Case</th>
                            <th>Space</th>
                            <th>Stable</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>Bubble Sort</td>
                            <td>O(n)</td>
                            <td>O(n²)</td>
                            <td>O(n²)</td>
                            <td>O(1)</td>
                            <td>Yes</td>
                        </tr>
                        <tr>
                            <td>Selection Sort</td>
                            <td>O(n²)</td>
                            <td>O(n²)</td>
                            <td>O(n²)</td>
                            <td>O(1)</td>
                            <td>No</td>
                        </tr>
                        <tr>
                            <td>Insertion Sort</td>
                            <td>O(n)</td>
                            <td>O(n²)</td>
                            <td>O(n²)</td>
                            <td>O(1)</td>
                            <td>Yes</td>
                        </tr>
                        <tr>
                            <td>Merge Sort</td>
                            <td>O(n log n)</td>
                            <td>O(n log n)</td>
                            <td>O(n log n)</td>
                            <td>O(n)</td>
                            <td>Yes</td>
                        </tr>
                        <tr>
                            <td>Quick Sort</td>
                            <td>O(n log n)</td>
                            <td>O(n log n)</td>
                            <td>O(n²)</td>
                            <td>O(log n)</td>
                            <td>No</td>
                        </tr>
                        <tr>
                            <td>Heap Sort</td>
                            <td>O(n log n)</td>
                            <td>O(n log n)</td>
                            <td>O(n log n)</td>
                            <td>O(1)</td>
                            <td>No</td>
                        </tr>
                        <tr>
                            <td>Counting Sort</td>
                            <td>O(n + k)</td>
                            <td>O(n + k)</td>
                            <td>O(n + k)</td>
                            <td>O(k)</td>
                            <td>Yes</td>
                        </tr>
                        <tr>
                            <td>Radix Sort</td>
                            <td>O(d(n + k))</td>
                            <td>O(d(n + k))</td>
                            <td>O(d(n + k))</td>
                            <td>O(n + k)</td>
                            <td>Yes</td>
                        </tr>
                    </tbody>
                </table>
            </div>

            <div class="topic">
                <h3>Search Algorithms</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Binary Search</h4>
                        <div class="math-display">
                            Prerequisite: sorted array
                            
                            Algorithm:
                            ```
                            while low ≤ high:
                                mid = (low + high) / 2
                                if arr[mid] == target: return mid
                                elif arr[mid] < target: low = mid + 1
                                else: high = mid - 1
                            ```
                            
                            Time: $O(\log n)$, Space: $O(1)$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Hash Table Search</h4>
                        <div class="math-display">
                            Average case: $O(1)$ for search, insert, delete
                            Worst case: $O(n)$ if many collisions
                            
                            Load factor $\alpha = \frac{n}{m}$ (items/buckets)
                            Keep $\alpha < 0.75$ for good performance
                            
                            Collision resolution: chaining, open addressing
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Dynamic Programming</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Optimal Substructure</h4>
                        <div class="math-display">
                            A problem has optimal substructure if optimal solution contains optimal solutions to subproblems
                            
                            Examples: shortest paths, matrix chain multiplication, optimal binary search trees, edit distance
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Overlapping Subproblems</h4>
                        <div class="math-display">
                            Recursive algorithm solves same subproblems repeatedly
                            
                            Memoization: top-down approach, store results
                            Tabulation: bottom-up approach, fill table
                            
                            Fibonacci: naive $O(2^n)$, DP $O(n)$
                        </div>
                    </div>
                </div>
                
                <div class="algorithm-box">
                    <h5>Classic DP Problems</h5>
                    <div class="code-block">
                        Knapsack Problem: max value with weight constraint
                        DP[i][w] = max value using first i items, weight ≤ w
                        
                        Longest Common Subsequence:
                        LCS[i][j] = length of LCS of first i chars of X, first j chars of Y
                        
                        Edit Distance (Levenshtein):
                        ED[i][j] = min operations to transform X[1..i] to Y[1..j]
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Greedy Algorithms</h3>
                <div class="important">
                    <h5>Greedy Choice Property</h5>
                    Global optimum can be reached by making locally optimal choices at each step
                </div>
                
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Activity Selection</h4>
                        <div class="math-display">
                            Select maximum number of non-overlapping activities
                            
                            Greedy strategy: sort by finish time, always pick earliest finishing activity
                            
                            Time: $O(n \log n)$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Huffman Coding</h4>
                        <div class="math-display">
                            Optimal prefix-free binary codes
                            
                            Greedy strategy: repeatedly merge two nodes with minimum frequency
                            
                            Time: $O(n \log n)$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Complexity Classes</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>P vs NP</h4>
                        <div class="math-display">
                            P: problems solvable in polynomial time
                            NP: problems verifiable in polynomial time
                            NP-Complete: hardest problems in NP
                            NP-Hard: at least as hard as NP-Complete
                            
                            $P \subseteq NP$, but $P = NP$? is open question
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Reduction</h4>
                        <div class="math-display">
                            Problem $A$ reduces to $B$ ($A \leq_p B$) if $A$ can be solved using polynomial number of calls to $B$
                            
                            If $A \leq_p B$ and $B \in P$, then $A \in P$
                            
                            Used to prove NP-completeness
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <section id="crypto" class="section">
            <h2>Cryptography</h2>
            
            <div class="topic">
                <h3>Classical Cryptography</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Caesar Cipher</h4>
                        <div class="math-display">
                            Encryption: $E(x) = (x + k) \bmod 26$
                            Decryption: $D(y) = (y - k) \bmod 26$
                            
                            Key space: 26 possible keys
                            Vulnerable to frequency analysis
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Affine Cipher</h4>
                        <div class="math-display">
                            Encryption: $E(x) = (ax + b) \bmod 26$
                            Decryption: $D(y) = a^{-1}(y - b) \bmod 26$
                            
                            Requirement: $\gcd(a, 26) = 1$
                            Key space: $\varphi(26) \times 26 = 12 \times 26 = 312$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Vigenère Cipher</h4>
                        <div class="math-display">
                            Encryption: $C_i = (M_i + K_{i \bmod \text{keylen}}) \bmod 26$
                            
                            Polyalphabetic substitution
                            
                            Broken by Kasiski examination and index of coincidence
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Public Key Cryptography</h3>
                <div class="theorem">
                    <h4>RSA Algorithm</h4>
                    <div class="math-display">
                        Key Generation:
                        1. Choose large primes $p, q$
                        2. $n = pq$, $\varphi(n) = (p-1)(q-1)$
                        3. Choose $e$: $\gcd(e, \varphi(n)) = 1$
                        4. Find $d$: $ed \equiv 1 \pmod{\varphi(n)}$
                        
                        Public key: $(n, e)$
                        Private key: $(n, d)$
                        
                        Encryption: $C = M^e \bmod n$
                        Decryption: $M = C^d \bmod n$
                    </div>
                </div>
                
                <div class="proof-sketch">
                    <strong>Why RSA works:</strong> By Euler's theorem, if $\gcd(M, n) = 1$, then $M^{\varphi(n)} \equiv 1 \pmod{n}$. 
                    Since $ed \equiv 1 \pmod{\varphi(n)}$, we have $ed = 1 + k\varphi(n)$ for some $k$. 
                    Therefore: $(M^e)^d = M^{ed} = M^{1+k\varphi(n)} = M \cdot (M^{\varphi(n)})^k \equiv M \cdot 1^k = M \pmod{n}$
                </div>
                
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Diffie-Hellman Key Exchange</h4>
                        <div class="math-display">
                            Public: prime $p$, generator $g$
                            
                            Alice: chooses $a$, sends $g^a \bmod p$
                            Bob: chooses $b$, sends $g^b \bmod p$
                            
                            Shared secret: $K = g^{ab} \bmod p$
                            
                            Security based on discrete log problem
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>ElGamal Encryption</h4>
                        <div class="math-display">
                            Key Generation:
                            Choose prime $p$, generator $g$, private key $x$
                            Public key: $y = g^x \bmod p$
                            
                            Encryption of $M$:
                            Choose random $k$, send $(g^k \bmod p, M \cdot y^k \bmod p)$
                            
                            Decryption: $M = c_2 \cdot (c_1^x)^{-1} \bmod p$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Hash Functions</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Properties</h4>
                        <div class="math-display">
                            Pre-image resistance: given $h$, hard to find $x$ with $H(x) = h$
                            
                            Second pre-image resistance: given $x$, hard to find $x' \neq x$ with $H(x) = H(x')$
                            
                            Collision resistance: hard to find $x, x'$ with $H(x) = H(x')$
                            
                            Birthday paradox: expect collision after $\sqrt{2^n}$ inputs for $n$-bit hash
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Applications</h4>
                        <div class="math-display">
                            Digital signatures: sign hash instead of message
                            
                            Password storage: store $H(\text{password} + \text{salt})$
                            
                            Proof of work: find nonce with $H(\text{block} + \text{nonce}) < \text{target}$
                            
                            Data integrity: compare hash values
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Digital Signatures</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>RSA Signatures</h4>
                        <div class="math-display">
                            Signing: $S = H(M)^d \bmod n$
                            
                            Verification: check if $S^e \equiv H(M) \pmod{n}$
                            
                            Must use padding (PSS) to prevent attacks
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>DSA (Digital Signature Algorithm)</h4>
                        <div class="math-display">
                            Parameters: prime $p$, $q \mid (p-1)$, generator $g$
                            Private key: $x$, Public key: $y = g^x \bmod p$
                            
                            Signing $M$:
                            $k = $ random, $r = (g^k \bmod p) \bmod q$
                            $s = k^{-1}(H(M) + xr) \bmod q$
                            Signature: $(r, s)$
                            
                            Verification: check if $r = ((g^{H(M)s^{-1}} \cdot y^{rs^{-1}}) \bmod p) \bmod q$
                        </div>
                    </div>
                </div>

                <div class="cs-application">
                    <h5>CS Applications:</h5>
                    Secure communications, blockchain technology, password authentication, digital certificates, software signing, cryptocurrency
                </div>
            </div>
        </section>

        <section id="optimization" class="section">
            <h2>Optimization</h2>
            
            <div class="topic">
                <h3>Linear Programming</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Standard Form</h4>
                        <div class="math-display">
                            Minimize: $\mathbf{c}^T \mathbf{x}$
                            Subject to: $A\mathbf{x} = \mathbf{b}$, $\mathbf{x} \geq \mathbf{0}$
                            
                            Can convert any LP to standard form:
                            - $\max f \rightarrow \min(-f)$
                            - inequality $\rightarrow$ equality (add slack variables)
                            - unrestricted variable $\rightarrow$ difference of non-negative variables
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Simplex Method</h4>
                        <div class="math-display">
                            1. Start at basic feasible solution (vertex of polytope)
                            2. Check optimality conditions
                            3. If not optimal, move to adjacent vertex that improves objective
                            4. Repeat until optimal or unbounded
                            
                            Worst case: exponential
                            Average case: polynomial
                        </div>
                    </div>
                </div>
                
                <div class="theorem">
                    <h4>Fundamental Theorem of Linear Programming</h4>
                    If LP has optimal solution, then it has optimal basic feasible solution (vertex of feasible region)
                </div>
                
                <div class="theorem">
                    <h4>Duality Theorem</h4>
                    <div class="math-display">
                        Primal: $\min \mathbf{c}^T \mathbf{x}$ subject to $A\mathbf{x} \geq \mathbf{b}$, $\mathbf{x} \geq \mathbf{0}$
                        
                        Dual: $\max \mathbf{b}^T \mathbf{y}$ subject to $A^T \mathbf{y} \leq \mathbf{c}$, $\mathbf{y} \geq \mathbf{0}$
                        
                        Strong duality: if both have optimal solutions, optimal values are equal
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Nonlinear Optimization</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Unconstrained Optimization</h4>
                        <div class="math-display">
                            First-order condition: $\nabla f(\mathbf{x}^*) = \mathbf{0}$
                            
                            Second-order condition: $\nabla^2 f(\mathbf{x}^*)$ positive definite
                            
                            Gradient descent: $\mathbf{x}_{k+1} = \mathbf{x}_k - \alpha_k \nabla f(\mathbf{x}_k)$
                            
                            Newton's method: $\mathbf{x}_{k+1} = \mathbf{x}_k - [\nabla^2 f(\mathbf{x}_k)]^{-1} \nabla f(\mathbf{x}_k)$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Constrained Optimization</h4>
                        <div class="math-display">
                            KKT conditions for $\min f(\mathbf{x})$ subject to $g(\mathbf{x}) \leq \mathbf{0}$, $h(\mathbf{x}) = \mathbf{0}$:
                            
                            $\nabla f(\mathbf{x}^*) + \sum_i \lambda_i \nabla g_i(\mathbf{x}^*) + \sum_j \mu_j \nabla h_j(\mathbf{x}^*) = \mathbf{0}$
                            
                            $g_i(\mathbf{x}^*) \leq 0$, $h_j(\mathbf{x}^*) = 0$
                            
                            $\lambda_i \geq 0$, $\lambda_i g_i(\mathbf{x}^*) = 0$ (complementary slackness)
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Convex Optimization</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Convex Sets & Functions</h4>
                        <div class="math-display">
                            Convex set: $\forall \mathbf{x}, \mathbf{y} \in S, \forall \lambda \in [0,1]: \lambda\mathbf{x} + (1-\lambda)\mathbf{y} \in S$
                            
                            Convex function: $f(\lambda\mathbf{x} + (1-\lambda)\mathbf{y}) \leq \lambda f(\mathbf{x}) + (1-\lambda)f(\mathbf{y})$
                            
                            Properties:
                            - Local minimum = global minimum
                            - First-order condition sufficient for optimality
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Interior Point Methods</h4>
                        <div class="math-display">
                            Barrier method: replace constraints $g(\mathbf{x}) \leq \mathbf{0}$ with penalty terms $-t \sum_i \log(-g_i(\mathbf{x}))$
                            
                            As $t \to \infty$, solution approaches constrained optimum
                            
                            Polynomial time complexity for convex problems
                        </div>
                    </div>
                </div>

                <div class="cs-application">
                    <h5>CS Applications:</h5>
                    Machine learning (SVM, neural network training), resource allocation, network flow optimization, compiler optimization, game theory
                </div>
            </div>

            <div class="topic">
                <h3>Integer Programming</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Branch and Bound</h4>
                        <div class="math-display">
                            1. Solve LP relaxation
                            2. If solution integer, update best bound
                            3. If not integer, branch on fractional variable
                            4. Recursively solve subproblems
                            5. Prune if bound worse than current best
                            
                            NP-hard in general, but practical for many instances
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Cutting Planes</h4>
                        <div class="math-display">
                            Add linear constraints (cuts) that remove fractional solutions but preserve all integer solutions
                            
                            Gomory cuts: derived from optimal LP tableau
                            
                            Problem-specific cuts often more effective
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <div class="section">
            <h2 class="highlight">Mathematical Software & Tools</h2>
            
            <div class="formula-grid">
                <div class="formula-card">
                    <h4>Symbolic Computation</h4>
                    <div class="math-display">
                        Mathematica, Maple, SymPy (Python)
                        
                        Exact arithmetic, symbolic integration/differentiation,
                        equation solving, simplification
                        
                        Computer algebra systems
                    </div>
                </div>
                
                <div class="formula-card">
                    <h4>Numerical Computing</h4>
                    <div class="math-display">
                        MATLAB, NumPy/SciPy (Python), R
                        
                        Linear algebra (BLAS, LAPACK)
                        Optimization (CPLEX, Gurobi)
                        Statistics and data analysis
                    </div>
                </div>
                
                <div class="formula-card">
                    <h4>Proof Assistants</h4>
                    <div class="math-display">
                        Coq, Lean, Agda, Isabelle/HOL
                        
                        Formal verification of mathematical proofs
                        Computer-checked mathematics
                        Growing importance in CS theory
                    </div>
                </div>
                
                <div class="formula-card">
                    <h4>Computational Complexity</h4>
                    <div class="math-display">
                        Complexity Zoo: database of complexity classes
                        
                        P, NP, PSPACE, EXPTIME, etc.
                        Reductions and completeness results
                        Interactive proofs, quantum complexity
                    </div>
                </div>
            </div>
            
            <div class="important">
                <h5>Study Strategy for Advanced Math in CS:</h5>
                Focus on applications: understand how each mathematical concept applies to computer science problems. 
                Practice implementation: code algorithms and verify theoretical results computationally.
                Connect concepts: see relationships between different mathematical areas and their CS applications.
                Stay current: mathematics in CS is rapidly evolving, especially in machine learning and quantum computing.
            </div>
        </div>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            // Initialize KaTeX auto-render
            renderMathInElement(document.body, {
                delimiters: [
                    {left: '$', right: '$', display: true},
                    {left: ', right: ', display: false},
                    {left: '\\(', right: '\\)', display: false},
                    {left: '\\[', right: '\\]', display: true}
                ],
                throwOnError: false
            });

            // Smooth scrolling for navigation
            document.querySelectorAll('.nav-link, .nav-card a').forEach(link => {
                link.addEventListener('click', function(e) {
                    e.preventDefault();
                    const targetId = this.getAttribute('href');
                    const target = document.querySelector(targetId);
                    if (target) {
                        target.scrollIntoView({ behavior: 'smooth', block: 'start' });
                    }
                });
            });

            // Add hover effects to cards
            document.querySelectorAll('.formula-card, .theorem, .algorithm-box').forEach(card => {
                card.addEventListener('mouseenter', function() {
                    this.style.transform = 'translateY(-2px)';
                    this.style.boxShadow = '0 4px 15px rgba(0, 0, 0, 0.15)';
                    this.style.transition = 'all 0.3s ease';
                });
                
                card.addEventListener('mouseleave', function() {
                    this.style.transform = 'translateY(0)';
                    this.style.boxShadow = '0 2px 8px rgba(0, 0, 0, 0.08)';
                });
            });

            // Highlight active navigation item
            const observer = new IntersectionObserver((entries) => {
                entries.forEach(entry => {
                    if (entry.isIntersecting) {
                        const id = entry.target.id;
                        document.querySelectorAll('.nav-link').forEach(link => {
                            link.classList.remove('active');
                            if (link.getAttribute('href') === `#${id}`) {
                                link.style.background = '#f0f0f0';
                                link.style.color = '#000000';
                            } else {
                                link.style.background = '';
                                link.style.color = '#000000';
                            }
                        });
                    }
                });
            }, { threshold: 0.1 });

            document.querySelectorAll('.section').forEach(section => {
                observer.observe(section);
            });
        });
    </script>
</body>
</html>, right: '
    
    <link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;700&family=Inter:wght@400;600;700&display=swap" rel="stylesheet">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Inter', sans-serif;
            background: #ffffff;
            color: #1a1a1a;
            min-height: 100vh;
            line-height: 1.6;
        }

        .container {
            max-width: 1600px;
            margin: 0 auto;
            padding: 20px;
        }

        .header {
            text-align: center;
            margin-bottom: 40px;
            padding: 30px;
            background: linear-gradient(135deg, #000000, #333333);
            color: white;
            border-radius: 12px;
            box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
        }

        .header h1 {
            font-size: 2.5rem;
            margin-bottom: 10px;
            font-weight: 700;
        }

        .header p {
            font-size: 1.1rem;
            opacity: 0.9;
        }

        .nav-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
            gap: 15px;
            margin-bottom: 40px;
        }

        .nav-card {
            background: #f8f9fa;
            border: 2px solid #e9ecef;
            border-radius: 8px;
            padding: 15px;
            text-align: center;
            transition: all 0.3s ease;
            cursor: pointer;
        }

        .nav-card:hover {
            border-color: #333333;
            background: #f0f0f0;
            transform: translateY(-2px);
        }

        .nav-card a {
            text-decoration: none;
            color: #000000;
            font-weight: 600;
            font-size: 0.9rem;
        }

        .section {
            margin-bottom: 50px;
            padding: 30px;
            background: #ffffff;
            border: 1px solid #e9ecef;
            border-radius: 12px;
            box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
        }

        .section h2 {
            color: #000000;
            font-size: 1.8rem;
            margin-bottom: 25px;
            border-bottom: 3px solid #333333;
            padding-bottom: 10px;
            font-weight: 700;
        }

        .topic {
            margin-bottom: 30px;
            padding: 20px;
            background: #f8f9fa;
            border-left: 4px solid #333333;
            border-radius: 0 8px 8px 0;
        }

        .topic h3 {
            color: #1a1a1a;
            font-size: 1.3rem;
            margin-bottom: 15px;
            font-weight: 600;
        }

        .formula-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
            gap: 20px;
            margin: 20px 0;
        }

        .formula-card {
            background: #ffffff;
            border: 1px solid #dee2e6;
            border-radius: 8px;
            padding: 20px;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
        }

        .formula-card h4 {
            color: #333333;
            font-size: 1rem;
            margin-bottom: 12px;
            font-weight: 600;
        }

        .math-display {
            background: #f8f9fa;
            padding: 20px;
            border-radius: 6px;
            margin: 10px 0;
            overflow-x: auto;
            font-size: 1.1rem;
        }

        .math-display .katex {
            font-size: 1.2em;
        }

        .math-display .katex-display {
            margin: 0.5em 0;
        }

        .theorem {
            background: linear-gradient(135deg, #f0f0f0, #e5e5e5);
            border: 1px solid #666666;
            border-radius: 8px;
            padding: 20px;
            margin: 15px 0;
        }

        .theorem h4 {
            color: #000000;
            font-size: 1.1rem;
            margin-bottom: 10px;
            font-weight: 700;
        }

        .proof-sketch {
            background: #f5f5f5;
            border-left: 4px solid #666666;
            padding: 15px;
            margin: 10px 0;
            border-radius: 0 6px 6px 0;
            font-size: 0.9rem;
        }

        .complexity-table {
            width: 100%;
            border-collapse: collapse;
            margin: 15px 0;
            background: white;
        }

        .complexity-table th,
        .complexity-table td {
            border: 1px solid #dee2e6;
            padding: 12px;
            text-align: left;
        }

        .complexity-table th {
            background: #333333;
            color: white;
            font-weight: 600;
        }

        .complexity-table tr:nth-child(even) {
            background: #f8f9fa;
        }

        .algorithm-box {
            background: #f8f8f8;
            border: 1px solid #666666;
            border-radius: 8px;
            padding: 20px;
            margin: 15px 0;
        }

        .algorithm-box h5 {
            color: #1a1a1a;
            font-size: 1rem;
            margin-bottom: 10px;
            font-weight: 600;
        }

        .code-block {
            background: #263238;
            color: #ffffff;
            padding: 15px;
            border-radius: 6px;
            font-family: 'JetBrains Mono', monospace;
            font-size: 0.85rem;
            overflow-x: auto;
            margin: 10px 0;
        }

        .important {
            background: linear-gradient(135deg, #f8f8f8, #e8e8e8);
            border: 2px solid #666666;
            border-radius: 8px;
            padding: 15px;
            margin: 15px 0;
        }

        .important h5 {
            color: #1a1a1a;
            font-size: 1rem;
            margin-bottom: 8px;
            font-weight: 600;
        }

        .matrix-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
            gap: 15px;
        }

        .stats-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
            gap: 15px;
        }

        .graph-theory-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
            gap: 18px;
        }

        .navigation {
            position: fixed;
            top: 20px;
            right: 20px;
            background: rgba(255, 255, 255, 0.95);
            border: 1px solid #dee2e6;
            border-radius: 8px;
            padding: 15px;
            max-height: 80vh;
            overflow-y: auto;
            z-index: 1000;
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
        }

        .nav-link {
            display: block;
            color: #000000;
            text-decoration: none;
            font-size: 0.8rem;
            margin-bottom: 8px;
            padding: 6px;
            border-radius: 4px;
            transition: background 0.3s;
        }

        .nav-link:hover {
            background: #f0f0f0;
        }

        .cs-application {
            background: linear-gradient(135deg, #f5f5f5, #e8e8e8);
            border: 1px solid #666666;
            border-radius: 8px;
            padding: 15px;
            margin: 10px 0;
        }

        .cs-application h5 {
            color: #1a1a1a;
            font-size: 0.95rem;
            margin-bottom: 8px;
            font-weight: 600;
        }

        /* Special styling for inline math */
        .katex {
            font-size: 1.1em;
        }

        /* Make math in lists look good */
        li .katex {
            margin: 0 0.2em;
        }

        @media (max-width: 1024px) {
            .navigation {
                position: relative;
                margin-bottom: 30px;
            }
            
            .formula-grid {
                grid-template-columns: 1fr;
            }
            
            .header h1 {
                font-size: 2rem;
            }
        }
    </style>
</head>
<body>
    <div class="navigation">
        <a href="#calculus" class="nav-link">Calculus</a>
        <a href="#calc3" class="nav-link">Multivariable Calculus</a>
        <a href="#diffeq" class="nav-link">Differential Equations</a>
        <a href="#linear" class="nav-link">Linear Algebra</a>
        <a href="#discrete" class="nav-link">Discrete Mathematics</a>
        <a href="#probability" class="nav-link">Probability & Statistics</a>
        <a href="#numerical" class="nav-link">Numerical Analysis</a>
        <a href="#complex" class="nav-link">Complex Analysis</a>
        <a href="#graph" class="nav-link">Graph Theory</a>
        <a href="#number" class="nav-link">Number Theory</a>
        <a href="#algorithms" class="nav-link">Algorithm Analysis</a>
        <a href="#crypto" class="nav-link">Cryptography</a>
        <a href="#optimization" class="nav-link">Optimization</a>
    </div>

    <div class="container">
        <div class="header">
            <h1>Advanced Mathematics for Computer Science</h1>
            <p>Complete Reference: Calculus • Multivariable Calculus • Linear Algebra • Discrete Math • Graph Theory • Algorithms • Cryptography</p>
        </div>

        <div class="nav-grid">
            <div class="nav-card"><a href="#calculus">Calculus</a></div>
            <div class="nav-card"><a href="#calc3">Multivariable Calculus</a></div>
            <div class="nav-card"><a href="#diffeq">Differential Equations</a></div>
            <div class="nav-card"><a href="#linear">Linear Algebra</a></div>
            <div class="nav-card"><a href="#discrete">Discrete Mathematics</a></div>
            <div class="nav-card"><a href="#probability">Probability & Statistics</a></div>
            <div class="nav-card"><a href="#numerical">Numerical Analysis</a></div>
            <div class="nav-card"><a href="#complex">Complex Analysis</a></div>
            <div class="nav-card"><a href="#graph">Graph Theory</a></div>
            <div class="nav-card"><a href="#number">Number Theory</a></div>
            <div class="nav-card"><a href="#algorithms">Algorithm Analysis</a></div>
            <div class="nav-card"><a href="#crypto">Cryptography</a></div>
            <div class="nav-card"><a href="#optimization">Optimization</a></div>
        </div>

        <section id="calculus" class="section">
            <h2>Calculus</h2>
            
            <div class="topic">
                <h3>Limits</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Definition of a Limit</h4>
                        <div class="math-display">
                            $$\lim_{x \to a} f(x) = L$$
                            means: For every $\varepsilon > 0$, there exists $\delta > 0$ such that
                            $$0 < |x - a| < \delta \implies |f(x) - L| < \varepsilon$$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Important Limits</h4>
                        <div class="math-display">
                            $$\lim_{x \to 0} \frac{\sin x}{x} = 1$$
                            $$\lim_{x \to 0} \frac{1 - \cos x}{x} = 0$$
                            $$\lim_{x \to 0} \frac{e^x - 1}{x} = 1$$
                            $$\lim_{x \to \infty} \left(1 + \frac{1}{x}\right)^x = e$$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>L'Hôpital's Rule</h4>
                        <div class="math-display">
                            If $\lim_{x \to a} f(x) = \lim_{x \to a} g(x) = 0$ or $\pm\infty$, then:
                            $$\lim_{x \to a} \frac{f(x)}{g(x)} = \lim_{x \to a} \frac{f'(x)}{g'(x)}$$
                            (provided the right side exists)
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Derivatives</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Definition</h4>
                        <div class="math-display">
                            $$f'(x) = \lim_{h \to 0} \frac{f(x + h) - f(x)}{h}$$
                            Alternative notation: $\frac{df}{dx}$, $\frac{d}{dx}f(x)$, $D_x f$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Derivative Rules</h4>
                        <div class="math-display">
                            Power Rule: $\frac{d}{dx}(x^n) = nx^{n-1}$
                            
                            Product Rule: $(fg)' = f'g + fg'$
                            
                            Quotient Rule: $\left(\frac{f}{g}\right)' = \frac{f'g - fg'}{g^2}$
                            
                            Chain Rule: $\frac{d}{dx}f(g(x)) = f'(g(x)) \cdot g'(x)$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Common Derivatives</h4>
                        <div class="math-display">
                            $$\frac{d}{dx}(\sin x) = \cos x \qquad \frac{d}{dx}(\cos x) = -\sin x$$
                            $$\frac{d}{dx}(e^x) = e^x \qquad \frac{d}{dx}(\ln x) = \frac{1}{x}$$
                            $$\frac{d}{dx}(\tan x) = \sec^2 x \qquad \frac{d}{dx}(\arctan x) = \frac{1}{1+x^2}$$
                        </div>
                    </div>
                </div>

                <div class="theorem">
                    <h4>Mean Value Theorem</h4>
                    <div class="math-display">
                        If $f$ is continuous on $[a,b]$ and differentiable on $(a,b)$, then there exists $c \in (a,b)$ such that:
                        $$f'(c) = \frac{f(b) - f(a)}{b - a}$$
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Integrals</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Definite Integral</h4>
                        <div class="math-display">
                            $$\int_a^b f(x)\,dx = \lim_{n \to \infty} \sum_{i=1}^n f(x_i^*) \Delta x$$
                            where $\Delta x = \frac{b-a}{n}$ and $x_i^* \in [x_{i-1}, x_i]$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Fundamental Theorem of Calculus</h4>
                        <div class="math-display">
                            Part 1: If $F(x) = \int_a^x f(t)\,dt$, then $F'(x) = f(x)$
                            
                            Part 2: If $F'(x) = f(x)$, then
                            $$\int_a^b f(x)\,dx = F(b) - F(a)$$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Integration Techniques</h4>
                        <div class="math-display">
                            Substitution: $\int f(g(x))g'(x)\,dx = \int f(u)\,du$
                            
                            Integration by Parts: $\int u\,dv = uv - \int v\,du$
                            
                            Partial Fractions: Decompose rational functions
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Common Integrals</h4>
                        <div class="math-display">
                            $$\int x^n\,dx = \frac{x^{n+1}}{n+1} + C \quad (n \neq -1)$$
                            $$\int \frac{1}{x}\,dx = \ln|x| + C$$
                            $$\int e^x\,dx = e^x + C$$
                            $$\int \sin x\,dx = -\cos x + C$$
                            $$\int \frac{1}{\sqrt{1-x^2}}\,dx = \arcsin x + C$$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Series and Sequences</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Sequences</h4>
                        <div class="math-display">
                            A sequence $\{a_n\}$ converges to $L$ if:
                            $$\lim_{n \to \infty} a_n = L$$
                            
                            Common limits:
                            $$\lim_{n \to \infty} \frac{1}{n} = 0 \qquad \lim_{n \to \infty} \sqrt[n]{n} = 1$$
                            $$\lim_{n \to \infty} \left(1 + \frac{1}{n}\right)^n = e$$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Series Convergence Tests</h4>
                        <div class="math-display">
                            Geometric Series: $\sum_{n=0}^{\infty} ar^n = \frac{a}{1-r}$ if $|r| < 1$
                            
                            p-Series: $\sum_{n=1}^{\infty} \frac{1}{n^p}$ converges if $p > 1$
                            
                            Ratio Test: If $\lim_{n \to \infty} \left|\frac{a_{n+1}}{a_n}\right| = L$
                            then series converges if $L < 1$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Taylor Series</h4>
                        <div class="math-display">
                            $$f(x) = \sum_{n=0}^{\infty} \frac{f^{(n)}(a)}{n!}(x-a)^n$$
                            
                            Common Taylor series:
                            $$e^x = \sum_{n=0}^{\infty} \frac{x^n}{n!}$$
                            $$\sin x = \sum_{n=0}^{\infty} \frac{(-1)^n x^{2n+1}}{(2n+1)!}$$
                            $$\ln(1+x) = \sum_{n=1}^{\infty} \frac{(-1)^{n+1} x^n}{n}$$
                        </div>
                    </div>
                </div>

                <div class="cs-application">
                    <h5>CS Applications:</h5>
                    Machine learning (gradient descent, backpropagation), computer graphics (physics simulations), numerical methods, algorithm complexity analysis, signal processing
                </div>
            </div>

            <div class="topic">
                <h3>Applications of Calculus</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Optimization</h4>
                        <div class="math-display">
                            Critical points: $f'(x) = 0$ or $f'(x)$ undefined
                            
                            Second derivative test:
                            - If $f''(c) > 0$: local minimum at $x = c$
                            - If $f''(c) < 0$: local maximum at $x = c$
                            - If $f''(c) = 0$: test inconclusive
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Related Rates</h4>
                        <div class="math-display">
                            If variables $x$ and $y$ are related by an equation and vary with time $t$:
                            $$\frac{dy}{dt} = \frac{dy}{dx} \cdot \frac{dx}{dt}$$
                            
                            Example: Area of circle $A = \pi r^2$
                            $$\frac{dA}{dt} = 2\pi r \frac{dr}{dt}$$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Arc Length & Surface Area</h4>
                        <div class="math-display">
                            Arc length: $L = \int_a^b \sqrt{1 + (f'(x))^2}\,dx$
                            
                            Surface area (revolution about x-axis):
                            $$S = 2\pi \int_a^b f(x)\sqrt{1 + (f'(x))^2}\,dx$$
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <section id="calc3" class="section">
            <h2>Multivariable Calculus</h2>
            
            <div class="topic">
                <h3>Partial Derivatives & Gradients</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Partial Derivatives</h4>
                        <div class="math-display">
                            $$\frac{\partial f}{\partial x} = \lim_{h \to 0} \frac{f(x+h,y) - f(x,y)}{h}$$
                            
                            Mixed partials theorem (Clairaut):
                            $$\frac{\partial^2 f}{\partial x \partial y} = \frac{\partial^2 f}{\partial y \partial x}$$
                            (if both are continuous)
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Gradient & Directional Derivatives</h4>
                        <div class="math-display">
                            $$\nabla f = \left( \frac{\partial f}{\partial x}, \frac{\partial f}{\partial y}, \frac{\partial f}{\partial z} \right)$$
                            
                            Directional derivative:
                            $$D_{\mathbf{u}} f = \nabla f \cdot \mathbf{u}$$
                            
                            Maximum rate of change: $|\nabla f|$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Chain Rule (Multivariable)</h4>
                        <div class="math-display">
                            If $z = f(x,y)$ where $x = g(t)$ and $y = h(t)$:
                            $$\frac{dz}{dt} = \frac{\partial z}{\partial x}\frac{dx}{dt} + \frac{\partial z}{\partial y}\frac{dy}{dt}$$
                            
                            General form:
                            $$\frac{\partial z}{\partial t} = \sum_{i} \frac{\partial z}{\partial x_i}\frac{\partial x_i}{\partial t}$$
                        </div>
                    </div>
                </div>
                
                <div class="cs-application">
                    <h5>CS Applications:</h5>
                    Machine learning optimization (gradient descent), computer graphics (surface normals), image processing (edge detection), neural network training
                </div>
            </div>

            <div class="topic">
                <h3>Multiple Integrals</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Double Integrals</h4>
                        <div class="math-display">
                            $$\iint_R f(x,y) \, dA = \int_a^b \int_{c(x)}^{d(x)} f(x,y) \, dy \, dx$$
                            
                            Fubini's Theorem: For continuous $f$,
                            $$\int_a^b \int_c^d f(x,y) \, dy \, dx = \int_c^d \int_a^b f(x,y) \, dx \, dy$$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Change of Variables</h4>
                        <div class="math-display">
                            $$\iint_R f(x,y) \, dx \, dy = \iint_S f(x(u,v), y(u,v)) |J| \, du \, dv$$
                            
                            Jacobian: $J = \frac{\partial(x,y)}{\partial(u,v)} = \begin{vmatrix} \frac{\partial x}{\partial u} & \frac{\partial x}{\partial v} \\ \frac{\partial y}{\partial u} & \frac{\partial y}{\partial v} \end{vmatrix}$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Cylindrical & Spherical Coordinates</h4>
                        <div class="math-display">
                            Cylindrical: $\begin{cases} x = r\cos\theta \\ y = r\sin\theta \\ z = z \end{cases}$ 
                            $dV = r \, dr \, d\theta \, dz$
                            
                            Spherical: $\begin{cases} x = \rho\sin\phi\cos\theta \\ y = \rho\sin\phi\sin\theta \\ z = \rho\cos\phi \end{cases}$
                            $dV = \rho^2\sin\phi \, d\rho \, d\phi \, d\theta$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Vector Calculus</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Vector Fields & Line Integrals</h4>
                        <div class="math-display">
                            $$\int_C \mathbf{F} \cdot d\mathbf{r} = \int_a^b \mathbf{F}(\mathbf{r}(t)) \cdot \mathbf{r}'(t) \, dt$$
                            
                            Conservative field: $\nabla \times \mathbf{F} = \mathbf{0}$
                            
                            If $\mathbf{F} = \nabla f$: $\int_C \mathbf{F} \cdot d\mathbf{r} = f(B) - f(A)$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Green's Theorem</h4>
                        <div class="math-display">
                            $$\oint_C (P \, dx + Q \, dy) = \iint_D \left( \frac{\partial Q}{\partial x} - \frac{\partial P}{\partial y} \right) dA$$
                            
                            Area formula: $A = \frac{1}{2} \oint_C (x \, dy - y \, dx)$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Divergence & Curl</h4>
                        <div class="math-display">
                            $$\text{div } \mathbf{F} = \nabla \cdot \mathbf{F} = \frac{\partial P}{\partial x} + \frac{\partial Q}{\partial y} + \frac{\partial R}{\partial z}$$
                            
                            $$\text{curl } \mathbf{F} = \nabla \times \mathbf{F} = \begin{vmatrix} \mathbf{i} & \mathbf{j} & \mathbf{k} \\ \frac{\partial}{\partial x} & \frac{\partial}{\partial y} & \frac{\partial}{\partial z} \\ P & Q & R \end{vmatrix}$$
                        </div>
                    </div>
                </div>

                <div class="theorem">
                    <h4>Stokes' Theorem</h4>
                    <div class="math-display">
                        $$\oint_C \mathbf{F} \cdot d\mathbf{r} = \iint_S (\nabla \times \mathbf{F}) \cdot \mathbf{n} \, dS$$
                    </div>
                    Relates line integral around boundary to surface integral of curl
                </div>

                <div class="theorem">
                    <h4>Divergence Theorem</h4>
                    <div class="math-display">
                        $$\iint_S \mathbf{F} \cdot \mathbf{n} \, dS = \iiint_E \nabla \cdot \mathbf{F} \, dV$$
                    </div>
                    Relates surface integral to volume integral of divergence
                </div>
            </div>
        </section>

        <section id="diffeq" class="section">
            <h2>Differential Equations</h2>
            
            <div class="topic">
                <h3>First-Order ODEs</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Separable Equations</h4>
                        <div class="math-display">
                            $$\frac{dy}{dx} = f(x)g(y)$$
                            
                            Solution method:
                            $$\int \frac{dy}{g(y)} = \int f(x) \, dx$$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Linear First-Order</h4>
                        <div class="math-display">
                            $$\frac{dy}{dx} + P(x)y = Q(x)$$
                            
                            Integrating factor: $\mu(x) = e^{\int P(x) \, dx}$
                            
                            Solution: $y = \frac{1}{\mu(x)}\left[\int \mu(x)Q(x) \, dx + C\right]$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Exact Equations</h4>
                        <div class="math-display">
                            $$M(x,y) \, dx + N(x,y) \, dy = 0$$
                            
                            Exact if: $\frac{\partial M}{\partial y} = \frac{\partial N}{\partial x}$
                            
                            Solution: Find $F(x,y)$ where $\frac{\partial F}{\partial x} = M$ and $\frac{\partial F}{\partial y} = N$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Second-Order Linear ODEs</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Homogeneous with Constant Coefficients</h4>
                        <div class="math-display">
                            $$ay'' + by' + cy = 0$$
                            
                            Characteristic equation: $ar^2 + br + c = 0$
                            
                            Solutions:
                            - If $r_1 \neq r_2$: $y = c_1e^{r_1x} + c_2e^{r_2x}$
                            - If $r_1 = r_2 = r$: $y = (c_1 + c_2x)e^{rx}$
                            - If $r = \alpha \pm \beta i$: $y = e^{\alpha x}(c_1\cos(\beta x) + c_2\sin(\beta x))$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Method of Undetermined Coefficients</h4>
                        <div class="math-display">
                            For $ay'' + by' + cy = f(x)$:
                            
                            - If $f(x) = e^{\alpha x}$: try $y_p = Ae^{\alpha x}$
                            - If $f(x) = \text{polynomial}$: try polynomial of same degree
                            - If $f(x) = \sin(\alpha x)$ or $\cos(\alpha x)$: 
                              try $y_p = A\cos(\alpha x) + B\sin(\alpha x)$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Variation of Parameters</h4>
                        <div class="math-display">
                            For $y'' + P(x)y' + Q(x)y = f(x)$
                            
                            If $y_1, y_2$ are homogeneous solutions:
                            $$y_p = -y_1\int\frac{y_2f}{W}dx + y_2\int\frac{y_1f}{W}dx$$
                            
                            Wronskian: $W = y_1y_2' - y_2y_1'$
                        </div>
                    </div>
                </div>

                <div class="cs-application">
                    <h5>CS Applications:</h5>
                    System dynamics, control theory, signal processing, population models in algorithms, oscillator circuits, physics simulations
                </div>
            </div>

            <div class="topic">
                <h3>Laplace Transforms</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Definition & Properties</h4>
                        <div class="math-display">
                            $$\mathcal{L}\{f(t)\} = F(s) = \int_0^{\infty} e^{-st}f(t) \, dt$$
                            
                            Properties:
                            - $\mathcal{L}\{af + bg\} = a\mathcal{L}\{f\} + b\mathcal{L}\{g\}$
                            - $\mathcal{L}\{f'\} = sF(s) - f(0)$
                            - $\mathcal{L}\{f''\} = s^2F(s) - sf(0) - f'(0)$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Common Transforms</h4>
                        <div class="math-display">
                            $$\mathcal{L}\{1\} = \frac{1}{s}$$
                            $$\mathcal{L}\{t^n\} = \frac{n!}{s^{n+1}}$$
                            $$\mathcal{L}\{e^{at}\} = \frac{1}{s-a}$$
                            $$\mathcal{L}\{\sin(at)\} = \frac{a}{s^2+a^2}$$
                            $$\mathcal{L}\{\cos(at)\} = \frac{s}{s^2+a^2}$$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Systems of ODEs</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Matrix Form</h4>
                        <div class="math-display">
                            $$\mathbf{x}' = A\mathbf{x} + \mathbf{b}$$
                            
                            Solution: $\mathbf{x}(t) = e^{At}\mathbf{x}_0 + \int_0^t e^{A(t-\tau)}\mathbf{b}(\tau) \, d\tau$
                            
                            Matrix exponential: $e^{At} = \sum_{n=0}^{\infty} \frac{A^n t^n}{n!}$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Eigenvalue Method</h4>
                        <div class="math-display">
                            If $A\mathbf{v} = \lambda\mathbf{v}$, then $\mathbf{x} = \mathbf{v}e^{\lambda t}$ is a solution
                            
                            General solution:
                            $$\mathbf{x} = c_1\mathbf{v}_1e^{\lambda_1 t} + c_2\mathbf{v}_2e^{\lambda_2 t} + \cdots$$
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <section id="linear" class="section">
            <h2>Linear Algebra</h2>
            
            <div class="topic">
                <h3>Matrix Operations & Properties</h3>
                <div class="matrix-grid">
                    <div class="formula-card">
                        <h4>Basic Operations</h4>
                        <div class="math-display">
                            $(AB)C = A(BC)$ - Associative
                            
                            $A(B + C) = AB + AC$ - Distributive
                            
                            $(AB)^T = B^T A^T$
                            
                            $(AB)^{-1} = B^{-1}A^{-1}$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Determinants</h4>
                        <div class="math-display">
                            $\det(AB) = \det(A)\det(B)$
                            
                            $\det(A^T) = \det(A)$
                            
                            $\det(A^{-1}) = \frac{1}{\det(A)}$
                            
                            For $2 \times 2$: $\det\begin{pmatrix}a & b\\c & d\end{pmatrix} = ad - bc$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Matrix Inverse</h4>
                        <div class="math-display">
                            $A^{-1} = \frac{1}{\det(A)} \cdot \text{adj}(A)$
                            
                            For $2 \times 2$: $A^{-1} = \frac{1}{ad-bc}\begin{pmatrix}d & -b\\-c & a\end{pmatrix}$
                            
                            Gauss-Jordan: $[A|I] \rightarrow [I|A^{-1}]$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Vector Spaces & Linear Independence</h3>
                <div class="theorem">
                    <h4>Vector Space Axioms</h4>
                    A vector space $V$ over field $F$ satisfies:
                    <div class="math-display">
                        1. $\mathbf{u} + \mathbf{v} \in V$ (closure under addition)
                        2. $\mathbf{u} + \mathbf{v} = \mathbf{v} + \mathbf{u}$ (commutativity)
                        3. $(\mathbf{u} + \mathbf{v}) + \mathbf{w} = \mathbf{u} + (\mathbf{v} + \mathbf{w})$ (associativity)
                        4. $\exists \mathbf{0} \in V: \mathbf{v} + \mathbf{0} = \mathbf{v}$ (additive identity)
                        5. $\forall \mathbf{v} \exists (-\mathbf{v}): \mathbf{v} + (-\mathbf{v}) = \mathbf{0}$ (additive inverse)
                        6-10. Scalar multiplication axioms
                    </div>
                </div>
                
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Linear Independence</h4>
                        <div class="math-display">
                            Vectors $\mathbf{v}_1, \mathbf{v}_2, \ldots, \mathbf{v}_n$ are linearly independent if:
                            $$c_1\mathbf{v}_1 + c_2\mathbf{v}_2 + \cdots + c_n\mathbf{v}_n = \mathbf{0} \implies c_1 = c_2 = \cdots = c_n = 0$$
                            
                            Matrix form: $A\mathbf{x} = \mathbf{0}$ has only trivial solution
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Basis & Dimension</h4>
                        <div class="math-display">
                            Basis: linearly independent set that spans the space
                            
                            $\dim(V) = $ number of vectors in any basis
                            
                            If $\dim(V) = n$, then any $n$ linearly independent vectors form a basis
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Eigenvalues & Eigenvectors</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Characteristic Equation</h4>
                        <div class="math-display">
                            $$A\mathbf{v} = \lambda\mathbf{v} \quad (\mathbf{v} \neq \mathbf{0})$$
                            
                            Characteristic polynomial: $\det(A - \lambda I) = 0$
                            
                            Eigenspace: $E_{\lambda} = \{\mathbf{v} : A\mathbf{v} = \lambda\mathbf{v}\} = \text{null}(A - \lambda I)$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Diagonalization</h4>
                        <div class="math-display">
                            $$A = PDP^{-1}$$
                            where $D$ is diagonal
                            
                            $P = [\mathbf{v}_1 \, \mathbf{v}_2 \, \cdots \, \mathbf{v}_n]$ (eigenvectors)
                            
                            $D = \text{diag}(\lambda_1, \lambda_2, \ldots, \lambda_n)$ (eigenvalues)
                            
                            $A^k = PD^k P^{-1}$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Properties</h4>
                        <div class="math-display">
                            $$\text{tr}(A) = \lambda_1 + \lambda_2 + \cdots + \lambda_n$$
                            $$\det(A) = \lambda_1 \times \lambda_2 \times \cdots \times \lambda_n$$
                            
                            If $A$ symmetric: all eigenvalues real, eigenvectors orthogonal
                        </div>
                    </div>
                </div>

                <div class="cs-application">
                    <h5>CS Applications:</h5>
                    Google PageRank algorithm, Principal Component Analysis (PCA), computer graphics transformations, quantum computing gates, network analysis
                </div>
            </div>

            <div class="topic">
                <h3>Orthogonality & Least Squares</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Inner Products & Norms</h4>
                        <div class="math-display">
                            $$\langle \mathbf{u}, \mathbf{v} \rangle = \mathbf{u}^T\mathbf{v} = u_1v_1 + u_2v_2 + \cdots + u_nv_n$$
                            
                            $$\|\mathbf{v}\| = \sqrt{\langle \mathbf{v}, \mathbf{v} \rangle} = \sqrt{v_1^2 + v_2^2 + \cdots + v_n^2}$$
                            
                            Cauchy-Schwarz: $|\langle \mathbf{u}, \mathbf{v} \rangle| \leq \|\mathbf{u}\| \|\mathbf{v}\|$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Gram-Schmidt Process</h4>
                        <div class="math-display">
                            $$\mathbf{u}_1 = \mathbf{v}_1$$
                            $$\mathbf{u}_2 = \mathbf{v}_2 - \text{proj}_{\mathbf{u}_1}\mathbf{v}_2$$
                            $$\mathbf{u}_3 = \mathbf{v}_3 - \text{proj}_{\mathbf{u}_1}\mathbf{v}_3 - \text{proj}_{\mathbf{u}_2}\mathbf{v}_3$$
                            
                            where $\text{proj}_{\mathbf{u}}\mathbf{v} = \frac{\langle \mathbf{v}, \mathbf{u} \rangle}{\langle \mathbf{u}, \mathbf{u} \rangle}\mathbf{u}$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Least Squares</h4>
                        <div class="math-display">
                            Normal equation: $A^T A\hat{\mathbf{x}} = A^T\mathbf{b}$
                            
                            Solution: $\hat{\mathbf{x}} = (A^T A)^{-1}A^T\mathbf{b}$
                            
                            If $A$ has orthonormal columns: $\hat{\mathbf{x}} = A^T\mathbf{b}$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Singular Value Decomposition</h3>
                <div class="theorem">
                    <h4>SVD Theorem</h4>
                    Every $m \times n$ matrix $A$ can be written as:
                    <div class="math-display">
                        $$A = U\Sigma V^T$$
                        
                        $U$: $m \times m$ orthogonal (left singular vectors)
                        $\Sigma$: $m \times n$ diagonal (singular values $\sigma_1 \geq \sigma_2 \geq \cdots \geq 0$)
                        $V$: $n \times n$ orthogonal (right singular vectors)
                    </div>
                </div>
                
                <div class="cs-application">
                    <h5>CS Applications:</h5>
                    Image compression, dimensionality reduction, recommender systems, data analysis, pseudoinverse computation
                </div>
            </div>
        </section>

        <section id="discrete" class="section">
            <h2>Discrete Mathematics</h2>
            
            <div class="topic">
                <h3>Logic & Proofs</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Logical Operators</h4>
                        <div class="math-display">
                            $\neg$ (NOT), $\land$ (AND), $\lor$ (OR), $\rightarrow$ (IMPLIES), $\leftrightarrow$ (IFF)
                            
                            De Morgan's Laws:
                            $$\neg(P \land Q) \equiv \neg P \lor \neg Q$$
                            $$\neg(P \lor Q) \equiv \neg P \land \neg Q$$
                            
                            $P \rightarrow Q \equiv \neg P \lor Q$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Quantifiers</h4>
                        <div class="math-display">
                            $\forall x \, P(x)$: "for all $x$, $P(x)$"
                            
                            $\exists x \, P(x)$: "there exists $x$ such that $P(x)$"
                            
                            $$\neg\forall x \, P(x) \equiv \exists x \, \neg P(x)$$
                            $$\neg\exists x \, P(x) \equiv \forall x \, \neg P(x)$$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Proof Techniques</h4>
                        <div class="math-display">
                            Direct proof: $P \rightarrow Q$
                            
                            Contrapositive: $\neg Q \rightarrow \neg P$
                            
                            Contradiction: Assume $\neg Q$ and derive contradiction
                            
                            Induction: Base case + inductive step
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Set Theory</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Set Operations</h4>
                        <div class="math-display">
                            $A \cup B = \{x : x \in A \text{ or } x \in B\}$
                            
                            $A \cap B = \{x : x \in A \text{ and } x \in B\}$
                            
                            $A - B = \{x : x \in A \text{ and } x \notin B\}$
                            
                            $A^c = \{x : x \notin A\}$
                            
                            $|A \cup B| = |A| + |B| - |A \cap B|$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Relations</h4>
                        <div class="math-display">
                            Reflexive: $\forall x \, (x,x) \in R$
                            
                            Symmetric: $\forall x,y \, ((x,y) \in R \rightarrow (y,x) \in R)$
                            
                            Transitive: $\forall x,y,z \, ((x,y) \in R \land (y,z) \in R \rightarrow (x,z) \in R)$
                            
                            Equivalence relation: reflexive + symmetric + transitive
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Functions</h4>
                        <div class="math-display">
                            Injective (one-to-one): $\forall x,y \, (f(x) = f(y) \rightarrow x = y)$
                            
                            Surjective (onto): $\forall y \, \exists x \, (f(x) = y)$
                            
                            Bijective: injective + surjective
                            
                            $|A| = |B|$ iff $\exists$ bijection $f: A \rightarrow B$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Combinatorics</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Counting Principles</h4>
                        <div class="math-display">
                            Addition Principle: $|A \cup B| = |A| + |B|$ if $A \cap B = \emptyset$
                            
                            Multiplication Principle: $|A \times B| = |A| \times |B|$
                            
                            Pigeonhole Principle: If $n$ objects in $m$ boxes and $n > m$, then some box contains $> 1$ object
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Permutations & Combinations</h4>
                        <div class="math-display">
                            $$P(n,r) = \frac{n!}{(n-r)!} \text{ (permutations)}$$
                            
                            $$C(n,r) = \binom{n}{r} = \frac{n!}{r!(n-r)!} \text{ (combinations)}$$
                            
                            Binomial theorem: $(x+y)^n = \sum_{k=0}^n \binom{n}{k} x^k y^{n-k}$
                            
                            Stars and bars: $\binom{n+k-1}{k-1}$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Inclusion-Exclusion</h4>
                        <div class="math-display">
                            $$|A_1 \cup A_2 \cup \cdots \cup A_n| =$$
                            $$\sum |A_i| - \sum |A_i \cap A_j| + \sum |A_i \cap A_j \cap A_k| - \cdots$$
                            $$+ (-1)^{n+1}|A_1 \cap \cdots \cap A_n|$$
                        </div>
                    </div>
                </div>

                <div class="cs-application">
                    <h5>CS Applications:</h5>
                    Algorithm analysis, database query optimization, complexity theory, coding theory, cryptographic protocols
                </div>
            </div>

            <div class="topic">
                <h3>Generating Functions</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Ordinary Generating Functions</h4>
                        <div class="math-display">
                            $$G(x) = \sum_{n=0}^{\infty} a_n x^n = a_0 + a_1x + a_2x^2 + \cdots$$
                            
                            Fibonacci: $F(x) = \frac{x}{1 - x - x^2}$
                            
                            Geometric: $\frac{1}{1-x} = \sum_{n=0}^{\infty} x^n$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Exponential Generating Functions</h4>
                        <div class="math-display">
                            $$E(x) = \sum_{n=0}^{\infty} a_n \frac{x^n}{n!}$$
                            
                            $e^x = \sum_{n=0}^{\infty} \frac{x^n}{n!}$
                            
                            Useful for problems with labels/arrangements
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Recurrence Relations</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Linear Homogeneous</h4>
                        <div class="math-display">
                            $$a_n = c_1a_{n-1} + c_2a_{n-2} + \cdots + c_ka_{n-k}$$
                            
                            Characteristic equation: $r^k - c_1r^{k-1} - \cdots - c_k = 0$
                            
                            If roots distinct: $a_n = A_1r_1^n + A_2r_2^n + \cdots$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Master Theorem</h4>
                        <div class="math-display">
                            For $T(n) = aT(n/b) + f(n)$:
                            
                            Case 1: $f(n) = O(n^{\log_b a - \varepsilon}) \Rightarrow T(n) = \Theta(n^{\log_b a})$
                            
                            Case 2: $f(n) = \Theta(n^{\log_b a}) \Rightarrow T(n) = \Theta(n^{\log_b a} \log n)$
                            
                            Case 3: $f(n) = \Omega(n^{\log_b a + \varepsilon}) \Rightarrow T(n) = \Theta(f(n))$
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <section id="probability" class="section">
            <h2>Probability & Statistics</h2>
            
            <div class="topic">
                <h3>Probability Theory</h3>
                <div class="stats-grid">
                    <div class="formula-card">
                        <h4>Basic Probability</h4>
                        <div class="math-display">
                            $$P(A \cup B) = P(A) + P(B) - P(A \cap B)$$
                            $$P(A^c) = 1 - P(A)$$
                            $$P(A|B) = \frac{P(A \cap B)}{P(B)}$$
                            
                            Independence: $P(A \cap B) = P(A)P(B)$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Bayes' Theorem</h4>
                        <div class="math-display">
                            $$P(A|B) = \frac{P(B|A)P(A)}{P(B)}$$
                            
                            Law of Total Probability:
                            $$P(B) = \sum_i P(B|A_i)P(A_i)$$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Random Variables</h4>
                        <div class="math-display">
                            $$E[X] = \sum_x x \cdot P(X = x) \text{ (discrete)}$$
                            $$E[X] = \int_{-\infty}^{\infty} x \cdot f(x) \, dx \text{ (continuous)}$$
                            
                            $\text{Var}(X) = E[X^2] - (E[X])^2$
                            
                            $\text{Var}(aX + b) = a^2\text{Var}(X)$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Common Distributions</h3>
                <div class="stats-grid">
                    <div class="formula-card">
                        <h4>Discrete Distributions</h4>
                        <div class="math-display">
                            Bernoulli: $P(X = 1) = p$, $P(X = 0) = 1-p$
                            
                            Binomial: $P(X = k) = \binom{n}{k}p^k(1-p)^{n-k}$
                            $E[X] = np$, $\text{Var}(X) = np(1-p)$
                            
                            Poisson: $P(X = k) = \frac{\lambda^k e^{-\lambda}}{k!}$
                            $E[X] = \text{Var}(X) = \lambda$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Continuous Distributions</h4>
                        <div class="math-display">
                            Uniform: $f(x) = \frac{1}{b-a}$ for $x \in [a,b]$
                            $E[X] = \frac{a+b}{2}$, $\text{Var}(X) = \frac{(b-a)^2}{12}$
                            
                            Normal: $f(x) = \frac{1}{\sigma\sqrt{2\pi}}e^{-\frac{(x-\mu)^2}{2\sigma^2}}$
                            $E[X] = \mu$, $\text{Var}(X) = \sigma^2$
                            
                            Exponential: $f(x) = \lambda e^{-\lambda x}$ for $x \geq 0$
                            $E[X] = \frac{1}{\lambda}$, $\text{Var}(X) = \frac{1}{\lambda^2}$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Central Limit Theorem</h4>
                        <div class="math-display">
                            If $X_1, X_2, \ldots, X_n$ are i.i.d. with $E[X_i] = \mu$, $\text{Var}(X_i) = \sigma^2$:
                            
                            $$\frac{\bar{X} - \mu}{\sigma/\sqrt{n}} \xrightarrow{d} N(0,1) \text{ as } n \to \infty$$
                            
                            where $\bar{X} = \frac{1}{n}\sum_{i=1}^n X_i$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Statistical Inference</h3>
                <div class="stats-grid">
                    <div class="formula-card">
                        <h4>Confidence Intervals</h4>
                        <div class="math-display">
                            For mean $\mu$ ($\sigma$ known):
                            $$\bar{x} \pm z_{\alpha/2} \times \frac{\sigma}{\sqrt{n}}$$
                            
                            For mean $\mu$ ($\sigma$ unknown):
                            $$\bar{x} \pm t_{\alpha/2,n-1} \times \frac{s}{\sqrt{n}}$$
                            
                            For proportion $p$:
                            $$\hat{p} \pm z_{\alpha/2} \times \sqrt{\frac{\hat{p}(1-\hat{p})}{n}}$$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Hypothesis Testing</h4>
                        <div class="math-display">
                            Test statistic for mean:
                            $$z = \frac{\bar{x} - \mu_0}{\sigma/\sqrt{n}} \text{ or } t = \frac{\bar{x} - \mu_0}{s/\sqrt{n}}$$
                            
                            p-value = P(observing test statistic or more extreme | $H_0$)
                            
                            Reject $H_0$ if p-value $< \alpha$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Regression</h4>
                        <div class="math-display">
                            Simple linear: $\hat{y} = a + bx$
                            
                            $$b = \frac{\sum (x_i - \bar{x})(y_i - \bar{y})}{\sum (x_i - \bar{x})^2}$$
                            $$a = \bar{y} - b\bar{x}$$
                            
                            $R^2 = 1 - \frac{SSE}{SST}$ (coefficient of determination)
                        </div>
                    </div>
                </div>

                <div class="cs-application">
                    <h5>CS Applications:</h5>
                    Machine learning algorithms, A/B testing, data mining, quality assurance, performance analysis, randomized algorithms
                </div>
            </div>
        </section>

        <section id="numerical" class="section">
            <h2>Numerical Analysis</h2>
            
            <div class="topic">
                <h3>Root Finding</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Bisection Method</h4>
                        <div class="math-display">
                            If $f(a)f(b) < 0$, then $\exists c \in (a,b): f(c) = 0$
                            
                            Algorithm:
                            1. $c = \frac{a + b}{2}$
                            2. If $f(a)f(c) < 0$: $b = c$, else $a = c$
                            3. Repeat until $|b - a| < $ tolerance
                            
                            Convergence: $O(\log_2((b-a)/\varepsilon))$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Newton's Method</h4>
                        <div class="math-display">
                            $$x_{n+1} = x_n - \frac{f(x_n)}{f'(x_n)}$$
                            
                            Quadratic convergence when $f'(\text{root}) \neq 0$
                            
                            May fail if $f'(x_n) \approx 0$ or poor initial guess
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Secant Method</h4>
                        <div class="math-display">
                            $$x_{n+1} = x_n - f(x_n)\frac{x_n - x_{n-1}}{f(x_n) - f(x_{n-1})}$$
                            
                            Approximates derivative using secant line
                            
                            Superlinear convergence: $\varphi = \frac{1+\sqrt{5}}{2} \approx 1.618$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Interpolation</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Lagrange Interpolation</h4>
                        <div class="math-display">
                            $$P(x) = \sum_{i=0}^n y_i L_i(x)$$
                            
                            where $L_i(x) = \prod_{j=0, j \neq i}^n \frac{x - x_j}{x_i - x_j}$
                            
                            Unique polynomial of degree $\leq n$ through $n+1$ points
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Newton's Divided Differences</h4>
                        <div class="math-display">
                            $$P(x) = f[x_0] + f[x_0,x_1](x-x_0) + f[x_0,x_1,x_2](x-x_0)(x-x_1) + \cdots$$
                            
                            $f[x_i,x_{i+1}] = \frac{f[x_{i+1}] - f[x_i]}{x_{i+1} - x_i}$
                            
                            More efficient for adding new points
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Spline Interpolation</h4>
                        <div class="math-display">
                            Cubic spline: $S(x) = a_i + b_i(x-x_i) + c_i(x-x_i)^2 + d_i(x-x_i)^3$
                            
                            Conditions:
                            - $S(x_i) = y_i$
                            - $S'(x_i^-) = S'(x_i^+)$
                            - $S''(x_i^-) = S''(x_i^+)$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Numerical Integration</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Composite Rules</h4>
                        <div class="math-display">
                            Composite Trapezoidal:
                            $$\int_a^b f(x)\,dx \approx \frac{h}{2}[f(x_0) + 2f(x_1) + \cdots + 2f(x_{n-1}) + f(x_n)]$$
                            Error: $O(h^2)$
                            
                            Composite Simpson's:
                            $$\int_a^b f(x)\,dx \approx \frac{h}{3}[f(x_0) + 4f(x_1) + 2f(x_2) + 4f(x_3) + \cdots + f(x_n)]$$
                            Error: $O(h^4)$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Gaussian Quadrature</h4>
                        <div class="math-display">
                            $$\int_{-1}^1 f(x)\,dx \approx \sum_{i=1}^n w_i f(x_i)$$
                            
                            Optimal choice of points $x_i$ and weights $w_i$
                            
                            $n$-point Gauss rule exact for polynomials of degree $\leq 2n-1$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Ordinary Differential Equations</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Euler's Method</h4>
                        <div class="math-display">
                            $$y_{n+1} = y_n + h \cdot f(x_n, y_n)$$
                            
                            First-order accuracy: $O(h)$
                            
                            Simple but may be unstable for large $h$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Runge-Kutta Methods</h4>
                        <div class="math-display">
                            RK4 (Fourth-order):
                            $$k_1 = hf(x_n, y_n)$$
                            $$k_2 = hf(x_n + h/2, y_n + k_1/2)$$
                            $$k_3 = hf(x_n + h/2, y_n + k_2/2)$$
                            $$k_4 = hf(x_n + h, y_n + k_3)$$
                            
                            $$y_{n+1} = y_n + \frac{k_1 + 2k_2 + 2k_3 + k_4}{6}$$
                        </div>
                    </div>
                </div>

                <div class="cs-application">
                    <h5>CS Applications:</h5>
                    Computer graphics (ray tracing), scientific computing, game physics, signal processing, finite element analysis
                </div>
            </div>
        </section>

        <section id="complex" class="section">
            <h2>Complex Analysis</h2>
            
            <div class="topic">
                <h3>Complex Numbers</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Basic Operations</h4>
                        <div class="math-display">
                            $$z = x + iy = re^{i\theta} = r(\cos\theta + i\sin\theta)$$
                            
                            $|z| = \sqrt{x^2 + y^2} = r$
                            
                            $\arg(z) = \theta = \arctan(y/x)$
                            
                            $z^* = x - iy = re^{-i\theta}$ (complex conjugate)
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Polar Form</h4>
                        <div class="math-display">
                            $$z_1z_2 = r_1r_2e^{i(\theta_1+\theta_2)}$$
                            $$\frac{z_1}{z_2} = \frac{r_1}{r_2}e^{i(\theta_1-\theta_2)}$$
                            
                            De Moivre's theorem: $z^n = r^n e^{in\theta}$
                            
                            $n$th roots: $z^{1/n} = r^{1/n} e^{i(\theta+2\pi k)/n}$, $k = 0,1,\ldots,n-1$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Analytic Functions</h3>
                <div class="theorem">
                    <h4>Cauchy-Riemann Equations</h4>
                    If $f(z) = u(x,y) + iv(x,y)$ is analytic:
                    <div class="math-display">
                        $$\frac{\partial u}{\partial x} = \frac{\partial v}{\partial y}$$
                        $$\frac{\partial u}{\partial y} = -\frac{\partial v}{\partial x}$$
                    </div>
                </div>
                
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Elementary Functions</h4>
                        <div class="math-display">
                            $$e^z = e^x(\cos y + i\sin y)$$
                            
                            $$\sin z = \frac{e^{iz} - e^{-iz}}{2i}$$
                            $$\cos z = \frac{e^{iz} + e^{-iz}}{2}$$
                            
                            $\log z = \ln|z| + i(\arg z + 2\pi n)$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Power Series</h4>
                        <div class="math-display">
                            $$f(z) = \sum_{n=0}^{\infty} a_n(z - z_0)^n$$
                            
                            Radius of convergence: $R = \frac{1}{\limsup_{n \to \infty} |a_n|^{1/n}}$
                            
                            Convergent for $|z - z_0| < R$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Integration & Residues</h3>
                <div class="theorem">
                    <h4>Cauchy's Theorem</h4>
                    If $f$ is analytic in simply connected domain $D$ and $C$ is a closed curve in $D$:
                    <div class="math-display">
                        $$\oint_C f(z) \, dz = 0$$
                    </div>
                </div>

                <div class="theorem">
                    <h4>Residue Theorem</h4>
                    <div class="math-display">
                        $$\oint_C f(z) \, dz = 2\pi i \sum_k \text{Res}(f, z_k)$$
                    </div>
                    where $z_k$ are poles inside $C$
                </div>
                
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Computing Residues</h4>
                        <div class="math-display">
                            Simple pole at $z_0$:
                            $$\text{Res}(f, z_0) = \lim_{z \to z_0} (z - z_0)f(z)$$
                            
                            Pole of order $n$:
                            $$\text{Res}(f, z_0) = \frac{1}{(n-1)!} \lim_{z \to z_0} \frac{d^{n-1}}{dz^{n-1}}[(z-z_0)^n f(z)]$$
                        </div>
                    </div>
                </div>

                <div class="cs-application">
                    <h5>CS Applications:</h5>
                    Signal processing (Fourier transforms), control systems, quantum computing, computer graphics (fractals), digital filters
                </div>
            </div>
        </section>

        <section id="graph" class="section">
            <h2>Graph Theory</h2>
            
            <div class="topic">
                <h3>Basic Definitions</h3>
                <div class="graph-theory-grid">
                    <div class="formula-card">
                        <h4>Graph Properties</h4>
                        <div class="math-display">
                            Graph $G = (V, E)$ where $V =$ vertices, $E =$ edges
                            
                            Order: $|V|$ (number of vertices)
                            Size: $|E|$ (number of edges)
                            
                            Degree: $\deg(v) = $ number of edges incident to $v$
                            
                            Handshaking lemma: $\sum_{v \in V} \deg(v) = 2|E|$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Special Graphs</h4>
                        <div class="math-display">
                            Complete graph $K_n$: $|E| = \frac{n(n-1)}{2}$
                            
                            Complete bipartite $K_{m,n}$: $|E| = mn$
                            
                            Cycle $C_n$: $n$ vertices, $n$ edges
                            
                            Path $P_n$: $n$ vertices, $n-1$ edges
                            
                            Tree: connected, acyclic, $|E| = |V| - 1$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Matrix Representations</h4>
                        <div class="math-display">
                            Adjacency matrix $A$: $A[i,j] = 1$ if edge $(i,j)$ exists
                            
                            Incidence matrix: rows = vertices, columns = edges
                            
                            Number of walks of length $k$ from $i$ to $j$: $(A^k)[i,j]$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Connectivity</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Paths & Cycles</h4>
                        <div class="math-display">
                            Walk: sequence of vertices $v_0, v_1, \ldots, v_k$
                            
                            Trail: walk with distinct edges
                            
                            Path: walk with distinct vertices
                            
                            Connected: path exists between any two vertices
                            
                            Distance $d(u,v)$: length of shortest path from $u$ to $v$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Euler & Hamilton</h4>
                        <div class="math-display">
                            Eulerian path: uses every edge exactly once
                            Exists iff graph connected and $\leq 2$ odd-degree vertices
                            
                            Eulerian cycle: closed Eulerian path
                            Exists iff graph connected and all vertices even degree
                            
                            Hamiltonian path: visits every vertex exactly once
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Trees & Spanning Trees</h3>
                <div class="theorem">
                    <h4>Tree Properties</h4>
                    For a graph $G$ with $n$ vertices, these are equivalent:
                    <div class="math-display">
                        1. $G$ is a tree
                        2. $G$ is connected and has $n-1$ edges
                        3. $G$ is acyclic and has $n-1$ edges
                        4. $G$ is connected and removing any edge disconnects it
                        5. $G$ is acyclic and adding any edge creates exactly one cycle
                    </div>
                </div>
                
                <div class="algorithm-box">
                    <h5>Kruskal's Algorithm (Minimum Spanning Tree)</h5>
                    <div class="code-block">
                        1. Sort edges by weight
                        2. Initialize disjoint sets for each vertex
                        3. For each edge (u,v):
                           - If u and v in different components:
                             - Add edge to MST
                             - Union components of u and v
                        4. Stop when n-1 edges added
                        
                        Time complexity: O(E log E)
                    </div>
                </div>
                
                <div class="algorithm-box">
                    <h5>Prim's Algorithm</h5>
                    <div class="code-block">
                        1. Start with arbitrary vertex
                        2. Maintain priority queue of edges from current tree
                        3. Repeatedly add minimum weight edge that connects
                           tree to new vertex
                        4. Update priority queue
                        
                        Time complexity: O(E log V) with binary heap
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Shortest Paths</h3>
                <div class="algorithm-box">
                    <h5>Dijkstra's Algorithm</h5>
                    <div class="code-block">
                        1. Initialize distances: d[source] = 0, d[v] = ∞ for v ≠ source
                        2. Priority queue Q with all vertices
                        3. While Q not empty:
                           - u = extract minimum from Q
                           - For each neighbor v of u:
                             - If d[u] + weight(u,v) < d[v]:
                               - d[v] = d[u] + weight(u,v)
                               - parent[v] = u
                        
                        Time: O((V + E) log V) with binary heap
                        Requirements: non-negative weights
                    </div>
                </div>
                
                <div class="algorithm-box">
                    <h5>Bellman-Ford Algorithm</h5>
                    <div class="code-block">
                        1. Initialize distances: d[source] = 0, d[v] = ∞ for v ≠ source
                        2. For i = 1 to |V| - 1:
                           - For each edge (u,v):
                             - If d[u] + weight(u,v) < d[v]:
                               - d[v] = d[u] + weight(u,v)
                        3. Check for negative cycles
                        
                        Time: O(VE)
                        Handles negative weights
                    </div>
                </div>
                
                <div class="algorithm-box">
                    <h5>Floyd-Warshall Algorithm</h5>
                    <div class="code-block">
                        1. Initialize distance matrix D
                        2. For k = 1 to n:
                           - For i = 1 to n:
                             - For j = 1 to n:
                               - D[i][j] = min(D[i][j], D[i][k] + D[k][j])
                        
                        Time: O(V³)
                        Finds all-pairs shortest paths
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Network Flow</h3>
                <div class="theorem">
                    <h4>Max-Flow Min-Cut Theorem</h4>
                    In any flow network, the maximum value of flow equals the minimum capacity of all cuts.
                </div>
                
                <div class="algorithm-box">
                    <h5>Ford-Fulkerson Method</h5>
                    <div class="code-block">
                        1. Initialize flow f = 0
                        2. While there exists augmenting path P from source to sink:
                           - Find bottleneck capacity c along P
                           - Augment flow along P by c
                           - Update residual graph
                        3. Return maximum flow
                        
                        Time: O(E × max_flow) for integer capacities
                        With Edmonds-Karp (BFS): O(VE²)
                    </div>
                </div>

                <div class="cs-application">
                    <h5>CS Applications:</h5>
                    Social networks, internet routing, database optimization, compiler optimization, bioinformatics, recommendation systems
                </div>
            </div>

            <div class="topic">
                <h3>Graph Coloring</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Chromatic Number</h4>
                        <div class="math-display">
                            $\chi(G) = $ minimum number of colors needed
                            
                            $\chi(K_n) = n$
                            
                            $\chi(C_n) = 2$ if $n$ even, $3$ if $n$ odd
                            
                            $\chi(\text{bipartite graph}) = 2$
                            
                            Four Color Theorem: $\chi(\text{planar graph}) \leq 4$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Greedy Coloring</h4>
                        <div class="math-display">
                            Brooks' Theorem: If $G$ connected, not complete, not odd cycle, then $\chi(G) \leq \Delta(G)$
                            
                            where $\Delta(G) = $ maximum degree
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <section id="number" class="section">
            <h2>Number Theory</h2>
            
            <div class="topic">
                <h3>Divisibility & GCD</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Division Algorithm</h4>
                        <div class="math-display">
                            For integers $a, b$ with $b > 0$:
                            $$a = qb + r \text{ where } 0 \leq r < b$$
                            
                            $q = $ quotient, $r = $ remainder
                            
                            $a \equiv r \pmod{b}$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Euclidean Algorithm</h4>
                        <div class="math-display">
                            $$\gcd(a, b) = \gcd(b, a \bmod b)$$
                            
                            Extended Euclidean Algorithm:
                            $$\gcd(a, b) = ax + by$$
                            for some integers $x, y$
                            
                            Time complexity: $O(\log \min(a, b))$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Properties</h4>
                        <div class="math-display">
                            $$\gcd(a, b) \times \text{lcm}(a, b) = ab$$
                            
                            If $\gcd(a, n) = 1$ and $\gcd(b, n) = 1$,
                            then $\gcd(ab, n) = 1$
                            
                            Bézout's identity: $\gcd(a, b) = ax + by$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Modular Arithmetic</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Congruences</h4>
                        <div class="math-display">
                            $a \equiv b \pmod{n}$ iff $n \mid (a - b)$
                            
                            Properties:
                            $(a + b) \bmod n = ((a \bmod n) + (b \bmod n)) \bmod n$
                            
                            $(a \times b) \bmod n = ((a \bmod n) \times (b \bmod n)) \bmod n$
                            
                            Reflexive: $a \equiv a \pmod{n}$
                            Symmetric: $a \equiv b \implies b \equiv a \pmod{n}$
                            Transitive: $a \equiv b, b \equiv c \implies a \equiv c \pmod{n}$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Modular Inverse</h4>
                        <div class="math-display">
                            $a^{-1} \pmod{n}$ exists iff $\gcd(a, n) = 1$
                            
                            Finding inverse: use Extended Euclidean Algorithm
                            $ax + ny = 1 \implies ax \equiv 1 \pmod{n} \implies a^{-1} \equiv x \pmod{n}$
                            
                            Fermat's Little Theorem: If $p$ prime, $\gcd(a, p) = 1$:
                            $$a^{-1} \equiv a^{p-2} \pmod{p}$$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Prime Numbers</h3>
                <div class="theorem">
                    <h4>Fundamental Theorem of Arithmetic</h4>
                    Every integer $n > 1$ has a unique prime factorization:
                    <div class="math-display">
                        $$n = p_1^{a_1} \times p_2^{a_2} \times \cdots \times p_k^{a_k}$$
                    </div>
                    where $p_1 < p_2 < \cdots < p_k$ are primes and $a_i > 0$
                </div>
                
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Prime Testing</h4>
                        <div class="math-display">
                            Trial division: test divisibility up to $\sqrt{n}$
                            Time: $O(\sqrt{n})$
                            
                            Sieve of Eratosthenes: find all primes $\leq n$
                            Time: $O(n \log \log n)$
                            
                            Miller-Rabin: probabilistic primality test
                            Time: $O(k \log^3 n)$ for $k$ rounds
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Prime Distribution</h4>
                        <div class="math-display">
                            Prime Number Theorem:
                            $$\pi(n) \approx \frac{n}{\ln(n)}$$
                            
                            where $\pi(n) = $ number of primes $\leq n$
                            
                            There are infinitely many primes
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Euler's Function</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Definition & Properties</h4>
                        <div class="math-display">
                            $$\varphi(n) = |\{k : 1 \leq k \leq n, \gcd(k, n) = 1\}|$$
                            
                            $\varphi(p) = p - 1$ for prime $p$
                            
                            $\varphi(p^k) = p^k - p^{k-1} = p^{k-1}(p - 1)$
                            
                            If $\gcd(m, n) = 1$: $\varphi(mn) = \varphi(m)\varphi(n)$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Euler's Theorem</h4>
                        <div class="math-display">
                            If $\gcd(a, n) = 1$, then:
                            $$a^{\varphi(n)} \equiv 1 \pmod{n}$$
                            
                            Fermat's Little Theorem (special case):
                            If $p$ prime and $\gcd(a, p) = 1$:
                            $$a^{p-1} \equiv 1 \pmod{p}$$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Chinese Remainder Theorem</h3>
                <div class="theorem">
                    <h4>CRT Statement</h4>
                    If $n_1, n_2, \ldots, n_k$ are pairwise coprime, then the system:
                    <div class="math-display">
                        $$\begin{cases}
                        x \equiv a_1 \pmod{n_1} \\
                        x \equiv a_2 \pmod{n_2} \\
                        \vdots \\
                        x \equiv a_k \pmod{n_k}
                        \end{cases}$$
                    </div>
                    has a unique solution modulo $N = n_1n_2 \cdots n_k$
                </div>
                
                <div class="algorithm-box">
                    <h5>CRT Algorithm</h5>
                    <div class="code-block">
                        1. Compute N = n₁n₂...nₖ
                        2. For each i, compute Nᵢ = N/nᵢ
                        3. Find Mᵢ such that NᵢMᵢ ≡ 1 (mod nᵢ)
                        4. Solution: x ≡ Σ aᵢNᵢMᵢ (mod N)
                    </div>
                </div>

                <div class="cs-application">
                    <h5>CS Applications:</h5>
                    Cryptography (RSA, ElGamal), hash functions, pseudorandom number generation, error-correcting codes, computer algebra
                </div>
            </div>
        </section>

        <section id="algorithms" class="section">
            <h2>Algorithm Analysis</h2>
            
            <div class="topic">
                <h3>Asymptotic Notation</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Big O Notation</h4>
                        <div class="math-display">
                            $f(n) = O(g(n))$ if $\exists c > 0, n_0$ such that
                            $f(n) \leq c \cdot g(n)$ for all $n \geq n_0$
                            
                            Upper bound: $f$ grows no faster than $g$
                            
                            $f(n) = \Omega(g(n))$ if $g(n) = O(f(n))$
                            Lower bound: $f$ grows at least as fast as $g$
                            
                            $f(n) = \Theta(g(n))$ if $f(n) = O(g(n))$ and $f(n) = \Omega(g(n))$
                            Tight bound: $f$ and $g$ grow at same rate
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Common Complexities</h4>
                        <div class="math-display">
                            $$O(1) < O(\log n) < O(n) < O(n \log n) < O(n^2) < O(n^3) < O(2^n) < O(n!)$$
                            
                            Logarithmic: binary search, balanced tree operations
                            Linear: linear search, single loop
                            Linearithmic: merge sort, heap sort
                            Quadratic: nested loops, simple sorting
                            Exponential: brute force subsets
                            Factorial: brute force permutations
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Sorting Algorithms</h3>
                
                <table class="complexity-table">
                    <thead>
                        <tr>
                            <th>Algorithm</th>
                            <th>Best Case</th>
                            <th>Average Case</th>
                            <th>Worst Case</th>
                            <th>Space</th>
                            <th>Stable</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>Bubble Sort</td>
                            <td>O(n)</td>
                            <td>O(n²)</td>
                            <td>O(n²)</td>
                            <td>O(1)</td>
                            <td>Yes</td>
                        </tr>
                        <tr>
                            <td>Selection Sort</td>
                            <td>O(n²)</td>
                            <td>O(n²)</td>
                            <td>O(n²)</td>
                            <td>O(1)</td>
                            <td>No</td>
                        </tr>
                        <tr>
                            <td>Insertion Sort</td>
                            <td>O(n)</td>
                            <td>O(n²)</td>
                            <td>O(n²)</td>
                            <td>O(1)</td>
                            <td>Yes</td>
                        </tr>
                        <tr>
                            <td>Merge Sort</td>
                            <td>O(n log n)</td>
                            <td>O(n log n)</td>
                            <td>O(n log n)</td>
                            <td>O(n)</td>
                            <td>Yes</td>
                        </tr>
                        <tr>
                            <td>Quick Sort</td>
                            <td>O(n log n)</td>
                            <td>O(n log n)</td>
                            <td>O(n²)</td>
                            <td>O(log n)</td>
                            <td>No</td>
                        </tr>
                        <tr>
                            <td>Heap Sort</td>
                            <td>O(n log n)</td>
                            <td>O(n log n)</td>
                            <td>O(n log n)</td>
                            <td>O(1)</td>
                            <td>No</td>
                        </tr>
                        <tr>
                            <td>Counting Sort</td>
                            <td>O(n + k)</td>
                            <td>O(n + k)</td>
                            <td>O(n + k)</td>
                            <td>O(k)</td>
                            <td>Yes</td>
                        </tr>
                        <tr>
                            <td>Radix Sort</td>
                            <td>O(d(n + k))</td>
                            <td>O(d(n + k))</td>
                            <td>O(d(n + k))</td>
                            <td>O(n + k)</td>
                            <td>Yes</td>
                        </tr>
                    </tbody>
                </table>
            </div>

            <div class="topic">
                <h3>Search Algorithms</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Binary Search</h4>
                        <div class="math-display">
                            Prerequisite: sorted array
                            
                            Algorithm:
                            ```
                            while low ≤ high:
                                mid = (low + high) / 2
                                if arr[mid] == target: return mid
                                elif arr[mid] < target: low = mid + 1
                                else: high = mid - 1
                            ```
                            
                            Time: $O(\log n)$, Space: $O(1)$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Hash Table Search</h4>
                        <div class="math-display">
                            Average case: $O(1)$ for search, insert, delete
                            Worst case: $O(n)$ if many collisions
                            
                            Load factor $\alpha = \frac{n}{m}$ (items/buckets)
                            Keep $\alpha < 0.75$ for good performance
                            
                            Collision resolution: chaining, open addressing
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Dynamic Programming</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Optimal Substructure</h4>
                        <div class="math-display">
                            A problem has optimal substructure if optimal solution contains optimal solutions to subproblems
                            
                            Examples: shortest paths, matrix chain multiplication, optimal binary search trees, edit distance
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Overlapping Subproblems</h4>
                        <div class="math-display">
                            Recursive algorithm solves same subproblems repeatedly
                            
                            Memoization: top-down approach, store results
                            Tabulation: bottom-up approach, fill table
                            
                            Fibonacci: naive $O(2^n)$, DP $O(n)$
                        </div>
                    </div>
                </div>
                
                <div class="algorithm-box">
                    <h5>Classic DP Problems</h5>
                    <div class="code-block">
                        Knapsack Problem: max value with weight constraint
                        DP[i][w] = max value using first i items, weight ≤ w
                        
                        Longest Common Subsequence:
                        LCS[i][j] = length of LCS of first i chars of X, first j chars of Y
                        
                        Edit Distance (Levenshtein):
                        ED[i][j] = min operations to transform X[1..i] to Y[1..j]
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Greedy Algorithms</h3>
                <div class="important">
                    <h5>Greedy Choice Property</h5>
                    Global optimum can be reached by making locally optimal choices at each step
                </div>
                
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Activity Selection</h4>
                        <div class="math-display">
                            Select maximum number of non-overlapping activities
                            
                            Greedy strategy: sort by finish time, always pick earliest finishing activity
                            
                            Time: $O(n \log n)$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Huffman Coding</h4>
                        <div class="math-display">
                            Optimal prefix-free binary codes
                            
                            Greedy strategy: repeatedly merge two nodes with minimum frequency
                            
                            Time: $O(n \log n)$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Complexity Classes</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>P vs NP</h4>
                        <div class="math-display">
                            P: problems solvable in polynomial time
                            NP: problems verifiable in polynomial time
                            NP-Complete: hardest problems in NP
                            NP-Hard: at least as hard as NP-Complete
                            
                            $P \subseteq NP$, but $P = NP$? is open question
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Reduction</h4>
                        <div class="math-display">
                            Problem $A$ reduces to $B$ ($A \leq_p B$) if $A$ can be solved using polynomial number of calls to $B$
                            
                            If $A \leq_p B$ and $B \in P$, then $A \in P$
                            
                            Used to prove NP-completeness
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <section id="crypto" class="section">
            <h2>Cryptography</h2>
            
            <div class="topic">
                <h3>Classical Cryptography</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Caesar Cipher</h4>
                        <div class="math-display">
                            Encryption: $E(x) = (x + k) \bmod 26$
                            Decryption: $D(y) = (y - k) \bmod 26$
                            
                            Key space: 26 possible keys
                            Vulnerable to frequency analysis
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Affine Cipher</h4>
                        <div class="math-display">
                            Encryption: $E(x) = (ax + b) \bmod 26$
                            Decryption: $D(y) = a^{-1}(y - b) \bmod 26$
                            
                            Requirement: $\gcd(a, 26) = 1$
                            Key space: $\varphi(26) \times 26 = 12 \times 26 = 312$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Vigenère Cipher</h4>
                        <div class="math-display">
                            Encryption: $C_i = (M_i + K_{i \bmod \text{keylen}}) \bmod 26$
                            
                            Polyalphabetic substitution
                            
                            Broken by Kasiski examination and index of coincidence
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Public Key Cryptography</h3>
                <div class="theorem">
                    <h4>RSA Algorithm</h4>
                    <div class="math-display">
                        Key Generation:
                        1. Choose large primes $p, q$
                        2. $n = pq$, $\varphi(n) = (p-1)(q-1)$
                        3. Choose $e$: $\gcd(e, \varphi(n)) = 1$
                        4. Find $d$: $ed \equiv 1 \pmod{\varphi(n)}$
                        
                        Public key: $(n, e)$
                        Private key: $(n, d)$
                        
                        Encryption: $C = M^e \bmod n$
                        Decryption: $M = C^d \bmod n$
                    </div>
                </div>
                
                <div class="proof-sketch">
                    <strong>Why RSA works:</strong> By Euler's theorem, if $\gcd(M, n) = 1$, then $M^{\varphi(n)} \equiv 1 \pmod{n}$. 
                    Since $ed \equiv 1 \pmod{\varphi(n)}$, we have $ed = 1 + k\varphi(n)$ for some $k$. 
                    Therefore: $(M^e)^d = M^{ed} = M^{1+k\varphi(n)} = M \cdot (M^{\varphi(n)})^k \equiv M \cdot 1^k = M \pmod{n}$
                </div>
                
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Diffie-Hellman Key Exchange</h4>
                        <div class="math-display">
                            Public: prime $p$, generator $g$
                            
                            Alice: chooses $a$, sends $g^a \bmod p$
                            Bob: chooses $b$, sends $g^b \bmod p$
                            
                            Shared secret: $K = g^{ab} \bmod p$
                            
                            Security based on discrete log problem
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>ElGamal Encryption</h4>
                        <div class="math-display">
                            Key Generation:
                            Choose prime $p$, generator $g$, private key $x$
                            Public key: $y = g^x \bmod p$
                            
                            Encryption of $M$:
                            Choose random $k$, send $(g^k \bmod p, M \cdot y^k \bmod p)$
                            
                            Decryption: $M = c_2 \cdot (c_1^x)^{-1} \bmod p$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Hash Functions</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Properties</h4>
                        <div class="math-display">
                            Pre-image resistance: given $h$, hard to find $x$ with $H(x) = h$
                            
                            Second pre-image resistance: given $x$, hard to find $x' \neq x$ with $H(x) = H(x')$
                            
                            Collision resistance: hard to find $x, x'$ with $H(x) = H(x')$
                            
                            Birthday paradox: expect collision after $\sqrt{2^n}$ inputs for $n$-bit hash
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Applications</h4>
                        <div class="math-display">
                            Digital signatures: sign hash instead of message
                            
                            Password storage: store $H(\text{password} + \text{salt})$
                            
                            Proof of work: find nonce with $H(\text{block} + \text{nonce}) < \text{target}$
                            
                            Data integrity: compare hash values
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Digital Signatures</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>RSA Signatures</h4>
                        <div class="math-display">
                            Signing: $S = H(M)^d \bmod n$
                            
                            Verification: check if $S^e \equiv H(M) \pmod{n}$
                            
                            Must use padding (PSS) to prevent attacks
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>DSA (Digital Signature Algorithm)</h4>
                        <div class="math-display">
                            Parameters: prime $p$, $q \mid (p-1)$, generator $g$
                            Private key: $x$, Public key: $y = g^x \bmod p$
                            
                            Signing $M$:
                            $k = $ random, $r = (g^k \bmod p) \bmod q$
                            $s = k^{-1}(H(M) + xr) \bmod q$
                            Signature: $(r, s)$
                            
                            Verification: check if $r = ((g^{H(M)s^{-1}} \cdot y^{rs^{-1}}) \bmod p) \bmod q$
                        </div>
                    </div>
                </div>

                <div class="cs-application">
                    <h5>CS Applications:</h5>
                    Secure communications, blockchain technology, password authentication, digital certificates, software signing, cryptocurrency
                </div>
            </div>
        </section>

        <section id="optimization" class="section">
            <h2>Optimization</h2>
            
            <div class="topic">
                <h3>Linear Programming</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Standard Form</h4>
                        <div class="math-display">
                            Minimize: $\mathbf{c}^T \mathbf{x}$
                            Subject to: $A\mathbf{x} = \mathbf{b}$, $\mathbf{x} \geq \mathbf{0}$
                            
                            Can convert any LP to standard form:
                            - $\max f \rightarrow \min(-f)$
                            - inequality $\rightarrow$ equality (add slack variables)
                            - unrestricted variable $\rightarrow$ difference of non-negative variables
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Simplex Method</h4>
                        <div class="math-display">
                            1. Start at basic feasible solution (vertex of polytope)
                            2. Check optimality conditions
                            3. If not optimal, move to adjacent vertex that improves objective
                            4. Repeat until optimal or unbounded
                            
                            Worst case: exponential
                            Average case: polynomial
                        </div>
                    </div>
                </div>
                
                <div class="theorem">
                    <h4>Fundamental Theorem of Linear Programming</h4>
                    If LP has optimal solution, then it has optimal basic feasible solution (vertex of feasible region)
                </div>
                
                <div class="theorem">
                    <h4>Duality Theorem</h4>
                    <div class="math-display">
                        Primal: $\min \mathbf{c}^T \mathbf{x}$ subject to $A\mathbf{x} \geq \mathbf{b}$, $\mathbf{x} \geq \mathbf{0}$
                        
                        Dual: $\max \mathbf{b}^T \mathbf{y}$ subject to $A^T \mathbf{y} \leq \mathbf{c}$, $\mathbf{y} \geq \mathbf{0}$
                        
                        Strong duality: if both have optimal solutions, optimal values are equal
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Nonlinear Optimization</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Unconstrained Optimization</h4>
                        <div class="math-display">
                            First-order condition: $\nabla f(\mathbf{x}^*) = \mathbf{0}$
                            
                            Second-order condition: $\nabla^2 f(\mathbf{x}^*)$ positive definite
                            
                            Gradient descent: $\mathbf{x}_{k+1} = \mathbf{x}_k - \alpha_k \nabla f(\mathbf{x}_k)$
                            
                            Newton's method: $\mathbf{x}_{k+1} = \mathbf{x}_k - [\nabla^2 f(\mathbf{x}_k)]^{-1} \nabla f(\mathbf{x}_k)$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Constrained Optimization</h4>
                        <div class="math-display">
                            KKT conditions for $\min f(\mathbf{x})$ subject to $g(\mathbf{x}) \leq \mathbf{0}$, $h(\mathbf{x}) = \mathbf{0}$:
                            
                            $\nabla f(\mathbf{x}^*) + \sum_i \lambda_i \nabla g_i(\mathbf{x}^*) + \sum_j \mu_j \nabla h_j(\mathbf{x}^*) = \mathbf{0}$
                            
                            $g_i(\mathbf{x}^*) \leq 0$, $h_j(\mathbf{x}^*) = 0$
                            
                            $\lambda_i \geq 0$, $\lambda_i g_i(\mathbf{x}^*) = 0$ (complementary slackness)
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Convex Optimization</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Convex Sets & Functions</h4>
                        <div class="math-display">
                            Convex set: $\forall \mathbf{x}, \mathbf{y} \in S, \forall \lambda \in [0,1]: \lambda\mathbf{x} + (1-\lambda)\mathbf{y} \in S$
                            
                            Convex function: $f(\lambda\mathbf{x} + (1-\lambda)\mathbf{y}) \leq \lambda f(\mathbf{x}) + (1-\lambda)f(\mathbf{y})$
                            
                            Properties:
                            - Local minimum = global minimum
                            - First-order condition sufficient for optimality
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Interior Point Methods</h4>
                        <div class="math-display">
                            Barrier method: replace constraints $g(\mathbf{x}) \leq \mathbf{0}$ with penalty terms $-t \sum_i \log(-g_i(\mathbf{x}))$
                            
                            As $t \to \infty$, solution approaches constrained optimum
                            
                            Polynomial time complexity for convex problems
                        </div>
                    </div>
                </div>

                <div class="cs-application">
                    <h5>CS Applications:</h5>
                    Machine learning (SVM, neural network training), resource allocation, network flow optimization, compiler optimization, game theory
                </div>
            </div>

            <div class="topic">
                <h3>Integer Programming</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Branch and Bound</h4>
                        <div class="math-display">
                            1. Solve LP relaxation
                            2. If solution integer, update best bound
                            3. If not integer, branch on fractional variable
                            4. Recursively solve subproblems
                            5. Prune if bound worse than current best
                            
                            NP-hard in general, but practical for many instances
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Cutting Planes</h4>
                        <div class="math-display">
                            Add linear constraints (cuts) that remove fractional solutions but preserve all integer solutions
                            
                            Gomory cuts: derived from optimal LP tableau
                            
                            Problem-specific cuts often more effective
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <div class="section">
            <h2 class="highlight">Mathematical Software & Tools</h2>
            
            <div class="formula-grid">
                <div class="formula-card">
                    <h4>Symbolic Computation</h4>
                    <div class="math-display">
                        Mathematica, Maple, SymPy (Python)
                        
                        Exact arithmetic, symbolic integration/differentiation,
                        equation solving, simplification
                        
                        Computer algebra systems
                    </div>
                </div>
                
                <div class="formula-card">
                    <h4>Numerical Computing</h4>
                    <div class="math-display">
                        MATLAB, NumPy/SciPy (Python), R
                        
                        Linear algebra (BLAS, LAPACK)
                        Optimization (CPLEX, Gurobi)
                        Statistics and data analysis
                    </div>
                </div>
                
                <div class="formula-card">
                    <h4>Proof Assistants</h4>
                    <div class="math-display">
                        Coq, Lean, Agda, Isabelle/HOL
                        
                        Formal verification of mathematical proofs
                        Computer-checked mathematics
                        Growing importance in CS theory
                    </div>
                </div>
                
                <div class="formula-card">
                    <h4>Computational Complexity</h4>
                    <div class="math-display">
                        Complexity Zoo: database of complexity classes
                        
                        P, NP, PSPACE, EXPTIME, etc.
                        Reductions and completeness results
                        Interactive proofs, quantum complexity
                    </div>
                </div>
            </div>
            
            <div class="important">
                <h5>Study Strategy for Advanced Math in CS:</h5>
                Focus on applications: understand how each mathematical concept applies to computer science problems. 
                Practice implementation: code algorithms and verify theoretical results computationally.
                Connect concepts: see relationships between different mathematical areas and their CS applications.
                Stay current: mathematics in CS is rapidly evolving, especially in machine learning and quantum computing.
            </div>
        </div>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            // Initialize KaTeX auto-render
            renderMathInElement(document.body, {
                delimiters: [
                    {left: '$', right: '$', display: true},
                    {left: ', right: ', display: false},
                    {left: '\\(', right: '\\)', display: false},
                    {left: '\\[', right: '\\]', display: true}
                ],
                throwOnError: false
            });

            // Smooth scrolling for navigation
            document.querySelectorAll('.nav-link, .nav-card a').forEach(link => {
                link.addEventListener('click', function(e) {
                    e.preventDefault();
                    const targetId = this.getAttribute('href');
                    const target = document.querySelector(targetId);
                    if (target) {
                        target.scrollIntoView({ behavior: 'smooth', block: 'start' });
                    }
                });
            });

            // Add hover effects to cards
            document.querySelectorAll('.formula-card, .theorem, .algorithm-box').forEach(card => {
                card.addEventListener('mouseenter', function() {
                    this.style.transform = 'translateY(-2px)';
                    this.style.boxShadow = '0 4px 15px rgba(0, 0, 0, 0.15)';
                    this.style.transition = 'all 0.3s ease';
                });
                
                card.addEventListener('mouseleave', function() {
                    this.style.transform = 'translateY(0)';
                    this.style.boxShadow = '0 2px 8px rgba(0, 0, 0, 0.08)';
                });
            });

            // Highlight active navigation item
            const observer = new IntersectionObserver((entries) => {
                entries.forEach(entry => {
                    if (entry.isIntersecting) {
                        const id = entry.target.id;
                        document.querySelectorAll('.nav-link').forEach(link => {
                            link.classList.remove('active');
                            if (link.getAttribute('href') === `#${id}`) {
                                link.style.background = '#f0f0f0';
                                link.style.color = '#000000';
                            } else {
                                link.style.background = '';
                                link.style.color = '#000000';
                            }
                        });
                    }
                });
            }, { threshold: 0.1 });

            document.querySelectorAll('.section').forEach(section => {
                observer.observe(section);
            });
        });
    </script>
</body>
</html>, display: false}, {left: '\\(', right: '\\)', display: false}, {left: '\\[', right: '\\]', display: true}], throwOnError: false});"></script>
    
    <link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;700&family=Inter:wght@400;600;700&display=swap" rel="stylesheet">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Inter', sans-serif;
            background: #ffffff;
            color: #1a1a1a;
            min-height: 100vh;
            line-height: 1.6;
        }

        .container {
            max-width: 1600px;
            margin: 0 auto;
            padding: 20px;
        }

        .header {
            text-align: center;
            margin-bottom: 40px;
            padding: 30px;
            background: linear-gradient(135deg, #000000, #333333);
            color: white;
            border-radius: 12px;
            box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
        }

        .header h1 {
            font-size: 2.5rem;
            margin-bottom: 10px;
            font-weight: 700;
        }

        .header p {
            font-size: 1.1rem;
            opacity: 0.9;
        }

        .nav-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
            gap: 15px;
            margin-bottom: 40px;
        }

        .nav-card {
            background: #f8f9fa;
            border: 2px solid #e9ecef;
            border-radius: 8px;
            padding: 15px;
            text-align: center;
            transition: all 0.3s ease;
            cursor: pointer;
        }

        .nav-card:hover {
            border-color: #333333;
            background: #f0f0f0;
            transform: translateY(-2px);
        }

        .nav-card a {
            text-decoration: none;
            color: #000000;
            font-weight: 600;
            font-size: 0.9rem;
        }

        .section {
            margin-bottom: 50px;
            padding: 30px;
            background: #ffffff;
            border: 1px solid #e9ecef;
            border-radius: 12px;
            box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
        }

        .section h2 {
            color: #000000;
            font-size: 1.8rem;
            margin-bottom: 25px;
            border-bottom: 3px solid #333333;
            padding-bottom: 10px;
            font-weight: 700;
        }

        .topic {
            margin-bottom: 30px;
            padding: 20px;
            background: #f8f9fa;
            border-left: 4px solid #333333;
            border-radius: 0 8px 8px 0;
        }

        .topic h3 {
            color: #1a1a1a;
            font-size: 1.3rem;
            margin-bottom: 15px;
            font-weight: 600;
        }

        .formula-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
            gap: 20px;
            margin: 20px 0;
        }

        .formula-card {
            background: #ffffff;
            border: 1px solid #dee2e6;
            border-radius: 8px;
            padding: 20px;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
        }

        .formula-card h4 {
            color: #333333;
            font-size: 1rem;
            margin-bottom: 12px;
            font-weight: 600;
        }

        .math-display {
            background: #f8f9fa;
            padding: 20px;
            border-radius: 6px;
            margin: 10px 0;
            overflow-x: auto;
            font-size: 1.1rem;
        }

        .math-display .katex {
            font-size: 1.2em;
        }

        .math-display .katex-display {
            margin: 0.5em 0;
        }

        .theorem {
            background: linear-gradient(135deg, #f0f0f0, #e5e5e5);
            border: 1px solid #666666;
            border-radius: 8px;
            padding: 20px;
            margin: 15px 0;
        }

        .theorem h4 {
            color: #000000;
            font-size: 1.1rem;
            margin-bottom: 10px;
            font-weight: 700;
        }

        .proof-sketch {
            background: #f5f5f5;
            border-left: 4px solid #666666;
            padding: 15px;
            margin: 10px 0;
            border-radius: 0 6px 6px 0;
            font-size: 0.9rem;
        }

        .complexity-table {
            width: 100%;
            border-collapse: collapse;
            margin: 15px 0;
            background: white;
        }

        .complexity-table th,
        .complexity-table td {
            border: 1px solid #dee2e6;
            padding: 12px;
            text-align: left;
        }

        .complexity-table th {
            background: #333333;
            color: white;
            font-weight: 600;
        }

        .complexity-table tr:nth-child(even) {
            background: #f8f9fa;
        }

        .algorithm-box {
            background: #f8f8f8;
            border: 1px solid #666666;
            border-radius: 8px;
            padding: 20px;
            margin: 15px 0;
        }

        .algorithm-box h5 {
            color: #1a1a1a;
            font-size: 1rem;
            margin-bottom: 10px;
            font-weight: 600;
        }

        .code-block {
            background: #263238;
            color: #ffffff;
            padding: 15px;
            border-radius: 6px;
            font-family: 'JetBrains Mono', monospace;
            font-size: 0.85rem;
            overflow-x: auto;
            margin: 10px 0;
        }

        .important {
            background: linear-gradient(135deg, #f8f8f8, #e8e8e8);
            border: 2px solid #666666;
            border-radius: 8px;
            padding: 15px;
            margin: 15px 0;
        }

        .important h5 {
            color: #1a1a1a;
            font-size: 1rem;
            margin-bottom: 8px;
            font-weight: 600;
        }

        .matrix-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
            gap: 15px;
        }

        .stats-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
            gap: 15px;
        }

        .graph-theory-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
            gap: 18px;
        }

        .navigation {
            position: fixed;
            top: 20px;
            right: 20px;
            background: rgba(255, 255, 255, 0.95);
            border: 1px solid #dee2e6;
            border-radius: 8px;
            padding: 15px;
            max-height: 80vh;
            overflow-y: auto;
            z-index: 1000;
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
        }

        .nav-link {
            display: block;
            color: #000000;
            text-decoration: none;
            font-size: 0.8rem;
            margin-bottom: 8px;
            padding: 6px;
            border-radius: 4px;
            transition: background 0.3s;
        }

        .nav-link:hover {
            background: #f0f0f0;
        }

        .cs-application {
            background: linear-gradient(135deg, #f5f5f5, #e8e8e8);
            border: 1px solid #666666;
            border-radius: 8px;
            padding: 15px;
            margin: 10px 0;
        }

        .cs-application h5 {
            color: #1a1a1a;
            font-size: 0.95rem;
            margin-bottom: 8px;
            font-weight: 600;
        }

        /* Special styling for inline math */
        .katex {
            font-size: 1.1em;
        }

        /* Make math in lists look good */
        li .katex {
            margin: 0 0.2em;
        }

        @media (max-width: 1024px) {
            .navigation {
                position: relative;
                margin-bottom: 30px;
            }
            
            .formula-grid {
                grid-template-columns: 1fr;
            }
            
            .header h1 {
                font-size: 2rem;
            }
        }
    </style>
</head>
<body>
    <div class="navigation">
        <a href="#calculus" class="nav-link">Calculus</a>
        <a href="#calc3" class="nav-link">Multivariable Calculus</a>
        <a href="#diffeq" class="nav-link">Differential Equations</a>
        <a href="#linear" class="nav-link">Linear Algebra</a>
        <a href="#discrete" class="nav-link">Discrete Mathematics</a>
        <a href="#probability" class="nav-link">Probability & Statistics</a>
        <a href="#numerical" class="nav-link">Numerical Analysis</a>
        <a href="#complex" class="nav-link">Complex Analysis</a>
        <a href="#graph" class="nav-link">Graph Theory</a>
        <a href="#number" class="nav-link">Number Theory</a>
        <a href="#algorithms" class="nav-link">Algorithm Analysis</a>
        <a href="#crypto" class="nav-link">Cryptography</a>
        <a href="#optimization" class="nav-link">Optimization</a>
    </div>

    <div class="container">
        <div class="header">
            <h1>Advanced Mathematics for Computer Science</h1>
            <p>Complete Reference: Calculus • Multivariable Calculus • Linear Algebra • Discrete Math • Graph Theory • Algorithms • Cryptography</p>
        </div>

        <div class="nav-grid">
            <div class="nav-card"><a href="#calculus">Calculus</a></div>
            <div class="nav-card"><a href="#calc3">Multivariable Calculus</a></div>
            <div class="nav-card"><a href="#diffeq">Differential Equations</a></div>
            <div class="nav-card"><a href="#linear">Linear Algebra</a></div>
            <div class="nav-card"><a href="#discrete">Discrete Mathematics</a></div>
            <div class="nav-card"><a href="#probability">Probability & Statistics</a></div>
            <div class="nav-card"><a href="#numerical">Numerical Analysis</a></div>
            <div class="nav-card"><a href="#complex">Complex Analysis</a></div>
            <div class="nav-card"><a href="#graph">Graph Theory</a></div>
            <div class="nav-card"><a href="#number">Number Theory</a></div>
            <div class="nav-card"><a href="#algorithms">Algorithm Analysis</a></div>
            <div class="nav-card"><a href="#crypto">Cryptography</a></div>
            <div class="nav-card"><a href="#optimization">Optimization</a></div>
        </div>

        <section id="calculus" class="section">
            <h2>Calculus</h2>
            
            <div class="topic">
                <h3>Limits</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Definition of a Limit</h4>
                        <div class="math-display">
                            $$\lim_{x \to a} f(x) = L$$
                            means: For every $\varepsilon > 0$, there exists $\delta > 0$ such that
                            $$0 < |x - a| < \delta \implies |f(x) - L| < \varepsilon$$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Important Limits</h4>
                        <div class="math-display">
                            $$\lim_{x \to 0} \frac{\sin x}{x} = 1$$
                            $$\lim_{x \to 0} \frac{1 - \cos x}{x} = 0$$
                            $$\lim_{x \to 0} \frac{e^x - 1}{x} = 1$$
                            $$\lim_{x \to \infty} \left(1 + \frac{1}{x}\right)^x = e$$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>L'Hôpital's Rule</h4>
                        <div class="math-display">
                            If $\lim_{x \to a} f(x) = \lim_{x \to a} g(x) = 0$ or $\pm\infty$, then:
                            $$\lim_{x \to a} \frac{f(x)}{g(x)} = \lim_{x \to a} \frac{f'(x)}{g'(x)}$$
                            (provided the right side exists)
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Derivatives</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Definition</h4>
                        <div class="math-display">
                            $$f'(x) = \lim_{h \to 0} \frac{f(x + h) - f(x)}{h}$$
                            Alternative notation: $\frac{df}{dx}$, $\frac{d}{dx}f(x)$, $D_x f$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Derivative Rules</h4>
                        <div class="math-display">
                            Power Rule: $\frac{d}{dx}(x^n) = nx^{n-1}$
                            
                            Product Rule: $(fg)' = f'g + fg'$
                            
                            Quotient Rule: $\left(\frac{f}{g}\right)' = \frac{f'g - fg'}{g^2}$
                            
                            Chain Rule: $\frac{d}{dx}f(g(x)) = f'(g(x)) \cdot g'(x)$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Common Derivatives</h4>
                        <div class="math-display">
                            $$\frac{d}{dx}(\sin x) = \cos x \qquad \frac{d}{dx}(\cos x) = -\sin x$$
                            $$\frac{d}{dx}(e^x) = e^x \qquad \frac{d}{dx}(\ln x) = \frac{1}{x}$$
                            $$\frac{d}{dx}(\tan x) = \sec^2 x \qquad \frac{d}{dx}(\arctan x) = \frac{1}{1+x^2}$$
                        </div>
                    </div>
                </div>

                <div class="theorem">
                    <h4>Mean Value Theorem</h4>
                    <div class="math-display">
                        If $f$ is continuous on $[a,b]$ and differentiable on $(a,b)$, then there exists $c \in (a,b)$ such that:
                        $$f'(c) = \frac{f(b) - f(a)}{b - a}$$
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Integrals</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Definite Integral</h4>
                        <div class="math-display">
                            $$\int_a^b f(x)\,dx = \lim_{n \to \infty} \sum_{i=1}^n f(x_i^*) \Delta x$$
                            where $\Delta x = \frac{b-a}{n}$ and $x_i^* \in [x_{i-1}, x_i]$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Fundamental Theorem of Calculus</h4>
                        <div class="math-display">
                            Part 1: If $F(x) = \int_a^x f(t)\,dt$, then $F'(x) = f(x)$
                            
                            Part 2: If $F'(x) = f(x)$, then
                            $$\int_a^b f(x)\,dx = F(b) - F(a)$$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Integration Techniques</h4>
                        <div class="math-display">
                            Substitution: $\int f(g(x))g'(x)\,dx = \int f(u)\,du$
                            
                            Integration by Parts: $\int u\,dv = uv - \int v\,du$
                            
                            Partial Fractions: Decompose rational functions
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Common Integrals</h4>
                        <div class="math-display">
                            $$\int x^n\,dx = \frac{x^{n+1}}{n+1} + C \quad (n \neq -1)$$
                            $$\int \frac{1}{x}\,dx = \ln|x| + C$$
                            $$\int e^x\,dx = e^x + C$$
                            $$\int \sin x\,dx = -\cos x + C$$
                            $$\int \frac{1}{\sqrt{1-x^2}}\,dx = \arcsin x + C$$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Series and Sequences</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Sequences</h4>
                        <div class="math-display">
                            A sequence $\{a_n\}$ converges to $L$ if:
                            $$\lim_{n \to \infty} a_n = L$$
                            
                            Common limits:
                            $$\lim_{n \to \infty} \frac{1}{n} = 0 \qquad \lim_{n \to \infty} \sqrt[n]{n} = 1$$
                            $$\lim_{n \to \infty} \left(1 + \frac{1}{n}\right)^n = e$$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Series Convergence Tests</h4>
                        <div class="math-display">
                            Geometric Series: $\sum_{n=0}^{\infty} ar^n = \frac{a}{1-r}$ if $|r| < 1$
                            
                            p-Series: $\sum_{n=1}^{\infty} \frac{1}{n^p}$ converges if $p > 1$
                            
                            Ratio Test: If $\lim_{n \to \infty} \left|\frac{a_{n+1}}{a_n}\right| = L$
                            then series converges if $L < 1$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Taylor Series</h4>
                        <div class="math-display">
                            $$f(x) = \sum_{n=0}^{\infty} \frac{f^{(n)}(a)}{n!}(x-a)^n$$
                            
                            Common Taylor series:
                            $$e^x = \sum_{n=0}^{\infty} \frac{x^n}{n!}$$
                            $$\sin x = \sum_{n=0}^{\infty} \frac{(-1)^n x^{2n+1}}{(2n+1)!}$$
                            $$\ln(1+x) = \sum_{n=1}^{\infty} \frac{(-1)^{n+1} x^n}{n}$$
                        </div>
                    </div>
                </div>

                <div class="cs-application">
                    <h5>CS Applications:</h5>
                    Machine learning (gradient descent, backpropagation), computer graphics (physics simulations), numerical methods, algorithm complexity analysis, signal processing
                </div>
            </div>

            <div class="topic">
                <h3>Applications of Calculus</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Optimization</h4>
                        <div class="math-display">
                            Critical points: $f'(x) = 0$ or $f'(x)$ undefined
                            
                            Second derivative test:
                            - If $f''(c) > 0$: local minimum at $x = c$
                            - If $f''(c) < 0$: local maximum at $x = c$
                            - If $f''(c) = 0$: test inconclusive
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Related Rates</h4>
                        <div class="math-display">
                            If variables $x$ and $y$ are related by an equation and vary with time $t$:
                            $$\frac{dy}{dt} = \frac{dy}{dx} \cdot \frac{dx}{dt}$$
                            
                            Example: Area of circle $A = \pi r^2$
                            $$\frac{dA}{dt} = 2\pi r \frac{dr}{dt}$$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Arc Length & Surface Area</h4>
                        <div class="math-display">
                            Arc length: $L = \int_a^b \sqrt{1 + (f'(x))^2}\,dx$
                            
                            Surface area (revolution about x-axis):
                            $$S = 2\pi \int_a^b f(x)\sqrt{1 + (f'(x))^2}\,dx$$
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <section id="calc3" class="section">
            <h2>Multivariable Calculus</h2>
            
            <div class="topic">
                <h3>Partial Derivatives & Gradients</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Partial Derivatives</h4>
                        <div class="math-display">
                            $$\frac{\partial f}{\partial x} = \lim_{h \to 0} \frac{f(x+h,y) - f(x,y)}{h}$$
                            
                            Mixed partials theorem (Clairaut):
                            $$\frac{\partial^2 f}{\partial x \partial y} = \frac{\partial^2 f}{\partial y \partial x}$$
                            (if both are continuous)
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Gradient & Directional Derivatives</h4>
                        <div class="math-display">
                            $$\nabla f = \left( \frac{\partial f}{\partial x}, \frac{\partial f}{\partial y}, \frac{\partial f}{\partial z} \right)$$
                            
                            Directional derivative:
                            $$D_{\mathbf{u}} f = \nabla f \cdot \mathbf{u}$$
                            
                            Maximum rate of change: $|\nabla f|$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Chain Rule (Multivariable)</h4>
                        <div class="math-display">
                            If $z = f(x,y)$ where $x = g(t)$ and $y = h(t)$:
                            $$\frac{dz}{dt} = \frac{\partial z}{\partial x}\frac{dx}{dt} + \frac{\partial z}{\partial y}\frac{dy}{dt}$$
                            
                            General form:
                            $$\frac{\partial z}{\partial t} = \sum_{i} \frac{\partial z}{\partial x_i}\frac{\partial x_i}{\partial t}$$
                        </div>
                    </div>
                </div>
                
                <div class="cs-application">
                    <h5>CS Applications:</h5>
                    Machine learning optimization (gradient descent), computer graphics (surface normals), image processing (edge detection), neural network training
                </div>
            </div>

            <div class="topic">
                <h3>Multiple Integrals</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Double Integrals</h4>
                        <div class="math-display">
                            $$\iint_R f(x,y) \, dA = \int_a^b \int_{c(x)}^{d(x)} f(x,y) \, dy \, dx$$
                            
                            Fubini's Theorem: For continuous $f$,
                            $$\int_a^b \int_c^d f(x,y) \, dy \, dx = \int_c^d \int_a^b f(x,y) \, dx \, dy$$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Change of Variables</h4>
                        <div class="math-display">
                            $$\iint_R f(x,y) \, dx \, dy = \iint_S f(x(u,v), y(u,v)) |J| \, du \, dv$$
                            
                            Jacobian: $J = \frac{\partial(x,y)}{\partial(u,v)} = \begin{vmatrix} \frac{\partial x}{\partial u} & \frac{\partial x}{\partial v} \\ \frac{\partial y}{\partial u} & \frac{\partial y}{\partial v} \end{vmatrix}$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Cylindrical & Spherical Coordinates</h4>
                        <div class="math-display">
                            Cylindrical: $\begin{cases} x = r\cos\theta \\ y = r\sin\theta \\ z = z \end{cases}$ 
                            $dV = r \, dr \, d\theta \, dz$
                            
                            Spherical: $\begin{cases} x = \rho\sin\phi\cos\theta \\ y = \rho\sin\phi\sin\theta \\ z = \rho\cos\phi \end{cases}$
                            $dV = \rho^2\sin\phi \, d\rho \, d\phi \, d\theta$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Vector Calculus</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Vector Fields & Line Integrals</h4>
                        <div class="math-display">
                            $$\int_C \mathbf{F} \cdot d\mathbf{r} = \int_a^b \mathbf{F}(\mathbf{r}(t)) \cdot \mathbf{r}'(t) \, dt$$
                            
                            Conservative field: $\nabla \times \mathbf{F} = \mathbf{0}$
                            
                            If $\mathbf{F} = \nabla f$: $\int_C \mathbf{F} \cdot d\mathbf{r} = f(B) - f(A)$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Green's Theorem</h4>
                        <div class="math-display">
                            $$\oint_C (P \, dx + Q \, dy) = \iint_D \left( \frac{\partial Q}{\partial x} - \frac{\partial P}{\partial y} \right) dA$$
                            
                            Area formula: $A = \frac{1}{2} \oint_C (x \, dy - y \, dx)$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Divergence & Curl</h4>
                        <div class="math-display">
                            $$\text{div } \mathbf{F} = \nabla \cdot \mathbf{F} = \frac{\partial P}{\partial x} + \frac{\partial Q}{\partial y} + \frac{\partial R}{\partial z}$$
                            
                            $$\text{curl } \mathbf{F} = \nabla \times \mathbf{F} = \begin{vmatrix} \mathbf{i} & \mathbf{j} & \mathbf{k} \\ \frac{\partial}{\partial x} & \frac{\partial}{\partial y} & \frac{\partial}{\partial z} \\ P & Q & R \end{vmatrix}$$
                        </div>
                    </div>
                </div>

                <div class="theorem">
                    <h4>Stokes' Theorem</h4>
                    <div class="math-display">
                        $$\oint_C \mathbf{F} \cdot d\mathbf{r} = \iint_S (\nabla \times \mathbf{F}) \cdot \mathbf{n} \, dS$$
                    </div>
                    Relates line integral around boundary to surface integral of curl
                </div>

                <div class="theorem">
                    <h4>Divergence Theorem</h4>
                    <div class="math-display">
                        $$\iint_S \mathbf{F} \cdot \mathbf{n} \, dS = \iiint_E \nabla \cdot \mathbf{F} \, dV$$
                    </div>
                    Relates surface integral to volume integral of divergence
                </div>
            </div>
        </section>

        <section id="diffeq" class="section">
            <h2>Differential Equations</h2>
            
            <div class="topic">
                <h3>First-Order ODEs</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Separable Equations</h4>
                        <div class="math-display">
                            $$\frac{dy}{dx} = f(x)g(y)$$
                            
                            Solution method:
                            $$\int \frac{dy}{g(y)} = \int f(x) \, dx$$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Linear First-Order</h4>
                        <div class="math-display">
                            $$\frac{dy}{dx} + P(x)y = Q(x)$$
                            
                            Integrating factor: $\mu(x) = e^{\int P(x) \, dx}$
                            
                            Solution: $y = \frac{1}{\mu(x)}\left[\int \mu(x)Q(x) \, dx + C\right]$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Exact Equations</h4>
                        <div class="math-display">
                            $$M(x,y) \, dx + N(x,y) \, dy = 0$$
                            
                            Exact if: $\frac{\partial M}{\partial y} = \frac{\partial N}{\partial x}$
                            
                            Solution: Find $F(x,y)$ where $\frac{\partial F}{\partial x} = M$ and $\frac{\partial F}{\partial y} = N$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Second-Order Linear ODEs</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Homogeneous with Constant Coefficients</h4>
                        <div class="math-display">
                            $$ay'' + by' + cy = 0$$
                            
                            Characteristic equation: $ar^2 + br + c = 0$
                            
                            Solutions:
                            - If $r_1 \neq r_2$: $y = c_1e^{r_1x} + c_2e^{r_2x}$
                            - If $r_1 = r_2 = r$: $y = (c_1 + c_2x)e^{rx}$
                            - If $r = \alpha \pm \beta i$: $y = e^{\alpha x}(c_1\cos(\beta x) + c_2\sin(\beta x))$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Method of Undetermined Coefficients</h4>
                        <div class="math-display">
                            For $ay'' + by' + cy = f(x)$:
                            
                            - If $f(x) = e^{\alpha x}$: try $y_p = Ae^{\alpha x}$
                            - If $f(x) = \text{polynomial}$: try polynomial of same degree
                            - If $f(x) = \sin(\alpha x)$ or $\cos(\alpha x)$: 
                              try $y_p = A\cos(\alpha x) + B\sin(\alpha x)$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Variation of Parameters</h4>
                        <div class="math-display">
                            For $y'' + P(x)y' + Q(x)y = f(x)$
                            
                            If $y_1, y_2$ are homogeneous solutions:
                            $$y_p = -y_1\int\frac{y_2f}{W}dx + y_2\int\frac{y_1f}{W}dx$$
                            
                            Wronskian: $W = y_1y_2' - y_2y_1'$
                        </div>
                    </div>
                </div>

                <div class="cs-application">
                    <h5>CS Applications:</h5>
                    System dynamics, control theory, signal processing, population models in algorithms, oscillator circuits, physics simulations
                </div>
            </div>

            <div class="topic">
                <h3>Laplace Transforms</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Definition & Properties</h4>
                        <div class="math-display">
                            $$\mathcal{L}\{f(t)\} = F(s) = \int_0^{\infty} e^{-st}f(t) \, dt$$
                            
                            Properties:
                            - $\mathcal{L}\{af + bg\} = a\mathcal{L}\{f\} + b\mathcal{L}\{g\}$
                            - $\mathcal{L}\{f'\} = sF(s) - f(0)$
                            - $\mathcal{L}\{f''\} = s^2F(s) - sf(0) - f'(0)$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Common Transforms</h4>
                        <div class="math-display">
                            $$\mathcal{L}\{1\} = \frac{1}{s}$$
                            $$\mathcal{L}\{t^n\} = \frac{n!}{s^{n+1}}$$
                            $$\mathcal{L}\{e^{at}\} = \frac{1}{s-a}$$
                            $$\mathcal{L}\{\sin(at)\} = \frac{a}{s^2+a^2}$$
                            $$\mathcal{L}\{\cos(at)\} = \frac{s}{s^2+a^2}$$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Systems of ODEs</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Matrix Form</h4>
                        <div class="math-display">
                            $$\mathbf{x}' = A\mathbf{x} + \mathbf{b}$$
                            
                            Solution: $\mathbf{x}(t) = e^{At}\mathbf{x}_0 + \int_0^t e^{A(t-\tau)}\mathbf{b}(\tau) \, d\tau$
                            
                            Matrix exponential: $e^{At} = \sum_{n=0}^{\infty} \frac{A^n t^n}{n!}$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Eigenvalue Method</h4>
                        <div class="math-display">
                            If $A\mathbf{v} = \lambda\mathbf{v}$, then $\mathbf{x} = \mathbf{v}e^{\lambda t}$ is a solution
                            
                            General solution:
                            $$\mathbf{x} = c_1\mathbf{v}_1e^{\lambda_1 t} + c_2\mathbf{v}_2e^{\lambda_2 t} + \cdots$$
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <section id="linear" class="section">
            <h2>Linear Algebra</h2>
            
            <div class="topic">
                <h3>Matrix Operations & Properties</h3>
                <div class="matrix-grid">
                    <div class="formula-card">
                        <h4>Basic Operations</h4>
                        <div class="math-display">
                            $(AB)C = A(BC)$ - Associative
                            
                            $A(B + C) = AB + AC$ - Distributive
                            
                            $(AB)^T = B^T A^T$
                            
                            $(AB)^{-1} = B^{-1}A^{-1}$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Determinants</h4>
                        <div class="math-display">
                            $\det(AB) = \det(A)\det(B)$
                            
                            $\det(A^T) = \det(A)$
                            
                            $\det(A^{-1}) = \frac{1}{\det(A)}$
                            
                            For $2 \times 2$: $\det\begin{pmatrix}a & b\\c & d\end{pmatrix} = ad - bc$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Matrix Inverse</h4>
                        <div class="math-display">
                            $A^{-1} = \frac{1}{\det(A)} \cdot \text{adj}(A)$
                            
                            For $2 \times 2$: $A^{-1} = \frac{1}{ad-bc}\begin{pmatrix}d & -b\\-c & a\end{pmatrix}$
                            
                            Gauss-Jordan: $[A|I] \rightarrow [I|A^{-1}]$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Vector Spaces & Linear Independence</h3>
                <div class="theorem">
                    <h4>Vector Space Axioms</h4>
                    A vector space $V$ over field $F$ satisfies:
                    <div class="math-display">
                        1. $\mathbf{u} + \mathbf{v} \in V$ (closure under addition)
                        2. $\mathbf{u} + \mathbf{v} = \mathbf{v} + \mathbf{u}$ (commutativity)
                        3. $(\mathbf{u} + \mathbf{v}) + \mathbf{w} = \mathbf{u} + (\mathbf{v} + \mathbf{w})$ (associativity)
                        4. $\exists \mathbf{0} \in V: \mathbf{v} + \mathbf{0} = \mathbf{v}$ (additive identity)
                        5. $\forall \mathbf{v} \exists (-\mathbf{v}): \mathbf{v} + (-\mathbf{v}) = \mathbf{0}$ (additive inverse)
                        6-10. Scalar multiplication axioms
                    </div>
                </div>
                
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Linear Independence</h4>
                        <div class="math-display">
                            Vectors $\mathbf{v}_1, \mathbf{v}_2, \ldots, \mathbf{v}_n$ are linearly independent if:
                            $$c_1\mathbf{v}_1 + c_2\mathbf{v}_2 + \cdots + c_n\mathbf{v}_n = \mathbf{0} \implies c_1 = c_2 = \cdots = c_n = 0$$
                            
                            Matrix form: $A\mathbf{x} = \mathbf{0}$ has only trivial solution
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Basis & Dimension</h4>
                        <div class="math-display">
                            Basis: linearly independent set that spans the space
                            
                            $\dim(V) = $ number of vectors in any basis
                            
                            If $\dim(V) = n$, then any $n$ linearly independent vectors form a basis
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Eigenvalues & Eigenvectors</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Characteristic Equation</h4>
                        <div class="math-display">
                            $$A\mathbf{v} = \lambda\mathbf{v} \quad (\mathbf{v} \neq \mathbf{0})$$
                            
                            Characteristic polynomial: $\det(A - \lambda I) = 0$
                            
                            Eigenspace: $E_{\lambda} = \{\mathbf{v} : A\mathbf{v} = \lambda\mathbf{v}\} = \text{null}(A - \lambda I)$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Diagonalization</h4>
                        <div class="math-display">
                            $$A = PDP^{-1}$$
                            where $D$ is diagonal
                            
                            $P = [\mathbf{v}_1 \, \mathbf{v}_2 \, \cdots \, \mathbf{v}_n]$ (eigenvectors)
                            
                            $D = \text{diag}(\lambda_1, \lambda_2, \ldots, \lambda_n)$ (eigenvalues)
                            
                            $A^k = PD^k P^{-1}$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Properties</h4>
                        <div class="math-display">
                            $$\text{tr}(A) = \lambda_1 + \lambda_2 + \cdots + \lambda_n$$
                            $$\det(A) = \lambda_1 \times \lambda_2 \times \cdots \times \lambda_n$$
                            
                            If $A$ symmetric: all eigenvalues real, eigenvectors orthogonal
                        </div>
                    </div>
                </div>

                <div class="cs-application">
                    <h5>CS Applications:</h5>
                    Google PageRank algorithm, Principal Component Analysis (PCA), computer graphics transformations, quantum computing gates, network analysis
                </div>
            </div>

            <div class="topic">
                <h3>Orthogonality & Least Squares</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Inner Products & Norms</h4>
                        <div class="math-display">
                            $$\langle \mathbf{u}, \mathbf{v} \rangle = \mathbf{u}^T\mathbf{v} = u_1v_1 + u_2v_2 + \cdots + u_nv_n$$
                            
                            $$\|\mathbf{v}\| = \sqrt{\langle \mathbf{v}, \mathbf{v} \rangle} = \sqrt{v_1^2 + v_2^2 + \cdots + v_n^2}$$
                            
                            Cauchy-Schwarz: $|\langle \mathbf{u}, \mathbf{v} \rangle| \leq \|\mathbf{u}\| \|\mathbf{v}\|$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Gram-Schmidt Process</h4>
                        <div class="math-display">
                            $$\mathbf{u}_1 = \mathbf{v}_1$$
                            $$\mathbf{u}_2 = \mathbf{v}_2 - \text{proj}_{\mathbf{u}_1}\mathbf{v}_2$$
                            $$\mathbf{u}_3 = \mathbf{v}_3 - \text{proj}_{\mathbf{u}_1}\mathbf{v}_3 - \text{proj}_{\mathbf{u}_2}\mathbf{v}_3$$
                            
                            where $\text{proj}_{\mathbf{u}}\mathbf{v} = \frac{\langle \mathbf{v}, \mathbf{u} \rangle}{\langle \mathbf{u}, \mathbf{u} \rangle}\mathbf{u}$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Least Squares</h4>
                        <div class="math-display">
                            Normal equation: $A^T A\hat{\mathbf{x}} = A^T\mathbf{b}$
                            
                            Solution: $\hat{\mathbf{x}} = (A^T A)^{-1}A^T\mathbf{b}$
                            
                            If $A$ has orthonormal columns: $\hat{\mathbf{x}} = A^T\mathbf{b}$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Singular Value Decomposition</h3>
                <div class="theorem">
                    <h4>SVD Theorem</h4>
                    Every $m \times n$ matrix $A$ can be written as:
                    <div class="math-display">
                        $$A = U\Sigma V^T$$
                        
                        $U$: $m \times m$ orthogonal (left singular vectors)
                        $\Sigma$: $m \times n$ diagonal (singular values $\sigma_1 \geq \sigma_2 \geq \cdots \geq 0$)
                        $V$: $n \times n$ orthogonal (right singular vectors)
                    </div>
                </div>
                
                <div class="cs-application">
                    <h5>CS Applications:</h5>
                    Image compression, dimensionality reduction, recommender systems, data analysis, pseudoinverse computation
                </div>
            </div>
        </section>

        <section id="discrete" class="section">
            <h2>Discrete Mathematics</h2>
            
            <div class="topic">
                <h3>Logic & Proofs</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Logical Operators</h4>
                        <div class="math-display">
                            $\neg$ (NOT), $\land$ (AND), $\lor$ (OR), $\rightarrow$ (IMPLIES), $\leftrightarrow$ (IFF)
                            
                            De Morgan's Laws:
                            $$\neg(P \land Q) \equiv \neg P \lor \neg Q$$
                            $$\neg(P \lor Q) \equiv \neg P \land \neg Q$$
                            
                            $P \rightarrow Q \equiv \neg P \lor Q$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Quantifiers</h4>
                        <div class="math-display">
                            $\forall x \, P(x)$: "for all $x$, $P(x)$"
                            
                            $\exists x \, P(x)$: "there exists $x$ such that $P(x)$"
                            
                            $$\neg\forall x \, P(x) \equiv \exists x \, \neg P(x)$$
                            $$\neg\exists x \, P(x) \equiv \forall x \, \neg P(x)$$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Proof Techniques</h4>
                        <div class="math-display">
                            Direct proof: $P \rightarrow Q$
                            
                            Contrapositive: $\neg Q \rightarrow \neg P$
                            
                            Contradiction: Assume $\neg Q$ and derive contradiction
                            
                            Induction: Base case + inductive step
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Set Theory</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Set Operations</h4>
                        <div class="math-display">
                            $A \cup B = \{x : x \in A \text{ or } x \in B\}$
                            
                            $A \cap B = \{x : x \in A \text{ and } x \in B\}$
                            
                            $A - B = \{x : x \in A \text{ and } x \notin B\}$
                            
                            $A^c = \{x : x \notin A\}$
                            
                            $|A \cup B| = |A| + |B| - |A \cap B|$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Relations</h4>
                        <div class="math-display">
                            Reflexive: $\forall x \, (x,x) \in R$
                            
                            Symmetric: $\forall x,y \, ((x,y) \in R \rightarrow (y,x) \in R)$
                            
                            Transitive: $\forall x,y,z \, ((x,y) \in R \land (y,z) \in R \rightarrow (x,z) \in R)$
                            
                            Equivalence relation: reflexive + symmetric + transitive
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Functions</h4>
                        <div class="math-display">
                            Injective (one-to-one): $\forall x,y \, (f(x) = f(y) \rightarrow x = y)$
                            
                            Surjective (onto): $\forall y \, \exists x \, (f(x) = y)$
                            
                            Bijective: injective + surjective
                            
                            $|A| = |B|$ iff $\exists$ bijection $f: A \rightarrow B$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Combinatorics</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Counting Principles</h4>
                        <div class="math-display">
                            Addition Principle: $|A \cup B| = |A| + |B|$ if $A \cap B = \emptyset$
                            
                            Multiplication Principle: $|A \times B| = |A| \times |B|$
                            
                            Pigeonhole Principle: If $n$ objects in $m$ boxes and $n > m$, then some box contains $> 1$ object
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Permutations & Combinations</h4>
                        <div class="math-display">
                            $$P(n,r) = \frac{n!}{(n-r)!} \text{ (permutations)}$$
                            
                            $$C(n,r) = \binom{n}{r} = \frac{n!}{r!(n-r)!} \text{ (combinations)}$$
                            
                            Binomial theorem: $(x+y)^n = \sum_{k=0}^n \binom{n}{k} x^k y^{n-k}$
                            
                            Stars and bars: $\binom{n+k-1}{k-1}$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Inclusion-Exclusion</h4>
                        <div class="math-display">
                            $$|A_1 \cup A_2 \cup \cdots \cup A_n| =$$
                            $$\sum |A_i| - \sum |A_i \cap A_j| + \sum |A_i \cap A_j \cap A_k| - \cdots$$
                            $$+ (-1)^{n+1}|A_1 \cap \cdots \cap A_n|$$
                        </div>
                    </div>
                </div>

                <div class="cs-application">
                    <h5>CS Applications:</h5>
                    Algorithm analysis, database query optimization, complexity theory, coding theory, cryptographic protocols
                </div>
            </div>

            <div class="topic">
                <h3>Generating Functions</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Ordinary Generating Functions</h4>
                        <div class="math-display">
                            $$G(x) = \sum_{n=0}^{\infty} a_n x^n = a_0 + a_1x + a_2x^2 + \cdots$$
                            
                            Fibonacci: $F(x) = \frac{x}{1 - x - x^2}$
                            
                            Geometric: $\frac{1}{1-x} = \sum_{n=0}^{\infty} x^n$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Exponential Generating Functions</h4>
                        <div class="math-display">
                            $$E(x) = \sum_{n=0}^{\infty} a_n \frac{x^n}{n!}$$
                            
                            $e^x = \sum_{n=0}^{\infty} \frac{x^n}{n!}$
                            
                            Useful for problems with labels/arrangements
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Recurrence Relations</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Linear Homogeneous</h4>
                        <div class="math-display">
                            $$a_n = c_1a_{n-1} + c_2a_{n-2} + \cdots + c_ka_{n-k}$$
                            
                            Characteristic equation: $r^k - c_1r^{k-1} - \cdots - c_k = 0$
                            
                            If roots distinct: $a_n = A_1r_1^n + A_2r_2^n + \cdots$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Master Theorem</h4>
                        <div class="math-display">
                            For $T(n) = aT(n/b) + f(n)$:
                            
                            Case 1: $f(n) = O(n^{\log_b a - \varepsilon}) \Rightarrow T(n) = \Theta(n^{\log_b a})$
                            
                            Case 2: $f(n) = \Theta(n^{\log_b a}) \Rightarrow T(n) = \Theta(n^{\log_b a} \log n)$
                            
                            Case 3: $f(n) = \Omega(n^{\log_b a + \varepsilon}) \Rightarrow T(n) = \Theta(f(n))$
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <section id="probability" class="section">
            <h2>Probability & Statistics</h2>
            
            <div class="topic">
                <h3>Probability Theory</h3>
                <div class="stats-grid">
                    <div class="formula-card">
                        <h4>Basic Probability</h4>
                        <div class="math-display">
                            $$P(A \cup B) = P(A) + P(B) - P(A \cap B)$$
                            $$P(A^c) = 1 - P(A)$$
                            $$P(A|B) = \frac{P(A \cap B)}{P(B)}$$
                            
                            Independence: $P(A \cap B) = P(A)P(B)$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Bayes' Theorem</h4>
                        <div class="math-display">
                            $$P(A|B) = \frac{P(B|A)P(A)}{P(B)}$$
                            
                            Law of Total Probability:
                            $$P(B) = \sum_i P(B|A_i)P(A_i)$$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Random Variables</h4>
                        <div class="math-display">
                            $$E[X] = \sum_x x \cdot P(X = x) \text{ (discrete)}$$
                            $$E[X] = \int_{-\infty}^{\infty} x \cdot f(x) \, dx \text{ (continuous)}$$
                            
                            $\text{Var}(X) = E[X^2] - (E[X])^2$
                            
                            $\text{Var}(aX + b) = a^2\text{Var}(X)$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Common Distributions</h3>
                <div class="stats-grid">
                    <div class="formula-card">
                        <h4>Discrete Distributions</h4>
                        <div class="math-display">
                            Bernoulli: $P(X = 1) = p$, $P(X = 0) = 1-p$
                            
                            Binomial: $P(X = k) = \binom{n}{k}p^k(1-p)^{n-k}$
                            $E[X] = np$, $\text{Var}(X) = np(1-p)$
                            
                            Poisson: $P(X = k) = \frac{\lambda^k e^{-\lambda}}{k!}$
                            $E[X] = \text{Var}(X) = \lambda$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Continuous Distributions</h4>
                        <div class="math-display">
                            Uniform: $f(x) = \frac{1}{b-a}$ for $x \in [a,b]$
                            $E[X] = \frac{a+b}{2}$, $\text{Var}(X) = \frac{(b-a)^2}{12}$
                            
                            Normal: $f(x) = \frac{1}{\sigma\sqrt{2\pi}}e^{-\frac{(x-\mu)^2}{2\sigma^2}}$
                            $E[X] = \mu$, $\text{Var}(X) = \sigma^2$
                            
                            Exponential: $f(x) = \lambda e^{-\lambda x}$ for $x \geq 0$
                            $E[X] = \frac{1}{\lambda}$, $\text{Var}(X) = \frac{1}{\lambda^2}$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Central Limit Theorem</h4>
                        <div class="math-display">
                            If $X_1, X_2, \ldots, X_n$ are i.i.d. with $E[X_i] = \mu$, $\text{Var}(X_i) = \sigma^2$:
                            
                            $$\frac{\bar{X} - \mu}{\sigma/\sqrt{n}} \xrightarrow{d} N(0,1) \text{ as } n \to \infty$$
                            
                            where $\bar{X} = \frac{1}{n}\sum_{i=1}^n X_i$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Statistical Inference</h3>
                <div class="stats-grid">
                    <div class="formula-card">
                        <h4>Confidence Intervals</h4>
                        <div class="math-display">
                            For mean $\mu$ ($\sigma$ known):
                            $$\bar{x} \pm z_{\alpha/2} \times \frac{\sigma}{\sqrt{n}}$$
                            
                            For mean $\mu$ ($\sigma$ unknown):
                            $$\bar{x} \pm t_{\alpha/2,n-1} \times \frac{s}{\sqrt{n}}$$
                            
                            For proportion $p$:
                            $$\hat{p} \pm z_{\alpha/2} \times \sqrt{\frac{\hat{p}(1-\hat{p})}{n}}$$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Hypothesis Testing</h4>
                        <div class="math-display">
                            Test statistic for mean:
                            $$z = \frac{\bar{x} - \mu_0}{\sigma/\sqrt{n}} \text{ or } t = \frac{\bar{x} - \mu_0}{s/\sqrt{n}}$$
                            
                            p-value = P(observing test statistic or more extreme | $H_0$)
                            
                            Reject $H_0$ if p-value $< \alpha$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Regression</h4>
                        <div class="math-display">
                            Simple linear: $\hat{y} = a + bx$
                            
                            $$b = \frac{\sum (x_i - \bar{x})(y_i - \bar{y})}{\sum (x_i - \bar{x})^2}$$
                            $$a = \bar{y} - b\bar{x}$$
                            
                            $R^2 = 1 - \frac{SSE}{SST}$ (coefficient of determination)
                        </div>
                    </div>
                </div>

                <div class="cs-application">
                    <h5>CS Applications:</h5>
                    Machine learning algorithms, A/B testing, data mining, quality assurance, performance analysis, randomized algorithms
                </div>
            </div>
        </section>

        <section id="numerical" class="section">
            <h2>Numerical Analysis</h2>
            
            <div class="topic">
                <h3>Root Finding</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Bisection Method</h4>
                        <div class="math-display">
                            If $f(a)f(b) < 0$, then $\exists c \in (a,b): f(c) = 0$
                            
                            Algorithm:
                            1. $c = \frac{a + b}{2}$
                            2. If $f(a)f(c) < 0$: $b = c$, else $a = c$
                            3. Repeat until $|b - a| < $ tolerance
                            
                            Convergence: $O(\log_2((b-a)/\varepsilon))$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Newton's Method</h4>
                        <div class="math-display">
                            $$x_{n+1} = x_n - \frac{f(x_n)}{f'(x_n)}$$
                            
                            Quadratic convergence when $f'(\text{root}) \neq 0$
                            
                            May fail if $f'(x_n) \approx 0$ or poor initial guess
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Secant Method</h4>
                        <div class="math-display">
                            $$x_{n+1} = x_n - f(x_n)\frac{x_n - x_{n-1}}{f(x_n) - f(x_{n-1})}$$
                            
                            Approximates derivative using secant line
                            
                            Superlinear convergence: $\varphi = \frac{1+\sqrt{5}}{2} \approx 1.618$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Interpolation</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Lagrange Interpolation</h4>
                        <div class="math-display">
                            $$P(x) = \sum_{i=0}^n y_i L_i(x)$$
                            
                            where $L_i(x) = \prod_{j=0, j \neq i}^n \frac{x - x_j}{x_i - x_j}$
                            
                            Unique polynomial of degree $\leq n$ through $n+1$ points
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Newton's Divided Differences</h4>
                        <div class="math-display">
                            $$P(x) = f[x_0] + f[x_0,x_1](x-x_0) + f[x_0,x_1,x_2](x-x_0)(x-x_1) + \cdots$$
                            
                            $f[x_i,x_{i+1}] = \frac{f[x_{i+1}] - f[x_i]}{x_{i+1} - x_i}$
                            
                            More efficient for adding new points
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Spline Interpolation</h4>
                        <div class="math-display">
                            Cubic spline: $S(x) = a_i + b_i(x-x_i) + c_i(x-x_i)^2 + d_i(x-x_i)^3$
                            
                            Conditions:
                            - $S(x_i) = y_i$
                            - $S'(x_i^-) = S'(x_i^+)$
                            - $S''(x_i^-) = S''(x_i^+)$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Numerical Integration</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Composite Rules</h4>
                        <div class="math-display">
                            Composite Trapezoidal:
                            $$\int_a^b f(x)\,dx \approx \frac{h}{2}[f(x_0) + 2f(x_1) + \cdots + 2f(x_{n-1}) + f(x_n)]$$
                            Error: $O(h^2)$
                            
                            Composite Simpson's:
                            $$\int_a^b f(x)\,dx \approx \frac{h}{3}[f(x_0) + 4f(x_1) + 2f(x_2) + 4f(x_3) + \cdots + f(x_n)]$$
                            Error: $O(h^4)$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Gaussian Quadrature</h4>
                        <div class="math-display">
                            $$\int_{-1}^1 f(x)\,dx \approx \sum_{i=1}^n w_i f(x_i)$$
                            
                            Optimal choice of points $x_i$ and weights $w_i$
                            
                            $n$-point Gauss rule exact for polynomials of degree $\leq 2n-1$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Ordinary Differential Equations</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Euler's Method</h4>
                        <div class="math-display">
                            $$y_{n+1} = y_n + h \cdot f(x_n, y_n)$$
                            
                            First-order accuracy: $O(h)$
                            
                            Simple but may be unstable for large $h$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Runge-Kutta Methods</h4>
                        <div class="math-display">
                            RK4 (Fourth-order):
                            $$k_1 = hf(x_n, y_n)$$
                            $$k_2 = hf(x_n + h/2, y_n + k_1/2)$$
                            $$k_3 = hf(x_n + h/2, y_n + k_2/2)$$
                            $$k_4 = hf(x_n + h, y_n + k_3)$$
                            
                            $$y_{n+1} = y_n + \frac{k_1 + 2k_2 + 2k_3 + k_4}{6}$$
                        </div>
                    </div>
                </div>

                <div class="cs-application">
                    <h5>CS Applications:</h5>
                    Computer graphics (ray tracing), scientific computing, game physics, signal processing, finite element analysis
                </div>
            </div>
        </section>

        <section id="complex" class="section">
            <h2>Complex Analysis</h2>
            
            <div class="topic">
                <h3>Complex Numbers</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Basic Operations</h4>
                        <div class="math-display">
                            $$z = x + iy = re^{i\theta} = r(\cos\theta + i\sin\theta)$$
                            
                            $|z| = \sqrt{x^2 + y^2} = r$
                            
                            $\arg(z) = \theta = \arctan(y/x)$
                            
                            $z^* = x - iy = re^{-i\theta}$ (complex conjugate)
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Polar Form</h4>
                        <div class="math-display">
                            $$z_1z_2 = r_1r_2e^{i(\theta_1+\theta_2)}$$
                            $$\frac{z_1}{z_2} = \frac{r_1}{r_2}e^{i(\theta_1-\theta_2)}$$
                            
                            De Moivre's theorem: $z^n = r^n e^{in\theta}$
                            
                            $n$th roots: $z^{1/n} = r^{1/n} e^{i(\theta+2\pi k)/n}$, $k = 0,1,\ldots,n-1$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Analytic Functions</h3>
                <div class="theorem">
                    <h4>Cauchy-Riemann Equations</h4>
                    If $f(z) = u(x,y) + iv(x,y)$ is analytic:
                    <div class="math-display">
                        $$\frac{\partial u}{\partial x} = \frac{\partial v}{\partial y}$$
                        $$\frac{\partial u}{\partial y} = -\frac{\partial v}{\partial x}$$
                    </div>
                </div>
                
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Elementary Functions</h4>
                        <div class="math-display">
                            $$e^z = e^x(\cos y + i\sin y)$$
                            
                            $$\sin z = \frac{e^{iz} - e^{-iz}}{2i}$$
                            $$\cos z = \frac{e^{iz} + e^{-iz}}{2}$$
                            
                            $\log z = \ln|z| + i(\arg z + 2\pi n)$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Power Series</h4>
                        <div class="math-display">
                            $$f(z) = \sum_{n=0}^{\infty} a_n(z - z_0)^n$$
                            
                            Radius of convergence: $R = \frac{1}{\limsup_{n \to \infty} |a_n|^{1/n}}$
                            
                            Convergent for $|z - z_0| < R$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Integration & Residues</h3>
                <div class="theorem">
                    <h4>Cauchy's Theorem</h4>
                    If $f$ is analytic in simply connected domain $D$ and $C$ is a closed curve in $D$:
                    <div class="math-display">
                        $$\oint_C f(z) \, dz = 0$$
                    </div>
                </div>

                <div class="theorem">
                    <h4>Residue Theorem</h4>
                    <div class="math-display">
                        $$\oint_C f(z) \, dz = 2\pi i \sum_k \text{Res}(f, z_k)$$
                    </div>
                    where $z_k$ are poles inside $C$
                </div>
                
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Computing Residues</h4>
                        <div class="math-display">
                            Simple pole at $z_0$:
                            $$\text{Res}(f, z_0) = \lim_{z \to z_0} (z - z_0)f(z)$$
                            
                            Pole of order $n$:
                            $$\text{Res}(f, z_0) = \frac{1}{(n-1)!} \lim_{z \to z_0} \frac{d^{n-1}}{dz^{n-1}}[(z-z_0)^n f(z)]$$
                        </div>
                    </div>
                </div>

                <div class="cs-application">
                    <h5>CS Applications:</h5>
                    Signal processing (Fourier transforms), control systems, quantum computing, computer graphics (fractals), digital filters
                </div>
            </div>
        </section>

        <section id="graph" class="section">
            <h2>Graph Theory</h2>
            
            <div class="topic">
                <h3>Basic Definitions</h3>
                <div class="graph-theory-grid">
                    <div class="formula-card">
                        <h4>Graph Properties</h4>
                        <div class="math-display">
                            Graph $G = (V, E)$ where $V =$ vertices, $E =$ edges
                            
                            Order: $|V|$ (number of vertices)
                            Size: $|E|$ (number of edges)
                            
                            Degree: $\deg(v) = $ number of edges incident to $v$
                            
                            Handshaking lemma: $\sum_{v \in V} \deg(v) = 2|E|$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Special Graphs</h4>
                        <div class="math-display">
                            Complete graph $K_n$: $|E| = \frac{n(n-1)}{2}$
                            
                            Complete bipartite $K_{m,n}$: $|E| = mn$
                            
                            Cycle $C_n$: $n$ vertices, $n$ edges
                            
                            Path $P_n$: $n$ vertices, $n-1$ edges
                            
                            Tree: connected, acyclic, $|E| = |V| - 1$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Matrix Representations</h4>
                        <div class="math-display">
                            Adjacency matrix $A$: $A[i,j] = 1$ if edge $(i,j)$ exists
                            
                            Incidence matrix: rows = vertices, columns = edges
                            
                            Number of walks of length $k$ from $i$ to $j$: $(A^k)[i,j]$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Connectivity</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Paths & Cycles</h4>
                        <div class="math-display">
                            Walk: sequence of vertices $v_0, v_1, \ldots, v_k$
                            
                            Trail: walk with distinct edges
                            
                            Path: walk with distinct vertices
                            
                            Connected: path exists between any two vertices
                            
                            Distance $d(u,v)$: length of shortest path from $u$ to $v$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Euler & Hamilton</h4>
                        <div class="math-display">
                            Eulerian path: uses every edge exactly once
                            Exists iff graph connected and $\leq 2$ odd-degree vertices
                            
                            Eulerian cycle: closed Eulerian path
                            Exists iff graph connected and all vertices even degree
                            
                            Hamiltonian path: visits every vertex exactly once
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Trees & Spanning Trees</h3>
                <div class="theorem">
                    <h4>Tree Properties</h4>
                    For a graph $G$ with $n$ vertices, these are equivalent:
                    <div class="math-display">
                        1. $G$ is a tree
                        2. $G$ is connected and has $n-1$ edges
                        3. $G$ is acyclic and has $n-1$ edges
                        4. $G$ is connected and removing any edge disconnects it
                        5. $G$ is acyclic and adding any edge creates exactly one cycle
                    </div>
                </div>
                
                <div class="algorithm-box">
                    <h5>Kruskal's Algorithm (Minimum Spanning Tree)</h5>
                    <div class="code-block">
                        1. Sort edges by weight
                        2. Initialize disjoint sets for each vertex
                        3. For each edge (u,v):
                           - If u and v in different components:
                             - Add edge to MST
                             - Union components of u and v
                        4. Stop when n-1 edges added
                        
                        Time complexity: O(E log E)
                    </div>
                </div>
                
                <div class="algorithm-box">
                    <h5>Prim's Algorithm</h5>
                    <div class="code-block">
                        1. Start with arbitrary vertex
                        2. Maintain priority queue of edges from current tree
                        3. Repeatedly add minimum weight edge that connects
                           tree to new vertex
                        4. Update priority queue
                        
                        Time complexity: O(E log V) with binary heap
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Shortest Paths</h3>
                <div class="algorithm-box">
                    <h5>Dijkstra's Algorithm</h5>
                    <div class="code-block">
                        1. Initialize distances: d[source] = 0, d[v] = ∞ for v ≠ source
                        2. Priority queue Q with all vertices
                        3. While Q not empty:
                           - u = extract minimum from Q
                           - For each neighbor v of u:
                             - If d[u] + weight(u,v) < d[v]:
                               - d[v] = d[u] + weight(u,v)
                               - parent[v] = u
                        
                        Time: O((V + E) log V) with binary heap
                        Requirements: non-negative weights
                    </div>
                </div>
                
                <div class="algorithm-box">
                    <h5>Bellman-Ford Algorithm</h5>
                    <div class="code-block">
                        1. Initialize distances: d[source] = 0, d[v] = ∞ for v ≠ source
                        2. For i = 1 to |V| - 1:
                           - For each edge (u,v):
                             - If d[u] + weight(u,v) < d[v]:
                               - d[v] = d[u] + weight(u,v)
                        3. Check for negative cycles
                        
                        Time: O(VE)
                        Handles negative weights
                    </div>
                </div>
                
                <div class="algorithm-box">
                    <h5>Floyd-Warshall Algorithm</h5>
                    <div class="code-block">
                        1. Initialize distance matrix D
                        2. For k = 1 to n:
                           - For i = 1 to n:
                             - For j = 1 to n:
                               - D[i][j] = min(D[i][j], D[i][k] + D[k][j])
                        
                        Time: O(V³)
                        Finds all-pairs shortest paths
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Network Flow</h3>
                <div class="theorem">
                    <h4>Max-Flow Min-Cut Theorem</h4>
                    In any flow network, the maximum value of flow equals the minimum capacity of all cuts.
                </div>
                
                <div class="algorithm-box">
                    <h5>Ford-Fulkerson Method</h5>
                    <div class="code-block">
                        1. Initialize flow f = 0
                        2. While there exists augmenting path P from source to sink:
                           - Find bottleneck capacity c along P
                           - Augment flow along P by c
                           - Update residual graph
                        3. Return maximum flow
                        
                        Time: O(E × max_flow) for integer capacities
                        With Edmonds-Karp (BFS): O(VE²)
                    </div>
                </div>

                <div class="cs-application">
                    <h5>CS Applications:</h5>
                    Social networks, internet routing, database optimization, compiler optimization, bioinformatics, recommendation systems
                </div>
            </div>

            <div class="topic">
                <h3>Graph Coloring</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Chromatic Number</h4>
                        <div class="math-display">
                            $\chi(G) = $ minimum number of colors needed
                            
                            $\chi(K_n) = n$
                            
                            $\chi(C_n) = 2$ if $n$ even, $3$ if $n$ odd
                            
                            $\chi(\text{bipartite graph}) = 2$
                            
                            Four Color Theorem: $\chi(\text{planar graph}) \leq 4$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Greedy Coloring</h4>
                        <div class="math-display">
                            Brooks' Theorem: If $G$ connected, not complete, not odd cycle, then $\chi(G) \leq \Delta(G)$
                            
                            where $\Delta(G) = $ maximum degree
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <section id="number" class="section">
            <h2>Number Theory</h2>
            
            <div class="topic">
                <h3>Divisibility & GCD</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Division Algorithm</h4>
                        <div class="math-display">
                            For integers $a, b$ with $b > 0$:
                            $$a = qb + r \text{ where } 0 \leq r < b$$
                            
                            $q = $ quotient, $r = $ remainder
                            
                            $a \equiv r \pmod{b}$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Euclidean Algorithm</h4>
                        <div class="math-display">
                            $$\gcd(a, b) = \gcd(b, a \bmod b)$$
                            
                            Extended Euclidean Algorithm:
                            $$\gcd(a, b) = ax + by$$
                            for some integers $x, y$
                            
                            Time complexity: $O(\log \min(a, b))$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Properties</h4>
                        <div class="math-display">
                            $$\gcd(a, b) \times \text{lcm}(a, b) = ab$$
                            
                            If $\gcd(a, n) = 1$ and $\gcd(b, n) = 1$,
                            then $\gcd(ab, n) = 1$
                            
                            Bézout's identity: $\gcd(a, b) = ax + by$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Modular Arithmetic</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Congruences</h4>
                        <div class="math-display">
                            $a \equiv b \pmod{n}$ iff $n \mid (a - b)$
                            
                            Properties:
                            $(a + b) \bmod n = ((a \bmod n) + (b \bmod n)) \bmod n$
                            
                            $(a \times b) \bmod n = ((a \bmod n) \times (b \bmod n)) \bmod n$
                            
                            Reflexive: $a \equiv a \pmod{n}$
                            Symmetric: $a \equiv b \implies b \equiv a \pmod{n}$
                            Transitive: $a \equiv b, b \equiv c \implies a \equiv c \pmod{n}$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Modular Inverse</h4>
                        <div class="math-display">
                            $a^{-1} \pmod{n}$ exists iff $\gcd(a, n) = 1$
                            
                            Finding inverse: use Extended Euclidean Algorithm
                            $ax + ny = 1 \implies ax \equiv 1 \pmod{n} \implies a^{-1} \equiv x \pmod{n}$
                            
                            Fermat's Little Theorem: If $p$ prime, $\gcd(a, p) = 1$:
                            $$a^{-1} \equiv a^{p-2} \pmod{p}$$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Prime Numbers</h3>
                <div class="theorem">
                    <h4>Fundamental Theorem of Arithmetic</h4>
                    Every integer $n > 1$ has a unique prime factorization:
                    <div class="math-display">
                        $$n = p_1^{a_1} \times p_2^{a_2} \times \cdots \times p_k^{a_k}$$
                    </div>
                    where $p_1 < p_2 < \cdots < p_k$ are primes and $a_i > 0$
                </div>
                
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Prime Testing</h4>
                        <div class="math-display">
                            Trial division: test divisibility up to $\sqrt{n}$
                            Time: $O(\sqrt{n})$
                            
                            Sieve of Eratosthenes: find all primes $\leq n$
                            Time: $O(n \log \log n)$
                            
                            Miller-Rabin: probabilistic primality test
                            Time: $O(k \log^3 n)$ for $k$ rounds
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Prime Distribution</h4>
                        <div class="math-display">
                            Prime Number Theorem:
                            $$\pi(n) \approx \frac{n}{\ln(n)}$$
                            
                            where $\pi(n) = $ number of primes $\leq n$
                            
                            There are infinitely many primes
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Euler's Function</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Definition & Properties</h4>
                        <div class="math-display">
                            $$\varphi(n) = |\{k : 1 \leq k \leq n, \gcd(k, n) = 1\}|$$
                            
                            $\varphi(p) = p - 1$ for prime $p$
                            
                            $\varphi(p^k) = p^k - p^{k-1} = p^{k-1}(p - 1)$
                            
                            If $\gcd(m, n) = 1$: $\varphi(mn) = \varphi(m)\varphi(n)$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Euler's Theorem</h4>
                        <div class="math-display">
                            If $\gcd(a, n) = 1$, then:
                            $$a^{\varphi(n)} \equiv 1 \pmod{n}$$
                            
                            Fermat's Little Theorem (special case):
                            If $p$ prime and $\gcd(a, p) = 1$:
                            $$a^{p-1} \equiv 1 \pmod{p}$$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Chinese Remainder Theorem</h3>
                <div class="theorem">
                    <h4>CRT Statement</h4>
                    If $n_1, n_2, \ldots, n_k$ are pairwise coprime, then the system:
                    <div class="math-display">
                        $$\begin{cases}
                        x \equiv a_1 \pmod{n_1} \\
                        x \equiv a_2 \pmod{n_2} \\
                        \vdots \\
                        x \equiv a_k \pmod{n_k}
                        \end{cases}$$
                    </div>
                    has a unique solution modulo $N = n_1n_2 \cdots n_k$
                </div>
                
                <div class="algorithm-box">
                    <h5>CRT Algorithm</h5>
                    <div class="code-block">
                        1. Compute N = n₁n₂...nₖ
                        2. For each i, compute Nᵢ = N/nᵢ
                        3. Find Mᵢ such that NᵢMᵢ ≡ 1 (mod nᵢ)
                        4. Solution: x ≡ Σ aᵢNᵢMᵢ (mod N)
                    </div>
                </div>

                <div class="cs-application">
                    <h5>CS Applications:</h5>
                    Cryptography (RSA, ElGamal), hash functions, pseudorandom number generation, error-correcting codes, computer algebra
                </div>
            </div>
        </section>

        <section id="algorithms" class="section">
            <h2>Algorithm Analysis</h2>
            
            <div class="topic">
                <h3>Asymptotic Notation</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Big O Notation</h4>
                        <div class="math-display">
                            $f(n) = O(g(n))$ if $\exists c > 0, n_0$ such that
                            $f(n) \leq c \cdot g(n)$ for all $n \geq n_0$
                            
                            Upper bound: $f$ grows no faster than $g$
                            
                            $f(n) = \Omega(g(n))$ if $g(n) = O(f(n))$
                            Lower bound: $f$ grows at least as fast as $g$
                            
                            $f(n) = \Theta(g(n))$ if $f(n) = O(g(n))$ and $f(n) = \Omega(g(n))$
                            Tight bound: $f$ and $g$ grow at same rate
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Common Complexities</h4>
                        <div class="math-display">
                            $$O(1) < O(\log n) < O(n) < O(n \log n) < O(n^2) < O(n^3) < O(2^n) < O(n!)$$
                            
                            Logarithmic: binary search, balanced tree operations
                            Linear: linear search, single loop
                            Linearithmic: merge sort, heap sort
                            Quadratic: nested loops, simple sorting
                            Exponential: brute force subsets
                            Factorial: brute force permutations
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Sorting Algorithms</h3>
                
                <table class="complexity-table">
                    <thead>
                        <tr>
                            <th>Algorithm</th>
                            <th>Best Case</th>
                            <th>Average Case</th>
                            <th>Worst Case</th>
                            <th>Space</th>
                            <th>Stable</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>Bubble Sort</td>
                            <td>O(n)</td>
                            <td>O(n²)</td>
                            <td>O(n²)</td>
                            <td>O(1)</td>
                            <td>Yes</td>
                        </tr>
                        <tr>
                            <td>Selection Sort</td>
                            <td>O(n²)</td>
                            <td>O(n²)</td>
                            <td>O(n²)</td>
                            <td>O(1)</td>
                            <td>No</td>
                        </tr>
                        <tr>
                            <td>Insertion Sort</td>
                            <td>O(n)</td>
                            <td>O(n²)</td>
                            <td>O(n²)</td>
                            <td>O(1)</td>
                            <td>Yes</td>
                        </tr>
                        <tr>
                            <td>Merge Sort</td>
                            <td>O(n log n)</td>
                            <td>O(n log n)</td>
                            <td>O(n log n)</td>
                            <td>O(n)</td>
                            <td>Yes</td>
                        </tr>
                        <tr>
                            <td>Quick Sort</td>
                            <td>O(n log n)</td>
                            <td>O(n log n)</td>
                            <td>O(n²)</td>
                            <td>O(log n)</td>
                            <td>No</td>
                        </tr>
                        <tr>
                            <td>Heap Sort</td>
                            <td>O(n log n)</td>
                            <td>O(n log n)</td>
                            <td>O(n log n)</td>
                            <td>O(1)</td>
                            <td>No</td>
                        </tr>
                        <tr>
                            <td>Counting Sort</td>
                            <td>O(n + k)</td>
                            <td>O(n + k)</td>
                            <td>O(n + k)</td>
                            <td>O(k)</td>
                            <td>Yes</td>
                        </tr>
                        <tr>
                            <td>Radix Sort</td>
                            <td>O(d(n + k))</td>
                            <td>O(d(n + k))</td>
                            <td>O(d(n + k))</td>
                            <td>O(n + k)</td>
                            <td>Yes</td>
                        </tr>
                    </tbody>
                </table>
            </div>

            <div class="topic">
                <h3>Search Algorithms</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Binary Search</h4>
                        <div class="math-display">
                            Prerequisite: sorted array
                            
                            Algorithm:
                            ```
                            while low ≤ high:
                                mid = (low + high) / 2
                                if arr[mid] == target: return mid
                                elif arr[mid] < target: low = mid + 1
                                else: high = mid - 1
                            ```
                            
                            Time: $O(\log n)$, Space: $O(1)$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Hash Table Search</h4>
                        <div class="math-display">
                            Average case: $O(1)$ for search, insert, delete
                            Worst case: $O(n)$ if many collisions
                            
                            Load factor $\alpha = \frac{n}{m}$ (items/buckets)
                            Keep $\alpha < 0.75$ for good performance
                            
                            Collision resolution: chaining, open addressing
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Dynamic Programming</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Optimal Substructure</h4>
                        <div class="math-display">
                            A problem has optimal substructure if optimal solution contains optimal solutions to subproblems
                            
                            Examples: shortest paths, matrix chain multiplication, optimal binary search trees, edit distance
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Overlapping Subproblems</h4>
                        <div class="math-display">
                            Recursive algorithm solves same subproblems repeatedly
                            
                            Memoization: top-down approach, store results
                            Tabulation: bottom-up approach, fill table
                            
                            Fibonacci: naive $O(2^n)$, DP $O(n)$
                        </div>
                    </div>
                </div>
                
                <div class="algorithm-box">
                    <h5>Classic DP Problems</h5>
                    <div class="code-block">
                        Knapsack Problem: max value with weight constraint
                        DP[i][w] = max value using first i items, weight ≤ w
                        
                        Longest Common Subsequence:
                        LCS[i][j] = length of LCS of first i chars of X, first j chars of Y
                        
                        Edit Distance (Levenshtein):
                        ED[i][j] = min operations to transform X[1..i] to Y[1..j]
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Greedy Algorithms</h3>
                <div class="important">
                    <h5>Greedy Choice Property</h5>
                    Global optimum can be reached by making locally optimal choices at each step
                </div>
                
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Activity Selection</h4>
                        <div class="math-display">
                            Select maximum number of non-overlapping activities
                            
                            Greedy strategy: sort by finish time, always pick earliest finishing activity
                            
                            Time: $O(n \log n)$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Huffman Coding</h4>
                        <div class="math-display">
                            Optimal prefix-free binary codes
                            
                            Greedy strategy: repeatedly merge two nodes with minimum frequency
                            
                            Time: $O(n \log n)$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Complexity Classes</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>P vs NP</h4>
                        <div class="math-display">
                            P: problems solvable in polynomial time
                            NP: problems verifiable in polynomial time
                            NP-Complete: hardest problems in NP
                            NP-Hard: at least as hard as NP-Complete
                            
                            $P \subseteq NP$, but $P = NP$? is open question
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Reduction</h4>
                        <div class="math-display">
                            Problem $A$ reduces to $B$ ($A \leq_p B$) if $A$ can be solved using polynomial number of calls to $B$
                            
                            If $A \leq_p B$ and $B \in P$, then $A \in P$
                            
                            Used to prove NP-completeness
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <section id="crypto" class="section">
            <h2>Cryptography</h2>
            
            <div class="topic">
                <h3>Classical Cryptography</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Caesar Cipher</h4>
                        <div class="math-display">
                            Encryption: $E(x) = (x + k) \bmod 26$
                            Decryption: $D(y) = (y - k) \bmod 26$
                            
                            Key space: 26 possible keys
                            Vulnerable to frequency analysis
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Affine Cipher</h4>
                        <div class="math-display">
                            Encryption: $E(x) = (ax + b) \bmod 26$
                            Decryption: $D(y) = a^{-1}(y - b) \bmod 26$
                            
                            Requirement: $\gcd(a, 26) = 1$
                            Key space: $\varphi(26) \times 26 = 12 \times 26 = 312$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Vigenère Cipher</h4>
                        <div class="math-display">
                            Encryption: $C_i = (M_i + K_{i \bmod \text{keylen}}) \bmod 26$
                            
                            Polyalphabetic substitution
                            
                            Broken by Kasiski examination and index of coincidence
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Public Key Cryptography</h3>
                <div class="theorem">
                    <h4>RSA Algorithm</h4>
                    <div class="math-display">
                        Key Generation:
                        1. Choose large primes $p, q$
                        2. $n = pq$, $\varphi(n) = (p-1)(q-1)$
                        3. Choose $e$: $\gcd(e, \varphi(n)) = 1$
                        4. Find $d$: $ed \equiv 1 \pmod{\varphi(n)}$
                        
                        Public key: $(n, e)$
                        Private key: $(n, d)$
                        
                        Encryption: $C = M^e \bmod n$
                        Decryption: $M = C^d \bmod n$
                    </div>
                </div>
                
                <div class="proof-sketch">
                    <strong>Why RSA works:</strong> By Euler's theorem, if $\gcd(M, n) = 1$, then $M^{\varphi(n)} \equiv 1 \pmod{n}$. 
                    Since $ed \equiv 1 \pmod{\varphi(n)}$, we have $ed = 1 + k\varphi(n)$ for some $k$. 
                    Therefore: $(M^e)^d = M^{ed} = M^{1+k\varphi(n)} = M \cdot (M^{\varphi(n)})^k \equiv M \cdot 1^k = M \pmod{n}$
                </div>
                
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Diffie-Hellman Key Exchange</h4>
                        <div class="math-display">
                            Public: prime $p$, generator $g$
                            
                            Alice: chooses $a$, sends $g^a \bmod p$
                            Bob: chooses $b$, sends $g^b \bmod p$
                            
                            Shared secret: $K = g^{ab} \bmod p$
                            
                            Security based on discrete log problem
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>ElGamal Encryption</h4>
                        <div class="math-display">
                            Key Generation:
                            Choose prime $p$, generator $g$, private key $x$
                            Public key: $y = g^x \bmod p$
                            
                            Encryption of $M$:
                            Choose random $k$, send $(g^k \bmod p, M \cdot y^k \bmod p)$
                            
                            Decryption: $M = c_2 \cdot (c_1^x)^{-1} \bmod p$
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Hash Functions</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Properties</h4>
                        <div class="math-display">
                            Pre-image resistance: given $h$, hard to find $x$ with $H(x) = h$
                            
                            Second pre-image resistance: given $x$, hard to find $x' \neq x$ with $H(x) = H(x')$
                            
                            Collision resistance: hard to find $x, x'$ with $H(x) = H(x')$
                            
                            Birthday paradox: expect collision after $\sqrt{2^n}$ inputs for $n$-bit hash
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Applications</h4>
                        <div class="math-display">
                            Digital signatures: sign hash instead of message
                            
                            Password storage: store $H(\text{password} + \text{salt})$
                            
                            Proof of work: find nonce with $H(\text{block} + \text{nonce}) < \text{target}$
                            
                            Data integrity: compare hash values
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Digital Signatures</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>RSA Signatures</h4>
                        <div class="math-display">
                            Signing: $S = H(M)^d \bmod n$
                            
                            Verification: check if $S^e \equiv H(M) \pmod{n}$
                            
                            Must use padding (PSS) to prevent attacks
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>DSA (Digital Signature Algorithm)</h4>
                        <div class="math-display">
                            Parameters: prime $p$, $q \mid (p-1)$, generator $g$
                            Private key: $x$, Public key: $y = g^x \bmod p$
                            
                            Signing $M$:
                            $k = $ random, $r = (g^k \bmod p) \bmod q$
                            $s = k^{-1}(H(M) + xr) \bmod q$
                            Signature: $(r, s)$
                            
                            Verification: check if $r = ((g^{H(M)s^{-1}} \cdot y^{rs^{-1}}) \bmod p) \bmod q$
                        </div>
                    </div>
                </div>

                <div class="cs-application">
                    <h5>CS Applications:</h5>
                    Secure communications, blockchain technology, password authentication, digital certificates, software signing, cryptocurrency
                </div>
            </div>
        </section>

        <section id="optimization" class="section">
            <h2>Optimization</h2>
            
            <div class="topic">
                <h3>Linear Programming</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Standard Form</h4>
                        <div class="math-display">
                            Minimize: $\mathbf{c}^T \mathbf{x}$
                            Subject to: $A\mathbf{x} = \mathbf{b}$, $\mathbf{x} \geq \mathbf{0}$
                            
                            Can convert any LP to standard form:
                            - $\max f \rightarrow \min(-f)$
                            - inequality $\rightarrow$ equality (add slack variables)
                            - unrestricted variable $\rightarrow$ difference of non-negative variables
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Simplex Method</h4>
                        <div class="math-display">
                            1. Start at basic feasible solution (vertex of polytope)
                            2. Check optimality conditions
                            3. If not optimal, move to adjacent vertex that improves objective
                            4. Repeat until optimal or unbounded
                            
                            Worst case: exponential
                            Average case: polynomial
                        </div>
                    </div>
                </div>
                
                <div class="theorem">
                    <h4>Fundamental Theorem of Linear Programming</h4>
                    If LP has optimal solution, then it has optimal basic feasible solution (vertex of feasible region)
                </div>
                
                <div class="theorem">
                    <h4>Duality Theorem</h4>
                    <div class="math-display">
                        Primal: $\min \mathbf{c}^T \mathbf{x}$ subject to $A\mathbf{x} \geq \mathbf{b}$, $\mathbf{x} \geq \mathbf{0}$
                        
                        Dual: $\max \mathbf{b}^T \mathbf{y}$ subject to $A^T \mathbf{y} \leq \mathbf{c}$, $\mathbf{y} \geq \mathbf{0}$
                        
                        Strong duality: if both have optimal solutions, optimal values are equal
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Nonlinear Optimization</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Unconstrained Optimization</h4>
                        <div class="math-display">
                            First-order condition: $\nabla f(\mathbf{x}^*) = \mathbf{0}$
                            
                            Second-order condition: $\nabla^2 f(\mathbf{x}^*)$ positive definite
                            
                            Gradient descent: $\mathbf{x}_{k+1} = \mathbf{x}_k - \alpha_k \nabla f(\mathbf{x}_k)$
                            
                            Newton's method: $\mathbf{x}_{k+1} = \mathbf{x}_k - [\nabla^2 f(\mathbf{x}_k)]^{-1} \nabla f(\mathbf{x}_k)$
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Constrained Optimization</h4>
                        <div class="math-display">
                            KKT conditions for $\min f(\mathbf{x})$ subject to $g(\mathbf{x}) \leq \mathbf{0}$, $h(\mathbf{x}) = \mathbf{0}$:
                            
                            $\nabla f(\mathbf{x}^*) + \sum_i \lambda_i \nabla g_i(\mathbf{x}^*) + \sum_j \mu_j \nabla h_j(\mathbf{x}^*) = \mathbf{0}$
                            
                            $g_i(\mathbf{x}^*) \leq 0$, $h_j(\mathbf{x}^*) = 0$
                            
                            $\lambda_i \geq 0$, $\lambda_i g_i(\mathbf{x}^*) = 0$ (complementary slackness)
                        </div>
                    </div>
                </div>
            </div>

            <div class="topic">
                <h3>Convex Optimization</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Convex Sets & Functions</h4>
                        <div class="math-display">
                            Convex set: $\forall \mathbf{x}, \mathbf{y} \in S, \forall \lambda \in [0,1]: \lambda\mathbf{x} + (1-\lambda)\mathbf{y} \in S$
                            
                            Convex function: $f(\lambda\mathbf{x} + (1-\lambda)\mathbf{y}) \leq \lambda f(\mathbf{x}) + (1-\lambda)f(\mathbf{y})$
                            
                            Properties:
                            - Local minimum = global minimum
                            - First-order condition sufficient for optimality
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Interior Point Methods</h4>
                        <div class="math-display">
                            Barrier method: replace constraints $g(\mathbf{x}) \leq \mathbf{0}$ with penalty terms $-t \sum_i \log(-g_i(\mathbf{x}))$
                            
                            As $t \to \infty$, solution approaches constrained optimum
                            
                            Polynomial time complexity for convex problems
                        </div>
                    </div>
                </div>

                <div class="cs-application">
                    <h5>CS Applications:</h5>
                    Machine learning (SVM, neural network training), resource allocation, network flow optimization, compiler optimization, game theory
                </div>
            </div>

            <div class="topic">
                <h3>Integer Programming</h3>
                <div class="formula-grid">
                    <div class="formula-card">
                        <h4>Branch and Bound</h4>
                        <div class="math-display">
                            1. Solve LP relaxation
                            2. If solution integer, update best bound
                            3. If not integer, branch on fractional variable
                            4. Recursively solve subproblems
                            5. Prune if bound worse than current best
                            
                            NP-hard in general, but practical for many instances
                        </div>
                    </div>
                    
                    <div class="formula-card">
                        <h4>Cutting Planes</h4>
                        <div class="math-display">
                            Add linear constraints (cuts) that remove fractional solutions but preserve all integer solutions
                            
                            Gomory cuts: derived from optimal LP tableau
                            
                            Problem-specific cuts often more effective
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <div class="section">
            <h2 class="highlight">Mathematical Software & Tools</h2>
            
            <div class="formula-grid">
                <div class="formula-card">
                    <h4>Symbolic Computation</h4>
                    <div class="math-display">
                        Mathematica, Maple, SymPy (Python)
                        
                        Exact arithmetic, symbolic integration/differentiation,
                        equation solving, simplification
                        
                        Computer algebra systems
                    </div>
                </div>
                
                <div class="formula-card">
                    <h4>Numerical Computing</h4>
                    <div class="math-display">
                        MATLAB, NumPy/SciPy (Python), R
                        
                        Linear algebra (BLAS, LAPACK)
                        Optimization (CPLEX, Gurobi)
                        Statistics and data analysis
                    </div>
                </div>
                
                <div class="formula-card">
                    <h4>Proof Assistants</h4>
                    <div class="math-display">
                        Coq, Lean, Agda, Isabelle/HOL
                        
                        Formal verification of mathematical proofs
                        Computer-checked mathematics
                        Growing importance in CS theory
                    </div>
                </div>
                
                <div class="formula-card">
                    <h4>Computational Complexity</h4>
                    <div class="math-display">
                        Complexity Zoo: database of complexity classes
                        
                        P, NP, PSPACE, EXPTIME, etc.
                        Reductions and completeness results
                        Interactive proofs, quantum complexity
                    </div>
                </div>
            </div>
            
            <div class="important">
                <h5>Study Strategy for Advanced Math in CS:</h5>
                Focus on applications: understand how each mathematical concept applies to computer science problems. 
                Practice implementation: code algorithms and verify theoretical results computationally.
                Connect concepts: see relationships between different mathematical areas and their CS applications.
                Stay current: mathematics in CS is rapidly evolving, especially in machine learning and quantum computing.
            </div>
        </div>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            // Initialize KaTeX auto-render
            renderMathInElement(document.body, {
                delimiters: [
                    {left: '$', right: '$', display: true},
                    {left: ', right: ', display: false},
                    {left: '\\(', right: '\\)', display: false},
                    {left: '\\[', right: '\\]', display: true}
                ],
                throwOnError: false
            });

            // Smooth scrolling for navigation
            document.querySelectorAll('.nav-link, .nav-card a').forEach(link => {
                link.addEventListener('click', function(e) {
                    e.preventDefault();
                    const targetId = this.getAttribute('href');
                    const target = document.querySelector(targetId);
                    if (target) {
                        target.scrollIntoView({ behavior: 'smooth', block: 'start' });
                    }
                });
            });

            // Add hover effects to cards
            document.querySelectorAll('.formula-card, .theorem, .algorithm-box').forEach(card => {
                card.addEventListener('mouseenter', function() {
                    this.style.transform = 'translateY(-2px)';
                    this.style.boxShadow = '0 4px 15px rgba(0, 0, 0, 0.15)';
                    this.style.transition = 'all 0.3s ease';
                });
                
                card.addEventListener('mouseleave', function() {
                    this.style.transform = 'translateY(0)';
                    this.style.boxShadow = '0 2px 8px rgba(0, 0, 0, 0.08)';
                });
            });

            // Highlight active navigation item
            const observer = new IntersectionObserver((entries) => {
                entries.forEach(entry => {
                    if (entry.isIntersecting) {
                        const id = entry.target.id;
                        document.querySelectorAll('.nav-link').forEach(link => {
                            link.classList.remove('active');
                            if (link.getAttribute('href') === `#${id}`) {
                                link.style.background = '#f0f0f0';
                                link.style.color = '#000000';
                            } else {
                                link.style.background = '';
                                link.style.color = '#000000';
                            }
                        });
                    }
                });
            }, { threshold: 0.1 });

            document.querySelectorAll('.section').forEach(section => {
                observer.observe(section);
            });
        });
    </script>
</body>
</html>