Skip to content

Commit

Permalink
proper names for find-or-last lemmas
Browse files Browse the repository at this point in the history
  • Loading branch information
pmbittner committed Mar 12, 2024
1 parent bdd1960 commit 5388c68
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
10 changes: 5 additions & 5 deletions src/Translation/Lang/2ADT-to-VariantList.agda
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ open import Lang.2ADT.Path F V _==_
open import Translation.Lang.2ADT.DeadElim F V _==_ as DeadElim using (node; kill-dead; ⟦_⟧ᵤ)
open import Translation.Lang.2ADT.WalkSemantics F V _==_ as Walk using ()

open import Util.List using (find-or-last; ⁺++⁺-length; ⁺++⁺-length-≤; append-preserves; prepend-preserves-+; prepend-preserves-∸)
open import Util.List using (find-or-last; ⁺++⁺-length; ⁺++⁺-length-≤; find-or-last-append; find-or-last-prepend-+; find-or-last-prepend-∸)
open import Util.AuxProofs using (<-cong-+ˡ)

{-
Expand Down Expand Up @@ -102,7 +102,7 @@ preservation-walk-to-list-conf (D ⟨ l , r ⟩) ((_ ∷ pl) is-valid walk-left
walk l c
≡⟨ preservation-walk-to-list-conf l c ⟩
⟦ tr l ⟧ₗ (conf l c)
≡˘⟨ append-preserves (tr l) (tr r) (conf-bounded l c) ⟩
≡˘⟨ find-or-last-append (tr l) (tr r) (conf-bounded l c) ⟩
⟦ tr l ⁺++⁺ tr r ⟧ₗ (conf l c)
preservation-walk-to-list-conf (D ⟨ l , r ⟩) ((_ ∷ pr) is-valid walk-right t) =
Expand All @@ -112,7 +112,7 @@ preservation-walk-to-list-conf (D ⟨ l , r ⟩) ((_ ∷ pr) is-valid walk-right
walk r c
≡⟨ preservation-walk-to-list-conf r c ⟩
⟦ tr r ⟧ₗ (conf r c)
≡˘⟨ prepend-preserves-+ (conf r c) (tr l) (tr r) ⟩
≡˘⟨ find-or-last-prepend-+ (conf r c) (tr l) (tr r) ⟩
⟦ tr l ⁺++⁺ tr r ⟧ₗ (length (tr l) + (conf r c))

Expand All @@ -126,7 +126,7 @@ preservation-walk-to-list-fnoc (D ⟨ l , r ⟩) i with length (tr l) ≤? i
⟦ tr (D ⟨ l , r ⟩) ⟧ₗ i
≡⟨⟩
find-or-last i ((tr l) ⁺++⁺ (tr r))
≡⟨ append-preserves (tr l) (tr r) (≰⇒> ¬p) ⟩ -- this is satisfied by eq
≡⟨ find-or-last-append (tr l) (tr r) (≰⇒> ¬p) ⟩ -- this is satisfied by eq
find-or-last i (tr l)
≡⟨⟩
⟦ tr l ⟧ₗ i
Expand All @@ -138,7 +138,7 @@ preservation-walk-to-list-fnoc (D ⟨ l , r ⟩) i with length (tr l) ≤? i
⟦ tr (D ⟨ l , r ⟩) ⟧ₗ i
≡⟨⟩
find-or-last i ((tr l) ⁺++⁺ (tr r))
≡⟨ prepend-preserves-∸ (tr l) (tr r) len[tr-l]≤i ⟩
≡⟨ find-or-last-prepend-∸ (tr l) (tr r) len[tr-l]≤i ⟩
find-or-last (i ∸ length (tr l)) (tr r)
≡⟨⟩
⟦ tr r ⟧ₗ (i ∸ length (tr l))
Expand Down
22 changes: 11 additions & 11 deletions src/Util/List.agda
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,19 @@ map-find-or-last f (suc i) (x ∷ y ∷ zs) =
(find-or-last (suc i) ∘ map⁺ f) (x ∷ y ∷ zs)

append-preserves : {ℓ} {A : Set ℓ} {n : ℕ}
find-or-last-append : {ℓ} {A : Set ℓ} {n : ℕ}
(xs ys : List⁺ A)
n < List⁺.length xs
find-or-last n (xs ⁺++⁺ ys) ≡ find-or-last n xs
append-preserves {n = .zero} (x ∷ []) (y ∷ ys) (s≤s z≤n) = refl
append-preserves {n = zero} (x ∷ z ∷ zs) (y ∷ ys) (s≤s le) = refl
append-preserves {n = suc n} (x ∷ z ∷ zs) (y ∷ ys) (s≤s (n≤zzs)) = append-preserves (z ∷ zs) (y ∷ ys) (n≤zzs)
find-or-last-append {n = .zero} (x ∷ []) (y ∷ ys) (s≤s z≤n) = refl
find-or-last-append {n = zero} (x ∷ z ∷ zs) (y ∷ ys) (s≤s le) = refl
find-or-last-append {n = suc n} (x ∷ z ∷ zs) (y ∷ ys) (s≤s (n≤zzs)) = find-or-last-append (z ∷ zs) (y ∷ ys) (n≤zzs)

prepend-preserves-+ : {ℓ} {A : Set ℓ}
find-or-last-prepend-+ : {ℓ} {A : Set ℓ}
(n : ℕ)
(xs ys : List⁺ A)
find-or-last (List⁺.length xs + n) (xs ⁺++⁺ ys) ≡ find-or-last n ys
prepend-preserves-+ n (x ∷ xs) ys = ind n x xs ys
find-or-last-prepend-+ n (x ∷ xs) ys = ind n x xs ys
where
-- We need this indirection for termination checking.
-- We have to unpack the first list into two parameters.
Expand All @@ -98,18 +98,18 @@ prepend-preserves-+ n (x ∷ xs) ys = ind n x xs ys
ind n x [] ys = refl
ind n x (z ∷ zs) ys = ind n z zs ys

prepend-preserves-∸ : {ℓ} {A : Set ℓ} {n : ℕ}
find-or-last-prepend-∸ : {ℓ} {A : Set ℓ} {n : ℕ}
(xs ys : List⁺ A)
List⁺.length xs ≤ n
find-or-last n (xs ⁺++⁺ ys) ≡ find-or-last (n ∸ List⁺.length xs) ys
prepend-preserves-∸ {n = zero} xs ys ()
prepend-preserves-∸ {n = suc n} (x ∷ []) ys (s≤s z≤n) = refl
prepend-preserves-∸ {n = suc n} (x ∷ z ∷ zs) ys (s≤s smol) =
find-or-last-prepend-∸ {n = zero} xs ys ()
find-or-last-prepend-∸ {n = suc n} (x ∷ []) ys (s≤s z≤n) = refl
find-or-last-prepend-∸ {n = suc n} (x ∷ z ∷ zs) ys (s≤s smol) =
begin
find-or-last (suc n) ((x ∷ z ∷ zs) ⁺++⁺ ys)
≡⟨⟩
find-or-last n ((z ∷ zs) ⁺++⁺ ys)
≡⟨ prepend-preserves-∸ (z ∷ zs) ys smol ⟩
≡⟨ find-or-last-prepend-∸ (z ∷ zs) ys smol ⟩
find-or-last (n ∸ List⁺.length (z ∷ zs)) ys
≡⟨⟩
find-or-last (suc n ∸ suc (List⁺.length (z ∷ zs))) ys
Expand Down

0 comments on commit 5388c68

Please sign in to comment.