\documentclass[11pt,letterpaper]{amsart} \usepackage[margin=1in]{geometry} \usepackage[T1]{fontenc} \usepackage{lmodern,microtype,amsmath,amssymb,amsthm,mathtools} \usepackage{enumitem,booktabs} \usepackage[hidelinks]{hyperref} \numberwithin{equation}{section} \newtheorem{theorem}{Theorem}[section] \newtheorem{lemma}[theorem]{Lemma} \newtheorem{proposition}[theorem]{Proposition} \newtheorem{corollary}[theorem]{Corollary} \theoremstyle{definition} \newtheorem{definition}[theorem]{Definition} \newtheorem{example}[theorem]{Example} \theoremstyle{remark} \newtheorem{remark}[theorem]{Remark} \newcommand{\N}{\mathbb N} \newcommand{\Z}{\mathbb Z} \newcommand{\Q}{\mathbb Q} \newcommand{\R}{\mathbb R} \newcommand{\C}{\mathbb C} \newcommand{\eps}{\varepsilon} \DeclareMathOperator{\lcm}{lcm} \DeclareMathOperator{\supp}{supp} \DeclareMathOperator{\dist}{dist} \DeclareMathOperator{\diag}{diag} \DeclareMathOperator{\dom}{dom} \newcommand{\sem}[1]{\left[\!\left[#1\right]\!\right]} \newcommand{\Fail}{\mathop{\rm Fail}} \newcommand{\Prim}{\mathop{\rm Prim}} \newcommand{\size}[1]{\lvert #1\rvert} \title[Circuits for primitive words]{Decomposable disjoint-union circuits for primitive words} \author{Will Howe} \email{howew@purdue.edu} \author{Grant Huffman} \email{huffma97@purdue.edu} \author{Jensen Kohlmeyer} \email{jenwin@purdue.edu} \author{Liam Kruer} \email{kruerl@purdue.edu} \thanks{Prepared with AI assistance from OpenAI Codex in mathematical exploration, checking, and manuscript preparation.} \date{November 7, 2026} \keywords{Primitive words, decomposable circuits, disjoint unions, knowledge compilation} \begin{document} \begin{abstract} For every fixed finite alphabet $A$ with at least two letters, we construct smooth decomposable circuits representing the primitive words of each length $n$. The gates are literals, Cartesian products on disjoint position sets, and disjoint unions on equal position sets. The total number of gates and wires is $O_A(n^2 5^{\omega(n)})=n^{2+o(1)}$, and the construction takes $n^{2+o(1)}$ bit operations. Prime periods are expressed as coordinate directions of independent rectangular grids. A recursion at the first nonconstant vertex computes the exact set of failed directions; sharing its continuations gives the size bound. This resolves the primitive-word instance of the circuit question posed by Amarilli, Monet, Rapha\"el, and Salvati. It does not determine whether primitive words form a context-free or a poly-slicewise-unambiguous language. The same circuit bound holds for any union of exact power orders at a fixed length. \end{abstract} \maketitle \section{Statement and circuit model} A nonempty word is \emph{primitive} if it is not a power $u^d$ with $d\geq2$. The empty word is excluded. Write $\Prim_A(n)\subseteq A^n$ for the primitive words of length $n$, and let $\omega(n)$ be the number of distinct prime divisors of the positive integer $n$, with $\omega(1)=0$. Amarilli, Monet, Rapha\"el, and Salvati introduced a multivalued circuit framework for probabilistic language membership \cite[Section~5]{AMRS26}. Their construction for primitive words uses complementation, and \cite[Section~6]{AMRS26} asks whether complementation can be avoided for this language. We use their circuit model, with the conventions made explicit below. Their quadratic arithmetic algorithm for probabilistic membership is already available; the result here concerns the form and size of a representation. Fix a finite set $U$ of positions. An assignment on $D\subseteq U$ is a function $D\to A$. A circuit is a finite directed acyclic graph, with a designated output, built from the following gates. \begin{enumerate}[label=(\roman*),leftmargin=*] \item A literal $i:a$ has domain $\{i\}$ and represents the one assignment sending $i$ to $a$. \item A product gate has inputs with pairwise disjoint domains. Its domain is their union, and its assignments are all unions of one assignment from each input. \item A union gate has inputs with the same domain and pairwise disjoint represented sets. It represents their union, with that common domain. \end{enumerate} These requirements are called \emph{decomposability}, \emph{smoothness}, and \emph{disjointness}, respectively. We allow the nullary product, of domain $\varnothing$, representing the unique empty assignment, and the nullary union, of domain $\varnothing$, representing no assignment. The domain of every other gate is the union of its input domains. Thus the nullary union alone cannot represent the empty set on a prescribed nonempty domain. We denote the set represented by a gate $c$ by $\sem c$. The size of a circuit is its number of gates plus its number of wires. Fan-out is unrestricted, so a constructed gate may be shared by several later gates. Positions may be relabeled by any bijection without changing these properties or the size. \begin{theorem}\label{thm:main} Fix a finite alphabet $A$, with $|A|\geq2$. For each integer $n\geq1$ there is a smooth decomposable disjoint-union circuit with domain $\{0,\ldots,n-1\}$ representing exactly $\Prim_A(n)$ and having size \[ O_A\!\left(n^2 5^{\omega(n)}\right). \] One algorithm constructs these circuits in $n^{2+o(1)}$ bit operations as a function of $n$. The empty slice is represented by a nullary union. \end{theorem} Here and below $A$ is fixed, so constants may depend on $|A|$. Construction time is measured in the represented length $n$, or equivalently with $n$ given in unary. A stronger intermediate bound will be \begin{equation}\label{eq:strongbound} O_A\!\left(n\prod_{p\mid n,\ p\text{ prime}}(1+4p)\right). \end{equation} Products in this model may combine interlaced position sets. The theorem does not provide a context-free grammar or a family of polynomial-size unambiguous context-free grammars for the slices. These language-theoretic questions are separate from the circuit question; see also the discussion of primitive words in \cite[Section~6]{AMRSfull}. \section{From periods to independent grids} We identify positions of a length-$n$ word with $\Z/n\Z$. For a divisor $d\mid n$, a word is invariant under shift $d$ if $w(j+d)=w(j)$ for all positions $j$. \begin{lemma}\label{lem:primeperiod} Let $n\geq2$, and let $P$ be its set of distinct prime divisors. A word $w\in A^n$ is primitive if and only if it fails to be invariant under shift $n/p$ for every $p\in P$. \end{lemma} \begin{proof} If $w=u^d$ with $d\geq2$, then $d\mid n$. Choose a prime $p\mid d$ and write $w=(u^{d/p})^p$. It is invariant under shift $n/p$. Conversely, the orbits of shift $n/p$ are the sets $\{i,i+n/p,\ldots,i+(p-1)n/p\}$ for $0\leq is}=\{x_{s+1},\ldots,x_{v-1}\}$. Apply Lemma~\ref{lem:combine} to these states. Denote the gate of accumulated mask $N\subseteq U$, if nonempty, by $K_{G,s,b,a,N}$. It has domain $G_{>s}$. To obtain a branch for the original suffix, multiply it by the assignment $b$ on $\{x_t,\ldots,x_{s-1}\}$ and by the literal $x_s:a$. The three domains are disjoint, and their union is $G_{\geq t}$. By \eqref{eq:maskidentity}, this branch contributes precisely to \begin{equation}\label{eq:branchmask} \mathcal S(G,t,b,F\cup N). \end{equation} For each required mask take the union of these branches and the constant branch, if appropriate. Their domains agree. Two nonconstant branches are disjoint because their completed labelings have different first differing positions or different letters at that position. For fixed $s,a$, masks $N$ are exact and pairwise disjoint; moreover $F\cup N=M$ determines $N=M\setminus F$. The constant branch is disjoint from every nonconstant branch. Lemma~\ref{lem:first} shows that every completion occurs in the prescribed branch, so these gates represent exactly the claimed sets. Finally, form $\mathcal B(G,M)$ by the disjoint union, over $b\in A$, of the literal $x_0:b$ times the state $\mathcal S(G,1,b,M)$, omitting absent states. The two factors have disjoint domains. The resulting branches all have domain $G$, and their first letters make them pairwise disjoint. When $T=\varnothing$, $G$ is a singleton. The only possible mask is $\varnothing$; its states at $t=1$ are nullary products, and $\mathcal B(G,\varnothing)$ is the disjoint union of the literals at its one position. No nonconstant branch occurs. This supplies the base case, including all empty-domain states used above. \end{proof} \section{Sharing and the size bound} The induction alone gives a circuit construction. The following count depends on sharing a continuation across all compatible prefix lengths. \begin{lemma}\label{lem:localcost} Let $G$ have $v$ vertices and $m$ varying axes. Besides gates already constructed on its proper subgrids, all its states in Proposition~\ref{prop:recursion} require $O_A(v^2 4^m)$ gates and wires. \end{lemma} \begin{proof} We first build the constant assignment of letter $b$ on every interval $\{x_i,\ldots,x_{j-1}\}$, $0\leq i\leq j\leq v$. For fixed $i,b$, start with the nullary product and append one literal at a time. Each extension uses a binary decomposable product. This costs $O_A(v^2)$ gates and wires in total. Literals can be shared wherever they recur. For fixed $s\geq1$, $b$, and $a\ne b$, the partition into $H$, all numbers $r_H$, and the distinguished state with letter $a$ depend only on $G,s,b,a$. They do not depend on $t\leq s$. The core gates $K_{G,s,b,a,N}$ are therefore built once and shared for every such $t$. There are at most $v$ subgrids in this partition, and at most $m$ remaining axes. Lemma~\ref{lem:combine} bounds the cost of one core by $O(v4^m)$. There are $O_A(v)$ choices of $s,b,a$, so all cores cost $O_A(v^2 4^m)$. For each $t,s,b,a,N$ the branch in \eqref{eq:branchmask} is one product with at most three inputs. The number of choices is $O_A(v^2 2^m)$. Attach each to the union for its unique output mask $F(x_s)\cup N$. There are at most $O_A(v2^m)$ suffix states and $O_A(2^m)$ full-grid states, and the latter have at most $|A|$ inputs each. Counting their wires as well as their gates adds $O_A(v^2 2^m)$. Absent states and branches decrease these counts. Together with the constant intervals this proves the bound. \end{proof} \begin{proposition}\label{prop:gridcost} All exact-mask circuits for the full grid $X$ can be constructed simultaneously with size \begin{equation}\label{eq:gridcost} O_A\!\left(V\prod_{i\in I}(1+4q_i)\right). \end{equation} The number of bit operations is this bound times a polynomial in $|I|+\log(V+1)$. \end{proposition} \begin{proof} For fixed varying axes $T$, there are $V/v_T$ subgrids, one for each choice of their fixed coordinates. Summing Lemma~\ref{lem:localcost} over every subgrid gives \begin{align*} \sum_{T\subseteq I}\frac{V}{v_T}\,O_A(v_T^2 4^{|T|}) &=O_A\!\left(V\sum_{T\subseteq I}\prod_{i\in T}(4q_i)\right)\\ &=O_A\!\left(V\prod_{i\in I}(1+4q_i)\right). \end{align*} Build subgrids in increasing order of $|T|$, then cores, suffix states, and full-grid states, as in the proofs. This is a topological construction. Represent a subgrid by its varying-axis set and fixed coordinates, a vertex by its coordinate tuple, and a mask by a bit vector. All indices have polynomial length in $|I|+\log(V+1)$. For each possible differing vertex one may scan all $v_T$ vertices to obtain the partition and the prefix lengths $r_H$; over all vertices this takes $O(v_T^2)$ coordinate operations. Every remaining loop has one iteration per state, mask pair, or wire counted above. Feasibility flags are propagated by conjunction at products and disjunction at unions. Thus all indexing, arithmetic, and feasibility work fit within the stated polynomial factor. \end{proof} \begin{proof}[Proof of Theorem~\ref{thm:main}] For $n\geq2$ apply Proposition~\ref{prop:gridcost} to each of the $g$ grids from \eqref{eq:crt}, with $q_p=p$. Their total size is \[ O_A\!\left(gR\prod_{p\in P}(1+4p)\right) =O_A\!\left(n\prod_{p\in P}(1+4p)\right). \] Combine their exact masks by Lemma~\ref{lem:combine}, at additional cost $O(g4^k)$, and choose the output with mask $P$. The grid position sets are disjoint, so all products remain decomposable. By Lemmas~\ref{lem:primeperiod} and~\ref{lem:gridperiod}, the chosen output represents precisely $\Prim_A(n)$. This output is nonempty: for distinct $a,b\in A$, the word $a^{n-1}b$ is primitive, because the number of occurrences of $b$ in a $d$th power would be divisible by $d$. The additional cost is absorbed by the displayed bound. Indeed, $g4^k\leq gR\prod_{p\in P}(1+4p)$. As $1+4p\leq5p$ and $R\leq n$, this proves both \eqref{eq:strongbound} and $O_A(n^2 5^k)$. For completeness, $5^{\omega(n)}=n^{o(1)}$ follows without a prime number estimate. If the $k$ distinct primes are increasing, the $j$th is at least $j+1$, so $(k+1)!\leq n$. For $k\geq4$, at least $k/2$ factors in this factorial are at least $k/2$, whence \[ \log n\geq\frac{k}{2}\log(k/2). \] It follows that $k=o(\log n)$: when $k$ is large the ratio $k/\log n$ is at most $2/\log(k/2)$, and bounded values of $k$ also give a vanishing ratio. Thus $5^k=n^{o(1)}$. Also $k\leq\log_2 n$, so any fixed polynomial in $k+\log n$ is $n^{o(1)}$. Trial division finds the distinct primes of $n$ within the stated time. The position relabeling can be tabulated by enumerating $0\leq r