简体   繁体   English

定义中的“其他”-Coq

[英]'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. 我目前正在尝试定义可除性,在我的定义中,我写了真实的案例。

  1. Every nat is divisible with 1. 每个nat都可以被1整除。
  2. Every nat is divisible with itself. 每件事都可以被自己整除。

And my inductive case (applyable when '(i > j)' ): 和我的归纳案例(适用于'(i> j)'):

  1. Every nat 'i' is divisible by 'j' if '(i - j)' is divisible by 'j'. 如果'(i-j)'可被'j'整除,则每个nat'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: 另一种方法是用除法和余数定义除数:

  • Define a divn : nat -> nat -> nat * nat operation that divides two numbers and returns the remainder. 定义一个divn : nat -> nat -> nat * nat操作,该操作将两个数字相除并返回余数。
  • Then, divisibility is expressed as "remainder is equal to 0". 然后,除数表示为“余数等于0”。 You'll need to work out some details, such as what happens with 0 . 您需要确定一些细节,例如0会发生什么。
  • Then, a falsified divisibility hypothesis amounts to a false equality which can be usually solved by 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM