I am trying to create some functions that I want to comfortably compose together using the pure functions.
The functions were originally written in $\lambda$-expressions so I would like to keep the format as close to it as possible. They are
${\rm id}:=(\lambda x . x)$
${\rm almost\$factorial}:=(\lambda f.(\lambda n. \text{If } (n=0) \text{ then } 1 \text{ else } n*f(n-1)))$
- ${\rm factorial0}:= {\rm almost\$factorial} ({\rm id})$
I realized that I can write
id:= (#)&
for ${\rm id}$.
So id[x]
gives me x
, which is what I expected. However, I'm at lost on how to write $almost-factorial$. I tried
almost$factorial := If[#1==0, 1, #1*(#2[#1 - 1])]&
But it only works when it takes two arguments at once. I would to be able to define almost$factorial
as a pure function that takes only one argument and outputs another pure function, which I can apply.
almost$factorial[id] [0] = 1.
Is this possible to do in Mathematica?
Identity
function, so you can also doid=Identity
. $\endgroup$