Мне нужно рассуждать о перестановках векторов в Coq. Стандартная библиотека включает только определения перестановок для списков. В качестве первой попытки я попытался имитировать это для векторов как:
Inductive VPermutation: forall n, vector A n -> vector A n -> Prop :=
| vperm_nil: VPermutation 0 [] []
| vperm_skip {n} x l l' : VPermutation n l l' -> VPermutation (S n) (x::l) (x::l')
| vperm_swap {n} x y l : VPermutation (S (S n)) (y::x::l) (x::y::l)
| vperm_trans {n} l l' l'' :
VPermutation n l l' -> VPermutation n l' l'' -> VPermutation n l l''.
Я быстро понял, что существует множество лемм о перестановках, уже проверенных на списках, которые также необходимо доказать для векторов. Это большая работа, и я подумал, что, возможно, смогу сократить путь, доказав следующую лемму:
Lemma ListVecPermutation {n} {l1 l2} {v1 v2}:
l1 = list_of_vec v1 ->
l2 = list_of_vec v2 ->
Permutation l1 l2 ->
VPermutation A n v1 v2.
Proof.
Это позволило бы мне повторно использовать леммы перестановки списков для векторов, пока я могу показать, что векторы могут быть преобразованы в соответствующие списки.
Кроме того: я использую определение list_of_vec
из библиотеки coq-color
, поскольку его легче рассуждать, чем VectorDef.to_list
.
Fixpoint list_of_vec n (v : vector A n) : list A :=
match v with
| Vnil => nil
| Vcons x v => x :: list_of_vec v
end.
Доказательство этой леммы оказалось непростым. Я попробовал сделать это по индукции:
Proof.
intros H1 H2 P.
revert H1 H2.
dependent induction P.
-
intros H1 H2.
dep_destruct v1; auto.
dep_destruct v2; auto.
inversion H1.
-
Но это оставляет меня с индуктивной гипотезой, которая недостаточно обобщена и зависит от v1
и v2
:
IHP : l = list_of_vec v1 -> l' = list_of_vec v2 -> VPermutation A n v1 v2
Буду рад услышать предложения по подходу в целом и моей его формулировке.
P.S. Полный автономный пример: https://gist.github.com/vzaliva/c31300aa484ff6ad2089cb0c45c3828a
seq
иtuple
, доступными в math-comp. - person ejgallego   schedule 20.10.2017