cs.LGOct 19, 2026

Copying Under Repetition: From Prefix Matching to Position Hashing

Authors: Anxin Guo, Tianlong Huang, Chenxiao Yang, Zhiyuan Li

Organizations: Northwestern University · Duke University∗ · Toyota Technological Institute at Chicago

Abstract

Frontier LLMs can copy random text almost flawlessly, yet they often overrun or truncate long blocks of repeated characters. In repeated strings, matching local content no longer reliably identifies where copying should continue or when it should stop. Nevertheless, we show that a two-layer transformer with O(log⁡log⁡N)O(\log\log N)-bit precision and O(log⁡N/log⁡log⁡N)O(\log N/\log\log N) width can copy every string up to a chosen design horizon NN and terminate correctly under arbitrary repetition. We use RoPE-style rotations of attention values and outputs (VO-rotations) with small prime periods to encode distances from delimiter anchors modulo those primes. By the Chinese Remainder Theorem, these periodic encodings jointly distinguish all required distances, allowing one retrieval rule to select either the next source token or the end marker. In contrast, we prove a width-independent impossibility result for copying under sequential finite-precision softmax accumulation. It applies to transformers whose only positional input is an additive attention bias that eventually becomes constant, including NoPE and a recursive implementation of ALiBi. Once an identical-token run exceeds the resulting saturation threshold, further repetitions leave the logits unchanged. If this threshold grows sublinearly with NN, these models cannot both complete a long all-identical copy and stop correctly, a pattern resembling the termination errors of frontier LLMs. In synthetic copying experiments, baseline transformer models fail on long repeated strings even within the training range. Trained VO models, by contrast, generalize beyond the training lengths with near-perfect accuracy up to length ≈5005\approx 5005, the selected primes' period product.

Figures & tables

Appendix figures & tables5 assets

Supplementary material from the paper’s appendix.

Appendix

Explore similar work

CardsList
  1. Copy-Paste Language Models

    Oct 13, 2026Nathan Godey, Yoav ArtziLanguage Model PretrainingEfficient Language Model Training

  2. How Many Different Outputs Can a Transformer Generate?

    May 21, 2026Maxime Meyer, Mario Michelessa, Caroline Chaux +1Transformer ExpressivityTransformer