策略:filter_exercise

时间:2019-04-19 16:53:40

标签: coq logical-foundations

(** **** 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.
    +

这是我到目前为止所得到的:

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

在这里我被困住了。我必须注意的归纳假设有何特别之处?

1 个答案:

答案 0 :(得分:0)

给出一个带有箭头的目标,

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

下一步自然是intros。新前提

h :: filter test t = x :: lf

表示::的分量分别相等,即h = xfilter test t = lf,可以使用inversion提取。其余的都很琐碎。