acsets-relational-thinking

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

SKILL: ACSets Relational Thinking

SKILL: ACSets 关系型思维

Version: 2.0.0 Trit: 0 (ERGODIC) Domain: database, category-theory, rewriting Source: Topos Institute RelationalThinking Course + AlgebraicJulia

版本: 2.0.0 三元态: 0(遍历性) 领域: 数据库、范畴论、重写 来源: Topos Institute 关系型思维课程 + AlgebraicJulia

Overview

概述

ACSets (Attributed C-Sets) are functors X: C → Set where C is a small category (schema). This skill integrates:
  1. RelationalThinking Course - Topos Institute's pedagogical approach
  2. DPO Rewriting - Double Pushout graph transformation
  3. Self-Play Loop - Query → Execute → Evaluate → Refine
  4. GF(3) Conservation - Triadic skill composition

ACSets(属性C集合)是函子X: C → Set,其中C是一个小范畴(模式)。本技能整合了以下内容:
  1. 关系型思维课程 - Topos Institute的教学方法
  2. DPO重写 - 双推出图变换
  3. 自循环机制 - 查询→执行→评估→优化
  4. GF(3)守恒 - 三元技能组合

Core Concept: C-Set as Functor

核心概念:作为函子的C集合

Schema (Category C)          Instance (Functor X: C → Set)
┌─────────────────┐          ┌─────────────────────────────┐
│  E ──src──→ V   │    X     │  X(E) = {e1, e2, e3}        │
│    ←──tgt──     │   ───→   │  X(V) = {v1, v2}            │
└─────────────────┘          │  X(src): e1↦v1, e2↦v1, e3↦v2│
                             │  X(tgt): e1↦v2, e2↦v2, e3↦v1│
                             └─────────────────────────────┘

Schema (Category C)          Instance (Functor X: C → Set)
┌─────────────────┐          ┌─────────────────────────────┐
│  E ──src──→ V   │    X     │  X(E) = {e1, e2, e3}        │
│    ←──tgt──     │   ───→   │  X(V) = {v1, v2}            │
└─────────────────┘          │  X(src): e1↦v1, e2↦v1, e3↦v2│
                             │  X(tgt): e1↦v2, e2↦v2, e3↦v1│
                             └─────────────────────────────┘

Schema Definition

模式定义

Basic Graph Schema

基础图模式

julia
using Catlab.CategoricalAlgebra

@present SchGraph(FreeSchema) begin
  V::Ob                    # Vertices (object)
  E::Ob                    # Edges (object)
  src::Hom(E, V)           # Source morphism
  tgt::Hom(E, V)           # Target morphism
end

@acset_type Graph(SchGraph, index=[:src, :tgt])
julia
using Catlab.CategoricalAlgebra

@present SchGraph(FreeSchema) begin
  V::Ob                    # Vertices (object)
  E::Ob                    # Edges (object)
  src::Hom(E, V)           # Source morphism
  tgt::Hom(E, V)           # Target morphism
end

@acset_type Graph(SchGraph, index=[:src, :tgt])

Entity-Subtype Hierarchy (from RelationalThinking Ch8)

实体-子类型层级(来自《关系型思维》第8章)

julia
@present SchKitchen(FreeSchema) begin
  Entity::Ob
  
  Food::Ob
  food_in_on::Hom(Food, Entity)
  food_is_entity::Hom(Food, Entity)
  
  Kitchenware::Ob
  ware_in_on::Hom(Kitchenware, Entity)
  ware_is_entity::Hom(Kitchenware, Entity)
  
  BreadLoaf::Ob
  bread_loaf_is_food::Hom(BreadLoaf, Food)
  Knife::Ob
  knife_is_ware::Hom(Knife, Kitchenware)
end

@acset_type Kitchen(SchKitchen)

julia
@present SchKitchen(FreeSchema) begin
  Entity::Ob
  
  Food::Ob
  food_in_on::Hom(Food, Entity)
  food_is_entity::Hom(Food, Entity)
  
  Kitchenware::Ob
  ware_in_on::Hom(Kitchenware, Entity)
  ware_is_entity::Hom(Kitchenware, Entity)
  
  BreadLoaf::Ob
  bread_loaf_is_food::Hom(BreadLoaf, Food)
  Knife::Ob
  knife_is_ware::Hom(Knife, Kitchenware)
end

@acset_type Kitchen(SchKitchen)

DPO Rewriting (Double Pushout)

DPO重写(双推出)

The Pattern: L ← K → R

模式:L ← K → R

     L ←──l── K ──r──→ R
     │        │        │
match│        │        │
     ↓        ↓        ↓
     G ←───── D ──────→ H
       pushout      pushout
       complement
  • L = Find (what to match)
  • K = Keep (overlap preserved)
  • R = Replace (new structure)
  • G = Host graph
  • H = Result graph
     L ←──l── K ──r──→ R
     │        │        │
