dt#
Functions
|
Recursively flatten a list of arbitrary depth into a flat list. |
|
Parse DT notation (knot or link) and return a diagram. |
Serialize a knot/link diagram to DT notation. |
- from_dt_notation(notation, oriented=False)#
Parse DT notation (knot or link) and return a diagram.
This currently parses and validates the input but does not finish the DT→diagram construction (the original code also stopped mid-way). For now, non-empty inputs raise a clear
NotImplementedError
instead of silently printing and returningNone
.- Accepts:
A string with rows separated by commas/semicolons/spaces (e.g.
"4 -6 2"
or"4 -6 2 ; 8 -10 12"
)A list of ints (knot) → will be wrapped as a single-component link
A list of lists of ints (link)
- Parameters:
notation (str | Iterable[int] | Iterable[Iterable[int]]) – DT notation (string or nested iterables of ints).
oriented (bool) – If
True
, returns an oriented diagram instance; ifFalse
, an unoriented one.
- Returns:
PlanarDiagram | OrientedPlanarDiagram – Empty diagram if input is empty.
- Raises:
ValueError – If parsing fails.
NotImplementedError – For non-empty inputs until the constructor is completed.
Notes
The unfinished part in the original code explored endpoint placement options but never built the final diagram. This version preserves behavior safely by raising a clear exception.
- to_dt_notation(k)#
Serialize a knot/link diagram to DT notation.
For knots, returns a single tuple of signed odd labels. For links, returns a tuple of tuples (one per component), following the usual conventions: - Label even indices along the traversal at each crossing on the incoming over endpoint. - The sign of the paired odd label is positive/negative based on the local crossing orientation.
- Parameters:
k – Planar or oriented diagram.
- Returns:
tuple – For a knot,
(l1, l2, ..., l_{2n})
. For a link,((...), (...), ...)
.- Raises:
ValueError – If the diagram is not a knot/link in a way compatible with DT.
- Return type:
Tuple[Tuple[int, …], …] | Tuple[int, …]