Lambda Calculus Generator
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
I don't know where else to ask this question, I hope this is a good place.
I'm just curious to know if its possible to make a lambda calculus generator; essentially, a loop that will, given infinite time, produce every possible lambda calculus function. (like in the form of a string).
Since lambda calculus is so simple, having only a few elements to its notation I thought it might be possible (though, not very useful) to produce all possible combinations of that notation elements, starting with the simplest combinations, and thereby produce every possible lambda calculus function.
Of course, I know almost nothing about lambda calculus so I have no idea if this is really possible.
Is it? If so, is it pretty straightforward like I've envisioned it, or is it technically possible, but so difficult that it is effectively impossible?
PS. I'm not talking about beta-reduced functions, I'm just talking about every valid notation of every lambda calculus function.
lambda-calculus
add a comment |Â
up vote
2
down vote
favorite
I don't know where else to ask this question, I hope this is a good place.
I'm just curious to know if its possible to make a lambda calculus generator; essentially, a loop that will, given infinite time, produce every possible lambda calculus function. (like in the form of a string).
Since lambda calculus is so simple, having only a few elements to its notation I thought it might be possible (though, not very useful) to produce all possible combinations of that notation elements, starting with the simplest combinations, and thereby produce every possible lambda calculus function.
Of course, I know almost nothing about lambda calculus so I have no idea if this is really possible.
Is it? If so, is it pretty straightforward like I've envisioned it, or is it technically possible, but so difficult that it is effectively impossible?
PS. I'm not talking about beta-reduced functions, I'm just talking about every valid notation of every lambda calculus function.
lambda-calculus
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I don't know where else to ask this question, I hope this is a good place.
I'm just curious to know if its possible to make a lambda calculus generator; essentially, a loop that will, given infinite time, produce every possible lambda calculus function. (like in the form of a string).
Since lambda calculus is so simple, having only a few elements to its notation I thought it might be possible (though, not very useful) to produce all possible combinations of that notation elements, starting with the simplest combinations, and thereby produce every possible lambda calculus function.
Of course, I know almost nothing about lambda calculus so I have no idea if this is really possible.
Is it? If so, is it pretty straightforward like I've envisioned it, or is it technically possible, but so difficult that it is effectively impossible?
PS. I'm not talking about beta-reduced functions, I'm just talking about every valid notation of every lambda calculus function.
lambda-calculus
I don't know where else to ask this question, I hope this is a good place.
I'm just curious to know if its possible to make a lambda calculus generator; essentially, a loop that will, given infinite time, produce every possible lambda calculus function. (like in the form of a string).
Since lambda calculus is so simple, having only a few elements to its notation I thought it might be possible (though, not very useful) to produce all possible combinations of that notation elements, starting with the simplest combinations, and thereby produce every possible lambda calculus function.
Of course, I know almost nothing about lambda calculus so I have no idea if this is really possible.
Is it? If so, is it pretty straightforward like I've envisioned it, or is it technically possible, but so difficult that it is effectively impossible?
PS. I'm not talking about beta-reduced functions, I'm just talking about every valid notation of every lambda calculus function.
lambda-calculus
lambda-calculus
edited 8 hours ago
asked 8 hours ago
Legit Stack
1364
1364
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
5
down vote
Yes. Take something that enumerates all possible ASCII strings. For each output, check if it is a valid lambda calculus syntax that defines a function; if not, skip it. (That check can be done.) That enumerates all lambda calculus functions.
Essentially, all problems like this are solved by invoking the typing monkey...
– xuq01
1 hour ago
add a comment |Â
up vote
0
down vote
Sure, this is a standard encoding exercise.
First of all, let $p : mathbb N^2 to mathbb N$ any bijective computable function, called a pairing function. A standard choice is
$$
p(n,m) = dfrac(n+m)(n+m+1)2+n
$$
One can prove that this is a bijection, so given any natural $k$, we can compute $n,m$ such that $p(n,m)=k$.
To enumerate lambda terms, fix any enumeration for variables names: $x_0,x_1,x_2,ldots$.
Then, for each natural number $i$, print $lambda(i)$, defined recursively as follows:
- if $i$ is even, let $j=i/2$ and return variable $x_j$
- if $i$ is odd, let $j=(i-1)/2$
- if $j$ is even, let $k=j/2$ and find $n,m$ such that $p(n,m)=k$; compute $N=lambda(n), M=lambda(m)$; return application $(NM)$
- if $j$ is odd, let $k=(j-1)/2$ and find $n,m$ such that $p(n,m)=k$; compute $M=lambda(m)$; return abstraction $(lambda x_n. M)$
This program is constructed by the following "algebraic" bijection among lambda terms syntax:
$$
Lambda simeq mathbb N + Lambda^2 + mathbb N times Lambda
$$
which is read as "the lambda terms, syntactically, are the disjoint union of 1) variables (represented as a natural), 2) applications (make by two lambda terms), and 3) abstraction (a pair variable/natural + lambda term)".
Given that, we recursively apply computable bijections $mathbb N^2 simeq mathbb N$ ($p$) and $mathbb N + mathbb N simeq mathbb N$ (the standard even/odd one) to obtain the algorithm above.
This procedure is general, and will work on almost any language generated through a context-free grammar, which will provide a similar isomorphism to the one above.
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
Yes. Take something that enumerates all possible ASCII strings. For each output, check if it is a valid lambda calculus syntax that defines a function; if not, skip it. (That check can be done.) That enumerates all lambda calculus functions.
Essentially, all problems like this are solved by invoking the typing monkey...
– xuq01
1 hour ago
add a comment |Â
up vote
5
down vote
Yes. Take something that enumerates all possible ASCII strings. For each output, check if it is a valid lambda calculus syntax that defines a function; if not, skip it. (That check can be done.) That enumerates all lambda calculus functions.
Essentially, all problems like this are solved by invoking the typing monkey...
– xuq01
1 hour ago
add a comment |Â
up vote
5
down vote
up vote
5
down vote
Yes. Take something that enumerates all possible ASCII strings. For each output, check if it is a valid lambda calculus syntax that defines a function; if not, skip it. (That check can be done.) That enumerates all lambda calculus functions.
Yes. Take something that enumerates all possible ASCII strings. For each output, check if it is a valid lambda calculus syntax that defines a function; if not, skip it. (That check can be done.) That enumerates all lambda calculus functions.
answered 3 hours ago


D.W.♦
96.2k11111260
96.2k11111260
Essentially, all problems like this are solved by invoking the typing monkey...
– xuq01
1 hour ago
add a comment |Â
Essentially, all problems like this are solved by invoking the typing monkey...
– xuq01
1 hour ago
Essentially, all problems like this are solved by invoking the typing monkey...
– xuq01
1 hour ago
Essentially, all problems like this are solved by invoking the typing monkey...
– xuq01
1 hour ago
add a comment |Â
up vote
0
down vote
Sure, this is a standard encoding exercise.
First of all, let $p : mathbb N^2 to mathbb N$ any bijective computable function, called a pairing function. A standard choice is
$$
p(n,m) = dfrac(n+m)(n+m+1)2+n
$$
One can prove that this is a bijection, so given any natural $k$, we can compute $n,m$ such that $p(n,m)=k$.
To enumerate lambda terms, fix any enumeration for variables names: $x_0,x_1,x_2,ldots$.
Then, for each natural number $i$, print $lambda(i)$, defined recursively as follows:
- if $i$ is even, let $j=i/2$ and return variable $x_j$
- if $i$ is odd, let $j=(i-1)/2$
- if $j$ is even, let $k=j/2$ and find $n,m$ such that $p(n,m)=k$; compute $N=lambda(n), M=lambda(m)$; return application $(NM)$
- if $j$ is odd, let $k=(j-1)/2$ and find $n,m$ such that $p(n,m)=k$; compute $M=lambda(m)$; return abstraction $(lambda x_n. M)$
This program is constructed by the following "algebraic" bijection among lambda terms syntax:
$$
Lambda simeq mathbb N + Lambda^2 + mathbb N times Lambda
$$
which is read as "the lambda terms, syntactically, are the disjoint union of 1) variables (represented as a natural), 2) applications (make by two lambda terms), and 3) abstraction (a pair variable/natural + lambda term)".
Given that, we recursively apply computable bijections $mathbb N^2 simeq mathbb N$ ($p$) and $mathbb N + mathbb N simeq mathbb N$ (the standard even/odd one) to obtain the algorithm above.
This procedure is general, and will work on almost any language generated through a context-free grammar, which will provide a similar isomorphism to the one above.
add a comment |Â
up vote
0
down vote
Sure, this is a standard encoding exercise.
First of all, let $p : mathbb N^2 to mathbb N$ any bijective computable function, called a pairing function. A standard choice is
$$
p(n,m) = dfrac(n+m)(n+m+1)2+n
$$
One can prove that this is a bijection, so given any natural $k$, we can compute $n,m$ such that $p(n,m)=k$.
To enumerate lambda terms, fix any enumeration for variables names: $x_0,x_1,x_2,ldots$.
Then, for each natural number $i$, print $lambda(i)$, defined recursively as follows:
- if $i$ is even, let $j=i/2$ and return variable $x_j$
- if $i$ is odd, let $j=(i-1)/2$
- if $j$ is even, let $k=j/2$ and find $n,m$ such that $p(n,m)=k$; compute $N=lambda(n), M=lambda(m)$; return application $(NM)$
- if $j$ is odd, let $k=(j-1)/2$ and find $n,m$ such that $p(n,m)=k$; compute $M=lambda(m)$; return abstraction $(lambda x_n. M)$
This program is constructed by the following "algebraic" bijection among lambda terms syntax:
$$
Lambda simeq mathbb N + Lambda^2 + mathbb N times Lambda
$$
which is read as "the lambda terms, syntactically, are the disjoint union of 1) variables (represented as a natural), 2) applications (make by two lambda terms), and 3) abstraction (a pair variable/natural + lambda term)".
Given that, we recursively apply computable bijections $mathbb N^2 simeq mathbb N$ ($p$) and $mathbb N + mathbb N simeq mathbb N$ (the standard even/odd one) to obtain the algorithm above.
This procedure is general, and will work on almost any language generated through a context-free grammar, which will provide a similar isomorphism to the one above.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Sure, this is a standard encoding exercise.
First of all, let $p : mathbb N^2 to mathbb N$ any bijective computable function, called a pairing function. A standard choice is
$$
p(n,m) = dfrac(n+m)(n+m+1)2+n
$$
One can prove that this is a bijection, so given any natural $k$, we can compute $n,m$ such that $p(n,m)=k$.
To enumerate lambda terms, fix any enumeration for variables names: $x_0,x_1,x_2,ldots$.
Then, for each natural number $i$, print $lambda(i)$, defined recursively as follows:
- if $i$ is even, let $j=i/2$ and return variable $x_j$
- if $i$ is odd, let $j=(i-1)/2$
- if $j$ is even, let $k=j/2$ and find $n,m$ such that $p(n,m)=k$; compute $N=lambda(n), M=lambda(m)$; return application $(NM)$
- if $j$ is odd, let $k=(j-1)/2$ and find $n,m$ such that $p(n,m)=k$; compute $M=lambda(m)$; return abstraction $(lambda x_n. M)$
This program is constructed by the following "algebraic" bijection among lambda terms syntax:
$$
Lambda simeq mathbb N + Lambda^2 + mathbb N times Lambda
$$
which is read as "the lambda terms, syntactically, are the disjoint union of 1) variables (represented as a natural), 2) applications (make by two lambda terms), and 3) abstraction (a pair variable/natural + lambda term)".
Given that, we recursively apply computable bijections $mathbb N^2 simeq mathbb N$ ($p$) and $mathbb N + mathbb N simeq mathbb N$ (the standard even/odd one) to obtain the algorithm above.
This procedure is general, and will work on almost any language generated through a context-free grammar, which will provide a similar isomorphism to the one above.
Sure, this is a standard encoding exercise.
First of all, let $p : mathbb N^2 to mathbb N$ any bijective computable function, called a pairing function. A standard choice is
$$
p(n,m) = dfrac(n+m)(n+m+1)2+n
$$
One can prove that this is a bijection, so given any natural $k$, we can compute $n,m$ such that $p(n,m)=k$.
To enumerate lambda terms, fix any enumeration for variables names: $x_0,x_1,x_2,ldots$.
Then, for each natural number $i$, print $lambda(i)$, defined recursively as follows:
- if $i$ is even, let $j=i/2$ and return variable $x_j$
- if $i$ is odd, let $j=(i-1)/2$
- if $j$ is even, let $k=j/2$ and find $n,m$ such that $p(n,m)=k$; compute $N=lambda(n), M=lambda(m)$; return application $(NM)$
- if $j$ is odd, let $k=(j-1)/2$ and find $n,m$ such that $p(n,m)=k$; compute $M=lambda(m)$; return abstraction $(lambda x_n. M)$
This program is constructed by the following "algebraic" bijection among lambda terms syntax:
$$
Lambda simeq mathbb N + Lambda^2 + mathbb N times Lambda
$$
which is read as "the lambda terms, syntactically, are the disjoint union of 1) variables (represented as a natural), 2) applications (make by two lambda terms), and 3) abstraction (a pair variable/natural + lambda term)".
Given that, we recursively apply computable bijections $mathbb N^2 simeq mathbb N$ ($p$) and $mathbb N + mathbb N simeq mathbb N$ (the standard even/odd one) to obtain the algorithm above.
This procedure is general, and will work on almost any language generated through a context-free grammar, which will provide a similar isomorphism to the one above.
answered 5 mins ago
chi
10.2k1627
10.2k1627
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcs.stackexchange.com%2fquestions%2f97539%2flambda-calculus-generator%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password