<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://en.formulasearchengine.com/index.php?action=history&amp;feed=atom&amp;title=Wind</id>
	<title>Wind - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://en.formulasearchengine.com/index.php?action=history&amp;feed=atom&amp;title=Wind"/>
	<link rel="alternate" type="text/html" href="https://en.formulasearchengine.com/index.php?title=Wind&amp;action=history"/>
	<updated>2026-05-27T05:19:26Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.0-wmf.28</generator>
	<entry>
		<id>https://en.formulasearchengine.com/index.php?title=Wind&amp;diff=21591&amp;oldid=prev</id>
		<title>en&gt;LujViton: /* External links */ broken link replaced with new</title>
		<link rel="alternate" type="text/html" href="https://en.formulasearchengine.com/index.php?title=Wind&amp;diff=21591&amp;oldid=prev"/>
		<updated>2014-01-30T21:48:59Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;External links: &lt;/span&gt; broken link replaced with new&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;In [[computer science]], &amp;#039;&amp;#039;&amp;#039;Scott encoding&amp;#039;&amp;#039;&amp;#039; is a way to represent [[Recursive data type|(recursive) data type]]s in the [[lambda calculus]].  [[Church encoding]] performs a similar function.  The data and operators form a mathematical structure which is [[embedding|embedded]] in the lambda calculus.&lt;br /&gt;