match│        │        │
     ↓        ↓        ↓
     G ←───── D ──────→ H
       pushout      pushout
       complement
  • L = 查找(要匹配的内容)
  • K = 保留(保留重叠部分)
  • R = 替换(新结构)
  • G = 宿主图
  • H = 结果图

Rule Definition

规则定义

julia
using AlgebraicRewriting
julia
using AlgebraicRewriting

Slice bread rule: adds BreadSlice when knife + loaf present

Slice bread rule: adds BreadSlice when knife + loaf present

slice_bread = @migration(SchKitchen, begin L => @join begin loaf::BreadLoaf knife::Knife end R => @join begin loaf::BreadLoaf slice::BreadSlice food_in_on(bread_slice_is_food(slice)) == food_in_on(bread_loaf_is_food(loaf)) knife::Knife end K => @join begin loaf::BreadLoaf knife::Knife end end)
rule = make_rule(slice_bread, yKitchen)
undefined
slice_bread = @migration(SchKitchen, begin L => @join begin loaf::BreadLoaf knife::Knife end R => @join begin loaf::BreadLoaf slice::BreadSlice food_in_on(bread_slice_is_food(slice)) == food_in_on(bread_loaf_is_food(loaf)) knife::Knife end K => @join begin loaf::BreadLoaf knife::Knife end end)
rule = make_rule(slice_bread, yKitchen)
undefined

Apply Rewrite

应用重写

julia
matches = get_matches(rule, state)
new_state = rewrite_match(rule, matches[1])

julia
matches = get_matches(rule, state)
new_state = rewrite_match(rule, matches[1])

Self-Play Loop

自循环机制

The ACSet self-refinement monad:
Query₀ → Execute → Evaluate → Mine Patterns → Refine → Query₁ → ...
ACSet自优化单子:
Query₀ → Execute → Evaluate → Mine Patterns → Refine → Query₁ → ...

Implementation

实现

julia
struct SelfRefinementLoop
  schema::Presentation
  state::ACSet
  patterns::Vector{Pattern}
  generation::Int
end

function step!(loop::SelfRefinementLoop, rule::Rule)
  # Find matches
  matches = get_matches(rule, loop.state)
  
  # Evaluate each match
  evaluations = [evaluate_match(m, loop.patterns) for m in matches]
  
  # Mine new patterns from successful evaluations
  new_patterns = mine_patterns(evaluations)
  append!(loop.patterns, new_patterns)
  
  # Apply best match
  best = argmax(e -> e.score, evaluations)
  loop.state = rewrite_match(rule, matches[best.index])
  loop.generation += 1
  
  loop
end
julia
struct SelfRefinementLoop
  schema::Presentation
  state::ACSet
  patterns::Vector{Pattern}
  generation::Int
end

function step!(loop::SelfRefinementLoop, rule::Rule)
  # Find matches
  matches = get_matches(rule, loop.state)
  
  # Evaluate each match
  evaluations = [evaluate_match(m, loop.patterns) for m in matches]
  
  # Mine new patterns from successful evaluations
  new_patterns = mine_patterns(evaluations)
  append!(loop.patterns, new_patterns)
  
  # Apply best match
  best = argmax(e -> e.score, evaluations)
  loop.state = rewrite_match(rule, matches[best.index])
  loop.generation += 1
  
  loop
end

Convergence Criterion

收敛准则

julia
function converged(loop::SelfRefinementLoop; threshold=0.95)
  recent = loop.patterns[end-10:end]
  stability = std([p.score for p in recent])
  stability < (1 - threshold)
end

julia
function converged(loop::SelfRefinementLoop; threshold=0.95)
  recent = loop.patterns[end-10:end]
  stability = std([p.score for p in recent])
  stability < (1 - threshold)
end

GF(3) Integration

GF(3)集成

Trit Assignment

三元态分配

julia
function acset_to_trits(g::Graph, seed::UInt64)
  rng = SplitMix64(seed)
  trits = Int[]
  for e in parts(g, :E)
    h = next_u64!(rng)
    hue = (h >> 16 & 0xffff) / 65535.0 * 360
    trit = hue < 60 || hue >= 300 ? 1 :
           hue < 180 ? 0 : -1
    push!(trits, trit)
  end
  trits
end
julia
function acset_to_trits(g::Graph, seed::UInt64)
  rng = SplitMix64(seed)
  trits = Int[]
  for e in parts(g, :E)
    h = next_u64!(rng)
    hue = (h >> 16 & 0xffff) / 65535.0 * 360
    trit = hue < 60 || hue >= 300 ? 1 :
           hue < 180 ? 0 : -1
    push!(trits, trit)
  end
  trits
end

Conservation check

Conservation check

gf3_conserved(trits) = sum(trits) % 3 == 0
undefined
gf3_conserved(trits) = sum(trits) % 3 == 0
undefined

Synergistic Triads Containing ACSets

包含ACSets的协同三元组

clj-kondo-3color (-1) ⊗ acsets (0) ⊗ rama-gay-clojure (+1) = 0 ✓
three-match (-1) ⊗ acsets (0) ⊗ gay-mcp (+1) = 0 ✓
slime-lisp (-1) ⊗ acsets (0) ⊗ cider-clojure (+1) = 0 ✓
hatchery-papers (-1) ⊗ acsets (0) ⊗ frontend-design (+1) = 0 ✓

