Proofs of take n xs ++ drop n xs = xs
In Lean4, the functions
take : Nat → List α → Nat drop : Nat → List α → Nat (++) : List α → List α → List α
are defined such that
-
(take n xs) is the list consisting of the first n elements of xs. For example,
take 2 [3,5,1,9,7] = [3,5]
-
(drop n xs) is the list containing all elements of xs except the first n elements. For example,
drop 2 [3,5,1,9,7] = [1,9,7]
-
(xs ++ ys) is the list obtained by concatenating xs and ys. For example,
[3,5] ++ [1,9,7] = [3,5,1,9,7]
These functions are characterized by the following lemmas:
take_zero : take 0 xs = [] take_nil : take n [] = [] take_cons : take (succ n) (x :: xs) = x :: take n xs drop_zero : drop 0 xs = xs drop_nil : drop n [] = [] drop_succ_cons : drop (n + 1) (x :: xs) = drop n xs nil_append : [] ++ ys = ys cons_append : (x :: xs) ++ y = x :: (xs ++ ys)
Prove that
take n xs ++ drop n xs = xs
To do this, complete the following Lean4 theory:
import Mathlib.Data.List.Basic import Mathlib.Tactic open List Nat variable {α : Type} variable (n : ℕ) variable (x : α) variable (xs : List α) example : take n xs ++ drop n xs = xs := by sorry