---
title: Unfolding Expressions in Computational Semantics
url: https://www.emergentmind.com/topics/unfolding-expressions
type: topic
---

# Unfolding Expressions in Computational Semantics

“Unfolding expressions” denotes a family of operations in which a compact, implicit, folded, or detector-distorted representation is replaced by a more explicit one. In the supplied literature, the term ranges from cutting and flattening polyhedral surfaces into planar nets, to generating lists by anamorphisms, to reconstructing truth-level histograms from detector-level counts, to substituting recursive definitions in \(\lambda\)-letrec, to locally replacing constants by their defining expressions in dependent type theory, to inlining CHR constraints, to deriving source-level facts for lazy functional programs, and to assigning supercell eigenstates weights in the primitive Brillouin zone [0509054] [2406.01500] [2602.22776] [1610.05954] [2210.05420] [0807.3979] [1708.08003] [2506.21089]. A common thread is expansion under structural constraints: cuts must avoid overlap, coalgebras must terminate, recursive substitutions must preserve expressibility, and optimization or projection operators must preserve the relevant semantics.

## 1. Geometric and physical meanings of unfolding

In computational geometry, an **edge-unfolding** of a polyhedron is produced by cutting along edges and flattening the faces to a **net**, a connected planar piece with no overlaps. A **grid unfolding** allows additional cuts along grid edges induced by coordinate planes passing through every vertex, and a **vertex-unfolding** permits faces in the net to be connected at single vertices, not necessarily along edges [0509054]. For orthogonal polyhedra, the central result is that **any orthogonal polyhedron of genus zero has a grid vertex-unfolding**, and for an orthogonal polyhedron \(P\) with \(n\) vertices there is an algorithm that vertex-unfolds \(P\) in \(O(n^2)\) time; the same work also presents a simpler vertex-unfolding algorithm that requires a \(3 \times 1\) refinement of the vertex grid [0509054]. The supplied material also states that **there are orthogonal polyhedra that cannot be vertex-unfolded**, so some type of gridding of the faces is necessary [0509054].

In high-energy physics, **unfolding** is the inverse problem of reconstructing true distributions of physical observables from detector-distorted measurements. At the level of probability densities, the detector is modeled by a response function
\[
r(\mu \mid z) = m(\mu \mid z)\,\epsilon(z),
\]
and the expected reconstructed distribution is
\[
g(\mu) = \int r(\mu \mid z)\, f(z)\, dz + \beta(\mu).
\]
In the discretized formulation,
\[
\mu_i = \sum_{j=1}^{M} R_{ij} z_j + \beta_i,
\qquad
\boldsymbol{\mu} = R \boldsymbol{z} + \boldsymbol{\beta},
\]
with unfolding defined as estimating \(\boldsymbol{z}\) from \(\boldsymbol{n}\), \(R\), and \(\boldsymbol{\beta}\) subject to physical constraints [2602.22776].

In electronic-structure theory, **band structure unfolding** reverses the folding caused by supercell calculations. Primitive-cell bands are folded into the reduced supercell Brillouin zone, and unfolding assigns to each supercell eigenstate a weight at each primitive-cell \(\mathbf{k}\). The resulting unfolded spectral function is
\[
A(\mathbf{k}, E) = \sum_{\mathbf{K} N} W^{\mathbf{k}}_{\mathbf{K} N} \, \delta(E - E_{\mathbf{K} N}),
\]
with unfolding weight
\[
W^{\mathbf{k}}_{\mathbf{K} N}
= \langle \Psi_{\mathbf{K} N} | P_{\mathbf{k}} | \Psi_{\mathbf{K} N} \rangle
= \sum_j |\langle \mathbf{k} j | \Psi_{\mathbf{K} N} \rangle|^2
= \sum_n |\langle \psi_{\mathbf{k} n} | \Psi_{\mathbf{K} N} \rangle|^2.
\]
The AO-based formulation explicitly accounts for the non-orthogonality of atomic orbitals and their atom-centered nature, and the implementation in FHI-aims is presented as enabling accurate and efficient unfolding of conduction, valence, and core states [2506.21089].

These cases all involve explicit expansion of latent structure, but the object being “unfolded” differs: a surface in geometry, a truth-level spectrum in HEP, and a supercell eigenspace in electronic structure. This suggests that “unfolding” is best treated as a structural operator rather than a single domain-specific procedure.

## 2. Unfolding as generation, recursion, and symbolic expansion

In recursion-scheme–based program synthesis, unfolding appears concretely as the **anamorphism** pattern. Origami’s list anamorphism is
```haskell
f arg0 ... argn = ana coalg {1} where
  coalg seed = if {2} then []
               else {3} : {4}
```
with `{1}` the initial seed, `{2}` the predicate, `{3}` the head element, and `{4}` the next seed [2406.01500]. The same source states that anamorphisms generate data structures from seeds, while **hylomorphisms** compose an anamorphism and a catamorphism:
```haskell
f arg0 ... argn = hylo alg coalg arg0 where
  coalg seed = if {1} then [] else {2} : {3}
  alg []      = {4}
  alg (x:acc) = {5}
```
and explicitly describes Hylo as “captur[ing] an Anamorphism followed by a Catamorphism, such as applying `foldr` to the result of `unfold`” [2406.01500].

The role of unfolding in Origami is methodological as well as operational. The recursion scheme is fixed, and only slots are evolved by Genetic Programming, so the unfolding shape is not synthesized; rather, the GP searches for the initial seed, the termination test, the element generator, and the seed transformer [2406.01500]. The stated motivation is that recursion schemes decouple how to traverse or generate the data structure from how to process it, thereby avoiding some of the pitfalls of recursive functions during program synthesis [2406.01500].

In the unfolding semantics of higher-order, lazy functional programs, unfolding is a systematic way of “executing” a functional program symbolically by repeatedly replacing function calls with their definitions, producing a set of derived equations or **facts**. The language includes variables, constructors, user-defined functions, and predefined functions, with higher-order application encoded by `@`, and the semantics iterates an unfolding operator \(U_P\) over interpretations:
\[
I_{m+1} = U(I_m) = \mathit{clean}(I_{m+1}^\top).
\]
The meaning of a program is the least fixpoint or limit \(I_\omega = U_P^\infty(I_\bot)\) [1708.08003]. The paper emphasizes that these facts themselves are valid source code and can be used as a semantic representation of the program [1708.08003].

In both settings, unfolding is not merely expansion by substitution. In Origami it is a typed synthesis template over coalgebras; in unfolding semantics it is an interpretation transformer over facts, guards, and predefined functions. A plausible implication is that “unfolding expressions” in programming-language research often denotes controlled generation of explicit operational structure rather than unrestricted inlining.

## 3. Unfolding semantics in \(\lambda\)-letrec and related calculi

For the untyped \(\lambda\)-calculus with letrec, unfolding is the process of substituting occurrences of function variables by the right-hand side of their definition. A finite \(\lambda\)-letrec term expresses an infinite \(\lambda\)-term if the latter can be obtained as an infinite unfolding of the former [1610.05954]. The supplied material gives the intuitive example
\[
\Let fix = \lambda f.\,f (fix f) \In fix
\]
which unfolds to the infinite \(\lambda\)-term
\[
\lambda f.\, f (f (f (\dots))).
\]
Formally, unfolding is defined by rewriting systems \(\mathcal{U}\) and \(\mathcal{U}_\bullet\), with partial unfolding semantics
\[
\unfsem{L} = M \quad\text{iff}\quad L \to_{\mathcal{U}}^\infty M
\]
and total unfolding semantics with black holes
\[
\unfbhsem{L} = M \quad\text{iff}\quad L \to_{\mathcal{U}_\bullet}^\infty M.
\]
Theorem 1.25 is reported as establishing that these are well-defined functions [1610.05954].

The central characterization theorem states:
\[
M \text{ λ-letrec-expressible}
\iff
M \text{ strongly regular}
\iff
M \text{ regular and no infinite binding–capturing chains}.
\]
The supplied details further state that a regular \(\lambda\)-term is strongly regular iff all its binding–capturing chains are finite [1610.05954]. This turns unfolding from an operational intuition into a criterion for expressibility.

Equality of unfoldings is also made algorithmic. The same work identifies a first-order term graph formalism on which bisimulation preserves and reflects the unfolding semantics of \(\lambda\)-letrec and which is closed under functional bisimulation, and from this derives efficient methods to determine whether two terms are equivalent under infinite unfolding and to compute the maximally shared form of a given \(\lambda\)-letrec term [1610.05954]. The graph-theoretic layer is therefore not ancillary: it is the mechanism by which infinite unfolding is compared and compressed finitely.

This literature treats unfolding as a semantics for recursive syntax. Unlike the recursion-scheme literature, where unfolds generate data from seeds, here unfolds map finite recursive syntax into infinite terms by rewriting, with regularity and bisimulation providing the corresponding invariants.

## 4. Controlled unfolding in type theory and proof assistants

