contract_arc#

contract_arc(k, arc_for_contracting, inplace=True)#

Contract a specific arc by merging its endpoints into a single vertex.

The arc is specified as an ordered pair of endpoints: the first endpoint is kept (its vertex remains), and the second endpoint’s vertex is removed. All other incident endpoints of the removed vertex are reattached to the kept vertex, preserving cyclic order via pull_and_plug_endpoint.

This operation is only defined for vertex–vertex arcs (both endpoints must lie on vertices). Loops (both endpoints on the same vertex) are not contractible.

Parameters:
  • k (PlanarDiagram) – The planar diagram to modify.

  • arc_for_contracting (tuple[Endpoint | tuple, Endpoint | tuple]) – Ordered pair (keep_endpoint, remove_endpoint) where each endpoint is either an Endpoint or a (node, position) tuple.

  • inplace (bool) – If True (default), mutate k. If False, return a modified copy.

Returns:

The diagram with the arc contracted (k itself if inplace=True).

Raises:
  • TypeError – If either endpoint is not on a vertex.

  • ValueError – If the arc is a loop (both endpoints on the same vertex).

Return type:

PlanarDiagram