Synthesizing finite input clocks on two input blocks

30 September 2026. Working research note.

A finite input clock predicts stack height from the letters it reads, without seeing the stack. On words anbma^n b^m, it might count up during the first block and down during the second. Can finite control choose a clock that stays within a fixed error of every legal run of a given pushdown source?

For this two-block restriction, the answer is decidable even when neither the clock’s size nor the allowed error is supplied. The proof turns all possible input lengths and heights into finitely many arithmetic pieces, then checks whether their slopes fit one finite clock. A feasible system constructs the clock and an error bound; an infeasible one rules out every clock in the stated class.

The example below explains the obstruction: a stack can detect when it empties and reverse direction, while input-only finite control cannot remember an arbitrarily distant turning point. This limits reflected clocks, not persistent stack implementations. Extending the synthesis test beyond two input blocks remains open in this note.

Contents

1. A stack can turn around where a finite clock cannot

Consider inputs anbma^n b^m. A deterministic stack pushes on aa, pops on bb until empty, and then pushes on every further bb. Its height is ∣n−m∣\lvert n-m\rvert. Finite control remembers whether it is reading aa, descending on bb, or growing on bb. At empty in the descending phase, the next bb pushes and enters the growing phase in that same step. Inputs with aa after bb are disabled. The initial stack is empty; n=0n=0 enters the growing phase on the first bb. One stack symbol suffices. Accepting exactly at empty recognizes {anbn:n≥0}\{a^n b^n:n\ge0\}.

There is exactly one height on each legal input. Nevertheless no finite input observer, emitting −1,0,+1-1,0,+1 and updating its height by H′=max⁡(0,H+c)H'=\max(0,H+c), can stay within a constant of this source on all prefixes.

Here is a direct proof. Suppose the observer has ss states and a uniform error bound. After any ana^n, follow bb forever. The source eventually grows at one symbol per letter. The observer’s eventually periodic bb-output must therefore have mean +1+1: any smaller mean gives a smaller asymptotic reflected growth rate. Since each output is at most +1+1, every output on that eventual cycle is +1+1. The transient has length at most ss. At anbna^n b^n the clock is at least n−sn-s while the source is zero, contradicting the bound as nn grows.

This obstruction concerns every clock in this specified reflected-clock class. The source itself has a direct persistent implementation using one immutable stack root. It is not a lower bound on persistent representations or on its language. A different presentation of {anbn}\{a^n b^n\} can simply stop popping at empty and reject further bb’s, and has a matching reflected clock.

The distinction from an absolute signed sum matters: ∣#a−#b∣\lvert\#a-\#b\rvert tracks this example exactly. Nowotka and Srba’s treatment of Caucal’s transducer clocks uses that absolute-value convention, not our reflected recurrence. Their Example 2 and Appendix B already discuss this change from descent to growth. The example is not claimed as a new phenomenon.

2. Model and theorem

PP is a normalized nondeterministic real-time pushdown source: finite control, finite stack alphabet, initially empty stack, finitely many initial states, and one consumed input letter with one push/pop/keep per rule. Guards inspect top or empty only. An empty pop is disabled or explicitly a no-op. There are no epsilon actions, bulk updates or other storage tests.

Restrict legal runs to words in a∗b∗a^*b^*. This restriction is implemented by a finite phase guard and includes every prefix. All runs count, not only accepting runs. Define the height relation

T={(n,m,h):a legal run on anbm ends at height h}. T=\{(n,m,h):\text{a legal run on }a^n b^m\text{ ends at height }h\}.

A clock has complete finite input control RR, fixed initial state, outputs c(r,x)∈{−1,0,1}c(r,x)\in\{-1,0,1\}, H0=0H_0=0 and H′=max⁡(0,H+c)H'=\max(0,H+c). The control reads input only; it cannot inspect HH, the source stack, or a nondeterministic choice.

Theorem. For this restricted source, it is decidable whether there exist a finite clock CC and B∈NB\in\mathbb N such that ∣h−HC(anbm)∣≤B\lvert h-H_C(a^n b^m)\rvert\le B for every triple in TT. On a positive instance one can construct CC and a valid BB. Neither its state count nor BB must be supplied. The finite slope criterion below is necessary and sufficient.

