https://en.formulasearchengine.com/index.php?title=Real_analysis&feed=atom&action=historyReal analysis - Revision history2024-03-29T01:51:28ZRevision history for this page on the wikiMediaWiki 1.42.0-wmf.5https://en.formulasearchengine.com/index.php?title=Real_analysis&diff=284751&oldid=preven>Wcherowi: Reverted 3 edits by 99.231.166.88 (talk): Not a useful addition and not supported by citation. (TW)2015-01-13T04:14:26Z<p>Reverted 3 edits by <a href="/wiki/Special:Contributions/99.231.166.88" title="Special:Contributions/99.231.166.88">99.231.166.88</a> (<a href="/index.php?title=User_talk:99.231.166.88&action=edit&redlink=1" class="new" title="User talk:99.231.166.88 (page does not exist)">talk</a>): Not a useful addition and not supported by citation. (<a href="/index.php?title=WP:TW&action=edit&redlink=1" class="new" title="WP:TW (page does not exist)">TW</a>)</p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 05:14, 13 January 2015</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1">Line 1:</td>
<td colspan="2" class="diff-lineno">Line 1:</td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">{{Expert-subject|Computer science|date=August 2013|reason=disputed definition}}</del></div></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">Νothing </ins>to <ins style="font-weight: bold; text-decoration: none;">write </ins>about <ins style="font-weight: bold; text-decoration: none;">me </ins>at all.<<ins style="font-weight: bold; text-decoration: none;">br</ins>><ins style="font-weight: bold; text-decoration: none;">Hurгey Im here and </ins>a <ins style="font-weight: bold; text-decoration: none;">member </ins>of <ins style="font-weight: bold; text-decoration: none;">wmflabs</ins>.<ins style="font-weight: bold; text-decoration: none;">org</ins>.<<ins style="font-weight: bold; text-decoration: none;">br</ins>><ins style="font-weight: bold; text-decoration: none;">I really hope I</ins>'<ins style="font-weight: bold; text-decoration: none;">m useful </ins>in one <ins style="font-weight: bold; text-decoration: none;">way </ins>.<<ins style="font-weight: bold; text-decoration: none;">br</ins>><<ins style="font-weight: bold; text-decoration: none;">br</ins>><ins style="font-weight: bold; text-decoration: none;">Here </ins>is <ins style="font-weight: bold; text-decoration: none;">my site </ins>[http://<ins style="font-weight: bold; text-decoration: none;">21daysugardetoxpdf2</ins>.<ins style="font-weight: bold; text-decoration: none;">blogspot</ins>.<ins style="font-weight: bold; text-decoration: none;">com</ins>/ <ins style="font-weight: bold; text-decoration: none;">the 21 day sugar detox </ins>pdf]</div></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">{{unreferenced|date=February 2008}}</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> </div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">'''Referential transparency''' and '''referential opacity''' are properties of parts of [[computer program]]s. An [[expression (programming)|expression]] is said </del>to <del style="font-weight: bold; text-decoration: none;">be referentially transparent if it can be replaced with its [[Value (computer science)|value]] without changing the behavior of a program (in other words, yielding a program that has the same effects and output on the same input). The opposite term is referential opaqueness.</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> </div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">While in [[mathematics]] all function applications are referentially [[Transparency (human-computer interaction)|transparent]], in programming this is not always the case. The importance of referential transparency is that it allows the [[programmer]] and the [[compiler]] to reason </del>about <del style="font-weight: bold; text-decoration: none;">program behavior. This can help in proving [[correctness (computer science)|correctness]], simplifying an [[algorithm]], assisting in modifying code without breaking it, or [[optimization (computer science)|optimizing]] code by means of [[memoization]], [[common subexpression elimination]], [[lazy evaluation]], or [[parallelization]].</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> </div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">Referential transparency is one of the principles of [[functional programming]]; only referentially transparent functions can be memoized (transformed into equivalent functions which cache results). Some [[programming language]]s provide means to guarantee referential transparency.</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">Some functional programming languages enforce referential transparency for all functions.</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> </div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">As referential transparency requires the same results for a given set of inputs </del>at <del style="font-weight: bold; text-decoration: none;">any point in time, a referentially transparent expression is therefore [[Deterministic system (philosophy)|deterministic]].</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> </div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">== Examples and counterexamples ==</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">If </del>all <del style="font-weight: bold; text-decoration: none;">functions involved in the expression are [[pure function]]s, then the expression is referentially transparent</del>. <del style="font-weight: bold; text-decoration: none;"> Also, some impure functions can be included in the expression if their values are discarded and their [[side effect (computer science)|side effect]]s are insignificant.</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> </div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">Consider a function that returns the input from some source. In pseudocode, a call to this function might be </del><<del style="font-weight: bold; text-decoration: none;">code</del>><del style="font-weight: bold; text-decoration: none;">GetInput(Source)</code> where <code>Source</code> might identify </del>a <del style="font-weight: bold; text-decoration: none;">particular disc file, the [[computer keyboard|keyboard]], etc. Even with identical values </del>of <del style="font-weight: bold; text-decoration: none;"><code>Source</code>, the successive return values will be different</del>. <del style="font-weight: bold; text-decoration: none;">Therefore, function <code>GetInput()</code> is neither deterministic nor referentially transparent.</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> </div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">A more subtle example is that of a function that uses a [[global variable]] (or a dynamically [[scope (programming)|scope]]d variable, or a lexical [[closure (computer science)|closure]]) to help it compute its results</del>. <del style="font-weight: bold; text-decoration: none;"> Since this variable is not passed as a parameter but can be altered, the results of subsequent calls to the function can differ even if the parameters are identical. In pure [[functional programming]], [[destructive assignment]] is not allowed; thus, a function that uses global (or [[Dynamic scoping|dynamically scoped]]) variables may or may not be referentially transparent, depending on whether the global variables are immutable.</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> </div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">Arithmetic operations are referentially transparent: </del><<del style="font-weight: bold; text-decoration: none;">code>5*5</code> can be replaced by <code>25</code>, for instance. In fact, all functions in the mathematical sense are referentially transparent: <code>sin(x)</code> is transparent, since it will always give the same result for each particular <code>x</code>.</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> </div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">Assignments are not transparent. For instance, the [[C (programming language)|C]] expression <code>x = x + 1</code> changes the value assigned to the variable <code>x</code>. Assuming <code>x</code> initially has value <code>10</code>, two consecutive evaluations of the expression yield, respectively, <code>11</code> and <code>12</code>. Clearly, replacing <code>x = x + 1</code> with either <code>11</code> or <code>12</code> gives a program with different meaning, and so the expression is not referentially transparent. However, calling a function such as <code>int plusone(int x) {return x+1;}</code</del>> '<del style="font-weight: bold; text-decoration: none;">'is'' transparent, as it will not implicitly change the input x and thus has no such [[side effect (computer science)|side effects]].</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> </div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;"><code>today()</code> is not transparent, as if you evaluate it and replace it by its value (say, "Jan 1, 2001"), you don't get the same result as you will if you run it tomorrow. This is because it depends on a state (the time).</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> </div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">== Contrast to imperative programming ==</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> </div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">If the substitution of an expression with its value is valid only at a certain point </del>in <del style="font-weight: bold; text-decoration: none;">the execution of the program, then the expression is not referentially transparent. The definition and ordering of these [[sequence points]] are the theoretical foundation of [[imperative programming]], and part of the semantics of an imperative programming language.</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> </div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">However, because a referentially transparent expression can be evaluated at any time, it is not necessary to define sequence points nor any guarantee of the order of evaluation at all. Programming done without these considerations is called [[purely functional|purely functional programming]].</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> </div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">One advantage of writing code in a referentially transparent style is that given an intelligent compiler, [[static code analysis]] is easier and better [[code-improving transformation]]s are possible automatically. For example, when programming in C, there will be a performance penalty for including a call to an expensive function inside a loop, even if the function call could be moved outside of the loop without changing the results of the program. The programmer would be forced to perform manual [[code motion]] of the call, possibly at the expense of source code readability. However, if the compiler is able to determine that the function call is referentially transparent, it can perform this transformation automatically.</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> </div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">The primary disadvantage of languages that enforce referential transparency is that they make the expression of operations that naturally fit a sequence-of-steps imperative programming style more awkward and less concise. Such languages often incorporate mechanisms to make these tasks easier while retaining the purely functional quality of the language, such as [[definite clause grammar]]s and [[Monads in functional programming|monads]].</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> </div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">With referential transparency, no distinction is made or difference recognized between a reference to a thing and the corresponding thing itself. Without referential transparency, such difference can be easily made and utilized in programs.</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> </div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">==Another example==</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">As an example, let's use two functions, </del>one <del style="font-weight: bold; text-decoration: none;">which is referentially opaque, and the other which is referentially transparent:</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;"><pre></del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;"> globalValue = 0;</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> </div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;"> integer function rq(integer x)</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;"> begin</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;"> globalValue = globalValue + 1;</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;"> return x + globalValue;</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;"> end</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> </div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;"> integer function rt(integer x)</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;"> begin</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;"> return x + 1;</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;"> end</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;"></pre></del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">The function <code>rt</code> is referentially transparent, which means that <code>rt(x) = rt(y)</code> if <code>x = y</code></del>. <del style="font-weight: bold; text-decoration: none;">For instance, </del><<del style="font-weight: bold; text-decoration: none;">code</del>><del style="font-weight: bold; text-decoration: none;">rt(6) = 6 + 1 = 7, rt(4) = 4 + 1 = 5</del><<del style="font-weight: bold; text-decoration: none;">/code>, and so on. However, we can't say any such thing for <code>rq</code> because it uses a global variable that it modifies.</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> </div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">The referential opacity of <code>rq</code> makes reasoning about programs more difficult. For example, say we wish to reason about the following statement:</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> </div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;"> integer p = rq(x) + rq(y) * (rq(x) - rq(x));</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> </div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">One may be tempted to simplify this statement to:</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> </div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;"> integer p = rq(x) + rq(y) * (0);</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;"> integer p = rq(x) + 0;</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;"> integer p = rq(x);</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> </div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">However, this will not work for <code>rq()</code> because each occurrence of <code>rq(x)</code> evaluates to a different value. Remember that the return value of <code>rq</code</del>> is <del style="font-weight: bold; text-decoration: none;">based on a global value that isn't passed in and which gets modified on each call to <code>rq</code>. This means that mathematical identities such as <math>x - x = 0</math> no longer hold.</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> </div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">Such mathematical identities ''will'' hold for referentially transparent functions such as <code>rt</code>.</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> </div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">However, a more sophisticated analysis can be used to simplify the statement to:</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> </div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;"> integer a = globalValue; integer p = x + a + 1 + (y + a + 2) * (x + a + 3 - (x + a + 4)); globalValue = globalValue + 4;</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;"> integer a = globalValue; integer p = x + a + 1 + (y + a + 2) * (x + a + 3 - x - a - 4)); globalValue = globalValue + 4;</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;"> integer a = globalValue; integer p = x + a + 1 + (y + a + 2) * -1; globalValue = globalValue + 4;</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;"> integer a = globalValue; integer p = x + a + 1 - y - a - 2; globalValue = globalValue + 4;</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;"> integer p = x - y - 1; globalValue = globalValue + 4;</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> </div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">This takes more steps and requires a degree of insight into the code infeasible for compiler optimization.</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> </div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">Therefore, referential transparency allows us to reason about our code which will lead to more robust programs, the possibility of finding bugs that we couldn't hope to find by testing, and the possibility of seeing opportunities for </del>[<del style="font-weight: bold; text-decoration: none;">[optimization (computer science)|optimization]].</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> </div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">==See also==</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">* [[Idempotence#Computer_science_meaning|Idempotence in computer science]]</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> </div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">==References==</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">*{{cite journal|first1=Harald |last1=Søndergaard |first2=Peter |last2=Sestoft|year=1990|title=Referential transparency, definiteness and unfoldability|journal=Acta Informatica|volume=27|issue=6|pages=505–517|url=</del>http://<del style="font-weight: bold; text-decoration: none;">www</del>.<del style="font-weight: bold; text-decoration: none;">itu</del>.<del style="font-weight: bold; text-decoration: none;">dk</del>/<del style="font-weight: bold; text-decoration: none;">people/sestoft/papers/SondergaardSestoft1990.</del>pdf<del style="font-weight: bold; text-decoration: none;">}}</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> </div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">*{{cite book|last=Davie|first=Antony|title=An Introduction to Functional Programming Systems Using Haskell|year=1992|publisher=Cambridge University Press|location=New York|isbn=0-521-27724-8|pages=290}}</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> </div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">[[Category:Programming language theory]</del>]</div></td><td colspan="2" class="diff-side-added"></td></tr>
</table>en>Wcherowihttps://en.formulasearchengine.com/index.php?title=Real_analysis&diff=915&oldid=preven>Deville: /* Differentiation */ expand2014-02-03T14:11:20Z<p><span dir="auto"><span class="autocomment">Differentiation: </span> expand</span></p>
<p><b>New page</b></p><div>{{Expert-subject|Computer science|date=August 2013|reason=disputed definition}}<br />
{{unreferenced|date=February 2008}}<br />
<br />
'''Referential transparency''' and '''referential opacity''' are properties of parts of [[computer program]]s. An [[expression (programming)|expression]] is said to be referentially transparent if it can be replaced with its [[Value (computer science)|value]] without changing the behavior of a program (in other words, yielding a program that has the same effects and output on the same input). The opposite term is referential opaqueness.<br />
<br />
While in [[mathematics]] all function applications are referentially [[Transparency (human-computer interaction)|transparent]], in programming this is not always the case. The importance of referential transparency is that it allows the [[programmer]] and the [[compiler]] to reason about program behavior. This can help in proving [[correctness (computer science)|correctness]], simplifying an [[algorithm]], assisting in modifying code without breaking it, or [[optimization (computer science)|optimizing]] code by means of [[memoization]], [[common subexpression elimination]], [[lazy evaluation]], or [[parallelization]].<br />
<br />
Referential transparency is one of the principles of [[functional programming]]; only referentially transparent functions can be memoized (transformed into equivalent functions which cache results). Some [[programming language]]s provide means to guarantee referential transparency.<br />
Some functional programming languages enforce referential transparency for all functions.<br />
<br />
As referential transparency requires the same results for a given set of inputs at any point in time, a referentially transparent expression is therefore [[Deterministic system (philosophy)|deterministic]].<br />
<br />
== Examples and counterexamples ==<br />
If all functions involved in the expression are [[pure function]]s, then the expression is referentially transparent. Also, some impure functions can be included in the expression if their values are discarded and their [[side effect (computer science)|side effect]]s are insignificant.<br />
<br />
Consider a function that returns the input from some source. In pseudocode, a call to this function might be <code>GetInput(Source)</code> where <code>Source</code> might identify a particular disc file, the [[computer keyboard|keyboard]], etc. Even with identical values of <code>Source</code>, the successive return values will be different. Therefore, function <code>GetInput()</code> is neither deterministic nor referentially transparent.<br />
<br />
A more subtle example is that of a function that uses a [[global variable]] (or a dynamically [[scope (programming)|scope]]d variable, or a lexical [[closure (computer science)|closure]]) to help it compute its results. Since this variable is not passed as a parameter but can be altered, the results of subsequent calls to the function can differ even if the parameters are identical. In pure [[functional programming]], [[destructive assignment]] is not allowed; thus, a function that uses global (or [[Dynamic scoping|dynamically scoped]]) variables may or may not be referentially transparent, depending on whether the global variables are immutable.<br />
<br />
Arithmetic operations are referentially transparent: <code>5*5</code> can be replaced by <code>25</code>, for instance. In fact, all functions in the mathematical sense are referentially transparent: <code>sin(x)</code> is transparent, since it will always give the same result for each particular <code>x</code>.<br />
<br />
Assignments are not transparent. For instance, the [[C (programming language)|C]] expression <code>x = x + 1</code> changes the value assigned to the variable <code>x</code>. Assuming <code>x</code> initially has value <code>10</code>, two consecutive evaluations of the expression yield, respectively, <code>11</code> and <code>12</code>. Clearly, replacing <code>x = x + 1</code> with either <code>11</code> or <code>12</code> gives a program with different meaning, and so the expression is not referentially transparent. However, calling a function such as <code>int plusone(int x) {return x+1;}</code> ''is'' transparent, as it will not implicitly change the input x and thus has no such [[side effect (computer science)|side effects]].<br />
<br />
<code>today()</code> is not transparent, as if you evaluate it and replace it by its value (say, "Jan 1, 2001"), you don't get the same result as you will if you run it tomorrow. This is because it depends on a state (the time).<br />
<br />
== Contrast to imperative programming ==<br />
<br />
If the substitution of an expression with its value is valid only at a certain point in the execution of the program, then the expression is not referentially transparent. The definition and ordering of these [[sequence points]] are the theoretical foundation of [[imperative programming]], and part of the semantics of an imperative programming language.<br />
<br />
However, because a referentially transparent expression can be evaluated at any time, it is not necessary to define sequence points nor any guarantee of the order of evaluation at all. Programming done without these considerations is called [[purely functional|purely functional programming]].<br />
<br />
One advantage of writing code in a referentially transparent style is that given an intelligent compiler, [[static code analysis]] is easier and better [[code-improving transformation]]s are possible automatically. For example, when programming in C, there will be a performance penalty for including a call to an expensive function inside a loop, even if the function call could be moved outside of the loop without changing the results of the program. The programmer would be forced to perform manual [[code motion]] of the call, possibly at the expense of source code readability. However, if the compiler is able to determine that the function call is referentially transparent, it can perform this transformation automatically.<br />
<br />
The primary disadvantage of languages that enforce referential transparency is that they make the expression of operations that naturally fit a sequence-of-steps imperative programming style more awkward and less concise. Such languages often incorporate mechanisms to make these tasks easier while retaining the purely functional quality of the language, such as [[definite clause grammar]]s and [[Monads in functional programming|monads]].<br />
<br />
With referential transparency, no distinction is made or difference recognized between a reference to a thing and the corresponding thing itself. Without referential transparency, such difference can be easily made and utilized in programs.<br />
<br />
==Another example==<br />
As an example, let's use two functions, one which is referentially opaque, and the other which is referentially transparent:<br />
<pre><br />
globalValue = 0;<br />
<br />
integer function rq(integer x)<br />
begin<br />
globalValue = globalValue + 1;<br />
return x + globalValue;<br />
end<br />
<br />
integer function rt(integer x)<br />
begin<br />
return x + 1;<br />
end<br />
</pre><br />
The function <code>rt</code> is referentially transparent, which means that <code>rt(x) = rt(y)</code> if <code>x = y</code>. For instance, <code>rt(6) = 6 + 1 = 7, rt(4) = 4 + 1 = 5</code>, and so on. However, we can't say any such thing for <code>rq</code> because it uses a global variable that it modifies.<br />
<br />
The referential opacity of <code>rq</code> makes reasoning about programs more difficult. For example, say we wish to reason about the following statement:<br />
<br />
integer p = rq(x) + rq(y) * (rq(x) - rq(x));<br />
<br />
One may be tempted to simplify this statement to:<br />
<br />
integer p = rq(x) + rq(y) * (0);<br />
integer p = rq(x) + 0;<br />
integer p = rq(x);<br />
<br />
However, this will not work for <code>rq()</code> because each occurrence of <code>rq(x)</code> evaluates to a different value. Remember that the return value of <code>rq</code> is based on a global value that isn't passed in and which gets modified on each call to <code>rq</code>. This means that mathematical identities such as <math>x - x = 0</math> no longer hold.<br />
<br />
Such mathematical identities ''will'' hold for referentially transparent functions such as <code>rt</code>.<br />
<br />
However, a more sophisticated analysis can be used to simplify the statement to:<br />
<br />
integer a = globalValue; integer p = x + a + 1 + (y + a + 2) * (x + a + 3 - (x + a + 4)); globalValue = globalValue + 4;<br />
integer a = globalValue; integer p = x + a + 1 + (y + a + 2) * (x + a + 3 - x - a - 4)); globalValue = globalValue + 4;<br />
integer a = globalValue; integer p = x + a + 1 + (y + a + 2) * -1; globalValue = globalValue + 4;<br />
integer a = globalValue; integer p = x + a + 1 - y - a - 2; globalValue = globalValue + 4;<br />
integer p = x - y - 1; globalValue = globalValue + 4;<br />
<br />
This takes more steps and requires a degree of insight into the code infeasible for compiler optimization.<br />
<br />
Therefore, referential transparency allows us to reason about our code which will lead to more robust programs, the possibility of finding bugs that we couldn't hope to find by testing, and the possibility of seeing opportunities for [[optimization (computer science)|optimization]].<br />
<br />
==See also==<br />
* [[Idempotence#Computer_science_meaning|Idempotence in computer science]]<br />
<br />
==References==<br />
*{{cite journal|first1=Harald |last1=Søndergaard |first2=Peter |last2=Sestoft|year=1990|title=Referential transparency, definiteness and unfoldability|journal=Acta Informatica|volume=27|issue=6|pages=505–517|url=http://www.itu.dk/people/sestoft/papers/SondergaardSestoft1990.pdf}}<br />
<br />
*{{cite book|last=Davie|first=Antony|title=An Introduction to Functional Programming Systems Using Haskell|year=1992|publisher=Cambridge University Press|location=New York|isbn=0-521-27724-8|pages=290}}<br />
<br />
[[Category:Programming language theory]]</div>en>Deville