API reference

Filename: braid.py Description: Main braid class Authors: Baptiste Labat Created: 2025-05-24 Repository: https://github.com/baptistelabat/braidpy License: Mozilla Public License 2.0

class braidpy.braid.BraidWordNotation(value)

Bases: str, Enum

ARTIN = 'ARTIN'
ALPHA = 'ALPHA'
DEFAULT = 'DEFAULT'
braidpy.braid.single_crossing_braiding_process(process: Tuple[int | Tuple[int, ...], ...]) List[int]

Flattens a tuple of braiding steps into a list of signed crossings.

Each step may be a single crossing or multiple simultaneous crossings. To get Artin generators we need only consecutive single crossing, which is topologically equivalent

class braidpy.braid.Braid(process: int | Tuple[int | Tuple[BraidProcess, ...], ...], n_strands: int | None = None)

Bases: object

Sometimes referred as algebraic braids :param process: list of Artin’s generator, which may group or not by parenthesis (tuples) :type process: BraidProcess :param n_strands: number of strands. Default to the minimum number needed for process :type n_strands: Optional[int]

process: int | Tuple[int | Tuple[BraidProcess, ...], ...]
n_strands: int | None = None
property generators
property main_generator

A main generator of a braid word w is the generator with the lowest index https://pure.tue.nl/ws/portalfiles/portal/67742824/630595-1.pdf page 33

format_to_notation(target: str = '')

Inspired from https://github.com/abhikpal/dehornoy/blob/master/braid.py

Allow to format the braidword using several classical notations.:

The Artin representation can also be used in a latex file.

The neutral element is β€˜e’ for the Artin representation and β€˜#’ for alpha.

Parameters:

target (str) – Among β€˜alpha’: for example β€˜aBa’ β€˜artin’ for example β€˜s_{1}^{1.0} s_{2}^{1.0} s_{1}^{-1.0} s_{2}^{-1.0}’ β€˜default’ syntax used by other tools such as math-braid and braidlab

Returns:

the formated braid word

Return type:

str

format(generator_symbols: list[str] = None, inverse_generator_symbols: list[str] = None, zero_symbol: str = 'e', separator: str = '') str

Allow to format the braid word following different formats.

Note that the power are limited to -1/1 due to the actual braid word definition (not possible to display σ₁² for example)

See also format_to_notation for simpler predefined format

Parameters:
  • generator_symbols (Optional(list[str])) – Default to [β€œΟƒβ‚β€, β€œΟƒβ‚‚β€, …]

  • inverse_generator_symbols (Optional(list[str])) – Default to [β€œΟƒβ‚β»ΒΉβ€, …]

  • zero_symbol (Optional(str)) – Default to β€œe

  • separator (Optional(str)) – Default to β€œβ€

Returns:

the formated braid word

Return type:

str

no_zero()

Suppress all the zero steps (multiplication by neutral element)

Returns:

Braid

word_length()

Length of the word including neutral element

Returns:

the length of the braid word

Return type:

int

word_eq(other)
inverse() Braid

Return the inverse of the braid This corresponds to the image of the braid in a mirror. Both order and signs are reversed

Returns:

the inverse braid

Return type:

Braid

n(n_strands) Braid

Compact notation to allow to change the number of strands

Parameters:

n_strands

Returns:

flip() Braid

Flip the braid This corresponds to the image of the braid in a mirror on the side of the braid reordered from left to right The strands are reversed, not the order of operations Sign is also changed. This step is often used when braiding

>>> b = Braid([1], 3)
>>> basic_3_braid = (b*(b.flip()))**3
Returns:

the reversed braid

Return type:

Braid

half_twist(sign: int = 1) Braid

Twist the braid with half a turn

https://en.wikipedia.org/wiki/Twist_(differential_geometry)

Parameters:

sign (Optional[int]) – sign of the twist. IF positive the first strand is going over. Default to +1

Returns:

the twisted braid

Return type:

Braid

full_twist(sign: int = 1) Braid

Twist the braid with a complete turn

https://en.wikipedia.org/wiki/Twist_(differential_geometry)

Parameters:

sign (Optional[int]) – sign of the twist. IF positive the first strand is going over. Default to +1

Returns:

the twisted braid

Return type:

Braid

up_side_down() Braid

