# 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 $P$ be the referential transparent context, the Program, with $P\colon f \circ g$, where $f\colon Y \rightarrow Z$, $g \in Inj(X, Y)$, $f$ and $g$ are representing expressions.

if $\forall u,v \in Y: \exists x \in X: u=g(x)=v \land f(v) = f(y)$, then $g$ is referential transparent. Furthermore, it implies that $f \in Inj(Y, Z)$ since $\forall u,v \in Y: f(v) = f(v) \implies u=v$.

Referential Transparency, Definiteness and Unfoldability

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 $x \in \N, y \in \N$:

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);

• "A mode of containment φ is referentially transparent if, whenever an occurrence of a singular term $t$ is purely referential in a term or sentence $ψ(t)$, it is purely referential also in the containing term or sentence $φ(ψ(t))$." Quine: Word and Object, §30