---
title: Partial-State Lenses in Bidirectional Transformations
url: https://www.emergentmind.com/topics/partial-state-lenses
type: topic
---

# Partial-State Lenses in Bidirectional Transformations

Partial-state lenses (ps-lenses) generalize classical bidirectional transformation frameworks by introducing domains of partially-specified states—i-posets—that capture user update intentions and provide compositional and mergeable semantics for concurrent view updates. Unlike traditional lenses that operate on fully specified sources and views presuming exact correspondence, ps-lenses encode the degree and direction of specification, enabling robust synchronization even in the presence of multiple, overlapping, or concurrent view modifications [2601.04573].

## 1. I-posets and Partial Specification

The semantic domain of ps-lenses is the i-poset \(P = (S, \le, I)\), where \(S\) is a set of "states," \(\le\) is a partial order capturing informational refinement, and \(I \subseteq \le\) is a reflexive subrelation denoting "identical updates." The key intuition is that \(s' \le s\) indicates \(s'\) is at least as informative as \(s\), while \((s', s) \in I\) further asserts that \(s'\) brings no new update relative to \(s\). This structure allows for encoding both traditional discrete states (\(S\) with equality, \(I = \{(s, s)\}\)), powerset structures (\((2^X, \supseteq, \supseteq)\)), and edit-oriented update pairs (\(S \times U\), with \(U\) a poset of edits).

This abstraction supports domains where states or edits may be partially specified—crucial for expressing and merging user intentions across multiple views and updates.

## 2. Formalization of Partial-State Lenses

A partial-state lens \(\ell: P \Leftrightarrow Q\) between i-posets consists of two partial functions: \(\ell.\mathrm{get}: S \to V\) and \(\ell.\mathrm{put}: S \times V \rightharpoonup S\), generalizing the "get" and "put" operations of ordinary asymmetric lenses. The essential innovation is that partial specification percolates into both source and view, such that updates can be encoded as partial states themselves [2601.04573].

Well-behavedness for a ps-lens is captured by three generalized laws:

- **ps-consistency** (Generalizing PutGet): If putting a view \(v'\) into a source \(s\) yields a result no more informative than \(s'\), then \(s'\)'s view must be at least as informative as \(v'\).
- **ps-acceptability** (Generalizing GetPut): Inserting a view identical (in the sense of \(I\)) to \(\ell.s\) back into \(s\) must yield a state identical to \(s\).
- **ps-stability** (Replacing PutPut): Round-tripping via "upgrade" and composite views generates a state that refines the original, closing under composition.

These laws permit compositional reasoning and express incremental update preservation using partial orders and identical update relations, rather than exactness.

## 3. Update Preservation, Intention Merging, and Synchronization

Key functionality of ps-lenses is representing and merging user update intentions. Each view update is a partial specification that can be compared and merged using the poset's ordering and a merge operator \(\oplus\) (sound for join, total on identical updates). Given two views \(v_1, v_2\) and respective intentions \(w_1, w_2\), their merge \(w_{\mathrm{merged}} = w_1 \oplus w_2\) concisely aggregates update intentions.

Synchronization is structured such that each intention \(w_i\) is preserved (in the sense of \(\le\)) in the resulting, merged view after propagation through the lens. This distributive, intention-preserving merge is critical for distributed and collaborative scenarios, resembling, but strictly generalizing, CRDT-style concurrency semantics.

## 4. Compositionality and Lens Construction

The partial-state lens framework extends the compositional structure of ordinary lenses to the partially-specified domain. Two fundamental combinators are formalized:

- **Sequential composition**: If \(\ell_1: P \Leftrightarrow Q\) and \(\ell_2: Q \Leftrightarrow R\) are well-behaved, so is their composite \(\ell_1 \fatsemi \ell_2: P \Leftrightarrow R\), preserving all three ps-laws.
- **Parallel (product) composition**: If \(\ell_1: P_1 \Leftrightarrow Q_1\) and \(\ell_2: P_2 \Leftrightarrow Q_2\), then the product lens \(\ell_1 \times \ell_2: P_1 \times P_2 \Leftrightarrow Q_1 \times Q_2\) is well-behaved, operating point-wise.

A significant result is that the laws of ps-lenses—ps-consistency, ps-acceptability, and ps-stability—are preserved under these composition operations, enabling modular construction of complex, intention-preserving bidirectional transformations.

## 5. Fundamental Theorems and Properties

Several meta-theoretical properties underpin the robustness of ps-lenses:

| Theorem                | Statement (condensed)                                                                     | Conditions                                                         |
|------------------------|-------------------------------------------------------------------------------------------|---------------------------------------------------------------------|
| Get-monotonicity       | \(s \le s' \implies \ell.\mathrm{get}(s) \le \ell.\mathrm{get}(s')\)                      | Weak well-behavedness (ps-consistency, ps-acceptability)           |
| View-stability         | \(\ell.\mathrm{get}(\ell.\mathrm{put}(s, \ell.\mathrm{get}(s))) = \ell.\mathrm{get}(s)\)  | Weak well-behavedness                                              |
| Put-determines-Get     | \(\ell.\mathrm{get}(s) = \max\{v \mid \exists s_0, s'.\; \ell.\mathrm{put}(s_0, v) = s' \le s\}\) | Weak well-behavedness                                   |
| Stability implication  | Well-behaved ps-lenses satisfy \(\ell.\mathrm{put}(s, \ell.\mathrm{get}(s)) = s\)         | Well-behavedness (all three laws)                                  |
| Composition preserves  | Compositions of well-behaved ps-lenses are well-behaved                                   | See sequential and product composition, above                      |

These theorems establish both the soundness and the expressiveness of the partial-state lens model, justifying the ability to reason about update propagation, merge, and synchronization in a partially-specified context [2601.04573].

## 6. Representative Examples

Partial-state lenses instantiate naturally in diverse scenarios:

- **Duplication lens**: \(\DUP: P \Leftrightarrow P \times P\) duplicates a source; "put" merges two partial specifications using \(\oplus\).
- **Ps-Initiator**: \(\mathit{init}: S \Leftrightarrow P\) applies partial updates (e.g., edits); "get" simply embeds, "put" applies edits in \(w\) to \(s\).
- **Filter lens**: Extracts a subset of data (e.g., "ongoing tasks") and propagates user modifications in the filtered view as partial specifications to the original domain. This enables concurrent edits from multiple views (e.g., "today's tasks" and "ongoing tasks") to be merged and faithfully reflected in the shared underlying source, with preservation guarantees.

In a composed scenario, such as two task-management views ("ongoing" and "today"), the overall lens
\[
\ell_\mathrm{task} = \DUP \fatsemi (\mathit{filter}_\mathrm{ongoing} \times \mathit{filter}_\mathrm{today}) \fatsemi \mathit{init}
\]
ensures that edits performed on either view—represented as partial specifications—are merged, yielding consistent synchronized states for all views and preserving every original update intention.

## 7. Significance and Scope

Partial-state lenses advance the bidirectional programming landscape by integrating compositionality, mergeability, and partial order semantics into the core framework. Their ability to encode and preserve user update intentions amidst concurrent and partially overlapping view updates enables fine-grained, consistent synchronization in collaborative and distributed systems. The formalization with i-posets and ps-laws demonstrates both modular expressiveness and precise control over update propagation, supporting both theoretical analysis and practical deployment in scenarios demanding robust multi-view consistency [2601.04573].

Source: https://www.emergentmind.com/topics/partial-state-lenses