gpt4 book ai didi

coq - 帮助子序列的 Coq 证明

转载 作者:行者123 更新时间:2023-12-04 17:58:44 28 4
gpt4 key购买 nike

我有定义的归纳类型:

Inductive InL (A:Type) (y:A) : list A -> Prop := 
| InHead : forall xs:list A, InL y (cons y xs)
| InTail : forall (x:A) (xs:list A), InL y xs -> InL y (cons x xs).

Inductive SubSeq (A:Type) : list A -> list A -> Prop :=
| SubNil : forall l:list A, SubSeq nil l
| SubCons1 : forall (x:A) (l1 l2:list A), SubSeq l1 l2 -> SubSeq l1 (x::l2)
| SubCons2 : forall (x:A) (l1 l2:list A), SubSeq l1 l2 -> SubSeq (x::l1) (x::l2).

现在我必须证明该归纳类型的一系列属性,但我一直被卡住。
Lemma proof1: forall (A:Type) (x:A) (l1 l2:list A), SubSeq l1 l2 -> InL x l1 -> InL x l2.
Proof.
intros.
induction l1.
induction l2.
exact H0.

Qed.

有人可以帮助我前进吗?

最佳答案

其实直接对SubSet判断做归纳比较容易。
但是,您需要尽可能通用,所以这是我的建议:

Lemma proof1: forall (A:Type) (x:A) (l1 l2:list A), 
SubSeq l1 l2 -> InL x l1 -> InL x l2.
(* first introduce your hypothesis, but put back x and In foo
inside the goal, so that your induction hypothesis are correct*)
intros.
revert x H0. induction H; intros.
(* x In [] is not possible, so inversion will kill the subgoal *)
inversion H0.

(* here it is straitforward: just combine the correct hypothesis *)
apply InTail; apply IHSubSeq; trivial.

(* x0 in x::l1 has to possible sources: x0 == x or x0 in l1 *)
inversion H0; subst; clear H0.
apply InHead.
apply InTail; apply IHSubSeq; trivial.
Qed.

“反转”是一种检查归纳项的策略,并为您提供构建此类项的所有可能方法!!没有任何归纳假设!!
它只给你 build 性的前提。

你可以直接通过对 l1 然后 l2 的归纳来完成它,但是你必须手工构建正确的反演实例,因为你的归纳假设真的很弱。

希望能帮助到你,
五、

关于coq - 帮助子序列的 Coq 证明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3220050/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com