contract_arc#

contract_arc(k: PlanarDiagram, arc_for_contracting, inplace=True) PlanarDiagram#

Contracts a specific arc in a PlanarDiagram by merging its endpoints into one vertex.

Args:

k (PlanarDiagram): The planar diagram in which the arc contraction will be performed. arc_for_contracting (Tuple[Tuple[int, int], Tuple[int, int]]): The arc to be contracted,

represented as a tuple of two endpoints, where each endpoint is a tuple consisting of a node identifier and a position index. The first tuple is the ‘contracted’ endpoint that remains after contraction, and the second tuple is the endpoint to be removed.

inplace (bool, optional): If True, the operation is performed directly on the input

PlanarDiagram object. If False, a copy of the input diagram will be modified, and the original remains unchanged. Defaults to True.

Returns:

PlanarDiagram: The modified planar diagram after the arc contraction if inplace is False, or the same (mutated) diagram if inplace is True.

Raises:

TypeError: If either of the endpoints specified in arc_for_contracting does not belong to a vertex in the planar diagram. ValueError: If the arc specified forms a loop (i.e., the endpoints are on the same vertex) and cannot be contracted.