Skip to content
homoiconic-rewriting logo

Homoiconic Rewriting

homoiconic-rewriting

Unified homoiconic graph rewriting - λ-calculus, interaction nets, ACSets, CUDA parallelism

plurigrid/asi0installs67starsOther

SKILL.md

Full skill instructions

Homoiconic Rewriting

Code = Data = Graph = Parallel Reduction

Trit: 0 (ERGODIC - coordinates the stack)

Core Synthesis

┌─────────────────────────────────────────────────────────────────┐
│              HOMOICONIC REWRITING PIPELINE                      │
├─────────────────────────────────────────────────────────────────┤
│                                                                  │
│   λ-term ──quote──→ S-exp ──parse──→ INet ──CUDA──→ Result     │
│     │                  │               │              │         │
│   typed              data            graph         parallel     │
│   code            (homoiconic)     rewriting      reduction     │
│                                                                  │
└─────────────────────────────────────────────────────────────────┘

GF(3) Balanced Dependencies

TritSkillRole
+1lambda-calculusTerm generation
+1gay-mcpColor generation
0interaction-netsParallel coordination
0lispsyntax-acsetData bridge
-1algebraic-rewritingRule validation
-1slime-lispEvaluation sink

Sum: (+1+1) + (0+0) + (-1-1) = 0 ✓

The Homoiconic Property

Level 1: S-expressions (Lisp)

;; Code
(+ 1 2)

;; Data (same representation!)
'(+ 1 2)

