Guarded terms
Lax149335.GuardedTerms · concepts/Lax149335/GuardedTerms.lean · lax-149335
No public endorsements yet.
Loading review…
Sign in with ORCIDNatural Language Statement
Definition
Definition 6.3. Let . A term is -guarded if it is either
- constant: the composition of the unique term with a value; or
- long: of the form for values of length and a simple rational term .
A term is nonempty if it never produces the empty list.
The reductions of Lemmas 6.4 and 6.5 are about -ary co-pairings of such terms, and about the nesting depth of the list constructor in a type, on which the proof of Lemma 6.1 is an induction.
Concept map
Lean source view on GitHub
| 1 | import Lax149335.SimpleRationalWithinSyntax |
| 2 | |
| 3 | /-! |
| 4 | --- |
| 5 | title: Guarded terms |
| 6 | type: definition |
| 7 | --- |
| 8 | **Definition 6.3.** Let . A term is *-guarded* |
| 9 | if it is either |
| 10 | |
| 11 | 1. *constant*: the composition of the unique term with a value; or |
| 12 | 2. *long*: of the form for values of length and a simple |
| 13 | rational term . |
| 14 | |
| 15 | A term is *nonempty* if it never produces the empty list. |
| 16 | |
| 17 | The reductions of Lemmas 6.4 and 6.5 are about -ary co-pairings |
| 18 | of such terms, and about the |
| 19 | *nesting depth* of the list constructor in a type, on which the proof of Lemma 6.1 is an |
| 20 | induction. |
| 21 | |
| 22 | # Formalization notes |
| 23 | |
| 24 | An -ary co-pairing, for , is given by its first term |
| 25 | and the list of the remaining terms (`Cases`); its input type |
| 26 | is `sumTyOf A₁ [A₂, …, Aₙ]`. |
| 27 | -/ |
| 28 | |
| 29 | namespace Lax149335.GuardedTerms |
| 30 | |
| 31 | open Lax149335.Types Lax149335.Terms Lax149335.DerivedTerms Lax149335.DerivedTerms.Term |
| 32 | Lax149335.SimpleRationalWithinSyntax |
| 33 | |
| 34 | /-- **Definition 6.3.** `f : A → B*` is `k`-guarded if it is constant, or of the form |
| 35 | `u · h · v` for values `u`, `v` of length `k` and a simple rational term `h`. -/ |
| 36 | def KGuarded (k : ℕ) (B : Ty) {A : Ty} (f : Term A B⋆) : Prop := |
| 37 | (∃ v : Value B⋆, f = toUnit A ⨟ v) ∨ |
| 38 | (∃ (u v : Value B⋆) (h : Term A B⋆), |
| 39 | IsSimple B h ∧ valLength u = k ∧ valLength v = k ∧ f = dotR (dotL u h) v) |
| 40 | |
| 41 | /-- A term with list outputs is nonempty if it never produces the empty list. -/ |
| 42 | def NonemptyOutput {A B : Ty} (f : Term A B⋆) : Prop := ∀ a : ⟦A⟧, f.den a ≠ [] |
| 43 | |
| 44 | /-- The co-product `A₀ + (A₁ + ⋯ + Aₙ)` of a nonempty list of types. -/ |
| 45 | def sumTyOf : Ty → List Ty → Ty |
| 46 | | A, [] => A |
| 47 | | A, (A' :: As) => A ⊕' sumTyOf A' As |
| 48 | |
| 49 | /-- A list of terms `Aᵢ → B`, one for each type in a list of types. -/ |
| 50 | inductive Cases (B : Ty) : List Ty → Type |
| 51 | /-- The empty list of terms. -/ |
| 52 | | nil : Cases B [] |
| 53 | /-- One more term. -/ |
| 54 | | cons {A : Ty} {As : List Ty} : Term A B → Cases B As → Cases B (A :: As) |
| 55 | |
| 56 | /-- The `n`-ary co-pairing `⟨f₀, f₁, …, fₙ⟩ : A₀ + (A₁ + ⋯ + Aₙ) → B`. -/ |
| 57 | def copair {B : Ty} : {A : Ty} → {As : List Ty} → Term A B → Cases B As → |
| 58 | Term (sumTyOf A As) B |
| 59 | | _, [], f, _ => f |
| 60 | | _, _ :: _, f, .cons g rest => Term.either f (copair g rest) |
| 61 | |
| 62 | /-- A property holds for all terms in a list of terms. -/ |
| 63 | def Cases.All {B : Ty} (P : (A : Ty) → Term A B → Prop) : |
| 64 | {As : List Ty} → Cases B As → Prop |
| 65 | | [], _ => True |
| 66 | | _ :: _, .cons f rest => P _ f ∧ Cases.All P rest |
| 67 | |
| 68 | /-- The nesting depth of the list constructor in a type. -/ |
| 69 | def Ty.listDepth : Ty → ℕ |
| 70 | | .unit => 0 |
| 71 | | .prod A B => max (Ty.listDepth A) (Ty.listDepth B) |
| 72 | | .sum A B => max (Ty.listDepth A) (Ty.listDepth B) |
| 73 | | .list A => Ty.listDepth A + 1 |
| 74 | |
| 75 | end Lax149335.GuardedTerms |
| 76 |
Formalization notes
An -ary co-pairing, for , is given by its first term and the list of the remaining terms (); its input type is .
Builds on
From Mathlib
none
Discussion
Ask a question or add context. Endorsements and structured flags are kept in the review panel above.
0 comments