Functional programming Coq证明中使用了错误的Typeclass实例

Functional programming Coq证明中使用了错误的Typeclass实例,functional-programming,coq,typeclass,dependent-type,theorem-proving,Functional Programming,Coq,Typeclass,Dependent Type,Theorem Proving,我试图基于CoqExtLib中定义的有限映射执行以下证明。然而,我遇到了一个问题,证明中出现的RelDec实例与我认为声明的实例不同 Require Import ExtLib.Data.Map.FMapAList. Require ExtLib.Structures.Sets. Module DSet := ExtLib.Structures.Sets. Require ExtLib.Structures.Maps. Module Map := ExtLib.Structu

我试图基于CoqExtLib中定义的有限映射执行以下证明。然而,我遇到了一个问题,证明中出现的
RelDec
实例与我认为声明的实例不同

Require Import ExtLib.Data.Map.FMapAList.
Require ExtLib.Structures.Sets.
Module DSet := ExtLib.Structures.Sets.          
Require ExtLib.Structures.Maps.
Module Map := ExtLib.Structures.Maps.
Require Import ExtLib.Data.Nat.
Require Import Coq.Lists.List.

Definition Map k v := alist k v.
Definition loc := nat.
Definition sigma : Type := (Map loc nat).


Lemma not_in_sigma : forall (l l' : loc) (e : nat) (s : sigma),
    l <> l' ->
    Map.lookup l ((l',e)::s) = Map.lookup l s.
  intros. simpl. assert ( RelDec.rel_dec l l' = true -> l = l').
  pose (ExtLib.Core.RelDec.rel_dec_correct l l') as i. destruct i.

(*i := RelDec.rel_dec_correct l l' : RelDec.rel_dec l l' = true <-> l >= l'*)
需要导入ExtLib.Data.Map.FMapAList。
需要ExtLib.Structures.set。
模块DSet:=ExtLib.Structures.set。
需要ExtLib.Structures.Maps。
模块映射:=ExtLib.Structures.Maps。
需要导入ExtLib.Data.Nat。
需要导入Coq.Lists.List。
定义映射kv:=列表kv。
定义loc:=nat。
定义:类型:=(映射位置nat)。
引理不在sigma中:forall(l:loc)(e:nat)(s:sigma),
l'->
Map.lookup l((l',e)::s)=Map.lookup l s。
介绍。简单。断言(RelDec.rel_dec l'=true->l=l')。
将(ExtLib.Core.RelDec.rel_dec_correct l')摆成i。破坏i。
(*i:=RelDec.rel_dec_correct l l':RelDec.rel_dec l'=true l>=l'*)
如您所见,我试图使用这样一个事实:如果两个输入不相等,则
rel_dec
的计算结果必须为false。这似乎与ExtLib.Data.Nat中给出的定义相匹配:

全局实例RelDec\u eq:RelDec(@eq-nat):=
{rel_dec:=EqNat.beq_nat}。

然而,在我上面展示的代码中,它使用
=
而不是
=
作为有限映射的参数化关系,因此我无法应用定理
rel\u dec\u correct


为什么会这样?如何选择RelDec的实例?当证明关于由类型类限定的类型的定理时,我需要做什么特殊的事情吗?如何获得适用于等式且不大于的
rel\u dec\u correct
版本?

要解决此问题,您可能需要设置
调试类型类
选项:

Set Debug Typeclasses.
assert ( RelDec.rel_dec l l' = true -> l = l').
或者,也可以使用
Set Printing Implicit
显示Coq拾取的实例

后者向我们展示了它是RelDec\u ge,因为目标现在具有以下形式:

@RelDec.rel_dec loc ge RelDec_ge l l' = true -> l = l'
显然,Coq选择的实例不符合您的目的,但是您可以锁定所需的关系,如下所示:

assert ( RelDec.eq_dec l l' = true -> l = l').
现在
apply(RelDec.rel\u dec\u correct l')。
解决了目标,但是
pose
不起作用,因为没有任何信息可以将目标与有用的实例联系起来。
pose
策略只会找到
RelDec nat
的一个实例(您可以使用以下术语列出所有实例:
Print Instances RelDec.RelDec.

有一个B.C.皮尔斯的非常好的作品,你可能想看一看