Coq Import problems

2019-08-19 01:54发布

I'm trying to import Library Coq.Structures.OrdersFacts as usual with:

Require Import Coq.Structures.OrdersFacts

Then I try to use of the lemmas there with either: apply CompareFacts.compare_nlt_iff. or apply compare_nlt_iff. But none work ... what am I missing?

标签: import coq
1条回答
等我变得足够好
2楼-- · 2019-08-19 02:06

CompareFacts is a Module Type, not a Module. You can see that if you do

Require Import  Coq.Structures.OrdersFacts.
Print OrdersFacts.CompareFacts.

Find a Module of this type and apply its Lemmas instead.

EDIT:

I meant that to use the lemmas on i.e. nat, you need a module that shows that nat is a DecStrOrder' (and Nat from PeanoNat is such a module), and also one that specializes CompareFacts for nat .

Perhaps an example is more useful.

Require Import  Coq.Structures.OrdersFacts.

Module mymodule (O:DecStrOrder') (T: CompareFacts O).
  Import T.
  Import O.
  Check compare_eq_iff. (* from CompareFacts *)

  (* a theorem about terms of type O.t *)
  Lemma lem1 a b c: (a ?= b) = Eq -> b == c -> c == a. 
    intros.
    rewrite compare_eq_iff in H.  (* here we use the lemma *)
    rewrite H.
    rewrite H0.
    apply eq_equiv.
  Qed.
End mymodule.

(* the above module functor can be specialised for i.e. nat *)

Require Import PeanoNat.

Print CompareFacts.
Module M : CompareFacts Nat.
  Definition compare_eq_iff := Nat.compare_eq_iff.
  Definition compare_eq := Nat.compare_eq.
  Definition compare_lt_iff := Nat.compare_lt_iff.
  Definition compare_gt_iff := Nat.compare_gt_iff.
  Definition compare_nlt_iff := Nat.compare_nlt_iff.
  Definition compare_ngt_iff := Nat.compare_ngt_iff.
  Definition compare_refl := Nat.compare_refl.
  Definition compare_compat: Proper (eq==>eq==>eq) Nat.compare.
    intros x y Hxy a b Hab; now subst. Defined.
  Definition compare_antisym := Nat.compare_antisym.
End M.  

Module natmodule := mymodule Nat M.
Check natmodule.lem1.
查看更多
登录 后发表回答