Recursion 如何定义我自己的(递归)Coq符号?
我现在已经开始大量使用Recursion 如何定义我自己的(递归)Coq符号?,recursion,operators,coq,Recursion,Operators,Coq,我现在已经开始大量使用集成s,因为它们更灵活。为了帮助我,我正在尝试定义一些方便的符号。例如,以下内容相对简单: Notation "a ∈ S" := (@In _ S a) (at level 80). 我可以为其他二元集操作符添加一个类似的簇 但我在使用这样的符号时遇到了很多麻烦: Notation "∀ x ∈ S , P" := (forall x, (x ∈ S) -> P) (at level 90). 它已被接受,但每当我尝试使用它时,都会出现以下错误: 语法错误:
集成
s,因为它们更灵活。为了帮助我,我正在尝试定义一些方便的符号。例如,以下内容相对简单:
Notation "a ∈ S" := (@In _ S a) (at level 80).
我可以为其他二元集操作符添加一个类似的簇
但我在使用这样的符号时遇到了很多麻烦:
Notation "∀ x ∈ S , P" := (forall x, (x ∈ S) -> P) (at level 90).
它已被接受,但每当我尝试使用它时,都会出现以下错误:
语法错误:“∈" 预计在[constr:operconstr 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\u core
中的库版本应该解析,而我的不应该解析,但是:
错误:找不到递归模式的起始位置
问题2:见问题1。上面的递归表示法不起作用的原因是活页夹(在本例中为
x
和y
)只能在右侧的两个特定位置之一使用[]:
- 在
术语中的活页夹位置,或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
接受一个谓词(afun
),并在给定集合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.
还请注意集合运算符的新优先级别,相对于现有优先级别[]更具意义