% % \subsection{Polynomial indexing of cycles over an implicit weighted alphabet} \label{sec:weighted-cycle-oracle} This is an explicit oracle-closure theorem and proof. No historical priority is claimed for its standard ingredients. The ingredients are the standard prefix-avoidance automaton, transfer-matrix counting, Burnside's lemma, and binary-search unranking. Relevant predecessors include Kociumaka--Radoszewski--Rytter~\cite{KRR2016}, Kopparty--Kumar--Saks~\cite{KKS2016}, Adamson~\cite{Adamson2021}, Sawada--Williams~\cite{SW2017}, and Hartman--Sawada~\cite{HS2019}. Related later decoding results for bounded-weight universal cycles concern a more specific task. \cite{GIJS2026} The modest point isolated here is that the alphabet need not be enumerated: its positive-weight classes can be exponentially large. \paragraph{A small example before the general construction.} Take letters $aH_s$ moves to state $0$; when $a=H_s$ there is one fixed destination $e_s$. A complete match with $w$ is allowed, and falls back to the longest proper border. This is important: the inequality being enforced is $\ge w$, not $>w$. \begin{lemma}[Finite-memory and unique closed-path property] For any nonempty word $u$ of length $d$, the nonrejecting automaton has exactly one closed path labelled $u$ if the infinite periodic word $u^\infty$ avoids $\mathcal F_w$, and no such path otherwise. \end{lemma} \begin{proof} Ignoring rejection, the state update is the ordinary longest-prefix/suffix update. Its possible active shorter prefixes are exactly the borders of the longest active prefix. Thus rejection detects every newly completed member of $\mathcal F_w$. After reading at least $k-1$ letters, the ending state, whenever the path has not rejected, is determined by the final $k-1$ letters alone: no proper prefix of $w$ is longer. This is true even when the initial state was not reachable from the empty state. For $k=1$ the automaton has only state $0$. If a closed path labelled $u$ exists, repeat it sufficiently often. Every factor of length at most $k$ in $u^\infty$ then occurs entirely in the read labels, so no forbidden factor can occur. Conversely, for an avoiding periodic word, at each position assign the state given by the longest proper prefix of $w$ matching the preceding infinite history. These states obey the nonrejecting transition rule and repeat after $d$ positions, giving a closed path. Finally, if there were two closed starting states for the same label word $u$, repeat $u$ until at least $k-1$ letters have been read. Finite memory forces their ending states to coincide. Closedness says the ending states are the respective starting states, proving uniqueness. \end{proof} \paragraph{Weighted aggregation.} Let $M_w(z)$ be the $k\times k$ transition matrix, with an edge labelled by letter $a$ weighted $z^{\wt(a)}$. At state $s$, the letters greater than $H_s$ all go to $0$, and the single letter $H_s$ goes to $e_s$. Hence \[ (M_w(z))_{s,0}\mathrel{+}=\sum_{m=1}^n g_m(H_s)z^m, \qquad (M_w(z))_{s,e_s}\mathrel{+}=z^{\wt(H_s)}, \] where $g_m(b)=|\{a\in\mathcal A_m:a>b\}|$. If $b$ has weight $h$ and within-class rank $r$, these coefficients are \[ g_m(b)=\begin{cases}0&mh.\end{cases} \] The two contributions are added when their destinations coincide. There are at most two distinct destination states in each row. No sum over the individual letters of a weight class is performed. For the example above with $w=ac$, the states are $0,1$ and the matrix is \[ M_{ac}(z)=\begin{pmatrix}2z^2&z\\z^2&0\end{pmatrix}. \] At state $0$, the letters $b,c$ reset and $a$ matches the first prefix letter. At state $1$, only $c$ can complete a nonrejecting transition. Thus $[z^3]\tr(M_{ac}^2)=2$: the labelled words are $ac$ and $ca$. After quotienting by their two rotations there is one cycle at least $ac$, and hence one of the two weight-three, length-two cycles lies strictly below it. The calculation illustrates both weight aggregation and the distinction between labelled words and rotation classes. The preceding lemma gives the exact identity \[ [z^t]\tr(M_w(z)^d) =|\{u\in\Sigma_n^d:\wt(u)=t,\ u^\infty\text{ avoids }\mathcal F_w\}|. \tag{WC1} \] Uniqueness is necessary here: traces of arbitrary deterministic automata can count the same cyclic label word multiple times. \paragraph{Burnside, including all periodicities.} Let $C_{n,k}^{\ge w}$ count length-$k$, weight-$n$ cycles whose least rotation is at least $w$. This condition is invariant under rotation. A word fixed by a rotation with $r$ equal repetitions has the unique form $u^r$, with $|u|=k/r$ and $\wt(u)=n/r$. There are $\varphi(r)$ such rotations of $k$ positions. Equation (WC1) and Burnside's lemma therefore give \[ C_{n,k}^{\ge w}= \frac1k\sum_{r\mid\gcd(n,k)}\varphi(r) [z^{n/r}]\tr(M_w(z)^{k/r}). \tag{WC2} \] No primitivity assumption is made. The automaton keeps the full threshold $w$ even for the smaller exponents $k/r$; this avoids replacing a periodic comparison by an unjustified comparison with a truncated threshold. Writing $A_n(z)=\sum_{m=1}^n a_mz^m$, the total number is the standard weighted cycle-index formula \[ C_{n,k}=\frac1k\sum_{r\mid\gcd(n,k)}\varphi(r) [z^{n/r}]A_n(z)^{k/r}. \tag{WC3} \] Consequently the desired strictly-below rank is $R_{n,k}(w)=C_{n,k}-C_{n,k}^{\ge w}$. For completeness, primitive cycles can also be handled without changing the threshold automaton. Let $P_{n,k}^{\ge w}$ denote the number of primitive labelled words of length $k$, weight $n$, and least rotation at least $w$. Unique primitive-root decomposition and ordinary divisor inversion give \[ P_{n,k}^{\ge w}=\sum_{r\mid\gcd(n,k)}\mu(r) [z^{n/r}]\tr(M_w(z)^{k/r}). \tag{WC4} \] Dividing (WC4) by $k$ counts the corresponding primitive cycles. Each smaller power is still tested against the original full threshold $w$. Merely comparing a shorter word with a truncated threshold is unsafe without additional boundary conditions. For example, $u=01$ and $w=0102$ satisfy $u=w_{(2)}$ but $u^2w$. \paragraph{Dynamic program and bit bound.} For each initial state $s$, count paths of lengths $0,\ldots,k$, recording their ending state and weight $0,\ldots,n$. At a given length, this uses $O(kn)$ cells. Each row has at most $n+1$ weighted transition coefficients, so one length update takes $O(kn^2)$ arithmetic operations. Repeating for $k$ lengths and $k$ initial states costs $O(k^3n^2)$ operations. Accumulate the diagonal counts in a length/weight table, also of $O(kn)$ cells. Only the previous and current length tables for one initial state are needed. Naive border and equal-target preprocessing costs $O(k^3)$ symbol operations. Coefficients and ordinals are available from the $n$ class counts and the threshold's $k$ within-class ranks. There are at most $q^k$ words, and summing diagonal counts or Burnside summands adds only a factor polynomial in $k$. All integers have $O(k\log(2+q)+\log k)=O(kB(n)+\log k)$ bits. Thus even elementary integer arithmetic makes the above bit cost polynomial. Divisions by $k$ in (WC2) and (WC3) are exact. Here polynomial means polynomial in the total weight $n$, not in $\log n$ when numeric weights are binary encoded. % % \paragraph{A scalar recurrence for all required traces.} In the notation above, set $\ell=k$, retain the thresholds $H_s$, and let $f(s)$ be the destination of the equality transition. The sparse transition matrix has the more specific form \[ M(z)=E(z)+u(z)e_0^{\mathsf T},\qquad E_{s,f(s)}(z)=z^{\operatorname{wt}(H_s)},\qquad u_s(z)=F_s(z):=\sum_{a>H_s}z^{\operatorname{wt}(a)}. \] Here $f(s)=e_s$ is the equality destination; each row of $E$ has exactly one monomial entry. The reset and equality contributions are added if $f(s)=0$, but their letter sets remain disjoint. Introduce $x$ to mark the number of letters, keeping $z$ for their total weight. Define $s_j=f^j(0)$ and $W_j=\sum_{i=0}^{j-1}\operatorname{wt}(H_{s_i})$, with $W_0=0$. For $1\le j\le\ell$ put \[ R_j(z)=z^{W_{j-1}}F_{s_{j-1}}(z),\qquad R(x,z)=\sum_{j=1}^{\ell}x^jR_j(z) \pmod{x^{\ell+1},z^{n+1}}. \] Thus $R_j$ counts a path starting at state zero, taking $j-1$ equality steps and then one strict reset to zero. For $P_0(z)=1$, calculate successively \begin{equation} P_d(z)=\sum_{j=1}^dR_j(z)P_{d-j}(z),\qquad 1\le d\le\ell. \label{eq:cycle-renewal-P} \end{equation} All polynomials are truncated after degree $n$. If $T_{E,d}(z)=\tr E(z)^d$, the required traces are \begin{equation} \tr M(z)^d=T_{E,d}(z)+\sum_{j=1}^d jR_j(z)P_{d-j}(z). \label{eq:cycle-renewal-trace} \end{equation} These identities retain the original length-$\ell$ threshold in every divisor term; the shorter power $d$ does not replace that threshold. To prove them, work first in formal series in $x$, so that $I-xE$ is invertible. The rank-one determinant identity gives \[ \det(I-xM)=\det(I-xE) \bigl(1-xe_0^{\mathsf T}(I-xE)^{-1}u\bigr) =\det(I-xE)(1-R). \] The last equality is modulo $x^{\ell+1}$: the unique equality path from zero computes the displayed coefficients of $R$. The classical trace--determinant identity \cite[Proposition~V.6(ii), pp.~337--338]{FS2009} now yields \[ \sum_{d\ge1}\tr M^d x^d =\sum_{d\ge1}\tr E^d x^d+ \frac{x\,\partial R/\partial x}{1-R}. \] Since $P=(1-R)^{-1}$, coefficient extraction proves \eqref{eq:cycle-renewal-P}--\eqref{eq:cycle-renewal-trace}. The argument uses rational formal identities only to prove the formulas; their evaluation uses nonnegative integer additions and multiplications. The functional graph of $f$ supplies $T_{E,d}$ directly. Every directed cycle $C$ of length $h_C$ and total equality-edge weight $v_C$ contributes \[ h_C z^{dv_C/h_C}\quad\hbox{if }h_C\mid d, \] and contributes zero otherwise. All cycles are included, not only the cycle reached from zero. For example, for threshold $ba$ over $aH_s$ is reset. This remains true when both transitions have destination zero. Consequently $P_d$ counts a subset of length-$d$ words, rather than multiple decompositions of one word. Its coefficients have $O(\ell B)$ bits for $B=\lceil\log_2(2+q)\rceil$. If, additionally, $a_j\le C^j$ for a fixed $C$, the number of all words of total weight $w$ is at most $2^{w-1}C^w$ for $w\ge1$; thus every coefficient truncated at weight $n$, including these intermediates, has $O(n)$ bits. Polynomial factors from traces or summands add only $O(\log(n+2))$ bits. There are $O(\ell^2)$ polynomial products, each with a shifted tail polynomial $R_j$ whose coefficients have at most $B$ bits. With $\beta$-bit intermediate coefficients, their elementary bit cost is $O(\ell^2n^2\beta B)$. Multiply a completed convolution by $j$ when forming~\eqref{eq:cycle-renewal-trace}; the extra $O(\ell^2n\beta\log(\ell+1))$ cost is absorbed by the same bound. Storing the $P_d$ and required traces costs $O(\ell(n+1)\beta)$ bits, in addition to the threshold and tail data. Hence one threshold query costs $O(n^5B^2)$ bits in the generic interface, and $O(n^6)$ bits when $a_j\le C^j$ with fixed $C$. This improves the earlier direct trace evaluation in this note; the determinant, renewal and transfer- matrix principles themselves are classical. \begin{lemma}[Weight-aware flat-word unranking] \label{lem:weight-aware-unrank} Suppose a family of words of fixed length $\ell$ and total positive weight $n$ is listed lexicographically over a size-first alphabet with grade counts $a_w$. Its arbitrary-threshold strictly-below oracle suffices to unrank an output with letter weights $w_1,\ldots,w_\ell$ using \[ O\!\left(\ell+\sum_i\log(w_i+1)+\sum_i\log(a_{w_i}+1)\right) \] threshold calls. In particular the number is $O(n)$ if $a_w\le C^w$ for a fixed $C>1$. This applies to canonical necklaces and bracelets, without requiring all words to belong to the family. \end{lemma} \begin{proof} Write $R_{n,\ell}(v)$ for the number of family members strictly below an arbitrary word $v$ of length $\ell$. Retain the target's global zero-based rank $r$. Suppose its already chosen prefix is $p$. Its valid completions form one lexicographic rank interval; retain the exclusive upper endpoint $u_p$ of that interval. Initially this is the full length-block count. For ordinals $0\le xr. \] Indeed $F_p(A_t)$ is the rank boundary after all next-letter grades at most $t$. Empty grades merely produce equal consecutive boundaries and cannot be selected. Query this predicate at $t=1,2,4,\ldots$, capped at $M=n-\operatorname{wt}(p)-(\ell-|p|-1)$, and then binary search between its last false and first true positions. The final capped position is true because the remaining letters have positive weight. This locates the actual weight $w$ using $O(\log(w+1))$ queries. Next binary search only within the ordinal interval $[A_{w-1},A_w)$, using $F_p(x)\le r$, to select the letter $a$. This takes $O(\log(a_w+1))$ further queries. Set $u_{pa}=F_p(a+1)$, using the known endpoint when $a+1=q$. This costs at most one additional query and maintains the invariant. No arbitrary-word sentinel is submitted to the threshold oracle. Summing these costs gives the displayed output-sensitive query bound. When $a_w\le C^w$, positivity and $\sum_iw_i=n$ make this $O(n)$. The grade endpoints are prepared once from the existing count table; this adds $O(nB)$ bit operations and bits when their ordinals have at most $B$ bits. Only ordinal symbols are used in internal queries; actual output letters are decoded afterwards. \end{proof} The same query bound holds for words of variable length at fixed total positive weight, provided the interface supplies cumulative next-letter prefix boundaries at the stated query cost. No two such words are proper prefixes of one another. Use the remaining weight itself as the grade-search cap $M$ and stop when it is zero. The prefix interval, empty-grade and within-grade arguments are unchanged. In particular this version applies to sorted component words when their multiset-tail oracle supplies those boundaries; it does not require reordering them by their number of components. The lemma concerns one flat word whose letter weights sum to $n$. It must not be applied across all recursive child-word choices in a tree: their weights can sum to $\Theta(n^2)$ along a path. Nor does it remove the separate output-letter decoding charge. The generic unranking bounds in unrestricted $B$ remain valid; the lemma sharpens their exponential-grade specializations. \paragraph{Ranking and unranking.} For ranking a cycle, encode its letters by $(m,r_m)$, take the least rotation, and evaluate $R_{n,k}$ at it. Taking a least rotation may be done by any polynomial algorithm; linear-time rotation selection is not needed for this theorem. For unranking, use zero-based rank $r