Skip to main content

OpenHypergraph

Struct OpenHypergraph 

Source
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>

Source

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>

Source

pub fn tensor_assign(&mut self, rhs: OpenHypergraph<O, A>)

Compute the tensor product f.tensor(g) by mutating the data of f

Source

pub fn append( &mut self, rhs: OpenHypergraph<O, A>, ) -> (Vec<NodeId>, Vec<NodeId>)

Append the data of rhs into self, but leave boundaries unchanged. Return the new source/target nodes of rhs after appending.

Source§

impl<O, A> OpenHypergraph<O, A>

Source

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.

Source

pub fn from_strict(f: OpenHypergraph<VecKind, O, A>) -> Self

Source

pub fn new_node(&mut self, w: O) -> NodeId

Create a new node in the hypergraph labeled w.

Source

pub fn new_edge(&mut self, x: A, interface: impl Into<Hyperedge>) -> EdgeId

Source

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:

  1. a new hyperedge labeled x
  2. len(s) new nodes, with the ith node labeled s[i]
  3. len(t) new nodes, with the ith node labeled t[i]

Returns the new hyperedge ID and the NodeIds of the source/target nodes.

This is a convenience wrapper for Hypergraph::new_operation

Source

pub fn singleton(x: A, source_type: Vec<O>, target_type: Vec<O>) -> Self

An OpenHypergraph consisting of a single operation.

Source

pub fn unify(&mut self, v: NodeId, w: NodeId)

Compute an open hypergraph by calling to_hypergraph on the internal Hypergraph.

Source

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.

Source

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.

Source

pub fn add_edge_source(&mut self, edge_id: EdgeId, w: O) -> NodeId

Source

pub fn add_edge_target(&mut self, edge_id: EdgeId, w: O) -> NodeId

Source

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.

Source

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

Source

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.

Source

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>

Source

pub fn identity(a: Vec<O>) -> Self

Source

pub fn spider(s: FiniteFunction, t: FiniteFunction, w: Vec<O>) -> Option<Self>

Source§

impl<O: Clone, A: Clone> OpenHypergraph<O, A>

Source

pub fn tensor(&self, other: &Self) -> Self

Source§

impl<O: Clone + PartialEq, A: Clone> OpenHypergraph<O, A>

Source

pub fn quotient(&mut self) -> Result<FiniteFunction, FiniteFunction>

Apply the quotient map to identify nodes in the internal Hypergraph, returning the computed coequalizer.

Source

pub fn quotient_witness(&mut self) -> Result<FiniteFunction, FiniteFunction>

👎Deprecated since 0.2.10:

use OpenHypergraph::quotient

Deprecated alias for Self::quotient

Source

pub fn to_strict(self) -> OpenHypergraph<VecKind, O, A>

Convert this lax OpenHypergraph to a strict crate::strict::OpenHypergraph by quotienting.

Source

pub fn to_open_hypergraph(self) -> OpenHypergraph<VecKind, O, A>

👎Deprecated since 0.2.4:

renamed to_strict

Source§

impl<O: Clone + PartialEq, A: Clone> OpenHypergraph<O, A>

Source

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 + m on the left, where p is the number of global source occurrences and m is the number of operation-source occurrences;
  • 1 + n -> q on the right, where n is the number of operation-target occurrences and q is 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.

Source

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> Arrow for OpenHypergraph<O, A>

Source§

type Object = Vec<O>

Source§

fn source(&self) -> Self::Object

Source§

fn target(&self) -> Self::Object

Source§

fn identity(a: Self::Object) -> Self

the identity morphism on a
Source§

fn compose(&self, other: &Self) -> Option<Self>

Compose morphisms in diagrammatic order: self ; other Read more
Source§

impl<O: Clone + PartialEq, A: Clone> BitOr<&OpenHypergraph<O, A>> for &OpenHypergraph<O, A>

Source§

type Output = OpenHypergraph<O, A>

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: &OpenHypergraph<O, A>) -> Self::Output

Performs the | operation. Read more
Source§

impl<O: Clone, A: Clone> Clone for OpenHypergraph<O, A>

Source§

fn clone(&self) -> OpenHypergraph<O, A>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<O: Debug, A: Debug> Debug for OpenHypergraph<O, A>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<O: Clone + PartialEq, A: Clone> Monoidal for OpenHypergraph<O, A>

Source§

fn unit() -> Self::Object

the monoidal unit object
Source§

fn tensor(&self, other: &Self) -> Self

f \otimes g of two morphisms
Source§

impl<O: PartialEq, A: PartialEq> PartialEq for OpenHypergraph<O, A>

Source§

fn eq(&self, other: &OpenHypergraph<O, A>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<O: Clone + PartialEq, A: Clone> Shr<&OpenHypergraph<O, A>> for &OpenHypergraph<O, A>

Source§

type Output = Option<OpenHypergraph<O, A>>

The resulting type after applying the >> operator.
Source§

fn shr(self, rhs: &OpenHypergraph<O, A>) -> Self::Output

Performs the >> operation. Read more
Source§

impl<O: Clone + PartialEq, A: Clone + PartialEq> Spider<VecKind> for OpenHypergraph<O, A>

Source§

fn dagger(&self) -> Self

Given an 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>

Construct a spider using a type w, and source s and target t interface maps.
Source§

fn half_spider(s: FiniteFunction<K>, w: Self::Object) -> Option<Self>

Construct a “half-spider”: a spider whose t leg is identity.
Source§

impl<O: PartialEq, A: PartialEq> StructuralPartialEq for OpenHypergraph<O, A>

Source§

impl<O: Clone + PartialEq, A: Clone + PartialEq> SymmetricMonoidal for OpenHypergraph<O, A>

Source§

fn twist(a: Self::Object, b: Self::Object) -> Self

Construct the symmetry \sigma_{a,b} from a and b.

Auto Trait Implementations§

§

impl<O, A> Freeze for OpenHypergraph<O, A>

§

impl<O, A> RefUnwindSafe for OpenHypergraph<O, A>

§

impl<O, A> Send for OpenHypergraph<O, A>
where O: Send, A: Send,

§

impl<O, A> Sync for OpenHypergraph<O, A>
where O: Sync, A: Sync,

§

impl<O, A> Unpin for OpenHypergraph<O, A>
where O: Unpin, A: Unpin,

§

impl<O, A> UnsafeUnpin for OpenHypergraph<O, A>

§

impl<O, A> UnwindSafe for OpenHypergraph<O, A>
where O: UnwindSafe, A: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.