How does the BLC encode parenthesis? For example, how would this:
λa.λb.λc.(a ((b c) d))
Be encoded in BLC?
Note: the Wikipedia article is not very helpful as it uses an unfamiliar notation and provides only one simple example, which doesn't involve parenthesis, and a very complex example, which is hard to analyze. The paper is similar in that aspect.
Binary lambda calculus (BLC) is a minimal, purely functional programming language based on a binary encoding of the untyped lambda calculus with De Bruijn indices. Lambda terms have the following representation in BLC: term. lambda. BLC.
Lambda calculus is composed of 3 elements: variables, functions, and applications. The most basic function is the identity function: λx. x which is equivalent to f(x) = x . The first “x” is the function's argument, and the second is the body of the function.
Lambda calculus is a notation for describing mathematical functions and programs. It is a mathematical system for studying the interaction of functional abstraction and functional application. It captures some of the essential, common features of a wide variety of programming languages.
When talking about Haskell, the term “lambda calculus” often crops up. It's a theoretical framework used to define the meaning of computation in many functional languages, such as Haskell, Agda, Idris, etc. Understanding lambda calculus can be very helpful when talking about programs written in these languages.
If you mean the binary encoding based on De Bruijn indices discussed in the Wikipedia, that's actually quite simple. You first need to do De Bruijn encoding, which means replacing the variables with natural numbers denoting the number of λ binders between the variable and its λ binder. In this notation,
λa.λb.λc.(a ((b c) d))
becomes
λλλ 3 ((2 1) d)
where d is some natural number >=4. Since it is unbound in the expression, we can't really tell which number it should be.
Then the encoding itself, defined recursively as
enc(λM) = 00 + enc(M)
enc(MN) = 01 + enc(M) + enc(N)
enc(i) = 1*i + 0
where +
denotes string concatenation and * means repetition. Systematically applying this, we get
enc(λλλ 3 ((2 1) d))
= 00 + enc(λλ 3 ((2 1) d))
= 00 + 00 + enc(λ 3 ((2 1) d))
= 00 + 00 + 00 + enc(3 ((2 1) d))
= 00 + 00 + 00 + 01 + enc(3) + enc((2 1) d)
= 00 + 00 + 00 + 01 + enc(3) + 01 + enc(2 1) + enc(d)
= 00 + 00 + 00 + 01 + enc(3) + 01 + 01 + enc(2) + enc(1) + enc(d)
= 000000011110010111010 + enc(d)
and as you can see, the open parentheses are encoded as 01
while the close parens are not needed in this encoding.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With