In dependent type theory, unfolding is the operation of replacing a constant or definition by its defining expression. The supplied material gives addition as the canonical example:
\[
plus : \mathbb{N} \to \mathbb{N} \to \mathbb{N}
\]
with defining equations
\[
\mathsf{ze} + n = n,
\qquad
\mathsf{su}\;m + n = \mathsf{su}\,(m + n).
\]
Unfolding `plus` in \(\mathsf{su}\,\mathsf{ze} + \mathsf{su}\,\mathsf{ze}\) means replacing occurrences of `+` by these clauses and reducing [2210.05420].

“Controlling unfolding in type theory” proposes that definitions are **opaque by default** and can be selectively unfolded in a local manner. A top-level annotation such as
```text
(⊕) unfolds (+)
```
makes `+` transparent within the body of `(⊕)`, while outside `(⊕)` it remains opaque [2210.05420]. The details further state that unfolding is **local** and **transitive**: if definition \(f\) is unfolded and \(f\)'s body uses \(g\), then it must be legal to unfold \(g\) as well, and this is enforced via proposition symbols that track unfolding entailment [2210.05420].

The formal core calculus \(\mathrm{TT}_\mathbb{P}\) introduces proposition symbols \(p,q,\dots\), dependent products over propositions \(\{p\}A\), and **extension types** \(\mathrm{Ext}(A,p,a_p)\). The key rules include
\[
\frac{\Gamma \vdash A : \mathsf{Type} \quad \Gamma,p \vdash a_p : A}
{\Gamma \vdash \mathrm{Ext}(A,p,a_p) : \mathsf{Type}},
\]
\[
\frac{\Gamma \vdash a : A \quad \Gamma,p \vdash a_p : A \quad \Gamma,p \vdash a = a_p : A}
{\Gamma \vdash \mathsf{In}_p(a) : \mathrm{Ext}(A,p,a_p)},
\]
and
\[
\frac{\Gamma \vdash a : \mathrm{Ext}(A,p,a_p)}
{\Gamma \vdash \mathsf{Out}_p(a) : A}.
\]
The intended reading is that \(\mathrm{Ext}(A,p,a_p)\) is the type of elements of \(A\) that are definitionally equal to \(a_p\) when the unfolding condition \(p\) is assumed [2210.05420].

The same source states that the system has been implemented in the cooltt proof assistant and that a normalization theorem is proved for the core calculus [2210.05420]. Here, unfolding expressions are not treated as tactics or ad hoc conversion settings, but as a type-theoretic construct with elaboration into a core language. This distinguishes controlled unfolding from unrestricted definitional equality.

## 5. Program transformation: CHR and lazy functional programs

