Skip to content

Instantly share code, notes, and snippets.

@ice1000
Last active June 13, 2023 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ice1000/4a3c83ba5e9e9c1dfa10f7fade8d26fa to your computer and use it in GitHub Desktop.
Save ice1000/4a3c83ba5e9e9c1dfa10f7fade8d26fa to your computer and use it in GitHub Desktop.
A question from a groupchat
{-# OPTIONS --cubical #-}
open import Cubical.Data.Vec
open import Cubical.Data.Nat.Base
open import Cubical.Data.Equality hiding (map)
variable
A : Type
B : Type
n : ℕ
insVec : A → Vec A n → Vec A (doubleℕ n)
insVec a [] = []
insVec a (x ∷ xs) = a ∷ x ∷ insVec a xs
intersperse : A → Vec A n → Vec A (predℕ (doubleℕ n))
intersperse a [] = []
intersperse {n = n} a xs@(x ∷ _) = tail (insVec a xs)
lem : {f : A → B} {a : A} (xs : Vec A n) →
map f (insVec a xs) ≡ insVec (f a) (map f xs)
lem [] = refl
lem {f = f} {a = a} (x ∷ xs) = ap (f a ∷_) (ap (_ ∷_) (lem xs))
thm : {f : A → B} {a : A} (xs : Vec A n) →
map f (intersperse a xs) ≡ intersperse (f a) (map f xs)
thm [] = refl
thm (x ∷ xs) = ap (_ ∷_) (lem xs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment