Skip to content

Instantly share code, notes, and snippets.

@Abhiroop
Created March 26, 2025 13:45
Show Gist options
  • Save Abhiroop/8e2862609c2f2907178c5a1eaec0e335 to your computer and use it in GitHub Desktop.
Save Abhiroop/8e2862609c2f2907178c5a1eaec0e335 to your computer and use it in GitHub Desktop.
_++_ : ∀ {A : Set} → List A → List A → List A
[] ++ ys = ys
(x ∷ xs) ++ ys = x ∷ (xs ++ ys)
length : ∀ {A : Set} → List A → ℕ
length [] = 0
length (x ∷ xs) = 1 + length xs
length-lemma : ∀ {A : Set} → (xs ys : List A) →
length (xs ++ ys) ≡ length xs + length ys -- the theorem to be proven
length-lemma [] ys =
begin
length ([] ++ ys)
≡⟨⟩
length ys
≡⟨⟩
0 + length ys
length-lemma (x ∷ xs) ys =
begin
length ((x ∷ xs) ++ ys)
≡⟨⟩
length (x ∷ (xs ++ ys))
≡⟨⟩
1 + length (xs ++ ys)
≡⟨ cong (1 +_) (length-lemma xs ys) ⟩ -- using the induction hypothesis here
1 + (length xs + length ys)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment