使用Coq字段公理

时间:2019-05-10 03:54:20

标签: coq

我正在尝试Coq字段模块,试图直接从字段公理证明以下简单身份:forall v, 0v == v。我看到0==都有现有的符号,所以我尝试了一下(但失败了):

(***********)
(* IMPORTS *)
(***********)
Require Import Coq.setoid_ring.Field_theory.

(*********************)
(* forall v, 0v == v *)
(*********************)
Lemma mul_0_l: forall v,
  ("0" * v "==" "0")%R_scope.
Proof.

我收到此错误消息:

Unknown scope delimiting key R_scope.

当我看着the field library时,R_scope肯定在那里, 所以我一定很想念东西。

2 个答案:

答案 0 :(得分:3)

实际上,这些符号位于一节中,这意味着它们无法从外部获得。

此外,所有这些定义都由字段结构参数化,因此,如果要证明有关字段的一般结果,则需要在本地声明(或实例化)这些参数。

我不确定它是否真的打算以这种方式使用。我的建议是在Github上打开一个问题,询问setoid_ring插件的用途。

Require Import Coq.setoid_ring.Field_theory.
Require Import Coq.setoid_ring.Ring_theory.
Require Import Setoid.

Section MyFieldTheory.

(* Theory parameterized by a field R *)
Variable (R:Type)
         (rO:R) (rI:R)
         (radd rmul rsub : R -> R -> R)
         (ropp : R -> R)
         (rdiv : R -> R -> R)
         (rinv : R -> R)
         (req : R -> R -> Prop)
.
Variable Rfield : field_theory rO rI radd rmul rsub ropp rdiv rinv req.
Variable Reqeq : Equivalence req.
Variable Reqext : ring_eq_ext radd rmul ropp req.

(* Field notations *)
Notation "0" := rO : R_scope.
Notation "1" := rI : R_scope.
Infix "+" := radd : R_scope.
Infix "*" := rmul : R_scope.
Infix "==" := req : R_scope.

(* Use these notations by default *)
Local Open Scope R_scope.


(* Example lemma *)

Lemma mul_0_l: forall v, (0 * v == 0).
Proof.
  intros v.
  apply ARmul_0_l with rI radd rsub ropp.
  apply F2AF, AF_AR in Rfield; auto.
Qed.

关于符号

请注意,引号是Notation / Infix命令语法的一部分

Infix "+" := radd : R_scope.

您现在可以只写x + y,不用引号。

优良作法是将范围分配给您的符号(例如,通过上面的: R_scope注释),因为这样可以为同一符号启用区分不同含义的机制。特别是,使符号可用的主要两种方法是:

  • Local Open Scope R_scope.使所有R_scope符号可用于当前文件。

  • Bind Scope R_scope with whatever.定界键 whatever与范围R_scope相关联。分隔键是在%符号之后用来在给定表达式中打开作用域的内容,因此无论先前是否使用(0 == 0 * v)%whatever打开R_scope,您都可以编写Local Open Scope

答案 1 :(得分:0)

这是基于@ Li-yao-Xia的(失败的)尝试:

(***********)
(* IMPORTS *)
(***********)
Require Import Coq.setoid_ring.Field_theory.
Require Import Coq.setoid_ring.Ring_theory.

(**********)
(* SCOPES *)
(**********)
Delimit Scope R_scope with ring.

(************)
(* SECTIONS *)
(************)
Section MyFieldTheory.

(* Theory parameterized by a field R *)
Variable (R:Type)
         (rO:R) (rI:R)
         (radd rmul rsub : R -> R -> R)
         (ropp : R -> R)
         (rdiv : R -> R -> R)
         (rinv : R -> R)
         (req : R -> R -> Prop)
.
Variable Rfield : field_theory rO rI radd rmul rsub ropp rdiv rinv req.

(*******************)
(* Field notations *)
(*******************)
Notation "0" := rO   : R_scope.
Notation "1" := rI   : R_scope.
Infix    "+" := radd : R_scope.
Infix    "*" := rmul : R_scope.
(*******************)
(* Field notations *)
(*******************)
Infix "==" := req (at level 70, no associativity) : R_scope.

(* Use these notations by default *)
Local Open Scope R_scope.


(* Example lemma *)

Lemma mul_0_l: forall v, (0 * v == 0).
Proof.
  intros v.
  apply ARmul_0_l with rI radd rsub ropp.
  apply Rfield.

假设我有:

Rfield : field_theory 0 1 radd rmul rsub ropp rdiv rinv req

目标说:

almost_ring_theory 0 1 radd rmul rsub ropp req

我认为必须有这样的内容:field_theory -> almost_ring_theory。 但是当我尝试apply Rfield时,我得到了:

In environment
R : Type
rO, rI : R
radd, rmul, rsub : R -> R -> R
ropp : R -> R
rdiv : R -> R -> R
rinv : R -> R
req : R -> R -> Prop
Rfield : field_theory 0 1 radd rmul rsub ropp rdiv rinv req
v : R
Unable to unify "field_theory 0 1 radd rmul rsub ropp rdiv rinv req" with
 "almost_ring_theory 0 1 radd rmul rsub ropp req".