An R port of core Catlab.jl functionality — categorical algebra for applied category theory. Provides limits/colimits, graph rewriting (DPO/SPO/SqPO), undirected wiring diagrams, data migration, typed ACSets, and structured cospans.
Built on top of the acsets package.
Installation
Install from GitHub (requires the acsets dependency):
# install.packages("remotes")
remotes::install_github("catRgory/acsets")
remotes::install_github("catRgory/catlab")Quick example
library(catlab)
# Create two graphs and glue them along a shared vertex
g1 <- path_graph(3) # 1 → 2 → 3
g2 <- path_graph(2) # 1 → 2
# Identify vertex 3 of g1 with vertex 1 of g2
interface <- Graph()
add_vertex(interface)
f <- ACSetTransformation(list(V = 3L, E = integer(0)), interface, g1)
g <- ACSetTransformation(list(V = 1L, E = integer(0)), interface, g2)
result <- pushout(f, g)
nv(result$pushout) # 4 vertices: the two paths joined end-to-end
ne(result$pushout) # 3 edges
# DPO graph rewriting: add an edge between two vertices
I <- Graph(); add_vertices(I, 2)
L <- Graph(); add_vertices(L, 2)
R <- path_graph(2) # 1 → 2
l <- ACSetTransformation(list(V = c(1L, 2L), E = integer(0)), I, L)
r <- ACSetTransformation(list(V = c(1L, 2L), E = integer(0)), I, R)
add_edge_rule <- rule(l, r)
triangle <- cycle_graph(3)
result <- rewrite(add_edge_rule, triangle)
ne(result) # 4 edges (added one to the triangle)Features
-
Graphs — Directed, symmetric, reflexive, weighted, and labelled graph schemas with constructors (
path_graph,cycle_graph,complete_graph) and query functions (nv,ne,neighbors) -
Finite categories & functors —
FinCat,FinFunctor, andACSetTransformationwith naturality checking -
Limits & colimits —
product,pullback,equalizer,coproduct,pushout,coequalizer, plusterminal/initialobjects -
Homomorphism search — Backtracking search for graph homomorphisms (
find_homomorphism,find_all_homomorphisms,is_homomorphic) with monic and initial-match support -
Graph rewriting — DPO, SPO, and SqPO semantics via
rule(),rewrite(),get_matches(), andrewrite_match() -
Data migration — Pull back (
delta_migrate) and push forward (sigma_migrate) data along schema functors -
Undirected wiring diagrams — Compositional system specification with a concise DSL (
uwd(),relation()) -
Typed ACSets — Type-stratified graphs with
typed_product(pullback over types) andtyped_coproduct -
Structured cospans — Open systems with interfaces; compose via
compose_cospans,otimes_cospans, andoapply_cospans -
Visualization — Graphviz/DOT output for graphs, Petri nets, and UWDs via
to_dot()/to_graphviz()
Vignettes
Detailed tutorials are available as package vignettes:
- Limits, colimits, and graph rewriting — terminal/initial objects, products, coproducts, pushouts, pullbacks, equalizers, coequalizers
- Graphs and visualization — graph schemas, constructors, homomorphisms, DOT rendering
- Undirected wiring diagrams — composing open systems via shared variables (SIR, SEIR, Lotka–Volterra examples)
- Data migration with functors — delta/sigma migration for schema evolution and data transformation
- Graph rewriting: DPO, SPO, and SqPO — algebraic graph transformation with gluing conditions
- Open systems and typed ACSets — typed products, structured cospans, and UWD-directed composition
Author
Simon Frost (@sdwfrost) — ORCID 0000-0002-5207-9879
License
MIT — see LICENSE for details.
