Coq 什么是诱导策略的等效案例?
我想对一个归纳变量进行归纳,但我想把这个案例放在假设中,就像在案例等式中一样。例如,如果我做了Coq 什么是诱导策略的等效案例?,coq,Coq,我想对一个归纳变量进行归纳,但我想把这个案例放在假设中,就像在案例等式中一样。例如,如果我做了归纳n,在基本案例中,我希望在我的假设中有n=0。有什么策略可以帮我做到这一点吗?一般来说,这样做有点痛苦,确实提供了一些策略来做到这一点,但最有启发性的是通过在归纳假设中添加一个等式来自己做到这一点: Lemma foo P (n : nat) : P n. Proof. generalize (eq_refl n); generalize n at 1. induction n. 但是请注意,这是
归纳n
,在基本案例中,我希望在我的假设中有n=0
。有什么策略可以帮我做到这一点吗?一般来说,这样做有点痛苦,确实提供了一些策略来做到这一点,但最有启发性的是通过在归纳假设中添加一个等式来自己做到这一点:
Lemma foo P (n : nat) : P n.
Proof.
generalize (eq_refl n); generalize n at 1.
induction n.
但是请注意,这是痛苦的,因为您需要构造正确的等式来使用归纳假设
编辑:此解决方案适用于@yves指出的示例:
Require Import List.
Import ListNotations.
Section EqList.
Variables (A : Type) (eqb : A -> A -> bool).
Variables (eqbP : forall a1 a2, eqb a1 a2 = true <-> a1 = a2).
Implicit Types (l : list A).
Fixpoint eqb_list l1 l2 {struct l1} : bool :=
match l1,l2 with
| [], [] => false
| (x1::l1), (x2::l2) => eqb x1 x2 && eqb_list l1 l2
| _,_ => false
end.
Lemma eqb_list_true_iff_left_to_right l1 l2 :
eqb_list l1 l2 = true -> l1 = l2.
Proof.
revert l2; generalize (eq_refl l1); generalize l1 at 1.
induction l1 as [|x1 l1 IHl1]; intros l1'.
- now destruct l1'; destruct l2; auto.
- destruct l1' as [|x1' l1']; [congruence|intros hl].
destruct l2 as [|x2 l2]; [simpl; congruence|]; simpl; intros heq.
pose proof (andb_prop _ _ heq) as [h1 h2].
pose proof (eqbP x1 x2) as [rl rr].
rewrite rl; auto.
pose proof (IHl1 l1 (eq_refl _) l2 h2).
now rewrite H.
Qed.
我担心这是行不通的,正如在前面的问题中已经暗示的那样。亲爱的@Yves,为什么你认为这不起作用?您需要对等式变量进行泛化,但就我所见,它确实有效[参见编辑]。当然,你要为增加的宣传付出代价。[请原谅我糟糕的非ssr证明技能]
From mathcomp Require Import all_ssreflect.
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Section EqList.
Variables (A : eqType).
Implicit Types (l : seq A).
Fixpoint eqb_list l1 l2 {struct l1} : bool :=
match l1,l2 with
| [::], [::] => false
| (x1::l1), (x2::l2) => [&& x1 == x2 & eqb_list l1 l2]
| _, _ => false
end.
Lemma eqb_list_true_iff_left_to_right l1 l2 :
eqb_list l1 l2 = true -> l1 = l2.
Proof.
move E: l1 l2 => l1'; elim: l1' l1 E => [|x1 l1 ihl1] [|? ?] // ? [|x2 l2] //=.
by case/andP=> /eqP-> /(ihl1 l1 erefl)->.
Qed.