WorksComputer Science
Decomposable disjoint-union circuits for primitive words
Abstract
For every fixed finite alphabet with at least two letters, we construct smooth decomposable circuits representing the primitive words of each length . 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 , and the construction takes 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, Raphael, 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.
Statement and circuit model
A nonempty word is primitive if it is not a power with . The empty word is excluded.
Write for the primitive words of length , and let be the number of distinct prime divisors of the positive integer , with .
Amarilli, Monet, Raphaël, and Salvati introduced a multivalued circuit framework for probabilistic language membership [1 Section 5]. Their construction for primitive words uses complementation, and [1 Section 6] 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 of positions. An assignment on is a function . A circuit is a finite directed acyclic graph, with a designated output, built from the following gates.
A literal has domain and represents the one assignment sending to .
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.
A union gate has inputs with the same domain and pairwise disjoint represented sets. It represents their union, with that common domain.
These requirements are called decomposability, smoothness, and disjointness, respectively. We allow the nullary product, of domain , representing the unique empty assignment, and the nullary union, of domain , 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 by . 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.
Theorem 1.1. Fix a finite alphabet , with . For each integer there is a smooth decomposable disjoint-union circuit with domain representing exactly and
having size
One algorithm constructs these circuits in bit operations as a function of . The empty slice is represented by a nullary union.
Here and below is fixed, so constants may depend on . Construction time is measured in the represented length , or equivalently with given in unary. A stronger intermediate bound will be
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 [2 Section 6].
From periods to independent grids
We identify positions of a length- word with . For a divisor , a word is invariant under shift if for all positions .
Lemma 2.1. Let , and let be its set of distinct prime divisors. A word is primitive if and only if it fails to be invariant under shift for every .
Proof. If with , then . Choose a prime and write . It is invariant under shift . Conversely, the orbits of shift are the sets for . Invariance therefore says precisely that is the th power of its prefix of length .
Set
Every shift preserves the residue of a position modulo . Within residue class , , write a position uniquely as , where . Use the Chinese remainder bijection
Shift adds to . In these coordinates it fixes every coordinate other than , and adds the nonzero residue in coordinate . Repeated addition visits all values of that coordinate. Thus the residue classes form independent copies of a rectangular grid with side lengths .
For a labeled grid, call an axis failed if at least one line parallel to it is not constant. The set of failed axes is its mask. The preceding observations prove the following statement.
Lemma 2.2. The word fails shift exactly when axis fails in at least one of the grids. Its primitive-word condition is therefore that the union of the masks of the grids is .
We next construct circuits for each exact grid mask. Exactness will make all unions in the construction disjoint.
The constant-prefix recursion
For this section take any ordered finite set of axes, with integer side lengths . Write
A subgrid fixes the coordinates outside some and varies all the coordinates in . Its varying axes are , its size is , and its vertices inherit lexicographic order from the ordered axes. In particular, a subgrid with no varying axes has a single vertex.
Let be an ordered subgrid with varying axes . For a labeling define
For , , and , let be the assignments on whose extension by the value on has mask exactly . Let be the assignments on all of with mask exactly . The constant prefix is a condition on the represented assignments, and its positions are outside their domain.
We will represent every nonempty one of these sets by a gate. If a state is empty, we record that fact and create no gate for it. A proposed product involving an empty state is omitted, and unions range only over nonempty inputs. This convention respects the structural definition of domain above. Feasibility is determined during the same recursion, without examining all assignments.
Lemma 3.1 (first differing vertex). Let , and complete a prefix of copies of to a nonconstant labeling of . Let be its first vertex whose label differs from . Put
Then , is nonempty, and every axis in fails. Partition into subgrids by fixing all coordinates in , so that each has varying axes . The following hold.
(i) In the subgrid containing , that vertex is first, and no earlier vertex of lies in .
(ii) In every other , the vertices preceding in form an initial segment of , all labeled .
(iii) For , axis fails in if and only if it fails in at least one of these subgrids.
Consequently, for every such completed labeling ,
Proof. The first vertex has all varying coordinates zero. Since , we have and hence . For each , reset coordinate of to zero, keeping all others fixed. The resulting vertex precedes in lexicographic order, so its label is , whereas the label of is . The two vertices share an -axis line, and that line is nonconstant.
Every coordinate of in is zero. After the coordinates are fixed to those of , it is therefore the first vertex of . Lexicographic order on any other is the restriction of the order on . Intersecting an initial segment of with gives an initial segment of , proving (ii). Finally, any line in an axis has fixed coordinates. It is contained in one , and the -lines of all the are exactly the -lines of . This proves (iii) and (3.1).
We spell out the use of exact masks in combining subgrids.
Lemma 3.2 (combining exact masks). Suppose are pairwise disjoint position sets. For each suppose gates on domain represent pairwise disjoint families indexed by , with empty families recorded as absent. There is a smooth decomposable disjoint-union construction representing, for every ,
using new gates and wires. All nonempty resulting states have domain .
Proof. Start with the nullary product at mask and no state at any other mask. After processing domains, keep one state for each nonempty family with accumulated mask . For every nonempty pair and , form their product and attach it to the union for . These products are decomposable. For a fixed resulting mask, all products have domain . An assignment on this domain determines its restrictions to the first domains and to . Pairwise disjointness of the state families then determines both and uniquely. Thus the union is disjoint. Induction proves (3.2) and pairwise disjointness across its different masks. At each step there are at most mask pairs, so the claimed bound counts both gates and wires. Empty states are recognized by the absence of a nonempty pair.
Proposition 3.3. For every subgrid and every admissible , the nonempty sets and admit circuits of the specified type. All these circuits can be constructed simultaneously by induction on the number of varying axes.
Proof. Suppose the construction is available on subgrids with fewer than varying axes. For each the constant completion contributes the single all- assignment on to . It is represented by a product of literals; when the domain is empty this is the nullary product.
For a nonconstant completion, fix its first differing index and its letter . Use , , and the subgrids of Lemma 3.1. They have fewer varying axes because is nonempty. For let
If , use the states on all of . If , use on the remaining suffix of . For use . In every case the prescribed prefix lies outside the state’s domain. These remaining domains partition .
Apply Lemma 3.2 to these states. Denote the gate of accumulated mask , if nonempty, by . It has domain . To obtain a branch for the original suffix, multiply it by the assignment on and by the literal . The three domains are disjoint, and their union is . By (3.1), this branch contributes precisely to
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 , masks are exact and pairwise disjoint; moreover determines . The constant branch is disjoint from every nonconstant branch. Lemma 3.1 shows that every completion occurs in the prescribed branch, so these gates represent exactly the claimed sets.
Finally, form by the disjoint union, over , of the literal times the state , omitting absent states. The two factors have disjoint domains. The resulting branches all have domain , and their first letters make them pairwise disjoint.
When , is a singleton. The only possible mask is ; its states at are nullary products, and 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.
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.
Lemma 4.1. Let have vertices and varying axes. Besides gates already constructed on its proper subgrids, all its states in Proposition 3.3 require gates and wires.
Proof. We first build the constant assignment of letter on every interval , $0 \le i \le j \le v$. For fixed , start with the nullary product and append one literal at a time. Each extension uses a binary decomposable product. This costs gates and wires in total. Literals can be shared wherever they recur.
For fixed , , and , the partition into , all numbers , and the distinguished state with letter depend only on . They do not depend on . The core gates are therefore built once and shared for every such . There are at most subgrids in this partition, and at most remaining axes. Lemma 3.2 bounds the cost of one core by . There are choices of , so all cores cost .
For each the branch in (5) is one product with at most three inputs. The number of choices is . Attach each to the union for its unique output mask . There are at most suffix states and full-grid states, and the latter have at most inputs each. Counting their wires as well as their gates adds . Absent states and branches decrease these counts. Together with the constant intervals this proves the bound. □
Proposition 4.2. All exact-mask circuits for the full grid can be constructed simultaneously with size
The number of bit operations is this bound times a polynomial in .
Proof. For fixed varying axes , there are subgrids, one for each choice of their fixed coordinates. Summing Lemma 4.1 over every subgrid gives
Build subgrids in increasing order of , 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 . For each possible differing vertex one may scan all vertices to obtain the partition and the prefix lengths ; over all vertices this takes 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. □
Proof of Theorem 1.1. For apply Proposition 4.2 to each of the grids from (2), with . Their total size is
Combine their exact masks by Lemma 3.2, at additional cost , and choose the output with mask . The grid position sets are disjoint, so all products remain decomposable. By Lemmas 2.1 and 2.2, the chosen output represents precisely . This output is nonempty: for distinct , the word is primitive, because the number of occurrences of in a th power would be divisible by . The additional cost is absorbed by the displayed bound. Indeed, . As and , this proves both (1.1) and .
For completeness, follows without a prime number estimate. If the distinct primes are increasing, the th is at least , so . For , at least factors in this factorial are at least , whence
It follows that : when is large the ratio is at most , and bounded values of also give a vanishing ratio. Thus . Also , so any fixed polynomial in is .
Trial division finds the distinct primes of within the stated time. The position relabeling can be tabulated by enumerating and and computing the residues in (2); no search over assignments is involved. Together with Proposition 4.2, these facts give construction time in the bit model. For , use the disjoint union of the literals at its sole position. For , use the nullary union. □
Exact power orders
We finish with a consequence for the exact order of a word. The usual uniqueness of a primitive root can be proved directly in the cyclic notation used here.
Lemma 5.1. Every nonempty word has a unique expression with primitive and .
Proof. For a word of length , let
This is an additive subgroup of containing , so for a positive divisor of . The word is the th power of its prefix of length . If were a proper power, its shorter block length would belong to , contrary to minimality of .
If also with primitive, then and hence . Invariance under shift says that the prefix is itself a power of the prefix of length . Primitivity forces , so and . □
Call in Lemma 5.1 the order of .
Corollary 5.2. Fix as in Theorem 1.1. For any and any set of positive divisors of , the length- words whose orders belong to have a smooth decomposable disjoint-union circuit of size , constructible in bit operations. This includes a circuit for each individual exact order.
Proof. Fix and put . A word has order exactly when it is for . Take the circuit of Theorem 1.1 for length . For every literal , replace it by the product of the literals
For distinct source positions , the corresponding position sets are disjoint. Consequently every original product stays decomposable, and equal original domains give equal expanded domains. The expansion of an assignment is injective: restriction to the first positions recovers it. Disjoint unions therefore remain disjoint. The output represents exactly the words of order .
Share equal source literals before replacing them. There are at most of them, so the replacements add gates and wires. The circuit for this order has size
Construct such circuits separately for and take the union of their outputs. All domains are the same, and the outputs are pairwise disjoint by Lemma 5.1. Finally,
where the last inequality follows by comparing the terms from onwards with . Also times the number of divisors of is at most . These estimates give the size bound. The same summation, with the polynomial indexing factors already bounded uniformly in , proves the construction-time bound. If is empty, a constant assignment on the full domain multiplied by a nullary union gives the required empty output with size . □
References
Email address: [email protected]
Email address: [email protected]
Email address: [email protected]
Email address: [email protected]
References
- [1]Antoine Amarilli, Mikaël Monet, Paul Raphaël, and Sylvain Salvati, On the complexity of language membership for probabilistic words, in 43rd International Symposium on Theoretical Aspects of Computer Science (STACS 2026), Leibniz International Proceedings in Informatics 364 (2026), article 5, 5:1–5:21. doi:10.4230/LIPIcs.STACS.2026.5.DOI
- [2]Antoine Amarilli, Mikaël Monet, Paul Raphaël, and Sylvain Salvati, On the complexity of language membership for probabilistic words, full version, arXiv:2510.08127v2, 22 June 2026. https://arxiv.org/abs/2510.08127v2.