gpt4 book ai didi

recursion - 如何定义我自己的(递归)Coq 符号?

转载 作者:行者123 更新时间:2023-12-05 01:20:28 24 4
gpt4 key购买 nike

我已经开始大量使用 Ensemble s 现在,因为它们更灵活。为了帮助我解决这个问题,我试图定义一些方便的符号。下面比较简单,例如:

Notation "a ∈ S" := (@In _ S a)  (at level 80).

我可以为其他二元集运算符添加类似的一堆。

但是我在使用这样的符号时遇到了很多麻烦:
Notation "∀ x ∈ S , P" := (forall x, (x ∈ S) -> P)  (at level 90).

它被接受,但每当我尝试使用它时,我都会收到此错误:

Syntax error: "∈" expected after [constr:operconstr level 200] (in [constr:operconstr]).



问题一:我究竟做错了什么?

对于奖励积分,你能告诉我如何为它定义一个递归符号吗?我已经尝试过了,但它似乎给了我一系列全新的问题。这是我的尝试,对库定义的直接编辑:
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 中的库版本应该解析而我的不应该,但是:

Error: Cannot find where the recursive pattern starts.



问题二:见问题 1。

最佳答案

上面的递归符号不起作用的原因是活页夹(在本例中为 xy )只能用于右侧的两个特定位置之一 [ see manual ]:

  • fun [ ] => ... 中的活页夹位置术语,或
  • forall [ ], ... 中的活页夹位置学期。

  • 因此,我不能再次将它们用作术语。这对我来说似乎有些武断,因为活页夹是其绑定(bind)上下文中的术语。但是,您几乎可以使用 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_Eex_in_E取一个谓词 (a 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 相比更有意义。 ]。

    关于recursion - 如何定义我自己的(递归)Coq 符号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16920170/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com