pub struct OpenHypergraph<O, A> {
pub sources: Vec<NodeId>,
pub targets: Vec<NodeId>,
pub hypergraph: Hypergraph<O, A>,
}Expand description
A lax OpenHypergraph is a cospan of lax hypergraphs: a hypergraph equipped with two finite maps representing the interfaces.
Fields§
§sources: Vec<NodeId>§targets: Vec<NodeId>§hypergraph: Hypergraph<O, A>Implementations§
Source§impl<O: Clone, A: Clone> OpenHypergraph<O, A>
impl<O: Clone, A: Clone> OpenHypergraph<O, A>
Sourcepub fn lax_compose(&self, other: &Self) -> Option<Self>
pub fn lax_compose(&self, other: &Self) -> Option<Self>
Compose two open hypergraphs, unifying the boundary nodes without checking labels.
Returns None when the boundary arities do not match.
Source§impl<O, A> OpenHypergraph<O, A>
impl<O, A> OpenHypergraph<O, A>
Sourcepub fn tensor_assign(&mut self, rhs: OpenHypergraph<O, A>)
pub fn tensor_assign(&mut self, rhs: OpenHypergraph<O, A>)
Compute the tensor product f.tensor(g) by mutating the data of f
Source§impl<O, A> OpenHypergraph<O, A>
impl<O, A> OpenHypergraph<O, A>
Sourcepub fn empty() -> Self
pub fn empty() -> Self
The empty OpenHypergraph with no nodes and no edges.
In categorical terms, this is the identity map at the unit object.
pub fn from_strict(f: OpenHypergraph<VecKind, O, A>) -> Self
pub fn new_edge(&mut self, x: A, interface: impl Into<Hyperedge>) -> EdgeId
Sourcepub fn new_operation(
&mut self,
x: A,
source_type: Vec<O>,
target_type: Vec<O>,
) -> (EdgeId, Interface)
pub fn new_operation( &mut self, x: A, source_type: Vec<O>, target_type: Vec<O>, ) -> (EdgeId, Interface)
Create a new “operation” in the hypergraph.
Concretely, f.new_operation(x, s, t) mutates f by adding:
- a new hyperedge labeled
x len(s)new nodes, with theith node labeleds[i]len(t)new nodes, with theith node labeledt[i]
Returns the new hyperedge ID and the NodeIds of the source/target nodes.
This is a convenience wrapper for Hypergraph::new_operation
Sourcepub fn singleton(x: A, source_type: Vec<O>, target_type: Vec<O>) -> Self
pub fn singleton(x: A, source_type: Vec<O>, target_type: Vec<O>) -> Self
An OpenHypergraph consisting of a single operation.
Sourcepub fn unify(&mut self, v: NodeId, w: NodeId)
pub fn unify(&mut self, v: NodeId, w: NodeId)
Compute an open hypergraph by calling to_hypergraph on the internal Hypergraph.
Sourcepub fn delete_edges(&mut self, edge_ids: &[EdgeId])
pub fn delete_edges(&mut self, edge_ids: &[EdgeId])
Delete the specified edges from the hypergraph.
Panics if any edge id is out of bounds.
Sourcepub fn delete_nodes(&mut self, node_ids: &[NodeId])
pub fn delete_nodes(&mut self, node_ids: &[NodeId])
Delete the specified nodes from the hypergraph, and renumber the source/target interfaces.
Panics if any node id is out of bounds.
pub fn add_edge_source(&mut self, edge_id: EdgeId, w: O) -> NodeId
pub fn add_edge_target(&mut self, edge_id: EdgeId, w: O) -> NodeId
Sourcepub fn with_nodes<T, F: FnOnce(Vec<O>) -> Vec<T>>(
self,
f: F,
) -> Option<OpenHypergraph<T, A>>
pub fn with_nodes<T, F: FnOnce(Vec<O>) -> Vec<T>>( self, f: F, ) -> Option<OpenHypergraph<T, A>>
Set the nodes of the OpenHypergraph, possibly changing types. Returns None if new nodes array had different length.
Sourcepub fn map_nodes<F: Fn(O) -> T, T>(self, f: F) -> OpenHypergraph<T, A>
pub fn map_nodes<F: Fn(O) -> T, T>(self, f: F) -> OpenHypergraph<T, A>
Map the node labels of this OpenHypergraph, possibly changing their type
Sourcepub fn with_edges<T, F: FnOnce(Vec<A>) -> Vec<T>>(
self,
f: F,
) -> Option<OpenHypergraph<O, T>>
pub fn with_edges<T, F: FnOnce(Vec<A>) -> Vec<T>>( self, f: F, ) -> Option<OpenHypergraph<O, T>>
Set the edges of the OpenHypergraph, possibly changing types. Returns None if new edges array had different length.
Sourcepub fn map_edges<F: Fn(A) -> T, T>(self, f: F) -> OpenHypergraph<O, T>
pub fn map_edges<F: Fn(A) -> T, T>(self, f: F) -> OpenHypergraph<O, T>
Map the edge labels of this OpenHypergraph, possibly changing their type
Source§impl<O, A> OpenHypergraph<O, A>
impl<O, A> OpenHypergraph<O, A>
pub fn identity(a: Vec<O>) -> Self
pub fn spider(s: FiniteFunction, t: FiniteFunction, w: Vec<O>) -> Option<Self>
Source§impl<O: Clone, A: Clone> OpenHypergraph<O, A>
impl<O: Clone, A: Clone> OpenHypergraph<O, A>
Source§impl<O: Clone + PartialEq, A: Clone> OpenHypergraph<O, A>
impl<O: Clone + PartialEq, A: Clone> OpenHypergraph<O, A>
Sourcepub fn quotient(&mut self) -> Result<FiniteFunction, FiniteFunction>
pub fn quotient(&mut self) -> Result<FiniteFunction, FiniteFunction>
Apply the quotient map to identify nodes in the internal Hypergraph,
returning the computed coequalizer.
Sourcepub fn quotient_witness(&mut self) -> Result<FiniteFunction, FiniteFunction>
👎Deprecated since 0.2.10: use OpenHypergraph::quotient
pub fn quotient_witness(&mut self) -> Result<FiniteFunction, FiniteFunction>
use OpenHypergraph::quotient
Deprecated alias for Self::quotient
Sourcepub fn to_strict(self) -> OpenHypergraph<VecKind, O, A>
pub fn to_strict(self) -> OpenHypergraph<VecKind, O, A>
Convert this lax OpenHypergraph to a strict crate::strict::OpenHypergraph by
quotienting.
pub fn to_open_hypergraph(self) -> OpenHypergraph<VecKind, O, A>
renamed to_strict
Source§impl<O: Clone + PartialEq, A: Clone> OpenHypergraph<O, A>
impl<O: Clone + PartialEq, A: Clone> OpenHypergraph<O, A>
Sourcepub fn spiderize(
self,
) -> Result<OpenHypergraph<O, WithSpider<A>>, FiniteFunction>
pub fn spiderize( self, ) -> Result<OpenHypergraph<O, WithSpider<A>>, FiniteFunction>
Replace implicit wiring with explicit spider operations.
The result is strict (has no pending quotient), monogamous, and
acyclic. Each original operation is retained as
WithSpider::Operation.
For every original node, the construction inserts two spiders:
p -> 1 + mon the left, wherepis the number of global source occurrences andmis the number of operation-source occurrences;1 + n -> qon the right, wherenis the number of operation-target occurrences andqis the number of global target occurrences.
The extra leg connects the two spiders. Every other occurrence gets a distinct node, making every node occur exactly once as a source and exactly once as a target (counting the global interfaces).
Pending identifications in the lax quotient are applied first. An error
means that the quotient attempted to identify nodes with different
labels; the returned finite function is the quotient witness, as for
OpenHypergraph::quotient.
Sourcepub fn spiderize_nodes(
self,
nodes: &[NodeId],
) -> Result<OpenHypergraph<O, WithSpider<A>>, FiniteFunction>
pub fn spiderize_nodes( self, nodes: &[NodeId], ) -> Result<OpenHypergraph<O, WithSpider<A>>, FiniteFunction>
Replace the chosen nodes’ implicit wiring with explicit spider operations.
Each selected node is replaced by the same pair of spiders used by
Self::spiderize. Unselected nodes retain their implicit wiring.
Consequently, unlike Self::spiderize, this operation does not by
itself guarantee that the result is acyclic or monogamous.
nodes contains IDs from the input hypergraph. Pending identifications
are applied first, and IDs in nodes are mapped through the resulting
quotient. Selecting any representative therefore selects its complete
equivalence class. Duplicate selections are ignored.
§Panics
Panics if a selected node ID is out of bounds.
Trait Implementations§
Source§impl<O: Clone + PartialEq, A: Clone> BitOr<&OpenHypergraph<O, A>> for &OpenHypergraph<O, A>
impl<O: Clone + PartialEq, A: Clone> BitOr<&OpenHypergraph<O, A>> for &OpenHypergraph<O, A>
Source§type Output = OpenHypergraph<O, A>
type Output = OpenHypergraph<O, A>
| operator.Source§impl<O: Clone, A: Clone> Clone for OpenHypergraph<O, A>
impl<O: Clone, A: Clone> Clone for OpenHypergraph<O, A>
Source§fn clone(&self) -> OpenHypergraph<O, A>
fn clone(&self) -> OpenHypergraph<O, A>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<O: Clone + PartialEq, A: Clone> Shr<&OpenHypergraph<O, A>> for &OpenHypergraph<O, A>
impl<O: Clone + PartialEq, A: Clone> Shr<&OpenHypergraph<O, A>> for &OpenHypergraph<O, A>
Source§impl<O: Clone + PartialEq, A: Clone + PartialEq> Spider<VecKind> for OpenHypergraph<O, A>
impl<O: Clone + PartialEq, A: Clone + PartialEq> Spider<VecKind> for OpenHypergraph<O, A>
Source§fn dagger(&self) -> Self
fn dagger(&self) -> Self
Arrow with type f : A → B,
construct its dagger f† : B → A
by using Hypergraph structure to bend sources to targets and vice-versa.Source§fn spider(
s: FiniteFunction<VecKind>,
t: FiniteFunction<VecKind>,
w: Self::Object,
) -> Option<Self>
fn spider( s: FiniteFunction<VecKind>, t: FiniteFunction<VecKind>, w: Self::Object, ) -> Option<Self>
w, and source s and target t interface maps.Source§fn half_spider(s: FiniteFunction<K>, w: Self::Object) -> Option<Self>
fn half_spider(s: FiniteFunction<K>, w: Self::Object) -> Option<Self>
t leg is identity.