a
と の間の累積和を計算すると終了することを証明したいと思いb
ます。
Acc lt x
このように、再帰が減少することを示すために用語を使用します
Require Import Omega.
Lemma L1 : forall a b, a<b -> (b-(1+a)) < (b-a).
intros; omega. Qed.
Lemma term_lemma: forall a b, Acc lt (b-a) -> Acc lt (b-(1+a)).
intros; inversion H; clear H; constructor; intros; apply H0; omega.
Defined.
Fixpoint cumsum a b (H: Acc lt (b-a)) {struct H} : nat.
refine (
match lt_dec a b with
| left a_lt_b => a + cumsum (1+a) b _
| right a_ge_b => if beq_nat a b then a else 0
end
).
apply (term_lemma _ _ H).
Qed.
すべてのサブゴールをクリアしますが、Qed
ステートメントでの型チェックは行いません。Coq は次のように不満を述べています。
Recursive definition of cumsum is ill-formed
Recursive call to cumsum has principal argument equal to
"term_lemma a b H" instead of a subterm of "H".
L1
再帰呼び出しの用語の引数が実際には小さいことを示すために何らかの形で使用する必要があると思いH
ますが、どうすればよいですか?