如何使用多个“符号”;0“;在Coq中
我在Coq中定义了场公理,并用它们证明了所描述的简单性质。然后,我添加了向量空间公理,并在那里证明了简单的性质。由于我的字段已经使用了如何使用多个“符号”;0“;在Coq中,coq,Coq,我在Coq中定义了场公理,并用它们证明了所描述的简单性质。然后,我添加了向量空间公理,并在那里证明了简单的性质。由于我的字段已经使用了0符号: (*******************) (* Field notations *) (*******************) Notation "0" := zero. Notation "1" := one. Infix "+" := add. Infix "*" := mul. 我在向量空间中使用了有点难看的符号: (***
0
符号:
(*******************)
(* Field notations *)
(*******************)
Notation "0" := zero.
Notation "1" := one.
Infix "+" := add.
Infix "*" := mul.
我在向量空间中使用了有点难看的符号:
(**************************)
(* Vector space notations *)
(**************************)
Notation "00" := zerov.
Notation "11" := onev.
Infix "+_v" := addv (at level 50, no associativity).
Infix "*_v" := mulv (at level 60, no associativity).
可以证明以下简单引理:
Lemma mul_0_l: forall (v : V), (eqv (mulv 0 v) 00).
当我将“00”
更改为“0V”
(更漂亮)时,一切都停止工作,我得到以下错误:
In environment
v : V
The term "0" has type "F" while it is expected to have type "V".
是否仍然可以使用
“0V”
?还是我一直在使用“00”
?令我惊讶的是,以数字开头的令牌无法识别。同时,我相信您可以使用的最接近的东西是范围表示法(尽管它长一个字符):
编辑 正如@JasonGross在评论中所建议的,您可以
Bind Scope
为两种类型T
和V
使用相同的符号0
。但在某些情况下,这可能会影响可读性
Section test.
Variable T : Type.
Variable zero : T.
Notation "0" := zero.
Variable V : Type.
Variable zeroV : V.
Notation "0" := zeroV : V_scope.
Delimit Scope V_scope with V.
Bind Scope V_scope with V.
Check 0. (* 0 : T *)
Check 0%V. (* 0%V : V *)
Variable mult : T -> V -> V.
Check mult 0 0. (* mult 0 0 : V *)
Check mult 0 0%V. (* mult 0 0 : V *)
请注意,使用
绑定作用域
,通常可以自动推断作用域(基本上,当您将其作为参数传递给函数时)
Section test.
Variable T : Type.
Variable zero : T.
Notation "0" := zero.
Variable V : Type.
Variable zeroV : V.
Notation "0" := zeroV : V_scope.
Delimit Scope V_scope with V.
Bind Scope V_scope with V.
Check 0. (* 0 : T *)
Check 0%V. (* 0%V : V *)
Variable mult : T -> V -> V.
Check mult 0 0. (* mult 0 0 : V *)
Check mult 0 0%V. (* mult 0 0 : V *)