remove#

Utilities for removing structure from planar diagrams: - empty nodes - a specific arc - all loops - unknots - bivalent (degree-2) vertices

Functions

remove_arc(k, arc_for_removing[, inplace])

Remove a single arc.

remove_bivalent_vertex(k, node[, keep_if_unknot])

Remove a degree-2 vertex by splicing its incident edges.

remove_bivalent_vertices(k[, match_attributes])

Remove all degree-2 vertices by splicing their incident edges.

remove_empty_nodes(k[, inplace])

Remove all nodes with degree 0.

remove_loops(k)

Remove all loops (arcs whose endpoints share the same node).

remove_unknots(k[, max_unknots])

Remove disjoint unknots (degree-2 looped vertices) from the diagram.

remove_empty_nodes(k, inplace=True)#

Remove all nodes with degree 0.

Parameters:
  • k (PlanarDiagram) – Diagram to clean.

  • inplace (bool) – If False, operate on a copy.

Returns:

The mutated diagram (or the new copy if inplace=False).

Return type:

PlanarDiagram

remove_arc(k, arc_for_removing, inplace=True)#

Remove a single arc.

Parameters:
  • k (PlanarDiagram) – Diagram to modify.

  • arc_for_removing (frozenset) – The arc to remove (conventionally a frozenset of two endpoints).

  • inplace (bool) – If False, operate on a copy.

Returns:

The mutated diagram (or the new copy if inplace=False).

Return type:

PlanarDiagram

remove_loops(k)#

Remove all loops (arcs whose endpoints share the same node).

Operates in place.

Parameters:

k (PlanarDiagram) – Diagram to modify.

Returns:

The number of removed loops.

Return type:

int

remove_unknots(k, max_unknots=None)#

Remove disjoint unknots (degree-2 looped vertices) from the diagram.

Parameters:
  • k (PlanarDiagram) – Diagram to modify (in place).

  • max_unknots (int | None) – If provided, remove at most this many unknots.

Returns:

Number of removed unknots.

Return type:

int

remove_bivalent_vertex(k, node, keep_if_unknot=True)#

Remove a degree-2 vertex by splicing its incident edges.

If both incident arcs form a trivial loop at the same vertex and keep_if_unknot is True, the vertex is kept.

Parameters:
  • k (PlanarDiagram) – Diagram to modify (in place).

  • node – The degree-2 vertex to remove.

  • keep_if_unknot (bool) – Preserve the vertex if it is the center of an unknot.

Raises:

ValueError – If node is not degree-2.

Return type:

None

remove_bivalent_vertices(k, match_attributes=False)#

Remove all degree-2 vertices by splicing their incident edges.

Parameters:
  • k (PlanarDiagram) – Diagram to modify (in place).

  • match_attributes (bool) – If True, only remove a bivalent vertex when the four adjacent/incident endpoints have matching attributes in pairs (i.e., compatible to splice). If False, remove regardless of attrs.

Returns:

The number of removed bivalent vertices.

Return type:

int

Notes

  • Loops are never spliced here.

  • For oriented diagrams, vertices whose two outward endpoints have the same direction are skipped (incoherent pairing).