【发布时间】:2017-12-12 20:09:11
【问题描述】:
我想为列表唯一性及其在 Coq 中的可判定性函数定义一个谓词。我的第一次尝试是:
Section UNIQUE.
Variable A : Type.
Variable P : A -> Prop.
Variable PDec : forall (x : A), {P x} + {~ P x}.
Definition Unique (xs : list A) := exists! x, In x xs /\ P x.
在这里,我刚刚指定了谓词Unique xs 将成立,如果列表x 中只有一个值xs 使得P x 成立。现在,问题来了。当我试图定义它的Unique 可判定性时:
Definition Unique_dec : forall xs, {Unique xs} + {~ Unique xs}.
induction xs ; unfold Unique in *.
+
right ; intro ; unfold unique in * ; simpl in * ; crush.
+
destruct IHxs ; destruct (PDec a).
destruct e as [y [Hiy HPy]].
...
我收到以下令人讨厌的错误消息:
Error: Case analysis on sort Set is not allowed for inductive definition ex.
我用谷歌搜索了这条消息,并在不同的上下文中看到了几个类似的问题。至少在我看来,这样的问题似乎与 Coq 模式匹配的一些限制有关,对吧?
既然问题解决了,我的问题:
1) 我只想为基于可判定谓词的唯一性测试定义可判定性。在标准库中,存在量词和通用量词有类似的测试。两者都可以定义为归纳谓词。有没有办法将“存在唯一”定义为列表上的归纳谓词?
2) 是否可以定义这样的谓词以匹配存在唯一性的标准逻辑含义?像存在! x, P x = 存在 x, P x /\ forall y, P y -> x = y?
【问题讨论】:
-
我认为您还需要要求相等的可判定性才能捕获!一点你的谓词。在实践中,我更喜欢避免使用
In并使用 math-comp 中的seq库,其中Fixpoint uniq s := if s is x :: s' then (x \notin s') && uniq s' else true. -
请注意,列表上的唯一性谓词有两个合理的定义。除了您提供的那个之外,还有一个更强大的变体,它要求
x恰好出现在列表xs的一个位置。 -
您可以通过 Arthur 的评论归纳定义更强的版本,例如:
Inductive Unique : list A -> Prop := | Unique_base_case : forall x xs, P x -> Forall (fun y => ~ P y) xs -> Unique (x :: xs) | Unique_inductive_case : forall x xs, ~ P x -> Unique xs -> Unique (x :: xs). -
对于您提供的较弱版本,可能会将基本情况更改为:
forall x xs, P x -> Forall (fun y => P y -> y = x) xs -> Unique (x :: xs)。 -
我不明白更强的版本捕获了什么。在我的脑海中,我只看到了一个独特的
uniq定义 [对于可判定的 eqtypes ]
标签: coq