The criterion depends only on TT. Thus two presentations having the same height relation receive the same answer. This is not invariance under language equivalence, nor a characterization of every persistent realization. If PP permits other words, the language compiled by this result is L(P)∩a∗b∗L(P)\cap a^*b^*, not all of L(P)L(P).

The finite source/guard hypotheses are directly checkable. The required semilinear description is computable from P, rather than assumed as evidence that a clock already exists. No practical complexity bound is asserted.

3. Obtaining the arithmetic data

A pushdown machine can simulate PP, enforce a∗b∗a^*b^*, then nondeterministically stop in any configuration and pop its remaining stack, emitting one fresh letter zz per symbol. This constructs the context-free language

{anbmzh:(n,m,h)∈T}. \{a^n b^m z^h:(n,m,h)\in T\}.

The draining mode is an offline analysis device, not additional real-time source work. Constructive Parikh theory therefore computes TT as a finite union of linear sets

Li=bi+∑jNvij,bi,vij∈N3.(1) L_i=b_i+\sum_j\mathbb N v_{ij},\qquad b_i,v_{ij}\in\mathbb N^3.\tag{1}

Coordinates are written (n,m,h)(n,m,h). Effective Parikh semilinearity is classical; we import it, with the explicit automaton construction of Esparza, Ganty, Kiefer and Luttenberger as a primary implementation route.

Call a component nn-unbounded if some period has positive nn-coordinate. For each such component put

gi=gcd⁡j(vij)n>0,M=lcm⁡igi, g_i=\gcd_j(v_{ij})_n>0,\qquad M=\operatorname{lcm}_i g_i, with M=1M=1 if there are no such components.

Let NN be one greater than the largest base nn-coordinate of an nn-bounded component, or N=0N=0 if no such component exists. Every triple with n≥Nn\ge N lies in an nn-unbounded component. For each n<Nn<N, compute a semilinear description of the fiber Tn={(m,h):(n,m,h)∈T}T_n=\{(m,h):(n,m,h)\in T\}. From (1), coefficients of positive-nn periods are bounded by nn, so enumerate them; retain zero-nn periods. The resulting fiber bases and periods are finite and explicit.

4. The finite slope criterion

Introduce rational unknowns

0≤α≤1,−1≤βr≤1(0≤r<M),0≤γn≤1(0≤n<N). \begin{aligned} 0&\le\alpha\le1,\\ -1&\le\beta_r\le1 &&(0\le r<M),\\ 0&\le\gamma_n\le1 &&(0\le n<N). \end{aligned}

For every residue rr and nn-unbounded component ii satisfying r≡(bi)n(modgi)r\equiv(b_i)_n\pmod{g_i}, impose the following constraints.

  • If some period of LiL_i has positive hh-coordinate, require, for every period v=(u,ν,w)v=(u,\nu,w) of that component,

    w=αu+βrν.(2) w=\alpha u+\beta_r\nu.\tag{2}

  • If all periods have zero hh-coordinate, require, for every period,

    αu+βrν≤0.(3) \alpha u+\beta_r\nu\le0.\tag{3}

For each n<Nn<N and every period (ν,w)(\nu,w) of every fiber component, require

w=γnν.(4) w=\gamma_n\nu.\tag{4}

These are finitely many rational linear equations and weak inequalities. Feasibility over the reals and over the rationals coincide, and elimination decides feasibility and returns a rational solution. The criterion is exactly feasibility of (2)-(4) with the displayed ranges. There is no enumeration of unknown observer sizes, periods or error bounds.

The period MM is derived from any supplied decomposition (1). Different decompositions can change its size, but not the answer proved below. MM and the constructed observer size are bounds, not minimum values.

5. Why every finite clock must satisfy the criterion

5.1 Reflected unary behavior

Starting at any finite observer state and reading one letter repeatedly gives an eventually periodic output sequence. Let StS_t be its signed sum and μ\mu its rational cycle mean. There is DD such that ∣St−μt∣≤D\lvert S_t-\mu t\rvert\le D for all tt. For initial numerical height x≥0x\ge0, reflection has the exact formula

Rx(S)t=x+St−min⁡(0,min⁡0≤j≤t(x+Sj)). R_x(S)_t=x+S_t-\min\left(0,\min_{0\le j\le t}(x+S_j)\right).

If two signed-sum paths differ by at most DD, this formula bounds the difference of their reflected paths by 2D2D. The reflected linear path is max⁡(0,x+μt)\max(0,x+\mu t). Consequently