Invert up and down crossing operations

For hair braiding this is called β€œinversé”

Returns:

the mirrored braid

Return type:

Braid

is_reduced() bool

A braid word w is reduced either if it is the null string, or the empty braid, or if the main generator of w occurs only positively or only negatively. https://pure.tue.nl/ws/portalfiles/portal/67742824/630595-1.pdf page 33

writhe() int

Calculate the writhe of the braid (sum of generator powers)

get_canonical_factors() GarsideCanonicalFactors

Get decomposition in left normal form

Relies on math_braid implementation from J. Cha et al, β€œAn Efficient Implementation of Braid Groups”, Advances in Cryptology: Proceedings of ASIACRYPT 2001, Lecture Notes in Computer Science (2001), 144–156. https://www.iacr.org/archive/asiacrypt2001/22480144.pdf

Returns:

the unique decomposition of the braid according to left convention

Return type:

GarsideCanonicalFactors

to_matrix() MutableDenseMatrix

Convert braid to its (unreduced) Burau matrix representation.

to_reduced_matrix()

Return the reduced Burau representation

odo Implementation not finished

is_trivial() bool

Check if the braid is trivial (identity braid)

permutations(plot=False) List[int]

Return the permutations induced by the braid

perm() list[PositiveInt]

Compute the permutation corresponding to the braid

This is a braid invariant.

Returns:

return the final permutation due to braid

Return type:

list

is_pure() bool

Check if a braid is pure (permutation is identity)

is_palindromic()
is_involutive() bool

Returns true if inverse of braid word ie the same as braid word This probably works only for the neutral element

Returns:

True if braid word is involutive

Return type:

bool

is_periodic() bool

braid x is periodic if and only if its nth power or its (n βˆ’ 1)st power is a power of the half-twist βˆ†

https://hal.science/hal-00647035v2/file/B_nNTHClassificationv5.pdf

Periodic braid are roots of βˆ†**m https://homepages.math.uic.edu/~jaca2009/notes/Meneses.pdf

is_brunnian() bool

A Brunnian braid is a braid that becomes trivial upon removal of any one of its strings. Brunnian braids form a subgroup of the braid group

https://en.wikipedia.org/wiki/Brunnian_link#Brunnian_braids

Returns:

True if Brunnian

Return type:

bool

is_reducible() bool
If a braid is reducible, it means that the strands can be separated into groups of strands

(less groups than number of strands), such that each group is running inside one tube. The tubes themselves can form a braid

Returns:

bool

to_parametric_strands(amplitude: float = 0.2) List[ParametricStrand]

Converts a braid into a list of 3D parametric strand paths.

Parameters:
  • braid – The Braid object containing crossing generators.

  • amplitude – Height of the sine wave for over/under crossings.

Returns:

A list of ParametricStrand objects representing the strands.

draw()

Draw the braid in the terminal with arrows allowing to better check the differnet operations (with colors !)

Returns:

return the braid itself to allow to debug in a chain

Return type:

Braid

plot(style='ext', line_width=3, gap_size=3, color='rainbow', save=False)

Plot the braid using library braid-visualiser https://github.com/rexgreenway/braid-visualiser

Parameters:
  • style (Optional(str)) – β€œcomp” or β€œext”(default) β€œcomp” renders the image of the braid in a compact style with crossings parallel to one another if possible. β€œext”, for extended, shows the crossings in series.

  • line_width (Optional(int)) – Default to 3 Thickness of the strands in the figure.

  • gap_size (Optional(int)) – Default to 3 Amount of space shown at crossings for undercrossing strands.

  • color (str) – Multicolor strands defined by β€œrainbow”. Single fixed colour for all strands can be chosen from: {β€˜b’: blue, β€˜g’: green, β€˜r’: red, β€˜c’: cyan, β€˜m’: magenta, β€˜y’: yellow, β€˜k’: black, β€˜w’: white}

  • save (bool) – if True save to file β€œtest.svg”

Returns:

return the slightly modified braid to allow to debug in a chain

Return type:

Braid

braidpy.braid.slide_strand(n_slide, start_index=1, sign: int = 1)

Combine Artin Generator to move one braid over or under several braids

This is noted as (ai…as) by Garside where i=start_index and s= i+n_slide

