@@ -60,7 +60,7 @@ if its parse tree node value is determined by the attribute value at its *parent
60
60
mutual
61
61
/--
62
62
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 .
64
64
-/
65
65
inductive TermS where
66
66
| var : Sym → TermS
73
73
74
74
/--
75
75
A term with inherited types.
76
- Constructors are typed via inheritance .
76
+ The main term in an eliminator is typed via synthesis .
77
77
-/
78
78
inductive TermI where
79
79
| lam : Sym → TermI → TermI
@@ -214,42 +214,42 @@ instance : Coe (TyI Γ m a) (TyS Γ (m.the a) a) where coe := TyS.syn
214
214
instance : Coe (TyS Γ m a) (TyI Γ m a) where coe := TyI.inh
215
215
216
216
namespace Notation
217
- scoped notation :40 Γ " ⊢ " m " ↥ " a:51 => TyS Γ m a
217
+ scoped notation :40 Γ " ⊢ " m " ⇡ " a:51 => TyS Γ m a
218
218
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
220
220
end Notation
221
221
222
222
abbrev twoTy : Γ ⊢ two ↟ ℕt := open TyS TyI in by
223
223
apply_rules [syn, succ, zero]
224
224
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
226
226
repeat apply_rules
227
227
[var, ap, prod, syn,
228
228
lam, zero, succ, case, mu, fst, snd, inh]
229
229
<;> elem
230
230
231
231
-- 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
233
233
repeat apply_rules
234
234
[var, ap, prod, syn,
235
235
lam, zero, succ, case, mu, fst, snd, inh,
236
236
addTy]
237
237
<;> elem
238
238
239
- abbrev twoCTy : Γ ⊢ twoC ↧ Ch := open TyS TyI Lookup in by
239
+ abbrev twoCTy : Γ ⊢ twoC ⇣ Ch := open TyS TyI Lookup in by
240
240
repeat apply_rules
241
241
[var, ap, prod, syn,
242
242
lam, zero, succ, case, mu, fst, snd, inh]
243
243
<;> elem
244
244
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
246
246
repeat apply_rules
247
247
[var, ap, prod, syn,
248
248
lam, zero, succ, case, mu, fst, snd, inh]
249
249
<;> elem
250
250
251
251
-- 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)
253
253
:= open TyS TyI Lookup in by
254
254
repeat apply_rules
255
255
[var, ap, prod, syn,
@@ -286,7 +286,7 @@ theorem Lookup.unique (i : Γ ∋ x ⦂ a) (j : Γ ∋ x ⦂ b) : a = b := by
286
286
| s => cases j with try trivial
287
287
| s => apply unique <;> trivial
288
288
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
290
290
match t with
291
291
| .var i => cases u with | var j => apply Lookup.unique <;> trivial
292
292
| .ap l _ => cases u with | ap l' _ => injection unique l l'
@@ -304,7 +304,7 @@ lemma Lookup.empty_ext_empty
304
304
305
305
def Lookup.lookup (Γ : Context) (x : Sym) : Decidable' (Σ a, Γ ∋ x ⦂ a) := by
306
306
match Γ, x with
307
- | [], _ => left; is_empty; intro.
307
+ | [], _ => left; is_empty; nofun
308
308
| ⟨y, b⟩ :: Γ, x =>
309
309
if h : x = y then
310
310
right; subst h; exact ⟨b, .z⟩
@@ -314,18 +314,18 @@ def Lookup.lookup (Γ : Context) (x : Sym) : Decidable' (Σ a, Γ ∋ x ⦂ a) :
314
314
315
315
-- https://plfa.github.io/Inference/#promoting-negations
316
316
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')
320
320
:= by
321
321
intro tl n; is_empty; intro ⟨b', .ap tl' tm'⟩
322
322
injection tl.unique tl'; rename_i h _; apply n.false ; rwa [←h] at tm'
323
323
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
325
325
intro ta n; is_empty; intro tb; have := ta.unique tb; contradiction
326
326
327
327
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
329
329
match m with
330
330
| ` x => match Lookup.lookup Γ x with
331
331
| .inr ⟨a, i⟩ => right; exact ⟨a, .var i⟩
@@ -335,7 +335,7 @@ mutual
335
335
| .inr ta => right; exact ⟨b, .ap tab ta⟩
336
336
| .inl n => left; exact tab.empty_arg n
337
337
| .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
339
339
| .inl n => left; is_empty; intro ⟨a, .ap tl _⟩; rename_i b _; exact n.false ⟨b =⇒ a, tl⟩
340
340
| .prod m n => match m.infer Γ, n.infer Γ with
341
341
| .inr ⟨a, tm⟩, .inr ⟨b, tn⟩ => right; exact ⟨a * b, tm.prod tn⟩
@@ -345,45 +345,45 @@ mutual
345
345
| .inr t => right; exact ⟨a, t⟩
346
346
| .inl n => left; is_empty; intro ⟨a', t'⟩; cases t'; apply n.false ; trivial
347
347
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
349
349
match m with
350
350
| ƛ x : n => match a with
351
351
| a =⇒ b => match n.infer (Γ‚ x ⦂ a) b with
352
352
| .inr t => right; exact .lam t
353
353
| .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
356
356
| 𝟘 => match a with
357
357
| ℕ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
360
360
| ι n => match a with
361
361
| ℕt => match n.infer Γ ℕt with
362
362
| .inr t => right; exact .succ t
363
363
| .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
366
366
| .case l m x n => match l.infer Γ with
367
367
| .inr ⟨ℕt, tl⟩ => match m.infer Γ a, n.infer (Γ‚ x ⦂ ℕt) a with
368
368
| .inr tm, .inr tn => right; exact .case tl tm tn
369
369
| .inl nm, _ => left; is_empty; intro (.case _ _ _); apply nm.false ; trivial
370
370
| .inr _, .inl nn => left; is_empty; intro (.case _ _ _); apply nn.false ; trivial
371
371
| .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
373
373
| .inl nl => left; is_empty; intro (.case _ _ _); apply nl.false ; constructor <;> trivial
374
374
| μ x : n => match n.infer (Γ‚ x ⦂ a) a with
375
375
| .inr t => right; exact .mu t
376
376
| .inl n => left; is_empty; intro (.mu t); exact n.false t
377
377
| .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
379
379
right; subst h; exact .fst tm
380
380
else
381
381
left; is_empty; intro (.fst t); injection t.unique tm; contradiction
382
382
| .inr ⟨ℕt, tm⟩ => left; is_empty; intro (.fst t); injection t.unique tm
383
383
| .inr ⟨_ =⇒ _, tm⟩ => left; is_empty; intro (.fst t); injection t.unique tm
384
384
| .inl n => left; is_empty; intro (.fst t); apply n.false ; constructor <;> trivial
385
385
| .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
387
387
right; subst h; exact .snd tm
388
388
else
389
389
left; is_empty; intro (.snd t); injection t.unique tm; contradiction
@@ -398,12 +398,9 @@ mutual
398
398
apply (tm.empty_switch h.symm).false ; trivial
399
399
| .inl nm => left; is_empty; intro (.inh tm); apply nm.false ; exists a
400
400
end
401
- termination_by
402
- TermS.infer m Γ => sizeOf m
403
- TermI.infer n Γ a => sizeOf n
404
401
405
402
-- 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
407
404
repeat apply_rules
408
405
[var, ap, prod, syn,
409
406
lam, zero, succ, case, mu, fst, snd, inh,
@@ -412,7 +409,7 @@ abbrev fourTy : Γ ⊢ four ↥ ℕt := open TyS TyI Lookup in by
412
409
413
410
example : four.infer ∅ = .inr ⟨ℕt, fourTy⟩ := by rfl
414
411
415
- abbrev four'Ty : Γ ⊢ four' ↥ ℕt := open TyS TyI Lookup in by
412
+ abbrev four'Ty : Γ ⊢ four' ⇡ ℕt := open TyS TyI Lookup in by
416
413
repeat apply_rules
417
414
[var, ap, prod, syn,
418
415
lam, zero, succ, case, mu, fst, snd, inh,
@@ -423,7 +420,7 @@ example : four'.infer ∅ = .inr ⟨ℕt, four'Ty⟩ := by rfl
423
420
424
421
abbrev four'' : TermS := mul □ two □ two
425
422
426
- abbrev four''Ty : Γ ⊢ four'' ↥ ℕt := open TyS TyI Lookup in by
423
+ abbrev four''Ty : Γ ⊢ four'' ⇡ ℕt := open TyS TyI Lookup in by
427
424
repeat apply_rules
428
425
[var, ap, prod, syn,
429
426
lam, zero, succ, case, mu, fst, snd, inh,
@@ -445,9 +442,9 @@ See: <https://leanprover.zulipchat.com/#narrow/stream/113489-new-members/topic/.
445
442
This won't work either, probably due to similar reasons...
446
443
-/
447
444
448
- -- instance : Decidable (Nonempty (Σ a, Γ ⊢ m ↥ a)) := (m.infer Γ).toDecidable
445
+ -- instance : Decidable (Nonempty (Σ a, Γ ⊢ m ⇡ a)) := (m.infer Γ).toDecidable
449
446
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
451
448
-- rw [ ←not_nonempty_iff ] ; decide
452
449
453
450
-- Unbound variable:
@@ -487,7 +484,7 @@ This won't work either, probably due to similar reasons...
487
484
def Ty.erase : Ty → More.Ty
488
485
| ℕt => .nat
489
486
| a =⇒ b => .fn a.erase b.erase
490
- | a * b => a.erase * b.erase
487
+ | .prod a b => a.erase * b.erase
491
488
492
489
def Context.erase : Context → More.Context
493
490
| [] => ∅
@@ -498,13 +495,13 @@ def Lookup.erase : Γ ∋ x ⦂ a → More.Lookup Γ.erase a.erase
498
495
| .s _ i => .s i.erase
499
496
500
497
mutual
501
- def TyS.erase : Γ ⊢ m ↥ a → More.Term Γ.erase a.erase
498
+ def TyS.erase : Γ ⊢ m ⇡ a → More.Term Γ.erase a.erase
502
499
| .var i => .var i.erase
503
500
| .ap l m => .ap l.erase m.erase
504
501
| .prod m n => .prod m.erase n.erase
505
502
| .syn m => m.erase
506
503
507
- def TyI.erase : Γ ⊢ m ↧ a → More.Term Γ.erase a.erase
504
+ def TyI.erase : Γ ⊢ m ⇣ a → More.Term Γ.erase a.erase
508
505
| .lam m => .lam m.erase
509
506
| .zero => .zero
510
507
| .succ m => .succ m.erase
@@ -514,7 +511,6 @@ mutual
514
511
| .snd m => .snd m.erase
515
512
| .inh m => m.erase
516
513
end
517
- termination_by _ m => sizeOf m
518
514
519
515
example : fourTy.erase (Γ := ∅) = More.Term.four := by rfl
520
516
0 commit comments