[英]'else' in definitions - Coq
First of all I'm new to proof theory and coq, so I'd appreciate answers to be easy to understand. 首先,我是证明理论和证明书的新手,所以我希望答案易于理解。
I'm trying to build up definitions to eventually define prime numbers; 我正在尝试建立定义以最终定义素数。 I'm currently trying to define divisibility, and in my definition I've written the true cases.
我目前正在尝试定义可除性,在我的定义中,我写了真实的案例。
And my inductive case (applyable when '(i > j)' ): 和我的归纳案例(适用于'(i> j)'):
Now in some of my subsequent lemmas I need that everything not fulfilling this is false. 现在,在接下来的一些引理中,我需要所有不满足要求的东西都是错误的。
How would I go about encoding this in my definition? 我将如何在定义中对此进行编码? I'm thinking something alike, when none of the above is applicable --> false.
当以上都不适用时,我在想类似的东西->否。 - In a sense an else statement for definitions.
-在某种意义上,else语句用于定义。
In constructive logic , which Coq is built upon, a proposition is only considered "true" when we have direct evidence, ie proof. 在构建 Coq的构造逻辑中 , 只有当我们有直接证据(即证明)时,命题才被视为“真实”。 So, one doesn't need such "else" part, because anything that cannot be constructed is in a sense false.
因此,不需要这样的“其他”部分,因为任何无法构造的东西在某种意义上都是错误的。 If none of the cases for your "is divisible by" relation are applicable, you'll be able to prove your statement by contradiction, ie derive
False
. 如果您的“可被”整除的情况都不适用,那么您将能够通过矛盾证明您的陈述,即得出
False
。
For example, if we have this definition of divisibility: 例如,如果我们有除数的定义:
(* we assume 0 divides 0 *)
Inductive divides (m : nat) : nat -> Prop :=
| div_zero: divides m 0
| div_add: forall n, divides m n -> divides m (m + n).
Notation "( x | y )" := (divides x y) (at level 0).
Then we can prove the fact that 3 does not divide 5, using inversion
, which handles the impossible cases: 然后,我们可以使用
inversion
证明3不会除以5的事实,这可以处理不可能的情况:
Fact three_does_not_divide_five:
~(3 | 5).
Proof.
intro H. inversion H. inversion H2.
Qed.
Note : we can check that our divides
relation captures the notion of divisibility by introducing an alternative ("obvious") definition: 注意 :我们可以通过引入替代(“显而易见的”)定义来检查
divides
关系是否涵盖了可除性的概念:
Definition divides' x y := exists z, y = z*x.
Notation "( x |' y )" := (divides' x y) (at level 0).
and proving their equivalence: 并证明它们的等效性:
Theorem divides_iff_divides' (m n : nat) :
(m | n) <-> (m |' n).
Admitted. (* it's not hard *)
A different approach is to define divisibility from with division and remainder: 另一种方法是用除法和余数定义除数:
divn : nat -> nat -> nat * nat
operation that divides two numbers and returns the remainder. divn : nat -> nat -> nat * nat
操作,该操作将两个数字相除并返回余数。 0
. 0
会发生什么。 congruence
. congruence
来解决。 You can manipulate the equality with the standard theory for the remainder. This is the approach used in the math-comp library, see http://math-comp.github.io/math-comp/htmldoc/mathcomp.ssreflect.div.html 这是math-comp库中使用的方法,请参见http://math-comp.github.io/math-comp/htmldoc/mathcomp.ssreflect.div.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.