As per https://homes.cs.washington.edu/~jrw12/InductionExercises.html I am tring to prove sum
and sum_cont
are equivalent. I get to:
sum : List Nat -> Nat
sum [] = 0
sum (x :: xs) = x + sum xs
sum_cont' : {a : Type} -> List Nat -> (Nat -> a) -> a
sum_cont' [] k = k 0
sum_cont' (x :: xs) k = sum_cont' xs (\ans => k (x + ans))
sum_cont : List Nat -> Nat
sum_cont l = sum_cont' l (\x => x)
sum_cont_correct' : (xs : List Nat) -> (x : Nat) -> sum_cont' xs (\ans => plus x ans) = plus x (sum xs)
sum_cont_correct' [] acc = Refl
sum_cont_correct' (x :: xs) acc =
rewrite plusAssociative acc x (sum xs) in
?todo
Where the hole todo
has type:
sum_cont' xs (\ans => plus acc (plus x ans)) = plus (plus acc x) (sum xs)
I'd like to apply the rewrite plusAssociative acc x ans
, but ans
is not in scope at the top. How do I apply the rewrite under the lambda, to a variable I can't bind?
The question How do I prove a "seemingly obvious" fact when relevant types are abstracted by a lambda in Idris? seems to answer some similar points, but ultimately suggests using cong
, which is inappropriate here as I can't make the outer pieces similar until after I apply the inner rewrite.