-
Notifications
You must be signed in to change notification settings - Fork 130
feat: de Bruijn Syntax for Untyped Lambda Calculus and a proof of Church-Rosser with Parallel Reduction #475
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
Open
zayn7lie
wants to merge
13
commits into
leanprover:main
Choose a base branch
from
zayn7lie:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
2cc8ebc
feat: Church–Rosser theorem (Q1308502) for ULC (de Bruijn)
zayn7lie df78d25
upd: change dir
zayn7lie 7c62711
upd: localize from to
zayn7lie 4e20051
upd: eliminate for de bruijn syntax and explicit all and
zayn7lie a551bd9
upd: eliminate for diamond and Confluent definition
zayn7lie c89adac
upd: generalize decrement for consistency
zayn7lie 3f03614
upd: instantiate with
zayn7lie 231440b
upd: newline between theorems
zayn7lie e5c5bbd
upd: clean up `ConfluentReduction.lean` to `Cslib.Foundations.Data.Re…
zayn7lie c33e118
upd: clean up `ConfluentReduction.lean` to `Cslib.Foundations.Data.Re…
zayn7lie fae2be0
upd: clarification for consistency of decre
zayn7lie d106175
upd: `reduction_sys` for generating notations for reductions and the …
zayn7lie 91db832
fix: notation typeclass for substitution
zayn7lie 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
72 changes: 72 additions & 0 deletions
72
Cslib/Languages/LambdaCalculus/Unscoped/Untyped/BetaReduction.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,72 @@ | ||
| /- | ||
| Copyright (c) 2026 zayn7lie. All rights reserved. | ||
| Released under Apache 2.0 license as described in the file LICENSE. | ||
| Authors: Zayn Wang | ||
| -/ | ||
| module | ||
|
|
||
| public import Cslib.Languages.LambdaCalculus.Unscoped.Untyped.DeBruijnSyntax | ||
| public import Cslib.Foundations.Data.Relation | ||
|
|
||
| /-! | ||
| # One-step β-reduction and its reflexive-transitive closure (Star) | ||
|
|
||
| This file defines the usual compatible one-step β-reduction on de Bruijn lambda terms. | ||
| It also introduces its reflexive-transitive closure and proves basic closure lemmas for | ||
| application and abstraction. | ||
|
|
||
| ## Main definitions | ||
|
|
||
| * `Lambda.Beta`: one-step β-reduction. | ||
|
|
||
| ## Main lemmas | ||
|
|
||
| Inside `namespace BetaStar` we provide the standard constructors and congruence lemmas: | ||
|
|
||
| * `BetaStar.appL`, `BetaStar.appR`, `BetaStar.app`, `BetaStar.abs` | ||
|
|
||
| These lemmas are used later to compare β-reduction with parallel reduction. | ||
| -/ | ||
|
|
||
|
|
||
| namespace Lambda | ||
| open Term | ||
| open Relation.ReflTransGen | ||
|
|
||
| /-- One-step β-reduction (compatible closure). -/ | ||
| @[reduction_sys "β"] | ||
| public inductive Beta : Term → Term → Prop | ||
| | abs {t t'} : Beta t t' → Beta (λ.t) (λ.t') | ||
| | appL {t t' u} : Beta t t' → Beta (t·u) (t'·u) | ||
| | appR {t u u'} : Beta u u' → Beta (t·u) (t·u') | ||
| | red (t' s : Term) : Beta ((λ.t')·s) (t'.sub 0 s) | ||
|
|
||
| namespace BetaStar | ||
|
|
||
| public theorem appL {t t' u : Term} (h : t ↠β t') : | ||
| (t·u) ↠β (t'·u) := by | ||
| induction h with | ||
| | refl => exact refl (t·u) | ||
| | tail hab hbc ih => exact tail ih (Beta.appL hbc) | ||
|
|
||
| public theorem appR {t u u' : Term} (h : u ↠β u') : | ||
| (t·u) ↠β (t·u') := by | ||
| induction h with | ||
| | refl => exact refl (t·u) | ||
| | tail hab hbc ih => exact tail ih (Beta.appR hbc) | ||
|
|
||
| public theorem app {t t' u u'} | ||
| (ht : t ↠β t') (hu : u ↠β u') : | ||
| (t·u) ↠β (t'·u') := by | ||
| induction ht with | ||
| | refl => exact appR hu | ||
| | tail hab hbc ih => exact tail ih (Beta.appL hbc) | ||
|
|
||
| public theorem abs {t t' : Term} (h : t ↠β t') : | ||
| (λ.t) ↠β (λ.t') := by | ||
| induction h with | ||
| | refl => exact refl (λ.t) | ||
| | tail hab hbc ih => exact tail ih (Beta.abs hbc) | ||
|
|
||
| end BetaStar | ||
| end Lambda |
58 changes: 58 additions & 0 deletions
58
Cslib/Languages/LambdaCalculus/Unscoped/Untyped/ChurchRosser.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,58 @@ | ||
| /- | ||
| Copyright (c) 2026 zayn7lie. All rights reserved. | ||
| Released under Apache 2.0 license as described in the file LICENSE. | ||
| Authors: Zayn Wang | ||
| -/ | ||
| module | ||
|
|
||
| public import Cslib.Foundations.Data.Relation | ||
| public import Cslib.Languages.LambdaCalculus.Unscoped.Untyped.ParallelReduction | ||
|
|
||
| /-! | ||
| # The Church–Rosser theorem for β-reduction | ||
|
|
||
| This file proves confluence of β-reduction on de Bruijn lambda terms. The proof follows | ||
| the classical route: | ||
|
|
||
| 1. define parallel β-reduction, | ||
| 2. show that parallel reduction has the diamond property using complete developments, | ||
| 3. compare parallel reduction with ordinary β-reduction via reflexive-transitive closure, | ||
| 4. transport confluence back to β-reduction. | ||
|
|
||
| ## Main results | ||
|
|
||
| * `diamond_par`: parallel reduction is diamond. | ||
| * `churchRosser_beta`: β-reduction is confluent. | ||
|
|
||
| ## Implementation note | ||
|
|
||
| The proof relies on the generic rewriting lemmas from `ConfluentReduction` together with | ||
| the complete-development machinery from `ParallelReduction`. | ||
| -/ | ||
|
|
||
| namespace Lambda | ||
| open Relation | ||
|
|
||
| /-- Parallel Reduction is Diamond. -/ | ||
| private lemma diamond_par : Diamond Par := by | ||
| intro a b c hab hac | ||
| exact ⟨a.dev, par_to_dev hab, par_to_dev hac⟩ | ||
|
|
||
| /-- Church–Rosser: β is confluent (on RTC). -/ | ||
| public theorem churchRosser_beta : Confluent Beta := by | ||
| -- Confluence of Par from diamond | ||
| have hPar : Confluent Par := | ||
| Diamond.toConfluent (r := Par) diamond_par | ||
| -- Identify BetaStar and ParStar via sandwich | ||
| have hEq {a b : Term} : a ↠β b ↔ a ↠∥ b := | ||
| ReflTransGen.sandwich_to_eq (r := Beta) (p := Par) | ||
| (by intro a b h; exact beta_subset_par h) | ||
| (by intro a b h; exact par_subset_betaStar h) | ||
| -- Transport confluence | ||
| intro a b c hab hac | ||
| have hab' : a ↠∥ b := (hEq).1 hab | ||
| have hac' : a ↠∥ c := (hEq).1 hac | ||
| rcases hPar hab' hac' with ⟨d, hbd, hcd⟩ | ||
| exact ⟨d, (hEq).2 hbd, (hEq).2 hcd⟩ | ||
|
|
||
| end Lambda |
Oops, something went wrong.
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.
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.
Perhaps better as
I think this was discussed on Zulip?
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.
Yes, this thread. I'd use the naming and shorter proof discussed there as well.