;; Transform code as data
(map inc '(+ 1 2))  ; → (1 2 3)

Level 2: Interaction Nets (Graphs)

Code (λ-term):     Data (graph):         Rewrite (reduction):
  λx. x x          ┌───┐                 ┌───┐     ┌───┐
                   │ λ │──┬──┐           │ @ │─────│ @ │
                   └─┬─┘  │  │           └─┬─┘     └─┬─┘
                     │    │  │             │         │
                   ┌─┴─┐  │  │     →       └────┬────┘
                   │ @ │──┘  │                  │
                   └─┬─┘     │               result
                     └───────┘

Level 3: ACSets (Algebraic Databases)

# Code: rewrite rule
rule = Rule(L, K, R)

# Data: same representation!
rule_data = @acset RuleSchema begin
    L = [...]; K = [...]; R = [...]
end

# Transform rules as data
composed_rule = compose_rules(rule1, rule2)

Key Algorithms

1. λ → Interaction Net Compilation

function compile_lambda_to_inet(term::LambdaTerm)::InteractionNet
    match term
        Var(x)      => wire_to(x)
        Lam(x, body) => agent(:λ, [x], compile(body))
        App(f, arg)  => agent(:@, [compile(f), compile(arg)])
    end
end

2. Parallel Reduction (CUDA-ready)

function parallel_reduce!(net::InteractionNet)
    while has_active_pairs(net)
        # Find all independent redexes (no shared wires)
        active = find_active_pairs(net)
        
        # Reduce ALL in parallel - no dependencies!
        @cuda threads=length(active) reduce_kernel!(net, active)
    end
end

3. ACSet Rewriting (DPO)

using AlgebraicRewriting

# L ← K → R (span defines rule)
rule = Rule(
    L = @acset Graph begin V=2; E=1; src=[1]; tgt=[2] end,
    K = @acset Graph begin V=1 end,
    R = @acset Graph begin V=1; E=1; src=[1]; tgt=[1] end  # self-loop
)

# Apply via double pushout
result = rewrite(rule, graph, match)

CUDA Integration (Groote et al.)

GPU Kernel for Active Pair Reduction

__global__ void reduce_active_pairs(
    Agent* agents,
    Wire* wires, 
    int* active_pairs,
    int n_active
) {
    int idx = blockIdx.x * blockDim.x + threadIdx.x;
    if (idx >= n_active) return;
    
    int pair_id = active_pairs[idx];
    Agent* a1 = &agents[wires[pair_id].from];
    Agent* a2 = &agents[wires[pair_id].to];
    
    // Dispatch by agent types
    if (a1->type == CONSTRUCTOR && a2->type == CONSTRUCTOR) {
        annihilate(a1, a2, wires);
    } else if (a1->type == CONSTRUCTOR && a2->type == DUPLICATOR) {
        commute(a1, a2, wires, agents);
    } else if (a1->type == ERASER) {
        erase(a1, a2, wires);
    }
}

Performance (from Eindhoven team)

BenchmarkCPUGPU (RTX 3090)Speedup
Fibonacci(30)2.4s0.08s30x
Tree reduction5.1s0.12s42x
λ-calculus eval1.2s0.05s24x

Typed Decomposition

Simply Typed λ-Calculus → Linear Logic → Interaction Nets

Type System          Linear Logic         Interaction Net
────────────         ────────────         ───────────────
A → B                !A ⊸ B               λ-agent + !-box
A × B                A ⊗ B                Constructor pair
A + B                A ⊕ B                Case agent

GF(3) Type Assignment

# Types carry trits
struct TypedTerm
    term::LambdaTerm
    type::SimpleType
    trit::Int  # -1, 0, +1
end

# Conservation: well-typed terms have balanced trits
function check_gf3(t::TypedTerm)::Bool
    sum_trits(t) % 3 == 0
end

Practical Commands

# Parse λ-term to S-expression
echo "(lambda (x) (x x))" | bb -e '(read)'

# Compile to interaction net (Bend/​HVM)
bend compile program.bend -o program.hvm

# Run with GPU parallelism
hvm run program.hvm --cuda

# Julia ACSet rewriting
julia -e 'using AlgebraicRewriting; include("rewrite_rules.jl")'

Triadic Pipelines

Pipeline 1: λ-Calculus Optimization

lambda-calculus (+1) → interaction-nets (0) → algebraic-rewriting (-1)
     source              parallel reduce          validate result

Pipeline 2: Colored Term Rewriting

gay-mcp (+1) → lispsyntax-acset (0) → slime-lisp (-1)
  color nodes      serialize            evaluate

Pipeline 3: Full Stack

λ-term → quote → sexp → parse → inet → reduce → result → eval
  +1      0       0      0       0      -1       -1      -1
                         (balanced across pipeline)

Key Authors

AuthorContributionAffiliation
Yves LafontInteraction nets (1990)Marseille
Jan Friso GrooteGPU term rewritingTU Eindhoven
Anton WijsCUDA rewritingTU Eindhoven
Thierry Boy de la TourParallel graph rewritingCNRS Grenoble
Nathan MarzSpecter (bidirectional nav)Red Planet Labs

Literature

  1. Lafont (1990) - "Interaction Nets"
  2. Groote et al. (2022) - "Innermost many-sorted term rewriting on GPUs"
  3. Boy de la Tour & Echahed (2020) - "Parallel rewriting of attributed graphs"
  4. Mazza (2007) - "Symmetric Interaction Combinators"

Related Skills

  • lambda-calculus (+1) - Term generation
  • interaction-nets (0) - Parallel semantics
  • algebraic-rewriting (-1) - DPO/​SPO rules
  • lispsyntax-acset (0) - Sexp ↔ data bridge
  • sexp-neighborhood (0) - Sexp skill index
  • gay-mcp (+1) - Deterministic coloring

Trit: 0 (ERGODIC - coordinates the homoiconic stack) GF(3): Balanced across all pipelines

More Other skills

Delegate independent tasks to specialized agents working concurrently with isolated context.

295.4K 206.3K
View

Applies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply.

179.7K 100.1K
View

Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with colors/fonts that you can apply to any artifact that has been creating, or can generate a new theme on-the-fly.

179.7K 89.5K
View

A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill whenever asked to write some sort of internal communications (status reports, leadership updates, 3P updates, company newsletters, FAQs, incident reports, project updates, etc.).

179.7K 76.1K
View

Fundamental design principles for writing maintainable, testable Python code.

40.2K 21.9K
View

Modern responsive layouts using container queries, fluid typography, CSS Grid, and mobile-first strategies.

40.2K 20K
View

Generate Playwright tests from scenarios using interactive browser exploration and validation.

39.7K 18.2K
View

Modern React state management with Redux Toolkit, Zustand, Jotai, and React Query for every state category.

40.2K 14.7K
View

GDPR-compliant data handling with consent management, data subject rights, and privacy controls.

40.2K 14.3K
View

Python error handling patterns including input validation, exception hierarchies, and partial failure handling. Use when implementing validation logic, designing exception strategies, handling batch processing failures, or building robust APIs.

40.2K 13.5K
View

Detailed multi-file refactor planning with safety checks and rollback guidance.

39.7K 13K
View