ArticleslgStudy

mathematics

Mogensen–Scott encoding

Mogensen–Scott encoding is a mathematics topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Mogensen–Scott encoding rather than just read about it. In short: In computer science, Scott encoding is a way to represent algebraic data types in the lambda calculus, following their syntactic definition without regard whether they are recursive or not. This is unlike Church encoding which treats recursive data types specially, representing them with right folds.

Key takeaways

  • Mogensen–Scott encoding belongs to mathematics; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Mogensen–Scott encoding to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Mogensen–Scott encoding from memory before moving on to harder problems.

Reference excerpt

In computer science, Scott encoding is a way to represent algebraic data types in the lambda calculus, following their syntactic definition without regard whether they are recursive or not. This is unlike Church encoding which treats recursive data types specially, representing them with right folds. The data and operators form a mathematical structure which is embedded in the lambda calculus. Mogensen–Scott encoding extends and slightly modifies Scott encoding by applying the encoding to Metaprogramming. This encoding allows the representation of lambda calculus terms, as data, to be operated on by a meta program.

Exposition

Numbers Scott encoding of numbers follows the Peano definition of natural numbers as a sum of two cases, the zero case and the successor case,

N a t := Zero ⁡ | Succ ⁡ N a t {\displaystyle \qquad Nat:=\operatorname {Zero} \ |\,\operatorname {Succ} Nat}

Correspondingly, Scott numerals are functions which expect two arguments, two handlers, each receiving the corresponding case's data from the number:

0 = λ z s . z Succ = λ n . λ z s . s n {\displaystyle \quad {\begin{aligned}0&=\lambda zs.z\\\operatorname {Succ} &=\lambda n.\lambda zs.s\ n\end{aligned}}}

The zero case has no data. The successor case data is its Scott numeral, which is served as the argument to the corresponding handler. When a Scott numeral is supplied with two handlers, it calls the appropriate one with its corresponding data. Scott encoded values embody a choice between the sum data type's cases.

IsZero = λ n . n True ⁡ ( λ m . False ) Pred = λ n . n 0 ( λ m . m ) {\displaystyle \quad {\begin{aligned}\operatorname {IsZero} &=\lambda n.n\ \operatorname {True} \ (\lambda m.\operatorname {False} )\\\operatorname {Pred} &=\lambda n.n\ 0\ (\lambda m.m)\end{aligned}}}

Recursive operations on Scott numerals require explicit use of recursion, e.g. using Y {\displaystyle \operatorname {Y} } combinator:

Add = Y ⁡ λ r p q . p q ( λ m . Succ ( r m q ) ) {\displaystyle \qquad \operatorname {Add} =\operatorname {Y} \lambda rpq.p\ q\ (\lambda m.\operatorname {Succ} \,(r\ m\ q))}

Church numerals, on the other hand, already embody the primitive recursion and perform the folding / looping on their own:

A d d C h u r c h = λ p q s z . p s ( q s z ) {\displaystyle \qquad \operatorname {Add_{_{\,Church}}} =\lambda pqsz.p\ s\ (q\ s\ z)}

The key difference is that Scott's handler's argument is the number's own predecessor Scott numeral, unprocessed, whereas Church's folding / looping function's argument is the result of folding / looping over its predecessor.

Lists Scott encoding of lists follows their definition as a sum of two cases, the empty list case and the cons case,

L i s t := NIL ⁡ | Cons ⟨ v a l ⟩ L i s t {\displaystyle \qquad List:=\operatorname {NIL} \ |\,\operatorname {Cons} \,\langle val\rangle \,List}

Correspondingly, Scott lists are functions which expect two arguments, two handlers, each receiving the corresponding data from the list:

NIL = λ n c . n Cons = λ a d . λ n c . c a d {\displaystyle \quad {\begin{aligned}\operatorname {NIL} &=\lambda nc.n\\\operatorname {Cons} &=\lambda ad.\lambda nc.c\ a\ d\end{aligned}}}

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Mogensen–Scott encoding

Start with the simplest possible case. Write down what Mogensen–Scott encoding claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In mathematics, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Mogensen–Scott encoding before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Mogensen–Scott encoding ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Mogensen–Scott encoding

In research
Mogensen–Scott encoding appears in mathematics research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Mogensen–Scott encoding in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Mogensen–Scott encoding is common in secondary-school and first-year university syllabi. It links to neighbouring topics Lambda calculus, so understanding it makes those chapters shorter.
In everyday life
Look for Mogensen–Scott encoding outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Mogensen–Scott encoding” →

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Mogensen–Scott encoding in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Mogensen–Scott encoding means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Mogensen–Scott encoding out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Mogensen–Scott encoding in simple terms?

In computer science, Scott encoding is a way to represent algebraic data types in the lambda calculus, following their syntactic definition without regard whether they are recursive or not. This is unlike Church encoding which treats recursive data types specially, representing them with right fold…

Why does Mogensen–Scott encoding matter?

Because it connects several mathematics ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Mogensen–Scott encoding?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Mogensen–Scott encoding.

Tags

  • Lambda calculus

Keep exploring