Rx(S)t=max⁡(0,x+μt)+O(1),(5) R_x(S)_t=\max(0,x+\mu t)+O(1),\tag{5}

where the constant is independent of xx and tt. There are finitely many observer states, so the bound can be uniform over starting states.

Applied to the aa-orbit from height zero, (5) gives H(an)=αn+O(1)H(a^n)=\alpha n+O(1), with α=max⁡(0,μa)∈[0,1]\alpha=\max(0,\mu_a)\in[0,1]. The observer state after ana^n is eventually periodic in nn, say with period pp after threshold KK. Applying (5) on bb then gives rational βj∈[−1,1]\beta_j\in[-1,1] such that, uniformly for all n≥Kn\ge K and m≥0m\ge0,

H(anbm)=max⁡(0,αn+βn mod pm)+O(1).(6) H(a^n b^m)=\max(0,\alpha n+\beta_{n\bmod p}m)+O(1).\tag{6}

For any fixed exceptional nn, the eventual bb-growth rate is a rational γn=max⁡(0,μb)∈[0,1]\gamma_n=\max(0,\mu_b)\in[0,1]; its height differs from γnm\gamma_n m by a constant.

5.2 Linear components force a common slope

Fix a linear component and a starting point whose nn-coordinate is at least KK. Adding pp times any period preserves the clock’s nn-residue. Scaling such directions and using (6) with bounded source error shows that every nonnegative combination dd of the periods satisfies

dh=max⁡(0,αdn+βdm).(7) d_h=\max(0,\alpha d_n+\beta d_m).\tag{7}

If all period heights are zero, the individual directions give (3). If some direction vv has vh>0v_h>0, (7) gives αvn+βvm=vh\alpha v_n+\beta v_m=v_h. Every other positive-height period satisfies the same equality. A zero-height period uu first gives αun+βum≤0\alpha u_n+\beta u_m\le0. If that value were negative, choose kk large enough that the linear expression on kv+ukv+u is positive. Equation (7) would then equate kvhkv_h with a strictly smaller value. Therefore the value on uu is zero too, yielding (2) for every period. This mixed-direction step is essential: testing the generators’ clipped values separately is weaker.

For a fixed nn fiber the same scaling argument with its eventual bb-growth rate gives (4), including zero-mm periods.

5.3 Why the source-derived period M suffices

The nn-projection of an nn-unbounded component is (bi)n(b_i)_n plus the additive monoid generated by its period nn-coordinates. It contains every sufficiently large integer in that congruence class modulo gig_i. To see this, divide by the gcd, choose one positive generator dd, and choose a nonnegative generated representative of each residue modulo dd; adding dd fills the tail of that residue. Such representatives exist because the generators have gcd one. This also gives an effective finite threshold.

Fix rr modulo MM. All components selected for rr therefore have a common sufficiently large n≡r(modM)n\equiv r\pmod M in their nn-projections. Choose n≥Kn\ge K as well. They all encounter the same old observer state after ana^n, and hence the same β\beta in (6). In each component choose a point above this nn and apply Section 5.2. That β\beta simultaneously satisfies all its required constraints for rr. Do this for each rr, retaining the one common α\alpha. The finitely many n<Nn<N fibers supply their γn\gamma_n. Thus a successful clock yields a feasible finite system despite its possibly unrelated period pp and threshold KK.

6. Constructing a clock from a feasible system

Given a rational solution, define β(n)=γn\beta(n)=\gamma_n if n<Nn<N, and β(n)=βn mod M\beta(n)=\beta_{n\bmod M} otherwise. The intended approximation is

F(n,m)=max⁡(0,αn+β(n)m).(8) F(n,m)=\max(0,\alpha n+\beta(n)m).\tag{8}

For an n-unbounded component and a relevant residue, (2) makes the linear expression on the period part exactly its height. Replacing its base height by α(bi)n+βr(bi)m\alpha(b_i)_n+\beta_r(b_i)_m changes (8) by at most (bi)n+(bi)m+(bi)h(b_i)_n+(b_i)_m+(b_i)_h, because max⁡(0,t)\max(0,t) is 1-Lipschitz. Under (3), height stays at the base height and the linear expression can only decrease as periods are added, giving the same safe bound. For n<Nn<N, (4) gives the identical base-error bound on every computed fiber component, using the base triple (n,m,h)(n,m,h). Thus

