77 lines
2.2 KiB
Coq
77 lines
2.2 KiB
Coq
Require Import Permutation.
|
|
Require Import List.
|
|
Import ListNotations.
|
|
Print Permutation.
|
|
|
|
(*
|
|
Permutation (A : Type)
|
|
: list A -> list A -> Prop :=
|
|
perm_nil : Permutation [] []
|
|
| perm_skip : forall (x : A)
|
|
(l l' : list A),
|
|
Permutation l l' ->
|
|
Permutation
|
|
(x :: l)
|
|
(x :: l')
|
|
| perm_swap : forall (x y : A)
|
|
(l : list A),
|
|
Permutation
|
|
(y :: x :: l)
|
|
(x :: y :: l)
|
|
| perm_trans : forall
|
|
l l' l'' : list A,
|
|
Permutation l l' ->
|
|
Permutation l' l'' ->
|
|
Permutation l l''
|
|
|
|
Arguments Permutation [A]%type_scope (_ _)%list_scope
|
|
Arguments perm_nil _%type_scope
|
|
Arguments perm_skip [A]%type_scope _ [l l']%list_scope
|
|
Arguments perm_swap [A]%type_scope _ _ _%list_scope
|
|
Arguments perm_trans [A]%type_scope [l l' l'']%list_scope
|
|
*)
|
|
|
|
Compute
|
|
perm_trans
|
|
(perm_skip
|
|
1
|
|
(perm_swap 3 2 [])
|
|
)
|
|
(perm_swap 3 1 [2])
|
|
: Permutation [1; 2; 3] [3; 1; 2].
|
|
(*
|
|
|
|
1) 2 3 | 3 2 (perm_swap)
|
|
2) 1 2 3 | 1 3 2 (perm_skip 1)
|
|
3) 1 3 2 | 3 1 2 (perm_swap)
|
|
4) 1 2 3 | 3 1 2 (perm_trans 2,3)
|
|
*)
|
|
|
|
Example butterfly : forall (b u t e r f l y : nat),
|
|
Permutation ([b;u;t;t;e;r]++[f;l;y]) ([f;l;u;t;t;e;r]++[b;y]).
|
|
Proof.
|
|
intros.
|
|
change [b;u;t;t;e;r] with ([b]++[u;t;t;e;r]).
|
|
change [f;l;u;t;t;e;r] with ([f;l]++[u;t;t;e;r]).
|
|
remember [u;t;t;e;r] as utter.
|
|
clear Hequtter. (* We don't need the value. Forget about the value. *)
|
|
change [f;l;y] with ([f;l]++[y]).
|
|
remember [f;l] as fl.
|
|
clear Heqfl.
|
|
replace ((fl ++ utter) ++ [b; y]) with (fl ++ utter ++ [b; y]) by apply app_assoc.
|
|
replace (([b] ++ utter) ++ fl ++ [y]) with ([b] ++ utter ++ fl ++ [y]) by apply app_assoc.
|
|
Qed.
|
|
|
|
Lemma p123 : Permutation [1;2;3] [3;1;2].
|
|
Proof.
|
|
Search Permutation.
|
|
(*apply (perm_trans [1;2;3] [1;3;2] [3;1;2]).*)
|
|
apply (perm_trans
|
|
(perm_swap 3 1 [2]) (*[1;3;2] [1; 3; 2]) *)
|
|
(perm_skip 1 Permutation [1;3;2] [3; 1; 2])).
|
|
apply (perm_trans
|
|
(Permutation [1;2;3] [1; 3; 2])
|
|
(Permutation [1;3;2] [3; 1; 2])).
|
|
apply (perm_swap 3 1 [2]).
|
|
constructor (perm_swap 3 2 []).
|