Ξ s corresponds to start_index=1 (default) and n_slide=s-1

Parameters:
  • n_slide (int) – number of crossings

  • start_index (Optional(int)) – index of the strand to move. Default to 1

  • sign (Optional[int]) – positive if the start strand is going over. Default to +1

Returns:

the corresponding braid

Return type:

Braid

braidpy.braid.weave_strand(n_slide, start_index=1, sign: int = 1)

Combine Artin Generator to move one braid over/under/over… or under/over/under… several braids

Parameters:
  • n_slide (int) – number of crossings

  • start_index (Optional(int)) – index of the strand to move. Default to 1

  • sign (Optional[int]) – positive if the start strand is first going over. Default to +1

Returns:

the corresponding braid

Return type:

Braid

Filename: artin_generators.py Description: Artin’s generators enables to describe a braid by successive crossing operations Authors: Baptiste Labat Created: 2025-05-30 Repository: https://github.com/baptistelabat/braidpy License: Mozilla Public License 2.0

class braidpy.artin_generators.a(process: int | Tuple[int | Tuple[BraidProcess, ...], ...], n_strands: int | None = None)

Bases: Braid

This class is a shortcut to be able to use a compact notation with Artin’s generators

Filename: braid_catalog.py Description: A catalog of different remarkable braids Authors: Baptiste Labat Created: 2025-05-30 Repository: https://github.com/baptistelabat/braidpy License: Mozilla Public License 2.0

braidpy.braid_catalog.garside_half_twist_braid(n_strands: StrictlyPositiveInt) Braid

Compute the Garside half twist braid also known as Garside element βˆ†n or (simply βˆ† if n=n_strands-1) βˆ†Β² is known to generate the β€œcenter” of the braid group Bn+1. This is the biggest simple element.

It is sometimes called fundamental braid. It can be obtained by recursion βˆ†n = Οƒ1Οƒ2…σnβˆ’1βˆ†nβˆ’1

Demi-vrille

Composition of half_twist is giving a β€œtorsade”

Parameters:

n_strands (StrictlyPositiveInt) – number of strands

Returns:

Braid

braidpy.braid_catalog.full_twist_braid(n_strands: StrictlyPositiveInt) Braid

Compute the full twist braid βˆ†nΒ² which is the square of Garside half twist braid βˆ†n It is known to generate the β€œcenter” of the braid group Bn.

Vrille

Composition of twist is giving a β€œtorsade”

Parameters:

n_strands (StrictlyPositiveInt) – number of strands

Returns:

Braid

braidpy.braid_catalog.flat3() Tuple[Braid, int]

Basic braid with 3 strands going above central braid

ABOK 2965: β€œFLAT, ENGLISH, ORDINARY or COMMON SINNET is the plat or braid seen in schoolgirl pigtails. It is made of three strands and is the simplest possible plat. To make: Secure three strands together and make the end fast to a hook or nail. Hold two strands in the right hand and one in the left. Bring the outer right strand down across its sister strand and lay it parallel to and below the single left strand. Now bring the upper Ie ft strand down across its sister strand and lay it parallel to and below the single right strand. Repeat alternately”

Returns:

the braid object describing the single step to realize the braid n: the number of iterations to get back to initial order of strands

Return type:

Braid

braidpy.braid_catalog.inverted_flat3() Tuple[Braid, int]

Basic braid with 3 strands going below central braid

ABOK 2966: β€œPossibly a quicker but less usual way to make this plat is - to pass the strands at the back, employing only the first and second fingers and the thumbs”

Returns:

the braid object describing the single step to realize the braid n: the number of iterations to get back to initial order of strands

Return type:

Braid

braidpy.braid_catalog.square4() Tuple[Braid, int]

Basic round braid with 4 strands

Returns:

the braid object describing the single step to realize the braid n: the number of iterations to get back to initial order of strands

Return type:

Braid

braidpy.braid_catalog.asymmetric_flat4() Tuple[Braid, int]

Basic flat braid with 4 strands

https://www.youtube.com/watch?v=7lTFIzm9BLY

ABOK 2969: β€œUnless for some special purpose, this method is usually limited to an odd number of strands, as with an even number of strands the sinnet is unsymmetrical. But I have seen the braid, made as if with three strands in the left hand and one in the right hand, as here pictured, used as edging on theater-seat upholstery. Of course it was machine-made.”

Returns:

the braid object describing the single step to realize the braid n: the number of iterations to get back to initial order of strands

Return type:

Braid

braidpy.braid_catalog.flat6() Tuple[Braid, int]

This one is probably not unique !

https://www.youtube.com/watch?v=ZHWlYBxL-mA

Returns:

the braid object describing the single step to realize the braid n: the number of iterations to get back to initial order of strands

Return type:

Braid

braidpy.braid_catalog.regular_flat6() Tuple[Braid, int]

https://www.youtube.com/watch?v=J65kCzm_BtI

Returns:

the braid object describing the single step to realize the braid n: the number of iterations to get back to initial order of strands

Return type:

Braid

braidpy.braid_catalog.double_flat3(parallel: bool = True)

if parallel = False ABOK 2971: β€œIf the same method of turning edges is applied where units of two or three parallel round cords are used, instead of single strands, a distinctive sinnet results”

if parallel = True ABOK 2972: β€œIn this sinnet the strands are double and parallel. The effect is very different from the last, in which the edges were turned.”

Returns:

the braid object describing the single step to realize the braid n: the number of iterations to get back to initial order of strands

Return type:

Braid

braidpy.braid_catalog.weave3()

This a 3 strands braid were 2 braids are running parallel while the third one is weaving them

ABOK 2973: β€œThe number of sinnets that are possible with three strands only seem very limited. Three are given on these two facing pages.”

Returns:

the braid object describing the single step to realize the braid n: the number of iterations to get back to initial order of strands

Return type:

Braid

braidpy.braid_catalog.abok_2974()
  1. With four strands the horizon is somewhat widened.

Returns:

braidpy.braid_catalog.flat5() Tuple[Braid, int]

https://www.youtube.com/watch?v=uRy4wvJwSWA

Returns:

the braid object describing the single step to realize the braid n: the number of iterations to get back to initial order of strands

Return type:

Braid

braidpy.braid_catalog.flat_sinnet5()

ABOK 2967: β€œWith more than three strands it is well to secure the strands in a straight line. Two pencils and two elastic bands are sufficient apparatus. FLAT SI~NET may be made with any odd number of strands in the way already described. The outer strands are moved alternately, and the tension is correctly and evenly arranged as each strand is passed”.

Returns:

the braid object describing the single step to realize the braid n: the number of iterations to get back to initial order of strands

Return type:

Braid

braidpy.braid_catalog.flat_sinnet7()

ABOK 2968: β€œSeven strands is about the practical limit of the method. Beyond that there is difficulty in keeping it even. Even if a degree of success is achieved, a very little rough treatment will cause it to distort.”

Returns:

the braid object describing the single step to realize the braid n: the number of iterations to get back to initial order of strands

Return type:

Braid

Filename: handles_reduction.py Description: Simplification of braid word to get unique braid representation Authors: Baptiste Labat Created: 2025-06-03 Repository: https://github.com/baptistelabat/braidpy License: Mozilla Public License 2.0

exception braidpy.handles_reduction.HandleReducedButUnexpectedResult

Bases: FunctionalException

Exception to be raised if handle reduction is not finishing as expected

class braidpy.handles_reduction.HandleReductionMode(value)

Bases: str, Enum

Define the possible options for handle reduction

-full: reduce all handles -compare: partical short circuit reductio which is exiting as long as we can determine if braid is positive, or negative

FULL = 'FULL'
COMPARE = 'COMPARE'
class braidpy.handles_reduction.HandleReductionResults(generators: tuple[int], sign: int, handle_reduction_mode: braidpy.handles_reduction.HandleReductionMode)

Bases: object

generators: tuple[int]
sign: int
handle_reduction_mode: HandleReductionMode
braidpy.handles_reduction.dehornoy_handle_indices(gens: list[int]) tuple[PositiveInt, PositiveInt] | None

Detect the first Dehornoy handle in gens. A handle is of the form g … g^-1, with all intermediates having strictly larger absolute values.

Parameters:

gens (list[SignedCrossingIndex]) – list of Artin’s generator

Returns:

(i, j) β€” the indices of g and g^-1 β€” for the first such valid handle or None if no more handles

Return type:

Tuple[int, int] | None

braidpy.handles_reduction.reduce_handle(segment: list[int]) list[int]

Reduces a Dehornoy handle of the form [sigma_m, u…, sigma_m^{-1}] by keeping u and replacing each sigma_{m+1} with sigma_{m+1}^{-1} * sigma_m * sigma_{m+1}.

Parameters:

segment (list[SignedCrossingIndex]) – segment corresponding to handle

Returns:

the segment with handle reduced (and no more complete handle, but it may create the start of new one)

Return type:

list[SignedCrossingIndex]

Raises:

ValueError – if segment is not a handle

braidpy.handles_reduction.dehornoy_sign(gens: List[int]) int | None

Check if braid is Dehornoy positive, negative, neutral or if this can not be directly said from braid word

Parameters:

gens(SignedCrossingIndex – list of Artin’s generator

Returns:

1 if Dehornoy positive, -1 if Dehornoy negative, 0 if neutral element and None if it can not be said

Return type:

int|None

braidpy.handles_reduction.dehornoy_reduce_core(gens: List[int], mode: HandleReductionMode | str = HandleReductionMode.FULL, time_out_s: float = 1) tuple[List[int], int | None]

Unified Dehornoy reduction engine.

Parameters:
  • -gens (List[SignedCrossingIndex]) – list of Artin’s generators

  • -mode (HandleReductionMode | str) – β€œFULL”: returns the fully reduced word. β€œCOMPARE`: returns early if positive/neutral/negative.

  • -time_out_s (Optional(float)) – safety timeout. Default to 1

Returns:

(reduced_gens, sign) where sign is:

Return type:

tuple[List[SignedCrossingIndex], int|None]

  • 1 if Dehornoy positive

  • -1 if Dehornoy negative

  • 0 if neutral element

  • None in case it can not be said without reducing handles further

Raises:

HandleReducedButUnexpectedResult –

Filename: material_braid.py Description: Material braids describe real world braid Authors: Baptiste Labat Created: 2025-05-25 Repository: https://github.com/baptistelabat/braidpy License: Mozilla Public License 2.0

class braidpy.material_braid.MaterialStrand(func: Callable[[float], tuple], radius: PositiveFloat = 0.005)

Bases: ParametricStrand

class braidpy.material_braid.MaterialBraid(strands: tuple[ParametricStrand])

Bases: object

Filename: parametric_braid.py Description: A braid describes by a punctured disk Authors: Baptiste Labat Created: 2025-05-25 Repository: https://github.com/baptistelabat/braidpy License: Mozilla Public License 2.0

class braidpy.parametric_braid.Plotter(value)

Bases: str, Enum

PLOTLY = 'PLOTLY'
MATPLOTLIB = 'MATPLOTLIB'
class braidpy.parametric_braid.ParametricBraid(strands: list[ParametricStrand])

Bases: object

get_positions_at(t: PositiveFloat) List[Tuple[float, float, float]]

Get position of different strands at a given time

Parameters:

t – time or z coordinates

Returns:

list of 3D coordinates

Return type:

List[Tuple[float, float, float]]

plot(n_sample: StrictlyPositiveInt = 200, plotter: Plotter = Plotter.PLOTLY) ParametricBraid

Plot the braid in 3D

Parameters:

n_sample

Returns:

the braid itself

Return type:

ParametricBraid

Filename: utils.py Description: Utility functions, not directly related to braids Authors: Baptiste Labat Created: 2025-05-24 Repository: https://github.com/baptistelabat/braidpy License: Mozilla Public License 2.0

braidpy.utils.colorize_by_index(text: str, index: int) str

Colorize a string using a repeating color based on index (starting at 0).

braidpy.utils.colorize(item: str | int, index: int | None = None) str

Colorize item based on index (or its value if it’s an int).

braidpy.utils.int_to_superscript(n: int) str
braidpy.utils.int_to_subscript(n: int) str
class braidpy.utils.PositiveFloat(value: Any)

Bases: float

class braidpy.utils.StrictlyPositiveFloat(value: Any)

Bases: float

class braidpy.utils.PositiveInt(value: Any)

Bases: int

class braidpy.utils.StrictlyPositiveInt(value: Any)

Bases: int

exception braidpy.utils.FunctionalException

Bases: Exception