应用具有不同字段的函数

时间:2014-05-23 15:26:24

标签: coq

有没有办法,将假设应用于我们在Coq中的目标?

例如:

假设:

1 subgoal
a : nat
l1 : list nat
l2 : list nat
H : Prefix (a :: l1) l2
IHl1 : Prefix l1 l2 -> sum l1 <= sum l2

目标

______________________________________(1/1)
sum (a :: l1) <= sum l2

我知道如果我能做到:应用IHl1,我可以得到像Prefix(a :: l1)l2这样的结果,之后我就可以做一个假设了! 但我无法申请,因为它给了我这个错误: 错误:无法将“sum l1&lt; = sum l2”与“sum(a :: l1)&lt; = sum l2”统一起来。

说明

不动点

Fixpoint sum (l: list nat) : nat := match l with
  | nil => 0
  | a::t => a + sum t
  end.

引理

Lemma parte2_1_c : forall l1 l2, Prefix l1 l2 -> sum l1 <= sum l2.
Proof.
intros.
induction l1.
simpl.
SearchAbout(_<=_).
apply le_0_n.
SearchAbout(sum).
(*must continue but do not know how to do it...*)

那么......我怎么能够解决这个问题?

1 个答案:

答案 0 :(得分:0)

a :: l1l1不同,因此您将无法使用该假设。

Require Import Coq.Arith.Arith.
Require Import Coq.Lists.List.

Definition Prefix : forall {t1}, list t1 -> list t1 -> Prop := fun _ l1 l2 =>
  exists l3, l1 ++ l3 = l2.

Conjecture C1 : forall t1 (x1 : t1) l1 l2, Prefix (x1 :: l1) l2 -> exists l3, l2 = x1 :: l3.
Conjecture C2 : forall n1 n2 n3, n1 <= n2 -> n3 + n1 <= n3 + n2.
Conjecture C3 : forall t1 (x1 : t1) l1 l2, Prefix (x1 :: l1) (x1 :: l2) -> Prefix l1 l2.
Hint Resolve C1 C2 C3.

Lemma parte2_1_c : forall l1 l2, Prefix l1 l2 -> sum l1 <= sum l2.
Proof.
intros.
induction l1.
simpl.
SearchAbout(_<=_).
apply le_0_n.
assert (H3 : exists l3, l2 = a :: l3) by info_eauto with *.
destruct H3.
subst.
simpl in *.
Abort.

在执行归纳之前,您还引入了太多变量。这使得归纳假设不那么普遍。

Lemma parte2_1_c : forall l1 l2, Prefix l1 l2 -> sum l1 <= sum l2.
Proof.
intros l1.
induction l1.
info_eauto with *.
intros.
assert (H3 : exists l3, l2 = a :: l3) by info_eauto with *.
destruct H3.
subst.
simpl in *.
info_eauto with *.
Qed.