ACSets (Attributed C-Sets) for categorical database design and DPO rewriting
Version: 2.0.0 Trit: 0 (ERGODIC) Domain: database, category-theory, rewriting Source: Topos Institute RelationalThinking Course + AlgebraicJulia
ACSets (Attributed C-Sets) are functors X: C β Set where C is a small category (schema). This skill integrates:
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β
βββββββββββββββββββββββββββββββ
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])
@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)
L βββlββ K ββrβββ R
β β β
matchβ β β
β β β
G ββββββ D βββββββ H
pushout pushout
complement
using AlgebraicRewriting
# 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)
matches = get_matches(rule, state)
new_state = rewrite_match(rule, matches[1])
The ACSet self-refinement monad:
Queryβ β Execute β Evaluate β Mine Patterns β Refine β Queryβ β ...
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
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
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
gf3_conserved(trits) = sum(trits) % 3 == 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 β
ACSets participates in the STRUCTURAL bundle:
| Direction | Skills | Behavior |
|---|---|---|
| STRUCTURAL | clj-kondo(-1) β acsets(0) β rama-gay(+1) | Schema validation β transport β generation |
| TEMPORAL | three-match(-1) β unworld(0) β gay-mcp(+1) | Reduction β derivation β coloring |
| STRATEGIC | proofgeneral(-1) β glass-bead(0) β rubato(+1) | Verification β hopping β composition |
| Concept | Visual |
|---|---|
| Schema object | Gray circle |
| Schema morphism | Colored arrow (cyan=src, blue=tgt) |
| Instance element | Filled shape |
| Morphism mapping | Slot/containment |
| Pushout | Merged regions with distinct colors |
| DPO rule | Thought bubble (L,K,R) |
# 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
# 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
# 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
# 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
rama-gay-clojure (+1) - Scalable backends with color tracingclj-kondo-3color (-1) - Schema validation/lintingglass-bead-game (0) - World hopping across schemasunworld (0) - Derivational chains for state evolutiondiscohy-streams (0) - DisCoPy categorical color streamsSkill Name: acsets-relational-thinking Type: Category-Theoretic Database / DPO Rewriting Trit: 0 (ERGODIC) GF(3): Conserved via triadic composition