1

I'm using the Coq MSet library in my development and I'm having some trouble to use the generalised rewriting involving MSet values. Below I have a simplified version of my problem:

First, we need to define the modules for MSet.

Module NSet := Make Nat_as_OT.
Module NSetDec := MSetDecide.WDecide NSet.

And I have a function with the following type:

Parameter calc : NSet.t -> string -> bool.

What I want is to rewrite set equalities present in calls to function calc. For this, I tried to define a Proper instance like this.

Instance calc_proper 
  : Proper (NSet.Equal ==> @eq string ==> @eq bool) calc.
Proof.
   intros S S' H s s' H1.
   rewrite H1.
   rewrite H. (** error here! *)

My doubt is how to finish such an instance. When I try to execute the last rewrite, Coq returns the following error message:

  Tactic failure: setoid rewrite failed: Unable to satisfy the following constraints:
   UNDEFINED EVARS:
   ?X33==[S S' H s s' H1 |- relation bool] (internal placeholder) {?r}
   ?X34==[S S' H s s' H1 |- relation string] (internal placeholder) {?r0}
   ?X35==[S S' H s s' H1 (do_subrelation:=do_subrelation)
           |- Proper (NSet.Equal ==> ?r0 ==> ?r) calc] (internal placeholder) {?p}
   ?X36==[S S' H s s' H1 |- ProperProxy ?r0 s'] (internal placeholder) {?p0}
   ?X38==[S S' H s s' H1 |- relation bool] (internal placeholder) {?r1}
   ?X39==[S S' H s s' H1 (do_subrelation:=do_subrelation)
           |- Proper (?r ==> ?r1 ==> flip impl) eq] (internal placeholder) {?p1}
   ?X40==[S S' H s s' H1 |- ProperProxy ?r1 (calc S' s')] (internal placeholder) {?p2}
           TYPECLASSES:?X33 ?X34 ?X35 ?X36 ?X38 ?X39 ?X40

Which seems that my code is missing some instance(s). The minimal example that exhibit the problem is available at the following gist.

Rodrigo Ribeiro
  • 3,198
  • 1
  • 18
  • 26
  • 1
    Li-yao Xia's answer is correct. However, perhaps you just want to 'assume' that calc already is Proper, and want to reason about it (before proving). Then you can just say that such a proof exists: `Context #{Proper _ (NSet.Equal ==> eq ==> eq) calc}.` Now you can rewrite. `Lemma foo a b c: NSet.Equal a b -> calc a c = calc b c. intros H0. rewrite H0. reflexivity. Qed.` Note that # should be a backtick, the stackoverflow comment eats my backticks! – larsr Mar 24 '20 at 11:05

1 Answers1

1

The Proper instance is part of the obligations that you need to be able to use rewrite in the first place. You need to prove it using more elementary methods.

Li-yao Xia
  • 31,896
  • 2
  • 33
  • 56