I'm trying to prove the following laws using structural induction on (finite) lists:
take m (drop n xs) = drop n (take (m + n) xs)
drop m (drop n xs) = drop (m + n) xs
for all m
, n
and every finite list xs
(code snippets are in Haskell). I'm not sure how to tackle it though, more specifically: afaik when using induction on intervals, the first induction step is for m > n
and the second for m ≤ n
. Now in this case the law must also be valid for all finite lists, does that mean the proof involves prooving all the following?
case
m > n
:[]
and(x:xs)
, and in the latterm + n > length xs
andm + n ≤ length xs
case
m ≤ n
:[]
and(x:xs)
, and in the latterm + n > length xs
andm + n ≤ length xs
If yes I can update my question and show exactly where I'm stuck.
(Please don't post the entire solution, I'd just like to have some pointers. Thanks!)
UPDATE
If []
denotes the empty list and (x:xs)
a list with at least one element (x
is the head of the list and xs
its tail), possible definitions of take
and drop
are:
take n [] = []
take 0 xs = []
take n (x:xs) = x : take (n - 1) xs
if n
is greater than l
, where l
is the length of the input list, then take
returns a list of length l
drop n [] = []
drop 0 xs = xs
drop n (x:xs) = drop (n - 1) xs
if n
is greater than l
, where l
is the length of the input list, then drop
returns the empty list
m>n
andm<=n
does not look too useful to me, at a first glance. Prove the equations forxs=[]
, which is trivial. Then, assume that they work onxs
for all pairs(n,m)
where eithern<N, m<=M
orn<=N, m<M
, and prove they must also work onx:xs
with the pair(N,M)
. (Check that this is a well-founded ordering) $\endgroup$take
anddrop
, for those of us not versed in Haskell. $\endgroup$