I was proving some properties of filter
and map
, everything went quite good until I stumbled on this property: filter p (map f xs) ≡ map f (f
The trouble with with
-clauses is that Agda forgets the information it learned from pattern match unless you arrange beforehand for this information to be preserved.
More precisely, when Agda sees a with expression
clause, it replaces all the occurences of expression
in the current context and goal with a fresh variable w
and then gives you that variable with updated context and goal into the with-clause, forgetting everything about its origin.
In your case, you write filter p (map f (x ∷ xs))
inside the with-block, so it goes into scope after Agda has performed the rewriting, so Agda has already forgotten the fact that p (f x)
is true
and does not reduce the term.
You can preserve the proof of equality by using one of the "Inspect"-patterns from the standard library, but I'm not sure how it can be useful in your case.