---
title: Canonical Intermediate Representation (CIR)
url: https://www.emergentmind.com/topics/canonical-intermediate-representation-cir
type: topic
---

# Canonical Intermediate Representation (CIR)

The Canonical Intermediate Representation (CIR) is a structured semantic layer that bridges high-level natural language descriptions of optimization problems and their formal mathematical instantiations, most notably in the automated formulation of linear, integer, and mixed-integer programs. CIR acts as a domain-specific language or schema, guaranteeing a unique, unambiguous textual or symbolic representation of problems by enforcing strict grammatical, syntactic, and ordering constraints. Recent research has also extended CIR to encompass a knowledge-driven, multi-agent pipeline capable of handling complex operational semantics across multiple modeling paradigms, thereby decoupling problem intent from its specific solver-friendly realization [2212.03575, 2602.02029].

## 1. Formal Definition and Canonicality Guarantees

CIR was initially introduced as a minimal domain-specific language for linear programs, defined strictly as a sequence of declarations—one objective, followed by a (possibly empty) list of constraint declarations. The CIR grammar and ordering rules enforce a deterministic mapping from a problem’s semantic structure to a single canonical string, eliminating ambiguity due to commutativity, reordering, or variable renaming. The grammar is:

- **Top-level:**  
  CIR ::= ObjectiveDecl ConstraintDecl*

- **Objective Declaration:**  
  ObjectiveDecl ::= "maximize" LinearExpr | "minimize" LinearExpr

- **Constraint Declaration:**  
  ConstraintDecl ::= LinearExpr CompOp Constant, with CompOp ∈ {“≤”, “≥”} and Constant ∈ ℤ

- **Linear Expression Decomposition:**  
  LinearExpr ::= Term ('+' Term)*; Term ::= Coeff Var; Coeff ∈ ℤ, Var ∈ {x, y, z, w, x₁, …}

- **Ordering Rules:**  
  1. Objective precedes constraints  
  2. Constraints follow a fixed archetype ordering (lower-bound, upper-bound, xy-type, xby-type, sum-type, arbitrary linear, ratio-type)  
  3. Terms within each constraint are lexicographically ordered by variable  
  4. Within identically-shaped constraints, “≤” precedes “≥”  
  5. Variable names are drawn from a fixed vocabulary

This canonicalization ensures that every abstract LP, modulo algebraic equivalence, maps to exactly one CIR representation [2212.03575].

## 2. CIR Representation in Mathematical and LaTeX Notation

While CIR is a textual format for NLP-to-mathematical program pipelines, its semantics are often displayed with conventional mathematical notation:

- **Variables**: \( x \in \mathbb{R}^n \) as “x₁, x₂, …, xₙ” or “x, y, z, w”
- **Objective**:  
  CIR: maximize 3 x + 4 y  
  LaTeX: \( \max_{x} \; c^\top x \)
- **Constraints**:  
  CIR: 1 x + 2 y ≤ 50  
  LaTeX: \( A x \leq b \), where \( A \in \mathbb{R}^{m \times n}, b \in \mathbb{R}^m \)

Coefficients of 1 are omitted (“1 x” → “x”), but others are not elided. This translation guarantees lossless mapping from CIR to matrix-based solver inputs such as AMPL or JSON [2212.03575].

## 3. Rule-to-Constraint Schema and Semantic Layering

Advances in CIR have generalized its scope from just linear programs to a flexible structured schema suitable for logic-heavy, mixed-integer, and quadratic programs. In this schema, a problem description \( d \) is transformed into:

- A set of operational rules \( \mathcal{R}(d) = \{r_1,...,r_K\} \) and entities/parameters \( \mathcal{E}(d) \)
- A multiset of instantiated templates \( C(d) = (\mathcal{E}(d), \mathcal{A}(d)) \), where each \( a_\ell = (A_\ell, k_\ell, p_\ell) \) represents:
  - Core intent (e.g., NonOverlap, Precedence, Capacity)
  - Source rule from the input
  - Modeling paradigm (time-indexed, continuous-time, event-based, arc-flow, etc.)

The CIR-to-model mapping takes the union across all paradigm-specific constraint templates:
$$
M(d) = T(C(d)) = \bigcup_{\ell=1}^{L} \mathcal{C}_{A_\ell, p_\ell}
$$
where \( \mathcal{C}_{A, p} \) is the full set of mathematical constraints for intent \( A \) under paradigm \( p \). This explicit intermediate abstraction ensures that all feasible solutions to \( M(d) \) satisfy the operational rules \( \mathcal{R}(d) \) by construction [2602.02029].

## 4. Constraint Archetypes and Modeling Paradigms

CIR organizes operational rules into a compact set of archetypes, each with reference templates in multiple modeling paradigms. Key archetypes include:

