Formal foundations

From nrdxp/predicate · View interactive version

Formal foundations is an AI agent skill from the GitHub repository nrdxp/predicate. Mathematical foundations, logical structures, and formal verification guidance. Trigger when: - Designing protocol contracts, formal specifications, verifying state spaces, or using proof assistants. - Tasks involve: TLA+, Alloy, Lean, Coq, model checkers, invariants, temporal logic. - Prompt contai

How to use this skill

Skill file

Formal Mathematical Foundations

Reference corpus — /form, /spec, boundary. This skill survives as the mathematical-language authority; the mandate to apply it is ambient, rooted in the workflows that invoke it as a lens. It supplies the foundational vocabulary for form's structural representations, the verification semantics for spec's formal tiers, and the theoretical grounding consulted by boundary. The formalisms here anchor the symbolic path of the Verification Dual: types-as-propositions (Curry-Howard), bisimulation as behavioral equivalence, and adjoint functors as the semantic spine of data migration.

Disposition directive: Recognize that the structures you encounter in software engineering — types, protocols, state machines, data schemas — are instances of deeper mathematical patterns. This skill equips you with the vocabulary to see those patterns. The sdma skill provides the domain-specific toolkit for _applying_ these foundations to concrete problems; this skill provides the _language_.


1. Categorical Foundations

Category theory is the algebra of composition. Its value to engineering is not abstraction for abstraction's sake — it provides a _universal language_ for describing how things combine, transform, and relate.

1.1. Symmetric Monoidal Categories (SMC)

A symmetric monoidal category is a quintuple (C, ⊗, I, α, λ, ρ, γ) defining a category C equipped with a bifunctor ⊗: C × C → C and a unit object I.

Coherence Axioms:

  1. Pentagon Identity: For any objects W, X, Y, Z, the following diagram commutes:

(id_W ⊗ α\_{X,Y,Z}) ∘ α\_{W, X⊗Y, Z} ∘ (α\_{W,X,Y} ⊗ id_Z) = α\_{W, X, Y⊗Z} ∘ α\_{W⊗X, Y, Z}

_All possible re-bracketings of four objects yield the same result. There is exactly one way to re-associate._

  1. Hexagon Identity: Connects the braiding γ to the associator α:

α\_{Y,Z,X} ∘ γ\_{X, Y⊗Z} ∘ α\_{X,Y,Z} = (id_Y ⊗ γ\_{X,Z}) ∘ α\_{Y,X,Z} ∘ (γ\_{X,Y} ⊗ id_Z)

_Braiding is compatible with association. Swapping "through" a group works the same as swapping then regrouping._

1.2. Closed Categories

A monoidal category is closed if the functor (− ⊗ Y) has a right adjoint, denoted as the internal hom [Y, −] or Y ⊸ −.

Hom(X ⊗ Y, Z) ≅ Hom(X, Y ⊸ Z)

_A function of two arguments is equivalent to a function that takes one argument and returns a function of the other. This is the mathematical foundation of currying in every programming language._

1.3. Compact Closed Categories

A compact closed category is a symmetric monoidal category where every object X has a dual X\, a unit η_X: I → X\ ⊗ X, and a counit ε_X: X ⊗ X\* → I satisfying the Zig-Zag (Yanking) Identities:

(ε_X ⊗ id_X) ∘ α\_{X, X\*, X} ∘ (id_X ⊗ η_X) = id_X

(id\_{X\} ⊗ ε_X) ∘ α\_{X\, X, X\}⁻¹ ∘ (η_X ⊗ id\_{X\}) = id\_{X\*}

_Every type has a "dual" (its continuation, its adjoint space, its negation). Creating a pair and then collapsing it is the same as doing nothing. This is the mathematical spine of evaluation, measurement, and resource consumption._


2. The Rosetta Stone Isomorphisms

The Rosetta Stone (Baez-Stay) maps the structural primitives of four disparate fields onto the common core of compact closed categories. This is the central insight: these four fields are not merely analogous — they are _formally isomorphic_. A proof about one transfers to the others via functorial mapping.

2.1. Physics (Hilbert Spaces)

2.2. Topology (Cobordisms)

2.3. Logic (Multiplicative Linear Logic — MILL)

2.4. Computation (Linear Type Theory)


3. Curry-Howard and Compositional Reasoning

The Curry-Howard correspondence — types are propositions, programs are proofs — is the computational column of the Rosetta Stone, but its implications extend beyond type theory:


4. Algebra vs. Coalgebra

This is the fundamental duality in formal modeling. Recognizing which side of this duality a problem lives on determines the correct tools.

| Aspect | Algebra | Coalgebra |