∣h−F(n,m)∣≤D(9) \lvert h-F(n,m)\rvert\le D\tag{9}

on all TT, where DD is the maximum coordinate sum of all nn-unbounded original bases and all computed small-fiber bases, or zero for an empty list.

On the jj-th aa, let the clock emit ⌊αj⌋−⌊α(j−1)⌋\lfloor\alpha j\rfloor-\lfloor\alpha(j-1)\rfloor, a periodic 0/1 sequence. Keep nn exactly below NN and thereafter nn modulo lcm⁡(M,den⁡(α))\operatorname{lcm}(M,\operatorname{den}(\alpha)). Here den⁡\operatorname{den} denotes the denominator in reduced form. On the first bb, choose β(n)\beta(n) and reset a finite phase counter. On the jj-th bb, emit

⌊β(n)j⌋−⌊β(n)(j−1)⌋. \lfloor\beta(n)j\rfloor-\lfloor\beta(n)(j-1)\rfloor.

These outputs lie in {−1,0,1}\{-1,0,1\}; for a fixed β\beta they are all nonnegative or all nonpositive. The resulting reflected height is exactly

H(anbm)=max⁡(0,⌊αn⌋+⌊β(n)m⌋).(10) H(a^n b^m)=\max(0,\lfloor\alpha n\rfloor+\lfloor\beta(n)m\rfloor).\tag{10}

It differs from FF by less than 2. Hence B=D+2B=D+2 is a valid integer construction bound. Complete the observer on inputs outside a∗b∗a^*b^* with an arbitrary sink. Its control never tests HH. With rational numbers in reduced form, a sufficient state count, including the sink, is

N+lcm⁡(M,den⁡(α))+∑rden⁡(βr)+∑n<Nden⁡(γn)+1.(11) \begin{aligned} N+\operatorname{lcm}(M,\operatorname{den}(\alpha)) &+\sum_r\operatorname{den}(\beta_r)\\ &+\sum_{n<N}\operatorname{den}(\gamma_n)+1. \end{aligned}\tag{11}

This proves sufficiency, effective synthesis and the theorem. The arithmetic criterion already supplies a terminating negative test; the prior fixed- clock decision theorem is not needed for this proof. It may subsequently compute the least skew for the particular clock constructed, if desired.

7. Examples that distinguish the conditions

Height relation on anbma^n b^m Result Reason
max⁡(0,n−m)\max(0,n-m) Yes α=1\alpha=1, β=−1\beta=-1.
∣n−m∣\lvert n-m\rvert No The two regions impose incompatible slopes.
max⁡(0,n−m)\max(0,n-m) for even nn, n+mn+m for odd nn Yes M=2M=2; β0=−1\beta_0=-1, β1=1\beta_1=1. A single common bb-slope would fail.
mm if n=0n=0, otherwise nn Yes The exceptional n=0n=0 fiber uses γ0=1\gamma_0=1; later bb-slope is 0.
⌊n/2⌋\lfloor n/2\rfloor Yes α=1/2\alpha=1/2 and β=0\beta=0. Integer slopes alone would miss it.
All heights 0,…,n0,\ldots,n No Growing and flat aa-directions require α=1\alpha=1 and α=0\alpha=0.
{n,n−1}\{n,n-1\} for n>0n>0, {0}\{0\} for n=0n=0 Yes α=1\alpha=1, β=0\beta=0, skew at most 1 despite nondeterminism.

All have normalized sources. Parity and half-rate behavior use finite control. In the last example the first aa nondeterministically pushes or keeps; all later aa’s push and bb’s keep. For the exceptional fiber, a finite state records whether any aa has occurred. All-run height semantics, rather than acceptance pruning, is used throughout.

For the valley ∣n−m∣\lvert n-m\rvert, the two linear components have base zero and periods

{(1,0,1),(1,1,0)},{(0,1,1),(1,1,0)}. \{(1,0,1),(1,1,0)\},\qquad\{(0,1,1),(1,1,0)\}.

Both have g=1g=1. The first forces α=1,β=−1\alpha=1,\beta=-1; the second forces β=1\beta=1 and α+β=0\alpha+\beta=0. The finite system is infeasible. This agrees with the direct obstruction in Section 1. It excludes all finite reflected clocks, not just small clocks tested by enumeration.

