-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Fix convert_classic_tokens #50
Conversation
src/parser.rs
Outdated
&mut Vec::with_capacity(tokens.len() - num_lambda), | ||
&mut Vec::with_capacity(num_lambda), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The maximum depth of the stack is less than the number of appearances of the lambda abstract.
The number of free variables is less than the number of tokens minus the number of lambda abstractions.
Thanks for another contribution! If I'm understanding this correctly (my lambda calculus skills are a bit rusty), ideally the term
would translate to
right? If that is the case, I'd just add an appropriate |
There is no doubt that there are bugs in the current implementation, but the test cases are certainly not correct if you ask me. |
We can use `push_front` instead of an ugly `insert` call
57fc702
to
190c29f
Compare
I read the N.G. de Bruijn's original paper, rewrote this PR, and did
It depends on what we assume the free variable list to be. If we assume it is [..., z, s, x7, x6, x5, x4, x3, x2, x1], (λλ(λλ1)2((λλ21)21))89 is a correct namefree expression. If we assume it is [..., z, s], (λλ(λλ1)2((λλ21)21))12 is a correct namefree expression. I added a test that failed in the previous commit. We need to adjust references to free variables according to the depth of the lambda abstraction. lambda_calculus/tests/parser.rs Lines 16 to 21 in 190c29f
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
Apologies for the delayed merge; would you like me to release a bugfix version now? |
No, I am in no hurry. If you have other things to tweak, release them when you are done. |
"a b"
, the classical notation containing two free variables, should be converted to"12"
inDeBruijn
notation, but the current implementation converts it to"11"
. This PR fixes the problem.Note that
"(λa. a) (λa. a) a"
can be converted to"(λ1)(λ1)2"
, but for simplicity of implementation, I convert it to"(λ1)(λ1)3"
. This is because I'm simply counting the number of appearances, not the maximum depth of λ-abstraction.