3

Eta Abstraction in lambda calculus means following.

A function f can be written as \x -> f x

  • Is Eta abstraction of any use while reducing lambda expressions?
  • Is it only an alternate way of writing certain expressions?

Practical use cases would be appreciated.

toraritte
  • 6,300
  • 3
  • 46
  • 67
user634615
  • 647
  • 7
  • 17
  • Depending on your evaluation strategy, eta conversion can be a useful way to delay evaluation – Mulan Nov 16 '16 at 05:46
  • Thanks, can you point me to some link or example where there are some use cases of eta abstraction. – user634615 Nov 16 '16 at 05:49
  • Under strict evaluation, eta abstraction could be used to implement the famous Y combinator. `Y := U (λh. λf. f (λx. h h f x))` where `U := λf. f f` — without `x` eta abstraction here, a strict evaluator would go into an infinite loop. – Mulan Nov 16 '16 at 06:45
  • 1
    I think it's called eta *reduction*. – 盛安安 Dec 15 '16 at 15:46
  • @盛安安 actually I believe it is called eta conversion. Not that it matters much. – rp.beltran Jan 19 '17 at 02:46
  • 1
    Paraphrasing a quote from the [Eta conversion](https://wiki.haskell.org/Eta_conversion) article in the Haskell wiki:"_Converting from `\x -> f x` to `f` would constitute an **eta reduction**, and moving in the opposite way would be an **eta abstraction**. The term **eta conversion** can refer to the process in either direction._" – toraritte Feb 15 '21 at 14:27
  • 1
    @toraritte another term for it is eta expansion. – Will Ness Feb 15 '21 at 17:59
  • @WillNess thanks! I just came across that one half a minute ago:) – toraritte Feb 15 '21 at 18:02
  • Related: [What's the point of η-conversion in lambda calculus?](https://cstheory.stackexchange.com/questions/8259/whats-the-point-of-eta-conversion-in-lambda-calculus) – toraritte Apr 19 '22 at 10:29

2 Answers2

6

The eta reduction/expansion is just a consequence of the law that says that given

f = g

it must be, that for any x

f x = g x

and vice versa.

Hence given:

f x = (\y -> f y) x

we get, by beta reducing the right hand side

f x = f x

which must be true. Thus we can conclude

f   = \y -> f y
Ingo
  • 36,037
  • 5
  • 53
  • 100
4

First, to clarify the terminology, paraphrasing a quote from the Eta conversion article in the Haskell wiki (also incorporating Will Ness' comment above):

Converting from \x -> f x to f would constitute an eta reduction, and moving in the opposite way would be an eta abstraction or expansion. The term eta conversion can refer to the process in either direction.

  • Extensive use of η-reduction can lead to Pointfree programming.
  • It is also typically used in certain compile-time optimisations.

Summary of the use cases found:

  1. Point-free (style of) programming
  2. Allow lazy evaluation in languages using strict/eager evaluation strategies
  3. Compile-time optimizations
  4. Extensionality

1. Point-free (style of) programming

From the Tacit programming Wikipedia article:

Tacit programming, also called point-free style, is a programming paradigm in which function definitions do not identify the arguments (or "points") on which they operate. Instead the definitions merely compose other functions

Borrowing a Haskell example from sth's answer (which also shows composition that I chose to ignore here):

inc x = x + 1

can be rewritten as

inc = (+) 1

This is because (following yatima2975's reasoning) inc x = x + 1 is just syntactic sugar for \x -> (+) 1 x so

\x -> f       x   => f
\x -> ((+) 1) x   => (+) 1

(Check Ingo's answer for the full proof.)

There is a good thread on Stackoverflow on its usage. (See also this repl.it snippet.)

2. Allow lazy evaluation in languages using strict/eager evaluation strategies

Makes it possible to use lazy evaluation in eager/strict languages.

Paraphrasing from the MLton documentation on Eta Expansion:

Eta expansion delays the evaluation of f until the surrounding function/lambda is applied, and will re-evaluate f each time the function/lambda is applied.

Interesting Stackoverflow thread: Can every functional language be lazy?

2.1 Thunks

I could be wrong, but I think the notion of thunking or thunks belongs here. From the wikipedia article on thunks:

In computer programming, a thunk is a subroutine used to inject an additional calculation into another subroutine. Thunks are primarily used to delay a calculation until its result is needed, or to insert operations at the beginning or end of the other subroutine.

The 4.2 Variations on a Scheme — Lazy Evaluation of the Structure and Interpretation of Computer Programs (pdf) has a very detailed introduction to thunks (and even though the latter has not one occurrence of the phrase "lambda calculus", it is worth reading).

(This paper also seemed interesting but didn't have the time to look into it yet: Thunks and the λ-Calculus.)

3. Compile-time optimizations

Completely ignorant on this topic, therefore just presenting sources:

4. Extensionality

This is another topic that I know little about, and this is more theoretical, so here it goes:

From the Lambda calculus wikipedia article:

η-reduction expresses the idea of extensionality, which in this context is that two functions are the same if and only if they give the same result for all arguments.

Some other sources:

Saved this page recursively in Internet Archive so if any of the links are not live anymore then that snapshot may have saved those too.

toraritte
  • 6,300
  • 3
  • 46
  • 67
  • 1
    Now, *this*, ladies and gentlemen, is a good answer. Not only did you explain the uses, you straightened out the confusion about the terminology so we can clearly understand what you're talking about. Thanks—this was exactly what I needed to read right now. – Ben Kovitz Jan 30 '22 at 17:28
  • Awww, you just made my day, thanks! Finally, my borderline OCD paid off:) – toraritte Jan 30 '22 at 21:24