Index
List of functions.
AnalyticComb.CYCAnalyticComb.I_gfAnalyticComb.MSETAnalyticComb.PSETAnalyticComb.SEQAnalyticComb.autocorrelation_polyAnalyticComb.bgf_momentsAnalyticComb.bin_words_runs_coeffAnalyticComb.bin_words_runs_probAnalyticComb.bin_words_with_k_occurencesAnalyticComb.bin_words_with_k_occurences_constrAnalyticComb.catalan_factorialAnalyticComb.dominant_poleAnalyticComb.estimate_markov_paramsAnalyticComb.fixed_size_compsAnalyticComb.fixed_size_comps_asymAnalyticComb.general_treesAnalyticComb.graph_closed_walks_gfAnalyticComb.graph_walks_countAnalyticComb.longest_run_binary_asymAnalyticComb.markov_bin_runs_bgfAnalyticComb.markov_bin_runs_momentsAnalyticComb.markov_bin_runs_probAnalyticComb.markov_bin_runs_pvalAnalyticComb.markov_dominant_poleAnalyticComb.partitions_asymAnalyticComb.partitions_asymAnalyticComb.partitions_gfAnalyticComb.partitions_max_rAnalyticComb.pattern_occurrences_bgfAnalyticComb.pattern_occurrences_momentsAnalyticComb.pattern_pvalAnalyticComb.pattern_waiting_probAnalyticComb.primes_composition_asymAnalyticComb.random_mapping_momentsAnalyticComb.restricted_sum_compAnalyticComb.restricted_sum_comp_gfAnalyticComb.restricted_sum_partAnalyticComb.restricted_sum_part_gfAnalyticComb.runs_dominant_poleAnalyticComb.stirling_catalan_asymAnalyticComb.stirling_factorial_asymAnalyticComb.transfer_matrix_gfAnalyticComb.transfer_matrix_momentsAnalyticComb.triangulationsAnalyticComb.weighted_bin_runs_bgfAnalyticComb.weighted_bin_runs_momentsAnalyticComb.weighted_bin_runs_probAnalyticComb.weighted_bin_runs_pvalAnalyticComb.words_without_k_run
Operators
Basic operators SEQ, MSET, PSET, CYC.
AnalyticComb.CYC — Method
CYC(z,max)
CYC(z,u,max)Cycle operator (Pólya logarithm).
Defined as $A = CYC(B) \implies A(z) = \sum_{1}^{\infty} \frac{\phi(k)}{k} log \frac{1}{1-z^k}$, or with marker $u$ for number of components: $A(z, u) = \sum_{1}^{\infty} \frac{\phi(k)}{k} log \frac{1}{1 - u^k z^k}$. Returns a SymPy :Sym object.
AnalyticComb.MSET — Method
MSET(z,max)
MSET(z,u,max)Multiset operator (Pólya exponential operator).
Defined as $A = MSET(B) \implies A(z) = exp(\sum_{1}^{\infty} \frac{1}{k} B(z^k))$, or with marker $u$ for number of components: $A(z, u) = exp(\sum_{1}^{\infty} \frac{u^k}{k} B(z^k))$. Returns a SymPy :Sym object.
AnalyticComb.PSET — Method
PSET(z,max)
PSET(z,u,max)Powerset operator (modified Pólya exponential operator).
Defined as $A = PSET(B) \implies A(z) = exp(\sum_{1}^{\infty} \frac{(-1)^{k-1}}{k} B(z^k))$, or with marker $u$ for number of components: $A(z, u) = exp(\sum_{1}^{\infty} \frac{(-1)^{k-1} u^k}{k} B(z^k))$. Returns a SymPy :Sym object.
AnalyticComb.SEQ — Method
SEQ(z)
SEQ(z, u)Sequence operator (Pólya quasi-inverse operator).
Defined as $A = SEQ(B) \implies A(z) = \frac{1}{1 - B(z)}$, or with marker $u$ for number of components: $A = SEQ(uB) \implies A(z, u) = \frac{1}{1 - u B(z)}$ (Flajolet & Sedgewick, Fig. III.7, p. 170).
AnalyticComb.bgf_moments — Method
bgf_moments(bgf::Function, n::Integer)
bgf_moments(bgf::SymPy.Sym, n::Integer; z=SymPy.symbols("z"), u=SymPy.symbols("u"))Compute exact analytical moments (mean, var, std, and total weight/count count) at size n from a Bivariate Generating Function (BGF) $A(z, u)$ where $z$ marks size and $u$ marks a combinatorial parameter $\chi$.
Uses Proposition III.2 of Flajolet & Sedgewick (Analytic Combinatorics, p. 158):
- $\mathbb{E}_n(\chi) = \frac{[z^n] \partial_u A(z, u)|_{u=1}}{[z^n] A(z, 1)}$
- $\mathbb{E}_n(\chi(\chi - 1)) = \frac{[z^n] \partial_u^2 A(z, u)|_{u=1}}{[z^n] A(z, 1)}$
- $\mathbb{V}_n(\chi) = \mathbb{E}_n(\chi(\chi - 1)) + \mathbb{E}_n(\chi) - \mathbb{E}_n(\chi)^2$
Returns a NamedTuple: (mean = ..., var = ..., std = ..., count = ...).
AnalyticComb.dominant_pole — Method
dominant_pole(denom_fn::Function; bracket=(0.0, 10.0), n_grid::Int=1000, tol::Real=1e-13) -> Float64Locate the smallest positive real root $z_0 > 0$ of a meromorphic/rational generating function's denominator denom_fn(z) == 0 via adaptive grid scanning followed by bisection (Flajolet & Sedgewick, Theorem IV.9 & Section IV.6).
Returns NaN if no sign change is detected within bracket.
AnalyticComb.markov_dominant_pole — Method
markov_dominant_pole(p00::Real, p01::Real, p10::Real, p11::Real, l::Integer)Compute the dominant real singularity $z_0$ of the 1st-order Markov run-avoidance generating function (cleared denominator $(1 - p_{00} z) - p_{01} p_{10} z \sum_{k=1}^{l-1} p_{11}^{k-1} z^k = 0$), together with the coherent persistence pole $z_{\text{persist}} = 1 / p_{11}$ of $(1 - p_{11} z)^{-1}$.
As coherent persistence $p_{11} \to 1$, the run-avoidance decay rate $1/z_0$ drops and $z_{\text{persist}} - 1 \to 0^+$.
Returns (z0 = ..., gap = z0 - 1.0, growth_rate = 1 / z0, persistence_pole = 1 / p11, persistence_gap = 1 / p11 - 1.0).
AnalyticComb.runs_dominant_pole — Method
runs_dominant_pole(p::Real, q::Real, l::Integer)Compute the dominant real singularity $z_0$ of the run-avoidance generating function (irredundant denominator $1 - q z \sum_{j=0}^{l-1} (p z)^j = 0$), where $p + q = 1$ and $l \ge 1$.
For run-avoidance, $P(\text{no } l\text{-run in } n) \sim c \cdot z_0^{-n}$: as $p$ increases, $z_0 > 1$ grows and the avoidance survival rate $1/z_0$ drops. Conversely, the coherent persistence pole $z_{\text{persist}} = 1/p$ of $(1 - pz)^{-1}$ satisfies $z_{\text{persist}} - 1 \to 0^+$ as $p \to 1$ (Flajolet & Sedgewick, Section V.2–V.3).
Returns (z0 = ..., gap = z0 - 1.0, growth_rate = 1 / z0, persistence_pole = 1 / p, persistence_gap = 1 / p - 1.0).
Partitions and compositions
Partitions and compositions of integers.
AnalyticComb.I_gf — Method
I_gf(z)Integers as combinatorial structures
$I(z)= \sum_{n \geq 1} z^n = \frac{z}{1-z}$. Returns a SymPy :Sym object.
AnalyticComb.fixed_size_comps — Method
fixed_size_comps(n,k)Compositions of size n made of k summands,
${C_n}^{k} = {n-1 \choose k -1}$
AnalyticComb.fixed_size_comps_asym — Method
fixed_size_comps_asym(n,k)Asymptotics for compositions of size n made of k summands,
${C_n}^{k} \sim \frac{n^{k-1}}{(k-1)!}$
AnalyticComb.partitions_asym — Method
partitions_asym(n,tau)Asymptotics for partitions of size n whose summands lie in the arbitrary finite set $\tau$ (tau).
tau must be an array of integers. ${P_n}^{T} \sim \frac{1}{\tau} \frac{n^{r-1}}{(r-1)!}$
AnalyticComb.partitions_asym — Method
partitions_asym(n)Asymptotics for partition of integers (EIS A000041) by Hardy and Ramanujan, later improved by Rademache
AnalyticComb.partitions_gf — Method
partitions_gf(z,max)Generating function for integer partitions.
Defined as $P(z) = \prod_{m = 1}^{\infty} \frac{1}{1-z^m}$ Returns a SymPy :Sym object. Use SymPy.series to obtain counts(EIS A000041): SymPy.series(partitions_gf(z,10),z,0,8) for n up to 8.
AnalyticComb.partitions_max_r — Method
partitions_max_r(n,r)Number of partitions of size n whose summands lie in the set {1, 2, ... , r}
n must be an integer and r is the maximum value in the set of summands.
AnalyticComb.primes_composition_asym — Method
primes_composition_asym(n)Asymptotics for composition of n into prime parts (EIS A023360).
$B_{n} \sim 0.30365 * 1.47622^n$
AnalyticComb.restricted_sum_comp — Method
restricted_sum_comp(n,r)Number of compositions of n with components in the set {1,2,..,r}.
r = 2 yields Fibonnaci numbers (EIS A000045): $F_{n} = F_{n-1} + F_{n-2}$. r>2 yields generalized Fibonacci numbers.
AnalyticComb.restricted_sum_comp_gf — Method
restricted_sum_comp_gf(r)Generating function for compositions with restricted summand. Returns a SymPy :Sym object.
AnalyticComb.restricted_sum_part — Method
restricted_sum_part(n,r)Number of partitions with components in r with restricted summand n.
n must be an integer and r must be a set of integers, like in r = [1,5,10,25] , n = 99.
AnalyticComb.restricted_sum_part_gf — Method
restricted_sum_part_gf(r)Generating function for partition with restricted summand. Returns a SymPy :Sym object.
Miscellaneous
Miscellaneous functins.
AnalyticComb.catalan_factorial — Method
catalan_factorial(n)The n_th Catalan number. (EIS A000108)
Calculated using factorials. $C_{n} = \frac{(2n)!}{(n+1)!n!}$
AnalyticComb.general_trees — Method
general_trees(n)The number of general trees, given by (n-1)_th Catalan number. (EIS A000108)
Calculated using binomial coefficients. $G_n = C_{n-1} = \frac{1}{n} {2n - 2 \choose n - 1}$
AnalyticComb.stirling_catalan_asym — Method
stirling_catalan_asym(n)Stirling approximation for n_th Catalan number. (EIS A000108)
$C_{n} \sim \frac{4^n}{\sqrt{\pi n^3}}$
AnalyticComb.stirling_factorial_asym — Method
stirling_factorial_asym(n)Stirling approximation for n! (EIS A000142)
$n! \sim \sqrt{2 \pi n} {\frac{n}{e}}^{n}$
AnalyticComb.triangulations — Method
triangulations(n)The number of triangulations, given by the n_th Catalan number. (EIS A000108)
Calculated using binomial coefficients. A maximal decomposition of the convex (n + 2)-gon defined by the points into n triangles. $T_n = C_{n-1} = \frac{1}{n+1} {2n \choose n}$
Words and regular languages
Words counts, patterns (via autocorrelation polynomials), and Markov binary runs generating functions.
AnalyticComb.autocorrelation_poly — Method
autocorrelation_poly(pattern::AbstractVector, probs::Union{AbstractDict,AbstractVector}, z)Compute the weighted Guibas–Odlyzko autocorrelation (correlation) polynomial $\gamma_{\mathfrak{p}}(z)$ for an arbitrary pattern $\mathfrak{p} = p_1 \dots p_k$ under letter weights probs (Flajolet & Sedgewick, Section I.4.1, p. 60 & Note III.39, p. 213):
$\gamma_{\mathfrak{p}}(z) = \sum_{j : p_1 \dots p_{k-j} = p_{j+1} \dots p_k} \left(\prod_{t=k-j+1}^k \pi_{p_t}\right) z^j$.
AnalyticComb.bin_words_runs_coeff — Method
bin_words_runs_coeff(r;n_tot=200)Taylor series coefficient from generating function for binary words (when p=q=prob(a)=prob(b)) that never have more than r consecutive identical letters.
The number of binary words that never have more than r consecutive identical letters is found to be (set α = β = r). n_tot defaults to 200, according to the example in Flajolet & Sedgewick pag. 52
AnalyticComb.bin_words_runs_prob — Method
bin_words_runs_prob(k,n)Returns probablity associatied with k-lenght double runs (or either $a$s or $b$s) in a sequence of size n (when p=q=prob(a)=prob(b)).
$W ∼= SEQ(b) SEQ(a SEQ(a) b SEQ(b)) SEQ(a).$ For instance, if n=5 and k=2, the probability of obtaining strings such as bbaab and aabba.
AnalyticComb.bin_words_with_k_occurences — Method
bin_words_with_k_occurences(k,n)The set L of binary words that contain exactly k occurrences of the letter b
$L = SEQ(a){(b SEQ(a))}^k \implies L(z) = \frac{z^k}{{(1-z)}^{k+1}}$ For instance, among binary words with 10 letters, there are 210 words with 4 $b$s. ($[z^{10}]L(z) = 210$)
AnalyticComb.bin_words_with_k_occurences_constr — Method
bin_words_with_k_occurences_constr(k,n,d)The set L of binary words that contain exactly k occurrences of the letter b, constrained by the maximum distance d among occurrences
$L^{[d]} = SEQ(a){(b SEQ_{<d}(a))}^{k-1}(b SEQ(a))$.
For instance, among binary words with 10 letters, there are 45 words with 4 $b$s in which the maximum distance between $b$s is 2 (e.g.aaabababab) ($[z^{10}]L^{[2]}(z) = 45$).
AnalyticComb.estimate_markov_params — Method
estimate_markov_params(seq::AbstractVector{<:Integer}; laplace::Real=0.0)
estimate_markov_params(seqs::AbstractVector{<:AbstractVector{<:Integer}}; laplace::Real=0.0)Estimate 1st-order Markov transition probabilities (p00, p01, p10, p11, p_stat, q_stat) from a binary sequence (or collection of sequences) with elements in {0, 1}. Optional laplace adds pseudocount smoothing to each transition cell.
AnalyticComb.longest_run_binary_asym — Method
longest_run_binary_asym(n)Asymptotics for the average of the longest run of $a$s in a random binary string of length n.
$\log_2 n$ . For instance, a random binary word with 10 letters (e.g. baaabababb) will present, on average, $3.32...$ consecutive $a$s
AnalyticComb.markov_bin_runs_bgf — Method
markov_bin_runs_bgf(p00, p01, p10, p11, l, z, u; mode="count_ge", init_probs=nothing)Exact 1st-order Markov Bivariate Generating Function $W_{\text{Markov}}(z, u)$ for consecutive runs in binary sequences, where $z$ marks sequence length $n$ and $u$ marks the run statistic (Flajolet & Sedgewick, Sections I.4.2 & III.6.1):
mode="count_ge"(default): number of maximal 1-runs of length $\ge l$mode="length_ge": total number of elements belonging to 1-runs of length $\ge l$mode="count_eq": number of maximal 1-runs of exact length $l$mode="double_count_ge": number of maximal runs of either 0 or 1 of length $\ge l$
init_probs may be (q0, p1) giving initial probabilities $(P(X_1=0), P(X_1=1))$; defaults to the stationary distribution $q_{\text{stat}} = 1 - p_{\text{stat}}$, $p_{\text{stat}} = p_{01} / (p_{01} + p_{10})$.
AnalyticComb.markov_bin_runs_moments — Method
markov_bin_runs_moments(p00, p01, p10, p11, l, n; mode="count_ge", init_probs=nothing)Exact analytical moments (mean, var, std, count) for run statistics of threshold l in a 1st-order Markov binary sequence of length n.
AnalyticComb.markov_bin_runs_prob — Method
markov_bin_runs_prob(p00, p01, p10, p11, l, n; init_probs=nothing) -> Float64Exact probability of observing zero 1-runs of length $\ge l$ in a 1st-order Markov binary sequence of length n (i.e., $P(L_n < l)$ where $L_n$ is the longest 1-run).
AnalyticComb.markov_bin_runs_pval — Method
markov_bin_runs_pval(p00, p01, p10, p11, l, n; init_probs=nothing) -> Float64Exact one-sided upper-tail $p$-value $P(L_n \ge l) = 1 - P(L_n < l)$ for observing at least one consecutive 1-run of length $\ge l$ in a 1st-order Markov binary sequence of length n.
AnalyticComb.pattern_occurrences_bgf — Method
pattern_occurrences_bgf(pattern::AbstractVector, probs::Union{AbstractDict,AbstractVector}, z, u; overlapping::Bool=true)Bivariate Generating Function $W_{\mathfrak{p}}(z, u)$ for an arbitrary pattern $\mathfrak{p}$ of length $k$ in Bernoulli sequences of symbols with probabilities probs, where $z$ marks sequence length and $u$ marks the number of occurrences of $\mathfrak{p}$ (Flajolet & Sedgewick, Note III.39, p. 213):
overlapping=true(default): counts possibly overlapping occurrences: $W(z, u) = \frac{(u - 1) \gamma(z) - u}{(1 - z)((u - 1)\gamma(z) - u) + (u - 1)\pi[\mathfrak{p}] z^k}$overlapping=false: counts greedy non-overlapping (renewal) occurrences: $W^{\text{non-ov}}(z, u) = \frac{\gamma(z)}{(1 - z)\gamma(z) + (1 - u)\pi[\mathfrak{p}] z^k}$
AnalyticComb.pattern_occurrences_moments — Method
pattern_occurrences_moments(pattern::AbstractVector, probs::Union{AbstractDict,AbstractVector}, n::Integer; overlapping::Bool=true)Exact analytical moments (mean, var, std, count) for the number of occurrences of arbitrary pattern in a random Bernoulli word of length n with letter probabilities probs.
AnalyticComb.pattern_pval — Method
pattern_pval(pattern::AbstractVector, probs::Union{AbstractDict,AbstractVector}, k_obs::Integer, n::Integer; overlapping::Bool=true) -> Float64Exact combinatorial upper-tail $p$-value $P(X_n \ge k_{\text{obs}})$ for observing at least k_obs occurrences of pattern in a random Bernoulli sequence of length n, computed directly by extracting $[z^n u^s] W_{\mathfrak{p}}(z, u)$ for $s = 0, \dots, k_{\text{obs}}-1$.
AnalyticComb.pattern_waiting_prob — Method
pattern_waiting_prob(pattern::AbstractVector, probs::Union{AbstractDict,AbstractVector}, n::Integer) -> Float64Exact probability that pattern does not occur anywhere in a random Bernoulli sequence of length n ($[z^n] W_{\mathfrak{p}}(z, 0)$).
AnalyticComb.weighted_bin_runs_bgf — Method
weighted_bin_runs_bgf(p, q, l, z, u; mode="count_ge")Weighted Bivariate Generating Function (BGF) $W(z, u)$ for consecutive runs in binary words of Bernoulli trials with probabilities $p$ and $q$, where $z$ marks sequence length $n$ and $u$ marks a run parameter (Flajolet & Sedgewick, Sections I.4 & III.3):
mode="count_ge"(default): $u$ marks the number of maximal runs of length $\ge l$: $W(z, u) = \frac{1 + (u - 1) p^l z^l}{1 - (p + q)z - (u - 1) q p^l z^{l+1}}$mode="length_ge": $u$ marks the total number of elements belonging to maximal runs of length $\ge l$ (the numerator of RQA Determinism / Laminarity): $W(z, u) = \frac{1 + \beta(z, u)}{1 - qz(1 + \beta(z, u))}$, where $\beta(z, u) = \frac{pz - p^l z^l}{1 - pz} + \frac{(upz)^l}{1 - upz}$mode="count_eq": $u$ marks the number of maximal runs of exact length $l$: $W(z, u) = \frac{1 + (u - 1) p^l z^l (1 - pz)}{1 - (p + q)z - (u - 1) q p^l z^{l+1} (1 - pz)}$mode="double_count_ge": $u$ marks the number of maximal runs of either outcome ($p$ or $q$) of length $\ge l$.
AnalyticComb.weighted_bin_runs_moments — Method
weighted_bin_runs_moments(p, q, l, n; mode="count_ge")Exact analytical moments (mean, var, std, count) for run statistics in a weighted binary sequence of length n with probabilities p and q and run threshold l, obtained by differentiating weighted_bin_runs_bgf at $u = 1$.
See weighted_bin_runs_bgf for available mode options ("count_ge", "length_ge", "count_eq", "double_count_ge").
AnalyticComb.weighted_bin_runs_prob — Method
weighted_bin_runs_prob(p,q,l,n)Weighted model for consecutive runs in binary words.
Probablity of the absence of l-runs among a sequence of n random trials with probabilities p and q. $[z^{n}] \frac{1 - p^l z^l}{1 - z + q p^l z^{l+1}}$. Use diff over output values to obtain a probability distribution. For n=15, p=0.4 and q=0.6: raw_probs = map(x->weighted_bin_runs_prob(0.4,0.6,x,15),0:1:15);plot(diff(raw_probs))
AnalyticComb.weighted_bin_runs_pval — Method
weighted_bin_runs_pval(p,q,l,n)p-value obtained from a one-tailed based on the exact distribution using the weighted model for consecutive runs weighted_bin_runs_coeff.
AnalyticComb.words_without_k_run — Method
words_without_k_run(k,n;m=2)OGF of words without k consecutive occurrences of a designated letter for an alphabet of cardinality m (defaults to binary words: m=2).
$\frac{1 - z^k}{ 1 - mz + (m-1)z^{k+1} }$ For instance, if n=4 and k=3, these words are not counted: aaab, baaa, aaaa.
Transfer matrices, graphs & dynamical systems
Transfer-matrix BGF moments, directed/undirected graph walk generating functions, dynamical zeta polynomials, and random mapping attractor statistics.
AnalyticComb.graph_closed_walks_gf — Method
graph_closed_walks_gf(A::AbstractMatrix{<:Real}, max_n::Integer)Analyze closed walks, dynamical zeta polynomial, and topological entropy on a directed or undirected graph with adjacency/transition matrix A (Flajolet & Sedgewick, Section V.5.1):
Returns a NamedTuple:
closed_walks: vector[Tr(A^1), Tr(A^2), ..., Tr(A^max_n)](coefficients of $z^k$ in $\text{Tr}(zA(I - zA)^{-1})$)zeta_inv_coeffs: coefficients[1, c_1, ..., c_m]of the reciprocal dynamical zeta polynomial $\zeta_A(z)^{-1} = \det(I - z A) = 1 + c_1 z + \dots + c_m z^m$ via Newton's identitiesspectral_radius: dominant eigenvalue modulus $\rho(A)$topological_entropy: $h_{\text{top}} = \log \rho(A)$
AnalyticComb.graph_walks_count — Method
graph_walks_count(A::AbstractMatrix{<:Real}, n::Integer; source=nothing, target=nothing)Count walks of exact length n on a graph with adjacency or weight matrix A (Flajolet & Sedgewick, Section V.5). Optionally restrict to walks starting at source and/or ending at target.
AnalyticComb.random_mapping_moments — Method
random_mapping_moments(n::Integer)Exact finite-$n$ and asymptotic statistics for a uniformly random discrete dynamical mapping $f: \{1, \dots, n\} \to \{1, \dots, n\}$ (Flajolet & Sedgewick, Section II.5.2 & Section VII.3.3):
Returns a NamedTuple:
expected_cyclic_nodes: exact $\mathbb{E}_n[\text{periodic states}] = Q(n) = \sum_{k=1}^n \frac{n!}{(n-k)! n^k} \sim \sqrt{\pi n / 2}$expected_components: exact $\mathbb{E}_n[\text{attractors}] = \sum_{k=1}^n \frac{1}{k} \frac{n!}{(n-k)! n^k} \sim \frac{1}{2}(\log(2n) + \gamma)$prob_connected: exact probability of a single connected attractor $Q(n) / n \sim \sqrt{\pi / (2n)}$expected_leaves: exact expected number of transient terminal states (in-degree 0) $n (1 - 1/n)^n \sim n / e$expected_fixed_points: exact $1.0$cyclic_nodes_asym: $\sqrt{\pi n / 2}$components_asym: $0.5 (\log(2n) + \gamma)$tail_len_asym: $\sqrt{\pi n / 8}$ (mean transient distance $\lambda$ to limit cycle)cycle_len_asym: $\sqrt{\pi n / 8}$ (mean limit cycle length $\mu$ from random state)rho_len_asym: $\sqrt{\pi n / 2}$ (mean total orbit length $\rho = \lambda + \mu$)largest_component_asym: $0.7582 n$largest_tree_asym: $0.48 n$
AnalyticComb.transfer_matrix_gf — Method
transfer_matrix_gf(T::AbstractMatrix{<:Real}, z;
mark_matrix=nothing, init_dist=nothing, final_vec=nothing, u=1)Evaluate the Transfer-Matrix Generating Function $G(z, u) = \mathbf{p}_0^T \bigl(\mathbf{I} - z \mathbf{T}(u)\bigr)^{-1} \mathbf{f}$ for symbolic SymPy.Sym arguments, TaylorSeries.Taylor1 series expansion, or numeric scalars.
AnalyticComb.transfer_matrix_moments — Method
transfer_matrix_moments(T::AbstractMatrix{<:Real}, mark_matrix::AbstractMatrix{<:Real}, n::Integer;
init_dist=nothing, final_vec=nothing)Compute exact analytical moments (mean, var, std, count) for the cumulative marked transition statistic $\chi = \sum_{t=1}^n M_{s_{t-1}, s_t}$ over paths of n transitions on an $m \times m$ transfer/transition matrix T (Flajolet & Sedgewick, Theorem V.7 & Section V.6):
$G(z, u) = \mathbf{p}_0^T \bigl(\mathbf{I} - z \mathbf{T}(u)\bigr)^{-1} \mathbf{f}, \qquad T_{ij}(u) = T_{ij} \, u^{M_{ij}}.$
Uses exact degree-2 Taylor1 propagation in $u = 1 + du$ in $O(\min(n m^2, m^3 \log n))$ time. If init_dist is nothing, defaults to the stationary distribution when T is row-stochastic, and ones(m) otherwise. final_vec defaults to ones(m).