LeanMachineLearning

Mathlib.Tactic.Widget.StringDiagram.mkKernelDiagram🔗

Definition

Construct a kernelized string diagram from a Penrose substance program and expressions embeds to display as labels in the diagram.

🔗def
Mathlib.Tactic.Widget.StringDiagram.mkKernelDiagram (nodes : List (List Node)) (strands : List (List Strand)) : ProofWidgets.Penrose.DiagramBuilderM PUnit.{1}
Mathlib.Tactic.Widget.StringDiagram.mkKernelDiagram (nodes : List (List Node)) (strands : List (List Strand)) : ProofWidgets.Penrose.DiagramBuilderM PUnit.{1}

Code

open scoped Jsx in def mkKernelDiagram (nodes : List (List Node)) (strands : List (List Strand)) : DiagramBuilderM PUnit := do /- Add 2-morphisms. -/ for x in nodes.flatten do match x with | .atom _ => do addPenroseVar "Atom" ( x.toPenroseVar_kernel) | .id _ => do StringDiagram.addPenroseVar "Id" ( x.toPenroseVar_kernel) /- Add constraints. -/ for l in nodes do for (x₁, x₂) in l.consecutivePairs do DiagramBuilderM.addInstruction s!"Left({ x₁.toPenroseVar_kernel}, { x₂.toPenroseVar_kernel})" /- Add constraints. -/ for (l₁, l₂) in nodes.consecutivePairs do if let some x₁ := l₁.head? then if let some x₂ := l₂.head? then DiagramBuilderM.addInstruction s!"Above({ x₁.toPenroseVar_kernel}, { x₂.toPenroseVar_kernel})" /- Add 1-morphisms as strings. -/ for l in strands do for s in l do StringDiagram.addConstructor "Mor1" s.toPenroseVar "MakeString" [ s.startPoint.toPenroseVar_kernel, s.endPoint.toPenroseVar_kernel]

Actions: Source · Open Issue

Meaning last changed in v4.34.0-rc2-1-g439785b (2026-08-23).

Self-contained, with its dependencies inlined and proofs replaced by sorry: download the raw file · open it in the Lean web editor.

Dependency graph

Audit surface: 3 project declarations, 138 external constants

✓ Proved: no sorry anywhere in its closure

This is the tool's own reading of one build's recorded axioms, and it is not robust against an author who wants it to pass. Checking meant to be relied on should go through Comparator, which replays the proof through the kernel from an export against an explicit list of permitted axioms.