chars
int64
40
24k
content_type
stringclasses
9 values
id
stringlengths
13
64
source
stringclasses
5 values
subset
stringclasses
31 values
text
stringlengths
40
24k
95
leanexplore_declaration
leanexplore:388275
leanexplore_sqlite
leanexplore_declarations
/-- Left congruence rule for application. -/ | appL: LC Z → Xi R M N → Xi R (app Z M) (app Z N)
97
leanexplore_declaration
leanexplore:388276
leanexplore_sqlite
leanexplore_declarations
/-- Right congruence rule for application. -/ | appR : LC Z → Xi R M N → Xi R (app M Z) (app N Z)
132
leanexplore_declaration
leanexplore:388277
leanexplore_sqlite
leanexplore_declarations
/-- The ξ (xi) rule for lambda terms. -/ | abs (xs : Finset Var) : (∀ x ∉ xs, Xi R (M ^ fvar x) (N ^ fvar x)) → Xi R (abs M) (abs N)
270
leanexplore_declaration
leanexplore:388278
leanexplore_sqlite
leanexplore_declarations
/-- The right side of a congruence step is locally closed. -/ @[scoped grind →] lemma step_lc_r (hR : ∀ {M' N'}, R M' N' → LC N') (step : Xi R M N) : LC N := by induction step with | base h => exact hR h | abs xs _ ih => constructor exact ih | _ => grind
197
leanexplore_declaration
leanexplore:388279
leanexplore_sqlite
leanexplore_declarations
/-- A single β-reduction step. -/ @[scoped grind] inductive Beta : Term Var → Term Var → Prop /-- Reduce an application to a lambda term. -/ | beta : LC (abs M)→ LC N → Beta (app (abs M) N) (M ^ N)
103
leanexplore_declaration
leanexplore:388280
leanexplore_sqlite
leanexplore_declarations
/-- Reduce an application to a lambda term. -/ | beta : LC (abs M)→ LC N → Beta (app (abs M) N) (M ^ N)
102
leanexplore_declaration
leanexplore:388281
leanexplore_sqlite
leanexplore_declarations
/-- Full β-reduction. -/ @[reduction_sys "βᶠ"] abbrev FullBeta : Term Var → Term Var → Prop := Xi Beta
77
leanexplore_declaration
leanexplore:388282
leanexplore_sqlite
leanexplore_declarations
@[reduction_sys "βᶠ"] abbrev FullBeta : Term Var → Term Var → Prop := Xi Beta
191
leanexplore_declaration
leanexplore:388284
leanexplore_sqlite
leanexplore_declarations
/-- The left side of a reduction is locally closed. -/ @[scoped grind →] lemma step_lc_l (step : M ⭢βᶠ M') : LC M := by induction step with | abs => constructor; assumption | _ => grind
199
leanexplore_declaration
leanexplore:388285
leanexplore_sqlite
leanexplore_declarations
/-- Left congruence rule for application in multiple reduction. -/ @[scoped grind ←] theorem redex_app_l_cong (redex : M ↠βᶠ M') (lc_N : LC N) : app M N ↠βᶠ app M' N := by induction redex <;> grind
200
leanexplore_declaration
leanexplore:388286
leanexplore_sqlite
leanexplore_declarations
/-- Right congruence rule for application in multiple reduction. -/ @[scoped grind ←] theorem redex_app_r_cong (redex : M ↠βᶠ M') (lc_N : LC N) : app N M ↠βᶠ app N M' := by induction redex <;> grind
323
leanexplore_declaration
leanexplore:388287
leanexplore_sqlite
leanexplore_declarations
@[scoped grind →] lemma invert_step_app_fvar (step : app M (fvar x) ⭢βᶠ N) : (∃ M', N = app M' (fvar x) ∧ M ⭢βᶠ M') ∨ (∃ M1, M = abs M1 ∧ N = M1 ^ fvar x) := by cases step case base h => cases h with | beta => exact .inr ⟨_, rfl, rfl⟩ case appR step_M _ => exact .inl ⟨_, rfl, step_M⟩ all_goals grind [cases ...
194
leanexplore_declaration
leanexplore:388288
leanexplore_sqlite
leanexplore_declarations
/-- The right side of a reduction is locally closed. -/ @[scoped grind →] lemma step_lc_r (step : M ⭢βᶠ M') : LC M' := by induction step case abs => constructor; assumption all_goals grind
98
leanexplore_declaration
leanexplore:388289
leanexplore_sqlite
leanexplore_declarations
lemma steps_lc_or_rfl {M M' : Term Var} (redex : M ↠βᶠ M') : (LC M ∧ LC M') ∨ M = M' := by grind
322
leanexplore_declaration
leanexplore:388290
leanexplore_sqlite
leanexplore_declarations
/-- Substitution of a locally closed term respects a single reduction step. -/ lemma redex_subst_cong_lc (s s' t : Term Var) (x : Var) (step : s ⭢βᶠ s') (h_lc : LC t) : s [ x := t ] ⭢βᶠ s' [ x := t ] := by induction step with | base => grind [subst_open] | abs => grind [Xi.abs <| free_union Var] | _ => gri...
238
leanexplore_declaration
leanexplore:388291
leanexplore_sqlite
leanexplore_declarations
/-- Substitution respects a single reduction step of a free variable. -/ lemma redex_subst_cong (s s' : Term Var) (x y : Var) (step : s ⭢βᶠ s') : s [ x := fvar y ] ⭢βᶠ s' [ x := fvar y ] := redex_subst_cong_lc _ _ _ _ step (.fvar y)
395
leanexplore_declaration
leanexplore:388292
leanexplore_sqlite
leanexplore_declarations
/-- An β-reduction step does not introduce new free variables. -/ lemma step_not_fv (step : M ⭢βᶠ N) (hw : w ∉ M.fv) : w ∉ N.fv := by induction step with | base h => cases h with | beta => grind [open_preserve_not_fvar] | abs => have ⟨x, _⟩ := fresh_exists <| free_union [fv] Var have := open_close x g...
186
leanexplore_declaration
leanexplore:388293
leanexplore_sqlite
leanexplore_declarations
/-- Abstracting then closing preserves a single reduction. -/ lemma step_abs_close {x : Var} (step : M ⭢βᶠ M') : M⟦0 ↜ x⟧.abs ⭢βᶠ M'⟦0 ↜ x⟧.abs := by grind [Xi.abs ∅, redex_subst_cong]
370
leanexplore_declaration
leanexplore:388294
leanexplore_sqlite
leanexplore_declarations
/-- Abstracting then closing preserves multiple reductions. -/ lemma redex_abs_close {x : Var} (step : M ↠βᶠ M') : (M⟦0 ↜ x⟧.abs ↠βᶠ M'⟦0 ↜ x⟧.abs) := by induction step using Relation.ReflTransGen.trans_induction_on case refl => rfl case single ih => exact Relation.ReflTransGen.single (step_abs_close ih) case ...
348
leanexplore_declaration
leanexplore:388295
leanexplore_sqlite
leanexplore_declarations
/-- Multiple reduction of opening implies multiple reduction of abstraction. -/ theorem step_abs_cong (xs : Finset Var) (cofin : ∀ x ∉ xs, (M ^ fvar x) ⭢βᶠ (M' ^ fvar x)) : M.abs ⭢βᶠ M'.abs := by have ⟨fresh, _⟩ := fresh_exists <| free_union [fv] Var rw [open_close fresh M 0 ?_, open_close fresh M' 0 ?_] all_...
350
leanexplore_declaration
leanexplore:388296
leanexplore_sqlite
leanexplore_declarations
/-- Multiple reduction of opening implies multiple reduction of abstraction. -/ theorem redex_abs_cong (xs : Finset Var) (cofin : ∀ x ∉ xs, (M ^ fvar x) ↠βᶠ (M' ^ fvar x)) : M.abs ↠βᶠ M'.abs := by have ⟨fresh, _⟩ := fresh_exists <| free_union [fv] Var rw [open_close fresh M 0 ?_, open_close fresh M' 0 ?_] all...
242
leanexplore_declaration
leanexplore:388297
leanexplore_sqlite
leanexplore_declarations
lemma step_open_cong_l (s s' t) (L : Finset Var) (step : ∀ x ∉ L, (s ^ fvar x) ⭢βᶠ (s' ^ fvar x)) (h_lc : LC t) : (s ^ t) ⭢βᶠ (s' ^ t) := by have ⟨x, _⟩ := fresh_exists <| free_union [fv] Var grind [subst_intro, redex_subst_cong_lc]
237
leanexplore_declaration
leanexplore:388298
leanexplore_sqlite
leanexplore_declarations
lemma invert_steps_abs {s t : Term Var} (step : s.abs ↠βᶠ t) : ∃ (s' : Term Var), s.abs ↠βᶠ s'.abs ∧ t = s'.abs := by induction step with | refl => grind | tail _ step _ => cases step with grind [step_abs_cong (free_union Var)]
412
leanexplore_declaration
leanexplore:388299
leanexplore_sqlite
leanexplore_declarations
lemma steps_open_cong_l_abs (s s' t : Term Var) (steps : s.abs ↠βᶠ s'.abs) (lc_s : LC s.abs) (lc_t : LC t) : (s ^ t) ↠βᶠ (s' ^ t) := by generalize eq : s.abs = s_abs at steps generalize eq' : s'.abs = s'_abs at steps induction steps generalizing s s' with | refl => grind | tail _ step ih => speciali...
371
leanexplore_declaration
leanexplore:388300
leanexplore_sqlite
leanexplore_declarations
lemma step_subst_cong_r {x : Var} (s t t' : Term Var) (step : t ⭢βᶠ t') (h_lc : LC s) : (s [ x := t ]) ↠βᶠ (s [ x := t' ]) := by induction h_lc with | fvar y => grind | abs => grind [redex_abs_cong (free_union Var)] | @app l r => calc (l.app r)[x:=t] ↠βᶠ l[x := t].app (r[x:=t']) := by grind ...
252
leanexplore_declaration
leanexplore:388301
leanexplore_sqlite
leanexplore_declarations
lemma steps_subst_cong_r {x : Var} (s t t' : Term Var) (step : t ↠βᶠ t') (h_lc : LC s) : (s [ x := t ]) ↠βᶠ (s [ x := t' ]) := by induction step with | refl => rfl | tail steps step ih => grind [Relation.ReflTransGen.trans, step_subst_cong_r]
437
leanexplore_declaration
leanexplore:388302
leanexplore_sqlite
leanexplore_declarations
lemma steps_open_cong_abs (s s' t t' : Term Var) (step1 : t ↠βᶠ t') (step2 : s.abs ↠βᶠ s'.abs) (lc_t : LC t) (lc_s : LC s.abs) : (s ^ t) ↠βᶠ (s' ^ t') := by cases lc_s with | abs L => have ⟨x, _⟩ := fresh_exists <| free_union [fv] Var rw [subst_intro x t s, subst_intro x t' s'] · trans (s ^ fvar x...
657
leanexplore_declaration
leanexplore:388303
leanexplore_sqlite
leanexplore_declarations
/-- A parallel β-reduction step. -/ @[reduction_sys "ₚ"] inductive Parallel : Term Var → Term Var → Prop /-- Free variables parallel step to themselves. -/ | fvar (x : Var) : Parallel (fvar x) (fvar x) /-- A parallel left and right congruence rule for application. -/ | app : Parallel L L' → Parallel M M' → Parallel (ap...
96
leanexplore_declaration
leanexplore:388304
leanexplore_sqlite
leanexplore_declarations
/-- Free variables parallel step to themselves. -/ | fvar (x : Var) : Parallel (fvar x) (fvar x)
136
leanexplore_declaration
leanexplore:388305
leanexplore_sqlite
leanexplore_declarations
/-- A parallel left and right congruence rule for application. -/ | app : Parallel L L' → Parallel M M' → Parallel (app L M) (app L' M')
146
leanexplore_declaration
leanexplore:388306
leanexplore_sqlite
leanexplore_declarations
/-- Congruence rule for lambda terms. -/ | abs (xs : Finset Var) : (∀ x ∉ xs, Parallel (m ^ fvar x) (m' ^ fvar x)) → Parallel (abs m) (abs m')
171
leanexplore_declaration
leanexplore:388307
leanexplore_sqlite
leanexplore_declarations
/-- A parallel β-reduction. -/ | beta (xs : Finset Var) : (∀ x ∉ xs, Parallel (m ^ fvar x) (m' ^ fvar x) ) → Parallel n n' → Parallel (app (abs m) n) (m' ^ n')
893
leanexplore_declaration
leanexplore:388308
leanexplore_sqlite
leanexplore_declarations
@[reduction_sys "ₚ"] inductive Parallel : Term Var → Term Var → Prop /-- Free variables parallel step to themselves. -/ | fvar (x : Var) : Parallel (fvar x) (fvar x) /-- A parallel left and right congruence rule for application. -/ | app : Parallel L L' → Parallel M M' → Parallel (app L M) (app L' M') /-- Congruence ru...
273
leanexplore_declaration
leanexplore:388310
leanexplore_sqlite
leanexplore_declarations
/-- The left side of a parallel reduction is locally closed. -/ @[scoped grind →] lemma para_lc_l (step : M ⭢ₚ N) : LC M := by induction step case abs _ _ xs _ ih => exact LC.abs xs _ ih case beta => refine LC.app (LC.abs ?_ _ ?_) ?_ <;> assumption all_goals grind
201
leanexplore_declaration
leanexplore:388311
leanexplore_sqlite
leanexplore_declarations
/-- Parallel reduction is reflexive for locally closed terms. -/ @[scoped grind →] lemma Parallel.lc_refl (M : Term Var) (lc : LC M) : M ⭢ₚ M := by induction lc all_goals constructor <;> assumption
274
leanexplore_declaration
leanexplore:388312
leanexplore_sqlite
leanexplore_declarations
/-- The right side of a parallel reduction is locally closed. -/ @[scoped grind →] lemma para_lc_r (step : M ⭢ₚ N) : LC N := by induction step case abs _ _ xs _ ih => exact LC.abs xs _ ih case beta => refine beta_lc (LC.abs ?_ _ ?_) ?_ <;> assumption all_goals grind
322
leanexplore_declaration
leanexplore:388313
leanexplore_sqlite
leanexplore_declarations
/-- A single β-reduction implies a single parallel reduction. -/ lemma step_to_para (step : M ⭢βᶠ N) : M ⭢ₚ N := by induction step with | base h => cases h with | beta abs_lc _ => cases abs_lc with | abs xs _ => apply Parallel.beta xs <;> grind | abs xs _ _ => apply Parallel.abs xs; grind | _ => gri...
729
leanexplore_declaration
leanexplore:388314
leanexplore_sqlite
leanexplore_declarations
/-- A single parallel reduction implies a multiple β-reduction. -/ lemma para_to_redex (para : M ⭢ₚ N) : M ↠βᶠ N := by induction para case fvar => constructor case app L L' R R' l_para m_para redex_l redex_m => have : L.app R ↠βᶠ L'.app R := by grind grind [ReflTransGen.trans] case abs t t' xs _ ih => ...
383
leanexplore_declaration
leanexplore:388315
leanexplore_sqlite
leanexplore_declarations
/-- Multiple parallel reduction is equivalent to multiple β-reduction. -/ theorem parachain_iff_redex : M ↠ₚ N ↔ M ↠βᶠ N := by refine Iff.intro ?chain_redex ?redex_chain <;> intros h <;> induction h <;> try rfl case redex_chain redex chain => exact ReflTransGen.tail chain (step_to_para redex) case chain_redex par...
387
leanexplore_declaration
leanexplore:388316
leanexplore_sqlite
leanexplore_declarations
/-- Parallel reduction respects substitution. -/ @[scoped grind .] lemma para_subst (x : Var) (pm : M ⭢ₚ M') (pn : N ⭢ₚ N') : M[x := N] ⭢ₚ M'[x := N'] := by induction pm with | beta => rw [subst_open _ _ _ _ (by grind)] refine Parallel.beta (free_union Var) ?_ ?_ <;> grind | app => constructor <;> assumpt...
167
leanexplore_declaration
leanexplore:388317
leanexplore_sqlite
leanexplore_declarations
/-- Parallel substitution respects closing and opening. -/ lemma para_open_close (x y z) (para : M ⭢ₚ M') : M⟦z ↜ x⟧⟦z ↝ fvar y⟧ ⭢ₚ M'⟦z ↜ x⟧⟦z ↝ fvar y⟧ := by grind
234
leanexplore_declaration
leanexplore:388318
leanexplore_sqlite
leanexplore_declarations
/-- Parallel substitution respects fresh opening. -/ lemma para_open_out (L : Finset Var) (mem : ∀ x, x ∉ L → (M ^ fvar x) ⭢ₚ N ^ fvar x) (para : M' ⭢ₚ N') : (M ^ M') ⭢ₚ (N ^ N') := by grind [fresh_exists <| free_union [fv] Var]
2,536
leanexplore_declaration
leanexplore:388319
leanexplore_sqlite
leanexplore_declarations
/-- Parallel reduction has the diamond property. -/ theorem para_diamond : Diamond (@Parallel Var) := by intros t t1 t2 tpt1 revert t2 induction tpt1 <;> intros t2 tpt2 case fvar x => exact ⟨t2, by grind⟩ case abs s1 s2' xs mem ih => cases tpt2 case abs t2' xs' mem' => have ⟨x, qx⟩ := fresh_exis...
121
leanexplore_declaration
leanexplore:388320
leanexplore_sqlite
leanexplore_declarations
/-- Parallel reduction is confluent. -/ theorem para_confluence : Confluent (@Parallel Var) := para_diamond.toConfluent
252
leanexplore_declaration
leanexplore:388321
leanexplore_sqlite
leanexplore_declarations
/-- β-reduction is confluent. -/ theorem confluence_beta : Confluent (@FullBeta Var) := by have eq : ReflTransGen (@Parallel Var) = ReflTransGen (@FullBeta Var) := by ext exact parachain_iff_redex rw [Confluent, ←eq] exact para_confluence
118
leanexplore_declaration
leanexplore:388322
leanexplore_sqlite
leanexplore_declarations
/-- Full βη-reduction. -/ @[reduction_sys "βηᶠ"] abbrev FullBetaEta : Term Var → Term Var → Prop := FullBeta ⊔ FullEta
92
leanexplore_declaration
leanexplore:388323
leanexplore_sqlite
leanexplore_declarations
@[reduction_sys "βηᶠ"] abbrev FullBetaEta : Term Var → Term Var → Prop := FullBeta ⊔ FullEta
2,081
leanexplore_declaration
leanexplore:388325
leanexplore_sqlite
leanexplore_declarations
/-- η-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 _ _...
243
leanexplore_declaration
leanexplore:388326
leanexplore_sqlite
leanexplore_declarations
/-- βη-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
199
leanexplore_declaration
leanexplore:388327
leanexplore_sqlite
leanexplore_declarations
/-- A single η-reduction step. -/ @[scoped grind] inductive Eta : Term Var → Term Var → Prop /-- The eta rule: λx. M x ⟶ M, provided x is not free in M. -/ | eta : LC M → Eta (abs (app M (bvar 0))) M
106
leanexplore_declaration
leanexplore:388328
leanexplore_sqlite
leanexplore_declarations
/-- The eta rule: λx. M x ⟶ M, provided x is not free in M. -/ | eta : LC M → Eta (abs (app M (bvar 0))) M
154
leanexplore_declaration
leanexplore:388329
leanexplore_sqlite
leanexplore_declarations
/-- Full η-reduction, defined as the congruence closure of the base η-rule. -/ @[reduction_sys "ηᶠ"] abbrev FullEta : Term Var → Term Var → Prop := Xi Eta
75
leanexplore_declaration
leanexplore:388330
leanexplore_sqlite
leanexplore_declarations
@[reduction_sys "ηᶠ"] abbrev FullEta : Term Var → Term Var → Prop := Xi Eta
162
leanexplore_declaration
leanexplore:388332
leanexplore_sqlite
leanexplore_declarations
/-- The right side of an η-reduction is locally closed. -/ @[scoped grind →] lemma step_lc_r (step : M ⭢ηᶠ M') : LC M' := by refine Xi.step_lc_r ?_ step grind
181
leanexplore_declaration
leanexplore:388333
leanexplore_sqlite
leanexplore_declarations
/-- Left congruence rule for application in multiple reduction. -/ theorem redex_app_l_cong (redex : M ↠ηᶠ M') (lc_N : LC N) : app M N ↠ηᶠ app M' N := by induction redex <;> grind
182
leanexplore_declaration
leanexplore:388334
leanexplore_sqlite
leanexplore_declarations
/-- Right congruence rule for application in multiple reduction. -/ theorem redex_app_r_cong (redex : M ↠ηᶠ M') (lc_N : LC N) : app N M ↠ηᶠ app N M' := by induction redex <;> grind
213
leanexplore_declaration
leanexplore:388335
leanexplore_sqlite
leanexplore_declarations
@[scoped grind →] lemma invert_step_app_fvar (step : (app M (fvar x)) ⭢ηᶠ N) : ∃ M', N = app M' (fvar x) ∧ M ⭢ηᶠ M' := by cases step with | appR _ step_M => exact ⟨_, rfl, step_M⟩ | _ => grind [cases Xi]
347
leanexplore_declaration
leanexplore:388336
leanexplore_sqlite
leanexplore_declarations
/-- An η-reduction step does not introduce new free variables. -/ lemma step_not_fv (step : M ⭢ηᶠ M') (hw : w ∉ M.fv) : w ∉ M'.fv := by induction step with | base => grind | abs => have ⟨x, _⟩ := fresh_exists <| free_union [fv] Var have := open_close x grind [close_preserve_not_fvar, open_fresh_preser...
269
leanexplore_declaration
leanexplore:388337
leanexplore_sqlite
leanexplore_declarations
/-- Substitution of a fresh variable preserves an η-reduction step. -/ @[scoped grind ←] lemma eta_subst_fvar {x y : Var} (step : M ⭢ηᶠ M') : M [ x := fvar y ] ⭢ηᶠ M' [ x := fvar y ] := by induction step with | abs => grind [Xi.abs <| free_union Var] | _ => grind
183
leanexplore_declaration
leanexplore:388338
leanexplore_sqlite
leanexplore_declarations
/-- Abstracting then closing preserves a single η-reduction step. -/ lemma step_abs_close {x} (step : M ⭢ηᶠ M') (lc_M : LC M) : (M ^* x).abs ⭢ηᶠ (M' ^* x).abs := by grind [Xi.abs ∅]
344
leanexplore_declaration
leanexplore:388339
leanexplore_sqlite
leanexplore_declarations
/-- Abstracting then closing preserves multiple reductions. -/ lemma redex_abs_close {x} (steps : M ↠ηᶠ M') (lc_M : LC M) : (M ^* x).abs ↠ηᶠ (M' ^* x).abs := by induction steps using Relation.ReflTransGen.head_induction_on case refl => exact .refl case head b c st_bc _ ih => exact .head (step_abs_close st_bc lc_M...
440
leanexplore_declaration
leanexplore:388340
leanexplore_sqlite
leanexplore_declarations
/-- Multiple reduction of opening implies multiple reduction of abstraction. -/ theorem redex_abs_cong {M M' : Term Var} (xs : Finset Var) (cofin : ∀ x ∉ xs, (M ^ fvar x) ↠ηᶠ M' ^ fvar x) (lc_M : LC M.abs) : M.abs ↠ηᶠ M'.abs := by cases lc_M case abs L hL => have ⟨x, _⟩ := fresh_exists <| free_union [fv...
611
leanexplore_declaration
leanexplore:388341
leanexplore_sqlite
leanexplore_declarations
lemma step_subst_cong_r {x : Var} (s t t' : Term Var) (st : t ⭢ηᶠ t') (lc_s : LC s) (lc_t : LC t) : s [ x := t ] ↠ηᶠ s [ x := t' ] := by induction lc_s generalizing t t' with | fvar => grind | app hl hr ih_l ih_r => trans · exact redex_app_l_cong (ih_l t t' st lc_t) (subst_lc hr lc_t) · exact rede...
320
leanexplore_declaration
leanexplore:388342
leanexplore_sqlite
leanexplore_declarations
lemma steps_subst_cong_r {x : Var} (s t t' : Term Var) (st : t ↠ηᶠ t') (lc_s : LC s) (lc_t : LC t) : s [ x := t ] ↠ηᶠ s [ x := t' ] := by induction st using Relation.ReflTransGen.head_induction_on case refl => rfl case head _ _ st _ ih => exact .trans (step_subst_cong_r s _ _ st lc_s lc_t) (ih (step_lc_r st))
287
leanexplore_declaration
leanexplore:388343
leanexplore_sqlite
leanexplore_declarations
lemma step_open_cong_r {s t t' : Term Var} (lc_s : LC s.abs) (lc_t : LC t) (step : t ⭢ηᶠ t') : (s ^ t) ↠ηᶠ s ^ t' := by cases lc_s case abs L hL => have ⟨x, _⟩ := fresh_exists <| free_union [fv] Var grind [step_subst_cong_r (x := x) (s ^ fvar x) t t' step (hL x ?_) lc_t]
300
leanexplore_declaration
leanexplore:388344
leanexplore_sqlite
leanexplore_declarations
lemma steps_open_cong_r {s t t' : Term Var} (lc_s : LC s.abs) (lc_t : LC t) (steps : t ↠ηᶠ t') : (s ^ t) ↠ηᶠ s ^ t' := by induction steps using Relation.ReflTransGen.head_induction_on case refl => rfl case head _ _ st _ ih => exact .trans (step_open_cong_r lc_s lc_t st) (ih (step_lc_r st))
245
leanexplore_declaration
leanexplore:388345
leanexplore_sqlite
leanexplore_declarations
lemma close_eta_steps (hx_M : x ∉ M.fv) (st_M : ReflGen FullEta (M ^ fvar x) N) : ReflGen FullEta M.abs (N ^* x).abs := by cases st_M with | refl => rw [←open_close_var x M hx_M] | single st => exact .single (Xi.abs {x} (by grind))
308
leanexplore_declaration
leanexplore:388346
leanexplore_sqlite
leanexplore_declarations
lemma step_subst_cong_l {x : Var} (s s' N : Term Var) (step : s ⭢ηᶠ s') (lc_N : LC N) : s [ x := N ] ⭢ηᶠ s' [ x := N ] := by induction step case base h => cases h with | eta lc => exact Xi.base (.eta (subst_lc lc lc_N)) case abs => grind [Xi.abs <| free_union Var, subst_open_var] all_goals grind
217
leanexplore_declaration
leanexplore:388347
leanexplore_sqlite
leanexplore_declarations
lemma steps_subst_cong_l {x : Var} (s s' N : Term Var) (steps : s ↠ηᶠ s') (lc_N : LC N) : s [ x := N ] ↠ηᶠ s' [ x := N ] := by induction steps with | refl => rfl | tail _ step ih => grind [step_subst_cong_l]
1,412
leanexplore_declaration
leanexplore:388348
leanexplore_sqlite
leanexplore_declarations
lemma stronglyConfluent_eta : StronglyConfluent (@FullEta Var) := by intro _ y z h₁ h₂ suffices ∃ w, ReflGen FullEta y w ∧ ReflGen FullEta z w by grind induction h₁ generalizing z case base h1_b => cases h1_b case eta M _ => cases h₂ case base => use (disch := grind) M case abs _ _ st_...
237
leanexplore_declaration
leanexplore:388349
leanexplore_sqlite
leanexplore_declarations
/-- `LcAt k M` is satisfied when all bound indices of M are smaller than `k`. -/ @[simp, scoped grind =] def LcAt (k : ℕ) : Term Var → Prop | bvar i => i < k | fvar _ => True | app t₁ t₂ => LcAt k t₁ ∧ LcAt k t₂ | abs t => LcAt (k + 1) t
226
leanexplore_declaration
leanexplore:388350
leanexplore_sqlite
leanexplore_declarations
/-- `depth` counts the maximum number of the lambdas that are enclosing variables. -/ @[simp, scoped grind =] def depth : Term Var → ℕ | bvar _ => 0 | fvar _ => 0 | app t₁ t₂ => max (depth t₁) (depth t₂) | abs t => depth t + 1
421
leanexplore_declaration
leanexplore:388351
leanexplore_sqlite
leanexplore_declarations
@[elab_as_elim] protected lemma ind_on_depth (P : Term Var → Prop) (bvar : ∀ i, P (bvar i)) (fvar : ∀ x, P (fvar x)) (app : ∀ M N, P M → P N → P (app M N)) (abs : ∀ M, P M → (∀ N, N.depth ≤ M.depth → P N) → P M.abs) (M : Term Var) : P M := by induction h : M.depth using Nat.strong_induction_on generalizin...
290
leanexplore_declaration
leanexplore:388352
leanexplore_sqlite
leanexplore_declarations
/-- The depth of the lambda expression doesn't change by opening at i-th bound variable for some free variable. -/ @[simp, scoped grind =] lemma depth_openRec_fvar_eq_depth (M : Term Var) (x : Var) (i : ℕ) : (M⟦i ↝ fvar x⟧).depth = M.depth := by induction M generalizing i <;> grind
219
leanexplore_declaration
leanexplore:388353
leanexplore_sqlite
leanexplore_declarations
/-- The depth of the lambda expression doesn't change by opening for some free variable. -/ theorem depth_open_fvar_eq_depth (M : Term Var) (x : Var) : depth (M ^ fvar x) = depth M := depth_openRec_fvar_eq_depth M x 0
263
leanexplore_declaration
leanexplore:388354
leanexplore_sqlite
leanexplore_declarations
/-- Opening for some free variable at i-th bound variable, increments `LcAt`. -/ @[simp, scoped grind =] theorem lcAt_openRec_fvar_iff_lcAt (M : Term Var) (x : Var) (i : ℕ) : LcAt i (M⟦i ↝ fvar x⟧) ↔ LcAt (i + 1) M := by induction M generalizing i <;> grind
215
leanexplore_declaration
leanexplore:388355
leanexplore_sqlite
leanexplore_declarations
/-- Opening for some free variable is locally closed if and only if `M` is `LcAt 1`. -/ theorem lcAt_open_fvar_iff_lcAt (M : Term Var) (x : Var) : LcAt 0 (M ^ fvar x) ↔ LcAt 1 M := lcAt_openRec_fvar_iff_lcAt M x 0
383
leanexplore_declaration
leanexplore:388356
leanexplore_sqlite
leanexplore_declarations
/-- `M` is `LcAt 0` if and only if `M` is locally closed. -/ theorem lcAt_iff_LC (M : Term Var) [HasFresh Var] : LcAt 0 M ↔ M.LC := by induction M using LambdaCalculus.LocallyNameless.Untyped.Term.ind_on_depth with | abs => constructor · grind [LC.abs ∅] · intros h2 rcases h2 with ⟨⟩|⟨L,...
134
leanexplore_declaration
leanexplore:388357
leanexplore_sqlite
leanexplore_declarations
lemma lcAt_openRec_lcAt (M N : Term Var) (i : ℕ) : LcAt i (M⟦i ↝ N⟧) → LcAt (i + 1) M := by induction M generalizing i <;> grind
149
leanexplore_declaration
leanexplore:388358
leanexplore_sqlite
leanexplore_declarations
lemma open_abs_lc [HasFresh Var] {M N : Term Var} (hlc : LC (M ^ N)) : LC (M.abs) := by rw [← lcAt_iff_LC] at * exact lcAt_openRec_lcAt _ _ _ hlc
275
leanexplore_declaration
leanexplore:388359
leanexplore_sqlite
leanexplore_declarations
/-- multiApp f [x₁, x₂, ..., xₙ] applies the arguments x₁, x₂, ..., xₙ to f in left-associative order, i.e. as (((f x₁) x₂) ... xₙ). -/ @[simp, scoped grind =] def multiApp (f : Term Var) : List (Term Var) → Term Var | [] => f | a :: as => Term.app (multiApp f as) a
666
leanexplore_declaration
leanexplore:388360
leanexplore_sqlite
leanexplore_declarations
/-- A list of arguments performs a single reduction step [x₁, ..., xᵢ ..., xₙ] ⭢βᶠ [x₁, ..., xᵢ', ..., xₙ] if one of the arguments performs a single step xᵢ ⭢βᶠ xᵢ' and the rest of the arguments are locally closed. -/ @[scoped grind, reduction_sys "lβᶠ"] inductive ListFullBeta : List (Term Var) → List (Te...
158
leanexplore_declaration
leanexplore:388361
leanexplore_sqlite
leanexplore_declarations
/-- head of the list performs a single reduction step, the rest are locally closed -/ | step : N ⭢βᶠ N' → (∀ N ∈ Ns, LC N) → ListFullBeta (N :: Ns) (N' :: Ns)
166
leanexplore_declaration
leanexplore:388362
leanexplore_sqlite
leanexplore_declarations
/-- given a list that already contains a step, we can add locally closed terms to the front -/ | cons : LC N → ListFullBeta Ns Ns' → ListFullBeta (N :: Ns) (N :: Ns')
734
leanexplore_declaration
leanexplore:388363
leanexplore_sqlite
leanexplore_declarations
@[scoped grind, reduction_sys "lβᶠ"] inductive ListFullBeta : List (Term Var) → List (Term Var) → Prop where /-- head of the list performs a single reduction step, the rest are locally closed -/ | step : N ⭢βᶠ N' → (∀ N ∈ Ns, LC N) → ListFullBeta (N :: Ns) (N' :: Ns) /-- given a list that already contains a step, we ca...
280
leanexplore_declaration
leanexplore:388365
leanexplore_sqlite
leanexplore_declarations
/-- A term resulting from a multi-application is locally closed if and only if the leftmost term and all arguments applied to it are locally closed -/ @[scoped grind ←] lemma multiApp_lc : LC (M.multiApp Ns) ↔ LC M ∧ (∀ N ∈ Ns, LC N) := by induction Ns with grind [cases LC]
264
leanexplore_declaration
leanexplore:388366
leanexplore_sqlite
leanexplore_declarations
/-- Just like ordinary beta reduction, the left-hand side of a multi-application step is locally closed -/ @[scoped grind ←] lemma step_multiApp_l (steps : M ⭢βᶠ M') (lc_Ns : ∀ N ∈ Ns, LC N) : M.multiApp Ns ⭢βᶠ M'.multiApp Ns := by induction Ns <;> grind
228
leanexplore_declaration
leanexplore:388367
leanexplore_sqlite
leanexplore_declarations
/-- Congruence lemma for multi reduction of the left most term of a multi-application -/ lemma steps_multiApp_l (steps : M ↠βᶠ M') (lc_Ns : ∀ N ∈ Ns, LC N) : M.multiApp Ns ↠βᶠ M'.multiApp Ns := by induction steps <;> grind
236
leanexplore_declaration
leanexplore:388368
leanexplore_sqlite
leanexplore_declarations
/-- Congruence lemma for single reduction of one of the arguments of a multi-application -/ @[scoped grind ←] lemma step_multiApp_r (steps : Ns ⭢lβᶠ Ns') (lc_M : LC M) : M.multiApp Ns ⭢βᶠ M.multiApp Ns' := by induction steps <;> grind
221
leanexplore_declaration
leanexplore:388369
leanexplore_sqlite
leanexplore_declarations
/-- Congruence lemma for multiple reduction of one of the arguments of a multi-application -/ lemma steps_multiApp_r (steps : Ns ↠lβᶠ Ns') (lc_M : LC M) : M.multiApp Ns ↠βᶠ M.multiApp Ns' := by induction steps <;> grind
974
leanexplore_declaration
leanexplore:388370
leanexplore_sqlite
leanexplore_declarations
/-- If a term (λ M) N P_1 ... P_n reduces in a single step to Q, then Q must be one of the following forms: Q = (λ M') N P₁ ... Pₙ where M ⭢βᶠ M' or Q = (λ M) N' P₁ ... Pₙ where N ⭢βᶠ N' or Q = (λ M) N P₁' ... Pₙ' where P_i ⭢βᶠ P_i' for some i or Q = (M ^ N) P₁ ... Pₙ -/ lemma invert_abs_multiApp_s...
1,004
leanexplore_declaration
leanexplore:388371
leanexplore_sqlite
leanexplore_declarations
/-- If a term (λ M) N P₁ ... Pₙ reduces in multiple steps to Q, then either Q if of the form Q = (λ M') N' P'₁ ... P'ₙ or we first reach an intermediate term of this shape, (λ M) N P₁ ... Pₙ ↠βᶠ (λ M') N' P'₁ ... P'ₙ then perform a beta reduction and reduce further to Q (λ M') N'...
229
leanexplore_declaration
leanexplore:388372
leanexplore_sqlite
leanexplore_declarations
/-- Just like ordinary beta reduction, the right-hand side of a multi-application step is locally closed -/ lemma multiApp_step_lc_r (step : Ns ⭢lβᶠ Ns') : ∀ N ∈ Ns', LC N := by induction step <;> grind [FullBeta.step_lc_r]
257
leanexplore_declaration
leanexplore:388373
leanexplore_sqlite
leanexplore_declarations
/-- Just like ordinary beta reduction, multiple steps of a argument list preserves local closure -/ lemma multiApp_steps_lc (step : Ns ↠lβᶠ Ns') (H : ∀ N ∈ Ns, LC N) : ∀ N ∈ Ns', LC N := by induction step <;> grind [FullBeta.step_lc_r, multiApp_step_lc_r]
191
leanexplore_declaration
leanexplore:388374
leanexplore_sqlite
leanexplore_declarations
/-- An environment in context of multi substition is a list of pairs of variable targets and terms to be substituted for that target -/ abbrev Env (Var : Type u) := Context Var (Term Var)
265
leanexplore_declaration
leanexplore:388375
leanexplore_sqlite
leanexplore_declarations
/-- Multi-substitution substitutes all target variables in an environment by their corresponding terms -/ @[scoped grind =] def multiSubst (E : Env Var) (M : Term Var) : Term Var := match E with | [] => M | ⟨i, sub⟩ :: E' => (multiSubst E' M) [ i := sub ]
282
leanexplore_declaration
leanexplore:388376
leanexplore_sqlite
leanexplore_declarations
/-- The free variables of an environment are the union of the free variables of all terms in the environment. The target variables are not necessarily included -/ def Env.fv (E : Env Var) : Finset Var := match E with | [] => {} | ⟨ _, sub ⟩ :: E' => sub.fv ∪ Env.fv E'
155
leanexplore_declaration
leanexplore:388377
leanexplore_sqlite
leanexplore_declarations
/-- An environment is locally closed if all terms in the environment are locally closed -/ abbrev env_LC (E : Env Var) : Prop := ∀ {x M}, ⟨x, M⟩ ∈ E → LC M
172
leanexplore_declaration
leanexplore:388378
leanexplore_sqlite
leanexplore_declarations
/-- Adding a locally closed term to an environment preserves local closure -/ lemma env_LC_cons (lc_sub : LC sub) (lc_E : env_LC E) : env_LC (⟨ x, sub ⟩ :: E) := by grind
177
leanexplore_declaration
leanexplore:388379
leanexplore_sqlite
leanexplore_declarations
/-- Multi-substitution of a fresh variable does nothing -/ lemma multiSubst_fvar_fresh (E : Env Var) : ∀ x ∉ E.dom, multiSubst E (fvar x) = fvar x := by induction E with grind