In CHR, unfolding is defined as the replacement of a procedure call by its definition, specialized to user-defined constraints in rule bodies. The paper “Unfolding in CHR” defines an unfolding rule for annotated CHR programs, proves its correctness, and discusses conditions under which an unfolded rule can replace an original one while preserving program meaning [0807.3979]. The operational setting uses the reference semantics \(\omega_t\) with a propagation history and a modified semantics \(\omega'_t\) for annotated programs, and the supplied details state
\[
\mathcal{QA}_{P}(G) = \mathcal{QA'}_{Ann(P)}(G).
\]
The observable semantics is therefore qualified answers, and correctness means preservation of qualified answers under unfolding [0807.3979].

The central transformation is compile-time pre-application of one rule inside another. If a rule \(r\) has body constraints that match the head of a rule \(v\), and the guard and built-in constraints are strong enough, the unfolding rule replaces those body constraints by the renamed body of \(v\), conjoins the necessary guard information, and updates the local token store [0807.3979]. Proposition 4.10 is reported as showing that if \(P' = P \cup \{r'\}\), where \(r'\) is the unfolding of \(r\) by \(v\), then for every goal \(G\),
\[
\mathcal{QA'}_{P'}(G) = \mathcal{QA'}_P(G).
\]
The same source also states that confluence and termination properties are preserved under the stated transformations [0807.3979].

The unfolding semantics of lazy functional programs uses a different technical apparatus but a similar intuition. A fact has the form
\[
h \mid c = b
\]
subject to the condition that \(b\) and \(c\) contain no user-defined function symbols and predefined functions are allowed only where they cannot be evaluated further [1708.08003]. The unfolding operator generates these facts by symbolically replacing user-defined calls, while `clean` removes redundancy among overlapping facts [1708.08003]. Adequacy is stated as equivalence between operational evaluation and evaluation with the limit interpretation \(I_\infty\) [1708.08003].

Both CHR and lazy functional unfolding are semantics-preserving program transformations, but the preserved semantics differs: qualified answers in CHR and adequacy with respect to a small-step operational semantics in lazy functional programming. This suggests that “unfolding expressions” in program transformation is best understood through the semantic invariant attached to the target language.

## 6. Optimization, inversion, and projection-based unfolding

In optimization-based HEP unfolding, the Poisson likelihood is approximated by a quadratic term and combined with curvature regularization to obtain
\[
\min_{\boldsymbol{z}}
\left(
\left\|R \boldsymbol{z} - \boldsymbol{n}\right\|^2
+ \lambda \left\|D \boldsymbol{z}\right\|^2
\right),
\]
with integer decision variables \(z_i \in [0, z_i^{\mathrm{max}}]\) [2602.22776]. The regularization term is a discrete Laplacian penalty,
\[
S(\boldsymbol{z}) = - \sum_{i=1}^{M-2} (-z_i + 2z_{i+1} - z_{i+2})^2,
\]
and the quadratic form is written as
\[
\min_{\boldsymbol{z}}
\left(
\boldsymbol{a} \cdot \boldsymbol{z}
+
\boldsymbol{z}^T B\,\boldsymbol{z}
\right),
\quad
\boldsymbol{a} = -2 R^T \boldsymbol{n},
\quad
B = R^T R + \lambda D^T D.
\]
The same work derives a QUBO representation
\[
f_Q(\boldsymbol{x}) = \boldsymbol{x}^T Q \boldsymbol{x},
\]
implemented in QUnfold with classical mixed-integer solvers and D-Wave’s hybrid quantum solver [2602.22776].

In AO-based band unfolding, the corresponding central expression is a projection weight. After Löwdin orthogonalization, the primitive translation operator reduces to a permutation matrix, and the unfolding weight takes the compact form
\[
W^{\mathbf{k}}_{\mathbf{K} N}
=
\sum_n
\left|
\mathbf{F}_{\mathbf{k} n}^\dagger \, \mathbf{C}'_{\mathbf{K} N}
\right|^2.
\]
Here \(\mathbf{C}'_{\mathbf{K} N}\) are Löwdin-orthogonalized supercell eigenvectors and \(\mathbf{F}_{\mathbf{k} n}\) are eigenvectors of the primitive-cell translation operator in the orthogonalized representation [2506.21089]. The same source presents the thermally averaged spectral function as
\[
\langle A(\mathbf{k},E) \rangle_T
=
\lim_{I\to\infty}
\frac{1}{I}
\sum_{i=1}^I
A^{(i)}(\mathbf{k},E),
\]
with each configuration sampled from the canonical ensemble [2506.21089].

These two uses are mathematically distinct—one is inverse estimation under regularization, the other is projector-based spectral decomposition—but each formulates unfolding as extraction of latent structure from a compressed representation by means of an explicit objective or projector. A plausible implication is that in contemporary physics literature the term “unfolding” increasingly denotes a reconstruction map equipped with a quantitative weight or loss.

## 7. Conceptual commonalities and major distinctions

Across the supplied sources, unfolding is always an operation from a more compact or folded representation to a more explicit one, but the preserved object varies sharply. In geometry, the invariant is a connected planar piece with no overlaps [0509054]. In \(\lambda\)-letrec, the invariant is infinite unfolding semantics and its characterization by strong regularity [1610.05954]. In controlled type theory, the invariant is definitional equality under explicit unfolding conditions mediated by extension types [2210.05420]. In CHR, it is preservation of qualified answers, and under stated conditions also confluence and termination [0807.3979]. In lazy functional programming, it is adequacy with respect to operational semantics [1708.08003]. In HEP, it is statistical compatibility between \(R\boldsymbol{z}+\boldsymbol{\beta}\) and measured counts under regularization [2602.22776]. In band unfolding, it is spectral weight in the primitive-cell Brillouin zone [2506.21089]. In Origami, it is a recursion-scheme template in which generation and processing are decoupled [2406.01500].

A recurring misconception is that unfolding is always unrestricted inlining. The supplied literature contradicts that view. Grid vertex-unfolding requires gridding because some orthogonal polyhedra cannot be vertex-unfolded without it [0509054]. Origami fixes the recursion scheme and searches only over typed slots [2406.01500]. Controlled type theory makes definitions opaque by default and permits only local selective unfolding [2210.05420]. CHR safe rule replacement requires explicit syntactic and guard conditions [0807.3979]. Functional unfolding semantics restricts facts so that bodies and guards contain no user-defined function symbols [1708.08003]. HEP unfolding depends on regularization and discretization choices [2602.22776]. AO band unfolding depends on orthogonalization and translation-operator structure [2506.21089].

The term therefore does not name a single algorithmic pattern. It names a class of expansion operators whose technical content is determined by the structure being unfolded, the admissible transformation rules, and the semantic or geometric invariant that must be preserved.

Source: https://www.emergentmind.com/topics/unfolding-expressions