Which vector library to use in coq?

若如初见. 提交于 2019-12-01 06:13:20

There are generally three approaches to vectors in Coq, each with their own trade-offs:

  1. Inductively defined vectors, as provided by the Coq standard library.

  2. Lists paired with an assertion of their length.

  3. Recursively-nested tuples.

Lists-with-length are nice in that they're easily coerced to lists, so you can reuse a lot of functions that operate on plain lists. Inductive vectors have the downside of requiring a lot of dependently-typed pattern matching, depending on what you're doing with them.

For most developments, I prefer the recursive tuple definition:

Definition Vec : nat -> Type :=
  fix vec n := match n return Type with
               | O   => unit
               | S n => prod A (vec n)
               end.

I am working extensively with vectors in Coq and I am using standard Coq.Vectors.Vector module. It is using textbook inductive vector definition.

The main problem is with this approach is it requires tedious type casting in situations where a vector of length, say a+b and b+a are not the same type.

I also ended up using Coq CoLoR library (opam instal coq-color) which includes package CoLoR.Util.Vector.VecUtil which contains lots of useful lemmas and definitions for vectors. I ended up writing even more on top of it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!