Zulip Chat Archive
Stream: general
Topic: Lambda calculus
Alexander Bentkamp (Dec 17 2018 at 11:24):
Hello,
Does anyone know of a formalization of the lambda calculus in Lean?
In particular termination of beta/eta reduction?
Patrick Massot (Dec 17 2018 at 11:34):
I would have a look at https://github.com/leanprover/mathlib/tree/master/computability (but maybe this is something else)
Patrick Massot (Dec 17 2018 at 11:36):
And, if it doesn't exist, maybe having a look at https://github.com/leanprover/mathlib/blob/5613d2ecc92ce8fae9555745bd94756dec61a323/group_theory/free_group.lean#L127 and https://github.com/leanprover/mathlib/blob/57194fa57e76721a517d6969ee88a6007f0722b3/logic/relation.lean#L288 could be a good idea
Mario Carneiro (Dec 17 2018 at 11:49):
I don't think lambda calculus has been done, although there are several projects in the same space
Mario Carneiro (Dec 17 2018 at 11:50):
I assume you are talking about simply typed lambda calculus, since of course the regular kind doesn't terminate
Mario Carneiro (Dec 17 2018 at 11:51):
I believe Jeremy has a formalization of lambda calculus, although he intended it for different purposes and I don't think he proved this property
Mario Carneiro (Dec 17 2018 at 11:53):
aha, here it is: https://github.com/avigad/embed/blob/master/src/exp.lean
Mario Carneiro (Dec 17 2018 at 11:53):
it's not much more than the definition
Mario Carneiro (Dec 17 2018 at 11:54):
I guess he never defined typechecking for lambda terms, since he was going for FOL
Alexander Bentkamp (Dec 17 2018 at 12:28):
Ok, thanks for the pointers. I will think about whether I'd like to work on this then. Actually, I'd like to formalize a unification procedure for lambda-terms, but I will need a formalization of the lambda-calculus for that first :-)
Kenny Lau (Dec 17 2018 at 12:34):
I might be missing something obvious here
Kenny Lau (Dec 17 2018 at 12:34):
but what happened to the Y-combinator?
Kenny Lau (Dec 17 2018 at 12:34):
oh, that's what "simply typed" rules out isn't it
Alexander Bentkamp (Dec 17 2018 at 12:37):
Yes, I wasn't very precise. I meant simply typed lambda calculus.
Wojciech Nawrocki (Dec 19 2018 at 22:43):
Hey, I'm actually working on this right now! Is there any particular formulation that you want to use? I'm trying to figure out inherently typed terms at the moment, but I have a formulation in raw terms with a typechecking procedure and a proof of progress, basically following "Software Foundations".
Alexander Bentkamp (Dec 20 2018 at 15:09):
Oh, that's great! As I said, I actually would like to formalize a unification procedure for lambda-terms. So if I could build on your library once it's finished, that would be perfect. I find it hard to predict which formulation would be more suitable for this, but I guess it doesn't matter too much.
Wojciech Nawrocki (Dec 20 2018 at 15:29):
It's not pretty code and definitely not suitable for a library, but I can upload it somewhere like git when I have a bit more time if that helps your project :)
Wojciech Nawrocki (Dec 20 2018 at 15:30):
By the way, you mean unification of the entire term assuming some holes on one (or both?) sides, not just types, right?
Alexander Bentkamp (Dec 20 2018 at 17:13):
Yes, with holes on both sides, but the holes are realized as free variables. In addition to that, there are also constant symbols. So for example, one could ask for unifiers of f (X a) b
and f c (Y d)
, where uppercase letters are variables and lowercase letters are constants. A unifier would be {X ↦ λZ. c; Y ↦ λZ. b}
. The procedure is described here: https://www.sciencedirect.com/science/article/pii/0304397576900219
Alexander Bentkamp (Dec 20 2018 at 17:28):
So it sounds like you don't plan / don't have time to improve your code such that it would be usable as a library? If I decide to formalize lambda calculus myself, I will ask you again for what you've done. But currently, I tend to using Isabelle/HOL instead for this project (Oh, oh, high treason in this chat I suppose).
Wojciech Nawrocki (Dec 20 2018 at 18:07):
Oh, I do hope to make it fairly readable, just not the very partial raw-term formulation, which is what I have currently, but rather the inherently-typed one which I only started on. That said, I'm using quantified type theory to support linear typing, which is more general than simply-typed lambda, but can be instantiated (I think..) to simply-typed lambda.
Josh Pollock (Dec 20 2018 at 22:54):
We actually did some stlc in lean in the University of Washington's graduate PL class last fall: https://courses.cs.washington.edu/courses/cse505/17au/lec11/lean/stlc.lean
Alexander Bentkamp (Dec 21 2018 at 11:27):
Thanks! I'll have a closer look next year. Happy holidays :-)
Patrick Thomas (Jan 02 2019 at 20:04):
I just started learning lambda calculus. If you don't mind explaining, I was wondering why the condition x2 \notin FV (e1) \/ x1 \notin FV (e)
is not a part of the definition for lam_diff
in is_subst
?
Mario Carneiro (Jan 02 2019 at 20:05):
are you referring to a particular formalization?
Patrick Thomas (Jan 02 2019 at 20:06):
Sorry, yes. The one that Josh Pollock posted a link to earlier in the thread.
Mario Carneiro (Jan 02 2019 at 20:11):
I think you are right. There are variable capturing substitutions that are admitted by is_subst
Patrick Thomas (Jan 02 2019 at 20:15):
If that is the case, would adding that condition be the simplest fix?
Patrick Thomas (Jan 02 2019 at 21:06):
If I try to add connectives like ∧
and ∨
to the inductive definition, I seem to get an error of "...contains variables that are not parameters". Are these permitted in inductive definitions?
Patrick Thomas (Jan 02 2019 at 21:28):
Would this work?
inductive is_subst : expr → string → expr → expr → Prop -- (λ y . P)[ x := N ] = (λ y . P [ x := N ]) if x ≠ y and y ∉ FV (N) or x ∉ FV (P) | lam_diff : ∀ (y : string) (P : expr) (x : string) (N : expr) (e : expr), x ≠ y → ((¬ is_free N y) ∨ (¬ is_free P x)) → is_subst P x N e → is_subst (expr.lam y P) x N (expr.lam y e)
Kenny Lau (Jan 02 2019 at 21:35):
meta constant is_free : expr → string → Prop meta inductive is_subst : expr → string → expr → expr → Prop -- (λ y . P)[ x := N ] = (λ y . P [ x := N ]) if x ≠ y and y ∉ FV (N) or x ∉ FV (P) | lam_diff : ∀ (y : string) (P : expr) (x : string) (N : expr) (e : expr), x ≠ y → ((¬ is_free N y) ∨ (¬ is_free P x)) → is_subst P x N e → is_subst (expr.lam y sorry P sorry) x N (expr.lam y sorry e sorry)
Kenny Lau (Jan 02 2019 at 21:35):
this works for me verbatim
Patrick Thomas (Jan 02 2019 at 21:40):
Thank you. Do you think this would be a good fix for the definition?
Kenny Lau (Jan 02 2019 at 21:41):
no because it has sorry
Patrick Thomas (Jan 02 2019 at 21:42):
I'm sorry, I didn't mean verbatim, but if the definition was amended in this manner.
Kenny Lau (Jan 02 2019 at 21:43):
my point is that I didn't change the part you complained about
Kenny Lau (Jan 02 2019 at 21:43):
i.e. your diagnosis is not very accurate
Patrick Thomas (Jan 02 2019 at 21:47):
The diagnosis about the error message or about the definition in the link that Josh posted? My post may have been confusing. I don't get error messages for the code I posted, it was changed to avoid them. I was asking if it worked to fix the definition that Josh posted.
Kenny Lau (Jan 02 2019 at 21:48):
oh... context...
Patrick Thomas (Jan 02 2019 at 21:48):
Sorry about that.
Last updated: Dec 20 2023 at 11:08 UTC