8. Persistent compilation and the boundary of the result

On a positive instance, the synthesized clock and BB enter the existing bounded-skew compiler. For the source restricted to a∗b∗a^*b^*, it supplies a degree-two, native-distance-two scaffold with one physical node per input letter and the reviewed fixed virtual initialization, without a padding letter. It preserves same-word prefix acceptance, including ε\varepsilon. The corresponding PEG recognizes (L(P)∩a∗b∗)R(L(P)\cap a^*b^*)^R.

The 2B+12B+1 source-symbol buffer and (11) are construction bounds, not optima. The preservation contract is fixed-controller acceptance and the decoded deterministic stack, not separate nondeterministic histories or raw graph equivalence under arbitrary scaffold contexts. This note’s offline analysis has no bounded-time guarantee.

The valley source still has a direct immutable-stack implementation: one root, one pointer field and at most one fresh logical record per letter. Clock synthesis is therefore a sufficient route to persistent memory. Preserving past stack versions does not by itself support general replay or reuse after arbitrary context changes.

9. Literature, proof status and next question

The proof combines classical effective Parikh semilinearity, unary finite- state periodicity, reflection, numerical-semigroup tails and rational linear feasibility. The additional argument here is the common-residue construction in Section 5.3: it replaces an unknown observer period by the finite period derived from source components, and yields the exact slope test and compiler consequence. Its novelty has not been established.

Primary comparisons inspected:

  • Esparza, Ganty, Kiefer and Luttenberger, Parikh’s Theorem: A simple and direct automaton construction, IPL 2011, Theorem 1.1 and Section 3. Effective semilinearity is imported, not a contribution of this note. https://archive.model.in.tum.de/um/bibdb/esparza/IPL11.pdf
  • Nowotka and Srba, Height-Deterministic Pushdown Automata, MFCS 2007, Definitions 2-3, Section 4.1, Appendix B Lemma 2 and Example 2. Unique height, exact synchronization, absolute signed sums and reflected clocks are distinct conditions. The periodicity argument is established. https://people.cs.aau.dk/~srba/files/NS:MFCS:07.pdf
  • Filiot, Jecker, Loding and Winter, On Equivalence and Uniformisation Problems for Finite Transducers, ICALP 2016, Theorem 2 and the resynchronization results. Choosing outputs by finite input control is related to uniformization, but our source-height relation need not be a rational word relation. No direct transfer of their decision or undecidability results is made. https://drops.dagstuhl.de/entities/document/10.4230/LIPIcs.ICALP.2016.125
  • Filiot, Jecker, Madnani and Sunny, Approximate Problems for Finite Transducers, ICALP 2025. The published abstract’s approximate rational/ sequential-function distinction was checked as a nearby comparison; no theorem is imported from it. Our reflected prefix-height requirement and pushdown source are not identified with its string-distance model. https://drops.dagstuhl.de/entities/document/10.4230/LIPIcs.ICALP.2025.155

For example, the graph of max⁡(0,n−m)\max(0,n-m) as a unary-output function on a∗b∗a^*b^* is not rational: the inverse image of ε\varepsilon is {anbm:m≥n}\{a^n b^m:m\ge n\}, which is not regular, whereas inverse images of regular languages under a rational transduction are regular. Semilinear triples alone do not make it a rational word relation. This explains why simply invoking finite-transducer synthesis would require an additional proof.

The arithmetic implementation accepts an explicit semilinear relation. It constructs (2)-(4), solves them with exact rational Fourier-Motzkin elimination, and rechecks every positive witness. For negative examples it rechecks nonnegative multipliers of the original inequalities yielding a constant contradiction. Recorded output includes the seven input relations, all constraints, solutions or negative certificates, and finite source-formula/clock comparisons through n,m=24. Those samples do not prove the infinite theorem. The full argument is a written proof, with no independent or proof-assistant verification. PDA-to-semilinear conversion and the scaffold compiler are not implemented.

The unrestricted-input clock-synthesis question remains unresolved here. The next useful test is whether the source-derived finite-period argument extends to three fixed input blocks. That extension is not automatic: later slopes may depend on both earlier residues, and reflection retains another piecewise-linear expression. A proof must bound the joint residue information from the source, rather than enumerate observers indefinitely. No pumping or recurrence theorem for PEGs or arbitrary scaffold interfaces is asserted.