Skip to content

Commit 739a803

Browse files
committed
chore(deps): (wip) upgrade lean to v4.7.0
1 parent 6c06d5f commit 739a803

8 files changed

+119
-106
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/.cache
2+
/.lake/*
23
/build
34
/lake-packages/*
45
/lakefile.olean

Plfl/Init.lean

+1-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,5 @@ namespace Vector
4343
Vector.get, dropLast, v.1.dropLast_eq_take,
4444
Vector.length_val, Nat.pred_succ, Fin.coe_eq_castSucc
4545
]
46-
change List.get _ _ = List.get _ _; rw [←List.get_take]
47-
· rfl
48-
· simp only [Fin.is_lt]
46+
change List.get _ _ = List.get _ _; rw [List.get_dropLast]; rfl
4947
end Vector

Plfl/More/Inference.lean

+35-39
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ if its parse tree node value is determined by the attribute value at its *parent
6060
mutual
6161
/--
6262
A term with synthesized types.
63-
The main term in an eliminator is typed via synthesis.
63+
The main term in a constructor is typed via inheritance.
6464
-/
6565
inductive TermS where
6666
| var : Sym → TermS
@@ -73,7 +73,7 @@ mutual
7373

7474
/--
7575
A term with inherited types.
76-
Constructors are typed via inheritance.
76+
The main term in an eliminator is typed via synthesis.
7777
-/
7878
inductive TermI where
7979
| lam : Sym → TermI → TermI
@@ -214,42 +214,42 @@ instance : Coe (TyI Γ m a) (TyS Γ (m.the a) a) where coe := TyS.syn
214214
instance : Coe (TyS Γ m a) (TyI Γ m a) where coe := TyI.inh
215215

216216
namespace Notation
217-
scoped notation:40 Γ " ⊢ " m " " a:51 => TyS Γ m a
217+
scoped notation:40 Γ " ⊢ " m " " a:51 => TyS Γ m a
218218
scoped notation:40 Γ " ⊢ " m " ↟ " a:51 => TyS Γ (TermS.syn m a) a
219-
scoped notation:40 Γ " ⊢ " m " " a:51 => TyI Γ m a
219+
scoped notation:40 Γ " ⊢ " m " " a:51 => TyI Γ m a
220220
end Notation
221221

222222
abbrev twoTy : Γ ⊢ two ↟ ℕt := open TyS TyI in by
223223
apply_rules [syn, succ, zero]
224224

225-
abbrev addTy : Γ ⊢ add (ℕt =⇒ ℕt =⇒ ℕt) := open TyS TyI Lookup in by
225+
abbrev addTy : Γ ⊢ add (ℕt =⇒ ℕt =⇒ ℕt) := open TyS TyI Lookup in by
226226
repeat apply_rules
227227
[var, ap, prod, syn,
228228
lam, zero, succ, case, mu, fst, snd, inh]
229229
<;> elem
230230

231231
-- https://plfa.github.io/Inference/#bidirectional-mul
232-
abbrev mulTy : Γ ⊢ mul (ℕt =⇒ ℕt =⇒ ℕt) := open TyS TyI Lookup in by
232+
abbrev mulTy : Γ ⊢ mul (ℕt =⇒ ℕt =⇒ ℕt) := open TyS TyI Lookup in by
233233
repeat apply_rules
234234
[var, ap, prod, syn,
235235
lam, zero, succ, case, mu, fst, snd, inh,
236236
addTy]
237237
<;> elem
238238

239-
abbrev twoCTy : Γ ⊢ twoC Ch := open TyS TyI Lookup in by
239+
abbrev twoCTy : Γ ⊢ twoC Ch := open TyS TyI Lookup in by
240240
repeat apply_rules
241241
[var, ap, prod, syn,
242242
lam, zero, succ, case, mu, fst, snd, inh]
243243
<;> elem
244244

245-
abbrev addCTy : Γ ⊢ addC (Ch =⇒ Ch =⇒ Ch) := open TyS TyI Lookup in by
245+
abbrev addCTy : Γ ⊢ addC (Ch =⇒ Ch =⇒ Ch) := open TyS TyI Lookup in by
246246
repeat apply_rules
247247
[var, ap, prod, syn,
248248
lam, zero, succ, case, mu, fst, snd, inh]
249249
<;> elem
250250

251251
-- https://plfa.github.io/Inference/#bidirectional-products
252-
example : Γ ⊢ .prod (two.the ℕt) add ℕt * (ℕt =⇒ ℕt =⇒ ℕt)
252+
example : Γ ⊢ .prod (two.the ℕt) add ℕt * (ℕt =⇒ ℕt =⇒ ℕt)
253253
:= open TyS TyI Lookup in by
254254
repeat apply_rules
255255
[var, ap, prod, syn,
@@ -286,7 +286,7 @@ theorem Lookup.unique (i : Γ ∋ x ⦂ a) (j : Γ ∋ x ⦂ b) : a = b := by
286286
| s => cases j with try trivial
287287
| s => apply unique <;> trivial
288288

289-
theorem TyS.unique (t : Γ ⊢ x a) (u : Γ ⊢ x b) : a = b := by
289+
theorem TyS.unique (t : Γ ⊢ x a) (u : Γ ⊢ x b) : a = b := by
290290
match t with
291291
| .var i => cases u with | var j => apply Lookup.unique <;> trivial
292292
| .ap l _ => cases u with | ap l' _ => injection unique l l'
@@ -304,7 +304,7 @@ lemma Lookup.empty_ext_empty
304304

305305
def Lookup.lookup (Γ : Context) (x : Sym) : Decidable' (Σ a, Γ ∋ x ⦂ a) := by
306306
match Γ, x with
307-
| [], _ => left; is_empty; intro.
307+
| [], _ => left; is_empty; nofun
308308
| ⟨y, b⟩ :: Γ, x =>
309309
if h : x = y then
310310
right; subst h; exact ⟨b, .z⟩
@@ -314,18 +314,18 @@ def Lookup.lookup (Γ : Context) (x : Sym) : Decidable' (Σ a, Γ ∋ x ⦂ a) :
314314

315315
-- https://plfa.github.io/Inference/#promoting-negations
316316
lemma TyS.empty_arg
317-
: Γ ⊢ l a =⇒ b
318-
→ IsEmpty (Γ ⊢ m a)
319-
→ IsEmpty (Σ b', Γ ⊢ l □ m b')
317+
: Γ ⊢ l a =⇒ b
318+
→ IsEmpty (Γ ⊢ m a)
319+
→ IsEmpty (Σ b', Γ ⊢ l □ m b')
320320
:= by
321321
intro tl n; is_empty; intro ⟨b', .ap tl' tm'⟩
322322
injection tl.unique tl'; rename_i h _; apply n.false; rwa [←h] at tm'
323323

324-
lemma TyS.empty_switch : Γ ⊢ m a → a ≠ b → IsEmpty (Γ ⊢ m b) := by
324+
lemma TyS.empty_switch : Γ ⊢ m a → a ≠ b → IsEmpty (Γ ⊢ m b) := by
325325
intro ta n; is_empty; intro tb; have := ta.unique tb; contradiction
326326

327327
mutual
328-
def TermS.infer (m : TermS) (Γ : Context) : Decidable' (Σ a, Γ ⊢ m a) := by
328+
def TermS.infer (m : TermS) (Γ : Context) : Decidable' (Σ a, Γ ⊢ m a) := by
329329
match m with
330330
| ` x => match Lookup.lookup Γ x with
331331
| .inr ⟨a, i⟩ => right; exact ⟨a, .var i⟩
@@ -335,7 +335,7 @@ mutual
335335
| .inr ta => right; exact ⟨b, .ap tab ta⟩
336336
| .inl n => left; exact tab.empty_arg n
337337
| .inr ⟨ℕt, t⟩ => left; is_empty; intro ⟨_, .ap tl _⟩; injection t.unique tl
338-
| .inr ⟨_ * _, t⟩ => left; is_empty; intro ⟨_, .ap tl _⟩; injection t.unique tl
338+
| .inr ⟨.prod _ _, t⟩ => left; is_empty; intro ⟨_, .ap tl _⟩; injection t.unique tl
339339
| .inl n => left; is_empty; intro ⟨a, .ap tl _⟩; rename_i b _; exact n.false ⟨b =⇒ a, tl⟩
340340
| .prod m n => match m.infer Γ, n.infer Γ with
341341
| .inr ⟨a, tm⟩, .inr ⟨b, tn⟩ => right; exact ⟨a * b, tm.prod tn⟩
@@ -345,45 +345,45 @@ mutual
345345
| .inr t => right; exact ⟨a, t⟩
346346
| .inl n => left; is_empty; intro ⟨a', t'⟩; cases t'; apply n.false; trivial
347347

348-
def TermI.infer (m : TermI) (Γ : Context) (a : Ty) : Decidable' (Γ ⊢ m a) := by
348+
def TermI.infer (m : TermI) (Γ : Context) (a : Ty) : Decidable' (Γ ⊢ m a) := by
349349
match m with
350350
| ƛ x : n => match a with
351351
| a =⇒ b => match n.infer (Γ‚ x ⦂ a) b with
352352
| .inr t => right; exact .lam t
353353
| .inl n => left; is_empty; intro (.lam t); exact n.false t
354-
| ℕt => left; is_empty; intro.
355-
| _ * _ => left; is_empty; intro.
354+
| ℕt => left; is_empty; nofun
355+
| .prod _ _ => left; is_empty; nofun
356356
| 𝟘 => match a with
357357
| ℕt => right; exact .zero
358-
| _ =⇒ _ => left; is_empty; intro.
359-
| _ * _ => left; is_empty; intro.
358+
| _ =⇒ _ => left; is_empty; nofun
359+
| .prod _ _ => left; is_empty; nofun
360360
| ι n => match a with
361361
| ℕt => match n.infer Γ ℕt with
362362
| .inr t => right; exact .succ t
363363
| .inl n => left; is_empty; intro (.succ t); exact n.false t
364-
| _ =⇒ _ => left; is_empty; intro.
365-
| _ * _ => left; is_empty; intro.
364+
| _ =⇒ _ => left; is_empty; nofun
365+
| .prod _ _ => left; is_empty; nofun
366366
| .case l m x n => match l.infer Γ with
367367
| .inr ⟨ℕt, tl⟩ => match m.infer Γ a, n.infer (Γ‚ x ⦂ ℕt) a with
368368
| .inr tm, .inr tn => right; exact .case tl tm tn
369369
| .inl nm, _ => left; is_empty; intro (.case _ _ _); apply nm.false; trivial
370370
| .inr _, .inl nn => left; is_empty; intro (.case _ _ _); apply nn.false; trivial
371371
| .inr ⟨_ =⇒ _, tl⟩ => left; is_empty; intro (.case t _ _); injection t.unique tl
372-
| .inr ⟨_ * _, tl⟩ => left; is_empty; intro (.case t _ _); injection t.unique tl
372+
| .inr ⟨.prod _ _, tl⟩ => left; is_empty; intro (.case t _ _); injection t.unique tl
373373
| .inl nl => left; is_empty; intro (.case _ _ _); apply nl.false; constructor <;> trivial
374374
| μ x : n => match n.infer (Γ‚ x ⦂ a) a with
375375
| .inr t => right; exact .mu t
376376
| .inl n => left; is_empty; intro (.mu t); exact n.false t
377377
| .fst m => match m.infer Γ with
378-
| .inr ⟨b * _, tm⟩ => if h : a = b then
378+
| .inr ⟨.prod b _, tm⟩ => if h : a = b then
379379
right; subst h; exact .fst tm
380380
else
381381
left; is_empty; intro (.fst t); injection t.unique tm; contradiction
382382
| .inr ⟨ℕt, tm⟩ => left; is_empty; intro (.fst t); injection t.unique tm
383383
| .inr ⟨_ =⇒ _, tm⟩ => left; is_empty; intro (.fst t); injection t.unique tm
384384
| .inl n => left; is_empty; intro (.fst t); apply n.false; constructor <;> trivial
385385
| .snd m => match m.infer Γ with
386-
| .inr ⟨_ * b, tm⟩ => if h : a = b then
386+
| .inr ⟨.prod _ b, tm⟩ => if h : a = b then
387387
right; subst h; exact .snd tm
388388
else
389389
left; is_empty; intro (.snd t); injection t.unique tm; contradiction
@@ -398,12 +398,9 @@ mutual
398398
apply (tm.empty_switch h.symm).false; trivial
399399
| .inl nm => left; is_empty; intro (.inh tm); apply nm.false; exists a
400400
end
401-
termination_by
402-
TermS.infer m Γ => sizeOf m
403-
TermI.infer n Γ a => sizeOf n
404401

405402
-- https://plfa.github.io/Inference/#testing-the-example-terms
406-
abbrev fourTy : Γ ⊢ four ℕt := open TyS TyI Lookup in by
403+
abbrev fourTy : Γ ⊢ four ℕt := open TyS TyI Lookup in by
407404
repeat apply_rules
408405
[var, ap, prod, syn,
409406
lam, zero, succ, case, mu, fst, snd, inh,
@@ -412,7 +409,7 @@ abbrev fourTy : Γ ⊢ four ↥ ℕt := open TyS TyI Lookup in by
412409

413410
example : four.infer ∅ = .inr ⟨ℕt, fourTy⟩ := by rfl
414411

415-
abbrev four'Ty : Γ ⊢ four' ℕt := open TyS TyI Lookup in by
412+
abbrev four'Ty : Γ ⊢ four' ℕt := open TyS TyI Lookup in by
416413
repeat apply_rules
417414
[var, ap, prod, syn,
418415
lam, zero, succ, case, mu, fst, snd, inh,
@@ -423,7 +420,7 @@ example : four'.infer ∅ = .inr ⟨ℕt, four'Ty⟩ := by rfl
423420

424421
abbrev four'': TermS := mul □ two □ two
425422

426-
abbrev four''Ty : Γ ⊢ four'' ℕt := open TyS TyI Lookup in by
423+
abbrev four''Ty : Γ ⊢ four'' ℕt := open TyS TyI Lookup in by
427424
repeat apply_rules
428425
[var, ap, prod, syn,
429426
lam, zero, succ, case, mu, fst, snd, inh,
@@ -445,9 +442,9 @@ See: <https://leanprover.zulipchat.com/#narrow/stream/113489-new-members/topic/.
445442
This won't work either, probably due to similar reasons...
446443
-/
447444

448-
-- instance : Decidable (Nonempty (Σ a, Γ ⊢ m a)) := (m.infer Γ).toDecidable
445+
-- instance : Decidable (Nonempty (Σ a, Γ ⊢ m a)) := (m.infer Γ).toDecidable
449446

450-
-- example := let m := (ƛ "x" : `"y").the (ℕt =⇒ ℕt); show IsEmpty (Σ a, ∅ ⊢ m a) by
447+
-- example := let m := (ƛ "x" : `"y").the (ℕt =⇒ ℕt); show IsEmpty (Σ a, ∅ ⊢ m a) by
451448
-- rw [←not_nonempty_iff]; decide
452449

453450
-- Unbound variable:
@@ -487,7 +484,7 @@ This won't work either, probably due to similar reasons...
487484
def Ty.erase : Ty → More.Ty
488485
| ℕt => .nat
489486
| a =⇒ b => .fn a.erase b.erase
490-
| a * b => a.erase * b.erase
487+
| .prod a b => a.erase * b.erase
491488

492489
def Context.erase : Context → More.Context
493490
| [] => ∅
@@ -498,13 +495,13 @@ def Lookup.erase : Γ ∋ x ⦂ a → More.Lookup Γ.erase a.erase
498495
| .s _ i => .s i.erase
499496

500497
mutual
501-
def TyS.erase : Γ ⊢ m a → More.Term Γ.erase a.erase
498+
def TyS.erase : Γ ⊢ m a → More.Term Γ.erase a.erase
502499
| .var i => .var i.erase
503500
| .ap l m => .ap l.erase m.erase
504501
| .prod m n => .prod m.erase n.erase
505502
| .syn m => m.erase
506503

507-
def TyI.erase : Γ ⊢ m a → More.Term Γ.erase a.erase
504+
def TyI.erase : Γ ⊢ m a → More.Term Γ.erase a.erase
508505
| .lam m => .lam m.erase
509506
| .zero => .zero
510507
| .succ m => .succ m.erase
@@ -514,7 +511,6 @@ mutual
514511
| .snd m => .snd m.erase
515512
| .inh m => m.erase
516513
end
517-
termination_by _ m => sizeOf m
518514

519515
example : fourTy.erase (Γ := ∅) = More.Term.four := by rfl
520516

Plfl/Untyped.lean

+9-5
Original file line numberDiff line numberDiff line change
@@ -300,15 +300,17 @@ def Progress.progress : (m : Γ ⊢ a) → Progress m := open Reduce in by
300300
| ` x => apply done; exact ′`ₙ x
301301
| ƛ n =>
302302
have : sizeOf n < sizeOf (ƛ n) := by simp only [
303-
Term.lam.sizeOf_spec, lt_add_iff_pos_left, add_pos_iff, true_or
303+
Term.lam.sizeOf_spec, lt_add_iff_pos_left,
304+
add_pos_iff, zero_lt_one, true_or,
304305
]
305306
match progress n with
306307
| .done n => apply done; exact ƛₙ n
307308
| .step n => apply step; exact lamζ n
308309
| ` x □ m =>
309310
have : sizeOf m < sizeOf (` x □ m) := by simp only [
310-
Term.ap.sizeOf_spec, Term.var.sizeOf_spec, Ty.star.sizeOf_spec,
311-
lt_add_iff_pos_left, add_pos_iff, true_or, or_self
311+
Term.ap.sizeOf_spec, Term.var.sizeOf_spec,
312+
Ty.star.sizeOf_spec, lt_add_iff_pos_left,
313+
add_pos_iff, zero_lt_one, true_or, or_self,
312314
]
313315
match progress m with
314316
| .done m => apply done; exact ′`ₙx □ₙ m
@@ -321,8 +323,10 @@ def Progress.progress : (m : Γ ⊢ a) → Progress m := open Reduce in by
321323
| .done (′l') =>
322324
simp_all only [namedPattern]; rename_i h; simp only [h.symm, Term.ap.sizeOf_spec]
323325
have : sizeOf m < sizeOf (l □ m) := by
324-
aesop_subst h
325-
simp only [Term.ap.sizeOf_spec, lt_add_iff_pos_left, add_pos_iff, true_or, or_self]
326+
aesop_subst h; simp only [
327+
Term.ap.sizeOf_spec, lt_add_iff_pos_left, add_pos_iff,
328+
zero_lt_one, true_or, or_self,
329+
]
326330
match progress m with
327331
| .done m => apply done; exact ′l' □ₙ m
328332
| .step m => apply step; exact apξ₂ m

Plfl/Untyped/Denotational.lean

+4-4
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ An `Env` gives meaning to a term's free vars by mapping vars to values.
8989
abbrev Env (Γ : Context) : Type := ∀ (_ : Γ ∋ ✶), Value
9090

9191
namespace Env
92-
instance : EmptyCollection (Env ∅) where emptyCollection := by intro.
92+
instance : EmptyCollection (Env ∅) where emptyCollection := nofun
9393

9494
abbrev snoc (γ : Env Γ) (v : Value) : Env (Γ‚ ✶)
9595
| .z => v
@@ -299,8 +299,8 @@ section
299299
apply_rules [fn]; induction n with
300300
| zero => let ⟨_ :: [], _⟩ := vs; exact var
301301
| succ n r =>
302-
unfold church.applyN; apply ap (v := vs.get n)
303-
· apply sub var; simp only [Env.snoc, Value.path]; simp_arith; exact .conjR₂ .refl
302+
unfold church.applyN; apply ap
303+
· apply sub var; simp only [Env.snoc, Value.path]; convert Sub.refl.conjR₂; sorry
304304
· convert sub_env (@r vs.dropLast) ?_ using 1
305305
· simp only [vs.get_dropLast n, Fin.coe_ofNat_eq_mod]
306306
congr; simp_arith [Nat.mod_eq_of_lt]
@@ -359,7 +359,7 @@ namespace AllFn
359359
def snd (f : AllFn (u ⊔ v)) : AllFn v := f ∘ .inr
360360
end AllFn
361361

362-
lemma not_isFn_bot : ¬ IsFn ⊥ := by intro.
362+
lemma not_isFn_bot : ¬ IsFn ⊥ := nofun
363363

364364
lemma elem_of_allFn (f : AllFn u) : ∃ v w, v ⇾ w ∈ u := by induction u with
365365
| bot => exact (not_isFn_bot <| f rfl).elim

0 commit comments

Comments
 (0)