| Archetype         | Example CIR Expression                      | LaTeX/Mathematical Formulation           |
|-------------------|---------------------------------------------|------------------------------------------|
| Assignment        | \( \sum_i x_{ij} = 1 \)                     | \( \forall j\in J: \sum_{i\in I} x_{ij}=1 \) |
| Precedence        | \( S_j \geq C_i \)                          | \( S_j \geq S_i + p_i \)                |
| Capacity          | \( \sum_j r_{j,k} z_{j,t} \leq R_k \)       | \( \forall t,k:\sum_{j\in J} r_{j,k} z_{j,t} \leq R_k \) |
| Non-overlap       | Disjunction in start/completion or time-index variables | Various forms, e.g., \( S_{j'} \geq S_j + p_j - M(1 - y_{jj'}) \) |
| Time Windows      | \( ES_j \leq S_j \leq LS_j \)               | \( ES_j \leq S_j \leq LS_j \)           |
| Integer-Multiple  | \( x = q u, u \in \mathbb{Z}_+ \)           | \( x = q u \) with constraints          |
| Logical/Indicator | \( 0 \leq x \leq M y \)                     | \( x=0 \text{ if } y=0 \)               |

Each archetype is instantiated for several paradigms: time-indexed MILP, continuous-time MILP, event-based, and arc-flow models. The CIR library maps each abstract intent to paradigm-specific templates:
$$
\{ p \mapsto \mathcal{C}_{A,p} \} \quad \forall p \in \{\mathrm{TI}, \mathrm{CT}, \mathrm{EB}, \mathrm{AF}\}
$$
[2602.02029].

## 5. CIR-Driven NLP Pipelines: Tagging, Embedding, and Multi-Agent Architectures

The text-to-CIR mapping employs a two-stage (and, in recent work, multi-agent) approach:

**BART with Entity Tags** [2212.03575]:  
- Word-piece tokens and entity tags (identifying coefficients, variables, comparators, etc.) are embedded:
  $$
  e_l = E^{tok}_{w_l} + E^{pos}_l + \lambda E^{tag}_{t_l}
  $$
  with tag embeddings weighted by a scaling factor \( \lambda \).
- The BiBART encoder processes sum embeddings to produce CIR outputs, which remain canonical due to grammar constraints.

**Multi-Agent Rule-to-Constraint (R2C) Pipeline** [2602.02029]:
1. **Extractor** tags and extracts rules and entities from natural language.
2. **Mapper** retrieves CIR intent templates per rule and binds parameters.
3. **Formalizer** composes the full model, emitting both mathematical and solver-executable formulations.
4. **Checker** verifies structural and semantic soundness end-to-end.

Retrieval of CIR templates is based on domain tags and semantic similarity, supported by in-memory and FAISS vector indices.

## 6. Illustrative Examples

**Linear Programming Canonicalization** [2212.03575]:
- NL statement: "A factory makes A ($3), B ($4); 1/2 machine-hours; ≤50 machine-hours; decide how many to produce; nonnegativity."
- CIR:  
  maximize 3 x + 4 y  
  x ≥ 0  
  y ≥ 0  
  1 x + 2 y ≤ 50

**Rich Rule Extraction and Paradigm Selection** [2602.02029]:
- NL statement: "Each job must finish before any downstream job begins, and at most one job can use Machine 1 at a time. Minimize makespan."
- Extractor maps precedence and non-overlap to intents.
- Mapper chooses continuous-time paradigm, instantiates correct templates.
- Formalizer emits constraints in both math and Gurobi-Python code.

## 7. Empirical Performance and Practical Impact

Empirical results on recognized benchmarks emphasize CIR’s role as an indispensable intermediate layer:

| System              | CIR Layer   | Key Accuracy (%)              | Benchmark                         |
|---------------------|-------------|-------------------------------|-----------------------------------|
| BART-large, λ=5     | Yes         | 88.46 (declaration accuracy)  | LPWP validation [2212.03575]      |
| R2C (7B LLM)        | Yes         | 47.2 (Accuracy Rate, AR)      | ORCOpt-Bench [2602.02029]         |
| GPT-5               | No          | 39.8 (AR)                     | ORCOpt-Bench [2602.02029]         |
| R2C ablation (no CIR) | No        | 31.6 (AR)                     | ORCOpt-Bench [2602.02029]         |
| R2C+reflection      | Yes         | 54.0 (AR)                     | ORCOpt-Bench [2602.02029]         |

Key findings include:
- Tag- and entity-aware embeddings, especially with high λ, notably increase mapping accuracy in classic LP settings [2212.03575].
- Introducing CIR in multi-agent frameworks yields a substantial accuracy gain over both proprietary and open baselines.
- CIR enables training-agnostic, retrieval-based formulations that remain competitive with tuned LLMs on industry-scale tasks.
- The reflection enhancement in R2C further boosts robustness in complex, compositional problem settings [2602.02029].

In summary, CIR establishes an extensible, verifiable, and semantically sound layer between natural-language problem specification and executable optimization code. By encoding intents as archetypes with paradigm-specific instantiations, CIR enables both symbolic and data-driven models to robustly and transparently translate diverse operational rules into solver-ready programs [2212.03575, 2602.02029].

Source: https://www.emergentmind.com/topics/canonical-intermediate-representation-cir