3
$\begingroup$

In lambda calculus, a recursive function $f$ is obtained by

$$ f = Y g $$

where $Y$ is the Y combinator and $g$ is the generator of $f$ i.e. $f$ is a fixed point of $g$ i.e. $f == g f$.

In The Scheme Programming Language, I saw an example implementing a recursive function $f$ that sums the integers in a list:

(let ([sum (lambda (f ls)
 (if (null? ls)
 0
 (+ (car ls) (f f (cdr ls)))))])
(sum sum '(1 2 3 4 5))) => 15

What is the mathematical derivation that drives to create the lambda abstraction

 lambda (f ls)
 (if (null? ls)
 0
 (+ (car ls) (f f (cdr ls))))

? It looks like a generator of $f$, but not entirely.

Thanks.

dkaeae
5,0771 gold badge17 silver badges31 bronze badges
asked Aug 28, 2019 at 16:32
$\endgroup$

1 Answer 1

4
$\begingroup$

If you look at the $Z$ combinator (because we're in an eager context), you have $$Z=\lambda g.(\lambda f.g(\lambda v.ffv))(\lambda f.g(\lambda v.ffv))$$

If you look at the code, we don't apply a fixed point combinator to sum, we simply apply sum to itself, so there's no reason for sum to be "generator".

You can also readily show that sum is (modulo currying) equal to $\lambda f.g(\lambda v.ffv)$ for some $g$, basically by replacing (f f ...) with (h ...) where h is the argument to $g$ in the definition for sum (minus the outermost lambda).

answered Aug 28, 2019 at 19:01
$\endgroup$
1
  • $\begingroup$ Thanks. I figured it out at the same time also by looking up the definition of the Y combinator (not sure whether it is called Y or Z). Before seeing the example in the book, I had never met a recursive function computed in such a "convoluted" yet "systematic" way. When is the technique in the example useful? $\endgroup$ Commented Aug 28, 2019 at 19:04

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.