Representing Time Series as Structured Programs for LLM Reasoning

Jaeho Kim, Changhun Oh, Seokhyun Lee, Irina Rish, Changhee LeearXiv 2026 · arXiv

TL;DR

Large Language Models (LLMs) struggle with time-series data due to a fundamental modality mismatch between raw numbers and text. This paper introduces Time-Series-to-Structured-Program (T2SP), a deterministic, training-free method that decomposes time series into trends, periods, and events expressed as code-like symbolic programs. By aligning time-series data with the code and text modalities LLMs excel at, T2SP significantly boosts performance, slashes inference latency, and scales gracefully to long sequences.

What Problem Does This Paper Address?

While LLMs excel at complex reasoning and instruction-following, time-series analysis remains a major blind spot. Currently, researchers try to bridge this gap in three ways: serializing raw numbers into long strings (e.g., [0.1962, 0.2121, ...]), rendering data as visual plots for Vision-Language Models (VLMs), or fine-tuning models directly on temporal data.

However, these approaches force the LLM to do the heavy lifting of inferring high-level temporal structures value-by-value or pixel-by-pixel. This creates a severe representation mismatch, leading to massive tokenization overhead, format failures on long sequences, and an inability to capture fine-grained localized anomalies.

Figure 1: Representations matter for LLM-based time- series reasoning. (A) Raw numerical sequences are dense and heterogeneous, forcing LLMs to infer the temporal structure value by value. (B) LLMs are pretrained on a vast corpus of natural language texts and code representations (Touvron et al., 2023), making them well-suited for reasoning over symbolic and functional forms (Gao et al., 2023; Chen et al., 2023).

Methods

Instead of changing the model, the authors propose changing the representation. T2SP is a deterministic, training-free, and fully invertible pipeline that translates a raw time-series signal into a structured, human- and machine-readable program.

The pipeline breaks down a time series into four interpretable components:

  1. Trend ($\tau$): Modeled using smooth, locally adaptive B-spline functions to capture the overall trajectory.
  2. Periods ($\pi_k$): Extracted using Fourier spectrum analysis to identify dominant frequencies and fit global or piecewise sinusoids.
  3. Events ($\epsilon_j$): Isolated from the remaining signal using mathematical primitives like Spikes (for instantaneous shocks) and Gaussian events (for smooth, localized bumps).
  4. Residuals ($r$): Parameterized as Gaussian noise or preserved as raw values depending on whether exact reconstruction is required.

These components are formatted into a clean, program-like syntax (e.g., BSplineTrend(...), Sinusoid(...)). Because the decomposition is additive ($x = \tau + \sum \pi_k + \sum \epsilon_j + r$), it is fully invertible. An LLM can modify the text program, and T2SP can perfectly reconstruct the edited program back into a raw time-series array.

Overview of the T2SP framework: structural decomposition, symbolic program generation, and downstream task execution.

Datasets

The authors evaluated T2SP across three core tasks—editing, captioning, and question answering—using several datasets:

  • TSEdit: A new synthetic benchmark introduced in this paper. It pairs time series with free-form natural language editing instructions (e.g., "Flatten the trend" or "Remove the anomaly at t=50") along with ground-truth edited series.
  • ETTh1: A real-world electricity transformer oil temperature dataset used for human evaluation of complex, ambiguous editing requests.
  • Wafer & ECG200: Standard UCR time-series classification datasets used to evaluate the quality of generated captions via downstream classification accuracy.
  • TSQA, TRQA, and ETI: Existing multiple-choice benchmarks testing structural pattern recognition and explanation matching.

Key Insights and Ideas

  • Leveraging Pretraining Code Corpora: LLMs are natively trained on massive amounts of source code. Representing a time series as a structured program allows the model to leverage its existing code-parsing and symbolic reasoning capabilities rather than guessing patterns from raw numbers.
  • Component Isolation: In time-series editing, traditional models struggle with the trade-off between fidelity (making the requested change) and preservation (leaving everything else untouched). Because T2SP isolates components into distinct lines of code, the LLM can delete a single spike event without corrupting the underlying trend or periodic cycles.
  • Algorithmic Efficiency over Model Scale: Shifting the burden of feature extraction from the neural network to a deterministic mathematical pipeline eliminates the need for expensive fine-tuning or complex agentic loops.

Key Results

T2SP was tested against raw string and vision baselines across multiple LLMs (including GPT-5.4, Claude-haiku-4.5, Gemini-3.1-flash-lite, and Qwen-3.5-9B).

  • Superior Editing Performance: On the TSEdit benchmark, T2SP consistently achieved the highest edit fidelity and format success rates. For instance, using GPT-5.4, T2SP achieved an average fidelity score of 0.907 compared to 0.753 for raw strings and 0.493 for vision.
  • Human Preference: In blind pairwise evaluations on real-world ETTh1 data, human annotators overwhelmingly preferred T2SP's edits over raw strings (up to an 84.4% win rate) and vision baselines (up to a 92.9% win rate).
  • Graceful Scaling: As sequence lengths scaled up to 4096 points, raw string and vision baselines suffered from exponential increases in runtime and format failure rates. T2SP remained completely stable in both processing time and success rate.
Figure 3: Time Taken and Success Rate Across Sequence Length. The left and right axes represent the time taken (seconds) to perform the editing and the success rate, respec- tively. The three representations perform comparably up to a sequence length of 256, beyond which the raw and vision- based baselines deteriorate rapidly, while T2SP remains stable.

Limitations and Future Work

The primary limitation of T2SP is its reliance on a general trend-period-event decomposition framework. While highly effective for many applications, this abstraction may not fit specialized domains. For example, electrocardiogram (ECG) signals are characterized by highly specific morphological primitives (P, Q, R, S, and T waves) where relative timing and precise shapes carry clinical meaning that global trends or simple sinusoids cannot capture.

The authors note that designing domain-specific symbolic decompositions tailored to these unique primitives is a promising direction for future work.

Summary updated

Abstract

Large language models (LLMs) have demonstrated strong reasoning and instruction-following capabilities, making them potentially powerful tools for time-series analysis. However, time series lie outside their native textual modality, raising a fundamental question: how should time series be represented so that LLMs can reason about them effectively? Existing work typically serializes raw numerical sequences or fine-tunes pre-trained LLMs on time-series data. These approaches place the burden of extracting temporal structure directly on the LLM, creating a modality mismatch that often degrades performance on long sequences and introduces substantial computational overhead. In this work, we introduce Time-Series-to-Structured-Program representation (T2SP), a deterministic, training-free method that represents a time series as a structured symbolic program. T2SP decomposes time series into trends, periods, and salient events, expressing them in a program-friendly format aligned with the textual and code-like modalities on which LLMs are natively trained. By shifting temporal-structure extraction from the model to the representation itself, T2SP enables off-the-shelf LLMs to leverage their existing reasoning capabilities for time-series understanding. We evaluate T2SP on three reasoning tasks -- editing, captioning, and question answering -- where it consistently improves performance, reduces reasoning time, and lowers failure rates compared with raw-string representations. Our results demonstrate that T2SP provides an effective interface between time series and LLMs.
BibTeX
@misc{kim2026representing,
  author = {Jaeho Kim and Changhun Oh and Seokhyun Lee and Irina Rish and Changhee Lee},
  title = {{Representing Time Series as Structured Programs for LLM Reasoning}},
  year = {2026},
  eprint = {2606.12481},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2606.12481},
}

Loading related content...

Figure