如何在coq中证明ListMap的递归函数定理?

时间:2018-01-02 11:10:56

标签: coq coq-tactic

我试图学习在Coq中使用ListMap模块。当ListMap由递归函数创建时,我真的不确定如何证明ListMap中的键或值的属性。我觉得我不知道使用什么战术。

(* Me proving statements about maps to understand how to use maps in Coq *)

Require Import FunInd.
Require Import Coq.Lists.List.
Require Import Coq.FSets.FMapInterface.


Require Import
  Coq.FSets.FMapList
  Coq.Structures.OrderedTypeEx.

Module Import MNat := FMapList.Make(Nat_as_OT).
Require Import
        Coq.FSets.FMapFacts.

Definition NatToNat := MNat.t nat.
Definition NatToNatEmpty : NatToNat := MNat.empty nat.

(* We wish to show that map will have only positive values *)
Function insertNats (n: nat)  (mm: NatToNat)  {struct n}: NatToNat :=
  match n with
  | O => mm
  | S (next) => insertNats  next (MNat.add n n mm)
  end.


Definition keys (mm: NatToNat) : list nat :=
  List.map  fst (elements mm).

(* vvvvv How do I prove this? Intuitively it is true *)
Example keys_nonnegative: forall (n: nat),
    forall (k: nat),
      List.In k (keys (insertNats n NatToNatEmpty)) -> k >= 0.
Proof.
  intros n k in_proof.
  induction n.
  simpl in in_proof. tauto.
  (* ??? NOW WHAT *)
Admitted.

非正式地,我将用于以下程序的论点是因为n >= 0因为它是nat,因此idMapsGo插入地图的键也将始终为非负

我需要n导入keys_nonnegative。在nth步骤中,我们添加了一个键n,这将是非负的(由于是nat)。基本案例是微不足道的。

但是,我无法将这种直觉转化为Coq证明:)

1 个答案:

答案 0 :(得分:3)

您想从elements_in_iff查看elements_mapsto_iffCoq.FSets.FMapFacts

键上的有用属性:

以下是您定义键的两个有用属性,可帮助您简化校样。代码来自我自己的项目Aniceto,其中包括地图上的辅助属性。

package test;

import javax.net.ssl.HttpsURLConnection;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.HttpParams;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
public class Test {

    String url="your URL"
    DefaultHttpClient httpClient = new DefaultHttpClient();
    httpget = new HttpGet(url);
    HttpResponse httpResponse  = httpClient.execute(httpget);


    if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
        //read response from body
        ResponseHandler<String> handler = new BasicResponseHandler();
        String respBody = handler.handleResponse(httpResponse);
        if (respBody != null && !"".equals(respBody)) {
            JsonObject responseJson =  new 
        JsonParser().parse(respBody).getAsJsonObject();

        }
    }

}