| :---------- | :------------------------------- | :------------------------------------------------------ |

| Defined by | Constructors (how to build) | Observers (how to interact) |

| Identity | Structural (isomorphism) | Behavioral (bisimulation) |

| Reasoning | Induction (from parts to whole) | Co-induction (from observations) |

| Data model | Finite, inductive (lists, trees) | Potentially infinite, co-inductive (streams, processes) |

| Typical use | Data structures, ADTs | State machines, protocols, reactive systems |

Coalgebra (formal definition)

A coalgebra is a morphism c: X → F(X) where X is the state space and F is a behavior endofunctor.

Bisimulation

A relation R ⊆ X × X is a bisimulation if for all (x₁, x₂) ∈ R, their transitions c(x₁) and c(x₂) map to equivalent behaviors in F(R). Bisimulation is the formal tool for checking behavioral equivalence in dynamical systems — two systems are "the same" if no external observer can distinguish them, regardless of internal structure.

_When you ask "are these two state machines equivalent?" you are asking about bisimulation, not structural equality. This is the correct frame for protocol equivalence, API compatibility, and behavioral testing._


5. Foundational Vocabulary: Data and Structure

These definitions provide the _formal vocabulary_ for the structures that the sdma skill applies in practice.

Database Schemas as Categories

1. Pullback (Δ_F): Pre-composition I ∘ F. _Restructure existing data into a new schema._

2. Left Pushforward (Σ_F): The Left Kan Extension, used for data integration and colimits. _Merge data from multiple sources._

3. Right Pushforward (Π_F): The Right Kan Extension, used for defining data constraints and limits. _Enforce invariants across schema boundaries._

Ologs (Ontology Logs) — Structural Constraints

  1. Objects (Types): Must be labeled with a singular indefinite noun phrase (e.g., "An employee", "A department").
  2. Morphisms (Aspects): Must represent functional relationships (mathematical functions), where each element of the domain maps to exactly one element of the codomain.
  3. Facts: Represented as commutative diagrams demonstrating path equivalence.

Signal Flow and Control

Signal flow is analyzed via Linear Relations using four categorical generators:

  1. Addition (+): ℝ × ℝ → ℝ.
  2. Duplication (Δ): ℝ → ℝ × ℝ.
  3. Integration (∫): The storage or delay operator.
  4. Scalar Multiplication: Gain factor k ∈ ℝ.

Information Metrics


6. Summary Reference Table

The Rosetta Stone in full — the correspondences that unify four fields under one algebraic structure:

| Feature | Physics | Topology | Logic | Computation |

| :----------------- | :-------------------------- | :---------------------- | :------------------ | :----------------------- |

| Objects | Hilbert Space (H) | (n−1)-dim Manifold | Proposition (A) | Type (A) |

| Morphisms | Linear Operator (f) | n-dim Cobordism | Proof (π) | Program (P) |

| Tensor Product | Composite System (H ⊗ K) | Disjoint Union (X ⊔ Y) | Conjunction (A ⊗ B) | Pair Type (A × B) |

| Duals | Adjoint (H\) | Reversed Manifold (X\) | Negation (A^⊥) | Continuation (A → ⊥) |

| Internal Hom | Linear Maps (H ⊸ K) | (N/A) | Implication (A ⊸ B) | Function Type (A → B) |

| Unit (η) | Bell State / Preparation | Cup (Creation) | Identity (Axiom) | Variable / Unit Value |

| Counit (ε) | Inner Product / Measurement | Cap (Annihilation) | Cut (Elimination) | Application / Evaluation |


7. Integration

Relationship to `engineering.md`

The engineering skill mandates strong typing, composition, and structural soundness. This skill provides the _mathematical justification_ for why those mandates work: types are propositions (Curry-Howard), composition is inference (categorical composition), and structural soundness is a consequence of coherence (pentagon and hexagon identities). When engineering intuition says "this feels wrong," these foundations often reveal _why_ — a violated commutativity condition, a broken adjunction, a misidentified duality.

Relationship to Cognitive Disposition (`ambient.md`)

The holonic lens in ambient.md's Cognitive Disposition — every component is both a whole and a part — is a natural language description of what category theory formalizes: objects that are simultaneously domains and codomains, algebras that are simultaneously initial and terminal, structures that compose fractally. The formal foundations give that ambient intuition _teeth_: instead of "think holistically," you can verify that the diagram commutes.

Relationship to SDMA

This skill tells you _what these structures are_. The sdma skill tells you _how to wield them_. If you need applied methodology — building an olog, verifying protocol equivalence via bisimulation, selecting between formalisms — load sdma alongside this skill.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.