Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Referential transparency
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{short description|Whether a program behaves differently if expressions and their values are interchanged}} {{About|referential transparency in programming language theory|its use in linguistics and philosophy|Opaque context}} In [[analytic philosophy]] and [[computer science]], '''referential transparency''' and '''referential opacity''' are properties of linguistic constructions,{{efn|A linguistic construction (also called mode of containment, context, or operator) is an expression with holes.}} and by extension of languages. A linguistic construction is called ''referentially transparent'' when for any expression built from it, [[Rewriting|replacing]] a subexpression with another one that [[Denotation|denotes]] the same value{{efn|Here a value is the denotation (also called meaning, object, or referent) of an expression, not the [[Expression (computer science)|result]] of the evaluation process.}} does not change the value of the expression.<ref name="quine1960">{{cite book |last=Quine |first=Willard Van Orman |author-link=Willard Van Orman Quine |date=1960 |title=Word and Object |edition=1st |url=https://archive.org/details/in.ernet.dli.2015.529086 |location=Cambridge, Massachusetts |publisher=MIT Press |page=144 |isbn=978-0-262-17001-7}}</ref><ref name="strachey1967">{{cite tech report |last1=Strachey |first1=Christopher |date=1967 |title=Fundamental Concepts in Programming Languages |url= |institution=Lecture notes for the International Summer School in Computer Programming at Copenhagen |number=}} Also: {{cite journal |last1=Strachey |first1=Christopher |date=2000 |title=Fundamental Concepts in Programming Languages |url=https://link.springer.com/article/10.1023%2FA%3A1010000313106 |journal=Higher-Order and Symbolic Computation |volume=13 |issue=1–2 |pages=11–49 |doi=10.1023/A:1010000313106 |s2cid=14124601 |doi-access=|url-access=subscription }}</ref> 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.<ref name="whitehead1927">{{cite book |last1=Whitehead |first1=Alfred North |last2=Russell |first2=Bertrand |author-link1=Alfred North Whitehead |author-link2=Bertrand Russell |date=1927 |title=Principia Mathematica |volume=1 |edition=2nd |url=https://archive.org/details/dli.ernet.247278 |location=Cambridge |publisher=Cambridge University Press |page=665 |isbn=978-0-521-06791-1}}</ref> 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 language]]s and [[imperative language]]s 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 (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]]. == History == The concept originated in [[Alfred North Whitehead]] and [[Bertrand Russell]]'s ''[[Principia Mathematica]]'' (1910–1913):<ref name="whitehead1927" /> <blockquote> A proposition as the vehicle of truth or falsehood is a particular occurrence, while a proposition considered factually is a class of similar occurrences. It is the proposition considered factually that occurs in such statements as “''A'' believes ''p''“ and “''p'' is about ''A''.” Of course it is possible to make statements about the particular fact “Socrates is Greek.” We may say how many centimetres long it is; we may say it is black; and so on. But these are not the statements that a philosopher or logician is tempted to make. When an assertion occurs, it is made by means of a particular fact, which is an instance of the proposition asserted. But this particular fact is, so to speak, “transparent”; nothing is said about it, but by means of it something is said about something else. It is this “transparent” quality that belongs to propositions as they occur in truth-functions. This belongs to ''p'' when ''p'' is asserted, but not when we say “''p'' is true.” </blockquote> It was adopted in analytic philosophy in [[Willard Van Orman Quine]]'s ''[[Word and Object]]'' (1960):<ref name="quine1960" /> <blockquote> When a singular term is used in a sentence purely to specify its object, and the sentence is true of the object, then certainly the sentence will stay true when any other singular term is substituted that designates the same object. Here we have a criterion for what may be called ''purely referential position'': the position must be subject to the ''substitutivity of identity''. […] Referential transparency has to do with constructions (§ 11); modes of containment, more specifically, of singular terms or sentences in singular terms or sentences. I call a mode of containment {{mvar|φ}} referentially transparent if, whenever an occurrence of a singular term {{mvar|t}} is purely referential in a term or sentence {{math|''ψ''(''t'')}}, it is purely referential also in the containing term or sentence {{math|''φ''(''ψ''(''t''))}}. </blockquote> The term appeared in its contemporary computer science usage in the discussion of [[Variable (computer science)|variable]]s in [[programming language]]s in [[Christopher Strachey]]'s seminal set of lecture notes ''[[Fundamental Concepts in Programming Languages]]'' (1967):<ref name="strachey1967" /> <blockquote> One of the most useful properties of expressions is that called by Quine [4] ''referential transparency''. In essence this means that if we wish to find the value of an expression which contains a sub-expression, the only thing we need to know about the sub-expression is its value. Any other features of the sub-expression, such as its internal structure, the number and nature of its components, the order in which they are evaluated or the colour of the ink in which they are written, are irrelevant to the value of the main expression. </blockquote> == Formal definitions == There are three fundamental properties concerning substitutivity in formal languages: referential transparency, definiteness, and unfoldability.<ref name="sondergaard1990">{{cite journal |last1=Søndergaard |first1=Harald |last2=Sestoft |first2=Peter |date=1990 |title=Referential Transparency, Definiteness and Unfoldability |url=http://www.itu.dk/people/sestoft/papers/SondergaardSestoft1990.pdf |journal=Acta Informatica |volume=27 |issue=6 |pages=505–517 |doi=10.1007/bf00277387}}</ref> Let’s denote syntactic equivalence with ≡ and semantic equivalence with =. === Referential transparency === A ''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 {{math|(+ (∗ ''e''<sub>1</sub> ''e''<sub>1</sub>) (∗ ''e''<sub>2</sub> ''e''<sub>2</sub>))}} is the place occupied by the first occurrence of {{math|{{var|e}}<sub>2</sub>}}. Expression {{mvar|e}} ''with'' expression {{mvar|e′}} ''inserted at'' position {{mvar|p}} is denoted by {{math|''e''[''e′''/''p'']}} and defined by : {{math|''e''[''e′''/ε] ≡ ''e′''}} : {{math|''e''[''e′''/''i''.''p''] ≡ <Ω ''e''<sub>1</sub> … ''e''<sub>''i''</sub>[''e′''/''p''] … ''e''<sub>''n''</sub>>}} if {{math|''e'' ≡ <Ω ''e''<sub>1</sub> … ''e''<sub>''i''</sub> … ''e''<sub>''n''</sub>>}} else undefined, for all operators {{math|Ω}} and expressions {{math|{{var|e}}<sub>1</sub>, …, {{var|e}}<sub>{{var|n}}</sub>}}. ''Example.'' — If {{math|''e'' ≡ (+ (∗ ''e''<sub>1</sub> ''e''<sub>1</sub>) (∗ ''e''<sub>2</sub> ''e''<sub>2</sub>))}} then {{math|''e''[''e''<sub>3</sub>/2.1] ≡ (+ (∗ ''e''<sub>1</sub> ''e''<sub>1</sub>) (∗ ''e''<sub>3</sub> ''e''<sub>2</sub>))}}. Position {{mvar|p}} is ''purely referential'' in expression {{mvar|e}} is defined by : {{math|1=''e''<sub>1</sub> = ''e''<sub>2</sub>}} implies {{math|1=''e''[''e''<sub>1</sub>/''p''] = ''e''[''e''<sub>2</sub>/''p'']}}, for all expressions {{math|{{var|e}}<sub>1</sub>, {{var|e}}<sub>2</sub>}}. In other words, a position is purely referential in an expression if and only if it is subject to the substitutivity of equals. {{mvar|ε}} is purely referential in all expressions. Operator {{math|Ω}} is ''referentially transparent'' in place {{mvar|i}} is defined by : {{mvar|p}} is purely referential in {{mvar|e<sub>''i''</sub>}} implies {{math|''i''.''p''}} is purely referential in {{math|''e'' ≡ <Ω ''e''<sub>1</sub> … ''e''<sub>''i''</sub> … ''e''<sub>''n''</sub>>}}, for all positions {{mvar|p}} and expressions {{math|{{var|e}}<sub>1</sub>, …, {{var|e}}<sub>{{var|n}}</sub>}}. Otherwise {{math|Ω}} is ''referentially opaque'' in place {{mvar|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: : ''She lives in London.'' 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: : ''‘London’ contains six letters.'' 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: : ''‘London’ refers to the largest city of the United Kingdom.'' 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. === Definiteness === A formal language is ''definite'' is defined by all the occurrences of a variable within its scope denote the same value. ''Example.'' — Mathematics is definite: : {{math|3''x''<sup>2</sup> + 2''x'' + 17}}. Indeed, the two occurrences of {{mvar|x}} denote the same value. === Unfoldability === A formal language is ''unfoldable'' is defined by all expressions are [[Lambda calculus|β-reducible]]. ''Example.'' — The [[lambda calculus]] is unfoldable: : {{math|((λ''x''.''x'' + 1) 3)}}. Indeed, {{math|1=((λ''x''.''x'' + 1) 3) = (''x'' + 1)[3/''x'']}}. === Relations between the properties === Referential 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 also == * [[Liskov substitution principle]] * [[Rewrite rule]] ==Notes== {{notelist}} == References == {{reflist}} == External links == * http://userpage.fu-berlin.de/~ram/pub/pub_jf47ht81Ht/referential_transparency * https://stackoverflow.com/a/9859966/655289 by [http://www.cs.bham.ac.uk/~udr/ Prof. Uday Reddy] (University of Birmingham) * http://okmij.org/ftp/Computation/PrincipiaMathematica.txt [[Category:Programming language theory]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:About
(
edit
)
Template:Cite book
(
edit
)
Template:Cite journal
(
edit
)
Template:Cite tech report
(
edit
)
Template:Efn
(
edit
)
Template:Math
(
edit
)
Template:Mvar
(
edit
)
Template:Notelist
(
edit
)
Template:Reflist
(
edit
)
Template:Short description
(
edit
)