我试图了解证明在 Coq 提取中的作用。我有以下取自此处的整数除以二的示例。对于我的第一次尝试,我使用了Admitted
关键字:
(*********************)
(* div_2_even_number *)
(*********************)
Definition div_2_even_number: forall n,
(Nat.Even n) -> {p:nat | n=p+p}.
Proof.
Admitted.
(*************)
(* test_even *)
(*************)
Definition test_even: forall n,
{Nat.Even n}+{Nat.Even (pred n)}.
Proof.
Admitted.
(********************)
(* div_2_any_number *)
(********************)
Definition div_2_any_number (n:nat):
{p:nat | n = p+p}+{p:nat | (pred n) = p+p} :=
match (test_even n) with
| left h => inl _ (div_2_even_number n h)
| right h' => inr _ (div_2_even_number (pred n) h')
end.
(***************************)
(* Extract to Haskell file *)
(***************************)
Extraction "/home/oren/some_file.hs" div_2_any_number.
当我检查生成的 Haskell 文件时,我发现它确实丢失了:
div_2_even_number :: Prelude.Integer -> Prelude.Integer
div_2_even_number =
Prelude.error "AXIOM TO BE REALIZED"
test_even :: Prelude.Integer -> Prelude.Bool
test_even =
Prelude.error "AXIOM TO BE REALIZED"
div_2_any_number :: Prelude.Integer -> Prelude.Either Prelude.Integer
Prelude.Integer
div_2_any_number n =
case test_even n of {
Prelude.True -> Prelude.Left (div_2_even_number n);
Prelude.False -> Prelude.Right (div_2_even_number (pred n))}
所以我想OK,让我们证明div_2_even_number
:
(*********************)
(* div_2_even_number *)
(*********************)
Definition div_2_even_number: forall n,
(Nat.Even n) -> {p:nat | n=p+p}.
Proof.
intros n0 H.
unfold Nat.Even in H.
destruct H as [m0].
exists m0.
Qed.
但我收到以下错误:
Error: Case analysis on sort Set is not allowed for inductive definition ex.
这里发生了什么?我显然在这里遗漏了一些东西。