&lt;br /&gt;
Where as Church encoding starts with representations of the basic data types, and builds up from it, Scott encoding starts from the simplest method to compose [[algebraic data types]].&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Mogensen–Scott encoding&amp;#039;&amp;#039;&amp;#039; extends and slightly modifies Scott encoding by applying the encoding to [[Metaprogramming]].  This encoding allows the representation of [[untyped lambda calculus|lambda calculus]] terms, as data, to be operated on by a meta program.&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
&lt;br /&gt;
Scott encoding appears first in a set of unpublished lecture notes by [[Dana Scott]]. [[Torben Mogensen]] later extended Scott encoding for the encoding of Lambda terms as data. &amp;lt;ref&amp;gt; &lt;br /&gt;
{{ cite journal|&lt;br /&gt;
last=Mogensen|&lt;br /&gt;
first=Torben|&lt;br /&gt;
title=Efficient Self-Interpretation in Lambda Calculus|&lt;br /&gt;
journal=Journal of Functional Programming|&lt;br /&gt;
year=1994|&lt;br /&gt;
volume=2|&lt;br /&gt;
pages=345-364}}&lt;br /&gt;
&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Discussion==&lt;br /&gt;
&lt;br /&gt;
Lambda calculus allows data to be stored as [[Parameter (computer programming)|parameters]] to a function that does not yet have all the parameters required for application.  For example,&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;math&amp;gt; ((\lambda x_1 \ldots x_n.\lambda c.c\ x_1 \ldots x_n)\ v_1 \ldots v_n)\ f &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
May be thought of as a record or struct where the fields &amp;lt;math&amp;gt; x_1 \ldots x_n &amp;lt;/math&amp;gt; have been initialized with the values &amp;lt;math&amp;gt; v_1 \ldots v_n &amp;lt;/math&amp;gt;.  These values may then be accessed by applying the term to a function &amp;#039;&amp;#039;f&amp;#039;&amp;#039;.  This reduces to,&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;math&amp;gt; f\ v_1 \ldots v_n &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;c&amp;#039;&amp;#039; may represent a constructor for an algebraic data type in functional languages such as [[Haskell (programming language)|Haskell]].  Now suppose there &amp;#039;&amp;#039;N&amp;#039;&amp;#039; constructors, each with &amp;lt;math&amp;gt;A_i&amp;lt;/math&amp;gt; arguments;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Constructor !! Given arguments !! Result&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;math&amp;gt; ((\lambda x_1 \ldots x_{A_1}.\lambda c_1 \ldots c_N.c_1\ x_1 \ldots x_{A_1})\ v_1 \ldots v_{A_1}) &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; f_1 \ldots f_N &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; f_1\ v_1 \ldots v_{A_1} &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;math&amp;gt; ((\lambda x_1 \ldots x_{A_1}.\lambda c_1 \ldots c_N.c_2\ x_1 \ldots x_{A_2})\ v_1 \ldots v_{A_2}) &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; f_1 \ldots f_N &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; f_2\ v_1 \ldots v_{A_2} &amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| colspan=&amp;#039;3&amp;#039;  align=&amp;#039;center&amp;#039; style=&amp;#039;border-left: 1px solid white; border-right: 1px solid white&amp;#039; | ...&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;math&amp;gt; ((\lambda x_1 \ldots x_{A_N}.\lambda c_1 \ldots c_N.c_N\ x_1 \ldots x_{A_N})\ v_1 \ldots v_{A_N}) &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; f_1 \ldots f_N &amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt; f_N\ v_1 \ldots v_{A_1} &amp;lt;/math&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Each constructor selects a different function from the function parameters &amp;lt;math&amp;gt; f_1 \ldots f_N &amp;lt;/math&amp;gt;. This provides branching in the process flow, based on the constructor.    Each constructor may have a different [[arity]] (number of parameters).  If the constructors have no parameters then the set of constructors acts like an &amp;#039;&amp;#039;enum&amp;#039;&amp;#039;; a type with a fixed number of values.  If the constructors have parameters, recursive data structures may be constructed.&lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
Let &amp;#039;&amp;#039;D&amp;#039;&amp;#039; be a datatype with &amp;#039;&amp;#039;N&amp;#039;&amp;#039; [[Algebraic data type|constructors]], &amp;lt;math&amp;gt;\{c_i\}_{i=1}^N&amp;lt;/math&amp;gt;, such that constructor &amp;lt;math&amp;gt;c_i&amp;lt;/math&amp;gt; has [[arity]] &amp;lt;math&amp;gt;A_i&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Scott encoding===&lt;br /&gt;
&lt;br /&gt;
The Scott encoding of constructor &amp;lt;math&amp;gt;c_i&amp;lt;/math&amp;gt; of the data type &amp;#039;&amp;#039;D&amp;#039;&amp;#039; is&lt;br /&gt;
: &amp;lt;math&amp;gt;\lambda x_1 \ldots x_{A_i} . \lambda c_1 \ldots c_N . c_i\ x_1 \ldots x_{A_i}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Mogensen–Scott encoding===&lt;br /&gt;
&lt;br /&gt;
Mogensen extends Scott encoding to encode any untyped lambda term as data.  This allows a lambda term to be represented as data, within a Lambda calculus [[Metaprogramming|meta program]].  The meta function &amp;#039;&amp;#039;mse&amp;#039;&amp;#039; converts a lambda term into the corresponding data representation of the lambda term;&lt;br /&gt;
:&amp;lt;math&amp;gt;\begin{array}{rcl}&lt;br /&gt;
\operatorname{mse}[x] &amp;amp; = &amp;amp; \lambda a, b, c.a\ x \\&lt;br /&gt;
\ \operatorname{mse}[M\ N] &amp;amp; = &amp;amp; \lambda a, b, c.b\ \operatorname{mse}[M]\ \operatorname{mse}[N] \\&lt;br /&gt;
\ \operatorname{mse}[\lambda x . M] &amp;amp; = &amp;amp; \lambda a, b, c.c\ (\lambda x.\operatorname{mse}[M]) \\&lt;br /&gt;
\end{array}&amp;lt;/math&amp;gt;&amp;lt;!-- &amp;quot;\ &amp;quot; to work around some WP weirdness -- MarSch. (Actually, that is not WP-specific: LaTeX \\ takes an optional argument.) --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;lambda term&amp;quot; is represented as a [[tagged union]] with three cases:&lt;br /&gt;
* Constructor &amp;#039;&amp;#039;a&amp;#039;&amp;#039; - a variable ([[Arity|arity]] 1, not recursive)&lt;br /&gt;
* Constructor &amp;#039;&amp;#039;b&amp;#039;&amp;#039; - function application (arity 2, recursive in both arguments),&lt;br /&gt;
* Constructor &amp;#039;&amp;#039;c&amp;#039;&amp;#039; - lambda-abstraction (arity 1, recursive).&lt;br /&gt;
&lt;br /&gt;
For example,&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;math&amp;gt; \operatorname{mse}[\lambda x.f\ (x\ x)]&amp;lt;/math&amp;gt;&lt;br /&gt;
: &amp;lt;math&amp;gt; \lambda a, b, c.c\ (\lambda x.\operatorname{mse}[f\ (x\ x)])&amp;lt;/math&amp;gt;&lt;br /&gt;
: &amp;lt;math&amp;gt; \lambda a, b, c.c\ (\lambda x.\lambda a, b, c.b\ \operatorname{mse}[f]\ \operatorname{mse}[x\ x])&amp;lt;/math&amp;gt;&lt;br /&gt;
: &amp;lt;math&amp;gt; \lambda a, b, c.c\ (\lambda x.\lambda a, b, c.b\ (\lambda a, b, c.a\ f)\ \operatorname{mse}[x\ x])&amp;lt;/math&amp;gt;&lt;br /&gt;
: &amp;lt;math&amp;gt; \lambda a, b, c.c\ (\lambda x.\lambda a, b, c.b\ (\lambda a, b, c.a\ f)\ (\lambda a, b, c.b\ \operatorname{mse}[x]\ \operatorname{mse}[x]))&amp;lt;/math&amp;gt;&lt;br /&gt;
: &amp;lt;math&amp;gt; \lambda a, b, c.c\ (\lambda x.\lambda a, b, c.b\ (\lambda a, b, c.a\ f)\ (\lambda a, b, c.b\ (\lambda a, b, c.a\ x)\ (\lambda a, b, c.a\ x)))&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Comparison to the Church encoding==&lt;br /&gt;
&lt;br /&gt;
The Scott encoding coincides with the [[Church encoding]] for booleans.  Church encoding of pairs may be generalized to arbitrary data types by encoding &amp;lt;math&amp;gt;c_i&amp;lt;/math&amp;gt; of &amp;#039;&amp;#039;D&amp;#039;&amp;#039; above as&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;math&amp;gt;\lambda x_1 \ldots x_{A_i} . \lambda c_1 \ldots c_N . c_i (x_1 c_1 \ldots c_N) \ldots (x_{A_i} c_1 \ldots c_N)&amp;lt;/math&amp;gt;&lt;br /&gt;
compare this to the Mogensen Scott encoding,&lt;br /&gt;
: &amp;lt;math&amp;gt;\lambda x_1 \ldots x_{A_i} . \lambda c_1 \ldots c_N . c_i x_1 \ldots x_{A_i}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With this generalization, the Scott and Church encodings coincide on all enumerated datatypes (such as the boolean datatype) because each constructor is a constant (no parameters).&lt;br /&gt;
&lt;br /&gt;
==Type definitions==&lt;br /&gt;
&lt;br /&gt;
Church-encoded data and operations on them are typable in [[system F]], but Scott-encoded data and operations are not obviously typable in system F. Universal as well as recursive types appear to be required,&amp;lt;ref&amp;gt;See the note [http://lucacardelli.name/Papers/Notes/scott2.pdf &amp;quot;Types for the Scott numerals&amp;quot;] by Martín Abadi, Luca Cardelli and Gordon Plotkin (February 18, 1993).&amp;lt;/ref&amp;gt; and since [[strong normalization]] does not hold for recursively typed lambda calculus, termination of programs manipulating Scott-encoded data cannot be established by determining well-typedness of such programs.&lt;br /&gt;
&amp;lt;!-- explain pros of Scott encoding --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [[Church encoding]]&lt;br /&gt;
* [[System F]]&lt;br /&gt;
* [[Lambda cube]]&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&lt;br /&gt;
{{Reflist}}&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
*[http://www.divms.uiowa.edu/~astump/papers/archon.pdf Directly Reﬂective Meta-Programming]&lt;br /&gt;
*Torben Mogensen (1992). [ftp://ftp.diku.dk/diku/semantics/papers/D-128.ps.Z Efficient Self-Interpretation in Lambda Calculus]. &amp;#039;&amp;#039; Journal of Functional Programming&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
{{DEFAULTSORT:Mogensen-Scott encoding}}&lt;br /&gt;
[[Category:Lambda calculus]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{compsci-stub}}&lt;/div&gt;</summary>
		<author><name>en&gt;LujViton</name></author>
	</entry>
</feed>