Contextual Equivalence and Observable Behavior
Compare expressions by all well-typed enclosing contexts and use a small context to distinguish two behaviors.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 2
- Reading time
- 1 min
In this article2 chapters
A context contains a hole with a fixed type
Two expressions are contextually equivalent when putting either into any allowed closing context yields the same observations. The language must specify whether results, divergence, exceptions or output traces are observed. In a pure total integer fragment, replacing \(1+2\) by \(3\) preserves its value in every such context. A language that exposes additional effects can need a different relation.
An enclosing program can make a hidden difference visible
Consider two functions that both return zero but produce different logs. A context that calls the function once and observes output can distinguish them even though the returned integers agree. Conversely, proving equivalence by testing a few contexts is insufficient. A compositional proof can establish a relation preserved by the context rules. Operational semantics determines what the context actually observes. Advanced programming-language semantics relates such observations to mathematical denotations.[1][2]