Lambda Calculus in 400 Bytes

3 years ago (justine.lol)

I feel like you could build a semester-long university course out of this single web page, and it would be a really valuable way to spend that semester.

  • Agreed. This is sheer brilliance.

    Technical work like this borders on art.

    It is inspiring in the traditional sense of the word, not in the Ted Talks sense of the word, as in it inspires me to blow the dust off old ideas I've had and get working on them and to set the quality bar high for myself.

I was about to mention SectorLisp as a somewhat related project when I noticed that it was written by the very same genius, not to mention Blinkenlights, which has provided many hours of delight. Incredible!

Justine and making things ridiculously small. Maybe off-topic but seriously impressive projects by the author, consistently. It's amazing.

Everything she touches is gold. Also: she would be the most fearsome cybercriminal I can imagine.

  • I was thinking of the same and also that this is just a glimpse of what's possible and possibly just intended this way to raise the interest in those genuinely curious. Unfortunately I don't fully understand from just glancing over the article (sorry, my bad), but I understand the implications. And these are incredibly fascinating to me. I was always thinking of living-code (just like DNA) living through the packet-state.

    Anyway I think abstracting away variables+lexer via sed and indexing is hot!

    My mind is so rusty, but I can imagine constructing an elegant & expressive language using "category theory + lambda calculus" and oh my god... instead of computing a single result using binary encoding we can compute all results in parallel (array-based) by using a lossless compressor (similar to data-fusion).

    A Finite State Entropy Encoder (FSE) with a multi-symbol alphabet (>2) can be used for this purpose. FSE is a very interesting development in ANS encoding (Asymmetric numeral systems). I need to put all these pieces together + self-modifying code. Because I don't have the feeling that this is a dumb idea at all.

    Maybe infecting any device like the skynet code isn't that far of a stretch away? Disregarding any malicious intent, this is simply inspiring. Maybe I'm just too much of a nerd though to enjoy this a bit too much.. idk.

Slightly unrelated, but this thread is giving me a serious learning itch. Any book or online class recommendations on lambda calculus, combinators and that whole area of CS? Preferably written for the experienced programmer but very average mathematician.

The Informal Description section on Wikipedia is good for more background on Lambda Calculus:

https://en.m.wikipedia.org/wiki/Lambda_calculus

I love this. I love this person's mind. I've seen her (assuming that is the correct pronoun) stuff before, always fascinating.

And then I just discovered that for some unknown reason, this person has already blocked me on Twitter (I can recall exactly zero interactions with them, but I must have followed them already due to things like APE).

Not sure if she sees this but I'm sorry about whatever I said that I don't recall? Twitter username is same as this one here. Would love to see you in my feed again, will promise to keep big mouth shut

Does anyone know how the subroutine diagrams are generated, or have more info about these graphs in general?

Justine, this is one of the coolest things I’ve ever seen! I’m flabbergasted. Are you a wizard?

  • she surely is! this so far is the best thing I’ve seen on internet today.

    • *She

      Unless I've missed something.

      You should also check out the rest of her work! It's all amazing, SectorLISP, Blinkenlights and APE (Actually Portable Executable) are the really well known ones, but many of the other projects are things many programmers would have as the centerpiece of their portfolio.

I remember memorizing how to solve (reduce? resolve? expand?) lambda calculus expressions by hand that went over multiple lines for my degree but I never had the faintest clue what it is and why I was learning this and quickly forgot how to do it.

  • > solve (reduce? resolve? expand?)

    Reduction (in particular "beta-reduction") is essentially 'calling a function with an argument' (just defined in a precise, mathematically-rigorous way). Since lambda calculus only has functions (AKA "lambdas"), "reducing an expression" is another way of saying "running/executing a program".

    "Expansion" would be going the other way; e.g. introducing an abstraction layer which, when reduced/executed, would result in the original expression.

Can I just say this whole presentation (like the previous Lisp boot-sector one) is just astonishingly well put-together, on top of the tour-de-force achievement.

The blc.S didn’t build for me using `-oformat:binary` . Changing to `--oformat=binary` it compiled, but then get core dumps. Running Linux x86_64 up to date Ubuntu 20.04.4 .

    for cc in cc gcc clang
    do  echo "## $cc"
        $cc -no-pie -static -nostdlib -o blc -Wl,--oformat=binary blc.S || exit 1
        { printf 0010; printf 0101; } | ./blc; echo
    done

Any suggestions?

  • Sorry about that!

        wget https://justine.lol/lambda/blc.S
        wget https://justine.lol/lambda/flat.lds
        cc -c -o blc.o blc.S
        ld.bfd -o blc blc.o -T flat.lds
    

    Just tested myself on Linux with both GCC and Clang. Whatever you do, do not use any linker except big deal.

IIUC, this doesn't necessarily translate to more efficient programming, just because the program size is small. It's elegant. Just wondering about possible applications. Maybe I'm not understanding how currying works.

>you could prefix the compressed file with this 400 byte interpreter to get autonomous self-extracting archives that anyone can use.

What could possibly go wrong?

  • Assuming you verified that it's this particular 400 byte interpreter, which is as sandboxed as it gets, then the worst that can happen is hogging all your memory and cpu.

    • Given SPECTRE and rowhammer, I just don't believe that. This gives attackers full degrees of freedom to reactively search for a crack in the process space. With a normal statically compiled decoder, as an attacker you have a certain degree of freedom, but it is far less (unless one of your formats is a programmable environment, e.g. NGO's iOS exploit).

      I, for one, would not be comfortable having content distributed as a blob that runs as a virtual machine that builds the software that decodes the content. Justine has made this practical. I can see the appeal. I just worry that we're trading in our jpgs for exes in a sandbox, and I'm not sure its worth the risk.

      3 replies →

Cool article. My first thought is that this might be a fun way to implement some really simple executable obfuscation.

  • Should be trivial to add running off the end into into native code, presumably after decompressing it. Process is: 0. start a decompressor; 1. decompress a decryptor; 2. call that to decrypt a composite payload; 3. run off the end into a better, native decompressor to decompress the real payload, and write it out or; 4. run into that.

    I.e. it does not suffice to verify that the header is really a lambda calculus evaluator.