如何从FMapInterface.MapsTo获取FMapInterface.In,反之亦然?

时间:2014-12-03 22:48:36

标签: map coq

从手册FMapInterface.In定义为:

Definition In (k:key)(m: t elt) : Prop := exists e:elt, MapsTo k e m.

所以,我希望展开一个术语In k m会产生exists e, MapsTo k e m

然而,在Coq 8.4pl4中,鉴于此:

______________________________________(1/1)
In (elt:=t) k m

执行unfold收益

______________________________________(1/1)
Raw.In0 t (this m)

发出Print M(其中M是相关模块)我

Module M
 : Sig 
.
.
. 
   End
:= (FMapAVL.Make ID)

我的解决方案是使用lemmas find_mapsto_iffin_find_iff(来自FMapFacts),但这似乎过于复杂。为什么不展开定义工作?

1 个答案:

答案 0 :(得分:0)

模块FMapInterface的实例(从FMapAVL.Make获得)更改 In的定义,因此该基本属性在实例中丢失。

相反,必须在FMapInterface级别证明结果。解决方案是使用这两个属性创建一个辅助模块。

Require Coq.FSets.FMapFacts.
Require Coq.FSets.FMapInterface.

Module MapUtil (Import M:FMapInterface.WS).
  Module F := FMapFacts.Facts M.
  Import F.
  Lemma mapsto_to_in:
    forall elt k e m,
    MapsTo (elt:=elt) k e m ->
    In k m.
  Proof.
    intros.
    unfold In.
    exists e.
    assumption.
  Qed.

  Lemma in_to_mapsto : forall (elt:Type) m x,
    In x m -> exists (e:elt), MapsTo x e m.
  Proof.
    intros.
    unfold In in H.
    assumption.
  Qed.
End MapUtil.

使用上面的模块遵循使用Coq.FSets.FMapFacts的相同模式。例如:

Require Import Coq.Structures.OrderedTypeEx. (* Imports: Nat_as_OT *)
Require Import Coq.FSets.FMapAVL.            (* Imports: FMapAVL.Make *)
Module Map_Nat := FMapAVL.Make Nat_as_OT.    (* Defines a map with nats as keys. *)
Module Map_Nat_Util := MapUtil Map_Nat.      (* Defines an instance of module MapUtil. *)