module LengthIsortChain where
open import InsertionSortBool
open import Relation.Binary.PropositionalEquality
open ≡-Reasoning
length-insert : ∀ x ys → length (insert x ys) ≡ suc (length ys)
length-insert x [] = refl
length-insert x (y ∷ ys) with x <= y
... | true = begin
length (x ∷ y ∷ ys) ≡⟨⟩
suc (length (y ∷ ys))
∎
... | false = begin
length (y ∷ insert x ys) ≡⟨ refl ⟩
suc (length (insert x ys)) ≡⟨ cong suc (length-insert x ys) ⟩
suc (suc (length ys)) ≡⟨ refl ⟩
suc (length (y ∷ ys))
∎
length-isort : ∀ xs → length (isort xs) ≡ length xs
length-isort [] = begin
length (isort []) ≡⟨⟩
length {A = ℕ} [] ≡⟨⟩
zero ≡⟨⟩
length {A = ℕ} []
∎
length-isort (x ∷ xs) = begin
length (isort (x ∷ xs)) ≡⟨⟩
length (insert x (isort xs)) ≡⟨ length-insert _ _ ⟩
suc (length (isort xs)) ≡⟨ cong suc (length-isort xs) ⟩
suc (length xs) ≡⟨⟩
length (x ∷ xs)
∎