Show HN: A lambda expression visualizer for the web
brycec.github.comThe source is kinda crude at this point, but I hope to eventually allow named abstractions as well as direct manipulation of the tree (click n drag). Supporting types might be interesting as well.
The notation is cumbersome, but I like the visualization. I wish eta-reduction were implemented rather than just beta-reduction.
Unfortunately there appear to be some errors. Try entering the following expression:
#(##2 1)
This, if I've understood the notation correctly, means λx.(λy.λz.y)x. Thus, it should reduce to λx.λz.x, or ##2. However, the program instead reduces it to ##1, or λx.λz.z.
So, something's really wrong here.
Agreed, it is unwieldy. However, because of it, eta-reduction is not as important because equivalent terms look the same, and name collisions can't happen. It made it a bit simpler.
And, that is definitely a bug, thanks. I think I could solve it by lazy evaluation (it wouldn't reduce that term) but I think I just need to correctly change vars when they move scope.
Not sure what you mean by "equivalent terms look the same". I'm not clear on how e.g. ##(2 1) and #1 look the same. Going by your remark about name collisions, I must ask if you are thinking of alpha-equivalence? (Which certainly is rendered unnecessary by the notational system.)
And thank you for making/hopefully fixing this!
Oh I see. Yes I was thinking of alpha-equivalence, sorry.
Now I must ask, do you know any good papers/algos on that reduction? And how would you envision animating? It seems a bit like a lambda/var pair just fall off...
I don't know what I might refer you to. Beta reduction requires recognizing subtrees of the form (#T S) (where T and S are any subtrees), eta reduction just requires recognizing subtrees of the form #(T 1) (where T is any subtree).
No idea about animation. It's really not something I'd thought about, I have to say...
Oops -- I forgot about the non-freeness requirement. So not just any subtree. That makes it trickier. But still not hard, I think.
The text at the bottom says this is simply typed lambda calculus, but surely this is untyped lambda calculus.
Right, thanks! Corrected.
I think this would be really great with back and forward controls, i.e. rewind.