derangement-crdt
БесплатноБез исполняемых скриптовНе проверенDerangement-CRDT Skill
от plurigrid★ 73 звезды на GitHubОб этом скилле
Derangement-CRDT Skill
Status: ✅ Production Ready Trit: ERGODIC (0) Integration: CRDT, Gay.jl, Join-Semilattice
Core Concept
A derangement is a permutation σ where σ(i) ≠ i for all i (no fixed points). A colorable derangement CRDT assigns GF(3) colors to derangement cycles, ensuring merge operations preserve both the derangement property and color conservation.
Derangement: (1 2 3) → (2 3 1) ✓ no fixed points
Fixed point: (1 2 3) → (1 3 2) ✗ position 1 is fixed
Mathematical Foundation
Derangement Lattice
Derangements form a join-semilattice under cycle composition:
⊤ = identity (trivial - all fixed)
│
┌─┴─┬───┬───┐
│ │ │ │
(12) (13) (23) ... ← transpositions
│ │ │ │
└─┬─┴───┴─┬─┘
│ │
(123) (132) ← 3-cycles (derangements!)
│ │
└───┬───┘
│
⊥ = full derangement
GF(3) Coloring of Cycles
Each cycle receives a trit based on cycle length mod 3:
| Cycle Length | Trit | Color Range | Example |
|---|---|---|---|
| len ≡ 0 (mod 3) | ERGODIC (0) | 60°-180° (green) | (1 2 3) |
| len ≡ 1 (mod 3) | PLUS (+1) | 0°-60°, 300°-360° (warm) | (1) fixed |
| len ≡ 2 (mod 3) | MINUS (-1) | 180°-300° (cold) | (1 2) swap |
Conservation Law
For any valid derangement coloring:
Σ trit(cycle) ≡ 0 (mod 3)
This is automatically satisfied for derangements of length n ≡ 0 (mod 3).
CRDT Operations
Derangement-Set CRDT
class DerangementCRDT
# State: set of (element, position, color, replica_id, lamport)
def merge(other)
# Join-semilattice merge:
# 1. Union all mappings
# 2. For conflicts: higher Lamport wins
# 3. Verify derangement property preserved
# 4. Recolor to maintain GF(3) conservation
end
def apply_permutation(sigma)
# Apply permutation, ensuring no fixed points created
raise DerangementViolation if creates_fixed_point?(sigma)
update_colors!
end
def cycle_decomposition
# Decompose into disjoint cycles
# Color each cycle by length mod 3
end
end
Merge Semantics
State A: [2,3,1,5,4] (cycles: (123)(45))
Colors: [G,G,G,B,B] (ERGODIC, MINUS)
State B: [3,1,2,5,4] (cycles: (132)(45))
Colors: [G,G,G,B,B] (ERGODIC, MINUS)
Merge(A,B): Resolve by Lamport timestamp
Recolor to maintain Σ trits ≡ 0
Implementation
Babashka Script
#!/usr/bin/env bb
;; derangement_crdt.bb
(defn derangement? [perm]
"Check if permutation has no fixed points"
(every? (fn i v (not= i v))
(map-indexed vector perm)))
(defn cycle-decomposition [perm]
"Decompose permutation into disjoint cycles"
(loop [remaining (set (range (count perm)))
cycles []]
(if (empty? remaining)
cycles
(let [start (first remaining)
cycle (loop [current start
acc [start]]
(let [next (nth perm current)]
(if (= next start)
acc
(recur next (conj acc next)))))]
(recur (apply disj remaining cycle)
(conj cycles cycle))))))
(defn gf3-trit [cycle-len]
"Assign GF(3) trit based on cycle length"
(case (mod cycle-len 3)
0 :ERGODIC
1 :PLUS
2 :MINUS))
(defn hue-from-trit [trit seed]
"Map trit to hue range with seed variation"
(let [base (case trit
:MINUS (+ 180 (mod seed 120)) ; cold: 180-300
:ERGODIC (+ 60 (mod seed 120)) ; neutral: 60-180
:PLUS (if (< (mod seed 120) 60)
(mod seed 60) ; warm: 0-60
(+ 300 (mod seed 60)))) ; warm: 300-360
]
(mod base 360)))
(defn color-derangement [perm]
"Assign colors to derangement cycles"
(let [cycles (cycle-decomposition perm)]
(for [[idx cycle] (map-indexed vector cycles)]
{:cycle cycle
:length (count cycle)
:trit (gf3-trit (count cycle))
:hue (hue-from-trit (gf3-trit (count cycle)) idx)})))
(defn conservation-check [colored-cycles]
"Verify GF(3) conservation"
(let [trit-sum (->> colored-cycles
(map :trit)
(map {:MINUS -1 :ERGODIC 0 :PLUS 1})
(reduce +))]
(zero? (mod trit-sum 3))))
;; CRDT Merge
(defn merge-derangements [state-a state-b]
"Join-semilattice merge of two derangement states"
(let [merged (merge-with
(fn [a b]
(if (> (:lamport a) (:lamport b)) a b))
state-a state-b)]
(when-not (derangement? (:perm merged))
(throw (ex-info "Merge violated derangement property" {})))
(assoc merged :colors (color-derangement (:perm merged)))))
;; Demo
(defn demo []
(let [perm [1 2 0 4 3] ; (0 1 2)(3 4) - derangement!
colored (color-derangement perm)]
(println "Permutation:" perm)
(println "Derange
Установить derangement-crdt в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл derangement-crdt?
Derangement-CRDT Skill
Как установить скилл derangement-crdt?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл derangement-crdt запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
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…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic