1
$\begingroup$

In this reddit post it is given that $$\text{FAC}=λn.λf.n(λf.λn.n(f(λf.λx.n f(f x))))(λx.f)(λx.x)$$ However when I applied it to $1$ I get: $$\begin{align}\text{FAC}\ 1 &=(λn.λf.n(λf.λn.n(f(λf.λx.n f(f x))))(λx.f)(λx.x))1\\ &=λf.\color{red}1(λf.λn.n(f(λf.λx.n f(f x))))(λx.f)(λx.x)\tag{$\beta$}\\ &=λf.\color{red}{(λf.λx.fx)}\color{green}{(λf.λn.n(f(λf.λx.n f(f x))))}(λx.f)(λx.x)\\ &=λf.(λx.\color{green}{(λf.λn.n(f(λf.λx.n f(f x))))}x)(λx.f)(λx.x)\tag{$\beta$}\\ &=λf.(λx.(λp.λn.n(p(λp.λx.n p(p x))))x)\color{blue}{(λx.f)}(λx.x)\tag{$\alpha$}\\ &=λf.(λp.λn.n(p(λp.λx.n p(p x))))\color{blue}{(λx.f)}(λx.x)\tag{$\beta$}\\ &=λf.(λn.n(\color{blue}{(λx.f)}(λp.λx.n p(p x))))\color{purple}{(λx.x)}\tag{$\beta$}\\ &=λf.(\color{purple}{(λx.x)}\color{orange}{((λx.f)(λp.λx.(λx.x) p(p x))))}\tag{$\beta$}\\ &=λf.\color{orange}{((λx.f)(λp.λx.(λx.x) p(p x)))}\tag{$\beta$}\\ &=λf.f\tag{$\beta$}\end{align}$$ Which is the identity function, the same happens to $0$: $$\begin{align}\text{FAC}\ 0 &=(λn.λf.n(λf.λn.n(f(λf.λx.n f(f x))))(λx.f)(λx.x))0\\ &=λf.\color{red}0(λf.λn.n(f(λf.λx.n f(f x))))(λx.f)(λx.x)\tag{$\beta$}\\ &=λf.\color{red}{(λf.λx.x)}\color{green}{(λf.λn.n(f(λf.λx.n f(f x))))}(λx.f)(λx.x)\\ &=λf.(λx.x)\color{blue}{(λx.f)(λx.x)}\tag{$\beta$}\\ &=λf.(λx.f)\color{purple}{(λx.x)}\tag{$\beta$}\\ &=λf.f\tag{$\beta$}\end{align}$$ However when I apply it to $2$ or higher there's no problem.

Is the formula for $\text{FAC}$ given above wrong?

$\endgroup$
7
  • 7
    $\begingroup$ You know $0! = 1! = 1$, right? How is this different from what you expected, then? Recall that $1 = \lambda f x. f^1\, x = \lambda f x. f x = \lambda f. f$. $\endgroup$ Commented Aug 9 at 14:33
  • 1
    $\begingroup$ @NaïmCamilleFavier I don't think $1$ and the identity function are the same $\endgroup$ Commented Aug 9 at 14:34
  • 2
    $\begingroup$ They are eta-convertible, and you seem to work with beta-eta-converstion, right? $\endgroup$ Commented Aug 9 at 14:35
  • 2
    $\begingroup$ In the comment by @NaïmCamilleFavier the first two = symbols are definitional equality, i.e. just notations, and the last = symbol is eta-conversion. Given this, $\mathrm{FAC}\,1 =_{βη} \mathrm{FAC}\,0 =_{βη} 1$. $\endgroup$ Commented Aug 9 at 14:37
  • 3
    $\begingroup$ No strong opinion. :-) But if you were wondering, maybe someone else will be? $\endgroup$ Commented Aug 9 at 14:45

1 Answer 1

2
$\begingroup$

Your formula, with the condensed abstraction syntax, is

$$\text{FAC}=λnf.n\ (λfn.n\ (f\ (λfx.n\ f\ (f\ x))))\ (λx.f)\ (λx.x)$$

The $λfx.n\ f\ (f\ x)$ is of course $\text{SUCC}\ n$, so let's write it this way,

$$\text{FAC}=λnf.n\ (λfn.n\ (f\ (\text{SUCC}\ n)))\ (λx.f)\ (λx.x)$$

and use mnemonic names to guide understanding,

$$\text{FAC}=λnf.n\ (λra.a\ (r\ (\text{SUCC}\ a)))\ (λa. f)\ 1$$

(with $a$ for "accumulator" and $r$ for "recursive part") and now we see clearly that it is indeed correct, transforming e.g. $\text{FAC}\ 4\ f$ into

$ \qquad \begin{align} 0\ f\ x \, = \,\, & x \, \\ 1\ f\ x \, = \,\, & f\ x \, \\ \text{K}\ f\ a = \,\, & f \, \\ \text{R}\ r\ a\ \triangleq & \ a\ (r\ (\text{SUCC}\ a)) \\ \, \\ \text{FAC}\ 4\ f &=_{_{\beta}} 4\ R\ (K\ f)\ 1 \\ &=_{_{\beta}} R\ (R\ (R\ (R\ (K\ f))))\ 1 \\ &=_{_{\beta}} 1\,\ (R\ (R\ (R\ (K\ f)))\ 2) \\ &=_{_{\beta}} 1\,\ (2\,\ (R\ (R\ (K\ f))\ 3)) \\ &=_{_{\beta}} 1\,\ (2\,\ (3\,\ (R\ (K\ f)\ 4))) \\ &=_{_{\beta}} 1\,\ (2\,\ (3\,\ (4\,\ (K\ f\ 5)))) \\ &=_{_{\beta}} 1\,\ (2\,\ (3\,\ (4\,\ f))) \\ &=_{_{\beta}} (1 * (2 * (3 * 4)))\ f \end{align} $

We have $1 = \lambda f x.f x =_{_{\eta}} \lambda f.f$, so that's not a problem.

As can be seen above, doing manual reductions is oftentimes much easier in the equational style, using combinators, i.e. "lifted lambdas" in the programming jargon. Indeed,

$ \qquad \begin{align} \text{FAC}\ 0\ f\ x &=_{_{\beta}} 0\ R\ (K\ f)\ 1\ x \\ &=_{_{\beta}} K\ f\ 1\ x \\ &=_{_{\beta}} f\ x \\ &=_{_{\beta}} 1\ f\ x \\ \, \text{FAC}\ 1\ f\ x &=_{_{\beta}} 1\ R\ (K\ f)\ 1\ x \\ &=_{_{\beta}} R\ (K\ f)\ 1\ x \\ &=_{_{\beta}} 1\ (K\ f\ 2)\ x \\ &=_{_{\beta}} K\ f\ 2\ x \\ &=_{_{\beta}} f\ x \\ &=_{_{\beta}} 1\ f\ x \end{align} $

and so $ \qquad \begin{align} \text{FAC}\ 0 &=_{_{\eta}} 1 \\ \, \text{FAC}\ 1 &=_{_{\eta}} 1 \end{align} $

$\endgroup$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.