-
Notifications
You must be signed in to change notification settings - Fork 128
feat: prove confluence for βη-reduction #456
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
Merged
Merged
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
7c133fa
refactor: define FullBeta using Xi
chenson2018 f739dd0
refactor: define FullBeta using Xi
chenson2018 1af736e
add left and right redex_app congruence rules
m-ow 5b753e6
add open_preserve_not_fvar lemma
m-ow 55908c7
add beta step_not_fv lemma
m-ow aa58d58
add beta invert_step_app_fvar lemma
m-ow bdf4ca3
add eta step_subst_cong_l lemma
m-ow c22f267
prove right congruence for substitution and opening
m-ow d85c3ae
prove confluence beta eta reduction
m-ow 5aa8c44
skip step_multiApp_l in grind lint
m-ow 89c95b8
skip eta lint
m-ow 302ccc2
skip lint
m-ow 37f0c9d
add missing docstring
m-ow e171914
Merge branch 'fullbeta-refactor' into beta-eta-confluence
m-ow eeeef1d
update cslib
m-ow 4a84dce
remove trailing whitespace
m-ow 2ea1c54
Merge branch 'fullbeta-refactor' into beta-eta-confluence
m-ow 4b957e5
add missing docstring
m-ow 7617845
Merge remote-tracking branch 'origin/main' into beta-eta-confluence
chenson2018 0fde6f6
consistent name for Eta
chenson2018 e762ea3
Update Cslib/Languages/LambdaCalculus/LocallyNameless/Untyped/FullEta…
m-ow 38eed22
Update Cslib/Languages/LambdaCalculus/LocallyNameless/Untyped/FullEta…
m-ow 6486bd0
Update Cslib/Languages/LambdaCalculus/LocallyNameless/Untyped/FullEta…
m-ow b0b75cf
Update Cslib/Languages/LambdaCalculus/LocallyNameless/Untyped/FullEta…
m-ow 8ed31f3
Update Cslib/Languages/LambdaCalculus/LocallyNameless/Untyped/FullBet…
m-ow 051e755
Update Cslib/Languages/LambdaCalculus/LocallyNameless/Untyped/FullBet…
m-ow 37bf2c4
Update Cslib/Languages/LambdaCalculus/LocallyNameless/Untyped/FullBet…
m-ow 148ce54
Update Cslib/Languages/LambdaCalculus/LocallyNameless/Untyped/FullBet…
m-ow 342dc8d
Update Cslib/Languages/LambdaCalculus/LocallyNameless/Untyped/FullBet…
m-ow 158df15
Update Cslib/Languages/LambdaCalculus/LocallyNameless/Untyped/FullEta…
m-ow abd247b
Update Cslib/Languages/LambdaCalculus/LocallyNameless/Untyped/FullEta…
m-ow db60f78
Update Cslib/Languages/LambdaCalculus/LocallyNameless/Untyped/FullEta…
m-ow a6f03c7
Update Cslib/Languages/LambdaCalculus/LocallyNameless/Untyped/FullEta…
m-ow 6d6d92b
Update Cslib/Languages/LambdaCalculus/LocallyNameless/Untyped/FullEta…
m-ow 52eb262
Update Cslib/Languages/LambdaCalculus/LocallyNameless/Untyped/FullEta…
m-ow a77fc6f
feat: prove that omega-regular languages are closed under complementa…
ctchou 4fe9a85
remove scoped grind
m-ow 54250c6
Merge remote-tracking branch 'origin/main' into beta-eta-confluence
chenson2018 fa00b98
case' I missed
chenson2018 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
Cslib/Languages/LambdaCalculus/LocallyNameless/Untyped/FullBetaEtaConfluence.lean
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| /- | ||
| Copyright (c) 2026 Maximiliano Onofre Martínez. All rights reserved. | ||
| Released under Apache 2.0 license as described in the file LICENSE. | ||
| Authors: Maximiliano Onofre Martínez | ||
| -/ | ||
|
|
||
| module | ||
|
|
||
| public import Cslib.Languages.LambdaCalculus.LocallyNameless.Untyped.FullBetaConfluence | ||
| public import Cslib.Languages.LambdaCalculus.LocallyNameless.Untyped.FullEtaConfluence | ||
|
|
||
| @[expose] public section | ||
|
|
||
| set_option linter.unusedDecidableInType false | ||
|
|
||
| /-! # βη-Confluence for the λ-calculus | ||
|
|
||
| ## Reference | ||
|
|
||
| * [T. Nipkow, *More Church-Rosser Proofs (in Isabelle/HOL)*][Nipkow2001] | ||
|
|
||
| -/ | ||
|
|
||
| namespace Cslib | ||
|
|
||
| universe u | ||
|
|
||
| variable {Var : Type u} | ||
| variable [HasFresh Var] [DecidableEq Var] | ||
|
|
||
| namespace LambdaCalculus.LocallyNameless.Untyped.Term | ||
|
|
||
| open Relation | ||
|
|
||
| /-- Full βη-reduction. -/ | ||
| @[reduction_sys "βηᶠ"] | ||
| abbrev FullBetaEta : Term Var → Term Var → Prop := FullBeta ⊔ FullEta | ||
|
|
||
| open FullEta FullBeta in | ||
| /-- η-reduction and β-reduction strongly commute. -/ | ||
| lemma stronglyCommute_eta_beta : StronglyCommute (@FullEta Var) FullBeta := by | ||
| intro x y₁ y₂ h₁ st_beta | ||
| induction st_beta generalizing y₁ | ||
| case base h1_b => | ||
| cases h1_b | ||
| case beta M N _ _ => | ||
| cases h₁ | ||
| case base h => cases h | ||
| case appL v _ _ => | ||
| use M ^ v | ||
| grind [step_open_cong_r] | ||
| case appR u st_eta_absM _ => | ||
| have := step_lc_r st_eta_absM | ||
| cases st_eta_absM | ||
| case base h => use (disch := grind) app u N | ||
| case abs M_eta xs _ => | ||
| have ⟨_, hz⟩ := fresh_exists (xs ∪ N.fv ∪ M.fv ∪ M_eta.fv) | ||
| use M_eta ^ N | ||
| grind [step_subst_cong_l] | ||
| case appL Z _ N _ _ ih => | ||
| cases h₁ | ||
| case base h => cases h | ||
| case appL _ _ st => | ||
| use app Z (ih st).choose | ||
| grind [FullEta.redex_app_r_cong] | ||
| case appR z_red _ _ => use (disch := grind) app z_red N | ||
| case appR M _ Z _ _ ih => | ||
| cases h₁ | ||
| case base h => cases h | ||
| case appL z_red _ _ => use (disch := grind) app Z z_red | ||
| case appR _ st _ => | ||
| use app (ih st).choose M | ||
| grind [FullEta.redex_app_l_cong] | ||
| case abs M N xs st_body_beta ih => | ||
| cases h₁ | ||
| case base h_eta => | ||
| cases h_eta with | eta => | ||
| have ⟨w, _⟩ := fresh_exists <| free_union [fv] Var | ||
| have st_beta_w : app y₁ (fvar w) ⭢βᶠ N ^ fvar w := by grind [st_body_beta w] | ||
| rcases invert_step_app_fvar st_beta_w with ⟨u', _, st_u⟩ | ⟨u1, _, _⟩ | ||
| · use u' | ||
| grind [open_eq_app ?_ (step_not_fv st_u ?_)] | ||
| · use abs u1 | ||
| grind [open_injective w N u1] | ||
| case abs S ys st_body_eta => | ||
| have ⟨w, _⟩ := fresh_exists <| free_union [fv] Var | ||
| obtain ⟨K, h_beta, h_eta⟩ := ih w (by grind) (st_body_eta w (by grind)) | ||
| use abs (K ^* w) | ||
| constructor | ||
| · cases h_beta with | ||
| | refl => grind [open_close] | ||
| | single => exact .single (Xi.abs {w} (by grind [FullBeta.redex_subst_cong])) | ||
| · rw [open_close w N 0 (by grind)] | ||
| exact FullEta.redex_abs_close h_eta (FullBeta.step_lc_r (st_body_beta w (by grind))) | ||
|
|
||
| open Commute in | ||
| /-- βη-reduction is confluent. -/ | ||
| theorem confluent_beta_eta : Confluent (@FullBetaEta Var) := by | ||
| apply join_confluent | ||
| · exact confluence_beta | ||
| · exact stronglyConfluent_eta.toConfluent | ||
| exact symmetric stronglyCommute_eta_beta.toCommute | ||
|
|
||
| end LambdaCalculus.LocallyNameless.Untyped.Term | ||
|
|
||
| end Cslib | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
I know in a previous PR I mentioned proving
Xi r₁ ⊔ Xi r₂ = Xi (r₁ ⊔ r₂), but is this actually true generally? If so this could be written maybe slightly nicer asXi (Beta ⊔ Eta), but I got stuck on an abstraction case.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.
I agree that
Xi (Beta ⊔ Eta)is more elegant, but the abstraction case requires some heavy renaming lemmas. To keep this PR focused, I think sticking withFullBeta ⊔ FullEtais best for now. I'd be happy to tackle that refactor in a future PR! Let me know if everything else looks good to merge.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.
Sound good to me, I've sent to the merge queue. Great to see this complete! Please let me know if there's other work you're considering.