-
Notifications
You must be signed in to change notification settings - Fork 116
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
12
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
12 commits
Select commit
Hold shift + click to select a range
6102cf9
feat: Church–Rosser theorem (Q1308502) for ULC (de Bruijn)
zayn7lie 1c74c35
upd: change dir
zayn7lie d381f04
upd: localize from to
zayn7lie 67a3cb1
upd: eliminate for de bruijn syntax and explicit all and
zayn7lie 653d4dc
upd: eliminate for diamond and Confluent definition
zayn7lie fd07da0
upd: generalize decrement for consistency
zayn7lie 089b99a
upd: instantiate with
zayn7lie 901cf28
upd: newline between theorems
zayn7lie 28e7a79
upd: clean up `ConfluentReduction.lean` to `Cslib.Foundations.Data.Re…
zayn7lie d38b501
upd: clean up `ConfluentReduction.lean` to `Cslib.Foundations.Data.Re…
zayn7lie 45d3c75
upd: clarification for consistency of decre
zayn7lie 2c3aac6
upd: `reduction_sys` for generating notations for reductions and the …
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
95 changes: 95 additions & 0 deletions
95
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,95 @@ | ||
| /- | ||
| 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 | ||
|
|
||
| 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. | ||
| * `Lambda.BetaStar`: the reflexive-transitive closure of `Beta`. | ||
|
|
||
| ## Main lemmas | ||
|
|
||
| Inside `namespace BetaStar` we provide the standard constructors and congruence lemmas: | ||
|
|
||
| * `BetaStar.refl` | ||
| * `BetaStar.head` | ||
| * `BetaStar.tail` | ||
| * `BetaStar.trans` | ||
| * `BetaStar.appL`, `BetaStar.appR`, `BetaStar.app` | ||
| * `BetaStar.abs` | ||
|
|
||
| These lemmas are used later to compare β-reduction with parallel reduction. | ||
| -/ | ||
|
|
||
|
|
||
| namespace Lambda | ||
| open Term | ||
|
|
||
| /-- 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) | ||
| public abbrev BetaStar := Relation.ReflTransGen Beta | ||
|
|
||
| namespace BetaStar | ||
|
|
||
| public theorem refl (t : Term) : BetaStar t t := | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As a general style rule, please out a single space between theorems.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| Relation.ReflTransGen.refl | ||
|
|
||
| public theorem head {a b c} (hab : Beta a b) (hbc : BetaStar b c) : | ||
| BetaStar a c := | ||
| Relation.ReflTransGen.head hab hbc | ||
|
|
||
| public theorem tail {a b c} (hab : BetaStar a b) (hbc : Beta b c) : | ||
| BetaStar a c := | ||
| Relation.ReflTransGen.tail hab hbc | ||
|
|
||
| public theorem trans {a b c} | ||
| (hab : BetaStar a b) (hbc : BetaStar b c) : | ||
| BetaStar a c := | ||
| Relation.ReflTransGen.trans hab hbc | ||
|
|
||
| public theorem appL {t t' u : Term} (h : BetaStar t t') : | ||
| BetaStar (t·u) (t'·u) := by | ||
| induction h with | ||
| | refl => exact BetaStar.refl (t·u) | ||
| | tail hab hbc ih => exact BetaStar.tail ih (Beta.appL hbc) | ||
|
|
||
| public theorem appR {t u u' : Term} (h : BetaStar u u') : | ||
| BetaStar (t·u) (t·u') := by | ||
| induction h with | ||
| | refl => exact BetaStar.refl (t·u) | ||
| | tail hab hbc ih => exact BetaStar.tail ih (Beta.appR hbc) | ||
|
|
||
| public theorem app {t t' u u'} | ||
| (ht : BetaStar t t') | ||
| (hu : BetaStar u u') : | ||
| BetaStar (t·u) (t'·u') := by | ||
| induction ht with | ||
| | refl => exact BetaStar.appR hu | ||
| | tail hab hbc ih => exact BetaStar.tail ih (Beta.appL hbc) | ||
|
|
||
| public theorem abs {t t' : Term} (h : BetaStar t t') : | ||
| BetaStar (λ.t) (λ.t') := by | ||
| induction h with | ||
| | refl => exact BetaStar.refl (λ.t) | ||
| | tail hab hbc ih => exact BetaStar.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} : BetaStar a b ↔ ParStar 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' : ParStar a b := (hEq).1 hab | ||
| have hac' : ParStar 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.
We use the attribute
reduction_sysfor generating notations for reductions and the multi-step closure.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.
commits/2c3aac6ca1538a49b2fb26ad8f8196ecdc11b77b