1+ module
2+
13import Cslib.Foundations.Data.Relation
24import Cslib.Languages.LambdaCalculus.LocallyNameless.Stlc.Basic
35import Cslib.Languages.LambdaCalculus.LocallyNameless.Untyped.FullBeta
@@ -21,10 +23,10 @@ open scoped Term
2123
2224abbrev Environment (Var : Type u) := Context Var (Term Var)
2325
24- def multi_subst (σ : Environment Var) (M : Term Var) : Term Var :=
26+ def multiSubst (σ : Environment Var) (M : Term Var) : Term Var :=
2527 match σ with
2628 | [] => M
27- | ⟨ i, sub ⟩ :: σ' => (multi_subst σ' M) [ i := sub ]
29+ | ⟨ i, sub ⟩ :: σ' => (multiSubst σ' M) [ i := sub ]
2830
2931def fv (Ns : Environment Var) : Finset Var :=
3032 match Ns with
@@ -45,48 +47,48 @@ lemma context_LC_cons {Γ : Environment Var} {x : Var} {sub : Term Var} :
4547
4648
4749
48- def multi_subst_fvar_fresh (Ns : Environment Var) :
49- ∀ x ∉ Ns.dom, multi_subst Ns (Term.fvar x) = Term.fvar x := by
50+ def multiSubst_fvar_fresh (Ns : Environment Var) :
51+ ∀ x ∉ Ns.dom, multiSubst Ns (Term.fvar x) = Term.fvar x := by
5052 induction Ns <;> intro x h_fresh
5153 · case nil =>
52- simp [multi_subst ]
54+ simp [multiSubst ]
5355 · case cons N Ns ih =>
54- simp only [multi_subst ]
56+ simp only [multiSubst ]
5557 simp only [Context.dom] at h_fresh
5658 rw[ih]
5759 · rw[subst_fvar]
5860 by_cases h : N.1 = x <;> simp_all
5961 · simp_all
6062
61- lemma multi_subst_preserves_not_fvar {x : Var}
63+ lemma multiSubst_preserves_not_fvar {x : Var}
6264 (M : Term Var)
6365 (Ns : Environment Var)
6466 (nmem : x ∉ M.fv ∪ fv Ns) :
65- x ∉ (multi_subst Ns M).fv := by
67+ x ∉ (multiSubst Ns M).fv := by
6668 induction Ns
6769 · case nil =>
68- rw[multi_subst ]
70+ rw[multiSubst ]
6971 simp_all
7072 · case cons N Ns ih =>
71- rw[multi_subst ]
73+ rw[multiSubst ]
7274 apply subst_preserve_not_fvar
7375 rw[fv] at nmem
7476 simp_all
7577
7678
7779
78- def multi_subst_app (M N : Term Var) (Ps : Environment Var) :
79- multi_subst Ps (Term.app M N) = Term.app (multi_subst Ps M) (multi_subst Ps N) := by
80+ def multiSubst_app (M N : Term Var) (Ps : Environment Var) :
81+ multiSubst Ps (Term.app M N) = Term.app (multiSubst Ps M) (multiSubst Ps N) := by
8082 induction Ps
8183 · rfl
82- · case cons N Ns ih => rw[multi_subst,multi_subst ,ih]; rfl
84+ · case cons N Ns ih => rw[multiSubst,multiSubst ,ih]; rfl
8385
84- def multi_subst_abs (M : Term Var) (Ns : Environment Var) :
85- multi_subst Ns (Term.abs M) =
86- Term.abs (multi_subst Ns M) := by
86+ def multiSubst_abs (M : Term Var) (Ns : Environment Var) :
87+ multiSubst Ns (Term.abs M) =
88+ Term.abs (multiSubst Ns M) := by
8789 induction Ns
8890 · rfl
89- · case cons N Ns ih => rw[multi_subst , ih]; rfl
91+ · case cons N Ns ih => rw[multiSubst , ih]; rfl
9092
9193lemma open'_fvar_subst (M N : Term Var) (x : Var) (H : x ∉ Term.fv M) :
9294 (i : Nat) → (M ⟦ i ↝ Term.fvar x ⟧) [x := N] = M ⟦ i ↝ N ⟧ := by
@@ -112,16 +114,16 @@ lemma open'_fvar_subst (M N : Term Var) (x : Var) (H : x ∉ Term.fv M) :
112114 rw[ih_r H.2 ]
113115
114116
115- lemma multi_subst_open_var (M : Term Var) (Ns : Environment Var) (x : Var) :
117+ lemma multiSubst_open_var (M : Term Var) (Ns : Environment Var) (x : Var) :
116118 x ∉ Ns.dom →
117119 context_LC Ns →
118- (multi_subst Ns (M ^ (Term.fvar x))) =
119- (multi_subst Ns M) ^ (Term.fvar x) := by
120+ (multiSubst Ns (M ^ (Term.fvar x))) =
121+ (multiSubst Ns M) ^ (Term.fvar x) := by
120122 intro h_ndom h_lc
121123 induction Ns with
122124 | nil => rfl
123125 | cons N Ns ih =>
124- rw[multi_subst, multi_subst ]
126+ rw[multiSubst, multiSubst ]
125127 rw[ih]
126128 · rw[subst_open_var] <;> aesop
127129 · simp_all
@@ -131,7 +133,7 @@ inductive saturated (S : Set (Term Var)) : Prop :=
131133| intro : (∀ M ∈ S, LC M) →
132134 (∀ M ∈ S, SN M) →
133135 (∀ M, neutral M → LC M → M ∈ S) →
134- (∀ M N P, LC N → SN N → multi_app (M ^ N) P ∈ S → multi_app ((Term.abs M).app N) P ∈ S) →
136+ (∀ M N P, LC N → SN N → multiApp (M ^ N) P ∈ S → multiApp ((Term.abs M).app N) P ∈ S) →
135137 saturated S
136138
137139
@@ -142,14 +144,14 @@ def semanticMap (τ : Ty Base) : Set (Term Var) :=
142144 | Ty.arrow τ₁ τ₂ =>
143145 { t : Term Var | ∀ s : Term Var, s ∈ semanticMap τ₁ → (Term.app t s) ∈ semanticMap τ₂ }
144146
145- lemma multi_app_lc : ∀ {M P : Term Var} {Ns : List (Term Var)},
146- LC (multi_app M Ns) → (LC M → LC P) → LC (multi_app P Ns) := by
147+ lemma multiApp_lc : ∀ {M P : Term Var} {Ns : List (Term Var)},
148+ LC (multiApp M Ns) → (LC M → LC P) → LC (multiApp P Ns) := by
147149 intro N P Ns
148150 induction Ns <;> intro lc_Ns lc_P
149- · simp_all[multi_app ]
151+ · simp_all[multiApp ]
150152 · case cons a l ih =>
151- rw[multi_app ]
152- rw[multi_app ] at lc_Ns
153+ rw[multiApp ]
154+ rw[multiApp ] at lc_Ns
153155 cases lc_Ns
154156 grind
155157
@@ -165,8 +167,8 @@ def semanticMap_saturated (τ : Ty Base) :
165167 · simp_all[neutral_sn]
166168 · intro M N P lc_N sn_N h_app
167169 constructor
168- · simp_all[multi_app_sn ]
169- · apply multi_app_lc
170+ · simp_all[multiApp_sn ]
171+ · apply multiApp_lc
170172 · apply h_app.2
171173 · intro Hlc
172174 constructor
@@ -209,12 +211,12 @@ def semanticMap_saturated (τ : Ty Base) :
209211
210212
211213def entails_context (Ns : Context Var (Term Var)) (Γ : Context Var (Ty Base)) :=
212- ∀ {x τ}, ⟨ x, τ ⟩ ∈ Γ → (multi_subst Ns (Term.fvar x)) ∈ semanticMap τ
214+ ∀ {x τ}, ⟨ x, τ ⟩ ∈ Γ → (multiSubst Ns (Term.fvar x)) ∈ semanticMap τ
213215
214216lemma entails_context_empty {Γ : Context Var (Ty Base)} :
215217 entails_context [] Γ := by
216218 intro x τ h_mem
217- rw[multi_subst ]
219+ rw[multiSubst ]
218220 apply (semanticMap_saturated τ).3 <;> constructor
219221
220222
@@ -224,27 +226,27 @@ lemma entails_context_cons (Ns : Context Var (Term Var)) (Γ : Context Var (Ty B
224226 sub ∈ semanticMap τ →
225227 entails_context Ns Γ → entails_context (⟨ x, sub ⟩ :: Ns) (⟨ x, τ ⟩ :: Γ) := by
226228 intro h_fresh h_mem h_entails y σ h_mem
227- rw[multi_subst ]
229+ rw[multiSubst ]
228230 rw[entails_context] at h_entails
229231 cases h_mem
230232 · case head =>
231- rw[multi_subst_fvar_fresh ]
233+ rw[multiSubst_fvar_fresh ]
232234 · rw[subst_fvar]
233235 simp_all
234236 · simp_all
235237 · case tail h_mem =>
236238 specialize (h_entails h_mem)
237239 rw [subst_fresh]
238240 · assumption
239- · apply multi_subst_preserves_not_fvar
241+ · apply multiSubst_preserves_not_fvar
240242 apply List.mem_keys_of_mem at h_mem
241243 aesop
242244
243245
244246
245247
246248def entails (Γ : Context Var (Ty Base)) (t : Term Var) (τ : Ty Base) :=
247- ∀ Ns, context_LC Ns → (entails_context Ns Γ) → (multi_subst Ns t) ∈ semanticMap τ
249+ ∀ Ns, context_LC Ns → (entails_context Ns Γ) → (multiSubst Ns t) ∈ semanticMap τ
248250
249251
250252
@@ -258,20 +260,20 @@ theorem soundness {Γ : Context Var (Ty Base)} {t : Term Var} {τ : Ty Base} :
258260 apply hsat xσ_mem_Γ
259261 · case' abs σ Γ t τ L IH derivation_t =>
260262 intro Ns lc_Ns hsat s hsat_s
261- rw[multi_subst_abs ]
263+ rw[multiSubst_abs ]
262264 apply (semanticMap_saturated _).4 _ _ []
263265 · apply (semanticMap_saturated _).1
264266 assumption
265267 · apply (semanticMap_saturated _).2
266268 assumption
267- · rw[multi_app ]
268- set x := fresh (t.fv ∪ L ∪ Ns.dom ∪ fv Ns ∪ Context.dom Γ ∪ (multi_subst Ns t).fv)
269- have hfresh : x ∉ t.fv ∪ L ∪ Ns.dom ∪ fv Ns ∪ Context.dom Γ ∪ (multi_subst Ns t).fv := by apply fresh_notMem
269+ · rw[multiApp ]
270+ set x := fresh (t.fv ∪ L ∪ Ns.dom ∪ fv Ns ∪ Context.dom Γ ∪ (multiSubst Ns t).fv)
271+ have hfresh : x ∉ t.fv ∪ L ∪ Ns.dom ∪ fv Ns ∪ Context.dom Γ ∪ (multiSubst Ns t).fv := by apply fresh_notMem
270272 have hfreshL : x ∉ L := by simp_all
271273 have H1 := derivation_t x hfreshL
272274 rw[entails] at H1
273275 specialize H1 (⟨x,s⟩ :: Ns)
274- rw [multi_subst, multi_subst_open_var , ←subst_intro] at H1
276+ rw [multiSubst, multiSubst_open_var , ←subst_intro] at H1
275277 · apply H1
276278 · apply context_LC_cons
277279 · apply (semanticMap_saturated _).1
@@ -285,7 +287,7 @@ theorem soundness {Γ : Context Var (Ty Base)} {t : Term Var} {τ : Ty Base} :
285287 · aesop
286288 · case app derivation_t derivation_t' IH IH' =>
287289 intro Ns lc_Ns hsat
288- rw[multi_subst_app ]
290+ rw[multiSubst_app ]
289291 apply IH Ns lc_Ns hsat
290292 apply IH' Ns lc_Ns hsat
291293
0 commit comments