Created
March 26, 2025 13:45
-
-
Save Abhiroop/8e2862609c2f2907178c5a1eaec0e335 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_++_ : ∀ {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