Path and cycle#

Path and cycle on n nodes: moments, generating functions and exact laws.

The laws come from the generating functions of the exact stabilization-time paper, computed as exponential series whose normalized coefficients count (labeling, coloring) pairs by their number of peaks (see tinto.theory._egf): the monochrome path series solves the Riccati equation \(\partial_z P = v + 2P + P^2\), and the k-colored path and cycle series are rational in P.

tinto.theory.path_cycle.cycle_counts(order, k=1)[source]#

Peak counts on the cycle.

The cycle is opened at the node of smallest label, which leaves an oriented path whose ends may or may not share their color:

\[Y = kz + \int (1 + (k-1)v)\, T_{same} + \int (2 + (k-2)v)\, T_{dist},\]

with the series of path_counts() (monochrome, \(Y = z + \int P\)).

Parameters:
  • order (int) – Largest number of nodes.

  • k (int, default=1) – Number of colors.

Returns:

cyc[n][j] is the number of pairs (labeling with the smallest label on node 0, coloring) of the cycle on n nodes with j peaks: (n - 1)! k^n pairs in all, for n >= 3.

Return type:

series

Examples

On a monochrome triangle there is always exactly one peak:

>>> cycle_counts(3)[3]
[0, 2]
tinto.theory.path_cycle.cycle_series(z, v)[source]#

Closed form of the monochrome oriented cycle series.

\[Y(z, v) = -\log\left(\cos(z r) - \frac{\sin(z r)}{r}\right), \quad r = \sqrt{v - 1}.\]
Parameters:
  • z (complex) – Variable of the series, inside its disk of convergence.

  • v (complex) – Variable marking the peaks, v != 1.

Return type:

complex

Examples

>>> round(cycle_series(0.1, 2.0).real, 6)
0.110741
tinto.theory.path_cycle.law(n, k=1, cycle=False)[source]#

Exact law of the number of peaks S on the path (or the cycle), T = n - S.

Parameters:
  • n (int) – Number of nodes, n >= 3 for the cycle.

  • k (int, default=1) – Number of colors.

  • cycle (bool, default=False) – Cycle instead of path.

Returns:

P(S = j) for j = 0, ..., n.

Return type:

list of Fraction

Examples

>>> [str(x) for x in law(3)]
['0', '2/3', '1/3', '0']
>>> [str(x) for x in law(3, cycle=True)]
['0', '1', '0', '0']
tinto.theory.path_cycle.mean(n, k=1, cycle=False)[source]#

Mean stabilization time on the path (or the cycle) with n nodes.

Sum of the peak probabilities: two ends of degree 1 and n - 2 inner nodes of degree 2 on the path, n nodes of degree 2 on the cycle. Exact for n >= 2 (path) and n >= 3 (cycle).

Parameters:
  • n (int) – Number of nodes.

  • k (int, default=1) – Number of colors.

  • cycle (bool, default=False) – Cycle instead of path.

Return type:

float

Examples

>>> round(mean(60), 6)
39.666667
>>> round(mean(60, cycle=True), 6)
40.0
tinto.theory.path_cycle.path_counts(order, k=1)[source]#

Peak counts on the path, split by the colors of its two ends.

With \(P\) the monochrome series (\(\partial_z P = v + 2P + P^2\)), the k-colored path series are

\[T = \frac{kP}{1 - (k-1)P}, \quad T_{same} = \frac{(1 - (k-2)P)\, kP}{(1 + P)(1 - (k-1)P)}, \quad T_{dist} = \frac{k(k-1) P^2}{(1 + P)(1 - (k-1)P)},\]

with \(T = T_{same} + T_{dist}\).

Parameters:
  • order (int) – Largest number of nodes.

  • k (int, default=1) – Number of colors.

Returns:

(total, same, dist): total[n][j] is the number of (labeling, coloring) pairs of the path on n nodes with j peaks (n! k^n pairs in all); same and dist restrict to the colorings whose two ends share their color or not (a single node counts as same).

Return type:

tuple of three series

Examples

On three nodes, monochrome, 4 labelings of 6 have one peak:

>>> path_counts(3)[0][3]
[0, 4, 2]
>>> total, same, dist = path_counts(2, k=2)
>>> total[2], same[2], dist[2]
([0, 4, 4], [0, 4], [0, 0, 4])
tinto.theory.path_cycle.path_series(z, v)[source]#

Closed form of the monochrome path series.

\[P(z, v) = \frac{v \tan(z r)}{r - \tan(z r)}, \quad r = \sqrt{v - 1}.\]
Parameters:
  • z (complex) – Variable of the series, inside its disk of convergence.

  • v (complex) – Variable marking the peaks, v != 1.

Return type:

complex

Examples

>>> round(path_series(0.1, 2.0).real, 6)
0.223049
tinto.theory.path_cycle.variance(n, k=1, cycle=False)[source]#

Variance of the stabilization time on the path (or the cycle) with n nodes.

Linear in n with slope \((45k^3 - 90k^2 + 60k - 13)/(45k^4)\); the path subtracts the boundary term \((45k^3 - 135k^2 + 120k - 32)/(45k^4)\). Exact for n >= 4 (path) and n >= 5 (cycle), where pairs of nodes at distance two no longer overlap.

Parameters:
  • n (int) – Number of nodes.

  • k (int, default=1) – Number of colors.

  • cycle (bool, default=False) – Cycle instead of path.

Return type:

float

Examples

>>> round(variance(60), 6)
2.711111
>>> round(variance(60, cycle=True), 6)
2.666667