Referential transparency


programming
An expression E is referentially transparent if any subexpression and its value (the result of evaluating it) can be interchanged without changing the value of E. This is not the case if the value of an expression depends on global state which can change value. The most common example of changing global state is assignment to a global variable. For example, if y is a global variable in:
f(x) return x+y;
g(z) a = f(1); y = y + z; return a + f(1);
function g has the “side-effect” that it alters the value of y. Since f’s result depends on y, the two calls to f(1) will return different results even though the argument is the same. Thus f is not referentially transparent. Changing the order of evaluation of the statements in g will change its result.
Pure functional languages achieve referential transparency by forbidding assignment to global variables. Each expression is a constant or a function application whose evaluation has no side-effect, it only returns a value and that value depends only on the definition of the function and the values of its arguments.
We could make f above referentially transparent by passing in y as an argument:
f(x, y) = x+y
Similarly, g would need to take y as an argument and return its new value as part of the result:
g(z, y) a = f(1, y); y’ = y+z; return (a + f(1, y’), y’);
Referentially transparent programs are more amenable to formal methods and easier to reason about because the meaning of an expression depends only on the meaning of its subexpressions and not on the order of evaluation or side-effects of other expressions.
We can stretch the concept of referential transparency to include input and output if we consider the whole program to be a function from its input to its output. The program as a whole is referentially transparent because it will always produce the same output when given the same input. This is stretching the concept because the program’s input may include what the user types, the content of certain files or even the time of day. If we do not consider global state like the contents of files as input, then writing to a file and reading what was written behaves just like assignment to a global variable. However, if we must consider the state of the universe as an input rather than global state then any deterministic system would be referentially transparent!
See also extensional equality, observational equivalence.
(1997-03-25)

Read Also:

  • Referer

    World-Wide Web A misspelling of “referrer” which somehow made it into the HTTP standard. A given web page’s referer (sic) is the URL of whatever web page contains the link that the user followed to the current page. Most browsers pass this information as part of a request. (1998-10-19)

  • Referrable

    verb (used with object), referred, referring. 1. to direct for information or anything required: He referred me to books on astrology. 2. to direct the attention or thoughts of: The asterisk refers the reader to a footnote. 3. to hand over or submit for information, consideration, decision, etc.: to refer the argument to arbitration. 4. […]

  • Referral

    noun 1. an act of referring; the state of being referred. 2. an instance of referring. 3. a person recommended to someone or for something.

  • Referred

    verb (used with object), referred, referring. 1. to direct for information or anything required: He referred me to books on astrology. 2. to direct the attention or thoughts of: The asterisk refers the reader to a footnote. 3. to hand over or submit for information, consideration, decision, etc.: to refer the argument to arbitration. 4. […]

  • Referred-pain

    noun, Pathology. 1. pain felt in an area remote from the site of origin. referred pain noun 1. (psychol) pain felt in the body at some place other than its actual place of origin referred pain re·ferred pain (rĭ-fûrd’) n. Pain that is felt in a part of the body at a distance from its […]


Disclaimer: Referential transparency definition / meaning should not be considered complete, up to date, and is not intended to be used in place of a visit, consultation, or advice of a legal, medical, or any other professional. All content on this website is for informational purposes only.