Referential Transparency (Computer Science)
If an expression can be substituted for a value without changing the program's computational result, the expression is referential transparent.
The expression needs to be pure in order to achieve Referential Transparency.
Informal Description
let be the referential transparent context, the Program, with , where , , and are representing expressions.
if , then is referential transparent. Furthermore, it implies that since .
A more formal introduction to this topic is available from Sondergaard and Sestoft in Referential Transparency, Definiteness and Unfoldability:
"By this, an operator is referentially transparent if it preserves applicability of Leibniz's law, or substitutivity of identity: the principle that any subexpression can be replaced by any other equal in value. "
Example
For :
function f (y) {
return y * y;
}
function g (x) {
return x + 1;
}
// f(?) = 64
// 64 = 8 * 8; 64 = 8 * 8; 8 = 7 + 1; 8 = g (7); -> ? = 8 || g(7)
f(g(7)) === f (8);
see also
"A mode of containment φ is referentially transparent if, whenever an occurrence of a singular term is purely referential in a term or sentence , it is purely referential also in the containing term or sentence ." Quine: Word and Object, §30