Coq 逻辑:均衡双控
我被困在这里:Coq 逻辑:均衡双控,coq,logical-foundations,Coq,Logical Foundations,我被困在这里: Theorem evenb_double_conv : forall n, exists k, n = if evenb n then double k else S (double k). Proof. (* Hint: Use the [evenb_S] lemma from [Induction.v]. *) intros n. induction n as [|n' IHn']. - simpl. exists O. sim
Theorem evenb_double_conv : forall n,
exists k, n = if evenb n then double k
else S (double k).
Proof.
(* Hint: Use the [evenb_S] lemma from [Induction.v]. *)
intros n. induction n as [|n' IHn'].
- simpl. exists O. simpl. reflexivity.
- rewrite -> evenb_S. destruct (evenb n') as [H1 | H2].
+ simpl.
我们可以使用归纳假设将(双k)重写为n’,或者在目标上使用注入,然后应用归纳假设
但是我不能做这些,因为存在
rewrite我们需要打破存在的
与destruct的假设:destruct IHn'as[k HE]。
n' : nat
IHn' : exists k : nat, n' = double k
============================
exists k : nat, S n' = S (double k)
注射在这里不起作用,因为它只在假设条件下起作用。这不是课程中练习的答案吗?公布答案有意义吗?@Yves在保留对困难部分的提示的同时,我删除了解决方案的最后一部分。
Theorem evenb_double_conv : forall n,
exists k, n = if evenb n then double k
else S (double k).
Proof.
(* Hint: Use the [evenb_S] lemma from [Induction.v]. *)
intros n. induction n as [|n' IHn'].
- simpl. exists O. simpl. reflexivity.
- rewrite -> evenb_S. destruct IHn' as [k HE]. destruct (evenb n').
(* Now find out which k we need to insert into the goal for every branch *)