Lambda Calculus Generator

The name of the pictureThe name of the pictureThe name of the pictureClash 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.










share|cite|improve this question



























    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.










    share|cite|improve this question

























      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.










      share|cite|improve this question















      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






      share|cite|improve this question















      share|cite|improve this question













      share|cite|improve this question




      share|cite|improve this question








      edited 8 hours ago

























      asked 8 hours ago









      Legit Stack

      1364




      1364




















          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.






          share|cite|improve this answer




















          • Essentially, all problems like this are solved by invoking the typing monkey...
            – xuq01
            1 hour ago

















          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.






          share|cite




















            Your Answer




            StackExchange.ifUsing("editor", function ()
            return StackExchange.using("mathjaxEditing", function ()
            StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
            StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
            );
            );
            , "mathjax-editing");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "419"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













             

            draft saved


            draft discarded


















            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






























            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.






            share|cite|improve this answer




















            • Essentially, all problems like this are solved by invoking the typing monkey...
              – xuq01
              1 hour ago














            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.






            share|cite|improve this answer




















            • Essentially, all problems like this are solved by invoking the typing monkey...
              – xuq01
              1 hour ago












            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.






            share|cite|improve this answer












            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.







            share|cite|improve this answer












            share|cite|improve this answer



            share|cite|improve this answer










            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
















            • 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










            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.






            share|cite
























              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.






              share|cite






















                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.






                share|cite












                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.







                share|cite












                share|cite



                share|cite










                answered 5 mins ago









                chi

                10.2k1627




                10.2k1627



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    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













































































                    Comments

                    Popular posts from this blog

                    What does second last employer means? [closed]

                    List of Gilmore Girls characters

                    Confectionery