Project LambdaCAlculus
Posted: May 3rd, 2020, 8:32 am
We're collaborating to create a rule to simulate Lambda Calculus Diagrams.
First of all, what is "Lambda Calculus"?
You could try looking it up on Wikipedia, but that may be a little wordy, so I'll explain it right here.
TL;DR: (λstuff.(stuff and more stuff))(Things) -> (Things and more Things)
Basics: Substitution
Lambda Calculus is 99% substitution and 1% expressions. The 1% comes from what's left in the end.
Have you ever written a printf() command in C? It can go like this:
And it would output:
The printf, in this case, takes 2 strings: The format/body, ("Hello, %s") and the argument. Then, it replaces the %s in the format with the argument. ("there")
That's basically how Lambda Calculus works. It takes an argument, and replaces something inside its body.
If we were to write the above in Lambda Calculus notation, it'd be this:
Which evaluates to:
Basically, instead of printf() we have (λx.)
Instead of "Hello %s" we have (Hello x)
This says it's a function (a.k.a. "Lambda" or "Expression") that takes in a variable "x" and returns the expression "Hello (x)".
Notice how I said it returns an "Expression" and not a "String".
In reality, there are no strings in Lambda calculus. The above example would treat each letter of "Hello" as the variables 'H', 'e', 2 of 'l', and 'o'.
This means that, if we put that in something that takes 'l' as an argument, we could do this:
Which then becomes:
Some more examples:
Chaining
Now, the quirk of Lambda Calculus is that you can make an expression return another valid expression.
To explain this, I'll just give an example.
Seems a bit complex at first glance, though. Let's just look at what we need.
Now, we can see what we're doing. We're asking for λx, and we're giving it (red).
For now, let's just ignore everything other than that <x> that we're substituting.
Good.
But wait, we can still evaluate that, so let's keep going.
This works!
Recursion
Now, watch:
Looks a bit strange, let's evaluate it...
We ended up with the same thing we started with. We can then keep evaluating it forever and ever, and it'll never end!
This works with other expressions, and you can also give them your own arguments as well.
Here's an expression, that takes another expression, and gives it 15.
This simple substitution-based system is apparently proven to be Turing-complete.
First of all, what is "Lambda Calculus"?
You could try looking it up on Wikipedia, but that may be a little wordy, so I'll explain it right here.
TL;DR: (λstuff.(stuff and more stuff))(Things) -> (Things and more Things)
Basics: Substitution
Lambda Calculus is 99% substitution and 1% expressions. The 1% comes from what's left in the end.
Have you ever written a printf() command in C? It can go like this:
Code: Select all
printf("Hello %s", "there");Code: Select all
Hello thereThat's basically how Lambda Calculus works. It takes an argument, and replaces something inside its body.
If we were to write the above in Lambda Calculus notation, it'd be this:
Code: Select all
(λx.(Hello x))(there)Code: Select all
Hello (there)Instead of "Hello %s" we have (Hello x)
This says it's a function (a.k.a. "Lambda" or "Expression") that takes in a variable "x" and returns the expression "Hello (x)".
Notice how I said it returns an "Expression" and not a "String".
In reality, there are no strings in Lambda calculus. The above example would treat each letter of "Hello" as the variables 'H', 'e', 2 of 'l', and 'o'.
This means that, if we put that in something that takes 'l' as an argument, we could do this:
Code: Select all
(λl.(Hello (there)))(VAR)Code: Select all
He(VAR)(VAR)o (there)Code: Select all
(λz.z z)(Hello)
(Hello) (Hello)
Code: Select all
(λy.Period y)(15)
Attempt (15)
Now, the quirk of Lambda Calculus is that you can make an expression return another valid expression.
To explain this, I'll just give an example.
Code: Select all
(λx.(λy.(I like the colors x and y))(blue))(red)Code: Select all
(λx.
(λy.(I like the colors <x> and y))(blue)
)(red)
For now, let's just ignore everything other than that <x> that we're substituting.
Code: Select all
(λx.
(λy.(I like the colors x and y))(blue)
)(red)
take x = (red)
(λy.(I like the colors <x> and y))(blue)
substitute <x> with (red)
(λy.(I like the colors (red) and y))(blue)
But wait, we can still evaluate that, so let's keep going.
Code: Select all
(λy.
(I like the colors (red) and y)
)(blue)
take y = (blue)
(I like the colors (red) and <y>)
substitute <y> with (blue)
I like the colors (red) and (blue)
Recursion
Now, watch:
Code: Select all
(λx.x x)(λx.x x)
Code: Select all
(λx.x x)(λx.x x)
Take x = (λx.x x)
<x> <x>
substitute all x's with (λx.x x)
(λx.x x)(λx.x x)
This works with other expressions, and you can also give them your own arguments as well.
Here's an expression, that takes another expression, and gives it 15.
Code: Select all
(λx.x 15)(λy. Period y)
x = (λy. Period y)
<x> 15
(λy. Period y) 15
y = 15
Period <y>
Period 15