0
(** **** Exercise: 3 stars, advanced (filter_exercise)

    This one is a bit challenging.  Pay attention to the form of your
    induction hypothesis. *)

Theorem filter_exercise : forall (X : Type) (test : X -> bool)
                             (x : X) (l lf : list X),
     filter test l = x :: lf ->
     test x = true.
Proof.
  intros X test x l lf. induction l as [| h t].
  - simpl. intros H. discriminate H.
  - simpl. destruct (test h) eqn:E.
    +

Here is what I got so far:

X : Type
test : X -> bool
x, h : X
t, lf : list X
IHt : filter test t = x :: lf -> test x = true
E : test h = true
============================
h :: filter test t = x :: lf -> test x = true

And here I am stuck. What is so special in induction hypothesis that I must pay attention to?

user4035
  • 22,508
  • 11
  • 59
  • 94
  • I don't know what the authors meant here, but you are on the right track. What follows from the fact that two non-empty lists are equal? The answer will let you prove the first `+` subgoal. – Anton Trunov Apr 19 '19 at 17:09

1 Answers1

0

Given the goal with an arrow in it,

h :: filter test t = x :: lf -> test x = true
                             ^^

the natural next step is to intros the premise. The new premise

h :: filter test t = x :: lf

implies that the components of :: are respectively equal i.e. h = x and filter test t = lf, which can be extracted using inversion. The rest is trivial.

Bubbler
  • 940
  • 6
  • 15