我现在开始与Ensemble
合作很多,因为它们更灵活。为了帮助我,我试图定义一些方便的符号。以下相对容易,例如:
Notation "a ∈ S" := (@In _ S a) (at level 80).
我可以为其他二进制集运算符添加类似的数据集。
但是我对这样的符号有很多麻烦:
Notation "∀ x ∈ S , P" := (forall x, (x ∈ S) -> P) (at level 90).
它已被接受,但每当我尝试使用它时,我都会收到此错误:
语法错误:[constr:operconstr level 200]之后预期的“∈”(在[constr:operconstr]中)。
问题1:我做错了什么?
对于奖励积分,你能告诉我如何为它定义一个递归表示法吗?我试过了,但它似乎给了我一系列全新的问题。这是我的尝试,直接编辑库定义:
Notation "∀ x .. y ∈ S , P" :=
(forall x, (x ∈ S) -> .. (forall y, (y ∈ S) -> P) ..)
(at level 200, x binder, y binder, right associativity).
我不明白为什么Coq.Unicode.Utf8_core
中的库版本应该解析而我的不应该,但是:
错误:无法找到递归模式的开始位置。
问题2:请参阅问题1。
答案 0 :(得分:3)
上面的递归表示法不起作用的原因是绑定器(在这种情况下为x
和y
)只能 在两个特定位置之一中使用在右侧[see manual]:
fun [ ] => ...
字词的活页夹位置,或forall [ ], ...
字词的活页夹位置。所以,我不能再将它们用作术语了。这对我来说似乎有点武断,因为绑定器是绑定上下文中的术语。但是,您可以使用fun
路径执行任何操作:
Definition all_in_E `(E: Ensemble T, P: T → Prop) : T → Prop :=
(λ x: T, (x ∈ E) → (P x)).
Notation "∀ x .. y ∈ S , P" :=
( all ( all_in_E S ( fun x => .. ( all ( all_in_E S ( fun y => P ))) .. )))
(at level 200, x closed binder, y closed binder, right associativity).
Definition ex_in_E `(E: Ensemble T, P: T → Prop) : T → Prop :=
(λ x: T, (x ∈ E) ∧ (P x)).
Notation "∃ x .. y ∈ S , P" :=
( ex ( ex_in_E S ( fun x => .. ( ex ( ex_in_E S ( fun y => P ))) .. )))
(at level 200, x closed binder, y closed binder, right associativity).
函数all_in_E
和ex_in_E
采用谓词(fun
)并使用条件来增加给定系数E
的成员资格。它需要很长的路要走,但它确实有效。
这是一个完整工作的代码块,带有示例:
Require Export Coq.Unicode.Utf8.
Require Export Coq.Sets.Ensembles.
Generalizable All Variables.
Notation "a ∈ S" := (@In _ S a) (at level 70, no associativity).
Notation "A ∪ B" := (@Union _ A B) (at level 50, left associativity).
Notation "A ∩ B" := (@Intersection _ A B) (at level 40, left associativity).
Definition all_in_E `(E: Ensemble T, P: T → Prop) : T → Prop :=
(λ x: T, (x ∈ E) → (P x)).
Notation "∀ x .. y ∈ S , P" :=
( all ( all_in_E S ( fun x => .. ( all ( all_in_E S ( fun y => P ))) .. )))
(at level 200, x closed binder, y closed binder, right associativity).
Definition ex_in_E `(E: Ensemble T, P: T → Prop) : T → Prop :=
(λ x: T, (x ∈ E) ∧ (P x)).
Notation "∃ x .. y ∈ S , P" :=
( ex ( ex_in_E S ( fun x => .. ( ex ( ex_in_E S ( fun y => P ))) .. )))
(at level 200, x closed binder, y closed binder, right associativity).
Section TestingEnsembleQuantifiers.
Definition A_nat := Full_set nat.
Definition E_nat := Empty_set nat.
Definition F_nat := Singleton _ 5.
Require Import Coq.Arith.Gt.
Example exists_in_intersection: ∃ x ∈ A_nat ∩ F_nat , x = 5.
unfold ex_in_E.
exists 5.
split ; trivial.
split.
apply Full_intro.
apply In_singleton.
Qed.
Example forall_in_union: ∀ x ∈ F_nat ∪ E_nat, x ≥ 5.
unfold all_in_E, all.
intros.
destruct H ; destruct H.
auto with arith.
Qed.
End TestingEnsembleQuantifiers.
还请注意集合运算符的新优先级,它们与现有的优先级[see manual]相比更有意义。