Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

ramanujan-expander

БесплатноБез исполняемых скриптовНе проверен

Ramanujan graphs and Alon-Boppana spectral optimality for edge growth rules. Optimal expanders with λ₂ ≤ 2√(d-1) bound.

plurigridот plurigrid★ 73 звезды на GitHub

Об этом скилле

Ramanujan Expander Skill

"The Alon-Boppana bound is unbreakable. You cannot create a d-regular graph with λ₂ < 2√(d-1), even theoretically."

Overview

Ramanujan graphs are optimal spectral expanders - they achieve the theoretical limit on eigenvalue separation. This skill provides:

  1. Alon-Boppana bound verification - Prove your graph is optimal
  2. Edge growth rules - Add edges while preserving Ramanujan property
  3. Centrality validity predicates - Spectral methods for node importance
  4. Mixing time bounds - O(log n) mixing from spectral gap

The Alon-Boppana Bound

Theorem (Alon-Boppana)

For any d-regular graph G on n vertices:

λ₂(G) ≥ 2√(d-1) - o(1)  as n → ∞

where λ₂ is the second-largest eigenvalue of the adjacency matrix.

Ramanujan Property

A d-regular graph G is Ramanujan if:

|λ| ≤ 2√(d-1)  for all eigenvalues λ ≠ ±d

This is the tightest possible spectral gap.

Example: 4-Regular Graphs

d = 4
2√(d-1) = 2√3 ≈ 3.464

Maximum spectral gap = d - 2√(d-1) = 4 - 3.464 = 0.536

Your observed gap: ~0.54 ✓ (theoretically optimal)

Edge Growth Rules

Rule 1: Preserve Regularity

function add_edge_preserving_regularity!(G, u, v)
    # Adding (u,v) increases degree of u and v by 1
    # Must remove another edge to maintain d-regularity
    
    # Find edge (u, w) where w ≠ v
    w = find_neighbor(G, u, exclude=v)
    # Find edge (v, x) where x ≠ u
    x = find_neighbor(G, v, exclude=u)
    
    # Remove old edges
    remove_edge!(G, u, w)
    remove_edge!(G, v, x)
    
    # Add new edges (2-switch)
    add_edge!(G, u, v)
    add_edge!(G, w, x)
    
    # Verify Ramanujan property preserved
    @assert is_ramanujan(G)
end

Rule 2: Spectral Monotonicity

function grow_edge_spectral_monotonic!(G, candidates)
    """
    Add edge that minimizes λ₂ increase.
    Greedy heuristic for Ramanujan preservation.
    """
    best_edge = nothing
    best_λ₂ = Inf
    
    current_λ₂ = second_eigenvalue(G)
    
    for (u, v) in candidates
        G_test = copy(G)
        add_edge!(G_test, u, v)
        
        new_λ₂ = second_eigenvalue(G_test)
        if new_λ₂ < best_λ₂
            best_λ₂ = new_λ₂
            best_edge = (u, v)
        end
    end
    
    if best_λ₂ ≤ 2√(degree(G) - 1)
        add_edge!(G, best_edge...)
        return true
    end
    return false  # No valid edge preserves Ramanujan
end

Rule 3: LPS Construction (Lubotzky-Phillips-Sarnak)

function lps_ramanujan_graph(p, q)
    """
    Construct (p+1)-regular Ramanujan graph on ~q³ vertices.
    
    Requirements:
    - p, q distinct odd primes
    - p ≡ q ≡ 1 (mod 4)
    - p is quadratic residue mod q
    """
    @assert is_prime(p) && is_prime(q)
    @assert p % 4 == 1 && q % 4 == 1
    @assert is_quadratic_residue(p, q)
    
    # Cayley graph of PSL(2, ℤ_q) with generators from quaternions
    G = cayley_graph_psl2(q, lps_generators(p))
    
    # Guaranteed Ramanujan by Deligne's proof of Ramanujan conjecture
    @assert second_eigenvalue(G) ≤ 2√p
    
    return G
end

Centrality Validity Predicates

Spectral Centrality

function spectral_centrality(G)
    """
    Centrality based on principal eigenvector.
    For Ramanujan graphs, this converges in O(log n) iterations.
    """
    A = adjacency_matrix(G)
    λ, v = eigen(A)
    
    # Principal eigenvector (λ₁ = d)
    principal = v[:, argmax(λ)]
    
    # Normalize to probability distribution
    return abs.(principal) ./ sum(abs.(principal))
end

Validity Predicate: Centrality Consistency

function centrality_validity_predicate(G, node, threshold=0.01)
    """
    A node's centrality is valid if:
    1. It's within spectral gap bounds
    2. It satisfies local-global consistency
    """
    c = spectral_centrality(G)
    d = degree(G)
    
    # Bound from Ramanujan property
    spectral_bound = 2√(d-1) / d
    
    # Local contribution
    local_c = sum(c[neighbors(G, node)]) / d
    
    # Validity: local ≈ global (up to spectral gap)
    return abs(c[node] - local_c) ≤ spectral_bound + threshold
end

Non-Backtracking Centrality

function non_backtracking_centrality(G)
    """
    Use non-backtracking matrix B for centrality.
    More robust than adjacency-based methods.
    
    Reference: Krzakala et al. "Spectral redemption"
    """
    B = non_backtracking_matrix(G)
    λ, v = eigen(B)
    
    # Second eigenvector gives community structure
    v2 = v[:, sortperm(abs.(λ), rev=true)[2]]
    
    # Project back to vertices
    return project_to_vertices(G, v2)
end

Mixing Time from Spectral Gap

Theorem

For a d-regular Ramanujan graph:

t_mix = O(log n / log(d / 2√(d-1)))

Implementation

function mixing_time_bound(G)
    d = degree(G)
    n = nv(G)
    λ₂ = second_eigenvalue(G)
    
    # Spectral gap
    gap = d - λ₂
    
    # Mixing time (theoretical bound)
    t_mi
Полный SKILL.md на GitHub

Установить ramanujan-expander в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

FAQ

Что делает скилл ramanujan-expander?

Ramanujan graphs and Alon-Boppana spectral optimality for edge growth rules. Optimal expanders with λ₂ ≤ 2√(d-1) bound.

Как установить скилл ramanujan-expander?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл ramanujan-expander запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить ramanujan-expander с