tA's crappy blog
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
6.9KB

  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="x-ua-compatible" content="ie=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1">
  7. <meta name="referrer" content="no-referrer">
  8. <title>rf - An Idiot's Guide to Lambda Calculus</title>
  9. <link rel="stylesheet" href="../../css/default.css" />
  10. <link rel="shortcut icon" href="favicon.ico" type="image/x-icon"><link rel="shortcut icon" href="../../images/favicons/favicon32.png"><link rel="apple-touch-icon-precomposed" sizes="144x144" href="../../images/favicons/favicon144.png"><link rel="apple-touch-icon-precomposed" sizes="114x114" href="../../images/favicons/favicon114.png"><link rel="apple-touch-icon-precomposed" sizes="72x72" href="../../images/favicons/favicon72.png"><link rel="apple-touch-icon-precomposed" sizes="57x57" href="../../images/favicons/favicon57.png">
  11. </head>
  12. <body>
  13. <header>
  14. <div class="logo">
  15. <a href="../../">Regular Flolloping</a>
  16. </div>
  17. <nav class="navbar">
  18. <a href="../../">Home</a>
  19. <a href="../../about/">About</a>
  20. <a href="../../contact/">Contact</a>
  21. <a href="../../archive/">Archive</a>
  22. </nav>
  23. </header>
  24. <main role="main">
  25. <h1>An Idiot's Guide to Lambda Calculus</h1>
  26. <article>
  27. <section class="header">
  28. Posted on August 27, 2018
  29. </section>
  30. <section>
  31. <p>clarification: this is not a guide to lambda calculus for idiots, this is a guide to lambda calculus written by an idiot.</p>
  32. <p>imagine for a second you need to explain our numbering system without <strong><em>any</em></strong> background. any at all, think about that for a second.</p>
  33. <ul>
  34. <li>you have no idea what the number symbols mean</li>
  35. <li>you have no idea what plus minus or anything mean</li>
  36. <li>you have no idea of anything</li>
  37. </ul>
  38. <p>and this isn’t limited to just numbering, because almost anything we do on a computer is based around maths, imagine the same for pretty much literally anything.</p>
  39. <p>what you would need is….</p>
  40. <p><strong>is</strong>…</p>
  41. <p><strong><em>is</em></strong>…</p>
  42. <h2 id="a-way-to-describe-computability">a way to describe computability</h2>
  43. <p>and one way of doing that is with lambda calculus. to define lambda calculus we need just a few rules - variables, abstraction, application.</p>
  44. <p>these concepts aren’t too difficult, so awayyyy we go.</p>
  45. <h3 id="variables">variables</h3>
  46. <p>variables are simply a name, most of the time we use letters. there are two catches here, if you’re used to variables in maths or other languages:</p>
  47. <ul>
  48. <li><p>unlike pretty much every other language, lambda calc variables don’t have a value, only a name. this is because we don’t have any concept of what a value is.</p></li>
  49. <li><p>unlike any language worth using, variables in lambda calculus do not have a <em>type</em>. again this is because we don’t have a concept of what type is.</p></li>
  50. </ul>
  51. <p>this guide is gonna use lowercase letters for the most part, so the examples are <code>a b c d e f</code> etc etc</p>
  52. <h3 id="abstraction">abstraction</h3>
  53. <p>abstractions are the functions of lambda calc, and take the form off:</p>
  54. <pre><code>(λx.M)</code></pre>
  55. <p>where <code>λ</code> denotes that this is a function<br />
  56. <code>x</code> is an argument name (that is local to this function)<br />
  57. and <code>M</code> is a list of variables that will form the function body</p>
  58. <p>a quick example of an abstraction is the identity function:</p>
  59. <pre><code>(λx.x)</code></pre>
  60. <p>we’ll get onto more to do with fuctions in a bit, but next</p>
  61. <h3 id="application">application</h3>
  62. <p>application is what we pretentious people call “actually using a function” and it takes the form of:</p>
  63. <pre><code>(M N)</code></pre>
  64. <p>where <code>M</code> is an abstraction, and <code>N</code> is any lambda term at all. i will refer to <code>M</code> as an abstraction and <code>N</code> as the application body</p>
  65. <p>to do the application we just use <code>N</code> as the argument for <code>M</code>, and then do a find and replace based on the abstraction definition.</p>
  66. <p>for example, lets do an easy one using the identity function, which is a function that returns its input unchanged:</p>
  67. <p>if we have the abstraction <code>(λx.x)</code> and the variable <code>y</code> to use for the application, and then lay the application out as so:</p>
  68. <pre><code>( (λx.x) y )</code></pre>
  69. <p>we can then begin applying.</p>
  70. <p>the identity function has <code>x</code> as its argument, so we take the application body, in this case <code>y</code>, and every time we see <code>x</code> in the abstraction body (the bit past <code>.</code>) we replace it with our argument, <code>y</code>.</p>
  71. <p>so our abstraction body is <code>x</code>, and <code>x</code> is equal to our argument <code>y</code>, so therefore our function will return <code>y</code>, which is the identity.</p>
  72. <p>a sligtly more interesting example is something like:</p>
  73. <pre><code>( (λx.xx) y )</code></pre>
  74. <p>here, our argument to our abstraction is <code>y</code>, which gets bound to <code>x</code> in the abstraction body, which is then fed into the <code>xx</code> to produce:</p>
  75. <p><code>yy</code></p>
  76. <p>and thats how we go.</p>
  77. <p>as a spoiler for what the next lambda calc post will cover, heres a bit of an example, imagine we were using the same abstraction:</p>
  78. <pre><code>(λx.xx)</code></pre>
  79. <p>and instead of passing it <code>y</code>, we passed it <strong>another abstraction</strong>… say, itself?</p>
  80. <pre><code>( (λx.xx) (λx.xx) )</code></pre>
  81. <p>here, we bind the entire abstraction <code>(λx.xx)</code> to the variable <code>x</code> in the first abstraction.</p>
  82. <p>when we do the substitution into the body <code>xx</code> we get left with…</p>
  83. <pre><code>( (λx.xx) (λx.xx) )</code></pre>
  84. <p>the same thing, which means this is an <strong><em>infinite loop</em></strong></p>
  85. <p>fun stuff fun stuff imo</p>
  86. <h2 id="further-thoughts">further thoughts</h2>
  87. <p>theres a lot more to go before we get to a numbering system, and at this point it may seem like theres not much use to lambda calculus, but i am not joking when i say <strong><em>anything that can be done on a computer can be written in lambda calculus</em></strong>.</p>
  88. <p>it may be abstracted, it may be thousands of millions of pages long, but it is possible.</p>
  89. <p>and thats what makes it so wonderful.</p>
  90. <p>i’ll write more in depth on this at some point in the near future when i’m feeling smarter, less lazy, and don’t wanna write edgy armchair psych pieces instead.</p>
  91. <p>peace out ny’all, if you’re unlucky i’ll talk about Nock after this.</p>
  92. </section>
  93. </article>
  94. </main>
  95. <footer>
  96. powered by <a href="http://jaspervdj.be/hakyll">Hakyll</a>
  97. </footer>
  98. </body>
  99. </html>