Coq中“ ==>”是什么意思?

时间:2019-11-02 02:49:03

标签: coq

我有以下代码: 这是排序的定义:

const { Schema, Types: { ObjectId } } = mongoose = require('mongoose');

const uri = 'mongodb://localhost:27017/menu';
const options = { useNewUrlParser: true, useUnifiedTopology: true };

mongoose.set('debug', true);
mongoose.set('useFindAndModify', false);
mongoose.set('useCreateIndex', true);

const recipeCategorySchema = new Schema({
  CategoryName: String
});

const recipeSchema = new Schema({
  recipeTitle: String,
  Recipetags: [String],
  cookTime: String,
  recipeCategoryId: [{ type: Schema.Types.ObjectId, ref: 'RecipeCategory' }],
  recipeCuisineId: String,
  recepeType: Boolean,
  availableStreaming: String,
  postedBy: String
});

const userSchema = new Schema({
  emailId: String,
  fullName: String,
  accessToken: String
});

const RecipeCategory = mongoose.model('RecipeCategory', recipeCategorySchema);
const Recipe = mongoose.model('Recipe', recipeSchema);
const User = mongoose.model('User', userSchema);

const log = data => console.log(JSON.stringify(data, undefined, 2));

(async function() {

  try {

    const conn = await mongoose.connect(uri, options);

    // Clean data for demonstration
    await Promise.all(
      Object.values(conn.models).map(m => m.deleteMany())
    );

    // Insert some data
    await RecipeCategory.insertMany([
      {
        "_id": ObjectId( "5dada3c5761bb32a1201d4da"),
        "CategoryName":"Biryani"
      },
      {
        "_id": ObjectId("5dada3c5761bb32a1201d4db"),
        "CategoryName":"Mutton Biryani"
      },
      {
        "_id": ObjectId("5dada3c5761bb32a1201d4d4"),
        "CategoryName":"Chicken Biryani"
      },
      {
        "_id": ObjectId("5daea43a517cf601a7e80a3b"),
        "CategoryName":"Kathirikai gothsu"
      }
    ]);

    await Recipe.insertMany([

      {
        "recipeTitle":"Mutton dum biryani",
        "Recipetags":["Indian","NonVeg","Lunch"],
        "cookTime":"30 Mins",
        "recipeCategoryId":[
          ObjectId("5dada3c5761bb32a1201d4da"),
          ObjectId("5dada3c5761bb32a1201d4db"),
          ObjectId("5dada3c5761bb32a1201d4dc")
        ],
        "recipeCuisienId":"Indian",
        "recepeType":false,
        "availaleStreaming":"TEXT",
        "postedOn": new Date(),
        "postedBy":"shiva@yopmail.com"
      },
      {
        "recipeTitle":"Mutton Chicken biryani",
        "Recipetags":["Indian","NonVeg","Lunch"],
        "cookTime":"30 Mins",
        "recipeCategoryId":[
          ObjectId("5dada3c5761bb32a1201d4da"),
          ObjectId("5dada3c5761bb32a1201d4d4"),
          ObjectId("5dada3c5761bb32a1201d4dc")
        ],
        "recipeCuisienId":"Indian",
        "recepeType":false,
        "availaleStreaming":"TEXT",
        "postedOn": new Date(),
        "postedBy":"shiva@yopmail.com"
      }
    ]);

    await User.create({
      "emailId":"shiva@yopmail.com",
      "fullName":"siva prakash",
      "accessToken":"xxxxxxxxxxxxx",
    });

    const wantedCategories = [
      ObjectId("5dada3c5761bb32a1201d4da"),
      ObjectId("5dada3c5761bb32a1201d4db")
    ];

    let data = await Recipe.aggregate([
      // Match wanted category(ies)
      { "$match": {
        "recipeCategoryId": { "$in": wantedCategories }
      }},
      // Filter the content of the array
      { "$addFields": {
        "recipeCategoryId": {
          "$filter": {
            "input": "$recipeCategoryId",
            "cond": {
              "$in": [ "$$this", wantedCategories ]
            }
          }
        }
      }},
      // Lookup the related matching category(ies)
      { "$lookup": {
        "from": RecipeCategory.collection.name,
        "let": { "recipeCategoryIds": "$recipeCategoryId" },
        "pipeline": [
          { "$match": {
            "$expr": { "$in": [ "$_id", "$$recipeCategoryIds" ] }
          }}
        ],
        "as": "recipeCategoryId"
      }},
      // Lookup the related user to postedBy
      { "$lookup": {
        "from": User.collection.name,
        "let": { "postedBy": "$postedBy" },
        "pipeline": [
          { "$match": { "$expr": { "$eq": [ "$emailId", "$$postedBy" ] } } }
        ],
        "as": "postedBy"
      }},
      // postedBy is "singular"
      { "$unwind": "$postedBy" }
    ]);

    log({ data });

  } catch (e) {
    console.error(e)
  } finally {
    mongoose.disconnect();
  }

})()

这是插入的定义:

Fixpoint sorted (l : list nat) := 
  match l with 
  | [] => true 
  | x::xs => match xs with 
             | [] => true 
             | y :: ys => (x <=? y) && (sorted xs) 
             end 
  end.

这是insert_spec的定义:


Fixpoint insert (x : nat) (l : list nat) := 
  match l with 
  | [] => [x] 
  | y::ys => if x <=? y then x :: l 
             else y :: insert x ys 
  end.

在insert_spec中,“ ==>”是什么意思?

1 个答案:

答案 0 :(得分:3)

看来您从Software Foundations的QuickChick guide获得了代码。该指南中使用的许多(如果不是全部)符号可以在QuickChick Reference Manual中找到。在那里,我们发现"==>"被定义为一种符号。

Module QcNotation.
  Export QcDefaultNotation.
  Notation "x ==> y" :=
    (implication x y) (at level 55, right associativity)
    : Checker_scope.
End QcNotation.

implication是QuickChick使用的通用“此含义是否正确”参数。

Parameter implication :
  ∀ {prop : Type} `{Checkable prop} (b : bool) (p : prop), Checker.

只要第一个参数为true,QuickChick都会测试第二个参数(在您使用QuickChick的任何上下文中)是否也都为true。

因此对于您的特定代码段,"==>"用来表示我们要测试是否l被排序时,insert x l也被排序。

相关问题