Command Palette

Search for a command to run...

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

discopy-operads

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

DiscoPy Operads Skill

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

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

DiscoPy Operads Skill

Repo Color: #64e3ec | Seed: 0x128b6ef4564e3a00 | Index: 224/1055

DisCoPy: Python toolkit for computing with string diagrams, monoidal categories, and operads.

bmorphism Contributions

"universal topos construction for social cognition and democratization of mathematical approach to problem-solving to all" — Plurigrid: the story thus far

Operads as Skill Composition: DisCoPy's operad module implements the colored operad structure that bmorphism uses for skill composition. Each skill is an operation with typed inputs/outputs; composition follows operad laws.

Active Inference Connection: The operadic structure enables hierarchical Active Inference in String Diagrams — nested perception-action loops where higher-level beliefs parameterize lower-level policies.

GF(3) Colored Operads: Following the paper "On the homotopy theory of equivariant colored operads" (Bonventre & Pereira), colors can encode trit values {-1, 0, +1} for balanced skill composition.

Quick Reference

from discopy.monoidal import Ty, Box, Id, Diagram
from discopy.grammar.cfg import Tree, Rule, Word, Operad, Algebra
from discopy import symmetric, braided, compact, frobenius, hypergraph

String Diagram Syntax

# Types are objects in monoidal categories
x, y, z = Ty('x'), Ty('y'), Ty('z')
unit = Ty()  # monoidal unit

# Tensor product (horizontal composition)
xy = x @ y  # x ⊗ y

# Boxes are morphisms
f = Box('f', x, y)           # f: x → y
g = Box('g', y, z)           # g: y → z

# Sequential composition (vertical)
fg = f >> g                   # g ∘ f: x → z

# Parallel composition (tensor of morphisms)
f_par_g = f @ g              # f ⊗ g: x ⊗ y → y ⊗ z

# Identity morphisms
idx = Id(x)                  # id_x: x → x

# Interchange law
d = Id(x) @ g >> f @ Id(z)   # = (f @ g).interchange(0, 1)

Monoidal Category Operations

# Dagger (adjoint)
f_dag = f[::-1]              # f†: y → x

# Diagram slicing
d = f >> g >> h
first_two = d[:2]            # f >> g
last_box = d[2]              # h

# Interchange normalization
for step in (f @ g).normalize():
    print(step)              # yields normal form steps

normal = d.normal_form()     # boundary-connected normal form

Category Hierarchy

cat.Category
    └── monoidal.Category (planar diagrams)
        └── braided.Category (overcrossings)
            └── symmetric.Category (swaps)
                └── traced.Category (feedback loops)
                    └── compact.Category (cups/caps)
                        └── frobenius.Category (spiders)

Operad Composition

from discopy.grammar.cfg import Ty, Rule, Tree, Id, Operad

# Operads: multicategories with multi-input operations
x, y = Ty('x'), Ty('y')

# Rules are operad generators (atomic type codomain)
f = Rule(x @ x, x, name='f')  # f: x ⊗ x → x
g = Rule(x @ y, x, name='g')  # g: x ⊗ y → x
h = Rule(y @ x, x, name='h')  # h: y ⊗ x → x

# Tree construction via operadic composition
tree = f(g, h)               # plug g, h into f's inputs
assert tree == Tree(f, g, h)

# Axioms hold on the nose
assert Id(x)(f) == f == f(Id(x), Id(x))  # identity
left = f(Id(x), h)(g, Id(x), Id(x))
right = f(g, Id(x))(Id(x), Id(x), h)
assert f(g, h) == left == right          # associativity

# Nested diagram substitution (Patterson et al.)
diagram.substitute(i, other)  # replace box i with diagram other

Nested Operad Composition (Advanced)

from discopy.grammar.cfg import Ty, Rule, Tree, Id

# Multi-level nesting example
a, b, c = Ty('a'), Ty('b'), Ty('c')

# Arity-2 rules
add = Rule(a @ a, a, name='+')       # +: a ⊗ a → a
mul = Rule(a @ a, a, name='*')       # *: a ⊗ a → a
neg = Rule(a, a, name='-')           # -: a → a (unary)

# Deep composition: (a + b) * (-c)
# Corresponds to tree: mul(add(id_a, id_a), neg(id_a))
expr1 = mul(add, neg)                 # plug add and neg into mul's inputs
assert expr1.dom == a @ a @ a         # 3 leaves (a, a, a for left+, right*, and neg arg)

# Even deeper: ((a + b) * c) + (a * (b + c))
left_tree = mul(add, Id(a))           # (a + b) * c
right_tree = mul(Id(a), add)          # a * (b + c)  
full_expr = add(left_tree, right_tree)
print(f"Depth: {full_expr.depth}, Leaves: {len(list(full_expr.leaves))}")

# Operad morphism (algebra) evaluation
@Algebra.from_callable(a >> int)
def eval_int(rule: Rule, *args: int) -> int:
    if rule.name == '+': return args[0] + args[1]
    if rule.name == '*': return args[0] * args[1]
    if rule.name == '-': return -args[0]
    return args[0]

# Evaluate: (2 + 3) * (-4) = 5 * (-4) = -20
tree_with_leaves = mul(add(2, 3), neg(4))  # conceptual

CFG Example

n, d, v = Ty('N'), Ty('D'), Ty('V')
vp, np, s = Ty('VP'), Ty('NP'), Ty('S')

Caesar = Word('Caesar', n)
crossed = Word('crossed', v)
the, Rubicon = Word('the', d),
Полный SKILL.md на GitHub

Установить discopy-operads в Claude Code и Claude Desktop

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

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

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

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

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

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

FAQ

Что делает скилл discopy-operads?

DiscoPy Operads Skill

Как установить скилл discopy-operads?

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

Скилл discopy-operads запускает скрипты?

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

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

Сравнить discopy-operads с