A sleek and expressive Python library for modeling categories, functors, natural transformations, and higher categorical structures.
- ๐ฆ Core Structures: Objects, morphisms, categories with full composition laws
- ๐ Functors: Map between categories while preserving structure
- ๐ Natural Transformations: Morphisms between functors with naturality checking
- 2๏ธโฃ Higher Categories: 2-categories, โ-categories, simplicial sets
- ๐งฎ Advanced Constructions: Monoidal, braided, enriched categories, and toposes
- ๐ง Algebraic Structures: Operads and algebras
- ๐ Diagram Tools: Automated commutativity checking
- ๐๏ธ Standard Categories: Pre-built categories (terminal, initial, discrete, etc.)
HyperCat brings the mathematical elegance of category theory to Python, designed for:
- ๐ Research in pure and applied category theory
- ๐งฎ Computational modeling of categorical structures
- ๐ง Algebraic topology and homotopy theory
- ๐ค Categorical foundations for functional programming and type theory
- ๐ฌ Mathematical foundations for machine learning and AI systems
git clone https://github.com/Mircus/HyperCat.git
cd HyperCat
pip install -e .- Python 3.8 or higher
- Dependencies:
networkx,matplotlib,jupyter,pytest
import hypercat
from hypercat import Category, Object, Morphism, Functor
# Create a category
cat = Category("Sets")
# Add objects
A = Object("A")
B = Object("B")
cat.add_object(A)
cat.add_object(B)
# Add morphisms
f = Morphism("f", A, B)
cat.add_morphism(f)
# Compose morphisms
g = Morphism("g", B, A)
cat.add_morphism(g)
h = cat.compose(f, g) # h: A โ A
print(f"Composed morphism: {h}")# Create another category
cat2 = Category("Groups")
cat2.add_object(A)
cat2.add_object(B)
cat2.add_morphism(f)
# Create a functor
F = Functor("F", cat, cat2)
F.map_object(A, A)
F.map_object(B, B)
F.map_morphism(f, f)
# Check functor laws
print(f"Preserves composition: {F.is_functor()}")from hypercat import NaturalTransformation
# Create two functors F, G: cat โ cat2
G = Functor("G", cat, cat2)
# ... set up G's mappings ...
# Create natural transformation ฮท: F โ G
eta = NaturalTransformation("ฮท", F, G)
# ... set up components ...
# Verify naturality
print(f"Is natural: {eta.is_natural()}")from hypercat import StandardCategories
# Pre-built categories
terminal = StandardCategories.terminal_category() # Single object, single morphism
initial = StandardCategories.initial_category() # Empty category
discrete = StandardCategories.discrete_category(["X", "Y", "Z"]) # Only identity morphismsStart with our interactive Jupyter notebooks in the examples/ directory:
- 00_quickstart.ipynb: Complete introduction to HyperCat
- HyperCatDemo.ipynb: Advanced features demonstration
- hypercat_algebraic_topology_demo.ipynb: Algebraic topology applications
- hypercats.ipynb: Working with higher categories
hypercat/
โโโ core/ # Core classes: Category, Object, Morphism, Functor
โโโ categories/ # Specialized categories: Monoidal, Braided, Enriched, Topos
โโโ higher/ # Higher categories: 2-categories, โ-categories
โโโ diagram/ # Diagram and commutativity checking tools
โโโ algebraic/ # Operads and algebraic structures
Category: The fundamental structure with objects and morphismsFunctor: Structure-preserving mappings between categoriesNaturalTransformation: Morphisms between functorsTwoCategory: Categories with 2-cells (morphisms between morphisms)MonoidalCategory: Categories with tensor productsTopos: Categories with all finite limits and power objects
Run the test suite:
pytestSee ROADMAP.md for planned features:
- Universal properties and (co)limits
- Kan extensions
- Model categories
- Higher topos theory
- Categorical logic
- Integration with proof assistants
Check out our ROADMAP.md for upcoming features, including:
- (Co)limits and universal constructions
- Functorial logic and transformation categories
We welcome contributions! See CONTRIBUTING.md for how to get started.
"The fabric of higher structures"