Use proof of if expression = true in then part coq

大城市里の小女人 提交于 2019-12-12 20:56:21

问题


Forall 1 <= a and 2 <= b exists k that (b^k) divide a but (b^(k+1)) do not divide a ; And I want to calculate k in coq:

Require Import ZArith Znumtheory.

Local Open Scope Z_scope.


Require Coq.Program.Tactics.
Require Coq.Program.Wf.

Lemma divgt0 ( a b : Z ) ( agt0 : 0 < a ) ( bgt1 : 1 < b ) (dvd : (b|a) ) : 0<a/b.
Proof.
  apply Zdivide_Zdiv_lt_pos.
  auto.
  auto.
  auto.
Qed.

Program Fixpoint factor ( a b : Z ) ( agt0 : 0 < a ) ( bgt1 : 1 < b ) {measure (Z.abs_nat a)} := 
  if Zdivide_dec b a 
  then factor (a/b) b (divgt0 a b agt0 bgt1 (Zdivide_dec b a))  bgt1 
  else 0.
Next Obligation.

How I can use proof of (b|a) in then part of the if?


回答1:


Program remembers that kind of information. If you leave an underscore in place of the needed proof, the system can figure it out on its own.

Program Fixpoint factor ( a b : Z ) ( agt0 : 0 < a ) ( bgt1 : 1 < b ) {measure (Z.abs_nat a)} := 
  if Zdivide_dec b a 
  then factor (a/b) b (divgt0 a b agt0 bgt1 _)  bgt1 
  else 0.                                (* ^ here *)
Next Obligation.

At this point all you need to do is to prove that your measure decreases, which is not hard.



来源:https://stackoverflow.com/questions/51012942/use-proof-of-if-expression-true-in-then-part-coq

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!