如果在coq中的可判定道具中进行计算

时间:2018-06-07 04:47:59

标签: coq

我想写一个函数来计算nat-> prop函数中p 0 ... p t的真值的计数。

Section count_sc.

Variable p:nat->Prop.
Hypothesis p_dec:forall x:nat , {p x} + { ~ p x }.

Fixpoint count (x : nat) :=
    match x with
      | 0 => if p_dec(0) then 1 else 0
      | S y => if p_dec(x) then 1+count y else count y
    end. 

End count_sc.

Definition fret (x:nat) := False.

Check count.

Axiom fret_dec : forall x : nat , { fret x } + { ~ fret x }.


Theorem hello_decide : forall x : nat , count fret fret_dec x = 0.
Proof.
  intros.
  induction x.
  unfold count.
  replace (fret_dec 0) with false.
  
Qed. 

在替换战术之前我应该​​证明这样的目标:

(如果fret_dec 0则为1,否则为0)= 0

Coq剂量不能自动计算if语句的值。如果我尝试用它的值替换fret_dec,我将收到此错误:

错误:条款没有可转换类型。

我如何编写可以展开的计数函数并在定理中使用它?

1 个答案:

答案 0 :(得分:1)

您已将 <section id="dContainer"> <div class="dHeader">Title</div> <div id="dResults"> <div class="d">something A<span class="bButton">Click!</span></div> <div class="d">something b<span class="bButton">Click!</span></div> <div class="d">something c<span class="bButton">Click!</span></div> <div class="d">something d<span class="bButton">Click!</span></div> </div> </section>声明为公理。但这意味着它没有定义,或者换言之。因此,Coq无法用它来计算。

你仍然可以使用fret_dec策略证明你的定理:

destruct

但是,在这种情况下,提供这样的决策程序非常容易,而不是假设它。这大大简化了证明:

Theorem hello_decide : forall x : nat , count fret fret_dec x = 0.
Proof.
  induction x as [| x IH].
  - unfold count. destruct (fret_dec 0) as [contra | _].
    + contradiction. 
    + reflexivity.
  - simpl. rewrite IH. destruct (fret_dec (S x)) as [contra | _].
    + contradiction.
    + reflexivity.
Qed.