| Safe Haskell | None |
|---|---|
| Language | GHC2024 |
Circuit.Diagram.Hyper
Description
Hypergraph normal form for the drawing-level hyper fragment of
SDiagram (SWire, SSpider, multi-port SBox, SBeside, SThenD,
SSwap).
A diagram is interpreted as port connectivity: every node port and every boundary port is a port reference, and a union-find over those references quotients them into wire classes. Spiders contribute no node — they simply merge the classes of all their ports, so spider fusion (and hence the bialgebra and spider laws) is automatic, and diagrams that differ only in tree shape normalise to the same value. Constructors outside the hyper fragment (cups, caps, unitors, …) are treated as opaque nodes with their natural port arities.
This is not a full graph-isomorphism check: node ports are keyed by box label, so two boxes carrying the same label are interchangeable. That is exact for the oracle suite and cheap; revisit if unlabelled node isomorphism ever matters.
Synopsis
- data HyperGraph = HyperGraph {}
- data HyperNode = HyperNode {}
- data Wire = Wire {
- wBoundary :: [BoundaryEnd]
- wPorts :: [PortEnd]
- data BoundaryEnd
- data PortEnd = PortEnd String PortDir Int
- data PortDir
- normalise :: SDiagram -> HyperGraph
- hyperEquiv :: SDiagram -> SDiagram -> Bool
- arity :: SDiagram -> (Int, Int)
Documentation
data HyperGraph Source #
A diagram as port connectivity: boundary arities, a sorted multiset of nodes, and the wires (equivalence classes of ports).
Constructors
| HyperGraph | |
Instances
| Eq HyperGraph Source # | |
Defined in Circuit.Diagram.Hyper | |
| Show HyperGraph Source # | |
Defined in Circuit.Diagram.Hyper Methods showsPrec :: Int -> HyperGraph -> ShowS # show :: HyperGraph -> String # showList :: [HyperGraph] -> ShowS # | |
A box (or opaque constructor) with its port arities.
Instances
| Eq HyperNode Source # | |
| Ord HyperNode Source # | |
| Show HyperNode Source # | |
One wire class: the boundary ends and node ports it connects, each sorted.
Constructors
| Wire | |
Fields
| |
data BoundaryEnd Source #
A diagram boundary port.
Constructors
| InB Int | Input port (left boundary) at the given index. |
| OutB Int | Output port (right boundary) at the given index. |
Instances
| Eq BoundaryEnd Source # | |
Defined in Circuit.Diagram.Hyper | |
| Ord BoundaryEnd Source # | |
Defined in Circuit.Diagram.Hyper Methods compare :: BoundaryEnd -> BoundaryEnd -> Ordering # (<) :: BoundaryEnd -> BoundaryEnd -> Bool # (<=) :: BoundaryEnd -> BoundaryEnd -> Bool # (>) :: BoundaryEnd -> BoundaryEnd -> Bool # (>=) :: BoundaryEnd -> BoundaryEnd -> Bool # max :: BoundaryEnd -> BoundaryEnd -> BoundaryEnd # min :: BoundaryEnd -> BoundaryEnd -> BoundaryEnd # | |
| Show BoundaryEnd Source # | |
Defined in Circuit.Diagram.Hyper Methods showsPrec :: Int -> BoundaryEnd -> ShowS # show :: BoundaryEnd -> String # showList :: [BoundaryEnd] -> ShowS # | |
A node port: box label, direction and port index.
Whether a node port is an input or an output.
normalise :: SDiagram -> HyperGraph Source #
Interpret a diagram as its hypergraph normal form.
Assumes composable diagrams (SThenD zips the inner ports and drops
any excess): the drawing syntax is untyped, so ill-formed composites
degrade to dangling ports rather than an error.
STurn is involutive and reverses composition order:
>>>hyperEquiv (STurn (STurn (SBox "f" 1 1))) (SBox "f" 1 1)True>>>hyperEquiv (STurn (SThenD (SBox "f" 1 1) (SBox "g" 1 1))) (SThenD (STurn (SBox "g" 1 1)) (STurn (SBox "f" 1 1)))True
>>>putStr (toMermaid (STurn (SBox "f" 1 1)))flowchart LR in0(["in 0"]) out0(["out 0"]) n0["f†"] in0 --> n0 n0 --> out0