Referential transparencyIn analytic philosophy and computer science, referential transparency and referential opacity are properties of linguistic constructions,[a] and by extension of languages. A linguistic construction is called referentially transparent when for any expression built from it, replacing a subexpression with another one that denotes the same value[b] does not change the value of the expression.[1][2] Otherwise, it is called referentially opaque. Each expression built from a referentially opaque linguistic construction states something about a subexpression, whereas each expression built from a referentially transparent linguistic construction states something not about a subexpression, meaning that the subexpressions are ‘transparent’ to the expression, acting merely as ‘references’ to something else.[3] For example, the linguistic construction ‘_ was wise’ is referentially transparent (e.g., Socrates was wise is equivalent to The founder of Western philosophy was wise) but ‘_ said _’ is referentially opaque (e.g., Xenophon said ‘Socrates was wise’ is not equivalent to Xenophon said ‘The founder of Western philosophy was wise’). Referential transparency, in programming languages, depends on semantic equivalences among denotations of expressions, or on contextual equivalence of expressions themselves. That is, referential transparency depends on the semantics of the language. So, both declarative languages and imperative languages can have referentially transparent positions, referentially opaque positions, or (usually) both, according to the semantics they are given. The importance of referentially transparent positions is that they allow the programmer and the compiler to reason about program behavior as a rewrite system at those positions. This can help in proving correctness, simplifying an algorithm, assisting in modifying code without breaking it, or optimizing code by means of memoization, common subexpression elimination, lazy evaluation, or parallelization. HistoryThe concept originated in Alfred North Whitehead and Bertrand Russell's Principia Mathematica (1910–1913):[3]
It was adopted in analytic philosophy in Willard Van Orman Quine's Word and Object (1960):[1]
The term appeared in its contemporary computer science usage in the discussion of variables in programming languages in Christopher Strachey's seminal set of lecture notes Fundamental Concepts in Programming Languages (1967):[2]
Formal definitionsThere are three fundamental properties concerning substitutivity in formal languages: referential transparency, definiteness, and unfoldability.[4] Let’s denote syntactic equivalence with ≡ and semantic equivalence with =. Referential transparencyA position is defined by a sequence of natural numbers. The empty sequence is denoted by ε and the sequence constructor by ‘.’. Example. — Position 2.1 in the expression (+ (∗ e1 e1) (∗ e2 e2)) is the place occupied by the first occurrence of e2. Expression e with expression e′ inserted at position p is denoted by e[e′/p] and defined by
Example. — If e ≡ (+ (∗ e1 e1) (∗ e2 e2)) then e[e3/2.1] ≡ (+ (∗ e1 e1) (∗ e3 e2)). Position p is purely referential in expression e is defined by
In other words, a position is purely referential in an expression if and only if it is subject to the substitutivity of equals. ε is purely referential in all expressions. Operator Ω is referentially transparent in place i is defined by
Otherwise Ω is referentially opaque in place i. An operator is referentially transparent is defined by it is referentially transparent in all places. Otherwise it is referentially opaque. A formal language is referentially transparent is defined by all its operators are referentially transparent. Otherwise it is referentially opaque. Example. — The ‘_ lives in _’ operator is referentially transparent:
Indeed, the second position is purely referential in the assertion because substituting The capital of the United Kingdom for London does not change the value of the assertion. The first position is also purely referential for the same substitutivity reason. Example. — The ‘_ contains _’ and quote operators are referentially opaque:
Indeed, the first position is not purely referential in the statement because substituting The capital of the United Kingdom for London changes the value of the statement and the quotation. So in the first position, the ‘_ contains _’ and quote operators destroy the relation between an expression and the value that it denotes. Example. — The ‘_ refers to _’ operator is referentially transparent, despite the referential opacity of the quote operator:
Indeed, the first position is purely referential in the statement, though it is not in the quotation, because substituting The capital of the United Kingdom for London does not change the value of the statement. So in the first position, the ‘_ refers to _’ operator restores the relation between an expression and the value that it denotes. The second position is also purely referential for the same substitutivity reason. DefinitenessA formal language is definite is defined by all the occurrences of a variable within its scope denote the same value. Example. — Mathematics is definite:
Indeed, the two occurrences of x denote the same value. UnfoldabilityA formal language is unfoldable is defined by all expressions are β-reducible. Example. — The lambda calculus is unfoldable:
Indeed, ((λx.x + 1) 3) = (x + 1)[3/x]. Relations between the propertiesReferential transparency, definiteness, and unfoldability are independent. Definiteness implies unfoldability only for deterministic languages. Non-deterministic languages cannot have definiteness and unfoldability at the same time. See alsoNotesReferences
External links |