clj-kondo-3color (-1) ⊗ acsets (0) ⊗ rama-gay-clojure (+1) = 0 ✓
three-match (-1) ⊗ acsets (0) ⊗ gay-mcp (+1) = 0 ✓
slime-lisp (-1) ⊗ acsets (0) ⊗ cider-clojure (+1) = 0 ✓
hatchery-papers (-1) ⊗ acsets (0) ⊗ frontend-design (+1) = 0 ✓

Orthogonal Bundles

正交束

ACSets participates in the STRUCTURAL bundle:
DirectionSkillsBehavior
STRUCTURALclj-kondo(-1) ⊗ acsets(0) ⊗ rama-gay(+1)Schema validation → transport → generation
TEMPORALthree-match(-1) ⊗ unworld(0) ⊗ gay-mcp(+1)Reduction → derivation → coloring
STRATEGICproofgeneral(-1) ⊗ glass-bead(0) ⊗ rubato(+1)Verification → hopping → composition

ACSets属于STRUCTURAL(结构型)束:
方向技能行为
STRUCTURALclj-kondo(-1) ⊗ acsets(0) ⊗ rama-gay(+1)模式验证 → 传输 → 生成
TEMPORALthree-match(-1) ⊗ unworld(0) ⊗ gay-mcp(+1)约简 → 推导 → 着色
STRATEGICproofgeneral(-1) ⊗ glass-bead(0) ⊗ rubato(+1)验证 → 跳转 → 组合

Visual Conventions (from RelationalThinking)

视觉约定(来自《关系型思维》)

ConceptVisual
Schema objectGray circle
Schema morphismColored arrow (cyan=src, blue=tgt)
Instance elementFilled shape
Morphism mappingSlot/containment
PushoutMerged regions with distinct colors
DPO ruleThought bubble (L,K,R)

概念视觉表现
模式对象灰色圆形
模式态射彩色箭头(青色=src,蓝色=tgt)
实例元素填充形状
态射映射插槽/包含关系
推出不同颜色的合并区域
DPO规则思维气泡(L,K,R)

Commands

命令

bash
undefined
bash
undefined

Schema operations

Schema operations

just acset-schema FILE # Display schema diagram just acset-instance FILE # Display instance elements just acset-morphism F G # Show homomorphism F → G
just acset-schema FILE # Display schema diagram just acset-instance FILE # Display instance elements just acset-morphism F G # Show homomorphism F → G

DPO rewriting

DPO rewriting

just acset-rule RULE STATE # Apply rewrite rule just acset-matches RULE STATE # Find all matches just acset-chain RULES STATE # Chain multiple rewrites
just acset-rule RULE STATE # Apply rewrite rule just acset-matches RULE STATE # Find all matches just acset-chain RULES STATE # Chain multiple rewrites

Self-play

Self-play

just acset-selfplay SCHEMA # Run self-refinement loop just acset-patterns STATE # Mine patterns from state just acset-converge SCHEMA # Run until convergence
just acset-selfplay SCHEMA # Run self-refinement loop just acset-patterns STATE # Mine patterns from state just acset-converge SCHEMA # Run until convergence

GF(3) operations

GF(3) operations

just acset-trits STATE SEED # Color state with seed just acset-gf3 STATE # Check GF(3) conservation just acset-triads # Show synergistic triads

---
just acset-trits STATE SEED # Color state with seed just acset-gf3 STATE # Check GF(3) conservation just acset-triads # Show synergistic triads

---

References

参考资料

Topos Institute

Topos Institute

AlgebraicJulia

AlgebraicJulia

Papers

相关技能

  • Patterson et al. "Categorical data structures for technical computing" (Compositionality 2022)
  • Aguinaldo et al. "Categorical Representation Language for Knowledge-Based Planning" (AAAI 2023)

  • rama-gay-clojure
    (+1) - 带颜色追踪的可扩展后端
  • clj-kondo-3color
    (-1) - 模式验证/代码检查
  • glass-bead-game
    (0) - 跨模式的世界跳转
  • unworld
    (0) - 用于状态演化的推导链
  • discohy-streams
    (0) - DisCoPy范畴论颜色流

技能名称: acsets-relational-thinking 类型: 范畴论数据库 / DPO重写 三元态: 0(遍历性) GF(3): 通过三元组合保持守恒

Related Skills

  • rama-gay-clojure
    (+1) - Scalable backends with color tracing
  • clj-kondo-3color
    (-1) - Schema validation/linting
  • glass-bead-game
    (0) - World hopping across schemas
  • unworld
    (0) - Derivational chains for state evolution
  • discohy-streams
    (0) - DisCoPy categorical color streams

Skill Name: acsets-relational-thinking Type: Category-Theoretic Database / DPO Rewriting Trit: 0 (ERGODIC) GF(3): Conserved via triadic composition