程序修复点的Coq简化

时间:2016-03-31 09:22:54

标签: coq theorem-proving totality

对于simpl s有什么类似策略Program Fixpoint

特别是,如何证明以下琐碎的陈述?

Program Fixpoint bla (n:nat) {measure n} :=
match n with
| 0 => 0
| S n' => S (bla n')
end.

Lemma obvious: forall n, bla n = n. 
induction n. reflexivity.
(* I'm stuck here. For a normal fixpoint, I could for instance use 
simpl. rewrite IHn. reflexivity. But here, I couldn't find a tactic 
transforming bla (S n) to S (bla n).*)

显然,这个玩具示例不需要Program Fixpoint,但我在一个更复杂的设置中面临同样的问题,我需要手动证明​​Program Fixpoint的终止。

1 个答案:

答案 0 :(得分:4)

我不习惯使用Program,所以可能是更好的解决方案,但这是我通过展开bla提出的,看到它是内部定义的Fix_sub并使用SearchAbout Fix_sub查看有关该函数的定理。

Lemma obvious: forall n, bla n = n.
Proof.
intro n ; induction n.
 reflexivity.
 unfold bla ; rewrite fix_sub_eq ; simpl ; fold (bla n).
 rewrite IHn ; reflexivity.

(* This can probably be automated using Ltac *)
 intros x f g Heq.
  destruct x.
  reflexivity.
  f_equal ; apply Heq.
Qed.

在您的现实生活中,您可能希望引入缩小词条,这样您就不必每次都做同样的工作。 E.g:

Lemma blaS_red : forall n, bla (S n) = S (bla n).
Proof.
intro n.
 unfold bla ; rewrite fix_sub_eq ; simpl ; fold (bla n).
 reflexivity.

(* This can probably be automated using Ltac *)
 intros x f g Heq.
  destruct x.
  reflexivity.
  f_equal ; apply Heq.
Qed.

这样,下次有bla (S _)时,您就可以rewrite blaS_red