From 0dc59b43f78654a746ef5baaeabcc767c64ee0df Mon Sep 17 00:00:00 2001 From: Chloe Brown Date: Sat, 13 Mar 2021 20:06:22 +0000 Subject: Add weakening proofs for type judgements. --- src/Cfe/Judgement/Properties.agda | 159 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 159 insertions(+) create mode 100644 src/Cfe/Judgement/Properties.agda (limited to 'src/Cfe/Judgement/Properties.agda') diff --git a/src/Cfe/Judgement/Properties.agda b/src/Cfe/Judgement/Properties.agda new file mode 100644 index 0000000..b5183eb --- /dev/null +++ b/src/Cfe/Judgement/Properties.agda @@ -0,0 +1,159 @@ +{-# OPTIONS --without-K --safe #-} + +open import Relation.Binary using (Setoid) + +module Cfe.Judgement.Properties + {c ℓ} (over : Setoid c ℓ) + where + +open import Cfe.Expression over +open import Cfe.Judgement.Base over +open import Cfe.Type over +open import Data.Empty +open import Data.Fin as F hiding (cast) +open import Data.Fin.Properties +open import Data.Nat as ℕ +open import Data.Nat.Properties +open import Data.Vec +open import Data.Vec.Properties +open import Function +open import Relation.Binary.PropositionalEquality + +wkn₁ : ∀ {m n} {Γ : Vec (Type ℓ ℓ) m} {Δ : Vec (Type ℓ ℓ) n} {e τ} → + Γ , Δ ⊢ e ∶ τ → + ∀ τ′ i → + insert Γ i τ′ , Δ ⊢ cast (sym (+-suc n m)) (wkn e (F.cast (+-suc n m) (raise n i))) ∶ τ +wkn₁ Eps τ′ i = Eps +wkn₁ (Char c) τ′ i = Char c +wkn₁ Bot τ′ i = Bot +wkn₁ {m} {n} {Γ} {Δ} {e} {τ} (Var {i = j} j≥n) τ′ i = + subst (insert Γ i τ′ , Δ ⊢ cast (sym (+-suc n m)) (Var (punchIn (F.cast (+-suc n m) (raise n i)) j)) ∶_) + (eq Γ τ′ i j≥n) + (Var (le i j≥n)) + where + toℕ-punchIn : ∀ {m} i j → toℕ j ℕ.≤ toℕ (punchIn {m} i j) + toℕ-punchIn zero j = n≤1+n (toℕ j) + toℕ-punchIn (suc i) zero = z≤n + toℕ-punchIn (suc i) (suc j) = s≤s (toℕ-punchIn i j) + + le : ∀ {m n} i {j} → toℕ j ≥ n → toℕ (F.cast (sym (+-suc n m)) (punchIn (F.cast (+-suc n m) (raise n i)) j)) ≥ n + le {m} {n} i {j} j≥n = begin + n ≤⟨ j≥n ⟩ + toℕ j ≤⟨ toℕ-punchIn (F.cast (+-suc n m) (raise n i)) j ⟩ + toℕ (punchIn (F.cast _ (raise n i)) j) ≡˘⟨ toℕ-cast (sym (+-suc n m)) (punchIn (F.cast _ (raise n i)) j) ⟩ + toℕ (F.cast _ (punchIn (F.cast _ (raise n i)) j)) ∎ + where + open ≤-Reasoning + + lookup-cast : ∀ {a A n} l j → lookup {a} {A} {n} l (F.cast refl j) ≡ lookup l j + lookup-cast l zero = refl + lookup-cast (x ∷ l) (suc j) = lookup-cast l j + + toℕ-reduce : ∀ {m n} i i≥m → toℕ (reduce≥ {m} {n} i i≥m) ≡ toℕ i ∸ m + toℕ-reduce {zero} i i≥m = refl + toℕ-reduce {suc m} (suc i) (s≤s i≥m) = toℕ-reduce i i≥m + + punchIn-∸ : ∀ {m n} i {j} j≥n → toℕ (punchIn (F.cast (+-suc n m) (raise n i)) j) ∸ n ≡ toℕ (punchIn i (reduce≥ j j≥n)) + punchIn-∸ {zero} {n} zero {j} j≥n = ⊥-elim (<⇒≱ (begin-strict + toℕ j ≡˘⟨ toℕ-cast (+-identityʳ n) j ⟩ + toℕ (F.cast _ j) <⟨ toℕ